[libcamera-devel] Fixing debayering?

Laurent Pinchart laurent.pinchart at ideasonboard.com
Wed Jul 6 19:22:04 CEST 2022


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.

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list