Re: using libjpeg
- From: Edward Rosten <Edward.Rosten@xxxxxxxxx>
- Date: Wed, 30 Jan 2008 15:08:30 -0800 (PST)
On Jan 30, 6:47 am, oswald.ha...@xxxxxxxxx wrote:
hi
I have a char* imgnames[] that contain full path names of jpg files
(ie like "F:\myimgs\jpg\one.jpg",... etc) .I wish to read each
corresponding .jpg file and extract info into a struct ..and thus
create an array of structures.in each struct i would like to store
imgname,width,height,and value of each pixel(as a long?).
This should get you started. It uses libjpeg to read pixels from a
jpeg image. It reads from stdin, so use fopen() if you want to read
from a different file. The data is read in to image as RGBRGBRGB,
assuming the image is an RGB jpeg. It should be straightforward to
modify this to your needs.
#include <stdio.h>
#include <jpeglib.h>
#include <stdlib.h>
int main()
{
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
unsigned char *image;
/*Initialize, open the JPEG and query the parameters */
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo);
jpeg_stdio_src(&cinfo, stdin);
jpeg_read_header(&cinfo, TRUE);
jpeg_start_decompress(&cinfo);
/* 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);
}
/*Write a PPM */
printf("P6\n%i %i 255\n", cinfo.output_width, cinfo.output_height);
fwrite(image, 1, cinfo.output_width * cinfo.output_height * 3,
stdout);
return 0;
}
-Ed
--
(You can't go wrong with psycho-rats.)(http://mi.eng.cam.ac.uk/~er258)
/d{def}def/f{/Times s selectfont}d/s{11}d/r{roll}d f 2/m{moveto}d -1
r 230 350 m 0 1 179{ 1 index show 88 rotate 4 mul 0 rmoveto}for/s 12
d f pop 235 420 translate 0 0 moveto 1 2 scale show showpage
.
- Follow-Ups:
- Re: using libjpeg
- From: oswald . harry
- Re: using libjpeg
- References:
- using libjpeg
- From: oswald . harry
- using libjpeg
- Prev by Date: Re: Array bound read : pthread_exit
- Next by Date: Getting user input in Linux?
- Previous by thread: Re: using libjpeg
- Next by thread: Re: using libjpeg
- Index(es):
Relevant Pages
|