--- parser3/src/classes/image.C 2015/09/18 00:08:12 1.147 +++ parser3/src/classes/image.C 2016/10/04 22:05:28 1.154 @@ -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.147 2015/09/18 00:08:12 moko Exp $"; +volatile const char * IDENT_IMAGE_C="$Id: image.C,v 1.154 2016/10/04 22:05:28 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) { @@ -251,10 +259,7 @@ public: 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); } @@ -392,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); @@ -577,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); } @@ -630,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; @@ -698,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); @@ -720,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++; @@ -732,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 @@ -748,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) { @@ -771,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(); @@ -823,7 +810,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*/); + Value& vattribs=r.process(params[0]); if(!vattribs.is_string()) { // allow empty if((attribs=vattribs.get_hash())) { Attrib_info info={&tag, 0}; @@ -1146,17 +1133,17 @@ static void _font(Request& r, MethodPara int valid_options=0; if(Value* vspacebar_width=options->get(spacebar_width_name)){ valid_options++; - spacebar_width=r.process_to_value(*vspacebar_width).as_int(); + spacebar_width=r.process(*vspacebar_width).as_int(); } if(Value* vmonospace_width=options->get(monospace_width_name)){ valid_options++; - monospace_width=r.process_to_value(*vmonospace_width).as_int(); + monospace_width=r.process(*vmonospace_width).as_int(); if(!monospace_width) monospace_width=image->SX(); } if(Value* vletter_spacing=options->get(letter_spacing_name)){ valid_options++; - letter_spacing=r.process_to_value(*vletter_spacing).as_int(); + letter_spacing=r.process(*vletter_spacing).as_int(); } if(valid_options!=options->count()) throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION);