Skip to content

Commit

Permalink
debug dump SOF0
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinPulec committed Nov 12, 2024
1 parent 098b42e commit d4665db
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/gpujpeg_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit d4665db

Please sign in to comment.