ff_video_dec: single-pass rgb -> yuy2 conversion
authorTorsten Jager <t.jager@gmx.de>
Mon, 21 Jan 2013 10:51:54 +0200
changeset 122835e4ae6259dbd
parent 12282 bc4029b22f70
child 12284 7fe6f926f6c2
ff_video_dec: single-pass rgb -> yuy2 conversion
src/combined/ffmpeg/ff_video_decoder.c
     1.1 --- a/src/combined/ffmpeg/ff_video_decoder.c	Mon Jan 21 10:23:56 2013 +0200
     1.2 +++ b/src/combined/ffmpeg/ff_video_decoder.c	Mon Jan 21 10:51:54 2013 +0200
     1.3 @@ -101,7 +101,6 @@
     1.4    uint8_t           decoder_init_mode:1;
     1.5    uint8_t           is_mpeg12:1;
     1.6    uint8_t           pp_available:1;
     1.7 -  uint8_t           yuv_init:1;
     1.8    uint8_t           is_direct_rendering_disabled:1;  /* used only to avoid flooding log */
     1.9    uint8_t           cs_convert_init:1;
    1.10    uint8_t           assume_bad_field_picture:1;
    1.11 @@ -135,8 +134,6 @@
    1.12  
    1.13    xine_list_t       *dr1_frames;
    1.14  
    1.15 -  yuv_planes_t      yuv;
    1.16 -
    1.17  #ifdef AVPaletteControl
    1.18    AVPaletteControl  palette_control;
    1.19  #endif
    1.20 @@ -144,6 +141,9 @@
    1.21    int               color_matrix, full2mpeg;
    1.22    unsigned char     ytab[256], ctab[256];
    1.23  
    1.24 +  int               pix_fmt;
    1.25 +  void             *rgb2yuy2;
    1.26 +
    1.27  #ifdef LOG
    1.28    enum PixelFormat  debug_fmt;
    1.29  #endif
    1.30 @@ -784,6 +784,36 @@
    1.31    return 1;
    1.32  }
    1.33  
    1.34 +static void ff_setup_rgb2yuy2 (ff_video_decoder_t *this, int pix_fmt) {
    1.35 +  const char *fmt = "";
    1.36 +  int cm = 10; /* mpeg range ITU-R 601 */
    1.37 +
    1.38 +  switch (pix_fmt) {
    1.39 +    case PIX_FMT_ARGB:     fmt = "argb";     break;
    1.40 +    case PIX_FMT_BGRA:     fmt = "bgra";     break;
    1.41 +    case PIX_FMT_RGB24:    fmt = "rgb";      break;
    1.42 +    case PIX_FMT_BGR24:    fmt = "bgr";      break;
    1.43 +    case PIX_FMT_RGB555BE: fmt = "rgb555be"; break;
    1.44 +    case PIX_FMT_RGB555LE: fmt = "rgb555le"; break;
    1.45 +    case PIX_FMT_RGB565BE: fmt = "rgb565be"; break;
    1.46 +    case PIX_FMT_RGB565LE: fmt = "rgb565le"; break;
    1.47 +#ifdef __BIG_ENDIAN__
    1.48 +    case PIX_FMT_PAL8:     fmt = "argb";     break;
    1.49 +#else
    1.50 +    case PIX_FMT_PAL8:     fmt = "bgra";     break;
    1.51 +#endif
    1.52 +  }
    1.53 +  if (this->stream->video_out->get_capabilities (this->stream->video_out) & VO_CAP_FULLRANGE)
    1.54 +    cm = 11; /* full range */
    1.55 +  free (this->rgb2yuy2);
    1.56 +  this->rgb2yuy2 = rgb2yuy2_alloc (cm, fmt);
    1.57 +  this->pix_fmt = pix_fmt;
    1.58 +  VO_SET_FLAGS_CM (cm, this->frame_flags);
    1.59 +  if (pix_fmt == PIX_FMT_PAL8) fmt = "pal8";
    1.60 +  xprintf (this->stream->xine, XINE_VERBOSITY_LOG,
    1.61 +    "ffmpeg_video_dec: converting %s -> %s yuy2\n", fmt, cm_names[cm]);
    1.62 +}
    1.63 +
    1.64  static void ff_convert_frame(ff_video_decoder_t *this, vo_frame_t *img, AVFrame *av_frame) {
    1.65    int         y;
    1.66    uint8_t    *dy, *du, *dv, *sy, *su, *sv;
    1.67 @@ -806,311 +836,166 @@
    1.68     * so we use this->bih.biHeight instead (which is the displayed height)
    1.69     */
    1.70  
    1.71 -  if (this->context->pix_fmt == PIX_FMT_YUV410P) {
    1.72 +  switch (this->context->pix_fmt) {
    1.73 +    case PIX_FMT_YUV410P:
    1.74 +      yuv9_to_yv12(
    1.75 +       /* Y */
    1.76 +        av_frame->data[0],
    1.77 +        av_frame->linesize[0],
    1.78 +        img->base[0],
    1.79 +        img->pitches[0],
    1.80 +       /* U */
    1.81 +        av_frame->data[1],
    1.82 +        av_frame->linesize[1],
    1.83 +        img->base[1],
    1.84 +        img->pitches[1],
    1.85 +       /* V */
    1.86 +        av_frame->data[2],
    1.87 +        av_frame->linesize[2],
    1.88 +        img->base[2],
    1.89 +        img->pitches[2],
    1.90 +       /* width x height */
    1.91 +        img->width,
    1.92 +        this->bih.biHeight);
    1.93 +    break;
    1.94  
    1.95 -    yuv9_to_yv12(
    1.96 -     /* Y */
    1.97 -      av_frame->data[0],
    1.98 -      av_frame->linesize[0],
    1.99 -      img->base[0],
   1.100 -      img->pitches[0],
   1.101 -     /* U */
   1.102 -      av_frame->data[1],
   1.103 -      av_frame->linesize[1],
   1.104 -      img->base[1],
   1.105 -      img->pitches[1],
   1.106 -     /* V */
   1.107 -      av_frame->data[2],
   1.108 -      av_frame->linesize[2],
   1.109 -      img->base[2],
   1.110 -      img->pitches[2],
   1.111 -     /* width x height */
   1.112 -      img->width,
   1.113 -      this->bih.biHeight);
   1.114 +    case PIX_FMT_YUV411P:
   1.115 +      yuv411_to_yv12(
   1.116 +       /* Y */
   1.117 +        av_frame->data[0],
   1.118 +        av_frame->linesize[0],
   1.119 +        img->base[0],
   1.120 +        img->pitches[0],
   1.121 +       /* U */
   1.122 +        av_frame->data[1],
   1.123 +        av_frame->linesize[1],
   1.124 +        img->base[1],
   1.125 +        img->pitches[1],
   1.126 +       /* V */
   1.127 +        av_frame->data[2],
   1.128 +        av_frame->linesize[2],
   1.129 +        img->base[2],
   1.130 +        img->pitches[2],
   1.131 +       /* width x height */
   1.132 +        img->width,
   1.133 +        this->bih.biHeight);
   1.134 +    break;
   1.135  
   1.136 -  } else if (this->context->pix_fmt == PIX_FMT_YUV411P) {
   1.137 +    /* PIX_FMT_RGB32 etc. are only aliases for the native endian versions.
   1.138 +       Lets support them both - wont harm performance here :-) */
   1.139  
   1.140 -    yuv411_to_yv12(
   1.141 -     /* Y */
   1.142 -      av_frame->data[0],
   1.143 -      av_frame->linesize[0],
   1.144 -      img->base[0],
   1.145 -      img->pitches[0],
   1.146 -     /* U */
   1.147 -      av_frame->data[1],
   1.148 -      av_frame->linesize[1],
   1.149 -      img->base[1],
   1.150 -      img->pitches[1],
   1.151 -     /* V */
   1.152 -      av_frame->data[2],
   1.153 -      av_frame->linesize[2],
   1.154 -      img->base[2],
   1.155 -      img->pitches[2],
   1.156 -     /* width x height */
   1.157 -      img->width,
   1.158 -      this->bih.biHeight);
   1.159 +    case PIX_FMT_ARGB:
   1.160 +    case PIX_FMT_BGRA:
   1.161 +    case PIX_FMT_RGB24:
   1.162 +    case PIX_FMT_BGR24:
   1.163  
   1.164 -  } else if (this->context->pix_fmt == PIX_FMT_RGB32) {
   1.165 +    case PIX_FMT_RGB555BE:
   1.166 +    case PIX_FMT_RGB555LE:
   1.167 +    case PIX_FMT_RGB565BE:
   1.168 +    case PIX_FMT_RGB565LE:
   1.169 +      if (this->pix_fmt != this->context->pix_fmt)
   1.170 +        ff_setup_rgb2yuy2 (this, this->context->pix_fmt);
   1.171 +      rgb2yuy2_slice (this->rgb2yuy2, sy, av_frame->linesize[0],
   1.172 +        img->base[0], img->pitches[0], img->width, this->bih.biHeight);
   1.173 +    break;
   1.174  
   1.175 -    int x, plane_ptr = 0;
   1.176 -    uint32_t *argb_pixels;
   1.177 -    uint32_t argb;
   1.178 +    case PIX_FMT_PAL8:
   1.179 +      if (this->pix_fmt != this->context->pix_fmt)
   1.180 +        ff_setup_rgb2yuy2 (this, this->context->pix_fmt);
   1.181 +      rgb2yuy2_palette (this->rgb2yuy2, su, 256, 8);
   1.182 +      rgb2yuy2_slice (this->rgb2yuy2, sy, av_frame->linesize[0],
   1.183 +        img->base[0], img->pitches[0], img->width, this->bih.biHeight);
   1.184 +    break;
   1.185  
   1.186 -    for(y = 0; y < this->bih.biHeight; y++) {
   1.187 -      argb_pixels = (uint32_t *)sy;
   1.188 -      for(x = 0; x < img->width; x++) {
   1.189 -        uint8_t r, g, b;
   1.190 +    default: {
   1.191 +      int subsamph = (this->context->pix_fmt == PIX_FMT_YUV444P)
   1.192 +                  || (this->context->pix_fmt == PIX_FMT_YUVJ444P);
   1.193 +      int subsampv = (this->context->pix_fmt != PIX_FMT_YUV420P)
   1.194 +                  && (this->context->pix_fmt != PIX_FMT_YUVJ420P);
   1.195  
   1.196 -        /* this is endian-safe as the ARGB pixels are stored in
   1.197 -         * machine order */
   1.198 -        argb = *argb_pixels++;
   1.199 -        r = (argb >> 16) & 0xFF;
   1.200 -        g = (argb >>  8) & 0xFF;
   1.201 -        b = (argb >>  0) & 0xFF;
   1.202 +      if (this->full2mpeg) {
   1.203  
   1.204 -        this->yuv.y[plane_ptr] = COMPUTE_Y(r, g, b);
   1.205 -        this->yuv.u[plane_ptr] = COMPUTE_U(r, g, b);
   1.206 -        this->yuv.v[plane_ptr] = COMPUTE_V(r, g, b);
   1.207 -        plane_ptr++;
   1.208 -      }
   1.209 -      sy += av_frame->linesize[0];
   1.210 -    }
   1.211 +        uint8_t *ytab = this->ytab;
   1.212 +        uint8_t *ctab = this->ctab;
   1.213 +        uint8_t *p, *q;
   1.214 +        int x;
   1.215  
   1.216 -    yuv444_to_yuy2(&this->yuv, img->base[0], img->pitches[0]);
   1.217 +        for (y = 0; y < this->bih.biHeight; y++) {
   1.218 +          p = sy;
   1.219 +          q = dy;
   1.220 +          for (x = img->width; x > 0; x--) *q++ = ytab[*p++];
   1.221 +          dy += img->pitches[0];
   1.222 +          sy += av_frame->linesize[0];
   1.223 +        }
   1.224  
   1.225 -  } else if (this->context->pix_fmt == PIX_FMT_RGB565) {
   1.226 -
   1.227 -    int x, plane_ptr = 0;
   1.228 -    uint8_t *src;
   1.229 -    uint16_t pixel16;
   1.230 -
   1.231 -    for(y = 0; y < this->bih.biHeight; y++) {
   1.232 -      src = sy;
   1.233 -      for(x = 0; x < img->width; x++) {
   1.234 -        uint8_t r, g, b;
   1.235 -
   1.236 -        /* a 16-bit RGB565 pixel is supposed to be stored in native-endian
   1.237 -         * byte order; the following should be endian-safe */
   1.238 -        pixel16 = *((uint16_t *)src);
   1.239 -        src += 2;
   1.240 -        b = (pixel16 << 3) & 0xFF;
   1.241 -        g = (pixel16 >> 3) & 0xFF;
   1.242 -        r = (pixel16 >> 8) & 0xFF;
   1.243 -
   1.244 -        this->yuv.y[plane_ptr] = COMPUTE_Y(r, g, b);
   1.245 -        this->yuv.u[plane_ptr] = COMPUTE_U(r, g, b);
   1.246 -        this->yuv.v[plane_ptr] = COMPUTE_V(r, g, b);
   1.247 -        plane_ptr++;
   1.248 -      }
   1.249 -      sy += av_frame->linesize[0];
   1.250 -    }
   1.251 -
   1.252 -    yuv444_to_yuy2(&this->yuv, img->base[0], img->pitches[0]);
   1.253 -
   1.254 -  } else if (this->context->pix_fmt == PIX_FMT_RGB555) {
   1.255 -
   1.256 -    int x, plane_ptr = 0;
   1.257 -    uint8_t *src;
   1.258 -    uint16_t pixel16;
   1.259 -
   1.260 -    for(y = 0; y < this->bih.biHeight; y++) {
   1.261 -      src = sy;
   1.262 -      for(x = 0; x < img->width; x++) {
   1.263 -        uint8_t r, g, b;
   1.264 -
   1.265 -        /* a 16-bit RGB555 pixel is supposed to be stored in native-endian
   1.266 -         * byte order; the following should be endian-safe */
   1.267 -        pixel16 = *((uint16_t *)src);
   1.268 -        src += 2;
   1.269 -        b = (pixel16 << 3) & 0xFF;
   1.270 -        g = (pixel16 >> 2) & 0xFF;
   1.271 -        r = (pixel16 >> 7) & 0xFF;
   1.272 -
   1.273 -        this->yuv.y[plane_ptr] = COMPUTE_Y(r, g, b);
   1.274 -        this->yuv.u[plane_ptr] = COMPUTE_U(r, g, b);
   1.275 -        this->yuv.v[plane_ptr] = COMPUTE_V(r, g, b);
   1.276 -        plane_ptr++;
   1.277 -      }
   1.278 -      sy += av_frame->linesize[0];
   1.279 -    }
   1.280 -
   1.281 -    yuv444_to_yuy2(&this->yuv, img->base[0], img->pitches[0]);
   1.282 -
   1.283 -  } else if (this->context->pix_fmt == PIX_FMT_BGR24) {
   1.284 -
   1.285 -    int x, plane_ptr = 0;
   1.286 -    uint8_t *src;
   1.287 -
   1.288 -    for(y = 0; y < this->bih.biHeight; y++) {
   1.289 -      src = sy;
   1.290 -      for(x = 0; x < img->width; x++) {
   1.291 -        uint8_t r, g, b;
   1.292 -
   1.293 -        b = *src++;
   1.294 -        g = *src++;
   1.295 -        r = *src++;
   1.296 -
   1.297 -        this->yuv.y[plane_ptr] = COMPUTE_Y(r, g, b);
   1.298 -        this->yuv.u[plane_ptr] = COMPUTE_U(r, g, b);
   1.299 -        this->yuv.v[plane_ptr] = COMPUTE_V(r, g, b);
   1.300 -        plane_ptr++;
   1.301 -      }
   1.302 -      sy += av_frame->linesize[0];
   1.303 -    }
   1.304 -
   1.305 -    yuv444_to_yuy2(&this->yuv, img->base[0], img->pitches[0]);
   1.306 -
   1.307 -  } else if (this->context->pix_fmt == PIX_FMT_RGB24) {
   1.308 -
   1.309 -    int x, plane_ptr = 0;
   1.310 -    uint8_t *src;
   1.311 -
   1.312 -    for(y = 0; y < this->bih.biHeight; y++) {
   1.313 -      src = sy;
   1.314 -      for(x = 0; x < img->width; x++) {
   1.315 -        uint8_t r, g, b;
   1.316 -
   1.317 -        r = *src++;
   1.318 -        g = *src++;
   1.319 -        b = *src++;
   1.320 -
   1.321 -        this->yuv.y[plane_ptr] = COMPUTE_Y(r, g, b);
   1.322 -        this->yuv.u[plane_ptr] = COMPUTE_U(r, g, b);
   1.323 -        this->yuv.v[plane_ptr] = COMPUTE_V(r, g, b);
   1.324 -        plane_ptr++;
   1.325 -      }
   1.326 -      sy += av_frame->linesize[0];
   1.327 -    }
   1.328 -
   1.329 -    yuv444_to_yuy2(&this->yuv, img->base[0], img->pitches[0]);
   1.330 -
   1.331 -  } else if (this->context->pix_fmt == PIX_FMT_PAL8) {
   1.332 -
   1.333 -    int x, plane_ptr = 0;
   1.334 -    uint8_t *src;
   1.335 -    uint8_t pixel;
   1.336 -    uint32_t *palette32 = (uint32_t *)su;  /* palette is in data[1] */
   1.337 -    uint32_t rgb_color;
   1.338 -    uint8_t r, g, b;
   1.339 -    uint8_t y_palette[256];
   1.340 -    uint8_t u_palette[256];
   1.341 -    uint8_t v_palette[256];
   1.342 -
   1.343 -    for (x = 0; x < 256; x++) {
   1.344 -      rgb_color = palette32[x];
   1.345 -      b = rgb_color & 0xFF;
   1.346 -      rgb_color >>= 8;
   1.347 -      g = rgb_color & 0xFF;
   1.348 -      rgb_color >>= 8;
   1.349 -      r = rgb_color & 0xFF;
   1.350 -      y_palette[x] = COMPUTE_Y(r, g, b);
   1.351 -      u_palette[x] = COMPUTE_U(r, g, b);
   1.352 -      v_palette[x] = COMPUTE_V(r, g, b);
   1.353 -    }
   1.354 -
   1.355 -    for(y = 0; y < this->bih.biHeight; y++) {
   1.356 -      src = sy;
   1.357 -      for(x = 0; x < img->width; x++) {
   1.358 -        pixel = *src++;
   1.359 -
   1.360 -        this->yuv.y[plane_ptr] = y_palette[pixel];
   1.361 -        this->yuv.u[plane_ptr] = u_palette[pixel];
   1.362 -        this->yuv.v[plane_ptr] = v_palette[pixel];
   1.363 -        plane_ptr++;
   1.364 -      }
   1.365 -      sy += av_frame->linesize[0];
   1.366 -    }
   1.367 -
   1.368 -    yuv444_to_yuy2(&this->yuv, img->base[0], img->pitches[0]);
   1.369 -
   1.370 -  } else {
   1.371 -
   1.372 -    int subsamph = (this->context->pix_fmt == PIX_FMT_YUV444P)
   1.373 -                || (this->context->pix_fmt == PIX_FMT_YUVJ444P);
   1.374 -    int subsampv = (this->context->pix_fmt != PIX_FMT_YUV420P)
   1.375 -                && (this->context->pix_fmt != PIX_FMT_YUVJ420P);
   1.376 -
   1.377 -    if (this->full2mpeg) {
   1.378 -
   1.379 -      uint8_t *ytab = this->ytab;
   1.380 -      uint8_t *ctab = this->ctab;
   1.381 -      uint8_t *p, *q;
   1.382 -      int x;
   1.383 -
   1.384 -      for (y = 0; y < this->bih.biHeight; y++) {
   1.385 -        p = sy;
   1.386 -        q = dy;
   1.387 -        for (x = img->width; x > 0; x--) *q++ = ytab[*p++];
   1.388 -        dy += img->pitches[0];
   1.389 -        sy += av_frame->linesize[0];
   1.390 -      }
   1.391 -
   1.392 -      for (y = 0; y < this->bih.biHeight / 2; y++) {
   1.393 -        if (!subsamph) {
   1.394 -          p = su, q = du;
   1.395 -          for (x = img->width / 2; x > 0; x--) *q++ = ctab[*p++];
   1.396 -          p = sv, q = dv;
   1.397 -          for (x = img->width / 2; x > 0; x--) *q++ = ctab[*p++];
   1.398 -        } else {
   1.399 -          p = su, q = du;
   1.400 -          for (x = img->width / 2; x > 0; x--) {*q++ = ctab[*p]; p += 2;}
   1.401 -          p = sv, q = dv;
   1.402 -          for (x = img->width / 2; x > 0; x--) {*q++ = ctab[*p]; p += 2;}
   1.403 -        }
   1.404 -        du += img->pitches[1];
   1.405 -        dv += img->pitches[2];
   1.406 -        if (subsampv) {
   1.407 -          su += 2 * av_frame->linesize[1];
   1.408 -          sv += 2 * av_frame->linesize[2];
   1.409 -        } else {
   1.410 -          su += av_frame->linesize[1];
   1.411 -          sv += av_frame->linesize[2];
   1.412 -        }
   1.413 -      }
   1.414 -
   1.415 -    } else {
   1.416 -
   1.417 -      for (y = 0; y < this->bih.biHeight; y++) {
   1.418 -        xine_fast_memcpy (dy, sy, img->width);
   1.419 -        dy += img->pitches[0];
   1.420 -        sy += av_frame->linesize[0];
   1.421 -      }
   1.422 -
   1.423 -      for (y = 0; y < this->bih.biHeight / 2; y++) {
   1.424 -        if (!subsamph) {
   1.425 -          xine_fast_memcpy (du, su, img->width/2);
   1.426 -          xine_fast_memcpy (dv, sv, img->width/2);
   1.427 -        } else {
   1.428 -          int x;
   1.429 -          uint8_t *src;
   1.430 -          uint8_t *dst;
   1.431 -          src = su;
   1.432 -          dst = du;
   1.433 -          for (x = 0; x < (img->width / 2); x++) {
   1.434 -            *dst = *src;
   1.435 -            dst++;
   1.436 -            src += 2;
   1.437 +        for (y = 0; y < this->bih.biHeight / 2; y++) {
   1.438 +          if (!subsamph) {
   1.439 +            p = su, q = du;
   1.440 +            for (x = img->width / 2; x > 0; x--) *q++ = ctab[*p++];
   1.441 +            p = sv, q = dv;
   1.442 +            for (x = img->width / 2; x > 0; x--) *q++ = ctab[*p++];
   1.443 +          } else {
   1.444 +            p = su, q = du;
   1.445 +            for (x = img->width / 2; x > 0; x--) {*q++ = ctab[*p]; p += 2;}
   1.446 +            p = sv, q = dv;
   1.447 +            for (x = img->width / 2; x > 0; x--) {*q++ = ctab[*p]; p += 2;}
   1.448            }
   1.449 -          src = sv;
   1.450 -          dst = dv;
   1.451 -          for (x = 0; x < (img->width / 2); x++) {
   1.452 -            *dst = *src;
   1.453 -            dst++;
   1.454 -            src += 2;
   1.455 +          du += img->pitches[1];
   1.456 +          dv += img->pitches[2];
   1.457 +          if (subsampv) {
   1.458 +            su += 2 * av_frame->linesize[1];
   1.459 +            sv += 2 * av_frame->linesize[2];
   1.460 +          } else {
   1.461 +            su += av_frame->linesize[1];
   1.462 +            sv += av_frame->linesize[2];
   1.463            }
   1.464          }
   1.465 -        du += img->pitches[1];
   1.466 -        dv += img->pitches[2];
   1.467 -        if (subsampv) {
   1.468 -          su += 2*av_frame->linesize[1];
   1.469 -          sv += 2*av_frame->linesize[2];
   1.470 -        } else {
   1.471 -          su += av_frame->linesize[1];
   1.472 -          sv += av_frame->linesize[2];
   1.473 +
   1.474 +      } else {
   1.475 +
   1.476 +        for (y = 0; y < this->bih.biHeight; y++) {
   1.477 +          xine_fast_memcpy (dy, sy, img->width);
   1.478 +          dy += img->pitches[0];
   1.479 +          sy += av_frame->linesize[0];
   1.480          }
   1.481 +
   1.482 +        for (y = 0; y < this->bih.biHeight / 2; y++) {
   1.483 +          if (!subsamph) {
   1.484 +            xine_fast_memcpy (du, su, img->width/2);
   1.485 +            xine_fast_memcpy (dv, sv, img->width/2);
   1.486 +          } else {
   1.487 +            int x;
   1.488 +            uint8_t *src;
   1.489 +            uint8_t *dst;
   1.490 +            src = su;
   1.491 +            dst = du;
   1.492 +            for (x = 0; x < (img->width / 2); x++) {
   1.493 +              *dst = *src;
   1.494 +              dst++;
   1.495 +              src += 2;
   1.496 +            }
   1.497 +            src = sv;
   1.498 +            dst = dv;
   1.499 +            for (x = 0; x < (img->width / 2); x++) {
   1.500 +              *dst = *src;
   1.501 +              dst++;
   1.502 +              src += 2;
   1.503 +            }
   1.504 +          }
   1.505 +          du += img->pitches[1];
   1.506 +          dv += img->pitches[2];
   1.507 +          if (subsampv) {
   1.508 +            su += 2*av_frame->linesize[1];
   1.509 +            sv += 2*av_frame->linesize[2];
   1.510 +          } else {
   1.511 +            su += av_frame->linesize[1];
   1.512 +            sv += av_frame->linesize[2];
   1.513 +          }
   1.514 +        }
   1.515 +
   1.516        }
   1.517 -
   1.518      }
   1.519 +    break;
   1.520    }
   1.521  }
   1.522  
   1.523 @@ -1776,20 +1661,25 @@
   1.524          if(!this->av_frame->opaque) {
   1.525  	  /* indirect rendering */
   1.526  
   1.527 -	  /* initialize the colorspace converter */
   1.528 -	  if (!this->cs_convert_init && !this->context->pix_fmt != PIX_FMT_VAAPI_VLD) {
   1.529 -	    if ((this->context->pix_fmt == PIX_FMT_RGB32) ||
   1.530 -	        (this->context->pix_fmt == PIX_FMT_RGB565) ||
   1.531 -	        (this->context->pix_fmt == PIX_FMT_RGB555) ||
   1.532 -	        (this->context->pix_fmt == PIX_FMT_BGR24) ||
   1.533 -	        (this->context->pix_fmt == PIX_FMT_RGB24) ||
   1.534 -	        (this->context->pix_fmt == PIX_FMT_PAL8)) {
   1.535 -	      this->output_format = XINE_IMGFMT_YUY2;
   1.536 -	      init_yuv_planes(&this->yuv, (this->bih.biWidth + 15) & ~15, this->bih.biHeight);
   1.537 -	      this->yuv_init = 1;
   1.538 -	    }
   1.539 -	    this->cs_convert_init = 1;
   1.540 -	  }
   1.541 +          /* prepare for colorspace conversion */
   1.542 +          if (!this->cs_convert_init && !this->context->pix_fmt != PIX_FMT_VAAPI_VLD) {
   1.543 +            switch (this->context->pix_fmt) {
   1.544 +              case PIX_FMT_ARGB:
   1.545 +              case PIX_FMT_BGRA:
   1.546 +              case PIX_FMT_RGB24:
   1.547 +              case PIX_FMT_BGR24:
   1.548 +              case PIX_FMT_RGB555BE:
   1.549 +              case PIX_FMT_RGB555LE:
   1.550 +              case PIX_FMT_RGB565BE:
   1.551 +              case PIX_FMT_RGB565LE:
   1.552 +              case PIX_FMT_PAL8:
   1.553 +                this->output_format = XINE_IMGFMT_YUY2;
   1.554 +              break;
   1.555 +              default:
   1.556 +                this->output_format = XINE_IMGFMT_YV12;
   1.557 +            }
   1.558 +            this->cs_convert_init = 1;
   1.559 +          }
   1.560  
   1.561  	  if (this->aspect_ratio_prio == 0) {
   1.562  	    this->aspect_ratio = (double)this->bih.biWidth / (double)this->bih.biHeight;
   1.563 @@ -2053,6 +1943,8 @@
   1.564  
   1.565    lprintf ("ff_dispose\n");
   1.566  
   1.567 +  rgb2yuy2_free (this->rgb2yuy2);
   1.568 +
   1.569    if (this->decoder_ok) {
   1.570      xine_list_iterator_t it = NULL;
   1.571  
   1.572 @@ -2079,9 +1971,6 @@
   1.573    if(this->context && this->context->extradata)
   1.574      free(this->context->extradata);
   1.575  
   1.576 -  if(this->yuv_init)
   1.577 -    free_yuv_planes(&this->yuv);
   1.578 -
   1.579    if( this->context )
   1.580      av_free( this->context );
   1.581  
   1.582 @@ -2152,6 +2041,9 @@
   1.583    this->dr1_frames        = xine_list_new();
   1.584    this->set_stream_info   = 0;
   1.585  
   1.586 +  this->pix_fmt           = -1;
   1.587 +  this->rgb2yuy2          = NULL;
   1.588 +
   1.589  #ifdef LOG
   1.590    this->debug_fmt = -1;
   1.591  #endif