|
|
| version 1.71, 2002/04/18 10:50:59 | version 1.75, 2002/08/15 09:07:48 |
|---|---|
| Line 3 | Line 3 |
| Copyright(c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) | Copyright(c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) |
| Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) | Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) |
| $Id$ | |
| */ | */ |
| static const char* IDENT_IMAGE_C="$Date$"; | |
| /* | /* |
| jpegsize: gets the width and height (in pixels) of a jpeg file | jpegsize: gets the width and height (in pixels) of a jpeg file |
| Andrew Tong, werdna@ugcs.caltech.edu February 14, 1995 | Andrew Tong, werdna@ugcs.caltech.edu February 14, 1995 |
| Line 79 private: | Line 79 private: |
| }; | }; |
| #endif | #endif |
| /// PNG file header | |
| struct PNG_Header { | |
| char dummy[12]; | |
| char signature[4]; //< must be "IHDR" | |
| unsigned char high_width[2]; //< image width high bytes [we ignore for now] | |
| unsigned char width[2]; //< image width low bytes | |
| unsigned char high_height[2]; //< image height high bytes [we ignore for now] | |
| unsigned char height[4]; //< image height | |
| }; | |
| /// GIF file header | /// GIF file header |
| struct GIF_Header { | struct GIF_Header { |
| char type[3]; // 'GIF' | char signature[3]; // 'GIF' |
| char version[3]; | char version[3]; |
| unsigned char width[2]; | unsigned char width[2]; |
| unsigned char height[2]; | unsigned char height[2]; |
| Line 129 void measure_gif(Pool& pool, const Strin | Line 139 void measure_gif(Pool& pool, const Strin |
| "not GIF file - too small"); | "not GIF file - too small"); |
| GIF_Header *head=(GIF_Header *)buf; | GIF_Header *head=(GIF_Header *)buf; |
| if(strncmp(head->type, "GIF", 3)!=0) | if(strncmp(head->signature, "GIF", 3)!=0) |
| throw Exception("image.format", | throw Exception("image.format", |
| origin_string, | origin_string, |
| "not GIF file - wrong signature"); | "not GIF file - wrong signature"); |
| Line 195 void measure_jpeg(Pool& pool, const Stri | Line 205 void measure_jpeg(Pool& pool, const Stri |
| "broken JPEG file - size frame not found"); | "broken JPEG file - size frame not found"); |
| } | } |
| void measure_png(Pool& pool, const String *origin_string, | |
| Measure_reader& reader, int& width, int& height) { | |
| void *buf; | |
| const int head_size=sizeof(PNG_Header); | |
| if(reader.read(buf, head_size)<head_size) | |
| throw Exception("image.format", | |
| origin_string, | |
| "not PNG file - too small"); | |
| PNG_Header *head=(PNG_Header *)buf; | |
| if(strncmp(head->signature, "IHDR", 4)!=0) | |
| throw Exception("image.format", | |
| origin_string, | |
| "not PNG file - wrong signature"); | |
| width=big_endian_to_int(head->width); | |
| height=big_endian_to_int(head->height); | |
| } | |
| // measure center | // measure center |
| void measure(Pool& pool, const String& file_name, | void measure(Pool& pool, const String& file_name, |
| Line 205 void measure(Pool& pool, const String& f | Line 235 void measure(Pool& pool, const String& f |
| measure_gif(pool, &file_name, reader, width, height); | measure_gif(pool, &file_name, reader, width, height); |
| else if(strcasecmp(cext, "JPG")==0 || strcasecmp(cext, "JPEG")==0) | else if(strcasecmp(cext, "JPG")==0 || strcasecmp(cext, "JPEG")==0) |
| measure_jpeg(pool, &file_name, reader, width, height); | measure_jpeg(pool, &file_name, reader, width, height); |
| else if(strcasecmp(cext, "PNG")==0) | |
| measure_png(pool, &file_name, reader, width, height); | |
| else | else |
| throw Exception("image.format", | throw Exception("image.format", |
| &file_name, | &file_name, |
| Line 760 static void _circle(Request& r, const St | Line 792 static void _circle(Request& r, const St |
| gdImage& as_image(Pool& pool, const String& method_name, MethodParams *params, | gdImage& as_image(Pool& pool, const String& method_name, MethodParams *params, |
| int index, const char *msg) { | int index, const char *msg) { |
| Value& value=params->as_no_junction(index, msg); | gdImage *src=0; |
| if(strcmp(value.type(), VIMAGE_TYPE)!=0) | Value& value=params->as_no_junction(index, msg); |
| throw Exception("parser.runtime", | |
| &method_name, | |
| msg); | |
| gdImage *src=static_cast<VImage *>(&value)->image; | if(Value *vimage=value.as(VIMAGE_TYPE, false)) { |
| if(!src) | src=static_cast<VImage *>(vimage)->image; |
| if(!src) | |
| throw Exception("parser.runtime", | |
| &method_name, | |
| msg); | |
| } else | |
| throw Exception("parser.runtime", | throw Exception("parser.runtime", |
| &method_name, | &method_name, |
| msg); | msg); |