Skip to content

Commit 2628b85

Browse files
committed
add GPUJPEG_PIXFMT_NATIVE
1 parent 4460a3c commit 2628b85

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

libgpujpeg/gpujpeg_decoder.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ gpujpeg_decoder_destroy(struct gpujpeg_decoder* decoder);
238238
/// pixel format that may be stored in a PAM or Y4M file - a planar pixel
239239
/// format that is either 444, 422 or 420 for YUV, P012(3) otherwise
240240
#define GPUJPEG_PIXFMT_STD ((enum gpujpeg_pixel_format)(GPUJPEG_PIXFMT_NONE - 3))
241+
/// pixfmt nearest the internal JPEG subsampling
242+
#define GPUJPEG_PIXFMT_NATIVE ((enum gpujpeg_pixel_format)(GPUJPEG_PIXFMT_NONE - 4))
241243
/// @}
242244
/// Decode RGB for 3 or 4 channels, GPUJPEG_YCBCR for grayscale.
243245
/// decoder only, valid only if passed to gpujpeg_decoder_set_output_format()

src/gpujpeg_reader.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,9 +1507,6 @@ gcd(int a, int b)
15071507
static enum gpujpeg_pixel_format
15081508
get_native_pixel_format(struct gpujpeg_parameters* param)
15091509
{
1510-
if ( param->comp_count == 1 ) {
1511-
return GPUJPEG_U8;
1512-
}
15131510
if ( param->comp_count == 3 ) {
15141511
// reduce [2, 2; 1, 2; 1, 2] (FFmpeg) to [2, 1; 1, 1; 1, 1]
15151512
int horizontal_gcd = param->sampling_factor[0].horizontal;
@@ -1557,11 +1554,16 @@ get_native_pixel_format(struct gpujpeg_parameters* param)
15571554

15581555
static enum gpujpeg_pixel_format
15591556
adjust_pixel_format(struct gpujpeg_parameters * param, struct gpujpeg_image_parameters * param_image) {
1560-
assert(param_image->pixel_format == GPUJPEG_PIXFMT_AUTODETECT || param_image->pixel_format == GPUJPEG_PIXFMT_STD);
1557+
assert(param_image->pixel_format == GPUJPEG_PIXFMT_AUTODETECT || param_image->pixel_format == GPUJPEG_PIXFMT_STD ||
1558+
param_image->pixel_format == GPUJPEG_PIXFMT_NATIVE);
15611559
if ( param->comp_count == 1 ) {
15621560
return GPUJPEG_U8;
15631561
}
15641562

1563+
if ( param_image->pixel_format == GPUJPEG_PIXFMT_NATIVE ) {
1564+
return get_native_pixel_format(param);
1565+
}
1566+
15651567
if (param_image->pixel_format == GPUJPEG_PIXFMT_STD && param_image->color_space != GPUJPEG_RGB) {
15661568
struct gpujpeg_parameters tmp;
15671569
gpujpeg_parameters_chroma_subsampling(&tmp, GPUJPEG_SUBSAMPLING_420);
@@ -1738,6 +1740,7 @@ gpujpeg_reader_get_image_info(uint8_t *image, size_t image_size, struct gpujpeg_
17381740

17391741
struct gpujpeg_reader reader = {
17401742
.param.verbose = verbose,
1743+
.param_image.pixel_format = GPUJPEG_PIXFMT_NATIVE,
17411744
.image_end = image + image_size,
17421745
.metadata = &info->metadata,
17431746
};
@@ -1856,8 +1859,6 @@ gpujpeg_reader_get_image_info(uint8_t *image, size_t image_size, struct gpujpeg_
18561859
info->header_type = reader.header_type;
18571860
info->comment = reader.comment;
18581861

1859-
info->param_image.pixel_format = get_native_pixel_format(&reader.param);
1860-
18611862
return 0;
18621863
}
18631864

0 commit comments

Comments
 (0)