Skip to content

Commit 9c4a688

Browse files
authored
Update capture_ZWO.cpp: fix RAW16 mean calculation
Fixes #3187
1 parent dbdd504 commit 9c4a688

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/capture_ZWO.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ int iNumOfCtrl = NOT_SET; // Number of camera control capabilities
6363
pthread_t threadDisplay = 0;
6464
pthread_t hthdSave = 0;
6565
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
6767

6868
// Make sure we don't try to update a non-updateable control, and check for errors.
6969
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
264264
// For RGB24, data for each pixel is stored in 3 consecutive bytes: blue, green, red.
265265
// For all image types, each row in the image contains one row of pixels.
266266
// currentBpp doesn't apply to rows, just columns.
267+
//x int on = 0;
268+
//x static int did = 0; did++;
267269
switch (cg.imageType) {
268270
case IMG_RGB24:
269271
case IMG_RAW8:
270272
case IMG_Y8:
271273
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) {
273275
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) {
277278
// For RGB24 this averages the blue, green, and red pixels.
278-
total += buf[i+z];
279+
avg += buf[i+1] + buf[i+2];
279280
}
280-
int avg = total / currentBpp;
281+
//x if (useHistogramBox && did <=5) { printf("avg[%d]=%d\n", ++on, avg); }
281282
histogram[avg]++;
282283
}
283284
}
@@ -288,11 +289,9 @@ int computeHistogram(unsigned char *imageBuffer, config cg, bool useHistogramBox
288289
int i = (cg.width * y) + x;
289290
int pixelValue;
290291
// 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); }
296295
histogram[pixelValue]++;
297296
}
298297
}
@@ -307,6 +306,7 @@ int computeHistogram(unsigned char *imageBuffer, config cg, bool useHistogramBox
307306
for (int i = 0; i < 256; i++) {
308307
a += (i+1) * histogram[i];
309308
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); }
310310
}
311311

312312
if (b == 0)

0 commit comments

Comments
 (0)