diff --git a/src/gpujpeg_reader.c b/src/gpujpeg_reader.c index 8a8107e9..f03e8f27 100644 --- a/src/gpujpeg_reader.c +++ b/src/gpujpeg_reader.c @@ -691,6 +691,9 @@ static const char *array_serialize(int comp_count, const uint8_t *comp_id) { return buffer; } +/** + * checks component ID to determine if JPEG is in YCbCr (component IDs 1, 2, 3) or RGB (component IDs 'R', 'G', 'B') + */ static enum gpujpeg_color_space gpujpeg_reader_process_cid(int comp_count, uint8_t *comp_id, enum gpujpeg_color_space header_color_space) { _Static_assert(GPUJPEG_MAX_COMPONENT_COUNT >= 3, "An array of at least 3 components expected"); static const uint8_t ycbcr_ids[] = { 1, 2, 3 }; @@ -727,6 +730,21 @@ static enum gpujpeg_color_space gpujpeg_reader_process_cid(int comp_count, uint8 return GPUJPEG_NONE; } +static void +sof0_dump(int comp_count, const struct gpujpeg_component_sampling_factor* sampling_factor, const uint8_t* id, + const int* map) +{ + printf("SOF0 subsampling:"); + for (int comp = 0; comp < comp_count; ++comp) { + printf(" %dx%d", sampling_factor[comp].horizontal, sampling_factor[comp].vertical); + } + printf("\nSOF0 component quantization tab usage:"); + for (int comp = 0; comp < comp_count; ++comp) { + printf(" %" PRIu8 "->%d", id[comp], map[comp]); + } + printf("\n"); +} + /** * Read start of frame block from image * @@ -791,6 +809,10 @@ gpujpeg_reader_read_sof0(struct gpujpeg_parameters * param, struct gpujpeg_image length -= 3; } + if (param->verbose >= LL_DEBUG2) { + sof0_dump(param->comp_count, param->sampling_factor, comp_id, quant_map); + } + // Deduce color space if not known from headers enum gpujpeg_color_space detected_color_space = gpujpeg_reader_process_cid(param->comp_count, comp_id, header_color_space); if (header_color_space == GPUJPEG_NONE && detected_color_space != GPUJPEG_NONE) {