Index: ChangeLog =================================================================== RCS file: /cvsroot/xforms/xforms/ChangeLog,v retrieving revision 1.66 diff -u -p -r1.66 ChangeLog --- ChangeLog 24 Nov 2003 19:21:42 -0000 1.66 +++ ChangeLog 25 Nov 2003 20:59:30 -0000 @@ -1,3 +1,14 @@ +2003-11-25 Clive A Stubbings + + * image/image_gif.c (flush_buffer): new static function, containig ] + code factored out of process_lzw_code. + (process_lzw_code): invoke flush_buffer where old code was in + process_lzw_code itself. In addition, also invoke flush_buffer + when cleaning up after an old-style gif image. + + * image/image_jpeg.c (JPEG_identify): handle 'raw' JPEG images + without the JFIF header. + 2003-11-24 Angus Leeming * fdesign/sp_menu.c (emit_menu_header): output properly initialized Index: image/image_gif.c =================================================================== RCS file: /cvsroot/xforms/xforms/image/image_gif.c,v retrieving revision 1.5 diff -u -p -r1.5 image_gif.c --- image/image_gif.c 21 Nov 2003 13:23:23 -0000 1.5 +++ image/image_gif.c 25 Nov 2003 20:59:34 -0000 @@ -585,10 +585,35 @@ GIF_load(FL_IMAGE * im) #define OUTPIX(c) *lbuf++ = (c) #define MC_SIZE 4097 +/* if we've got more than one scanline, output */ +static void flush_buffer(FL_IMAGE * im, int incode) +{ + int i; + + incode = lbuf - lhead; + if (incode >= im->w) + { + lbuf = lhead; + + while (incode >= im->w) + { + outputline(im, lbuf); + incode -= im->w; + lbuf += im->w; + } + + /* copy the left over */ + for (i = 0; i < incode; i++) + lhead[i] = *lbuf++; + lbuf = lhead + incode; + } +} + + static int process_lzw_code(FL_IMAGE * im, register int code) { - register int incode, i; + register int incode; static unsigned char firstchar; static unsigned char stack[MC_SIZE]; static int avail, oldcode; @@ -637,6 +662,14 @@ process_lzw_code(FL_IMAGE * im, register { OUTPIX(suffix[code]); firstchar = oldcode = code; + /* Clive Stubbings. + * There is the posibility of an image with just alternate + * single code bytes and resets. I know thats really dumb, + * but I found one and it took a long time to work out why + * it crashed... + * So flush the buffer before it overuns. + */ + flush_buffer(im, incode); return 0; } @@ -676,23 +709,7 @@ process_lzw_code(FL_IMAGE * im, register while (stackp > stack); /* if we've got more than one scanline, output */ - incode = lbuf - lhead; - if (incode >= im->w) - { - lbuf = lhead; - - while (incode >= im->w) - { - outputline(im, lbuf); - incode -= im->w; - lbuf += im->w; - } - - /* copy the left over */ - for (i = 0; i < incode; i++) - lhead[i] = *lbuf++; - lbuf = lhead + incode; - } + flush_buffer(im, incode); return 0; } Index: image/image_jpeg.c =================================================================== RCS file: /cvsroot/xforms/xforms/image/image_jpeg.c,v retrieving revision 1.5 diff -u -p -r1.5 image_jpeg.c --- image/image_jpeg.c 21 Nov 2003 13:23:23 -0000 1.5 +++ image/image_jpeg.c 25 Nov 2003 20:59:34 -0000 @@ -68,12 +68,23 @@ static unsigned int jpeg_getc(j_decompre static int JPEG_identify(FILE * fp) { - char buf[128]; + unsigned char buf[128]; size_t i; fread(buf, 1, sizeof(buf), fp); rewind(fp); buf[sizeof(buf) - 1] = '\0'; + + /* Clive Stubbings. + * Test for a JPEG SOI code (0xff, 0xd8) followed by the start of + * APP0 segement (0xff). + * A 'raw' JPEG will not have the JFIF (JPEG file interchange format) + * header but is still readable + */ + if (buf[0] == (unsigned char)0xff && + buf[1] == (unsigned char)0xd8 && + buf[2] == (unsigned char)0xff) + return 1; for (i = 0; i < sizeof(buf) - 3 && buf[i] != 'J'; i++) ;