Skip to content

Commit c0f8ffa

Browse files
committed
gpujpeg_decoder_get_image_info2: include COM marker
1 parent db8673b commit c0f8ffa

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

libgpujpeg/gpujpeg_decoder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ struct gpujpeg_image_info {
272272
struct gpujpeg_parameters param;
273273
int segment_count;
274274
enum gpujpeg_header_type header_type;
275+
const char* comment; ///< NULL-terminated COM marker, ptr to img buffer
275276
};
276277
char reserved[512]; // for further extensions
277278
};

src/gpujpeg_reader.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

627628
static 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;

src/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ static int print_image_info_jpeg(const char *filename, int verbose) {
209209
if ( info.segment_count ) {
210210
printf("segment count: %d (DRI = %d)\n", info.segment_count, info.param.restart_interval);
211211
}
212+
if ( info.comment != NULL) {
213+
printf("comment: %s\n", info.comment);
214+
}
212215
}
213216
free(jpeg);
214217

0 commit comments

Comments
 (0)