X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2F3dengfx%2Fsrc%2Fgfx%2Fimage_jpg.c;fp=src%2F3dengfx%2Fsrc%2Fgfx%2Fimage_jpg.c;h=02e7ab2cee79453aa5da0a6d3a8448f61e9604a1;hb=6e23259dbabaeb1711a2a5ca25b9cb421f693759;hp=0000000000000000000000000000000000000000;hpb=fe068fa879814784c45e0cb2e65dac489e8f5594;p=summerhack diff --git a/src/3dengfx/src/gfx/image_jpg.c b/src/3dengfx/src/gfx/image_jpg.c new file mode 100644 index 0000000..02e7ab2 --- /dev/null +++ b/src/3dengfx/src/gfx/image_jpg.c @@ -0,0 +1,130 @@ +/* +Copyright 2004 John Tsiombikas + +This is a small image library. + +This library is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* jpeg support + * + * author: Mihalis Georgoulopoulos 2004 + * modified: John Tsiombikas 2004 + */ + +#include "3dengfx_config.h" +#include "image.h" +#include + +#ifdef IMGLIB_USE_JPEG + +#include + +#ifdef WIN32 +#include +#define HAVE_BOOLEAN +#endif + +#include +#include "color_bits.h" + +typedef struct +{ + unsigned char r,g,b; +} RGBTriplet; + +/*jpeg signature*/ +int check_jpeg(FILE *fp){ + unsigned char sig[10]; + + fseek(fp, 0, SEEK_SET); + fread(sig, 1, 10, fp); + + if(sig[0]!=0xff || sig[1]!=0xd8 || sig[2]!=0xff || sig[3]!=0xe0) { + return 0; + } + + if(/*sig[6]!='J' ||*/sig[7]!='F' || sig[8]!='I' || sig[9]!='F') { + return 0; + } + + return 1; +} + +void *load_jpeg(FILE *fp, unsigned long *xsz, unsigned long *ysz) { + int i; + RGBTriplet *buffer; + uint32_t *image; + + JSAMPLE *tmp; + + struct jpeg_decompress_struct cinfo; + struct jpeg_error_mgr jerr; + cinfo.err = jpeg_std_error(&jerr); + + fseek(fp, 0, SEEK_SET); + + jpeg_create_decompress(&cinfo); + jpeg_stdio_src(&cinfo, fp); + + jpeg_read_header(&cinfo, TRUE); + + /* force output to rgb */ + cinfo.out_color_space = JCS_RGB; + + /* allocate space */ + buffer = malloc(cinfo.image_width * sizeof(RGBTriplet)); + if (!buffer) return 0; + image = malloc(cinfo.image_width * (cinfo.image_height) * sizeof(uint32_t)); + if (!image) return 0; + + tmp = (JSAMPLE*) buffer; + + /* return w and h */ + *xsz = cinfo.image_width; + *ysz = cinfo.image_height; + + /* Decompress, pack and store */ + jpeg_start_decompress(&cinfo); + { + while (cinfo.output_scanline < cinfo.output_height) + { + jpeg_read_scanlines(&cinfo, &tmp, 1); + if (cinfo.output_scanline == 0) continue; + + for (i=0;i