Opening JPEG images.
I have been given a project that includes a .rpc file. In the file is information about a JPEG image and the image itself. I can open this file and get all kinds of information about the image but I don''t know how to display the JPEG image itself. Please help, I have been working on this for over a month.
Axel
libjpeg from http://www.ijg.org/ will let you do what you want in a couple of function calls. I was messing around with it trying to get it to dump the rendering window, and it works really well. I think I will try and modify lesson 6 to read the texture from a jpeg, and post the results if I get it to work.
Rohar,
When you modify what lesson 6 to work with JPEG can you forward me the changes in the code.
Axel
When you modify what lesson 6 to work with JPEG can you forward me the changes in the code.
Axel
this will prettymuch drop in for loadBMP, and load the texture from a jpeg. It works, but I didn't put alot of time into error checking, I will when I get a chance. There is a whack of info returned from the libjpeg library, which should be error checked for correctness....
You need to link with libjpeg.lib & have the headers. (I built my own libjpeg library from the source @ http://www.ijg.org/ for vc on win98, but it also works on my RH6.2 box with the included libjpeg library)
Make sure you use a 256x256x24 RGB JFIF jpeg... and you should be okey-dokey. (I just converted the NeHe bmp to a jpeg with no changes)
The dumb-assed looking math where I am swapping the buffer is because the image loads upside down. The row pointer array is because libjpeg needs a pointer array, and can return more than 1 line at a time... When I understand the library better, I think that the temp buffer can get turfed, and more than 1 line can be processed at a time. (array of pointers to the output buffer, and change them with each call to jpeg_read_scanlines)
The docs that come with libjpeg are pretty good.
If you don't mind... don't pick on my code, I did this from scratch in an hour and it even works
you'll need to wrap extern "C" { } around the c includes for vc
Edited by - rohar on November 1, 2000 7:48:28 PM
You need to link with libjpeg.lib & have the headers. (I built my own libjpeg library from the source @ http://www.ijg.org/ for vc on win98, but it also works on my RH6.2 box with the included libjpeg library)
Make sure you use a 256x256x24 RGB JFIF jpeg... and you should be okey-dokey. (I just converted the NeHe bmp to a jpeg with no changes)
The dumb-assed looking math where I am swapping the buffer is because the image loads upside down. The row pointer array is because libjpeg needs a pointer array, and can return more than 1 line at a time... When I understand the library better, I think that the temp buffer can get turfed, and more than 1 line can be processed at a time. (array of pointers to the output buffer, and change them with each call to jpeg_read_scanlines)
The docs that come with libjpeg are pretty good.
If you don't mind... don't pick on my code, I did this from scratch in an hour and it even works
you'll need to wrap extern "C" { } around the c includes for vc
#include <jpeglib.h>#include <jerror.h>/* simple loader for 24bit jpeg (data is in rgb-format) */int LoadJPEG(char *filename, textureImage *texture){ FILE *file; struct jpeg_decompress_struct cinfo; struct jpeg_error_mgr jerr; volatile JSAMPROW row = 0; JSAMPROW rowptr[1]; int i,j,nrows; cinfo.err = jpeg_std_error(&jerr); jpeg_create_decompress(&cinfo); /* make sure the file is there and open it read-only (binary) */ if ((file = fopen(filename, "rb")) == NULL) { printf("File not found : %s\n", filename); return 0; } jpeg_stdio_src(&cinfo, file); jpeg_read_header(&cinfo, TRUE); jpeg_start_decompress(&cinfo); texture->width = cinfo.output_width; texture->height = cinfo.output_height; printf("Colorspace %d\n",cinfo.jpeg_color_space); row = (JSAMPROW)calloc(1,cinfo.image_width * cinfo.output_components * sizeof(JSAMPLE)); texture->data = malloc(cinfo.image_width * cinfo.image_height * cinfo.output_components * sizeof(JSAMPLE)); rowptr[0] = row; for (i = 0; i < cinfo.output_height; i++) { nrows = jpeg_read_scanlines(&cinfo, rowptr, 1); if (nrows != 1) { fprintf(stderr, "jpeg_read_scanlines" " returns %u, expected 1\n", nrows); return 0; } for (j = 0; j < cinfo.output_width*cinfo.output_components; j++) texture->data[(cinfo.output_height-1-i)*cinfo.output_width*cinfo.output_components+j] = row[j]; } jpeg_finish_decompress(&cinfo); jpeg_destroy_decompress(&cinfo); free(row); return 1;}
Edited by - rohar on November 1, 2000 7:48:28 PM
rohar -> Thanks for your code...
But I couldn''t compile it... I done something wrong when I used it. The linker give me this messages:
"void __cdecl jpeg_destroy_decompress(struct jpeg_decompress_struct *)" (?jpeg_destroy_decompress@@YAXPAUjpeg_decompress_struct@@@Z)
"unsigned char __cdecl jpeg_finish_decompress(struct jpeg_decompress_struct *)" (?jpeg_finish_decompress@@YAEPAUjpeg_decompress_struct@@@Z)
"unsigned int __cdecl jpeg_read_scanlines(struct jpeg_decompress_struct *,unsigned char * *,unsigned int)" (?jpeg_read_scanlines@@YAIPAUjpeg_decompress_struct@@PAPAEI@Z)
"unsigned char __cdecl jpeg_start_decompress(struct jpeg_decompress_struct *)" (?jpeg_start_decompress@@YAEPAUjpeg_decompress_struct@@@Z)
"int __cdecl jpeg_read_header(struct jpeg_decompress_struct *,unsigned char)" (?jpeg_read_header@@YAHPAUjpeg_decompress_struct@@E@Z)
"void __cdecl jpeg_stdio_src(struct jpeg_decompress_struct *,struct _iobuf *)" (?jpeg_stdio_src@@YAXPAUjpeg_decompress_struct@@PAU_iobuf@@@Z)
"void __cdecl jpeg_CreateDecompress(struct jpeg_decompress_struct *,int,unsigned int)" (?jpeg_CreateDecompress@@YAXPAUjpeg_decompress_struct@@HI@Z)
"struct jpeg_error_mgr * __cdecl jpeg_std_error(struct jpeg_error_mgr *)" (?jpeg_std_error@@YAPAUjpeg_error_mgr@@PAU1@@Z)
Or short, the linker couldn''t find the stuff.
I used the Libjpeg.lib (wrong version??) but the linker couldn''t find the stuff.
Can you help me to solve this ''little'' problem?
Thanks
But I couldn''t compile it... I done something wrong when I used it. The linker give me this messages:
"void __cdecl jpeg_destroy_decompress(struct jpeg_decompress_struct *)" (?jpeg_destroy_decompress@@YAXPAUjpeg_decompress_struct@@@Z)
"unsigned char __cdecl jpeg_finish_decompress(struct jpeg_decompress_struct *)" (?jpeg_finish_decompress@@YAEPAUjpeg_decompress_struct@@@Z)
"unsigned int __cdecl jpeg_read_scanlines(struct jpeg_decompress_struct *,unsigned char * *,unsigned int)" (?jpeg_read_scanlines@@YAIPAUjpeg_decompress_struct@@PAPAEI@Z)
"unsigned char __cdecl jpeg_start_decompress(struct jpeg_decompress_struct *)" (?jpeg_start_decompress@@YAEPAUjpeg_decompress_struct@@@Z)
"int __cdecl jpeg_read_header(struct jpeg_decompress_struct *,unsigned char)" (?jpeg_read_header@@YAHPAUjpeg_decompress_struct@@E@Z)
"void __cdecl jpeg_stdio_src(struct jpeg_decompress_struct *,struct _iobuf *)" (?jpeg_stdio_src@@YAXPAUjpeg_decompress_struct@@PAU_iobuf@@@Z)
"void __cdecl jpeg_CreateDecompress(struct jpeg_decompress_struct *,int,unsigned int)" (?jpeg_CreateDecompress@@YAXPAUjpeg_decompress_struct@@HI@Z)
"struct jpeg_error_mgr * __cdecl jpeg_std_error(struct jpeg_error_mgr *)" (?jpeg_std_error@@YAPAUjpeg_error_mgr@@PAU1@@Z)
Or short, the linker couldn''t find the stuff.
I used the Libjpeg.lib (wrong version??) but the linker couldn''t find the stuff.
Can you help me to solve this ''little'' problem?
Thanks
The library is compiled without a extern "C" {...} when linked into c++.
You need to wrap extern "C" around the includes when you compile & link with vc++.
This should really be in the jpeglib.h, but it isn't.
Edited by - rohar on November 6, 2000 9:23:39 PM
You need to wrap extern "C" around the includes when you compile & link with vc++.
extern "C"{#include <jpeglib.h>#include <jerror.h>}
This should really be in the jpeglib.h, but it isn't.
Edited by - rohar on November 6, 2000 9:23:39 PM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement