]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/rawdec.c
avcodec: Constify AVCodecs
[ffmpeg] / libavcodec / rawdec.c
index 53f5b76e93e7b61655ea4c3470e8bc4e4d08a56b..96abf6a48c2a38c58def5029c99827d0b841165e 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "avcodec.h"
 #include "bswapdsp.h"
+#include "decode.h"
 #include "get_bits.h"
 #include "internal.h"
 #include "raw.h"
@@ -92,19 +93,13 @@ static av_cold int raw_init_decoder(AVCodecContext *avctx)
         return AVERROR(EINVAL);
     }
 
-    if (desc->flags & (AV_PIX_FMT_FLAG_PAL | FF_PSEUDOPAL)) {
+    if (desc->flags & AV_PIX_FMT_FLAG_PAL) {
         context->palette = av_buffer_alloc(AVPALETTE_SIZE);
         if (!context->palette)
             return AVERROR(ENOMEM);
-#if FF_API_PSEUDOPAL
-        if (desc->flags & AV_PIX_FMT_FLAG_PSEUDOPAL)
-            avpriv_set_systematic_pal2((uint32_t*)context->palette->data, avctx->pix_fmt);
-#endif
-        else {
-            memset(context->palette->data, 0, AVPALETTE_SIZE);
-            if (avctx->bits_per_coded_sample == 1)
-                memset(context->palette->data, 0xff, 4);
-        }
+        memset(context->palette->data, 0, AVPALETTE_SIZE);
+        if (avctx->bits_per_coded_sample == 1)
+            memset(context->palette->data, 0xff, 4);
     }
 
     if ((avctx->extradata_size >= 9 &&
@@ -223,7 +218,7 @@ static int raw_decode(AVCodecContext *avctx, void *data, int *got_frame,
                                                            FFALIGN(avctx->width, 16),
                                                            avctx->height, 1);
     } else {
-        context->is_lt_16bpp = av_get_bits_per_pixel(desc) == 16 && avctx->bits_per_coded_sample && avctx->bits_per_coded_sample < 16;
+        context->is_lt_16bpp = av_get_bits_per_pixel(desc) == 16 && avctx->bits_per_coded_sample > 8 && avctx->bits_per_coded_sample < 16;
         context->frame_size = av_image_get_buffer_size(avctx->pix_fmt, avctx->width,
                                                        avctx->height, 1);
     }
@@ -366,16 +361,8 @@ static int raw_decode(AVCodecContext *avctx, void *data, int *got_frame,
     }
 
     if (avctx->pix_fmt == AV_PIX_FMT_PAL8) {
-        int pal_size;
-        const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE,
-                                                     &pal_size);
         int ret;
 
-        if (pal && pal_size != AVPALETTE_SIZE) {
-            av_log(avctx, AV_LOG_ERROR, "Palette size %d is wrong\n", pal_size);
-            pal = NULL;
-        }
-
         if (!context->palette)
             context->palette = av_buffer_alloc(AVPALETTE_SIZE);
         if (!context->palette) {
@@ -388,15 +375,14 @@ static int raw_decode(AVCodecContext *avctx, void *data, int *got_frame,
             return ret;
         }
 
-        if (pal) {
-            memcpy(context->palette->data, pal, AVPALETTE_SIZE);
+        if (ff_copy_palette(context->palette->data, avpkt, avctx)) {
             frame->palette_has_changed = 1;
         } else if (context->is_nut_pal8) {
             int vid_size = avctx->width * avctx->height;
             int pal_size = avpkt->size - vid_size;
 
             if (avpkt->size > vid_size && pal_size <= AVPALETTE_SIZE) {
-                pal = avpkt->data + vid_size;
+                const uint8_t *pal = avpkt->data + vid_size;
                 memcpy(context->palette->data, pal, pal_size);
                 frame->palette_has_changed = 1;
             }
@@ -424,8 +410,7 @@ static int raw_decode(AVCodecContext *avctx, void *data, int *got_frame,
         frame->linesize[1] = FFALIGN(frame->linesize[1], linesize_align);
     }
 
-    if ((avctx->pix_fmt == AV_PIX_FMT_PAL8 && buf_size < context->frame_size) ||
-        (desc->flags & FF_PSEUDOPAL)) {
+    if (avctx->pix_fmt == AV_PIX_FMT_PAL8 && buf_size < context->frame_size) {
         frame->buf[1]  = av_buffer_ref(context->palette);
         if (!frame->buf[1]) {
             av_buffer_unref(&frame->buf[0]);
@@ -467,10 +452,13 @@ static int raw_decode(AVCodecContext *avctx, void *data, int *got_frame,
         avctx->pix_fmt   == AV_PIX_FMT_RGBA64BE) {
         uint8_t *dst = frame->data[0];
         uint64_t v;
-        int x;
-        for (x = 0; x >> 3 < avctx->width * avctx->height; x += 8) {
-            v = AV_RB64(&dst[x]);
-            AV_WB64(&dst[x], v << 16 | v >> 48);
+        int x, y;
+        for (y = 0; y < avctx->height; y++) {
+            for (x = 0; x >> 3 < avctx->width; x += 8) {
+                v = AV_RB64(&dst[x]);
+                AV_WB64(&dst[x], v << 16 | v >> 48);
+            }
+            dst += frame->linesize[0];
         }
     }
 
@@ -489,10 +477,11 @@ static av_cold int raw_close_decoder(AVCodecContext *avctx)
     RawVideoContext *context = avctx->priv_data;
 
     av_buffer_unref(&context->palette);
+    av_freep(&context->bitstream_buf);
     return 0;
 }
 
-AVCodec ff_rawvideo_decoder = {
+const AVCodec ff_rawvideo_decoder = {
     .name           = "rawvideo",
     .long_name      = NULL_IF_CONFIG_SMALL("raw video"),
     .type           = AVMEDIA_TYPE_VIDEO,