--- parser3/src/classes/image.C 2001/10/16 09:59:23 1.55 +++ parser3/src/classes/image.C 2002/02/08 07:27:40 1.65 @@ -1,10 +1,10 @@ /** @file Parser: @b image parser class. - Copyright(c) 2001 ArtLebedev Group(http://www.artlebedev.com) - Author: Alexander Petrosyan (http://design.ru/paf) + Copyright(c) 2001, 2002 ArtLebedev Group(http://www.artlebedev.com) + Author: Alexander Petrosyan (http://paf.design.ru) - $Id: image.C,v 1.55 2001/10/16 09:59:23 parser Exp $ + $Id: image.C,v 1.65 2002/02/08 07:27:40 paf Exp $ */ /* @@ -128,13 +128,13 @@ void measure_gif(Pool& pool, const Strin void *buf; const int head_size=sizeof(GIF_Header); if(reader.read(buf, head_size)type, "GIF", 3)!=0) - PTHROW(0, 0, + throw Exception(0, 0, origin_string, "not GIF file - wrong signature"); @@ -142,6 +142,7 @@ void measure_gif(Pool& pool, const Strin height=little_endian_to_int(head->height); } +/// @test remove ugly mech in reader - 20K limit void measure_jpeg(Pool& pool, const String *origin_string, Measure_reader& reader, int& width, int& height) { // JFIF format markers @@ -152,13 +153,13 @@ void measure_jpeg(Pool& pool, const Stri void *buf; const size_t prefix_size=2; if(reader.read(buf, prefix_size)for_each(append_attrib_pair, &attrib_info); } else - PTHROW(0, 0, + throw Exception(0, 0, &method_name, "attributes must be hash"); } @@ -342,12 +343,12 @@ static gdImage *load(Request& r, const S bool ok=image.CreateFromGif(f); fclose(f); if(!ok) - PTHROW(0, 0, + throw Exception(0, 0, &file_name, "is not in GIF format"); return ℑ } else { - PTHROW(0, 0, + throw Exception(0, 0, &method_name, "can not open '%s'", file_name_cstr); return 0; @@ -385,7 +386,7 @@ static void _gif(Request& r, const Strin gdImage *image=static_cast(r.self)->image; if(!image) - PTHROW(0, 0, + throw Exception(0, 0, &method_name, "does not contain an image"); @@ -396,7 +397,7 @@ static void _gif(Request& r, const Strin VFile& vfile=*new(pool) VFile(pool); Value *content_type=new(pool) VString(*new(pool) String(pool, "image/gif")); vfile.set(false/*not tainted*/, - out.cstr(String::UL_AS_IS), out.size(), 0, content_type); + out.cstr(), out.size(), 0, content_type); r.write_no_lang(vfile); } @@ -406,7 +407,7 @@ static void _line(Request& r, const Stri gdImage *image=static_cast(r.self)->image; if(!image) - PTHROW(0, 0, + throw Exception(0, 0, &method_name, "does not contain an image"); @@ -423,7 +424,7 @@ static void _fill(Request& r, const Stri gdImage *image=static_cast(r.self)->image; if(!image) - PTHROW(0, 0, + throw Exception(0, 0, &method_name, "does not contain an image"); @@ -438,7 +439,7 @@ static void _rectangle(Request& r, const gdImage *image=static_cast(r.self)->image; if(!image) - PTHROW(0, 0, + throw Exception(0, 0, &method_name, "does not contain an image"); @@ -455,7 +456,7 @@ static void _bar(Request& r, const Strin gdImage *image=static_cast(r.self)->image; if(!image) - PTHROW(0, 0, + throw Exception(0, 0, &method_name, "does not contain an image"); @@ -482,13 +483,13 @@ static void _replace(Request& r, const S gdImage *image=static_cast(r.self)->image; if(!image) - PTHROW(0, 0, + throw Exception(0, 0, &method_name, "does not contain an image"); Table *table=params->as_no_junction(2, "coordinates must not be code").get_table(); if(!table) - PTHROW(0, 0, + throw Exception(0, 0, &method_name, "coordinates must be table"); @@ -505,13 +506,13 @@ static void _polyline(Request& r, const gdImage *image=static_cast(r.self)->image; if(!image) - PTHROW(0, 0, + throw Exception(0, 0, &method_name, "does not contain an image"); Table *table=params->as_no_junction(1, "coordinates must not be code").get_table(); if(!table) - PTHROW(0, 0, + throw Exception(0, 0, &method_name, "coordinates must be table"); @@ -528,13 +529,13 @@ static void _polygon(Request& r, const S gdImage *image=static_cast(r.self)->image; if(!image) - PTHROW(0, 0, + throw Exception(0, 0, &method_name, "does not contain an image"); Table *table=params->as_no_junction(1, "coordinates must not be code").get_table(); if(!table) - PTHROW(0, 0, + throw Exception(0, 0, &method_name, "coordinates must be table"); @@ -550,13 +551,13 @@ static void _polybar(Request& r, const S gdImage *image=static_cast(r.self)->image; if(!image) - PTHROW(0, 0, + throw Exception(0, 0, &method_name, "does not contain an image"); Table *table=params->as_no_junction(1, "coordinates must not be code").get_table(); if(!table) - PTHROW(0, 0, + throw Exception(0, 0, &method_name, "coordinates must be table"); @@ -617,7 +618,7 @@ public: /* ******************************** string ********************************** */ int string_width(const String& s){ - const char *cstr=s.cstr(String::UL_AS_IS); + const char *cstr=s.cstr(); int result=0; for(; *cstr; cstr++) result+=index_width(index_of(*cstr)); @@ -625,7 +626,7 @@ public: } void string_display(gdImage& image, int x, int y, const String& s){ - const char *cstr=s.cstr(String::UL_AS_IS); + const char *cstr=s.cstr(); if(cstr) for(; *cstr; cstr++) { int index=index_of(*cstr); index_display(image, x, y, index); @@ -651,7 +652,7 @@ static void _font(Request& r, const Stri monospace_width=0; if(!alphabet.size()) - PTHROW(0, 0, + throw Exception(0, 0, &method_name, "alphabet must not be empty"); @@ -673,11 +674,11 @@ static void _text(Request& r, const Stri if(vimage.font) vimage.font->string_display(*vimage.image, x, y, s); else - PTHROW(0, 0, + throw Exception(0, 0, &method_name, "set the font first"); else - PTHROW(0, 0, + throw Exception(0, 0, &method_name, "does not contain an image"); } @@ -694,11 +695,11 @@ static void _length(Request& r, const St result.set_name(method_name); r.write_assign_lang(result); } else - PTHROW(0, 0, + throw Exception(0, 0, &method_name, "set the font first"); else - PTHROW(0, 0, + throw Exception(0, 0, &method_name, "does not contain an image"); } @@ -708,7 +709,7 @@ static void _arc(Request& r, const Strin gdImage *image=static_cast(r.self)->image; if(!image) - PTHROW(0, 0, + throw Exception(0, 0, &method_name, "does not contain an image"); @@ -727,7 +728,7 @@ static void _sector(Request& r, const St gdImage *image=static_cast(r.self)->image; if(!image) - PTHROW(0, 0, + throw Exception(0, 0, &method_name, "does not contain an image"); @@ -746,7 +747,7 @@ static void _circle(Request& r, const St gdImage *image=static_cast(r.self)->image; if(!image) - PTHROW(0, 0, + throw Exception(0, 0, &method_name, "does not contain an image"); @@ -766,26 +767,25 @@ gdImage& as_image(Pool& pool, const Stri Value& value=params->as_no_junction(index, msg); if(strcmp(value.type(), VIMAGE_TYPE)!=0) - PTHROW(0, 0, + throw Exception(0, 0, &method_name, msg); gdImage *src=static_cast(&value)->image; if(!src) - PTHROW(0, 0, + throw Exception(0, 0, &method_name, msg); return *src; } -// ^image.copy[source](src x;src y;src w;src h;dst x;dst y[;dest w[;dest h]]) static void _copy(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); gdImage *dest=static_cast(r.self)->image; if(!dest) - PTHROW(0, 0, + throw Exception(0, 0, &method_name, "self does not contain an image"); @@ -799,9 +799,12 @@ static void _copy(Request& r, const Stri int dy=params->as_int(6, "dest_y must be int", r); if(params->size()>1+2+2+2) { int dw=params->as_int(1+2+2+2, "dest_w must be int", r); - int dh=params->size()>1+2+2+2+1?params->as_int(1+2+2+2+1, "dest_h must be int", r):dw; + int dh=(int)(params->size()>1+2+2+2+1? + params->as_int(1+2+2+2+1, "dest_h must be int", r):sh*(((double)dw)/((double)sw))); + int tolerance=params->size()>1+2+2+2+2? + 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); + src.CopyResampled(*dest, dx, dy, sx, sy, dw, dh, sw, sh, tolerance); } else src.Copy(*dest, dx, dy, sx, sy, sw, sh); } @@ -873,8 +876,8 @@ MImage::MImage(Pool& apool) : Methoded(a // ^image.circle(center x;center y;r;color) add_native_method("circle", Method::CT_DYNAMIC, _circle, 4, 4); - // ^image.copy[source](src x;src y;src w;src h;dst x;dst y[;dest w[;dest h]]) - add_native_method("copy", Method::CT_DYNAMIC, _copy, 1+2+2+2, (1+2+2+2)+2); + // ^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); } // global variable