Skip to content

Commit 5eaa309

Browse files
committed
get_native_pixel_format: return fallback
do not return GPUJPEG_PIXFMT_NONE, use fallbacks for "weird" subsamplings
1 parent e51a8a4 commit 5eaa309

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

src/gpujpeg_reader.c

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,23 +1508,10 @@ static enum gpujpeg_pixel_format
15081508
get_native_pixel_format(struct gpujpeg_parameters* param)
15091509
{
15101510
if ( param->comp_count == 4 ) {
1511-
_Bool subsampling_is4444 = 1;
1512-
for (int i = 1; i < 4; ++i) {
1513-
if (param->sampling_factor[i].horizontal != param->sampling_factor[0].horizontal
1514-
|| param->sampling_factor[i].vertical != param->sampling_factor[0].vertical) {
1515-
subsampling_is4444 = 0;
1516-
break;
1517-
}
1518-
}
1519-
if (subsampling_is4444) {
1520-
return GPUJPEG_4444_U8_P0123;
1521-
}
1522-
return GPUJPEG_PIXFMT_NONE;
1511+
return GPUJPEG_4444_U8_P0123;
15231512
}
15241513

1525-
if ( param->comp_count != 3 ) {
1526-
return GPUJPEG_PIXFMT_NONE;
1527-
}
1514+
assert(param->comp_count == 3);
15281515

15291516
// reduce [2, 2; 1, 2; 1, 2] (FFmpeg) to [2, 1; 1, 1; 1, 1]
15301517
int horizontal_gcd = param->sampling_factor[0].horizontal;
@@ -1538,6 +1525,7 @@ get_native_pixel_format(struct gpujpeg_parameters* param)
15381525
param->sampling_factor[i].vertical /= vertical_gcd;
15391526
}
15401527

1528+
// handle normal 4:4:4, 4:2:2 or 4:2:0
15411529
if ( param->sampling_factor[1].horizontal == 1 && param->sampling_factor[1].vertical == 1 &&
15421530
param->sampling_factor[2].horizontal == 1 && param->sampling_factor[2].vertical == 1 ) {
15431531
int sum = param->interleaved << 16 | param->sampling_factor[0].horizontal << 8 |
@@ -1555,7 +1543,8 @@ get_native_pixel_format(struct gpujpeg_parameters* param)
15551543
}
15561544
}
15571545

1558-
return GPUJPEG_PIXFMT_NONE;
1546+
// fallback
1547+
return param->interleaved ? GPUJPEG_444_U8_P012 : GPUJPEG_444_U8_P0P1P2;
15591548
}
15601549

15611550
static enum gpujpeg_pixel_format

0 commit comments

Comments
 (0)