Re: using libjpeg



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



.



Relevant Pages

  • Re: dilation
    ... one pixel off, and I had array index out of bound errors). ... int foreground = 255; ... //create binary image from the input image ... //foreground, i set it to foreground value and exit for cycle. ...
    (sci.image.processing)
  • Malloc code
    ... set up some data in a strucuture called GMM. ... struct GMM{ ... will be displayed starting at pixel. ... int SETWINEXTHORZ_MSB, ...
    (microsoft.public.vc.language)
  • Re: Back to getting pixel RGBColor values from a pixmap
    ... >> RGBColor getpixel(GWorldPtr Source, int H, int V) ... > you can have a 16x16 pixel GWorld with topleft at. ...
    (comp.sys.mac.programmer.help)
  • Re: Problems with BufferedImage and ColorModel
    ... > I've been experimenting with BufferedImage and am attempting to extract the ... > individual R, G, B, and Alpha values from the color of each pixel in an image. ... > I pass that value to the getRedmethod of the ColorModel I get from ... is coded into the int value returned from getRGB. ...
    (comp.lang.java.help)
  • Re: Saving three 16 bit RGB values in 32 bits::
    ... course you can do a conversion like this. ... digits containing data. ... Converting this back to RGB, gives the correct 'R' value, a green value of 32900, but complete loss of the blue data. ... double Utility::RGB_ToDBL(int R, int G, int B) * ...
    (sci.image.processing)