[FFmpeg-trac] #10136(swscale:new): Can't convert color range with sws_scale
FFmpeg
trac at avcodec.org
Mon Jan 9 15:05:47 EET 2023
#10136: Can't convert color range with sws_scale
---------------------------------+--------------------------------------
Reporter: diogo.r | Type: defect
Status: new | Priority: normal
Component: swscale | Version: git-master
Keywords: | Blocked By:
Blocking: | Reproduced by developer: 0
Analyzed by developer: 0 |
---------------------------------+--------------------------------------
Summary of the bug:
I'm trying to convert a frame with sws_scale while selecting the color
range of the input and output, but for some input formats it doesn't work,
it ignores the color ranges I set. I looked into it and found weird this
check in 'libswscale/utils.c:1046':
{{{
//The srcBpc check is possibly wrong but we seem to lack a definitive
reference to test this
//and what we have in ticket 2939 looks better with this check
if (need_reinit && (c->srcBpc == 8 || !isYUV(c->srcFormat)))
ff_sws_init_range_convert(c);
}}}
I looked at ticket 2939, but didn't find reasoning about why the
{{{(c->srcBpc == 8 || !isYUV(c->srcFormat)}}} check is necessary.
How to reproduce:
{{{
extern "C"
{
#include <libswscale/swscale.h>
}
#include "assert.h"
int main() {
AVPixelFormat in_pix_fmt = AVPixelFormat::AV_PIX_FMT_YUV420P10LE;
AVPixelFormat out_pix_fmt = AVPixelFormat::AV_PIX_FMT_YUV420P;
int width = 32;
int height = 32;
SwsContext *sws_ctx = (struct SwsContext*)sws_getContext(
width,
height,
in_pix_fmt,
width,
height,
out_pix_fmt,
SWS_BILINEAR,
NULL,
NULL,
NULL
);
int *table = NULL;
int *inv_table = NULL;
int srcRange = -1;
int dstRange = -1;
int brightness = -1;
int contrast = -1;
int saturation = -1;
int res = sws_getColorspaceDetails(
sws_ctx,
&inv_table,
&srcRange,
&table,
&dstRange,
&brightness,
&contrast,
&saturation
);
assert(res == 0);
printf(
R"(
srcRange = %d
dstRange = %d
brightness = %d
contrast = %d
saturation = %d
table = [%d, %d, %d, %d]
inv_table = [%d, %d, %d, %d]
)",
srcRange,
dstRange,
brightness,
contrast,
saturation,
table[0],
table[1],
table[2],
table[3],
inv_table[0],
inv_table[1],
inv_table[2],
inv_table[3]
);
srcRange = 1;
res = sws_setColorspaceDetails(
sws_ctx,
inv_table,
srcRange,
table,
dstRange,
brightness,
contrast,
saturation
);
// Do the conversion
// sws_scale(...)
assert(res == 0);
return 0;
}
}}}
--
Ticket URL: <https://trac.ffmpeg.org/ticket/10136>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker
More information about the FFmpeg-trac
mailing list