006
01.09.2003, 17:44 Uhr
~werner
Gast
|
C++: |
short BitMapProcess (CMyBitmap *bm, int createScanProfile) // otherwise createPrintProfile { short bits16 = 0, i, j, index; int ret = bm->Open (); int bbp = bm->BBP (); int planes = bbp / 8, srcIncr = planes; int width = bm->Width (); int height = bm->Height (); char *scanline; int size; int ps_rows = PS_Rows, ps_cols = PS_Cols; int pixels_per_square, pixels_per_col, pixels_per_row, pixels_border; float float_pixels_per_col, float_pixels_per_row; unsigned char *srcPtr; unsigned short *srcPtr16; if (ret != BITMAP_NOERR) goto finish; fPS_Grid = (float*)malloc(PS_Rows*PS_Cols*4*sizeof(float)); fPS_Count = (long*)malloc(PS_Rows*PS_Cols*4*sizeof(float));
if (!fPS_Grid || !fPS_Count) { ret = -1; goto finish; }
for (i = 0; i < ps_rows; i++) for (j = 0; j < ps_cols; j++) { fPS_Count[i*ps_cols*4+j*4] = 0; fPS_Grid[i*ps_cols*4+j*4] = 0; fPS_Grid[i*ps_cols*4+j*4+1] = 0; fPS_Grid[i*ps_cols*4+j*4+2] = 0; }
float_pixels_per_col = width / (float) ps_cols; float_pixels_per_row = height / (float) ps_rows; pixels_per_col = (short) float_pixels_per_col; pixels_per_row = (short) float_pixels_per_row;
pixels_border = pixels_per_col / 3; // ignore one third on each side pixels_per_col -= 2 * pixels_border; // effectively the pixels per col without the border pixels_per_row -= 2 * pixels_border; // effectively the pixels per row without the border pixels_per_square = (pixels_per_col - 1) * (pixels_per_row - 1);
i = 0; // this is the row counter do { ret = bm->GetNextScanLine (&scanline, &size);
srcPtr = (unsigned char*)scanline; srcPtr16 = (unsigned short*)scanline; for (j = 0; j < width; j++) { int row_index, col_index; int start_col_border, start_row_border; row_index = (int) MIN(ps_rows-1, (float)i / float_pixels_per_row); col_index = (int) MIN(ps_cols-1, (float)j / float_pixels_per_col); start_row_border = (int)( (float)row_index * float_pixels_per_row + (float)pixels_border); start_col_border = (int)( (float)col_index * float_pixels_per_col + (float)pixels_border);
// // If this pixel is in the inset square of a patch, process it by accumulating it's color value and // bumping the count for that patch. (Happens regardless of preview or real profile building). // if ((i > start_row_border) && (i < (start_row_border + pixels_per_row)) && (j > start_col_border) && (j < (start_col_border + pixels_per_col))) { // Accumulate the color value from the image // index = row_index*ps_cols*4+col_index*4; if (bits16) { fPS_Grid[row_index*ps_cols*4+col_index*4] += srcPtr16 [0]; fPS_Grid[row_index*ps_cols*4+col_index*4+1] += srcPtr16 [1]; fPS_Grid[row_index*ps_cols*4+col_index*4+2] += srcPtr16 [2]; } else { fPS_Grid[index] += srcPtr [0]; fPS_Grid[index+1] += srcPtr [1]; fPS_Grid[index+2] += srcPtr [2]; } fPS_Count[index] ++;
if (index == 0) { int r = (int)( fPS_Grid[index] / (float)fPS_Count[index]); int g = (int)( fPS_Grid[index+1] / (float)fPS_Count[index]); int b = (int)( fPS_Grid[index+2] / (float)fPS_Count[index]); } // check minimum and maximum } if (bits16) srcPtr16 += srcIncr; else srcPtr += srcIncr;
} i++; } while (ret == BITMAP_NOERR); bm->Close ();
for (i = 0; i < ps_rows; i++) for (j = 0; j < ps_cols; j++) { fPS_Grid[i*ps_cols*4+j*4] /= (float)fPS_Count[i*ps_cols*4+j*4]; fPS_Grid[i*ps_cols*4+j*4+1] /= (float)fPS_Count[i*ps_cols*4+j*4]; fPS_Grid[i*ps_cols*4+j*4+2] /= (float)fPS_Count[i*ps_cols*4+j*4]; if (bits16) { fPS_Grid[i*ps_cols*4+j*4] /= 256.0; fPS_Grid[i*ps_cols*4+j*4+1] /= 256.0; fPS_Grid[i*ps_cols*4+j*4+2] /= 256.0; } }
if(createScanProfile) { ret = CreateProfile(0); } else { ret = CreateProfile(1); }
finish:
return ret; }
|
|