Skip to content

Commit 3b3db8b

Browse files
committed
gpujpegtool: respect subsampling if setting alpha
`gpujpegtool -s -a` gives 4:2:0:4 not 4:4:4:4 as before
1 parent 3039217 commit 3b3db8b

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/main.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,11 @@ adjust_params(struct gpujpeg_parameters* param, struct gpujpeg_image_parameters*
193193
}
194194
}
195195
if ( opts->keep_alpha && encode && param_image->pixel_format == GPUJPEG_4444_U8_P0123 ) {
196-
gpujpeg_parameters_chroma_subsampling(param, GPUJPEG_SUBSAMPLING_4444);
196+
gpujpeg_sampling_factor_t subs = GPUJPEG_SUBSAMPLING_4444;
197+
if ( opts->subsampling != GPUJPEG_SUBSAMPLING_UNKNOWN && (opts->subsampling & 0xFF) == 0 ) {
198+
subs = opts->subsampling | opts->subsampling >> 24; // copy Y samp factor to alpha
199+
}
200+
gpujpeg_parameters_chroma_subsampling(param, subs);
197201
}
198202

199203
if (encode && (param_image->width <= 0 || param_image->height <= 0)) {

0 commit comments

Comments
 (0)