--- parser3/src/classes/image.C 2020/12/07 23:18:40 1.178 +++ parser3/src/classes/image.C 2020/12/23 15:01:13 1.181 @@ -1,7 +1,7 @@ /** @file Parser: @b image parser class. - Copyright (c) 2001-2017 Art. Lebedev Studio (http://www.artlebedev.com) + Copyright (c) 2001-2020 Art. Lebedev Studio (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ @@ -26,7 +26,7 @@ #include "pa_table.h" #include "pa_charsets.h" -volatile const char * IDENT_IMAGE_C="$Id: image.C,v 1.178 2020/12/07 23:18:40 moko Exp $"; +volatile const char * IDENT_IMAGE_C="$Id: image.C,v 1.181 2020/12/23 15:01:13 moko Exp $"; // defines @@ -308,6 +308,7 @@ struct Measure_info { Value** exif; Value** xmp; Charset* xmp_charset; + bool video; }; @@ -955,11 +956,14 @@ static void measure(const String& file_n else if(strcasecmp(cext, "TIF")==0 || strcasecmp(cext, "TIFF")==0) measure_tiff(file_name, reader, info); 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 - 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 - 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 @@ -974,7 +978,7 @@ static void _measure(Request& r, MethodP Value* exif=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(HashStringValue* options=params.as_hash(1, "methods options")) { @@ -996,6 +1000,10 @@ static void _measure(Request& r, MethodP info.xmp_charset=&pa_charsets.get(value->as_string()); valid_options++; } + if(key == "video") { + info.video=r.process(*value).as_bool(); + valid_options++; + } } if(valid_options!=options->count()) throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION); @@ -1175,11 +1183,12 @@ static void _replace(Request& r, MethodP gdImage::Point* all_p=0; size_t count=0; if(params.count() == 3){ - Table* table=params.as_table(2, "coordinates"); - count=table->count(); - all_p=new(PointerFreeGC) gdImage::Point[count]; - gdImage::Point* add_p=all_p; - table->for_each(add_point, &add_p); + if(Table* table=params.as_table(2, "coordinates")){ + count=table->count(); + all_p=new(PointerFreeGC) gdImage::Point[count]; + gdImage::Point* add_p=all_p; + table->for_each(add_point, &add_p); + } } else { int max_x=image.SX()-1; int max_y=image.SY()-1; @@ -1201,38 +1210,34 @@ static void _replace(Request& r, MethodP static void _polyline(Request& r, MethodParams& params) { gdImage& image=GET_SELF(r, VImage).image(); - Table* table=params.as_table(1, "coordinates"); - - gdImage::Point* all_p=new(PointerFreeGC) 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)), - false/*not closed*/); + if(Table* table=params.as_table(1, "coordinates")){ + gdImage::Point* all_p=new(PointerFreeGC) 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)), false/*not closed*/); + } } static void _polygon(Request& r, MethodParams& params) { gdImage& image=GET_SELF(r, VImage).image(); - Table* table=(Table*)params.as_table(1, "coordinates"); - - gdImage::Point* all_p=new(PointerFreeGC) 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))); + if(Table* table=(Table*)params.as_table(1, "coordinates")){ + gdImage::Point* all_p=new(PointerFreeGC) 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, MethodParams& params) { gdImage& image=GET_SELF(r, VImage).image(); - Table* table=(Table*)params.as_table(1, "coordinates"); - - gdImage::Point* all_p=new(PointerFreeGC) gdImage::Point[table->count()]; - gdImage::Point *add_p=all_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))); + if(Table* table=(Table*)params.as_table(1, "coordinates")){ + gdImage::Point* all_p=new(PointerFreeGC) gdImage::Point[table->count()]; + gdImage::Point *add_p=all_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))); + } } // font