--- parser3/src/classes/image.C 2010/10/21 15:06:27 1.136 +++ parser3/src/classes/image.C 2015/10/26 01:21:54 1.150 @@ -1,12 +1,10 @@ /** @file Parser: @b image parser class. - Copyright(c) 2001-2009 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001-2015 Art. Lebedev Studio (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_IMAGE_C="$Date: 2010/10/21 15:06:27 $"; - /* jpegsize: gets the width and height (in pixels) of a jpeg file Andrew Tong, werdna@ugcs.caltech.edu February 14, 1995 @@ -17,11 +15,9 @@ static const char * const IDENT_IMAGE_C= */ #include "pa_config_includes.h" - -#include "pa_vmethod_frame.h" - #include "gif.h" +#include "pa_vmethod_frame.h" #include "pa_common.h" #include "pa_request.h" #include "pa_vfile.h" @@ -29,6 +25,8 @@ static const char * const IDENT_IMAGE_C= #include "pa_vdate.h" #include "pa_table.h" +volatile const char * IDENT_IMAGE_C="$Id: image.C,v 1.150 2015/10/26 01:21:54 moko Exp $"; + // defines static const String spacebar_width_name("space"); @@ -181,6 +179,14 @@ public: EXIF_TAG(0xa40b, DeviceSettingDescription); EXIF_TAG(0xa40c, SubjectDistanceRange); EXIF_TAG(0xa420, ImageUniqueID); + + // other tags + EXIF_TAG(0xa430, CameraOwnerName); + EXIF_TAG(0xa431, BodySerialNumber); + EXIF_TAG(0xa432, LensSpecification); + EXIF_TAG(0xa433, LensManufactor); + EXIF_TAG(0xa434, LensModel); + EXIF_TAG(0xa435, LensSerialNumber); } } exif_tag_value2name; @@ -245,13 +251,9 @@ public: return 0; char* lbuf=new(PointerFreeGC) 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, - &file_name, - "measure failed: actually read %u bytes count not in [0..%u] valid range", - read_size, limit); - + ssize_t read_size=::read(f, lbuf, limit); abuf=lbuf; + if(read_size<0) + throw Exception(0, &file_name, "measure read failed: %s (%d)", strerror(errno), errno); return read_size; } @@ -465,7 +467,7 @@ static Value* parse_IFD_entry_formatted_ } // date.C -tm cstr_to_time_t(char *cstr); +tm cstr_to_time_t(char *, const char **); static Value* parse_IFD_entry_formatted_value(bool is_big, ushort format, size_t component_size, uint components_count, @@ -481,7 +483,8 @@ static Value* parse_IFD_entry_formatted_ strcpy(cstr_writable, cstr); try { - return new VDate(cstr_to_time_t(cstr_writable)); + tm tmIn=cstr_to_time_t(cstr_writable, 0); + return new VDate(tmIn); } catch(...) { /*ignore bad date times*/ } } @@ -582,7 +585,7 @@ static void parse_IFD_entry(HashStringVa if(Value* value=parse_IFD_entry_value(is_big, reader, tiff_base, entry)) { if(const char* name=(gps)?exif_gps_tag_value2name.get(tag):exif_tag_value2name.get(tag)) - hash.put(String::Body(name), value); + hash.put(name, value); else hash.put(String::Body::Format(tag), value); } @@ -829,7 +832,7 @@ static void _html(Request& r, MethodPara if(params.count()) { // for backward compatibility: someday was ^html{} Value& vattribs=r.process_to_value(params[0], false/*don't intercept string*/); - if(!vattribs.is_string()) // allow empty + if(!vattribs.is_string()) { // allow empty if((attribs=vattribs.get_hash())) { Attrib_info info={&tag, 0}; attribs->for_each(append_attrib_pair, &info); @@ -837,6 +840,7 @@ static void _html(Request& r, MethodPara throw Exception(PARSER_RUNTIME, 0, "attributes must be hash"); + } } { @@ -890,18 +894,13 @@ static void _create(Request& r, MethodPa static void _gif(Request& r, MethodParams& params) { gdImage& image=GET_SELF(r, VImage).image(); - const String *file_name=0; - if(params.count()>0) - file_name=¶ms.as_string(0, FILE_NAME_MUST_BE_STRING); + const String *file_name=params.count()>0?¶ms.as_string(0, FILE_NAME_MUST_BE_STRING):0; gdBuf buf=image.Gif(); VFile& vfile=*new VFile; - Value* content_type=new VString(*new String("image/gif")); - vfile.set(false/*not tainted*/, - (const char*)buf.ptr, buf.size, - file_name? file_name->taint_cstr(String::L_FILE_SPEC): 0, - content_type); + + vfile.set_binary(false/*not tainted*/, (const char *)buf.ptr, buf.size, file_name, new VString(*new String("image/gif"))); r.write_no_lang(vfile); } @@ -977,11 +976,7 @@ static void _replace(Request& r, MethodP gdImage::Point* all_p=0; size_t count=0; if(params.count() == 3){ - Table* table=params.as_no_junction(2, COORDINATES_MUST_NOT_BE_CODE).get_table(); - if(!table) - throw Exception(PARSER_RUNTIME, - 0, - "coordinates must be table"); + Table* table=params.as_table(2, "coordinates"); count=table->count(); all_p=new(PointerFreeGC) gdImage::Point[count]; gdImage::Point* add_p=all_p; @@ -1007,11 +1002,7 @@ static void _replace(Request& r, MethodP static void _polyline(Request& r, MethodParams& params) { gdImage& image=GET_SELF(r, VImage).image(); - Table* table=params.as_no_junction(1, COORDINATES_MUST_NOT_BE_CODE).get_table(); - if(!table) - throw Exception(PARSER_RUNTIME, - 0, - "coordinates must be table"); + Table* table=params.as_table(1, "coordinates"); gdImage::Point* all_p=new(PointerFreeGC) gdImage::Point[table->count()]; gdImage::Point *add_p=all_p; @@ -1024,11 +1015,7 @@ static void _polyline(Request& r, Method static void _polygon(Request& r, MethodParams& params) { gdImage& image=GET_SELF(r, VImage).image(); - Table* table=params.as_no_junction(1, COORDINATES_MUST_NOT_BE_CODE).get_table(); - if(!table) - throw Exception(PARSER_RUNTIME, - 0, - "coordinates must be table"); + Table* table=(Table*)params.as_table(1, "coordinates"); gdImage::Point* all_p=new(PointerFreeGC) gdImage::Point[table->count()]; gdImage::Point *add_p=all_p; @@ -1040,11 +1027,7 @@ static void _polygon(Request& r, MethodP static void _polybar(Request& r, MethodParams& params) { gdImage& image=GET_SELF(r, VImage).image(); - Table* table=params.as_no_junction(1, COORDINATES_MUST_NOT_BE_CODE).get_table(); - if(!table) - throw Exception(PARSER_RUNTIME, - 0, - "coordinates must be table"); + Table* table=(Table*)params.as_table(1, "coordinates"); gdImage::Point* all_p=new(PointerFreeGC) gdImage::Point[table->count()]; gdImage::Point *add_p=all_p; @@ -1164,12 +1147,10 @@ static void _font(Request& r, MethodPara int monospace_width=0; // proportional int letter_spacing=1; if(params.count()>2){ - if(HashStringValue* options=params.as_no_junction(2, "param must be int or hash").get_hash()){ + if(HashStringValue* options=params[2].get_hash()){ // third option is hash if(params.count()>3) - throw Exception(PARSER_RUNTIME, - 0, - "too many options were specified"); + throw Exception(PARSER_RUNTIME, 0, "too many params were specified"); int valid_options=0; if(Value* vspacebar_width=options->get(spacebar_width_name)){ valid_options++; @@ -1189,7 +1170,7 @@ static void _font(Request& r, MethodPara throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION); } else { // backward - spacebar_width=params.as_int(2, "spacebar_width must be int", r); + spacebar_width=params.as_int(2, "param must be int or hash", r); if(params.count()>3) { monospace_width=params.as_int(3, "monospace_width must be int", r); if(!monospace_width)