--- parser3/src/classes/image.C 2012/06/15 11:54:18 1.142 +++ parser3/src/classes/image.C 2016/07/21 18:30:10 1.152 @@ -1,7 +1,7 @@ /** @file Parser: @b image parser class. - Copyright (c) 2001-2012 Art. Lebedev Studio (http://www.artlebedev.com) + Copyright (c) 2001-2015 Art. Lebedev Studio (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ @@ -25,7 +25,7 @@ #include "pa_vdate.h" #include "pa_table.h" -volatile const char * IDENT_IMAGE_C="$Id: image.C,v 1.142 2012/06/15 11:54:18 moko Exp $"; +volatile const char * IDENT_IMAGE_C="$Id: image.C,v 1.152 2016/07/21 18:30:10 moko Exp $"; // defines @@ -45,7 +45,7 @@ public: // globals -DECLARE_CLASS_VAR(image, new MImage, 0); +DECLARE_CLASS_VAR(image, new MImage); // helpers @@ -179,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; @@ -230,12 +238,12 @@ public: }; class Measure_file_reader: public Measure_reader { - const String& file_name; const char* fname; + const String& file_name; int f; public: - Measure_file_reader(int af, const String& afile_name, const char* afname): - file_name(afile_name), fname(afname), f(af) { + Measure_file_reader(int af, const String& afile_name): + file_name(afile_name), f(af) { } override size_t read(const char* &abuf, size_t limit) { @@ -243,22 +251,15 @@ 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; } override void seek(long value, int whence) { if(lseek(f, value, whence)<0) - throw Exception(IMAGE_FORMAT, - &file_name, - "seek(value=%ld, whence=%d) failed: %s (%d), actual filename '%s'", - value, whence, strerror(errno), errno, fname); + throw Exception(IMAGE_FORMAT, &file_name, "seek(value=%ld, whence=%d) failed: %s (%d)", value, whence, strerror(errno), errno); } override long tell() { return lseek(f, 0, SEEK_CUR); } @@ -396,8 +397,7 @@ inline uint endian_to_uint(bool is_big, x_endian_to_uint(b[0], b[1], b[2], b[3]); } -static void measure_gif(const String& origin_string, - Measure_reader& reader, ushort& width, ushort& height) { +static void measure_gif(const String& origin_string, Measure_reader& reader, ushort& width, ushort& height) { const char* buf; const size_t head_size=sizeof(GIF_Header); @@ -463,7 +463,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, @@ -479,7 +479,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*/ } } @@ -580,7 +581,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); } @@ -633,8 +634,7 @@ static Value* parse_exif(Measure_reader& return vhash; } -static void measure_jpeg(const String& origin_string, - Measure_reader& reader, ushort& width, ushort& height, Value** exif) { +static void measure_jpeg(const String& origin_string, Measure_reader& reader, ushort& width, ushort& height, Value** exif) { // JFIF format markers const uchar MARKER=0xFF; const uchar CODE_SIZE_A=0xC0; @@ -701,21 +701,16 @@ static void measure_jpeg(const String& o "broken JPEG file - size frame not found"); } -static void measure_png(const String& origin_string, - Measure_reader& reader, ushort& width, ushort& height) { +static void measure_png(const String& origin_string, Measure_reader& reader, ushort& width, ushort& height) { const char* buf; const size_t head_size=sizeof(PNG_Header); if(reader.read(buf, head_size)signature, "IHDR", 4)!=0) - throw Exception(IMAGE_FORMAT, - &origin_string, - "not PNG file - wrong signature"); + throw Exception(IMAGE_FORMAT, &origin_string, "not PNG file - wrong signature"); width=endian_to_ushort(true, head->width); height=endian_to_ushort(true, head->height); @@ -723,8 +718,7 @@ static void measure_png(const String& or // measure center -static void measure(const String& file_name, - Measure_reader& reader, ushort& width, ushort& height, Value** exif) { +static void measure(const String& file_name, Measure_reader& reader, ushort& width, ushort& height, Value** exif) { const char* file_name_cstr=file_name.taint_cstr(String::L_FILE_SPEC); if(const char* cext=strrchr(file_name_cstr, '.')) { cext++; @@ -735,13 +729,9 @@ static void measure(const String& file_n else if(strcasecmp(cext, "PNG")==0) measure_png(file_name, reader, width, height); else - throw Exception(IMAGE_FORMAT, - &file_name, - "unhandled image file name extension '%s'", cext); + throw Exception(IMAGE_FORMAT, &file_name, "unhandled image file name extension '%s'", cext); } else - throw Exception(IMAGE_FORMAT, - &file_name, - "can not determine image type - no file name extension"); + throw Exception(IMAGE_FORMAT, &file_name, "can not determine image type - no file name extension"); } // methods @@ -751,17 +741,13 @@ struct File_measure_action_info { ushort* width; ushort* height; Value** exif; - const String* file_name; }; #endif -static void file_measure_action( - struct stat& /*finfo*/, int f, - const String& /*file_spec*/, const char* fname, bool /*as_text*/, - void *context) { +static void file_measure_action(struct stat& /*finfo*/, int f, const String& file_spec, void *context) { File_measure_action_info& info=*static_cast(context); - Measure_file_reader reader(f, *info.file_name, fname); - measure(*info.file_name, reader, *info.width, *info.height, info.exif); + Measure_file_reader reader(f, file_spec); + measure(file_spec, reader, *info.width, *info.height, info.exif); } static void _measure(Request& r, MethodParams& params) { @@ -774,11 +760,9 @@ static void _measure(Request& r, MethodP if((file_name=data.get_string())) { File_measure_action_info info={ &width, &height, - &exif, - file_name + &exif }; - file_read_action_under_lock(r.absolute(*file_name), - "measure", file_measure_action, &info); + file_read_action_under_lock(r.absolute(*file_name), "measure", file_measure_action, &info); } else { VFile* vfile=data.as_vfile(String::L_AS_IS); file_name=&vfile->fields().get(name_name)->as_string(); @@ -827,7 +811,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); @@ -835,6 +819,7 @@ static void _html(Request& r, MethodPara throw Exception(PARSER_RUNTIME, 0, "attributes must be hash"); + } } { @@ -1141,12 +1126,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++; @@ -1166,7 +1149,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)