Re: [PATCH] dri2: Fix stride to pitch conversion

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxx>
> ---
>  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: signature.asc
Description: This is a digitally signed message part

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

[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux