All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dri2: Fix stride to pitch conversion
@ 2015-12-19 16:02 Nicolas Dufresne
  2015-12-21 15:12 ` Nicolas Dufresne
  0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Dufresne @ 2015-12-19 16:02 UTC (permalink / raw)
  To: dri-devel

Not all color formats have a pixel stride of 4 bytes. This
fixes importation of RGB565 images.

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
---
 src/gallium/state_trackers/dri/dri2.c | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/src/gallium/state_trackers/dri/dri2.c b/src/gallium/state_trackers/dri/dri2.c
index a11a6cb..1373785 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -46,34 +46,40 @@
 #include "dri_query_renderer.h"
 #include "dri2_buffer.h"
 
-static int convert_fourcc(int format, int *dri_components_p)
+static int convert_fourcc(int format, int *dri_components_p, int *pstride_p)
 {
-   int dri_components;
+   int dri_components, pstride;
    switch(format) {
    case __DRI_IMAGE_FOURCC_RGB565:
       format = __DRI_IMAGE_FORMAT_RGB565;
       dri_components = __DRI_IMAGE_COMPONENTS_RGB;
+      pstride = 2;
       break;
    case __DRI_IMAGE_FOURCC_ARGB8888:
       format = __DRI_IMAGE_FORMAT_ARGB8888;
       dri_components = __DRI_IMAGE_COMPONENTS_RGBA;
+      pstride = 4;
       break;
    case __DRI_IMAGE_FOURCC_XRGB8888:
       format = __DRI_IMAGE_FORMAT_XRGB8888;
       dri_components = __DRI_IMAGE_COMPONENTS_RGB;
+      pstride = 4;
       break;
    case __DRI_IMAGE_FOURCC_ABGR8888:
       format = __DRI_IMAGE_FORMAT_ABGR8888;
       dri_components = __DRI_IMAGE_COMPONENTS_RGBA;
+      pstride = 4;
       break;
    case __DRI_IMAGE_FOURCC_XBGR8888:
       format = __DRI_IMAGE_FORMAT_XBGR8888;
       dri_components = __DRI_IMAGE_COMPONENTS_RGB;
+      pstride = 4;
       break;
    default:
       return -1;
    }
    *dri_components_p = dri_components;
+   *pstride_p = pstride;
    return format;
 }
 
@@ -986,19 +992,19 @@ dri2_from_names(__DRIscreen *screen, int width, int height, int format,
                 void *loaderPrivate)
 {
    __DRIimage *img;
-   int stride, dri_components;
+   int stride, pstride, dri_components;
 
    if (num_names != 1)
       return NULL;
    if (offsets[0] != 0)
       return NULL;
 
-   format = convert_fourcc(format, &dri_components);
+   format = convert_fourcc(format, &dri_components, &pstride);
    if (format == -1)
       return NULL;
 
    /* Strides are in bytes not pixels. */
-   stride = strides[0] /4;
+   stride = strides[0] / pstride;
 
    img = dri2_create_image_from_name(screen, width, height, format,
                                      names[0], stride, loaderPrivate);
@@ -1101,19 +1107,19 @@ dri2_from_fds(__DRIscreen *screen, int width, int height, int fourcc,
               void *loaderPrivate)
 {
    __DRIimage *img;
-   int format, stride, dri_components;
+   int format, stride, pstride, dri_components;
 
    if (num_fds != 1)
       return NULL;
    if (offsets[0] != 0)
       return NULL;
 
-   format = convert_fourcc(fourcc, &dri_components);
+   format = convert_fourcc(fourcc, &dri_components, &pstride);
    if (format == -1)
       return NULL;
 
    /* Strides are in bytes not pixels. */
-   stride = strides[0] /4;
+   stride = strides[0] / pstride;
 
    img = dri2_create_image_from_fd(screen, width, height, format,
                                    fds[0], stride, loaderPrivate);
@@ -1137,21 +1143,21 @@ dri2_from_dma_bufs(__DRIscreen *screen,
                    void *loaderPrivate)
 {
    __DRIimage *img;
-   int format, stride, dri_components;
+   int format, stride, pstride, dri_components;
 
    if (num_fds != 1 || offsets[0] != 0) {
       *error = __DRI_IMAGE_ERROR_BAD_MATCH;
       return NULL;
    }
 
-   format = convert_fourcc(fourcc, &dri_components);
+   format = convert_fourcc(fourcc, &dri_components, &pstride);
    if (format == -1) {
       *error = __DRI_IMAGE_ERROR_BAD_MATCH;
       return NULL;
    }
 
    /* Strides are in bytes not pixels. */
-   stride = strides[0] /4;
+   stride = strides[0] / pstride;
 
    img = dri2_create_image_from_fd(screen, width, height, format,
                                    fds[0], stride, loaderPrivate);
-- 
2.5.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] dri2: Fix stride to pitch conversion
  2015-12-19 16:02 [PATCH] dri2: Fix stride to pitch conversion Nicolas Dufresne
@ 2015-12-21 15:12 ` Nicolas Dufresne
  2015-12-21 15:26   ` Daniel Vetter
  0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Dufresne @ 2015-12-21 15:12 UTC (permalink / raw)
  To: Nicolas Dufresne, dri-devel


[-- Attachment #1.1: Type: text/plain, Size: 5263 bytes --]

Le samedi 19 décembre 2015 à 11:02 -0500, Nicolas Dufresne a écrit :
> Not all color formats have a pixel stride of 4 bytes. This
> fixes importation of RGB565 images.


I just notice there is generic method to get the pixel stride (called
block something size iirc). But worst then that, the underlying
function will simply convert back to stride, better then this patch is
to change this function to take a stride as parameter. I'll submit a
new patch, please ignore this one.

> 
> Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
> ---
>  src/gallium/state_trackers/dri/dri2.c | 28 +++++++++++++++++------
> -----
>  1 file changed, 17 insertions(+), 11 deletions(-)
> 
> diff --git a/src/gallium/state_trackers/dri/dri2.c
> b/src/gallium/state_trackers/dri/dri2.c
> index a11a6cb..1373785 100644
> --- a/src/gallium/state_trackers/dri/dri2.c
> +++ b/src/gallium/state_trackers/dri/dri2.c
> @@ -46,34 +46,40 @@
>  #include "dri_query_renderer.h"
>  #include "dri2_buffer.h"
>  
> -static int convert_fourcc(int format, int *dri_components_p)
> +static int convert_fourcc(int format, int *dri_components_p, int
> *pstride_p)
>  {
> -   int dri_components;
> +   int dri_components, pstride;
>     switch(format) {
>     case __DRI_IMAGE_FOURCC_RGB565:
>        format = __DRI_IMAGE_FORMAT_RGB565;
>        dri_components = __DRI_IMAGE_COMPONENTS_RGB;
> +      pstride = 2;
>        break;
>     case __DRI_IMAGE_FOURCC_ARGB8888:
>        format = __DRI_IMAGE_FORMAT_ARGB8888;
>        dri_components = __DRI_IMAGE_COMPONENTS_RGBA;
> +      pstride = 4;
>        break;
>     case __DRI_IMAGE_FOURCC_XRGB8888:
>        format = __DRI_IMAGE_FORMAT_XRGB8888;
>        dri_components = __DRI_IMAGE_COMPONENTS_RGB;
> +      pstride = 4;
>        break;
>     case __DRI_IMAGE_FOURCC_ABGR8888:
>        format = __DRI_IMAGE_FORMAT_ABGR8888;
>        dri_components = __DRI_IMAGE_COMPONENTS_RGBA;
> +      pstride = 4;
>        break;
>     case __DRI_IMAGE_FOURCC_XBGR8888:
>        format = __DRI_IMAGE_FORMAT_XBGR8888;
>        dri_components = __DRI_IMAGE_COMPONENTS_RGB;
> +      pstride = 4;
>        break;
>     default:
>        return -1;
>     }
>     *dri_components_p = dri_components;
> +   *pstride_p = pstride;
>     return format;
>  }
>  
> @@ -986,19 +992,19 @@ dri2_from_names(__DRIscreen *screen, int width,
> int height, int format,
>                  void *loaderPrivate)
>  {
>     __DRIimage *img;
> -   int stride, dri_components;
> +   int stride, pstride, dri_components;
>  
>     if (num_names != 1)
>        return NULL;
>     if (offsets[0] != 0)
>        return NULL;
>  
> -   format = convert_fourcc(format, &dri_components);
> +   format = convert_fourcc(format, &dri_components, &pstride);
>     if (format == -1)
>        return NULL;
>  
>     /* Strides are in bytes not pixels. */
> -   stride = strides[0] /4;
> +   stride = strides[0] / pstride;
>  
>     img = dri2_create_image_from_name(screen, width, height, format,
>                                       names[0], stride, 
> loaderPrivate);
> @@ -1101,19 +1107,19 @@ dri2_from_fds(__DRIscreen *screen, int width,
> int height, int fourcc,
>                void *loaderPrivate)
>  {
>     __DRIimage *img;
> -   int format, stride, dri_components;
> +   int format, stride, pstride, dri_components;
>  
>     if (num_fds != 1)
>        return NULL;
>     if (offsets[0] != 0)
>        return NULL;
>  
> -   format = convert_fourcc(fourcc, &dri_components);
> +   format = convert_fourcc(fourcc, &dri_components, &pstride);
>     if (format == -1)
>        return NULL;
>  
>     /* Strides are in bytes not pixels. */
> -   stride = strides[0] /4;
> +   stride = strides[0] / pstride;
>  
>     img = dri2_create_image_from_fd(screen, width, height, format,
>                                     fds[0], stride, loaderPrivate);
> @@ -1137,21 +1143,21 @@ dri2_from_dma_bufs(__DRIscreen *screen,
>                     void *loaderPrivate)
>  {
>     __DRIimage *img;
> -   int format, stride, dri_components;
> +   int format, stride, pstride, dri_components;
>  
>     if (num_fds != 1 || offsets[0] != 0) {
>        *error = __DRI_IMAGE_ERROR_BAD_MATCH;
>        return NULL;
>     }
>  
> -   format = convert_fourcc(fourcc, &dri_components);
> +   format = convert_fourcc(fourcc, &dri_components, &pstride);
>     if (format == -1) {
>        *error = __DRI_IMAGE_ERROR_BAD_MATCH;
>        return NULL;
>     }
>  
>     /* Strides are in bytes not pixels. */
> -   stride = strides[0] /4;
> +   stride = strides[0] / pstride;
>  
>     img = dri2_create_image_from_fd(screen, width, height, format,
>                                     fds[0], stride, loaderPrivate);

[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

[-- Attachment #2: Type: text/plain, Size: 159 bytes --]

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] dri2: Fix stride to pitch conversion
  2015-12-21 15:12 ` Nicolas Dufresne
@ 2015-12-21 15:26   ` Daniel Vetter
  0 siblings, 0 replies; 3+ messages in thread
From: Daniel Vetter @ 2015-12-21 15:26 UTC (permalink / raw)
  To: Nicolas Dufresne; +Cc: dri-devel, Nicolas Dufresne

On Mon, Dec 21, 2015 at 10:12:54AM -0500, Nicolas Dufresne wrote:
> Le samedi 19 décembre 2015 à 11:02 -0500, Nicolas Dufresne a écrit :
> > Not all color formats have a pixel stride of 4 bytes. This
> > fixes importation of RGB565 images.
> 
> 
> I just notice there is generic method to get the pixel stride (called
> block something size iirc). But worst then that, the underlying
> function will simply convert back to stride, better then this patch is
> to change this function to take a stride as parameter. I'll submit a
> new patch, please ignore this one.
> 
> > 
> > Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>

Since this is a mesa patch please resubmit to
mesa-devel@lists.freedesktop.org. This list here is for the drm component
(despite that it says dri-devel, I know confusing ...).

Thanks, Daniel

> > ---
> >  src/gallium/state_trackers/dri/dri2.c | 28 +++++++++++++++++------
> > -----
> >  1 file changed, 17 insertions(+), 11 deletions(-)
> > 
> > diff --git a/src/gallium/state_trackers/dri/dri2.c
> > b/src/gallium/state_trackers/dri/dri2.c
> > index a11a6cb..1373785 100644
> > --- a/src/gallium/state_trackers/dri/dri2.c
> > +++ b/src/gallium/state_trackers/dri/dri2.c
> > @@ -46,34 +46,40 @@
> >  #include "dri_query_renderer.h"
> >  #include "dri2_buffer.h"
> >  
> > -static int convert_fourcc(int format, int *dri_components_p)
> > +static int convert_fourcc(int format, int *dri_components_p, int
> > *pstride_p)
> >  {
> > -   int dri_components;
> > +   int dri_components, pstride;
> >     switch(format) {
> >     case __DRI_IMAGE_FOURCC_RGB565:
> >        format = __DRI_IMAGE_FORMAT_RGB565;
> >        dri_components = __DRI_IMAGE_COMPONENTS_RGB;
> > +      pstride = 2;
> >        break;
> >     case __DRI_IMAGE_FOURCC_ARGB8888:
> >        format = __DRI_IMAGE_FORMAT_ARGB8888;
> >        dri_components = __DRI_IMAGE_COMPONENTS_RGBA;
> > +      pstride = 4;
> >        break;
> >     case __DRI_IMAGE_FOURCC_XRGB8888:
> >        format = __DRI_IMAGE_FORMAT_XRGB8888;
> >        dri_components = __DRI_IMAGE_COMPONENTS_RGB;
> > +      pstride = 4;
> >        break;
> >     case __DRI_IMAGE_FOURCC_ABGR8888:
> >        format = __DRI_IMAGE_FORMAT_ABGR8888;
> >        dri_components = __DRI_IMAGE_COMPONENTS_RGBA;
> > +      pstride = 4;
> >        break;
> >     case __DRI_IMAGE_FOURCC_XBGR8888:
> >        format = __DRI_IMAGE_FORMAT_XBGR8888;
> >        dri_components = __DRI_IMAGE_COMPONENTS_RGB;
> > +      pstride = 4;
> >        break;
> >     default:
> >        return -1;
> >     }
> >     *dri_components_p = dri_components;
> > +   *pstride_p = pstride;
> >     return format;
> >  }
> >  
> > @@ -986,19 +992,19 @@ dri2_from_names(__DRIscreen *screen, int width,
> > int height, int format,
> >                  void *loaderPrivate)
> >  {
> >     __DRIimage *img;
> > -   int stride, dri_components;
> > +   int stride, pstride, dri_components;
> >  
> >     if (num_names != 1)
> >        return NULL;
> >     if (offsets[0] != 0)
> >        return NULL;
> >  
> > -   format = convert_fourcc(format, &dri_components);
> > +   format = convert_fourcc(format, &dri_components, &pstride);
> >     if (format == -1)
> >        return NULL;
> >  
> >     /* Strides are in bytes not pixels. */
> > -   stride = strides[0] /4;
> > +   stride = strides[0] / pstride;
> >  
> >     img = dri2_create_image_from_name(screen, width, height, format,
> >                                       names[0], stride, 
> > loaderPrivate);
> > @@ -1101,19 +1107,19 @@ dri2_from_fds(__DRIscreen *screen, int width,
> > int height, int fourcc,
> >                void *loaderPrivate)
> >  {
> >     __DRIimage *img;
> > -   int format, stride, dri_components;
> > +   int format, stride, pstride, dri_components;
> >  
> >     if (num_fds != 1)
> >        return NULL;
> >     if (offsets[0] != 0)
> >        return NULL;
> >  
> > -   format = convert_fourcc(fourcc, &dri_components);
> > +   format = convert_fourcc(fourcc, &dri_components, &pstride);
> >     if (format == -1)
> >        return NULL;
> >  
> >     /* Strides are in bytes not pixels. */
> > -   stride = strides[0] /4;
> > +   stride = strides[0] / pstride;
> >  
> >     img = dri2_create_image_from_fd(screen, width, height, format,
> >                                     fds[0], stride, loaderPrivate);
> > @@ -1137,21 +1143,21 @@ dri2_from_dma_bufs(__DRIscreen *screen,
> >                     void *loaderPrivate)
> >  {
> >     __DRIimage *img;
> > -   int format, stride, dri_components;
> > +   int format, stride, pstride, dri_components;
> >  
> >     if (num_fds != 1 || offsets[0] != 0) {
> >        *error = __DRI_IMAGE_ERROR_BAD_MATCH;
> >        return NULL;
> >     }
> >  
> > -   format = convert_fourcc(fourcc, &dri_components);
> > +   format = convert_fourcc(fourcc, &dri_components, &pstride);
> >     if (format == -1) {
> >        *error = __DRI_IMAGE_ERROR_BAD_MATCH;
> >        return NULL;
> >     }
> >  
> >     /* Strides are in bytes not pixels. */
> > -   stride = strides[0] /4;
> > +   stride = strides[0] / pstride;
> >  
> >     img = dri2_create_image_from_fd(screen, width, height, format,
> >                                     fds[0], stride, loaderPrivate);



> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel


-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-12-21 15:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-19 16:02 [PATCH] dri2: Fix stride to pitch conversion Nicolas Dufresne
2015-12-21 15:12 ` Nicolas Dufresne
2015-12-21 15:26   ` Daniel Vetter

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.