--- parser3/src/classes/image.C 2001/08/27 15:47:13 1.32 +++ parser3/src/classes/image.C 2001/08/28 14:43:07 1.34 @@ -5,9 +5,9 @@ Author: Alexander Petrosyan (http://design.ru/paf) - $Id: image.C,v 1.32 2001/08/27 15:47:13 parser Exp $ + $Id: image.C,v 1.34 2001/08/28 14:43:07 parser Exp $ */ -static const char *RCSId="$Id: image.C,v 1.32 2001/08/27 15:47:13 parser Exp $"; +static const char *RCSId="$Id: image.C,v 1.34 2001/08/28 14:43:07 parser Exp $"; /* jpegsize: gets the width and height (in pixels) of a jpeg file @@ -111,8 +111,16 @@ struct JPG_Size_segment_body { // -inline short big_endian_to_int(unsigned char chars[2]) { - return(short)((chars[0]<<8) + chars[1]); +inline short x_endian_to_int(unsigned char L, unsigned char H) { + return(short)((H<<8) + L); +} + +inline short big_endian_to_int(unsigned char b[2]) { + return x_endian_to_int(b[1], b[0]); +} + +inline short little_endian_to_int(unsigned char b[2]) { + return x_endian_to_int(b[0], b[1]); } void measure_gif(Pool& pool, const String *origin_string, @@ -123,37 +131,37 @@ void measure_gif(Pool& pool, const Strin if(reader.read(buf, head_size)type, "GIF", 3)!=0) PTHROW(0, 0, origin_string, - "bad image file - GIF signature not found"); + "not GIF file - signature not found"); - width=big_endian_to_int(head->width); - height=big_endian_to_int(head->height); + width=little_endian_to_int(head->width); + height=little_endian_to_int(head->height); } void measure_jpeg(Pool& pool, const String *origin_string, Measure_reader& reader, int& width, int& height) { // JFIF format markers const unsigned char MARKER=0xFF; - const unsigned char SIZE_FIRST=0xC0; - const unsigned char SIZE_LAST=0xC3; + const unsigned char CODE_SIZE_FIRST=0xC0; + const unsigned char CODE_SIZE_LAST=0xC3; void *buf; const size_t prefix_size=2; if(reader.read(buf, prefix_size)marker!=MARKER) break; - if(head->code >= SIZE_FIRST && head->code <= SIZE_LAST) { + if(head->code >= CODE_SIZE_FIRST && head->code <= CODE_SIZE_LAST) { // Segments that contain size info if(reader.read(buf, sizeof(JPG_Size_segment_body))