--- parser3/src/classes/image.C 2001/08/27 15:17:15 1.31 +++ parser3/src/classes/image.C 2001/08/28 14:39:50 1.33 @@ -5,9 +5,9 @@ Author: Alexander Petrosyan (http://design.ru/paf) - $Id: image.C,v 1.31 2001/08/27 15:17:15 parser Exp $ + $Id: image.C,v 1.33 2001/08/28 14:39:50 parser Exp $ */ -static const char *RCSId="$Id: image.C,v 1.31 2001/08/27 15:17:15 parser Exp $"; +static const char *RCSId="$Id: image.C,v 1.33 2001/08/28 14:39:50 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 bytes_to_int(unsigned char chars[2]) { - return(short)((chars[1]<<8) + chars[0]); +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, @@ -131,8 +139,8 @@ void measure_gif(Pool& pool, const Strin origin_string, "bad image file - GIF signature not found"); - width=bytes_to_int(head->width); - height=bytes_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, @@ -173,13 +181,13 @@ void measure_jpeg(Pool& pool, const Stri break; JPG_Size_segment_body *body=(JPG_Size_segment_body *)buf; - width=bytes_to_int(body->width); - height=bytes_to_int(body->height); + width=big_endian_to_int(body->width); + height=big_endian_to_int(body->height); found=true; break; } else { // Dummy read to skip over data - size_t limit=bytes_to_int(head->length) - 2; + size_t limit=big_endian_to_int(head->length) - 2; if(reader.read(buf, limit)