Re: strange trouble in displaying a 8bit monochromy grey scale image



On 6/2/06, heavenscape <masonduan1 sina com> wrote:
char* pDisplayBuf = malloc(sizeX*sizeY*3);
for(i=0;i<sizeX*sizeY;i++)
        {
        //create a gray scale img in the display buffer
                pDisplayBuf[i+1]=pDisplayBuf[i+1]=pDisplayBuf[i+2] = pixel_value;
        }

This isn't going to work. You're only filling the first third of the
memory area.

How about (untested):

// malloc() can return NULL: you need to test the result
// g_malloc() cannot fail
char *p = g_malloc(sizeX * sizeY * 3);
char *q;
int i;

// i loops for number of pixels
// q loops pointing at each RGB triplet in turn
for (q = p, i = 0; i < sizeX * sizeY; i++, q += 3)
 q[0] = q[1] = q[2] = pixel_value;

// or alternatively in this special case
memset( p, sizeX * sizeY * 3, pixel_value )



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]