]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/pcx.c
lavc: remove disabled FF_API_COLOR_TABLE_ID cruft
[ffmpeg] / libavcodec / pcx.c
index 0a18acd486eed2ff5849cf0845ea42e20f74a29f..949ea1ca70431bca3d38bd33423cb445be973ba8 100644 (file)
 #include "avcodec.h"
 #include "bytestream.h"
 #include "get_bits.h"
-
-typedef struct PCXContext {
-    AVFrame picture;
-} PCXContext;
-
-static av_cold int pcx_init(AVCodecContext *avctx) {
-    PCXContext *s = avctx->priv_data;
-
-    avcodec_get_frame_defaults(&s->picture);
-    avctx->coded_frame= &s->picture;
-
-    return 0;
-}
+#include "internal.h"
 
 /**
  * @return advanced src pointer
@@ -76,13 +64,11 @@ static void pcx_palette(const uint8_t **src, uint32_t *dst, unsigned int pallen)
         memset(dst, 0, (256 - pallen) * sizeof(*dst));
 }
 
-static int pcx_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
+static int pcx_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
                             AVPacket *avpkt) {
     const uint8_t *buf = avpkt->data;
     int buf_size = avpkt->size;
-    PCXContext * const s = avctx->priv_data;
-    AVFrame *picture = data;
-    AVFrame * const p = &s->picture;
+    AVFrame * const p = data;
     int compressed, xmin, ymin, xmax, ymax;
     unsigned int w, h, bits_per_pixel, bytes_per_line, nplanes, stride, y, x,
                  bytes_per_scanline;
@@ -93,7 +79,7 @@ static int pcx_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
 
     if (buf[0] != 0x0a || buf[1] > 5) {
         av_log(avctx, AV_LOG_ERROR, "this is not PCX encoded data\n");
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
     compressed = buf[2];
@@ -104,7 +90,7 @@ static int pcx_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
 
     if (xmax < xmin || ymax < ymin) {
         av_log(avctx, AV_LOG_ERROR, "invalid image dimensions\n");
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
     w = xmax - xmin + 1;
@@ -117,12 +103,12 @@ static int pcx_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
 
     if (bytes_per_scanline < w * bits_per_pixel * nplanes / 8) {
         av_log(avctx, AV_LOG_ERROR, "PCX data is corrupted\n");
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
     switch ((nplanes<<8) + bits_per_pixel) {
         case 0x0308:
-            avctx->pix_fmt = PIX_FMT_RGB24;
+            avctx->pix_fmt = AV_PIX_FMT_RGB24;
             break;
         case 0x0108:
         case 0x0104:
@@ -131,25 +117,22 @@ static int pcx_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
         case 0x0401:
         case 0x0301:
         case 0x0201:
-            avctx->pix_fmt = PIX_FMT_PAL8;
+            avctx->pix_fmt = AV_PIX_FMT_PAL8;
             break;
         default:
             av_log(avctx, AV_LOG_ERROR, "invalid PCX file\n");
-            return -1;
+            return AVERROR_INVALIDDATA;
     }
 
     buf += 128;
 
-    if (p->data[0])
-        avctx->release_buffer(avctx, p);
-
-    if (av_image_check_size(w, h, 0, avctx))
-        return -1;
+    if ((ret = av_image_check_size(w, h, 0, avctx)) < 0)
+        return ret;
     if (w != avctx->width || h != avctx->height)
         avcodec_set_dimensions(avctx, w, h);
-    if (avctx->get_buffer(avctx, p) < 0) {
+    if ((ret = ff_get_buffer(avctx, p, 0)) < 0) {
         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
-        return -1;
+        return ret;
     }
 
     p->pict_type = AV_PICTURE_TYPE_I;
@@ -229,8 +212,7 @@ static int pcx_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
         pcx_palette(&palette, (uint32_t *) p->data[1], 16);
     }
 
-    *picture = s->picture;
-    *data_size = sizeof(AVFrame);
+    *got_frame = 1;
 
     ret = buf - bufstart;
 end:
@@ -238,22 +220,10 @@ end:
     return ret;
 }
 
-static av_cold int pcx_end(AVCodecContext *avctx) {
-    PCXContext *s = avctx->priv_data;
-
-    if(s->picture.data[0])
-        avctx->release_buffer(avctx, &s->picture);
-
-    return 0;
-}
-
 AVCodec ff_pcx_decoder = {
     .name           = "pcx",
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = AV_CODEC_ID_PCX,
-    .priv_data_size = sizeof(PCXContext),
-    .init           = pcx_init,
-    .close          = pcx_end,
     .decode         = pcx_decode_frame,
     .capabilities   = CODEC_CAP_DR1,
     .long_name      = NULL_IF_CONFIG_SMALL("PC Paintbrush PCX image"),