@@ -63,7 +63,7 @@ int iNumOfCtrl = NOT_SET; // Number of camera control capabilities
63
63
pthread_t threadDisplay = 0 ;
64
64
pthread_t hthdSave = 0 ;
65
65
int numExposures = 0 ; // how many valid pictures have we taken so far?
66
- int currentBpp = NOT_SET; // bytes per pixel: 8, 16 , or 24
66
+ int currentBpp = NOT_SET; // bytes per pixel: 1, 2 , or 3
67
67
68
68
// Make sure we don't try to update a non-updateable control, and check for errors.
69
69
ASI_ERROR_CODE setControl (int camNum, ASI_CONTROL_TYPE control, long value, ASI_BOOL makeAuto)
@@ -264,20 +264,21 @@ int computeHistogram(unsigned char *imageBuffer, config cg, bool useHistogramBox
264
264
// For RGB24, data for each pixel is stored in 3 consecutive bytes: blue, green, red.
265
265
// For all image types, each row in the image contains one row of pixels.
266
266
// currentBpp doesn't apply to rows, just columns.
267
+ // x int on = 0;
268
+ // x static int did = 0; did++;
267
269
switch (cg.imageType ) {
268
270
case IMG_RGB24:
269
271
case IMG_RAW8:
270
272
case IMG_Y8:
271
273
for (int y = roiY1; y < roiY2; y++) {
272
- for (int x = roiX1; x < roiX2; x+= currentBpp) {
274
+ for (int x = roiX1; x < roiX2; x += currentBpp) {
273
275
int i = (cg.width * y) + x;
274
- int total = 0 ;
275
- for (int z = 0 ; z < currentBpp; z++)
276
- {
276
+ int avg = buf[i];
277
+ if (cg.imageType == IMG_RGB24) {
277
278
// For RGB24 this averages the blue, green, and red pixels.
278
- total += buf[i+z ];
279
+ avg += buf[i+1 ] + buf[i+ 2 ];
279
280
}
280
- int avg = total / currentBpp;
281
+ // x if (useHistogramBox && did <=5) { printf("avg[%d]=%d\n", ++on, avg); }
281
282
histogram[avg]++;
282
283
}
283
284
}
@@ -288,11 +289,9 @@ int computeHistogram(unsigned char *imageBuffer, config cg, bool useHistogramBox
288
289
int i = (cg.width * y) + x;
289
290
int pixelValue;
290
291
// This assumes the image data is laid out in big endian format.
291
- // We are going to grab the most significant byte
292
- // and use that for the histogram value ignoring the
293
- // least significant byte so we can use the 256 value histogram array.
294
- // If it's acutally little endian then add a +1 to the array subscript for buf[i].
295
- pixelValue = buf[i];
292
+ // Use the least significant byte.
293
+ pixelValue = buf[i+1 ];
294
+ // x if (useHistogramBox && did <=5) { printf("pixel[%d]=0x%02x%02x, pixelValue=%'d\n", ++on, buf[i], buf[i+1], pixelValue); }
296
295
histogram[pixelValue]++;
297
296
}
298
297
}
@@ -307,6 +306,7 @@ int computeHistogram(unsigned char *imageBuffer, config cg, bool useHistogramBox
307
306
for (int i = 0 ; i < 256 ; i++) {
308
307
a += (i+1 ) * histogram[i];
309
308
b += histogram[i];
309
+ // x if (useHistogramBox && histogram[i] > 0 && did <=5) { printf("histogram[%d]=%'d, a=%'d, b=%'d\n", i, histogram[i], a, b); }
310
310
}
311
311
312
312
if (b == 0 )
0 commit comments