Re: using libjpeg
- From: Edward Rosten <Edward.Rosten@xxxxxxxxx>
- Date: Thu, 31 Jan 2008 09:39:16 -0800 (PST)
On Jan 31, 9:57 am, oswald.ha...@xxxxxxxxx wrote:
/* allocate data and read the image as RGBRGBRGBRGB */
image = malloc(cinfo.output_width * cinfo.output_height * 3);
for(int i=0; i < cinfo.output_height; i++)
{
unsigned char * ptr = image + i * 3 * cinfo.output_width;
jpeg_read_scanlines(&cinfo, &ptr, 1);
}
thanx for the code snippet,it helped me to take my first tentative
steps in c coding with this library..also i did
int colorcomponents;
colorcomponents=cinfo.output_width*cinfo.output_height*3;
That's OK. Remember that geryscale JPEGs exist, so at some point you
might want to make your code robust to that.
this lets me iterate over array like
for(i=0;i<numcolorcomponents;i++)
printf("%d\n",image[i]);
i learned that each set of 3 integers correspond to the rgb of each
pixel ..
i am thinking of packing the rgb into a single value(integer) ie
pixel with (155,147,145) => -6581359
You probably want an unsigned integer, not a signed one. If you have a
c99 compiler (you probably do), then you want to include stdint.h and
use something like uint32_t.
for this i use
int packedvalue=(255 << 24) | ((r & 0xff) << 16)|((g & 0xff) << 8)|(b
& 0xff);
this will be a long int..
is there something wrong with the way this is done..? as a beginner i
wd gratefully appreciate your views/comments/advice
It looks OK, except that the result will be unsigned, so you'll want
an unsigned int. For what it's worth, on a little endian machine (ie
x86), you're reversing the ordering of R, G and B in memory.
What are you trying to achieve, by the way?
-Ed
.
- References:
- using libjpeg
- From: oswald . harry
- Re: using libjpeg
- From: Edward Rosten
- Re: using libjpeg
- From: oswald . harry
- using libjpeg
- Prev by Date: Re: using libjpeg
- Next by Date: Re: Why I can not truncate a file with Posix 1990 ?
- Previous by thread: Re: using libjpeg
- Next by thread: Re: using libjpeg
- Index(es):
Relevant Pages
|
|