--- parser3/src/classes/image.C 2003/02/06 15:33:14 1.90.2.7 +++ parser3/src/classes/image.C 2003/03/04 12:38:15 1.90.2.13 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_IMAGE_C="$Date: 2003/02/06 15:33:14 $"; +static const char* IDENT_IMAGE_C="$Date: 2003/03/04 12:38:15 $"; /* jpegsize: gets the width and height (in pixels) of a jpeg file @@ -31,7 +31,7 @@ static const char* IDENT_IMAGE_C="$Date: // class -class MImage : public Methoded { +class MImage: public Methoded { public: // VStateless_class ValuePtr create_new_value() { return ValuePtr(new VImage()); } @@ -45,7 +45,7 @@ public: // Methoded // globals -MethodedPtr image_class(new MImage); +DECLARE_CLASS_VAR(image, new MImage, 0); // helpers @@ -394,7 +394,7 @@ static ValuePtr parse_IFD_entry_formatte } // date.C -time_t cstr_to_time_t(char *cstr, const String *report_error_origin); +time_t cstr_to_time_t(char *cstr, StringPtr report_error_origin); static ValuePtr parse_IFD_entry_formatted_value(Pool& pool, bool is_big, ushort format, @@ -410,7 +410,8 @@ static ValuePtr parse_IFD_entry_formatte char cstr_writable[JPEG_EXIF_DATE_CHARS]; strcpy(cstr_writable, cstr); - time_t t=cstr_to_time_t(cstr_writable, 0/* do not throw exception, just return bad result */); + time_t t=cstr_to_time_t(cstr_writable, + StringPtr(0)/* do not throw exception, just return bad result */); if(t>=0) return ValuePtr(new VDate(t)); } @@ -513,12 +514,12 @@ static void parse_IFD_entry(Pool& pool, } if(ValuePtr value=parse_IFD_entry_value(pool, is_big, reader, tiff_base, entry)) { - char *key_cstr=new(pool) char[MAX_NUMBER]; - StringPtr skey(new String(key_cstr, snprintf(key_cstr, MAX_NUMBER, "%u", tag))); - if(const char* name=exif_tag_value2name.get(skey)) + if(const char* name=exif_tag_value2name.get(tag)) hash.put(StringPtr(new String(name)), value); - else + else { + StringPtr skey(new String(pool.format_integer(tag))); hash.put(skey, value); + } } } @@ -702,10 +703,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, StringPtr method_name, MethodParams& params) { +static void _measure(Request& r, StringPtr method_name, MethodParams* params) { Pool& pool=r.pool(); - ValuePtr data=params.as_no_junction(0, "data must not be code"); + ValuePtr data=params->as_no_junction(0, "data must not be code"); ushort width=0; ushort height=0; @@ -753,7 +754,7 @@ static void append_attrib_pair( if(value->is_string() || value->as_int()>=0) *info->tag << "=\"" << value->as_string(info->pool) << "\""; } -static void _html(Request& r, StringPtr method_name, MethodParams& params) { +static void _html(Request& r, StringPtr method_name, MethodParams* params) { Pool& pool=r.pool(); String tag; @@ -762,9 +763,9 @@ static void _html(Request& r, StringPtr const HashStringValue& fields=GET_SELF(r, VImage).fields(); HashStringValue* attribs=0; - if(params.count()) { + if(params->count()) { // for backward compatibility: someday was ^html{} - ValuePtr vattribs=r.process_to_value(params.get(0), + ValuePtr vattribs=r.process_to_value(params->get(0), /*0/*no name* /,*/ false/*don't intercept string*/); if(!vattribs->is_string()) // allow empty @@ -809,30 +810,30 @@ static gdImagePtr load(Request& r, Strin } -static void _load(Request& r, StringPtr method_name, MethodParams& params) { +static void _load(Request& r, StringPtr method_name, MethodParams* params) { Pool& pool=r.pool(); - StringPtr file_name=params.as_string(0, "file name must not be code"); + StringPtr file_name=params->as_string(0, "file name must not be code"); gdImagePtr image=load(r, method_name, file_name); GET_SELF(r, VImage).set(file_name, image->SX(), image->SY(), image); } -static void _create(Request& r, StringPtr 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.count()>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); gdImagePtr image(new gdImage); image->Create(width, height); image->FilledRectangle(0, 0, width-1, height-1, image->Color(bgcolor_value)); GET_SELF(r, VImage).set(StringPtr(0), width, height, image); } -static void _gif(Request& r, StringPtr method_name, MethodParams& params) { +static void _gif(Request& r, StringPtr method_name, MethodParams* params) { Pool& pool=r.pool(); gdImagePtr image=GET_SELF(r, VImage).image; @@ -848,12 +849,12 @@ static void _gif(Request& r, StringPtr m VFilePtr vfile(new VFile); ValuePtr content_type(new VString(StringPtr(new String("image/gif")))); vfile->set(pool, false/*not tainted*/, - out.cstr(), out.size(), 0, content_type); + out.cstr(pool), out.size(), 0, content_type); r.write_no_lang(vfile); } -static void _line(Request& r, StringPtr method_name, MethodParams& params) { +static void _line(Request& r, StringPtr method_name, MethodParams* params) { Pool& pool=r.pool(); gdImagePtr image=GET_SELF(r, VImage).image; @@ -863,14 +864,14 @@ static void _line(Request& r, StringPtr "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, StringPtr method_name, MethodParams& params) { +static void _fill(Request& r, StringPtr method_name, MethodParams* params) { Pool& pool=r.pool(); gdImagePtr image=GET_SELF(r, VImage).image; @@ -880,12 +881,12 @@ static void _fill(Request& r, StringPtr "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, StringPtr method_name, MethodParams& params) { +static void _rectangle(Request& r, StringPtr method_name, MethodParams* params) { Pool& pool=r.pool(); gdImagePtr image=GET_SELF(r, VImage).image; @@ -895,14 +896,14 @@ static void _rectangle(Request& r, Strin "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, StringPtr method_name, MethodParams& params) { +static void _bar(Request& r, StringPtr method_name, MethodParams* params) { Pool& pool=r.pool(); gdImagePtr image=GET_SELF(r, VImage).image; @@ -912,11 +913,11 @@ static void _bar(Request& r, StringPtr m "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 @@ -927,7 +928,7 @@ static void add_point(Table::element_typ (*p)++; } #endif -static void _replace(Request& r, StringPtr method_name, MethodParams& params) { +static void _replace(Request& r, StringPtr method_name, MethodParams* params) { Pool& pool=r.pool(); gdImagePtr image=GET_SELF(r, VImage).image; @@ -936,7 +937,7 @@ static void _replace(Request& r, StringP 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, @@ -946,11 +947,11 @@ static void _replace(Request& r, StringP gdImage::Point *add_p=all_p; table->for_each(add_point, &add_p); image->FilledPolygonReplaceColor(all_p, table->count(), - 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, StringPtr method_name, MethodParams& params) { +static void _polyline(Request& r, StringPtr method_name, MethodParams* params) { Pool& pool=r.pool(); gdImagePtr image=GET_SELF(r, VImage).image; @@ -959,7 +960,7 @@ static void _polyline(Request& r, String 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, @@ -969,11 +970,11 @@ static void _polyline(Request& r, String gdImage::Point *add_p=all_p; table->for_each(add_point, &add_p); 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*/); } -static void _polygon(Request& r, StringPtr method_name, MethodParams& params) { +static void _polygon(Request& r, StringPtr method_name, MethodParams* params) { Pool& pool=r.pool(); gdImagePtr image=GET_SELF(r, VImage).image; @@ -982,7 +983,7 @@ static void _polygon(Request& r, StringP 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, @@ -992,10 +993,10 @@ static void _polygon(Request& r, StringP gdImage::Point *add_p=all_p; table->for_each(add_point, &add_p); 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, StringPtr method_name, MethodParams& params) { +static void _polybar(Request& r, StringPtr method_name, MethodParams* params) { Pool& pool=r.pool(); gdImagePtr image=GET_SELF(r, VImage).image; @@ -1004,7 +1005,7 @@ static void _polybar(Request& r, StringP 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, @@ -1014,7 +1015,7 @@ static void _polybar(Request& r, StringP gdImage::Point *add_p=all_p; table->for_each(add_point, &add_p); 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 @@ -1072,17 +1073,17 @@ public: // counts trailing letter_spacing, consider this OK. useful for contiuations int string_width(StringPtr s){ - const char* cstr=s->cstr(); + CharPtr cstr=s->cstr(); int result=0; - for(; *cstr; cstr++) - result+=step_width(index_of(*cstr)); + for(const char* current=cstr; *current; current++) + result+=step_width(index_of(*current)); return result; } void string_display(gdImagePtr image, int x, int y, StringPtr s){ - const char* cstr=s->cstr(); - if(cstr) for(; *cstr; cstr++) { - int index=index_of(*cstr); + CharPtr cstr=s->cstr(); + for(const char* current=cstr; *current; current++) { + int index=index_of(*current); index_display(image, x, y, index); x+=step_width(index); } @@ -1091,15 +1092,15 @@ public: }; const int Font::letter_spacing=1; -static void _font(Request& r, StringPtr method_name, MethodParams& params) { +static void _font(Request& r, StringPtr method_name, MethodParams* params) { Pool& pool=r.pool(); - StringPtr alphabet=params.as_string(0, "alphabet must not be code"); - gdImagePtr 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); + StringPtr alphabet=params->as_string(0, "alphabet must not be code"); + gdImagePtr 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.count()>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 @@ -1122,12 +1123,12 @@ static void _font(Request& r, StringPtr image->SY() / alphabet->size(), monospace_width, spacebar_width)); } -static void _text(Request& r, StringPtr 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); - StringPtr 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); + StringPtr s=params->as_string(2, "text must not be code"); VImage& vimage=GET_SELF(r, VImage); if(vimage.image) @@ -1143,10 +1144,10 @@ static void _text(Request& r, StringPtr "does not contain an image"); } -static void _length(Request& r, StringPtr method_name, MethodParams& params) { +static void _length(Request& r, StringPtr method_name, MethodParams* params) { Pool& pool=r.pool(); - const StringPtr s=params.as_string(0, "text must not be code"); + const StringPtr s=params->as_string(0, "text must not be code"); VImage& vimage=GET_SELF(r, VImage); if(vimage.image) @@ -1162,7 +1163,7 @@ static void _length(Request& r, StringPt "does not contain an image"); } -static void _arc(Request& r, StringPtr method_name, MethodParams& params) { +static void _arc(Request& r, StringPtr method_name, MethodParams* params) { Pool& pool=r.pool(); gdImagePtr image=GET_SELF(r, VImage).image; @@ -1172,16 +1173,16 @@ static void _arc(Request& r, StringPtr m "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, StringPtr method_name, MethodParams& params) { +static void _sector(Request& r, StringPtr method_name, MethodParams* params) { Pool& pool=r.pool(); gdImagePtr image=GET_SELF(r, VImage).image; @@ -1191,16 +1192,16 @@ static void _sector(Request& r, StringPt "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, StringPtr method_name, MethodParams& params) { +static void _circle(Request& r, StringPtr method_name, MethodParams* params) { Pool& pool=r.pool(); gdImagePtr image=GET_SELF(r, VImage).image; @@ -1209,22 +1210,22 @@ static void _circle(Request& r, StringPt 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))); } -gdImagePtr as_image(Pool& pool, StringPtr method_name, MethodParams& params, +gdImagePtr as_image(Pool& pool, StringPtr method_name, MethodParams* params, int index, const char* msg) { gdImagePtr src(0); - ValuePtr value=params.as_no_junction(index, msg); + ValuePtr value=params->as_no_junction(index, msg); if(Value* vimage=value->as(VIMAGE_TYPE, false)) { src=static_cast(vimage)->image; @@ -1240,7 +1241,7 @@ gdImagePtr as_image(Pool& pool, StringPt return src; } -static void _copy(Request& r, StringPtr method_name, MethodParams& params) { +static void _copy(Request& r, StringPtr method_name, MethodParams* params) { Pool& pool=r.pool(); gdImagePtr dest=GET_SELF(r, VImage).image; @@ -1251,18 +1252,18 @@ static void _copy(Request& r, StringPtr gdImagePtr 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.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; + 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