All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hans Verkuil <hverkuil@xs4all.nl>
To: Philipp Zabel <p.zabel@pengutronix.de>, linux-media@vger.kernel.org
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>, kernel@pengutronix.de
Subject: Re: [PATCH 5/7] media: coda: fix default JPEG colorimetry
Date: Thu, 21 Apr 2022 13:06:59 +0200	[thread overview]
Message-ID: <7baae67d-e5e0-1f6f-d915-4ef5ca5fffd3@xs4all.nl> (raw)
In-Reply-To: <4ddc131113b41bf8427d0b316b70335578971ff4.camel@pengutronix.de>

On 21/04/2022 12:38, Philipp Zabel wrote:
> On Do, 2022-04-21 at 12:02 +0200, Hans Verkuil wrote:
>> Hi Philipp,
>>
>> On 04/04/2022 18:35, Philipp Zabel wrote:
>>> Set default colorspace to SRGB for JPEG encoder and decoder devices,
>>> to fix the following v4l2-compliance test failure:
>>>
>>> 	test VIDIOC_TRY_FMT: OK
>>> 		fail: v4l2-test-formats.cpp(818): fmt_raw.g_colorspace() != V4L2_COLORSPACE_SRGB
>>>
>>> Also explicitly set transfer function, YCbCr encoding and quantization
>>> range, as required by v4l2-compliance for the JPEG encoded side.
>>
>> I'm not quite sure if this patch addresses the correct issue.
>>
>>>
>>> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
>>> ---
>>>  .../media/platform/chips-media/coda-common.c  | 36 +++++++++++++------
>>>  1 file changed, 25 insertions(+), 11 deletions(-)
>>>
>>> diff --git a/drivers/media/platform/chips-media/coda-common.c b/drivers/media/platform/chips-media/coda-common.c
>>> index 4a7346ed771e..c068c16d1eb4 100644
>>> --- a/drivers/media/platform/chips-media/coda-common.c
>>> +++ b/drivers/media/platform/chips-media/coda-common.c
>>> @@ -732,13 +732,22 @@ static int coda_try_fmt_vid_cap(struct file *file, void *priv,
>>>  	return 0;
>>>  }
>>>  
>>>
>>>
>>>
>>> -static void coda_set_default_colorspace(struct v4l2_pix_format *fmt)
>>> +static void coda_set_default_colorspace(struct coda_ctx *ctx,
>>> +					struct v4l2_pix_format *fmt)
>>>  {
>>>  	enum v4l2_colorspace colorspace;
>>>  
>>>
>>>
>>>
>>> -	if (fmt->pixelformat == V4L2_PIX_FMT_JPEG)
>>> -		colorspace = V4L2_COLORSPACE_JPEG;
>>
>> It's perfectly fine to keep this, the problem occurs with the raw image side
>> (capture for the decoder, output for the encoder).
>>
>> There the colorspace must be SRGB, the xfer_func may be 0 or SRGB, and the
>> ycbcr_enc is 0 (if not a YUV pixelformat) or ENC_601 (if it is a YUV format).
>> Actually, if the hardware can convert from other YUV encodings such as 709,
>> then other YUV encodings are valid, but I assume that's not the case.
> 
> So the driver has to support different colorspace on output and capture
> queues?

Correct. Note that it is OK to replace COLORSPACE_JPEG by explicit colorspace,
xfer_func, ycbcr_enc and quantization values, but in reality (almost?) all drivers
use COLORSPACE_JPEG, and that won't go away. Keeping it will certainly reduce
the patch size.

Regards,

	Hans

> 
>>> -	else if (fmt->width <= 720 && fmt->height <= 576)
>>> +	if (ctx->cvd->src_formats[0] == V4L2_PIX_FMT_JPEG ||
>>> +	    ctx->cvd->dst_formats[0] == V4L2_PIX_FMT_JPEG ||
>>> +	    fmt->pixelformat == V4L2_PIX_FMT_JPEG) {
>>> +		fmt->colorspace = V4L2_COLORSPACE_SRGB;
>>> +		fmt->xfer_func = V4L2_XFER_FUNC_SRGB;
>>> +		fmt->ycbcr_enc = V4L2_YCBCR_ENC_601;
>>> +		fmt->quantization = V4L2_QUANTIZATION_FULL_RANGE;
>>> +		return;
>>> +	}
>>> +
>>> +	if (fmt->width <= 720 && fmt->height <= 576)
>>>  		colorspace = V4L2_COLORSPACE_SMPTE170M;
>>>  	else
>>>  		colorspace = V4L2_COLORSPACE_REC709;
>>> @@ -763,7 +772,7 @@ static int coda_try_fmt_vid_out(struct file *file, void *priv,
>>>  		return ret;
>>>  
>>>
>>>
>>>
>>>  	if (f->fmt.pix.colorspace == V4L2_COLORSPACE_DEFAULT)
>>> -		coda_set_default_colorspace(&f->fmt.pix);
>>> +		coda_set_default_colorspace(ctx, &f->fmt.pix);
>>>  
>>>
>>>
>>>
>>>  	q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
>>>  	codec = coda_find_codec(dev, f->fmt.pix.pixelformat, q_data_dst->fourcc);
>>> @@ -1640,13 +1649,18 @@ static void set_default_params(struct coda_ctx *ctx)
>>>  	csize = coda_estimate_sizeimage(ctx, usize, max_w, max_h);
>>>  
>>>
>>>
>>>
>>>  	ctx->params.codec_mode = ctx->codec->mode;
>>> -	if (ctx->cvd->src_formats[0] == V4L2_PIX_FMT_JPEG)
>>> -		ctx->colorspace = V4L2_COLORSPACE_JPEG;
>>> -	else
>>> +	if (ctx->cvd->src_formats[0] == V4L2_PIX_FMT_JPEG ||
>>> +	    ctx->cvd->dst_formats[0] == V4L2_PIX_FMT_JPEG) {
>>> +		ctx->colorspace = V4L2_COLORSPACE_SRGB;
>>> +		ctx->xfer_func = V4L2_XFER_FUNC_SRGB;
>>> +		ctx->ycbcr_enc = V4L2_YCBCR_ENC_601;
>>> +		ctx->quantization = V4L2_QUANTIZATION_FULL_RANGE;
>>> +	} else {
>>>  		ctx->colorspace = V4L2_COLORSPACE_REC709;
>>
>> My guess is that the raw format colorspace is set to REC709, which is definitely
>> wrong for a JPEG codec. For a JPEG codec that must be set to SRGB.
>>
>> I suspect that's the real bug here.
>>
>> I'm skipping this patch for now.
> 
> Thank you, I think at least for the decoder the issue was that the
> driver defaulted to V4L2_COLORSPACE_JPEG, but since ctx->colorspace is
> used for both sides, that would also be used as colorspace for the raw
> image side. For the encoder it looks like you are right.
> 
> I'll double check.
> 
> regards
> Philipp


  reply	other threads:[~2022-04-21 11:07 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-04 16:35 [PATCH 1/7] media: coda: set output buffer bytesused to appease v4l2-compliance Philipp Zabel
2022-04-04 16:35 ` [PATCH 2/7] media: coda: disable encoder cmd ioctl on decoder and vice versa Philipp Zabel
2022-04-05 14:07   ` Nicolas Dufresne
2022-04-04 16:35 ` [PATCH 3/7] media: coda: disable encoder ioctls for decoder devices Philipp Zabel
2022-04-05 14:13   ` Nicolas Dufresne
2022-04-04 16:35 ` [PATCH 4/7] media: coda: disable stateful encoder ioctls for jpeg encoder Philipp Zabel
2022-04-05 14:14   ` Nicolas Dufresne
2022-04-04 16:35 ` [PATCH 5/7] media: coda: fix default JPEG colorimetry Philipp Zabel
2022-04-05 14:15   ` Nicolas Dufresne
2022-04-21 10:02   ` Hans Verkuil
2022-04-21 10:38     ` Philipp Zabel
2022-04-21 11:06       ` Hans Verkuil [this message]
2022-04-26  9:21         ` Philipp Zabel
2022-04-21 14:54     ` Philipp Zabel
2022-04-21 15:28       ` Philipp Zabel
2022-04-04 16:35 ` [PATCH 6/7] media: coda: enable capture G_PARM for stateful encoder Philipp Zabel
2022-04-05 14:19   ` Nicolas Dufresne
2022-04-21 10:30   ` Hans Verkuil
2022-04-21 14:58     ` Philipp Zabel
2022-04-25  5:34       ` Hans Verkuil
2022-04-04 16:35 ` [PATCH 7/7] media: coda: enable capture S_PARM " Philipp Zabel
2022-04-05 14:22   ` Nicolas Dufresne
2022-04-05 15:03     ` Philipp Zabel
2022-04-05 16:00       ` Nicolas Dufresne
2022-04-05 14:05 ` [PATCH 1/7] media: coda: set output buffer bytesused to appease v4l2-compliance Nicolas Dufresne
2022-04-21  9:44 ` Hans Verkuil
2022-04-21 10:24   ` Philipp Zabel
2022-04-26  5:52     ` Hans Verkuil
2022-04-26  9:32       ` Philipp Zabel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7baae67d-e5e0-1f6f-d915-4ef5ca5fffd3@xs4all.nl \
    --to=hverkuil@xs4all.nl \
    --cc=kernel@pengutronix.de \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=p.zabel@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.