--- parser3/src/classes/image.C 2003/03/04 15:59:18 1.90.2.15 +++ parser3/src/classes/image.C 2003/03/20 09:41:44 1.90.2.15.2.5 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_IMAGE_C="$Date: 2003/03/04 15:59:18 $"; +static const char* IDENT_IMAGE_C="$Date: 2003/03/20 09:41:44 $"; /* jpegsize: gets the width and height (in pixels) of a jpeg file @@ -155,27 +155,27 @@ public: #ifndef DOXYGEN class Measure_reader { public: - virtual size_t read(const char *&buf, size_t limit)=0; + virtual size_t read(const char* &buf, size_t limit)=0; virtual void seek(long value, int whence)=0; virtual long tell()=0; }; class Measure_file_reader: public Measure_reader { - Pool& pool; - StringPtr file_name; const char* fname; + ; + const String& file_name; const char* fname; int f; public: - Measure_file_reader(Pool& apool, int af, StringPtr afile_name, const char* afname): - pool(apool), file_name(afile_name), fname(afname), f(af) { + Measure_file_reader(int af, const String& afile_name, const char* afname): + pool(), file_name(afile_name), fname(afname), f(af) { } - override size_t read(const char *&abuf, size_t limit) { + override size_t read(const char* &abuf, size_t limit) { if(limit==0) return 0; - char* lbuf=new(pool) char[limit]; + char* lbuf=new char[limit]; size_t read_size=(size_t)::read(f, lbuf, limit); abuf=lbuf; if(ssize_t(read_size)<0 || read_size>limit) throw Exception(0, @@ -201,16 +201,16 @@ public: class Measure_buf_reader: public Measure_reader { const char* buf; size_t size; - StringPtr file_name; + const String& file_name; size_t offset; public: - Measure_buf_reader(const char* abuf, size_t asize, StringPtr afile_name): + Measure_buf_reader(const char* abuf, size_t asize, const String& afile_name): buf(abuf), size(asize), file_name(afile_name), offset(0) { } - override size_t read(const char *&abuf, size_t limit) { + override size_t read(const char* &abuf, size_t limit) { size_t to_read=min(limit, size-offset); abuf=buf+offset; offset+=to_read; @@ -223,8 +223,8 @@ public: case SEEK_CUR: new_offset=offset+value; break; case SEEK_SET: new_offset=(size_t)value; break; default: - throw Exception(Exception::undefined_type, - Exception::undefined_source, + throw Exception(0, + 0, "whence #%d not supported", 0, whence); break; // never } @@ -327,10 +327,10 @@ inline uint endian_to_uint(bool is_big, x_endian_to_uint(b[0], b[1], b[2], b[3]); } -static void measure_gif(Pool& pool, StringPtr origin_string, +static void measure_gifconst String* origin_string, Measure_reader& reader, ushort& width, ushort& height) { - const char *buf; + const char* buf; const int head_size=sizeof(GIF_Header); if(reader.read(buf, head_size)height); } -static ValuePtr parse_IFD_entry_formatted_one_value(Pool& pool, +static ValuePtr parse_IFD_entry_formatted_one_value( bool is_big, ushort format, size_t component_size, @@ -394,9 +394,9 @@ static ValuePtr parse_IFD_entry_formatte } // date.C -time_t cstr_to_time_t(char *cstr, StringPtr report_error_origin); +time_t cstr_to_time_t(char *cstr, const String& report_error_origin); -static ValuePtr parse_IFD_entry_formatted_value(Pool& pool, +static ValuePtr parse_IFD_entry_formatted_value( bool is_big, ushort format, size_t component_size, uint components_count, const uchar *value) { @@ -411,32 +411,32 @@ static ValuePtr parse_IFD_entry_formatte strcpy(cstr_writable, cstr); time_t t=cstr_to_time_t(cstr_writable, - StringPtr(0)/* do not throw exception, just return bad result */); + 0/* do not throw exception, just return bad result */); if(t>=0) return ValuePtr(new VDate(t)); } if(const char* premature_zero_pos=(const char* )memchr(cstr, 0, size)) size=premature_zero_pos-cstr; - return ValuePtr(new VString(StringPtr(new String(cstr, size, true/*tainted*/)))); + return ValuePtr(new VString(String* (new String(cstr, size, true/*tainted*/)))); } if(components_count==1) - return parse_IFD_entry_formatted_one_value(pool, is_big, format, component_size, value); + return parse_IFD_entry_formatted_one_value(is_big, format, component_size, value); VHashPtr result(new VHash); - HashStringValue& hash=result->hash(Exception::undefined_source); + HashStringValue& hash=result->hash(0); for(uint i=0; ihash(Exception::undefined_source), is_big, reader, tiff_base); + parse_IFD(vhash->hash(0), is_big, reader, tiff_base); return vhash; } -static void measure_jpeg(Pool& pool, StringPtr origin_string, +static void measure_jpegconst String* origin_string, Measure_reader& reader, ushort& width, ushort& height, ValuePtr* exif) { // JFIF format markers const uchar MARKER=0xFF; @@ -582,7 +582,7 @@ static void measure_jpeg(Pool& pool, Str const uchar CODE_SIZE_D=0xC3; const uchar CODE_EXIF=0xE1; - const char *buf; + const char* buf; const size_t prefix_size=2; if(reader.read(buf, prefix_size)cstr(String::UL_FILE_SPEC); + const char* file_name_cstr=file_name->cstr(String::UL_FILE_SPEC); if(const char* cext=strrchr(file_name_cstr, '.')) { cext++; if(strcasecmp(cext, "GIF")==0) - measure_gif(pool, file_name, reader, width, height); + measure_gif(file_name, reader, width, height); else if(strcasecmp(cext, "JPG")==0 || strcasecmp(cext, "JPEG")==0) - measure_jpeg(pool, file_name, reader, width, height, exif); + measure_jpeg(file_name, reader, width, height, exif); else if(strcasecmp(cext, "PNG")==0) - measure_png(pool, file_name, reader, width, height); + measure_png(file_name, reader, width, height); else throw Exception("image.format", file_name, @@ -690,45 +690,44 @@ struct File_measure_action_info { ushort* width; ushort* height; ValuePtr* exif; - StringPtr file_name; + const String& file_name; }; #endif -static void file_measure_action(Pool& pool, +static void file_measure_action( struct stat& finfo, int f, - StringPtr file_spec, const char* fname, bool as_text, + const String& file_spec, const char* fname, bool as_text, void *context) { File_measure_action_info& info=*static_cast(context); - Measure_file_reader reader(pool, f, info.file_name, fname); - measure(pool, info.file_name, reader, *info.width, *info.height, info.exif); + Measure_file_reader reader(f, info.file_name, fname); + measure(info.file_name, reader, *info.width, *info.height, info.exif); } -static void _measure(Request& r, StringPtr method_name, MethodParams* params) { - Pool& pool=r.pool(); +static void _measure(Request& r, const String& method_name, MethodParams* params) { ValuePtr data=params->as_no_junction(0, "data must not be code"); ushort width=0; ushort height=0; ValuePtr exif(0); - StringPtr file_name; + const String& file_name; if(file_name=data->get_string(&pool)) { File_measure_action_info info; info.width=&width; info.height=&height; info.exif=&exif; info.file_name=file_name; - file_read_action_under_lock(pool, r.absolute(file_name), + file_read_action_under_lock(r.absolute(file_name), "measure", file_measure_action, &info); } else { - VFilePtr vfile=data->as_vfile(pool); + VFilePtr vfile=data->as_vfile(); file_name=vfile->fields().get(name_name)->as_string(&pool); Measure_buf_reader reader( vfile->value_ptr(), vfile->value_size(), file_name ); - measure(pool, file_name, reader, width, height, &exif); + measure(file_name, reader, width, height, &exif); } GET_SELF(r, VImage).set(file_name, width, height, gdImagePtr(0), exif); @@ -736,7 +735,7 @@ static void _measure(Request& r, StringP #ifndef DOXYGEN struct Attrib_info { - Pool* pool; + ; String* tag; ///< html tag being constructed HashStringValue* skip; ///< tag attributes not to append to tag string [to skip] }; @@ -754,8 +753,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) { - Pool& pool=r.pool(); +static void _html(Request& r, const String& method_name, MethodParams* params) { String tag; tag << "is_string()) // allow empty if(attribs=vattribs->get_hash(method_name)) { - Attrib_info info={&pool, &tag}; + Attrib_info info={&&tag}; attribs->for_each(append_attrib_pair, &info); } else throw Exception("parser.runtime", @@ -779,7 +777,7 @@ static void _html(Request& r, StringPtr } { - Attrib_info info={&pool, &tag, attribs}; + Attrib_info info={&&tag, attribs}; fields.for_each(append_attrib_pair, &info); } tag << " />"; @@ -787,11 +785,10 @@ static void _html(Request& r, StringPtr } /// @test wrap FILE to auto-object -static gdImagePtr load(Request& r, StringPtr method_name, - StringPtr file_name){ - Pool& pool=r.pool(); +static gdImagePtr load(Request& r, const String& method_name, + const String& file_name){ - CharPtr file_name_cstr=r.absolute(file_name)->cstr(String::UL_FILE_SPEC); + const char* file_name_cstr=r.absolute(file_name)->cstr(String::UL_FILE_SPEC); if(FILE *f=fopen(file_name_cstr, "rb")) { gdImagePtr image(new gdImage); bool ok=image->CreateFromGif(f); @@ -810,17 +807,15 @@ static gdImagePtr load(Request& r, Strin } -static void _load(Request& r, StringPtr method_name, MethodParams* params) { - Pool& pool=r.pool(); +static void _load(Request& r, const String& method_name, MethodParams* params) { - StringPtr 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"); 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) { - Pool& pool=r.pool(); +static void _create(Request& r, const String& method_name, MethodParams* params) { int width=params->as_int(0, "width must be int", r); int height=params->as_int(1, "height must be int", r); @@ -830,11 +825,10 @@ static void _create(Request& r, StringPt 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); + GET_SELF(r, VImage).set(0, width, height, image); } -static void _gif(Request& r, StringPtr method_name, MethodParams* params) { - Pool& pool=r.pool(); +static void _gif(Request& r, const String& method_name, MethodParams* params) { gdImagePtr image=GET_SELF(r, VImage).image; if(!image) @@ -844,18 +838,17 @@ static void _gif(Request& r, StringPtr m // could _ but don't thing it's wise to use $image.src for vfile.name - String out; image->Gif(pool, out); + String out; image->Gif(out); VFilePtr vfile(new VFile); - ValuePtr content_type(new VString(StringPtr(new String("image/gif")))); - vfile->set(pool, false/*not tainted*/, - out.cstr(pool), out.size(), 0, content_type); + ValuePtr content_type(new VString(String* (new String("image/gif")))); + vfile->set(false/*not tainted*/, + out.cstr(), out.size(), 0, content_type); r.write_no_lang(vfile); } -static void _line(Request& r, StringPtr method_name, MethodParams* params) { - Pool& pool=r.pool(); +static void _line(Request& r, const String& method_name, MethodParams* params) { gdImagePtr image=GET_SELF(r, VImage).image; if(!image) @@ -871,8 +864,7 @@ static void _line(Request& r, StringPtr image->Color(params->as_int(4, "color must be int", r))); } -static void _fill(Request& r, StringPtr method_name, MethodParams* params) { - Pool& pool=r.pool(); +static void _fill(Request& r, const String& method_name, MethodParams* params) { gdImagePtr image=GET_SELF(r, VImage).image; if(!image) @@ -886,8 +878,7 @@ static void _fill(Request& r, StringPtr image->Color(params->as_int(2, "color must be int", r))); } -static void _rectangle(Request& r, StringPtr method_name, MethodParams* params) { - Pool& pool=r.pool(); +static void _rectangle(Request& r, const String& method_name, MethodParams* params) { gdImagePtr image=GET_SELF(r, VImage).image; if(!image) @@ -903,8 +894,7 @@ static void _rectangle(Request& r, Strin image->Color(params->as_int(4, "color must be int", r))); } -static void _bar(Request& r, StringPtr method_name, MethodParams* params) { - Pool& pool=r.pool(); +static void _bar(Request& r, const String& method_name, MethodParams* params) { gdImagePtr image=GET_SELF(r, VImage).image; if(!image) @@ -928,8 +918,7 @@ static void add_point(Table::element_typ (*p)++; } #endif -static void _replace(Request& r, StringPtr method_name, MethodParams* params) { - Pool& pool=r.pool(); +static void _replace(Request& r, const String& method_name, MethodParams* params) { gdImagePtr image=GET_SELF(r, VImage).image; if(!image) @@ -943,7 +932,7 @@ static void _replace(Request& r, StringP method_name, "coordinates must be table"); - gdImage::Point *all_p=new(pool) gdImage::Point[table->count()]; + gdImage::Point *all_p=new gdImage::Point[table->count()]; gdImage::Point *add_p=all_p; table->for_each(add_point, &add_p); image->FilledPolygonReplaceColor(all_p, table->count(), @@ -951,8 +940,7 @@ static void _replace(Request& r, StringP image->Color(params->as_int(1, "dest color must be int", r))); } -static void _polyline(Request& r, StringPtr method_name, MethodParams* params) { - Pool& pool=r.pool(); +static void _polyline(Request& r, const String& method_name, MethodParams* params) { gdImagePtr image=GET_SELF(r, VImage).image; if(!image) @@ -966,7 +954,7 @@ static void _polyline(Request& r, String method_name, "coordinates must be table"); - gdImage::Point* all_p=new(pool) gdImage::Point[table->count()]; + gdImage::Point* all_p=new gdImage::Point[table->count()]; gdImage::Point *add_p=all_p; table->for_each(add_point, &add_p); image->Polygon(all_p, table->count(), @@ -974,8 +962,7 @@ static void _polyline(Request& r, String false/*not closed*/); } -static void _polygon(Request& r, StringPtr method_name, MethodParams* params) { - Pool& pool=r.pool(); +static void _polygon(Request& r, const String& method_name, MethodParams* params) { gdImagePtr image=GET_SELF(r, VImage).image; if(!image) @@ -989,15 +976,14 @@ static void _polygon(Request& r, StringP method_name, "coordinates must be table"); - gdImage::Point* all_p=new(pool) gdImage::Point[table->count()]; + gdImage::Point* all_p=new gdImage::Point[table->count()]; 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))); } -static void _polybar(Request& r, StringPtr method_name, MethodParams* params) { - Pool& pool=r.pool(); +static void _polybar(Request& r, const String& method_name, MethodParams* params) { gdImagePtr image=GET_SELF(r, VImage).image; if(!image) @@ -1011,7 +997,7 @@ static void _polybar(Request& r, StringP method_name, "coordinates must be table"); - gdImage::Point* all_p=new(pool) gdImage::Point[table->count()]; + gdImage::Point* all_p=new gdImage::Point[table->count()]; gdImage::Point *add_p=all_p; table->for_each(add_point, &add_p); image->FilledPolygon(all_p, table->count(), @@ -1026,8 +1012,8 @@ static void _polybar(Request& r, StringP const int Font::letter_spacing=1; -Font::Font(//Pool& pool, - StringPtr aalphabet, +Font::Font(//, + const String& aalphabet, gdImagePtr aifont, int aheight, int amonospace, int aspacebarspace): alphabet(aalphabet), height(aheight), monospace(amonospace), spacebarspace(aspacebarspace), @@ -1065,16 +1051,16 @@ int Font::step_width(int index) { } // counts trailing letter_spacing, consider this OK. useful for contiuations -int Font::string_width(StringPtr s){ - CharPtr cstr=s->cstr(); +int Font::string_width(const String& s){ + const char* cstr=s->cstr(); int result=0; for(const char* current=cstr; *current; current++) result+=step_width(index_of(*current)); return result; } -void Font::string_display(gdImagePtr image, int x, int y, StringPtr s){ - CharPtr cstr=s->cstr(); +void Font::string_display(gdImagePtr image, int x, int y, const String& s){ + const char* cstr=s->cstr(); for(const char* current=cstr; *current; current++) { int index=index_of(*current); index_display(image, x, y, index); @@ -1085,10 +1071,9 @@ void Font::string_display(gdImagePtr ima // -static void _font(Request& r, StringPtr method_name, MethodParams* params) { - Pool& pool=r.pool(); +static void _font(Request& r, const String& method_name, MethodParams* params) { - StringPtr alphabet=params->as_string(0, "alphabet must not be code"); + const String& 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; @@ -1110,18 +1095,17 @@ static void _font(Request& r, StringPtr "font-file height(%d) not divisable by alphabet size(%d), remainder=%d", image->SY(), alphabet->size(), remainder); - GET_SELF(r, VImage).font=FontPtr(new Font(//pool, + GET_SELF(r, VImage).font=FontPtr(new Font(// alphabet, image, image->SY() / alphabet->size(), monospace_width, spacebar_width)); } -static void _text(Request& r, StringPtr method_name, MethodParams* params) { - Pool& pool=r.pool(); +static void _text(Request& r, const String& method_name, MethodParams* params) { 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"); + const String& s=params->as_string(2, "text must not be code"); VImage& vimage=GET_SELF(r, VImage); if(vimage.image) @@ -1137,10 +1121,9 @@ static void _text(Request& r, StringPtr "does not contain an image"); } -static void _length(Request& r, StringPtr method_name, MethodParams* params) { - Pool& pool=r.pool(); +static void _length(Request& r, const String& method_name, MethodParams* params) { - const StringPtr s=params->as_string(0, "text must not be code"); + const const String& s=params->as_string(0, "text must not be code"); VImage& vimage=GET_SELF(r, VImage); if(vimage.image) @@ -1156,8 +1139,7 @@ static void _length(Request& r, StringPt "does not contain an image"); } -static void _arc(Request& r, StringPtr method_name, MethodParams* params) { - Pool& pool=r.pool(); +static void _arc(Request& r, const String& method_name, MethodParams* params) { gdImagePtr image=GET_SELF(r, VImage).image; if(!image) @@ -1175,8 +1157,7 @@ static void _arc(Request& r, StringPtr m image->Color(params->as_int(6, "cx must be int", r))); } -static void _sector(Request& r, StringPtr method_name, MethodParams* params) { - Pool& pool=r.pool(); +static void _sector(Request& r, const String& method_name, MethodParams* params) { gdImagePtr image=GET_SELF(r, VImage).image; if(!image) @@ -1194,8 +1175,7 @@ static void _sector(Request& r, StringPt image->Color(params->as_int(6, "color must be int", r))); } -static void _circle(Request& r, StringPtr method_name, MethodParams* params) { - Pool& pool=r.pool(); +static void _circle(Request& r, const String& method_name, MethodParams* params) { gdImagePtr image=GET_SELF(r, VImage).image; if(!image) @@ -1214,7 +1194,7 @@ static void _circle(Request& r, StringPt image->Color(params->as_int(3, "color must be int", r))); } -gdImagePtr as_image(Pool& pool, StringPtr method_name, MethodParams* params, +gdImagePtr as_imageconst String& method_name, MethodParams* params, int index, const char* msg) { gdImagePtr src(0); @@ -1234,8 +1214,7 @@ gdImagePtr as_image(Pool& pool, StringPt return src; } -static void _copy(Request& r, StringPtr method_name, MethodParams* params) { - Pool& pool=r.pool(); +static void _copy(Request& r, const String& method_name, MethodParams* params) { gdImagePtr dest=GET_SELF(r, VImage).image; if(!dest) @@ -1243,7 +1222,7 @@ static void _copy(Request& r, StringPtr method_name, "self does not contain an image"); - gdImagePtr src=as_image(pool, method_name, params, 0, "src must be image"); + gdImagePtr src=as_image(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);