Merge commit 'b5f536d24b5ae360503935c34d5d59fa5181b94d'
authorMichael Niedermayer <michaelni@gmx.at>
Sun, 24 Feb 2013 13:14:28 +0000 (14:14 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Sun, 24 Feb 2013 13:14:28 +0000 (14:14 +0100)
* commit 'b5f536d24b5ae360503935c34d5d59fa5181b94d':
  pnm: add high-bitdepth PGMYUV support for both encoder and decoder

Conflicts:
libavcodec/pnm.c
libavcodec/pnmdec.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavcodec/pnm.c
libavcodec/pnmdec.c
libavcodec/pnmenc.c

@@@ -163,8 -152,18 +163,15 @@@ int ff_pnm_decode_header(AVCodecContex
          if (s->maxval >= 256) {
              if (avctx->pix_fmt == AV_PIX_FMT_GRAY8) {
                  avctx->pix_fmt = AV_PIX_FMT_GRAY16BE;
 -                if (s->maxval != 65535)
 -                    avctx->pix_fmt = AV_PIX_FMT_GRAY16;
              } else if (avctx->pix_fmt == AV_PIX_FMT_RGB24) {
 -                if (s->maxval > 255)
 -                    avctx->pix_fmt = AV_PIX_FMT_RGB48BE;
 +                avctx->pix_fmt = AV_PIX_FMT_RGB48BE;
+             } else if (avctx->pix_fmt == AV_PIX_FMT_YUV420P && s->maxval < 65536) {
+                 if (s->maxval < 512)
+                     avctx->pix_fmt = AV_PIX_FMT_YUV420P9BE;
+                 else if (s->maxval < 1024)
+                     avctx->pix_fmt = AV_PIX_FMT_YUV420P10BE;
+                 else
+                     avctx->pix_fmt = AV_PIX_FMT_YUV420P16;
              } else {
                  av_log(avctx, AV_LOG_ERROR, "Unsupported pixel format\n");
                  avctx->pix_fmt = AV_PIX_FMT_NONE;
@@@ -184,6 -166,65 +188,47 @@@ static int pnm_decode_frame(AVCodecCont
              }
          }
          break;
 -    case AV_PIX_FMT_RGB32:
 -        ptr      = p->data[0];
 -        linesize = p->linesize[0];
 -        if (s->bytestream + avctx->width * avctx->height * 4 > s->bytestream_end)
 -            return AVERROR_INVALIDDATA;
 -        for (i = 0; i < avctx->height; i++) {
 -            int j, r, g, b, a;
 -
 -            for (j = 0; j < avctx->width; j++) {
 -                r = *s->bytestream++;
 -                g = *s->bytestream++;
 -                b = *s->bytestream++;
 -                a = *s->bytestream++;
 -                ((uint32_t *)ptr)[j] = (a << 24) | (r << 16) | (g << 8) | b;
 -            }
 -            ptr += linesize;
 -        }
 -        break;
+     case AV_PIX_FMT_YUV420P16:
+         {
+             uint16_t *ptr1, *ptr2;
+             const int f = (65535 * 32768 + s->maxval / 2) / s->maxval;
+             unsigned int j, v;
+             n        = avctx->width * 2;
+             ptr      = p->data[0];
+             linesize = p->linesize[0];
+             if (s->bytestream + n * avctx->height * 3 / 2 > s->bytestream_end)
+                 return AVERROR_INVALIDDATA;
+             for (i = 0; i < avctx->height; i++) {
+                 for (j = 0; j < n / 2; j++) {
+                     v = av_be2ne16(((uint16_t *)s->bytestream)[j]);
+                     ((uint16_t *)ptr)[j] = (v * f + 16384) >> 15;
+                 }
+                 s->bytestream += n;
+                 ptr           += linesize;
+             }
+             ptr1 = (uint16_t*)p->data[1];
+             ptr2 = (uint16_t*)p->data[2];
+             n >>= 1;
+             h = avctx->height >> 1;
+             for (i = 0; i < h; i++) {
+                 for (j = 0; j < n / 2; j++) {
+                     v = av_be2ne16(((uint16_t *)s->bytestream)[j]);
+                     ptr1[j] = (v * f + 16384) >> 15;
+                 }
+                 s->bytestream += n;
+                 for (j = 0; j < n / 2; j++) {
+                     v = av_be2ne16(((uint16_t *)s->bytestream)[j]);
+                     ptr2[j] = (v * f + 16384) >> 15;
+                 }
+                 s->bytestream += n;
+                 ptr1 += p->linesize[1] / 2;
+                 ptr2 += p->linesize[2] / 2;
+             }
+         }
+         break;
      }
      *picture   = s->picture;
      *got_frame = 1;
@@@ -19,7 -19,9 +19,8 @@@
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
+ #include "libavutil/pixdesc.h"
  #include "avcodec.h"
 -#include "bytestream.h"
  #include "internal.h"
  #include "pnm.h"