[libcamera-devel] Fixing debayering?

Rafael Diniz rafael at riseup.net
Wed Jul 6 20:45:47 CEST 2022


Picture took with:
qcam -r gles -spixelformat=SBGGR8,width=1280,height=720 -platform xcb 
-style=fusion

Interestingly enough output is:
test.jpg: JPEG image data, JFIF standard 1.01, resolution (DPI), density 
96x96, segment length 16, baseline, precision 8, 1440x625, components 3

url:
https://www.abradig.org.br/maemo-crazyness/test.jpg

Rafael

On 7/6/22 14:22, Laurent Pinchart wrote:
> Hi Rafael,
> 
> On Wed, Jul 06, 2022 at 08:21:09PM +0300, Rafael Diniz wrote:
>> Thanks Laurent.
>>
>> I tried many different resolutions, and I still get the artifacts.
> 
> Could you share some sample images ?
> 
>> I'm going down to debugging what the driver is delivering to user-space,
>> as there could be something wrong in kernel space, so I want to be sure
>> there is nothing wrong.
>>
>> On 7/6/22 10:16, Laurent Pinchart wrote:
>>> On Wed, Jul 06, 2022 at 02:37:04PM +0300, Rafael Diniz wrote:
>>>> Thanks Laurent.
>>>>
>>>> I'm wondering if the frames SBGGR8 passed to this code are in the
>>>> required format...
>>>> /** Monochrome RGBA or GL_LUMINANCE Bayer encoded texture.*/
>>>
>>> That part should be fine. In ViewFinderGL::doRender(), for RAW8 formats,
>>> we have
>>>
>>> 		glTexImage2D(GL_TEXTURE_2D,
>>> 			     0,
>>> 			     GL_LUMINANCE,
>>> 			     stride_,
>>> 			     size_.height(),
>>> 			     0,
>>> 			     GL_LUMINANCE,
>>> 			     GL_UNSIGNED_BYTE,
>>> 			     image_->data(0).data());
>>>
>>> With GL_LUMINANCE + GL_UNSIGNED_BYTE, the texture sampler will read the
>>> texture with one byte per pixel, and store the value of the byte in the
>>> .r, .g and .b components (scaled from [0, 255] to [0.0, 1.0]). The
>>> fragment shader then uses the .r component only.
>>>
>>> One point to note is that the texture sampler will perform interpolation
>>> if the coordinates passed to it don't fall on a texel. For RAW8 formats,
>>> interpolation won't give correct results, as the sampler would try to
>>> interpolate between neighbour pixels with different colour filter. For
>>> that reason, ViewFinderGL::selectFormat() sets textureMinMagFilters_ to
>>> GL_NEAREST, which is then used in ViewFinderGL::configureTexture() to
>>> setup the min/mag filters. The lack of interpolation will affect the
>>> image quality when the display size is different than the capture size.
>>>
>>>> Trying to dig a bit further.
>>>>
>>>> On 7/6/22 07:50, Laurent Pinchart wrote:
>>>>> On Wed, Jul 06, 2022 at 12:26:29PM +0300, Rafael Diniz via libcamera-devel wrote:
>>>>>> Hi all,
>>>>>>
>>>>>> The last annoying bug I can find in using qcam on the Pinephone (at
>>>>>> least on lower resolutions, as high resolutions are still borked) is the
>>>>>> debayering from SBGGR8, which is clearly producing artifacts. Where can
>>>>>> I find its implementation? I plan to read it and compare to the
>>>>>> canonical one and see what could be wrong.
>>>>>
>>>>> The implementation is in src/qcam/assets/shader/bayer_8.vert and
>>>>> src/qcam/assets/shader/bayer_8.frag.
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 840 bytes
Desc: OpenPGP digital signature
URL: <https://lists.libcamera.org/pipermail/libcamera-devel/attachments/20220706/a9af1e2c/attachment.sig>


More information about the libcamera-devel mailing list