--- parser3/src/classes/image.C 2004/03/01 13:22:25 1.108 +++ parser3/src/classes/image.C 2007/04/23 10:30:09 1.115 @@ -1,11 +1,11 @@ /** @file Parser: @b image parser class. - Copyright(c) 2001-2004 ArtLebedev Group (http://www.artlebedev.com) + Copyright(c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_IMAGE_C="$Date: 2004/03/01 13:22:25 $"; +static const char * const IDENT_IMAGE_C="$Date: 2007/04/23 10:30:09 $"; /* jpegsize: gets the width and height (in pixels) of a jpeg file @@ -33,7 +33,7 @@ static const char * const IDENT_IMAGE_C= class MImage: public Methoded { public: // VStateless_class - Value* create_new_value(Pool&) { return new VImage(); } + Value* create_new_value(Pool&, HashStringValue&) { return new VImage(); } public: MImage(); @@ -402,7 +402,7 @@ static Value* parse_IFD_entry_formatted_ size_t length=components_count; // Data format is "YYYY:MM:DD HH:MM:SS"+0x00, total 20bytes if(length==JPEG_EXIF_DATE_CHARS - && isdigit(cstr[0]) + && isdigit((unsigned char)cstr[0]) && cstr[length-1]==0) { char cstr_writable[JPEG_EXIF_DATE_CHARS]; strcpy(cstr_writable, cstr); @@ -757,16 +757,16 @@ static void _html(Request& r, MethodPara if(!vattribs.is_string()) // allow empty if((attribs=vattribs.get_hash())) { Attrib_info info={&tag, 0}; - attribs->for_each(append_attrib_pair, &info); + attribs->for_each(append_attrib_pair, &info); } else - throw Exception("parser.runtime", + throw Exception(PARSER_RUNTIME, 0, "attributes must be hash"); } { Attrib_info info={&tag, attribs}; - fields.for_each(append_attrib_pair, &info); + fields.for_each(append_attrib_pair, &info); } tag << " />"; r.write_pass_lang(tag); @@ -876,6 +876,10 @@ static void _bar(Request& r, MethodParam #ifndef DOXYGEN static void add_point(Table::element_type row, 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).y=row->get(1)->as_int(); (*p)++; @@ -936,7 +940,7 @@ static void _polybar(Request& r, MethodP Table* table=params.as_no_junction(1, "coordinates must not be code").get_table(); if(!table) - throw Exception("parser.runtime", + throw Exception(PARSER_RUNTIME, 0, "coordinates must be table"); @@ -1027,12 +1031,12 @@ static void _font(Request& r, MethodPara monospace_width=0; if(!alphabet.length()) - throw Exception("parser.runtime", + throw Exception(PARSER_RUNTIME, 0, "alphabet must not be empty"); if(int remainder=image->SY() % alphabet.length()) - throw Exception("parser.runtime", + throw Exception(PARSER_RUNTIME, 0, "font-file height(%d) not divisable by alphabet size(%d), remainder=%d", image->SY(), alphabet.length(), remainder); @@ -1105,7 +1109,7 @@ gdImage& as_image(MethodParams& params, if(Value* vimage=value.as(VIMAGE_TYPE, false)) { return static_cast(vimage)->image(); } else - throw Exception("parser.runtime", + throw Exception(PARSER_RUNTIME, 0, msg); } @@ -1136,10 +1140,14 @@ static void _copy(Request& r, MethodPara static void _pixel(Request& r, MethodParams& params) { gdImage& image=GET_SELF(r, VImage).image(); - image.Fill( - params.as_int(0, "x must be int", r), - params.as_int(1, "y must be int", r), - image.Color(params.as_int(2, "color must be int", r))); + 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)))); } @@ -1210,5 +1218,5 @@ MImage::MImage(): Methoded("image") { 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("copy", Method::CT_DYNAMIC, _pixel, 2, 3); + add_native_method("pixel", Method::CT_DYNAMIC, _pixel, 2, 3); }