]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/pnm.c
hevc: change the stride of the MC buffer to be in bytes instead of elements
[ffmpeg] / libavcodec / pnm.c
index 2a89a723f3cb8aaf3558f00373bdc0d9a9338d8a..1c380b0ff864706bd6545a7b9d1b33d5e0e00365 100644 (file)
@@ -65,7 +65,7 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s)
     pnm_get(s, buf1, sizeof(buf1));
     s->type= buf1[1]-'0';
     if(buf1[0] != 'P')
-        return -1;
+        return AVERROR_INVALIDDATA;
 
     if (s->type==1 || s->type==4) {
         avctx->pix_fmt = AV_PIX_FMT_MONOWHITE;
@@ -103,12 +103,12 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s)
             } else if (!strcmp(buf1, "ENDHDR")) {
                 break;
             } else {
-                return -1;
+                return AVERROR_INVALIDDATA;
             }
         }
         /* check that all tags are present */
         if (w <= 0 || h <= 0 || maxval <= 0 || depth <= 0 || tuple_type[0] == '\0' || av_image_check_size(w, h, 0, avctx))
-            return -1;
+            return AVERROR_INVALIDDATA;
 
         avctx->width  = w;
         avctx->height = h;
@@ -123,25 +123,25 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s)
             } else {
                 av_log(avctx, AV_LOG_ERROR, "16-bit components are only supported for grayscale\n");
                 avctx->pix_fmt = AV_PIX_FMT_NONE;
-                return -1;
+                return AVERROR_INVALIDDATA;
             }
         } else if (depth == 4) {
             avctx->pix_fmt = AV_PIX_FMT_RGB32;
         } else {
-            return -1;
+            return AVERROR_INVALIDDATA;
         }
         return 0;
     } else {
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
     pnm_get(s, buf1, sizeof(buf1));
     avctx->width = atoi(buf1);
     if (avctx->width <= 0)
-        return -1;
+        return AVERROR_INVALIDDATA;
     pnm_get(s, buf1, sizeof(buf1));
     avctx->height = atoi(buf1);
     if(av_image_check_size(avctx->width, avctx->height, 0, avctx))
-        return -1;
+        return AVERROR_INVALIDDATA;
     if (avctx->pix_fmt != AV_PIX_FMT_MONOWHITE) {
         pnm_get(s, buf1, sizeof(buf1));
         s->maxval = atoi(buf1);
@@ -157,43 +157,30 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s)
             } else if (avctx->pix_fmt == AV_PIX_FMT_RGB24) {
                 if (s->maxval > 255)
                     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;
-                return -1;
+                return AVERROR_INVALIDDATA;
             }
         }
     }else
         s->maxval=1;
     /* more check if YUV420 */
-    if (avctx->pix_fmt == AV_PIX_FMT_YUV420P) {
+    if (av_pix_fmt_desc_get(avctx->pix_fmt)->flags & AV_PIX_FMT_FLAG_PLANAR) {
         if ((avctx->width & 1) != 0)
-            return -1;
+            return AVERROR_INVALIDDATA;
         h = (avctx->height * 2);
         if ((h % 3) != 0)
-            return -1;
+            return AVERROR_INVALIDDATA;
         h /= 3;
         avctx->height = h;
     }
     return 0;
 }
-
-av_cold int ff_pnm_end(AVCodecContext *avctx)
-{
-    PNMContext *s = avctx->priv_data;
-
-    if (s->picture.data[0])
-        avctx->release_buffer(avctx, &s->picture);
-
-    return 0;
-}
-
-av_cold int ff_pnm_init(AVCodecContext *avctx)
-{
-    PNMContext *s = avctx->priv_data;
-
-    avcodec_get_frame_defaults(&s->picture);
-    avctx->coded_frame = &s->picture;
-
-    return 0;
-}