|
|
| version 1.97, 2003/11/07 13:59:21 | version 1.112, 2005/07/28 11:23:01 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: @b image parser class. | Parser: @b image parser class. |
| Copyright(c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com) | Copyright(c) 2001-2004 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) |
| */ | */ |
| static const char* IDENT_IMAGE_C="$Date$"; | static const char * const 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 |
| Line 33 static const char* IDENT_IMAGE_C="$Date$ | Line 33 static const char* IDENT_IMAGE_C="$Date$ |
| class MImage: public Methoded { | class MImage: public Methoded { |
| public: // VStateless_class | public: // VStateless_class |
| Value* create_new_value(Pool& apool) { return new VImage(); } | Value* create_new_value(Pool&, HashStringValue&) { return new VImage(); } |
| public: | public: |
| MImage(); | MImage(); |
| Line 161 public: | Line 161 public: |
| }; | }; |
| class Measure_file_reader: public Measure_reader { | class Measure_file_reader: public Measure_reader { |
| ; | |
| const String& file_name; const char* fname; | const String& file_name; const char* fname; |
| int f; | int f; |
| Line 180 public: | Line 178 public: |
| if(ssize_t(read_size)<0 || read_size>limit) | if(ssize_t(read_size)<0 || read_size>limit) |
| throw Exception(0, | throw Exception(0, |
| &file_name, | &file_name, |
| "measure failed: actually read %lu bytes count not in [0..%lu] valid range", | "measure failed: actually read %u bytes count not in [0..%u] valid range", |
| read_size, limit); | read_size, limit); |
| return read_size; | return read_size; |
| Line 331 static void measure_gif(const String& or | Line 329 static void measure_gif(const String& or |
| Measure_reader& reader, ushort& width, ushort& height) { | Measure_reader& reader, ushort& width, ushort& height) { |
| const char* buf; | const char* buf; |
| const int head_size=sizeof(GIF_Header); | const size_t head_size=sizeof(GIF_Header); |
| if(reader.read(buf, head_size)<head_size) | if(reader.read(buf, head_size)<head_size) |
| throw Exception("image.format", | throw Exception("image.format", |
| &origin_string, | &origin_string, |
| Line 394 static Value* parse_IFD_entry_formatted_ | Line 392 static Value* parse_IFD_entry_formatted_ |
| } | } |
| // date.C | // date.C |
| time_t cstr_to_time_t(char *cstr, bool fail_on_error); | tm cstr_to_time_t(char *cstr); |
| static Value* parse_IFD_entry_formatted_value(bool is_big, ushort format, | static Value* parse_IFD_entry_formatted_value(bool is_big, ushort format, |
| size_t component_size, uint components_count, | size_t component_size, uint components_count, |
| Line 404 static Value* parse_IFD_entry_formatted_ | Line 402 static Value* parse_IFD_entry_formatted_ |
| size_t length=components_count; | size_t length=components_count; |
| // Data format is "YYYY:MM:DD HH:MM:SS"+0x00, total 20bytes | // Data format is "YYYY:MM:DD HH:MM:SS"+0x00, total 20bytes |
| if(length==JPEG_EXIF_DATE_CHARS | if(length==JPEG_EXIF_DATE_CHARS |
| && isdigit(cstr[0]) | && isdigit((unsigned char)cstr[0]) |
| && cstr[length-1]==0) { | && cstr[length-1]==0) { |
| char cstr_writable[JPEG_EXIF_DATE_CHARS]; | char cstr_writable[JPEG_EXIF_DATE_CHARS]; |
| strcpy(cstr_writable, cstr); | strcpy(cstr_writable, cstr); |
| time_t t=cstr_to_time_t(cstr_writable, | try { |
| false/* do not throw exception, just return bad result */); | return new VDate(cstr_to_time_t(cstr_writable)); |
| if(t>=0) | } |
| return new VDate(t); | catch(...) { /*ignore bad date times*/ } |
| } | } |
| if(const char* premature_zero_pos=(const char* )memchr(cstr, 0, length)) | if(const char* premature_zero_pos=(const char* )memchr(cstr, 0, length)) |
| Line 637 static void measure_png(const String& or | Line 635 static void measure_png(const String& or |
| Measure_reader& reader, ushort& width, ushort& height) { | Measure_reader& reader, ushort& width, ushort& height) { |
| const char* buf; | const char* buf; |
| const int head_size=sizeof(PNG_Header); | const size_t head_size=sizeof(PNG_Header); |
| if(reader.read(buf, head_size)<head_size) | if(reader.read(buf, head_size)<head_size) |
| throw Exception("image.format", | throw Exception("image.format", |
| &origin_string, | &origin_string, |
| Line 687 struct File_measure_action_info { | Line 685 struct File_measure_action_info { |
| }; | }; |
| #endif | #endif |
| static void file_measure_action( | static void file_measure_action( |
| struct stat& finfo, int f, | struct stat& /*finfo*/, int f, |
| const String& file_spec, const char* fname, bool as_text, | const String& /*file_spec*/, const char* fname, bool /*as_text*/, |
| void *context) { | void *context) { |
| File_measure_action_info& info=*static_cast<File_measure_action_info *>(context); | File_measure_action_info& info=*static_cast<File_measure_action_info *>(context); |
| Line 703 static void _measure(Request& r, MethodP | Line 701 static void _measure(Request& r, MethodP |
| ushort height=0; | ushort height=0; |
| Value* exif=0; | Value* exif=0; |
| const String* file_name; | const String* file_name; |
| if(file_name=data.get_string()) { | if((file_name=data.get_string())) { |
| File_measure_action_info info={0}; | File_measure_action_info info={ |
| info.width=&width; | &width, &height, |
| info.height=&height; | &exif, |
| info.exif=&exif; | file_name |
| info.file_name=file_name; | }; |
| file_read_action_under_lock(r.absolute(*file_name), | file_read_action_under_lock(r.absolute(*file_name), |
| "measure", file_measure_action, &info); | "measure", file_measure_action, &info); |
| } else { | } else { |
| Line 755 static void _html(Request& r, MethodPara | Line 753 static void _html(Request& r, MethodPara |
| if(params.count()) { | if(params.count()) { |
| // for backward compatibility: someday was ^html{} | // for backward compatibility: someday was ^html{} |
| Value& vattribs=r.process_to_value(params[0], | Value& vattribs=r.process_to_value(params[0], |
| /*0/*no name* /,*/ | |
| false/*don't intercept string*/); | false/*don't intercept string*/); |
| if(!vattribs.is_string()) // allow empty | if(!vattribs.is_string()) // allow empty |
| if(attribs=vattribs.get_hash()) { | if((attribs=vattribs.get_hash())) { |
| Attrib_info info={&tag}; | Attrib_info info={&tag, 0}; |
| attribs->for_each(append_attrib_pair, &info); | attribs->for_each(append_attrib_pair, &info); |
| } else | } else |
| throw Exception("parser.runtime", | throw Exception("parser.runtime", |
| Line 792 static gdImage* load(Request& r, | Line 789 static gdImage* load(Request& r, |
| throw Exception("file.missing", | throw Exception("file.missing", |
| 0, | 0, |
| "can not open '%s'", file_name_cstr); | "can not open '%s'", file_name_cstr); |
| return 0; | |
| } | } |
| } | } |
| Line 817 static void _create(Request& r, MethodPa | Line 813 static void _create(Request& r, MethodPa |
| } | } |
| static void _gif(Request& r, MethodParams& params) { | static void _gif(Request& r, MethodParams& params) { |
| gdImage* image=GET_SELF(r, VImage).image; | gdImage& image=GET_SELF(r, VImage).image(); |
| if(!image) | |
| throw Exception(0, | |
| 0, | |
| "does not contain an image"); | |
| const String *file_name=0; | const String *file_name=0; |
| if(params.count()>0) | if(params.count()>0) |
| file_name=¶ms.as_string(0, "file name must be string"); | file_name=¶ms.as_string(0, "file name must be string"); |
| gdBuf buf=image->Gif(); | gdBuf buf=image.Gif(); |
| VFile& vfile=*new VFile; | VFile& vfile=*new VFile; |
| Value* content_type=new VString(*new String("image/gif")); | Value* content_type=new VString(*new String("image/gif")); |
| Line 840 static void _gif(Request& r, MethodParam | Line 832 static void _gif(Request& r, MethodParam |
| } | } |
| static void _line(Request& r, MethodParams& params) { | static void _line(Request& r, MethodParams& params) { |
| gdImage* image=GET_SELF(r, VImage).image; | gdImage& image=GET_SELF(r, VImage).image(); |
| if(!image) | |
| throw Exception(0, | |
| 0, | |
| "does not contain an image"); | |
| image->Line( | image.Line( |
| params.as_int(0, "x0 must be int", r), | params.as_int(0, "x0 must be int", r), |
| params.as_int(1, "y0 must be int", r), | params.as_int(1, "y0 must be int", r), |
| params.as_int(2, "x1 must be int", r), | params.as_int(2, "x1 must be int", r), |
| params.as_int(3, "y1 must be int", r), | params.as_int(3, "y1 must be int", r), |
| image->Color(params.as_int(4, "color must be int", r))); | image.Color(params.as_int(4, "color must be int", r))); |
| } | } |
| static void _fill(Request& r, MethodParams& params) { | static void _fill(Request& r, MethodParams& params) { |
| gdImage* image=GET_SELF(r, VImage).image; | gdImage& image=GET_SELF(r, VImage).image(); |
| if(!image) | |
| throw Exception(0, | |
| 0, | |
| "does not contain an image"); | |
| image->Fill( | image.Fill( |
| params.as_int(0, "x must be int", r), | params.as_int(0, "x must be int", r), |
| params.as_int(1, "y must be int", r), | params.as_int(1, "y must be int", r), |
| image->Color(params.as_int(2, "color must be int", r))); | image.Color(params.as_int(2, "color must be int", r))); |
| } | } |
| static void _rectangle(Request& r, MethodParams& params) { | static void _rectangle(Request& r, MethodParams& params) { |
| gdImage* image=GET_SELF(r, VImage).image; | gdImage& image=GET_SELF(r, VImage).image(); |
| if(!image) | |
| throw Exception(0, | |
| 0, | |
| "does not contain an image"); | |
| image->Rectangle( | image.Rectangle( |
| params.as_int(0, "x0 must be int", r), | params.as_int(0, "x0 must be int", r), |
| params.as_int(1, "y0 must be int", r), | params.as_int(1, "y0 must be int", r), |
| params.as_int(2, "x1 must be int", r), | params.as_int(2, "x1 must be int", r), |
| params.as_int(3, "y1 must be int", r), | params.as_int(3, "y1 must be int", r), |
| image->Color(params.as_int(4, "color must be int", r))); | image.Color(params.as_int(4, "color must be int", r))); |
| } | } |
| static void _bar(Request& r, MethodParams& params) { | static void _bar(Request& r, MethodParams& params) { |
| gdImage* image=GET_SELF(r, VImage).image; | gdImage& image=GET_SELF(r, VImage).image(); |
| if(!image) | |
| throw Exception(0, | |
| 0, | |
| "does not contain an image"); | |
| image->FilledRectangle( | image.FilledRectangle( |
| params.as_int(0, "x0 must be int", r), | params.as_int(0, "x0 must be int", r), |
| params.as_int(1, "y0 must be int", r), | params.as_int(1, "y0 must be int", r), |
| params.as_int(2, "x1 must be int", r), | params.as_int(2, "x1 must be int", r), |
| params.as_int(3, "y1 must be int", r), | params.as_int(3, "y1 must be int", r), |
| image->Color(params.as_int(4, "color must be int", r))); | image.Color(params.as_int(4, "color must be int", r))); |
| } | } |
| #ifndef DOXYGEN | #ifndef DOXYGEN |
| static void add_point(Table::element_type row, | static void add_point(Table::element_type row, |
| gdImage::Point **p) { | gdImage::Point **p) { |
| if(row->count()!=2) | |
| throw Exception(0, | |
| 0, | |
| "coordinates table must contain two columns: x and y values"); | |
| (**p).x=row->get(0)->as_int(); | (**p).x=row->get(0)->as_int(); |
| (**p).y=row->get(1)->as_int(); | (**p).y=row->get(1)->as_int(); |
| (*p)++; | (*p)++; |
| } | } |
| #endif | #endif |
| static void _replace(Request& r, MethodParams& params) { | static void _replace(Request& r, MethodParams& params) { |
| gdImage* image=GET_SELF(r, VImage).image; | gdImage& image=GET_SELF(r, VImage).image(); |
| if(!image) | |
| throw Exception(0, | |
| 0, | |
| "does not contain an image"); | |
| Table* table=params.as_no_junction(2, "coordinates must not be code").get_table(); | Table* table=params.as_no_junction(2, "coordinates must not be code").get_table(); |
| if(!table) | if(!table) |
| Line 921 static void _replace(Request& r, MethodP | Line 897 static void _replace(Request& r, MethodP |
| gdImage::Point *all_p=new(PointerFreeGC) gdImage::Point[table->count()]; | gdImage::Point *all_p=new(PointerFreeGC) gdImage::Point[table->count()]; |
| gdImage::Point *add_p=all_p; | gdImage::Point *add_p=all_p; |
| table->for_each(add_point, &add_p); | table->for_each(add_point, &add_p); |
| image->FilledPolygonReplaceColor(all_p, table->count(), | image.FilledPolygonReplaceColor(all_p, table->count(), |
| image->Color(params.as_int(0, "src color must be int", r)), | image.Color(params.as_int(0, "src color must be int", r)), |
| image->Color(params.as_int(1, "dest color must be int", r))); | image.Color(params.as_int(1, "dest color must be int", r))); |
| } | } |
| static void _polyline(Request& r, MethodParams& params) { | static void _polyline(Request& r, MethodParams& params) { |
| gdImage* image=GET_SELF(r, VImage).image; | gdImage& image=GET_SELF(r, VImage).image(); |
| if(!image) | |
| throw Exception(0, | |
| 0, | |
| "does not contain an image"); | |
| Table* table=params.as_no_junction(1, "coordinates must not be code").get_table(); | Table* table=params.as_no_junction(1, "coordinates must not be code").get_table(); |
| if(!table) | if(!table) |
| Line 942 static void _polyline(Request& r, Method | Line 914 static void _polyline(Request& r, Method |
| gdImage::Point* all_p=new(PointerFreeGC) gdImage::Point[table->count()]; | gdImage::Point* all_p=new(PointerFreeGC) gdImage::Point[table->count()]; |
| gdImage::Point *add_p=all_p; | gdImage::Point *add_p=all_p; |
| table->for_each(add_point, &add_p); | table->for_each(add_point, &add_p); |
| image->Polygon(all_p, table->count(), | image.Polygon(all_p, table->count(), |
| image->Color(params.as_int(0, "color must be int", r)), | image.Color(params.as_int(0, "color must be int", r)), |
| false/*not closed*/); | false/*not closed*/); |
| } | } |
| static void _polygon(Request& r, MethodParams& params) { | static void _polygon(Request& r, MethodParams& params) { |
| gdImage* image=GET_SELF(r, VImage).image; | gdImage& image=GET_SELF(r, VImage).image(); |
| if(!image) | |
| throw Exception(0, | |
| 0, | |
| "does not contain an image"); | |
| Table* table=params.as_no_junction(1, "coordinates must not be code").get_table(); | Table* table=params.as_no_junction(1, "coordinates must not be code").get_table(); |
| if(!table) | if(!table) |
| Line 963 static void _polygon(Request& r, MethodP | Line 931 static void _polygon(Request& r, MethodP |
| gdImage::Point* all_p=new(PointerFreeGC) gdImage::Point[table->count()]; | gdImage::Point* all_p=new(PointerFreeGC) gdImage::Point[table->count()]; |
| gdImage::Point *add_p=all_p; | gdImage::Point *add_p=all_p; |
| table->for_each(add_point, &add_p); | table->for_each(add_point, &add_p); |
| image->Polygon(all_p, table->count(), | image.Polygon(all_p, table->count(), |
| image->Color(params.as_int(0, "color must be int", r))); | image.Color(params.as_int(0, "color must be int", r))); |
| } | } |
| static void _polybar(Request& r, MethodParams& params) { | static void _polybar(Request& r, MethodParams& params) { |
| gdImage* image=GET_SELF(r, VImage).image; | gdImage& image=GET_SELF(r, VImage).image(); |
| if(!image) | |
| throw Exception(0, | |
| 0, | |
| "does not contain an image"); | |
| Table* table=params.as_no_junction(1, "coordinates must not be code").get_table(); | Table* table=params.as_no_junction(1, "coordinates must not be code").get_table(); |
| if(!table) | if(!table) |
| Line 983 static void _polybar(Request& r, MethodP | Line 947 static void _polybar(Request& r, MethodP |
| gdImage::Point* all_p=new(PointerFreeGC) gdImage::Point[table->count()]; | gdImage::Point* all_p=new(PointerFreeGC) gdImage::Point[table->count()]; |
| gdImage::Point *add_p=all_p; | gdImage::Point *add_p=all_p; |
| table->for_each(add_point, &add_p); | table->for_each(add_point, &add_p); |
| image->FilledPolygon(all_p, table->count(), | image.FilledPolygon(all_p, table->count(), |
| image->Color(params.as_int(0, "color must be int", r))); | image.Color(params.as_int(0, "color must be int", r))); |
| } | } |
| // font | // font |
| Line 998 const int Font::letter_spacing=1; | Line 962 const int Font::letter_spacing=1; |
| Font::Font(//, | Font::Font(//, |
| const String& aalphabet, | const String& aalphabet, |
| gdImage* aifont, int aheight, int amonospace, int aspacebarspace): | gdImage* aifont, int aheight, int amonospace, int aspacebarspace): |
| alphabet(aalphabet), | |
| height(aheight), monospace(amonospace), spacebarspace(aspacebarspace), | height(aheight), monospace(amonospace), spacebarspace(aspacebarspace), |
| ifont(aifont) { | ifont(aifont), |
| alphabet(aalphabet) { | |
| } | } |
| /* ******************************** char ********************************** */ | /* ******************************** char ********************************** */ |
| Line 1022 int Font::index_width(size_t index) { | Line 986 int Font::index_width(size_t index) { |
| return 0; | return 0; |
| } | } |
| void Font::index_display(gdImage* image, int x, int y, size_t index){ | void Font::index_display(gdImage& image, int x, int y, size_t index){ |
| if(index!=STRING_NOT_FOUND) | if(index!=STRING_NOT_FOUND) |
| ifont->Copy(*image, x, y, 0, Y(0), index_width(index), height); | ifont->Copy(image, x, y, 0, Y(0), index_width(index), height); |
| } | } |
| /* ******************************** string ********************************** */ | /* ******************************** string ********************************** */ |
| Line 1042 int Font::string_width(const String& s){ | Line 1006 int Font::string_width(const String& s){ |
| return result; | return result; |
| } | } |
| void Font::string_display(gdImage* image, int x, int y, const String& s){ | void Font::string_display(gdImage& image, int x, int y, const String& s){ |
| const char* cstr=s.cstr(); | const char* cstr=s.cstr(); |
| for(const char* current=cstr; *current; current++) { | for(const char* current=cstr; *current; current++) { |
| size_t index=index_of(*current); | size_t index=index_of(*current); |
| Line 1077 static void _font(Request& r, MethodPara | Line 1041 static void _font(Request& r, MethodPara |
| "font-file height(%d) not divisable by alphabet size(%d), remainder=%d", | "font-file height(%d) not divisable by alphabet size(%d), remainder=%d", |
| image->SY(), alphabet.length(), remainder); | image->SY(), alphabet.length(), remainder); |
| GET_SELF(r, VImage).font=new Font( | GET_SELF(r, VImage).set_font(new Font( |
| alphabet, | alphabet, |
| image, | image, |
| image->SY() / alphabet.length(), monospace_width, spacebar_width); | image->SY() / alphabet.length(), monospace_width, spacebar_width)); |
| } | } |
| static void _text(Request& r, MethodParams& params) { | static void _text(Request& r, MethodParams& params) { |
| Line 1089 static void _text(Request& r, MethodPara | Line 1053 static void _text(Request& r, MethodPara |
| const String& s=params.as_string(2, "text must not be code"); | const String& s=params.as_string(2, "text must not be code"); |
| VImage& vimage=GET_SELF(r, VImage); | VImage& vimage=GET_SELF(r, VImage); |
| if(vimage.image) | vimage.font().string_display(vimage.image(), x, y, s); |
| if(vimage.font) | |
| vimage.font->string_display(vimage.image, x, y, s); | |
| else | |
| throw Exception("parser.runtime", | |
| 0, | |
| "set the font first"); | |
| else | |
| throw Exception(0, | |
| 0, | |
| "does not contain an image"); | |
| } | } |
| static void _length(Request& r, MethodParams& params) { | static void _length(Request& r, MethodParams& params) { |
| const String& s=params.as_string(0, "text must not be code"); | const String& s=params.as_string(0, "text must not be code"); |
| VImage& vimage=GET_SELF(r, VImage); | VImage& vimage=GET_SELF(r, VImage); |
| if(vimage.image) | r.write_no_lang(*new VInt(vimage.font().string_width(s))); |
| if(vimage.font) { | |
| r.write_no_lang(*new VInt(vimage.font->string_width(s))); | |
| } else | |
| throw Exception("parser.runtime", | |
| 0, | |
| "set the font first"); | |
| else | |
| throw Exception(0, | |
| 0, | |
| "does not contain an image"); | |
| } | } |
| static void _arc(Request& r, MethodParams& params) { | static void _arc(Request& r, MethodParams& params) { |
| gdImage* image=GET_SELF(r, VImage).image; | gdImage& image=GET_SELF(r, VImage).image(); |
| if(!image) | |
| throw Exception(0, | |
| 0, | |
| "does not contain an image"); | |
| image->Arc( | image.Arc( |
| params.as_int(0, "center_x must be int", r), | params.as_int(0, "center_x must be int", r), |
| params.as_int(1, "center_y must be int", r), | params.as_int(1, "center_y must be int", r), |
| params.as_int(2, "width must be int", r), | params.as_int(2, "width must be int", r), |
| params.as_int(3, "height must be int", r), | params.as_int(3, "height must be int", r), |
| params.as_int(4, "start degrees must be int", r), | params.as_int(4, "start degrees must be int", r), |
| params.as_int(5, "end degrees must be int", r), | params.as_int(5, "end degrees must be int", r), |
| image->Color(params.as_int(6, "cx must be int", r))); | image.Color(params.as_int(6, "cx must be int", r))); |
| } | } |
| static void _sector(Request& r, MethodParams& params) { | static void _sector(Request& r, MethodParams& params) { |
| gdImage* image=GET_SELF(r, VImage).image; | gdImage& image=GET_SELF(r, VImage).image(); |
| if(!image) | |
| throw Exception(0, | |
| 0, | |
| "does not contain an image"); | |
| image->Sector( | image.Sector( |
| params.as_int(0, "center_x must be int", r), | params.as_int(0, "center_x must be int", r), |
| params.as_int(1, "center_y must be int", r), | params.as_int(1, "center_y must be int", r), |
| params.as_int(2, "width must be int", r), | params.as_int(2, "width must be int", r), |
| params.as_int(3, "height must be int", r), | params.as_int(3, "height must be int", r), |
| params.as_int(4, "start degrees must be int", r), | params.as_int(4, "start degrees must be int", r), |
| params.as_int(5, "end degrees must be int", r), | params.as_int(5, "end degrees must be int", r), |
| image->Color(params.as_int(6, "color must be int", r))); | image.Color(params.as_int(6, "color must be int", r))); |
| } | } |
| static void _circle(Request& r, MethodParams& params) { | static void _circle(Request& r, MethodParams& params) { |
| gdImage* image=GET_SELF(r, VImage).image; | gdImage& image=GET_SELF(r, VImage).image(); |
| if(!image) | |
| throw Exception(0, | |
| 0, | |
| "does not contain an image"); | |
| int size=params.as_int(2, "radius must be int", r)*2; | int size=params.as_int(2, "radius must be int", r)*2; |
| image->Arc( | image.Arc( |
| params.as_int(0, "center_x must be int", r), | params.as_int(0, "center_x must be int", r), |
| params.as_int(1, "center_y must be int", r), | params.as_int(1, "center_y must be int", r), |
| size, //w | size, //w |
| size, //h | size, //h |
| 0, //s | 0, //s |
| 360, //e | 360, //e |
| image->Color(params.as_int(3, "color must be int", r))); | image.Color(params.as_int(3, "color must be int", r))); |
| } | } |
| gdImage* as_image(MethodParams& params, int index, const char* msg) { | gdImage& as_image(MethodParams& params, int index, const char* msg) { |
| gdImage* src=0; | |
| Value& value=params.as_no_junction(index, msg); | Value& value=params.as_no_junction(index, msg); |
| if(Value* vimage=value.as(VIMAGE_TYPE, false)) { | if(Value* vimage=value.as(VIMAGE_TYPE, false)) { |
| src=static_cast<VImage *>(vimage)->image; | return static_cast<VImage *>(vimage)->image(); |
| if(!src) | |
| throw Exception("parser.runtime", | |
| 0, | |
| msg); | |
| } else | } else |
| throw Exception("parser.runtime", | throw Exception("parser.runtime", |
| 0, | 0, |
| msg); | msg); |
| return src; | |
| } | } |
| static void _copy(Request& r, MethodParams& params) { | static void _copy(Request& r, MethodParams& params) { |
| gdImage* dest=GET_SELF(r, VImage).image; | gdImage& dest=GET_SELF(r, VImage).image(); |
| if(!dest) | |
| throw Exception(0, | |
| 0, | |
| "self does not contain an image"); | |
| gdImage* src=as_image(params, 0, "src must be image"); | gdImage& src=as_image(params, 0, "src must be image"); |
| int sx=params.as_int(1, "src_x must be int", r); | int sx=params.as_int(1, "src_x must be int", r); |
| int sy=params.as_int(2, "src_y must be int", r); | int sy=params.as_int(2, "src_y must be int", r); |
| Line 1212 static void _copy(Request& r, MethodPara | Line 1132 static void _copy(Request& r, MethodPara |
| int tolerance=params.count()>1+2+2+2+2? | int tolerance=params.count()>1+2+2+2+2? |
| params.as_int(1+2+2+2+2, "tolerance must be int", r):150; | params.as_int(1+2+2+2+2, "tolerance must be int", r):150; |
| src->CopyResampled(*dest, dx, dy, sx, sy, dw, dh, sw, sh, tolerance); | src.CopyResampled(dest, dx, dy, sx, sy, dw, dh, sw, sh, tolerance); |
| } else | } else |
| src->Copy(*dest, dx, dy, sx, sy, sw, sh); | src.Copy(dest, dx, dy, sx, sy, sw, sh); |
| } | |
| static void _pixel(Request& r, MethodParams& params) { | |
| gdImage& image=GET_SELF(r, VImage).image(); | |
| int x=params.as_int(0, "x must be int", r); | |
| int y=params.as_int(1, "y must be int", r); | |
| if(params.count()>2) { | |
| image.SetPixel(x, y, | |
| image.Color(params.as_int(2, "color must be int", r))); | |
| } else | |
| r.write_no_lang(*new VInt(image.DecodeColor(image.GetPixel(x, y)))); | |
| } | } |
| Line 1283 MImage::MImage(): Methoded("image") { | Line 1216 MImage::MImage(): Methoded("image") { |
| // ^image.copy[source](src x;src y;src w;src h;dst x;dst y[;dest w[;dest h[;tolerance]]]) | // ^image.copy[source](src x;src y;src w;src h;dst x;dst y[;dest w[;dest h[;tolerance]]]) |
| add_native_method("copy", Method::CT_DYNAMIC, _copy, 1+2+2+2, (1+2+2+2)+2+1); | add_native_method("copy", Method::CT_DYNAMIC, _copy, 1+2+2+2, (1+2+2+2)+2+1); |
| // ^image.pixel(x;y)[(color)] | |
| add_native_method("pixel", Method::CT_DYNAMIC, _pixel, 2, 3); | |
| } | } |