[Mesa-dev] [PATCH 06/12] st/va: colorspace conversion when image is yv12 and surface is nv12

Zhang, Boyuan Boyuan.Zhang at amd.com
Thu Jul 14 02:09:40 UTC 2016


Hi Christian,


Style issue is fixed.


Also, I checked the utility function, it seems that the existing yv12 to nv12 function can't be used for "copying from image to surface" case, so I added a new function in the utility function to do this job. Please see the new submitted patch set.


For IYUV case, it's already converted to yv12 (by swapping u and v field) before the colorspace conversion call, so IYUV case should also work.


Regards,

Boyuan


________________________________
From: Christian König <deathsimple at vodafone.de>
Sent: July 1, 2016 8:51 AM
To: Zhang, Boyuan; mesa-dev at lists.freedesktop.org
Subject: Re: [PATCH 06/12] st/va: colorspace conversion when image is yv12 and surface is nv12

Am 30.06.2016 um 20:30 schrieb Boyuan Zhang:
> Signed-off-by: Boyuan Zhang <boyuan.zhang at amd.com>
> ---
>   src/gallium/state_trackers/va/image.c | 48 +++++++++++++++++++++++++++++------
>   1 file changed, 40 insertions(+), 8 deletions(-)
>
> diff --git a/src/gallium/state_trackers/va/image.c b/src/gallium/state_trackers/va/image.c
> index 3c8cc9c..1f68169 100644
> --- a/src/gallium/state_trackers/va/image.c
> +++ b/src/gallium/state_trackers/va/image.c
> @@ -499,7 +499,7 @@ vlVaPutImage(VADriverContextP ctx, VASurfaceID surface, VAImageID image,
>      VAImage *vaimage;
>      struct pipe_sampler_view **views;
>      enum pipe_format format;
> -   void *data[3];
> +   uint8_t *data[3];
>      unsigned pitches[3], i, j;
>
>      if (!ctx)
> @@ -539,7 +539,9 @@ vlVaPutImage(VADriverContextP ctx, VASurfaceID surface, VAImageID image,
>         return VA_STATUS_ERROR_OPERATION_FAILED;
>      }
>
> -   if (format != surf->buffer->buffer_format) {
> +   if ((format != surf->buffer->buffer_format) &&
> +      ((format != PIPE_FORMAT_YV12) || (surf->buffer->buffer_format != PIPE_FORMAT_NV12)) &&
> +      ((format != PIPE_FORMAT_IYUV) || (surf->buffer->buffer_format != PIPE_FORMAT_NV12))) {
>         struct pipe_video_buffer *tmp_buf;
>         struct pipe_video_buffer templat = surf->templat;
>
> @@ -581,12 +583,42 @@ vlVaPutImage(VADriverContextP ctx, VASurfaceID surface, VAImageID image,
>         unsigned width, height;
>         if (!views[i]) continue;
>         vlVaVideoSurfaceSize(surf, i, &width, &height);
> -      for (j = 0; j < views[i]->texture->array_size; ++j) {
> -         struct pipe_box dst_box = {0, 0, j, width, height, 1};
> -         drv->pipe->transfer_inline_write(drv->pipe, views[i]->texture, 0,
> -            PIPE_TRANSFER_WRITE, &dst_box,
> -            data[i] + pitches[i] * j,
> -            pitches[i] * views[i]->texture->array_size, 0);
> +      if ((format == PIPE_FORMAT_YV12) || (format == PIPE_FORMAT_IYUV) &&
> +         (surf->buffer->buffer_format == PIPE_FORMAT_NV12) && (i == 1)) {
> +         struct pipe_transfer *transfer = NULL;
> +         uint8_t *map = NULL;
> +         struct pipe_box dst_box_1 = {0, 0, 0, width, height, 1};
> +         map = drv->pipe->transfer_map(drv->pipe,
> +                                       views[i]->texture,
> +                                       0,
> +                                       PIPE_TRANSFER_DISCARD_RANGE,
> +                                       &dst_box_1, &transfer);
> +         if (map == NULL)
> +            return VA_STATUS_ERROR_OPERATION_FAILED;
> +
> +         bool odd = false;
> +         for (unsigned int k = 0; k < ((vaimage->offsets[1])/2) ; k++){
> +            if (odd == false) {
> +               map[k] = data[i][k/2];
> +               odd = true;
> +            }
> +            else {
> +               map[k] = data[i+1][k/2];
> +               odd = false;
> +            }
> +         }
> +         pipe_transfer_unmap(drv->pipe, transfer);
> +         pipe_mutex_unlock(drv->mutex);
> +         return VA_STATUS_SUCCESS;
> +      }
> +      else {

Style issue, the "}" and the "else {" should be on the same line.

Apart from that please use the u_copy_yv12_to_nv12() functions for the
conversion instead of coding it manually.

Also the code doesn't looks like it handles IYUV correctly.

Regards,
Christian.

> +         for (j = 0; j < views[i]->texture->array_size; ++j) {
> +            struct pipe_box dst_box = {0, 0, j, width, height, 1};
> +            drv->pipe->transfer_inline_write(drv->pipe, views[i]->texture, 0,
> +               PIPE_TRANSFER_WRITE, &dst_box,
> +               data[i] + pitches[i] * j,
> +               pitches[i] * views[i]->texture->array_size, 0);
> +         }
>         }
>      }
>      pipe_mutex_unlock(drv->mutex);

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20160714/4d5e28b7/attachment.html>


More information about the mesa-dev mailing list