All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nicolas Dufresne <nicolas.dufresne@collabora.co.uk>
To: dri-devel@lists.freedesktop.org
Subject: [PATCH] dri2: Fix stride to pitch conversion
Date: Sat, 19 Dec 2015 11:02:24 -0500	[thread overview]
Message-ID: <1450540944-25821-1-git-send-email-nicolas.dufresne@collabora.co.uk> (raw)

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

             reply	other threads:[~2015-12-19 16:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-19 16:02 Nicolas Dufresne [this message]
2015-12-21 15:12 ` [PATCH] dri2: Fix stride to pitch conversion Nicolas Dufresne
2015-12-21 15:26   ` Daniel Vetter

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=1450540944-25821-1-git-send-email-nicolas.dufresne@collabora.co.uk \
    --to=nicolas.dufresne@collabora.co.uk \
    --cc=dri-devel@lists.freedesktop.org \
    /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.