@@ -95,6 +95,7 @@ struct gpujpeg_reader
9595 enum gpujpeg_header_type header_type ;
9696 bool in_spiff ;
9797 struct gpujpeg_exif_parameters exif_metadata ;
98+ const char * comment ;
9899};
99100
100101/**
@@ -625,17 +626,16 @@ gpujpeg_reader_read_app14(uint8_t** image, const uint8_t* image_end, enum gpujpe
625626}
626627
627628static int
628- gpujpeg_reader_read_com (uint8_t * * image , const uint8_t * image_end , bool ff_cs_itu601_is_709 ,
629- enum gpujpeg_color_space * color_space )
629+ gpujpeg_reader_read_com (uint8_t * * image , struct gpujpeg_reader * reader )
630630{
631- if ( image_end - * image < 2 ) {
631+ if ( reader -> image_end - * image < 2 ) {
632632 fprintf (stderr , "[GPUJPEG] [Error] Could not read com length\n" );
633633 return -1 ;
634634 }
635635
636636 int length = (int )gpujpeg_reader_read_2byte (* image );
637637
638- if ( length - 2 > image_end - * image ) {
638+ if ( length - 2 > reader -> image_end - * image ) {
639639 fprintf (stderr , "[GPUJPEG] [Error] COM goes beyond end of data\n" );
640640 return -1 ;
641641 }
@@ -644,7 +644,13 @@ gpujpeg_reader_read_com(uint8_t** image, const uint8_t* image_end, bool ff_cs_it
644644 const size_t com_length = length - 2 ; // check both with '\0' and without:
645645 if ( (com_length == sizeof cs_itu601 || com_length == sizeof cs_itu601 - 1 ) &&
646646 strncmp ((char * )* image , cs_itu601 , com_length ) == 0 ) {
647- * color_space = ff_cs_itu601_is_709 ? GPUJPEG_YCBCR_BT709 : GPUJPEG_YCBCR_BT601 ;
647+ reader -> header_color_space = reader -> ff_cs_itu601_is_709 ? GPUJPEG_YCBCR_BT709 : GPUJPEG_YCBCR_BT601 ;
648+ }
649+
650+ if ((* image )[com_length - 1 ] == '\0' ) {
651+ reader -> comment = (char * )* image ;
652+ } else {
653+ DEBUG_MSG (reader -> param .verbose , "Not storing non-NULL-terminated COM: %.*s" , (int )com_length , * image );
648654 }
649655
650656 * image += length - 2 ;
@@ -1452,8 +1458,7 @@ gpujpeg_reader_read_common_markers(uint8_t** image, int marker, struct gpujpeg_r
14521458 return -1 ;
14531459
14541460 case GPUJPEG_MARKER_COM :
1455- if ( gpujpeg_reader_read_com (image , reader -> image_end , reader -> ff_cs_itu601_is_709 ,
1456- & reader -> header_color_space ) != 0 ) {
1461+ if ( gpujpeg_reader_read_com (image , reader ) != 0 ) {
14571462 return -1 ;
14581463 }
14591464 break ;
@@ -1787,6 +1792,7 @@ gpujpeg_reader_get_image_info(uint8_t *image, size_t image_size, struct gpujpeg_
17871792 info -> param_image .pixel_format = GPUJPEG_PIXFMT_NONE ;
17881793 info -> segment_count = segments ;
17891794 info -> header_type = reader .header_type ;
1795+ info -> comment = reader .comment ;
17901796
17911797 if ( info -> param .comp_count == 1 ) {
17921798 info -> param_image .pixel_format = GPUJPEG_U8 ;
0 commit comments