Bug: getpixel setpixel - General Discussion and Assistance - CHDK Forum supplierdeeply

Bug: getpixel setpixel

  • 2 Replies
  • 2619 Views
Bug: getpixel setpixel
« on: 23 / August / 2009, 11:39:38 »
Advertisements
Hi,

I believe I found a bug in the getpixel/setpixel functions.

In core/raw.c: functions set_raw_pixel and get_raw_pixel

#if 0
 /* original code */
 unsigned char* addr=(unsigned char*)get_raw_image_addr()+y*RAW_ROWLEN+(x/8)*CAM_SENSOR_BITS_PER_PIXEL;
#else
 /* Put division second to avoid skipped pixels from order of precidence */
 unsigned char* addr=(unsigned char*)get_raw_image_addr()+y*RAW_ROWLEN+(x*CAM_SENSOR_BITS_PER_PIXEL)/8;
#endif

Currently, the code does division first -- truncating bits. Then it multiplies.
It should multiply first, then divide.

The change needs to be done in 4 places: 10-bit and 12-bit access for both set and get.

Doing this change increased my badpixel.bin file from 8K to 25K.

*

Offline ewavr

  • ****
  • 1057
  • A710IS
Re: Bug: getpixel setpixel
« Reply #1 on: 23 / August / 2009, 12:59:55 »
I believe I found a bug in the getpixel/setpixel functions.
unsigned char* addr=(unsigned char*)get_raw_image_addr()+y*RAW_ROWLEN+(x/8)*CAM_SENSOR_BITS_PER_PIXEL;
Currently, the code does division first -- truncating bits. Then it multiplies.
It should multiply first, then divide.

Low bits truncating is correct here - addr must be same for 8 pixels in row (for 10-bit raw).
Maybe for more readability we must replace in this function x/8 by x>>3 and x%8 by x&7  ;).
« Last Edit: 23 / August / 2009, 13:01:29 by ewavr »

*

Offline reyalp

  • ******
  • 14111
Re: Bug: getpixel setpixel
« Reply #2 on: 23 / August / 2009, 15:44:56 »
Maybe for more readability we must replace in this function x/8 by x>>3 and x%8 by x&7  ;).
Unless the compiler is already smart enough to do it, this should be faster too ;)
Don't forget what the H stands for.

 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal