rv34: export qp table
[ffmpeg.git] / libavcodec / pngdec.c
index 36db29e..086f3b4 100644 (file)
@@ -42,8 +42,7 @@ typedef struct PNGDecContext {
     AVCodecContext *avctx;
 
     GetByteContext gb;
-    AVFrame picture1, picture2;
-    AVFrame *current_picture, *last_picture;
+    AVFrame *prev;
 
     int state;
     int width, height;
@@ -508,18 +507,13 @@ static int decode_frame(AVCodecContext *avctx,
     PNGDecContext * const s = avctx->priv_data;
     const uint8_t *buf      = avpkt->data;
     int buf_size            = avpkt->size;
-    AVFrame *picture        = data;
+    AVFrame *p              = data;
     AVDictionary *metadata  = NULL;
     uint8_t *crow_buf_base  = NULL;
-    AVFrame *p;
     uint32_t tag, length;
     int64_t sig;
     int ret;
 
-    FFSWAP(AVFrame *, s->current_picture, s->last_picture);
-    avctx->coded_frame = s->current_picture;
-    p = s->current_picture;
-
     bytestream2_init(&s->gb, buf, buf_size);
 
     /* check signature */
@@ -642,14 +636,9 @@ static int decode_frame(AVCodecContext *avctx,
                                                  s->bit_depth, s->color_type);
                     goto fail;
                 }
-                if (p->data[0])
-                    avctx->release_buffer(avctx, p);
 
-                p->reference = 3;
-                if (ff_get_buffer(avctx, p) < 0) {
-                    av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+                if (ff_get_buffer(avctx, p, AV_GET_BUFFER_FLAG_REF) < 0)
                     goto fail;
-                }
                 p->pict_type        = AV_PICTURE_TYPE_I;
                 p->key_frame        = 1;
                 p->interlaced_frame = !!s->interlace_type;
@@ -762,7 +751,7 @@ static int decode_frame(AVCodecContext *avctx,
 
     if (s->bits_per_pixel == 1 && s->color_type == PNG_COLOR_TYPE_PALETTE){
         int i, j, k;
-        uint8_t *pd = s->current_picture->data[0];
+        uint8_t *pd = p->data[0];
         for (j = 0; j < s->height; j++) {
             i = s->width / 8;
             for (k = 7; k >= 1; k--)
@@ -783,7 +772,7 @@ static int decode_frame(AVCodecContext *avctx,
     }
     if (s->bits_per_pixel == 2){
         int i, j;
-        uint8_t *pd = s->current_picture->data[0];
+        uint8_t *pd = p->data[0];
         for (j = 0; j < s->height; j++) {
             i = s->width / 4;
             if (s->color_type == PNG_COLOR_TYPE_PALETTE){
@@ -812,7 +801,7 @@ static int decode_frame(AVCodecContext *avctx,
     }
     if (s->bits_per_pixel == 4){
         int i, j;
-        uint8_t *pd = s->current_picture->data[0];
+        uint8_t *pd = p->data[0];
         for (j = 0; j < s->height; j++) {
             i = s->width/2;
             if (s->color_type == PNG_COLOR_TYPE_PALETTE){
@@ -833,15 +822,15 @@ static int decode_frame(AVCodecContext *avctx,
     }
 
      /* handle p-frames only if a predecessor frame is available */
-     if (s->last_picture->data[0] != NULL) {
+     if (s->prev->data[0]) {
          if (   !(avpkt->flags & AV_PKT_FLAG_KEY)
-            && s->last_picture->width == s->current_picture->width
-            && s->last_picture->height== s->current_picture->height
-            && s->last_picture->format== s->current_picture->format
+            && s->prev->width == p->width
+            && s->prev->height== p->height
+            && s->prev->format== p->format
          ) {
             int i, j;
-            uint8_t *pd      = s->current_picture->data[0];
-            uint8_t *pd_last = s->last_picture->data[0];
+            uint8_t *pd      = p->data[0];
+            uint8_t *pd_last = s->prev->data[0];
 
             for (j = 0; j < s->height; j++) {
                 for (i = 0; i < s->width * s->bpp; i++) {
@@ -853,9 +842,13 @@ static int decode_frame(AVCodecContext *avctx,
         }
     }
 
-    av_frame_set_metadata(&s->current_picture, metadata);
+    av_frame_set_metadata(p, metadata);
     metadata   = NULL;
-    *picture   = *s->current_picture;
+
+    av_frame_unref(s->prev);
+     if ((ret = av_frame_ref(s->prev, p)) < 0)
+         goto fail;
+
     *got_frame = 1;
 
     ret = bytestream2_tell(&s->gb);
@@ -876,10 +869,9 @@ static av_cold int png_dec_init(AVCodecContext *avctx)
 {
     PNGDecContext *s = avctx->priv_data;
 
-    s->current_picture = &s->picture1;
-    s->last_picture    = &s->picture2;
-    avcodec_get_frame_defaults(&s->picture1);
-    avcodec_get_frame_defaults(&s->picture2);
+    s->prev = av_frame_alloc();
+    if (!s->prev)
+        return AVERROR(ENOMEM);
 
     ff_pngdsp_init(&s->dsp);
 
@@ -892,10 +884,7 @@ static av_cold int png_dec_end(AVCodecContext *avctx)
 {
     PNGDecContext *s = avctx->priv_data;
 
-    if (s->picture1.data[0])
-        avctx->release_buffer(avctx, &s->picture1);
-    if (s->picture2.data[0])
-        avctx->release_buffer(avctx, &s->picture2);
+    av_frame_free(&s->prev);
 
     return 0;
 }