<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p>Hi Christian,</p>
<p><br>
</p>
<p>Style issue is fixed. </p>
<p><br>
</p>
<p>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.</p>
<p><br>
</p>
<p>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.</p>
<p><br>
</p>
<p>Regards,</p>
<p>Boyuan</p>
<br>
<br>
<div style="color: rgb(0, 0, 0);">
<div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Christian König <deathsimple@vodafone.de><br>
<b>Sent:</b> July 1, 2016 8:51 AM<br>
<b>To:</b> Zhang, Boyuan; mesa-dev@lists.freedesktop.org<br>
<b>Subject:</b> Re: [PATCH 06/12] st/va: colorspace conversion when image is yv12 and surface is nv12</font>
<div> </div>
</div>
</div>
<font size="2"><span style="font-size:10pt;">
<div class="PlainText">Am 30.06.2016 um 20:30 schrieb Boyuan Zhang:<br>
> Signed-off-by: Boyuan Zhang <boyuan.zhang@amd.com><br>
> ---<br>
>   src/gallium/state_trackers/va/image.c | 48 +++++++++++++++++++++++++++++------<br>
>   1 file changed, 40 insertions(+), 8 deletions(-)<br>
><br>
> diff --git a/src/gallium/state_trackers/va/image.c b/src/gallium/state_trackers/va/image.c<br>
> index 3c8cc9c..1f68169 100644<br>
> --- a/src/gallium/state_trackers/va/image.c<br>
> +++ b/src/gallium/state_trackers/va/image.c<br>
> @@ -499,7 +499,7 @@ vlVaPutImage(VADriverContextP ctx, VASurfaceID surface, VAImageID image,<br>
>      VAImage *vaimage;<br>
>      struct pipe_sampler_view **views;<br>
>      enum pipe_format format;<br>
> -   void *data[3];<br>
> +   uint8_t *data[3];<br>
>      unsigned pitches[3], i, j;<br>
>   <br>
>      if (!ctx)<br>
> @@ -539,7 +539,9 @@ vlVaPutImage(VADriverContextP ctx, VASurfaceID surface, VAImageID image,<br>
>         return VA_STATUS_ERROR_OPERATION_FAILED;<br>
>      }<br>
>   <br>
> -   if (format != surf->buffer->buffer_format) {<br>
> +   if ((format != surf->buffer->buffer_format) &&<br>
> +      ((format != PIPE_FORMAT_YV12) || (surf->buffer->buffer_format != PIPE_FORMAT_NV12)) &&<br>
> +      ((format != PIPE_FORMAT_IYUV) || (surf->buffer->buffer_format != PIPE_FORMAT_NV12))) {<br>
>         struct pipe_video_buffer *tmp_buf;<br>
>         struct pipe_video_buffer templat = surf->templat;<br>
>   <br>
> @@ -581,12 +583,42 @@ vlVaPutImage(VADriverContextP ctx, VASurfaceID surface, VAImageID image,<br>
>         unsigned width, height;<br>
>         if (!views[i]) continue;<br>
>         vlVaVideoSurfaceSize(surf, i, &width, &height);<br>
> -      for (j = 0; j < views[i]->texture->array_size; ++j) {<br>
> -         struct pipe_box dst_box = {0, 0, j, width, height, 1};<br>
> -         drv->pipe->transfer_inline_write(drv->pipe, views[i]->texture, 0,<br>
> -            PIPE_TRANSFER_WRITE, &dst_box,<br>
> -            data[i] + pitches[i] * j,<br>
> -            pitches[i] * views[i]->texture->array_size, 0);<br>
> +      if ((format == PIPE_FORMAT_YV12) || (format == PIPE_FORMAT_IYUV) &&<br>
> +         (surf->buffer->buffer_format == PIPE_FORMAT_NV12) && (i == 1)) {<br>
> +         struct pipe_transfer *transfer = NULL;<br>
> +         uint8_t *map = NULL;<br>
> +         struct pipe_box dst_box_1 = {0, 0, 0, width, height, 1};<br>
> +         map = drv->pipe->transfer_map(drv->pipe,<br>
> +                                       views[i]->texture,<br>
> +                                       0,<br>
> +                                       PIPE_TRANSFER_DISCARD_RANGE,<br>
> +                                       &dst_box_1, &transfer);<br>
> +         if (map == NULL)<br>
> +            return VA_STATUS_ERROR_OPERATION_FAILED;<br>
> +<br>
> +         bool odd = false;<br>
> +         for (unsigned int k = 0; k < ((vaimage->offsets[1])/2) ; k++){<br>
> +            if (odd == false) {<br>
> +               map[k] = data[i][k/2];<br>
> +               odd = true;<br>
> +            }<br>
> +            else {<br>
> +               map[k] = data[i+1][k/2];<br>
> +               odd = false;<br>
> +            }<br>
> +         }<br>
> +         pipe_transfer_unmap(drv->pipe, transfer);<br>
> +         pipe_mutex_unlock(drv->mutex);<br>
> +         return VA_STATUS_SUCCESS;<br>
> +      }<br>
> +      else {<br>
<br>
Style issue, the "}" and the "else {" should be on the same line.<br>
<br>
Apart from that please use the u_copy_yv12_to_nv12() functions for the <br>
conversion instead of coding it manually.<br>
<br>
Also the code doesn't looks like it handles IYUV correctly.<br>
<br>
Regards,<br>
Christian.<br>
<br>
> +         for (j = 0; j < views[i]->texture->array_size; ++j) {<br>
> +            struct pipe_box dst_box = {0, 0, j, width, height, 1};<br>
> +            drv->pipe->transfer_inline_write(drv->pipe, views[i]->texture, 0,<br>
> +               PIPE_TRANSFER_WRITE, &dst_box,<br>
> +               data[i] + pitches[i] * j,<br>
> +               pitches[i] * views[i]->texture->array_size, 0);<br>
> +         }<br>
>         }<br>
>      }<br>
>      pipe_mutex_unlock(drv->mutex);<br>
<br>
</div>
</span></font></div>
</div>
</body>
</html>