--- parser3/src/classes/image.C 2003/01/31 12:34:26 1.90.2.3 +++ parser3/src/classes/image.C 2003/02/04 14:04:45 1.90.2.4 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_IMAGE_C="$Date: 2003/01/31 12:34:26 $"; +static const char* IDENT_IMAGE_C="$Date: 2003/02/04 14:04:45 $"; /* jpegsize: gets the width and height (in pixels) of a jpeg file @@ -598,10 +598,10 @@ static void file_measure_action(Pool& po measure(pool, *info.file_name, reader, *info.width, *info.height, info.exif); } -static void _measure(Request& r, const String& method_name, MethodParams *params) { +static void _measure(Request& r, StringPtr method_name, MethodParams& params) { Pool& pool=r.pool(); - Value& data=params->as_no_junction(0, "data must not be code"); + Value& data=params.as_no_junction(0, "data must not be code"); ushort width=0; ushort height=0; @@ -645,7 +645,7 @@ static void append_attrib_pair(const Has if(value.is_string() || value.as_int()>=0) *ai.tag << "=\"" << value.as_string() << "\""; } -static void _html(Request& r, const String& method_name, MethodParams *params) { +static void _html(Request& r, StringPtr method_name, MethodParams& params) { Pool& pool=r.pool(); String tag(pool); @@ -654,9 +654,9 @@ static void _html(Request& r, const Stri const Hash& fields=static_cast(r.get_self())->fields(); Hash *attribs=0; - if(params->size()) { + if(params.count()) { // for backward compatibility: someday was ^html{} - Value &vattribs=r.process_to_value(params->get(0), + Value &vattribs=r.process_to_value(params.get(0), /*0/*no name* /,*/ false/*don't intercept string*/); if(!vattribs.is_string()) // allow empty @@ -699,10 +699,10 @@ static gdImage *load(Request& r, const S } -static void _load(Request& r, const String& method_name, MethodParams *params) { +static void _load(Request& r, StringPtr method_name, MethodParams& params) { Pool& pool=r.pool(); - const String& file_name=params->as_string(0, "file name must not be code"); + const String& file_name=params.as_string(0, "file name must not be code"); gdImage& image=*load(r, method_name, file_name); int width=image.SX(); @@ -710,21 +710,21 @@ static void _load(Request& r, const Stri static_cast(r.get_self())->set(&file_name, width, height, &image); } -static void _create(Request& r, const String& method_name, MethodParams *params) { +static void _create(Request& r, StringPtr method_name, MethodParams& params) { Pool& pool=r.pool(); - int width=params->as_int(0, "width must be int", r); - int height=params->as_int(1, "height must be int", r); + int width=params.as_int(0, "width must be int", r); + int height=params.as_int(1, "height must be int", r); int bgcolor_value=0xffFFff; - if(params->size()>2) - bgcolor_value=params->as_int(2, "color must be int", r); + if(params.count()>2) + bgcolor_value=params.as_int(2, "color must be int", r); gdImage& image=*new(pool) gdImage(pool); image.Create(width, height); image.FilledRectangle(0, 0, width-1, height-1, image.Color(bgcolor_value)); static_cast(r.get_self())->set(0, width, height, &image); } -static void _gif(Request& r, const String& method_name, MethodParams *params) { +static void _gif(Request& r, StringPtr method_name, MethodParams& params) { Pool& pool=r.pool(); gdImage *image=static_cast(r.get_self())->image; @@ -745,7 +745,7 @@ static void _gif(Request& r, const Strin r.write_no_lang(vfile); } -static void _line(Request& r, const String& method_name, MethodParams *params) { +static void _line(Request& r, StringPtr method_name, MethodParams& params) { Pool& pool=r.pool(); gdImage *image=static_cast(r.get_self())->image; @@ -755,14 +755,14 @@ static void _line(Request& r, const Stri "does not contain an image"); image->Line( - params->as_int(0, "x0 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(3, "y1 must be int", r), - image->Color(params->as_int(4, "color 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(2, "x1 must be int", r), + params.as_int(3, "y1 must be int", r), + image->Color(params.as_int(4, "color must be int", r))); } -static void _fill(Request& r, const String& method_name, MethodParams *params) { +static void _fill(Request& r, StringPtr method_name, MethodParams& params) { Pool& pool=r.pool(); gdImage *image=static_cast(r.get_self())->image; @@ -772,12 +772,12 @@ static void _fill(Request& r, const Stri "does not contain an 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))); + 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))); } -static void _rectangle(Request& r, const String& method_name, MethodParams *params) { +static void _rectangle(Request& r, StringPtr method_name, MethodParams& params) { Pool& pool=r.pool(); gdImage *image=static_cast(r.get_self())->image; @@ -787,14 +787,14 @@ static void _rectangle(Request& r, const "does not contain an image"); image->Rectangle( - params->as_int(0, "x0 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(3, "y1 must be int", r), - image->Color(params->as_int(4, "color 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(2, "x1 must be int", r), + params.as_int(3, "y1 must be int", r), + image->Color(params.as_int(4, "color must be int", r))); } -static void _bar(Request& r, const String& method_name, MethodParams *params) { +static void _bar(Request& r, StringPtr method_name, MethodParams& params) { Pool& pool=r.pool(); gdImage *image=static_cast(r.get_self())->image; @@ -804,11 +804,11 @@ static void _bar(Request& r, const Strin "does not contain an image"); image->FilledRectangle( - params->as_int(0, "x0 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(3, "y1 must be int", r), - image->Color(params->as_int(4, "color 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(2, "x1 must be int", r), + params.as_int(3, "y1 must be int", r), + image->Color(params.as_int(4, "color must be int", r))); } #ifndef DOXYGEN @@ -821,7 +821,7 @@ static void add_point(Array::Item *value (*p)++; } #endif -static void _replace(Request& r, const String& method_name, MethodParams *params) { +static void _replace(Request& r, StringPtr method_name, MethodParams& params) { Pool& pool=r.pool(); gdImage *image=static_cast(r.get_self())->image; @@ -830,7 +830,7 @@ static void _replace(Request& r, const S &method_name, "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) throw Exception(0, &method_name, @@ -840,11 +840,11 @@ static void _replace(Request& r, const S gdImage::Point *add_p=all_p; table->for_each(add_point, &add_p); image->FilledPolygonReplaceColor(all_p, table->size(), - 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(0, "src color must be int", r)), + image->Color(params.as_int(1, "dest color must be int", r))); } -static void _polyline(Request& r, const String& method_name, MethodParams *params) { +static void _polyline(Request& r, StringPtr method_name, MethodParams& params) { Pool& pool=r.pool(); gdImage *image=static_cast(r.get_self())->image; @@ -853,7 +853,7 @@ static void _polyline(Request& r, const &method_name, "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) throw Exception(0, &method_name, @@ -863,11 +863,11 @@ static void _polyline(Request& r, const gdImage::Point *add_p=all_p; table->for_each(add_point, &add_p); image->Polygon(all_p, table->size(), - 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*/); } -static void _polygon(Request& r, const String& method_name, MethodParams *params) { +static void _polygon(Request& r, StringPtr method_name, MethodParams& params) { Pool& pool=r.pool(); gdImage *image=static_cast(r.get_self())->image; @@ -876,7 +876,7 @@ static void _polygon(Request& r, const S &method_name, "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) throw Exception(0, &method_name, @@ -886,10 +886,10 @@ static void _polygon(Request& r, const S gdImage::Point *add_p=all_p; table->for_each(add_point, &add_p); image->Polygon(all_p, table->size(), - 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, const String& method_name, MethodParams *params) { +static void _polybar(Request& r, StringPtr method_name, MethodParams& params) { Pool& pool=r.pool(); gdImage *image=static_cast(r.get_self())->image; @@ -898,7 +898,7 @@ static void _polybar(Request& r, const S &method_name, "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) throw Exception("parser.runtime", &method_name, @@ -908,7 +908,7 @@ static void _polybar(Request& r, const S gdImage::Point *add_p=all_p; table->for_each(add_point, &add_p); image->FilledPolygon(all_p, table->size(), - image->Color(params->as_int(0, "color must be int", r))); + image->Color(params.as_int(0, "color must be int", r))); } // font @@ -985,15 +985,15 @@ public: }; const int Font::letter_spacing=1; -static void _font(Request& r, const String& method_name, MethodParams *params) { +static void _font(Request& r, StringPtr method_name, MethodParams& params) { Pool& pool=r.pool(); - const String& alphabet=params->as_string(0, "alphabet must not be code"); - gdImage& image=*load(r, method_name, params->as_string(1, "file_name must not be code")); - int spacebar_width=params->as_int(2, "spacebar_width must be int", r); + const String& alphabet=params.as_string(0, "alphabet must not be code"); + gdImage& image=*load(r, method_name, params.as_string(1, "file_name must not be code")); + int spacebar_width=params.as_int(2, "spacebar_width must be int", r); int monospace_width; - if(params->size()>3) { - monospace_width=params->as_int(3, "monospace_width must be int", r); + if(params.count()>3) { + monospace_width=params.as_int(3, "monospace_width must be int", r); if(!monospace_width) monospace_width=image.SX(); } else @@ -1016,12 +1016,12 @@ static void _font(Request& r, const Stri image.SY() / alphabet.size(), monospace_width, spacebar_width); } -static void _text(Request& r, const String& method_name, MethodParams *params) { +static void _text(Request& r, StringPtr method_name, MethodParams& params) { Pool& pool=r.pool(); - int x=params->as_int(0, "x must be int", r); - int y=params->as_int(1, "y must be int", r); - const String& s=params->as_string(2, "text must not be code"); + int x=params.as_int(0, "x must be int", r); + int y=params.as_int(1, "y must be int", r); + const String& s=params.as_string(2, "text must not be code"); VImage& vimage=*static_cast(r.get_self()); if(vimage.image) @@ -1037,10 +1037,10 @@ static void _text(Request& r, const Stri "does not contain an image"); } -static void _length(Request& r, const String& method_name, MethodParams *params) { +static void _length(Request& r, StringPtr method_name, MethodParams& params) { Pool& pool=r.pool(); - 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=*static_cast(r.get_self()); if(vimage.image) @@ -1056,7 +1056,7 @@ static void _length(Request& r, const St "does not contain an image"); } -static void _arc(Request& r, const String& method_name, MethodParams *params) { +static void _arc(Request& r, StringPtr method_name, MethodParams& params) { Pool& pool=r.pool(); gdImage *image=static_cast(r.get_self())->image; @@ -1066,16 +1066,16 @@ static void _arc(Request& r, const Strin "does not contain an image"); image->Arc( - params->as_int(0, "center_x 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(3, "height must be int", r), - params->as_int(4, "start 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))); + params.as_int(0, "center_x 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(3, "height must be int", r), + params.as_int(4, "start 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))); } -static void _sector(Request& r, const String& method_name, MethodParams *params) { +static void _sector(Request& r, StringPtr method_name, MethodParams& params) { Pool& pool=r.pool(); gdImage *image=static_cast(r.get_self())->image; @@ -1085,16 +1085,16 @@ static void _sector(Request& r, const St "does not contain an image"); image->Sector( - params->as_int(0, "center_x 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(3, "height must be int", r), - params->as_int(4, "start 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))); + params.as_int(0, "center_x 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(3, "height must be int", r), + params.as_int(4, "start 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))); } -static void _circle(Request& r, const String& method_name, MethodParams *params) { +static void _circle(Request& r, StringPtr method_name, MethodParams& params) { Pool& pool=r.pool(); gdImage *image=static_cast(r.get_self())->image; @@ -1103,22 +1103,22 @@ static void _circle(Request& r, const St &method_name, "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( - params->as_int(0, "center_x must be int", r), - params->as_int(1, "center_y must be int", r), + params.as_int(0, "center_x must be int", r), + params.as_int(1, "center_y must be int", r), size, //w size, //h 0, //s 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(Pool& pool, const String& method_name, MethodParams *params, +gdImage& as_image(Pool& pool, StringPtr method_name, 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)) { src=static_cast(vimage)->image; @@ -1134,7 +1134,7 @@ gdImage& as_image(Pool& pool, const Stri return *src; } -static void _copy(Request& r, const String& method_name, MethodParams *params) { +static void _copy(Request& r, StringPtr method_name, MethodParams& params) { Pool& pool=r.pool(); gdImage *dest=static_cast(r.get_self())->image; @@ -1145,18 +1145,18 @@ static void _copy(Request& r, const Stri gdImage& src=as_image(pool, method_name, params, 0, "src must be image"); - 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 sw=params->as_int(3, "src_w must be int", r); - int sh=params->as_int(4, "src_h must be int", r); - int dx=params->as_int(5, "dest_x must be int", r); - 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=(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; + 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 sw=params.as_int(3, "src_w must be int", r); + int sh=params.as_int(4, "src_h must be int", r); + int dx=params.as_int(5, "dest_x must be int", r); + int dy=params.as_int(6, "dest_y must be int", r); + if(params.count()>1+2+2+2) { + int dw=params.as_int(1+2+2+2, "dest_w must be int", r); + int dh=(int)(params.count()>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.count()>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, tolerance); } else