|
|
| version 1.178, 2020/12/07 23:18:40 | version 1.185, 2024/09/11 21:07:36 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: @b image parser class. | Parser: @b image parser class. |
| Copyright (c) 2001-2017 Art. Lebedev Studio (http://www.artlebedev.com) | Copyright (c) 2001-2023 Art. Lebedev Studio (http://www.artlebedev.com) |
| Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) | Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru> |
| */ | */ |
| /* | /* |
| Line 308 struct Measure_info { | Line 308 struct Measure_info { |
| Value** exif; | Value** exif; |
| Value** xmp; | Value** xmp; |
| Charset* xmp_charset; | Charset* xmp_charset; |
| bool video; | |
| }; | }; |
| Line 420 static Value* parse_IFD_entry_formatted_ | Line 421 static Value* parse_IFD_entry_formatted_ |
| size_t length=components_count; | size_t length=components_count; |
| // Data format is "YYYY:MM:DD HH:MM:SS"+0x00, total 20bytes | // Data format is "YYYY:MM:DD HH:MM:SS"+0x00, total 20bytes |
| if(length==JPEG_EXIF_DATE_CHARS && isdigit((unsigned char)cstr[0]) && cstr[length-1]==0) { | if(length==JPEG_EXIF_DATE_CHARS && isdigit((unsigned char)cstr[0]) && cstr[length-1]==0) { |
| char cstr_writable[JPEG_EXIF_DATE_CHARS]; | |
| strcpy(cstr_writable, cstr); | |
| try { | try { |
| tm tmIn=cstr_to_time_t(cstr_writable, 0); | tm tmIn=cstr_to_time_t(pa_strdup(cstr), 0); |
| return new VDate(tmIn); | return new VDate(tmIn); |
| } | } |
| catch(...) { /*ignore bad date times*/ } | catch(...) { /*ignore bad date times*/ } |
| Line 440 static Value* parse_IFD_entry_formatted_ | Line 438 static Value* parse_IFD_entry_formatted_ |
| HashStringValue& hash=result->hash(); | HashStringValue& hash=result->hash(); |
| for(uint i=0; i<components_count; i++, value+=component_size) { | for(uint i=0; i<components_count; i++, value+=component_size) { |
| hash.put( | hash.put( |
| String::Body::Format(i), | pa_uitoa(i), |
| parse_IFD_entry_formatted_one_value(is_big, format, component_size, value)); | parse_IFD_entry_formatted_one_value(is_big, format, component_size, value)); |
| } | } |
| Line 517 static void parse_IFD_entry(HashStringVa | Line 515 static void parse_IFD_entry(HashStringVa |
| if(const char* name=(gps)?exif_gps_tag_value2name.get(tag):exif_tag_value2name.get(tag)) | if(const char* name=(gps)?exif_gps_tag_value2name.get(tag):exif_tag_value2name.get(tag)) |
| hash.put(name, value); | hash.put(name, value); |
| else | else |
| hash.put(String::Body::Format(tag), value); | hash.put(pa_uitoa(tag), value); |
| } | } |
| } | } |
| Line 955 static void measure(const String& file_n | Line 953 static void measure(const String& file_n |
| else if(strcasecmp(cext, "TIF")==0 || strcasecmp(cext, "TIFF")==0) | else if(strcasecmp(cext, "TIF")==0 || strcasecmp(cext, "TIFF")==0) |
| measure_tiff(file_name, reader, info); | measure_tiff(file_name, reader, info); |
| else if(strcasecmp(cext, "MP4")==0 || strcasecmp(cext, "MOV")==0) | else if(strcasecmp(cext, "MP4")==0 || strcasecmp(cext, "MOV")==0) |
| measure_mp4(file_name, reader, info.width, info.height); | if(info.video) |
| measure_mp4(file_name, reader, info.width, info.height); | |
| else | |
| throw Exception(IMAGE_FORMAT, &file_name, "handling disabled for file name extension '%s'", cext); | |
| else | else |
| throw Exception(IMAGE_FORMAT, &file_name, "unhandled image file name extension '%s'", cext); | throw Exception(IMAGE_FORMAT, &file_name, "unhandled file name extension '%s'", cext); |
| } else | } 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 file type - no file name extension"); |
| } | } |
| // methods | // methods |
| Line 974 static void _measure(Request& r, MethodP | Line 975 static void _measure(Request& r, MethodP |
| Value* exif=0; | Value* exif=0; |
| Value* xmp=0; | Value* xmp=0; |
| Measure_info info={ 0, 0, 0, 0, &pa_UTF8_charset }; | Measure_info info={ 0, 0, 0, 0, &pa_UTF8_charset, false }; |
| if(params.count()>1) | if(params.count()>1) |
| if(HashStringValue* options=params.as_hash(1, "methods options")) { | if(HashStringValue* options=params.as_hash(1, "methods options")) { |
| Line 996 static void _measure(Request& r, MethodP | Line 997 static void _measure(Request& r, MethodP |
| info.xmp_charset=&pa_charsets.get(value->as_string()); | info.xmp_charset=&pa_charsets.get(value->as_string()); |
| valid_options++; | valid_options++; |
| } | } |
| if(key == "video") { | |
| info.video=r.process(*value).as_bool(); | |
| valid_options++; | |
| } | |
| } | } |
| if(valid_options!=options->count()) | if(valid_options!=options->count()) |
| throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION); | throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION); |
| Line 1006 static void _measure(Request& r, MethodP | Line 1011 static void _measure(Request& r, MethodP |
| if(file_name=data.get_string()) { | if(file_name=data.get_string()) { |
| file_read_action_under_lock(r.full_disk_path(*file_name), "measure", file_measure_action, &info); | file_read_action_under_lock(r.full_disk_path(*file_name), "measure", file_measure_action, &info); |
| } else { | } else { |
| VFile* vfile=data.as_vfile(String::L_AS_IS); | VFile* vfile=data.as_vfile(); |
| file_name=&vfile->fields().get(name_name)->as_string(); | file_name=&vfile->fields().get(name_name)->as_string(); |
| Measure_buf_reader reader(vfile->value_ptr(), vfile->value_size(), *file_name); | Measure_buf_reader reader(vfile->value_ptr(), vfile->value_size(), *file_name); |
| measure(*file_name, reader, info); | measure(*file_name, reader, info); |
| Line 1175 static void _replace(Request& r, MethodP | Line 1180 static void _replace(Request& r, MethodP |
| gdImage::Point* all_p=0; | gdImage::Point* all_p=0; |
| size_t count=0; | size_t count=0; |
| if(params.count() == 3){ | if(params.count() == 3){ |
| Table* table=params.as_table(2, "coordinates"); | if(Table* table=params.as_table(2, "coordinates")){ |
| count=table->count(); | count=table->count(); |
| all_p=new(PointerFreeGC) gdImage::Point[count]; | all_p=new(PointerFreeGC) gdImage::Point[count]; |
| gdImage::Point* add_p=all_p; | gdImage::Point* add_p=all_p; |
| table->for_each(add_point, &add_p); | table->for_each(add_point, &add_p); |
| } | |
| } else { | } else { |
| int max_x=image.SX()-1; | int max_x=image.SX()-1; |
| int max_y=image.SY()-1; | int max_y=image.SY()-1; |
| Line 1201 static void _replace(Request& r, MethodP | Line 1207 static void _replace(Request& r, MethodP |
| static void _polyline(Request& r, MethodParams& params) { | static void _polyline(Request& r, MethodParams& params) { |
| gdImage& image=GET_SELF(r, VImage).image(); | gdImage& image=GET_SELF(r, VImage).image(); |
| Table* table=params.as_table(1, "coordinates"); | if(Table* table=params.as_table(1, "coordinates")){ |
| gdImage::Point* all_p=new(PointerFreeGC) gdImage::Point[table->count()]; | |
| gdImage::Point* all_p=new(PointerFreeGC) gdImage::Point[table->count()]; | gdImage::Point *add_p=all_p; |
| gdImage::Point *add_p=all_p; | table->for_each(add_point, &add_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)), false/*not closed*/); |
| image.Polygon(all_p, table->count(), | } |
| image.Color(params.as_int(0, "color must be int", r)), | |
| false/*not closed*/); | |
| } | } |
| static void _polygon(Request& r, MethodParams& params) { | static void _polygon(Request& r, MethodParams& params) { |
| gdImage& image=GET_SELF(r, VImage).image(); | gdImage& image=GET_SELF(r, VImage).image(); |
| Table* table=(Table*)params.as_table(1, "coordinates"); | if(Table* table=(Table*)params.as_table(1, "coordinates")){ |
| gdImage::Point* all_p=new(PointerFreeGC) gdImage::Point[table->count()]; | |
| gdImage::Point* all_p=new(PointerFreeGC) gdImage::Point[table->count()]; | gdImage::Point *add_p=all_p; |
| gdImage::Point *add_p=all_p; | table->for_each(add_point, &add_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.Polygon(all_p, table->count(), | } |
| image.Color(params.as_int(0, "color must be int", r))); | |
| } | } |
| static void _polybar(Request& r, MethodParams& params) { | static void _polybar(Request& r, MethodParams& params) { |
| gdImage& image=GET_SELF(r, VImage).image(); | gdImage& image=GET_SELF(r, VImage).image(); |
| Table* table=(Table*)params.as_table(1, "coordinates"); | if(Table* table=(Table*)params.as_table(1, "coordinates")){ |
| gdImage::Point* all_p=new(PointerFreeGC) gdImage::Point[table->count()]; | |
| gdImage::Point* all_p=new(PointerFreeGC) gdImage::Point[table->count()]; | gdImage::Point *add_p=all_p; |
| gdImage::Point *add_p=all_p; | table->for_each(add_point, &add_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.FilledPolygon(all_p, table->count(), | } |
| image.Color(params.as_int(0, "color must be int", r))); | |
| } | } |
| // font | // font |