LCOV - code coverage report
Current view: top level - libavcodec - qtrle.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 267 282 94.7 %
Date: 2017-12-16 13:57:32 Functions: 9 9 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Quicktime Animation (RLE) Video Decoder
       3             :  * Copyright (C) 2004 The FFmpeg project
       4             :  *
       5             :  * This file is part of FFmpeg.
       6             :  *
       7             :  * FFmpeg is free software; you can redistribute it and/or
       8             :  * modify it under the terms of the GNU Lesser General Public
       9             :  * License as published by the Free Software Foundation; either
      10             :  * version 2.1 of the License, or (at your option) any later version.
      11             :  *
      12             :  * FFmpeg is distributed in the hope that it will be useful,
      13             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15             :  * Lesser General Public License for more details.
      16             :  *
      17             :  * You should have received a copy of the GNU Lesser General Public
      18             :  * License along with FFmpeg; if not, write to the Free Software
      19             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      20             :  */
      21             : 
      22             : /**
      23             :  * @file
      24             :  * QT RLE Video Decoder by Mike Melanson (melanson@pcisys.net)
      25             :  * For more information about the QT RLE format, visit:
      26             :  *   http://www.pcisys.net/~melanson/codecs/
      27             :  *
      28             :  * The QT RLE decoder has seven modes of operation:
      29             :  * 1, 2, 4, 8, 16, 24, and 32 bits per pixel. For modes 1, 2, 4, and 8
      30             :  * the decoder outputs PAL8 colorspace data. 16-bit data yields RGB555
      31             :  * data. 24-bit data is RGB24 and 32-bit data is RGB32.
      32             :  */
      33             : 
      34             : #include <stdio.h>
      35             : #include <stdlib.h>
      36             : #include <string.h>
      37             : 
      38             : #include "avcodec.h"
      39             : #include "bytestream.h"
      40             : #include "internal.h"
      41             : 
      42             : typedef struct QtrleContext {
      43             :     AVCodecContext *avctx;
      44             :     AVFrame *frame;
      45             : 
      46             :     GetByteContext g;
      47             :     uint32_t pal[256];
      48             : } QtrleContext;
      49             : 
      50             : #define CHECK_PIXEL_PTR(n)                                                            \
      51             :     if ((pixel_ptr + n > pixel_limit) || (pixel_ptr + n < 0)) {                       \
      52             :         av_log (s->avctx, AV_LOG_ERROR, "Problem: pixel_ptr = %d, pixel_limit = %d\n",\
      53             :                 pixel_ptr + n, pixel_limit);                                          \
      54             :         return;                                                                       \
      55             :     }                                                                                 \
      56             : 
      57          38 : static void qtrle_decode_1bpp(QtrleContext *s, int row_ptr, int lines_to_change)
      58             : {
      59             :     int rle_code;
      60             :     int pixel_ptr;
      61          38 :     int row_inc = s->frame->linesize[0];
      62             :     uint8_t pi0, pi1;  /* 2 8-pixel values */
      63          38 :     uint8_t *rgb = s->frame->data[0];
      64          38 :     int pixel_limit = s->frame->linesize[0] * s->avctx->height;
      65             :     int skip;
      66             :     /* skip & 0x80 appears to mean 'start a new line', which can be interpreted
      67             :      * as 'go to next line' during the decoding of a frame but is 'go to first
      68             :      * line' at the beginning. Since we always interpret it as 'go to next line'
      69             :      * in the decoding loop (which makes code simpler/faster), the first line
      70             :      * would not be counted, so we count one more.
      71             :      * See: https://trac.ffmpeg.org/ticket/226
      72             :      * In the following decoding loop, row_ptr will be the position of the
      73             :      * current row. */
      74             : 
      75          38 :     row_ptr  -= row_inc;
      76          38 :     pixel_ptr = row_ptr;
      77          38 :     lines_to_change++;
      78       13072 :     while (lines_to_change) {
      79       13034 :         skip     =              bytestream2_get_byte(&s->g);
      80       13034 :         rle_code = (int8_t)bytestream2_get_byte(&s->g);
      81       13034 :         if (rle_code == 0)
      82          38 :             break;
      83       12996 :         if(skip & 0x80) {
      84        9120 :             lines_to_change--;
      85        9120 :             row_ptr += row_inc;
      86        9120 :             pixel_ptr = row_ptr + 2 * 8 * (skip & 0x7f);
      87             :         } else
      88        3876 :             pixel_ptr += 2 * 8 * skip;
      89       12996 :         CHECK_PIXEL_PTR(0);  /* make sure pixel_ptr is positive */
      90             : 
      91       12996 :         if(rle_code == -1)
      92           0 :             continue;
      93             : 
      94       12996 :         if (rle_code < 0) {
      95             :             /* decode the run length code */
      96        1825 :             rle_code = -rle_code;
      97             :             /* get the next 2 bytes from the stream, treat them as groups
      98             :              * of 8 pixels, and output them rle_code times */
      99             : 
     100        1825 :             pi0 = bytestream2_get_byte(&s->g);
     101        1825 :             pi1 = bytestream2_get_byte(&s->g);
     102        1825 :             CHECK_PIXEL_PTR(rle_code * 2 * 8);
     103             : 
     104        8897 :             while (rle_code--) {
     105        5247 :                 rgb[pixel_ptr++] = (pi0 >> 7) & 0x01;
     106        5247 :                 rgb[pixel_ptr++] = (pi0 >> 6) & 0x01;
     107        5247 :                 rgb[pixel_ptr++] = (pi0 >> 5) & 0x01;
     108        5247 :                 rgb[pixel_ptr++] = (pi0 >> 4) & 0x01;
     109        5247 :                 rgb[pixel_ptr++] = (pi0 >> 3) & 0x01;
     110        5247 :                 rgb[pixel_ptr++] = (pi0 >> 2) & 0x01;
     111        5247 :                 rgb[pixel_ptr++] = (pi0 >> 1) & 0x01;
     112        5247 :                 rgb[pixel_ptr++] =  pi0       & 0x01;
     113        5247 :                 rgb[pixel_ptr++] = (pi1 >> 7) & 0x01;
     114        5247 :                 rgb[pixel_ptr++] = (pi1 >> 6) & 0x01;
     115        5247 :                 rgb[pixel_ptr++] = (pi1 >> 5) & 0x01;
     116        5247 :                 rgb[pixel_ptr++] = (pi1 >> 4) & 0x01;
     117        5247 :                 rgb[pixel_ptr++] = (pi1 >> 3) & 0x01;
     118        5247 :                 rgb[pixel_ptr++] = (pi1 >> 2) & 0x01;
     119        5247 :                 rgb[pixel_ptr++] = (pi1 >> 1) & 0x01;
     120        5247 :                 rgb[pixel_ptr++] =  pi1       & 0x01;
     121             :             }
     122             :         } else {
     123             :             /* copy the same pixel directly to output 2 times */
     124       11171 :             rle_code *= 2;
     125       11171 :             CHECK_PIXEL_PTR(rle_code * 8);
     126             : 
     127      375132 :             while (rle_code--) {
     128      352790 :                 int x = bytestream2_get_byte(&s->g);
     129      352790 :                 rgb[pixel_ptr++] = (x >> 7) & 0x01;
     130      352790 :                 rgb[pixel_ptr++] = (x >> 6) & 0x01;
     131      352790 :                 rgb[pixel_ptr++] = (x >> 5) & 0x01;
     132      352790 :                 rgb[pixel_ptr++] = (x >> 4) & 0x01;
     133      352790 :                 rgb[pixel_ptr++] = (x >> 3) & 0x01;
     134      352790 :                 rgb[pixel_ptr++] = (x >> 2) & 0x01;
     135      352790 :                 rgb[pixel_ptr++] = (x >> 1) & 0x01;
     136      352790 :                 rgb[pixel_ptr++] =  x       & 0x01;
     137             :             }
     138             :         }
     139             :     }
     140             : }
     141             : 
     142         114 : static inline void qtrle_decode_2n4bpp(QtrleContext *s, int row_ptr,
     143             :                                        int lines_to_change, int bpp)
     144             : {
     145             :     int rle_code, i;
     146             :     int pixel_ptr;
     147         114 :     int row_inc = s->frame->linesize[0];
     148             :     uint8_t pi[16];  /* 16 palette indices */
     149         114 :     uint8_t *rgb = s->frame->data[0];
     150         114 :     int pixel_limit = s->frame->linesize[0] * s->avctx->height;
     151         114 :     int num_pixels = (bpp == 4) ? 8 : 16;
     152             : 
     153       27588 :     while (lines_to_change--) {
     154       27360 :         pixel_ptr = row_ptr + (num_pixels * (bytestream2_get_byte(&s->g) - 1));
     155       27360 :         CHECK_PIXEL_PTR(0);
     156             : 
     157      199836 :         while ((rle_code = (int8_t)bytestream2_get_byte(&s->g)) != -1) {
     158      145116 :             if (rle_code == 0) {
     159             :                 /* there's another skip code in the stream */
     160       32727 :                 pixel_ptr += (num_pixels * (bytestream2_get_byte(&s->g) - 1));
     161       32727 :                 CHECK_PIXEL_PTR(0);  /* make sure pixel_ptr is positive */
     162      112389 :             } else if (rle_code < 0) {
     163             :                 /* decode the run length code */
     164       30399 :                 rle_code = -rle_code;
     165             :                 /* get the next 4 bytes from the stream, treat them as palette
     166             :                  * indexes, and output them rle_code times */
     167      292911 :                 for (i = num_pixels-1; i >= 0; i--) {
     168      262512 :                     pi[num_pixels-1-i] = (bytestream2_peek_byte(&s->g) >> ((i*bpp) & 0x07)) & ((1<<bpp)-1);
     169      262512 :                     bytestream2_skip(&s->g, ((i & ((num_pixels>>2)-1)) == 0));
     170             :                 }
     171       30399 :                 CHECK_PIXEL_PTR(rle_code * num_pixels);
     172      162294 :                 while (rle_code--) {
     173      101496 :                     memcpy(&rgb[pixel_ptr], &pi, num_pixels);
     174      101496 :                     pixel_ptr += num_pixels;
     175             :                 }
     176             :             } else {
     177             :                 /* copy the same pixel directly to output 4 times */
     178       81990 :                 rle_code *= 4;
     179       81990 :                 CHECK_PIXEL_PTR(rle_code*(num_pixels>>2));
     180     3048400 :                 while (rle_code--) {
     181     2884420 :                     if(bpp == 4) {
     182     2213528 :                         int x = bytestream2_get_byte(&s->g);
     183     2213528 :                         rgb[pixel_ptr++] = (x >> 4) & 0x0f;
     184     2213528 :                         rgb[pixel_ptr++] =  x       & 0x0f;
     185             :                     } else {
     186      670892 :                         int x = bytestream2_get_byte(&s->g);
     187      670892 :                         rgb[pixel_ptr++] = (x >> 6) & 0x03;
     188      670892 :                         rgb[pixel_ptr++] = (x >> 4) & 0x03;
     189      670892 :                         rgb[pixel_ptr++] = (x >> 2) & 0x03;
     190      670892 :                         rgb[pixel_ptr++] =  x       & 0x03;
     191             :                     }
     192             :                 }
     193             :             }
     194             :         }
     195       27360 :         row_ptr += row_inc;
     196             :     }
     197             : }
     198             : 
     199         208 : static void qtrle_decode_8bpp(QtrleContext *s, int row_ptr, int lines_to_change)
     200             : {
     201             :     int rle_code;
     202             :     int pixel_ptr;
     203         208 :     int row_inc = s->frame->linesize[0];
     204             :     uint8_t pi1, pi2, pi3, pi4;  /* 4 palette indexes */
     205         208 :     uint8_t *rgb = s->frame->data[0];
     206         208 :     int pixel_limit = s->frame->linesize[0] * s->avctx->height;
     207             : 
     208       48727 :     while (lines_to_change--) {
     209       48311 :         pixel_ptr = row_ptr + (4 * (bytestream2_get_byte(&s->g) - 1));
     210       48311 :         CHECK_PIXEL_PTR(0);
     211             : 
     212      247649 :         while ((rle_code = (int8_t)bytestream2_get_byte(&s->g)) != -1) {
     213      151027 :             if (rle_code == 0) {
     214             :                 /* there's another skip code in the stream */
     215       39089 :                 pixel_ptr += (4 * (bytestream2_get_byte(&s->g) - 1));
     216       39089 :                 CHECK_PIXEL_PTR(0);  /* make sure pixel_ptr is positive */
     217      111938 :             } else if (rle_code < 0) {
     218             :                 /* decode the run length code */
     219       18173 :                 rle_code = -rle_code;
     220             :                 /* get the next 4 bytes from the stream, treat them as palette
     221             :                  * indexes, and output them rle_code times */
     222       18173 :                 pi1 = bytestream2_get_byte(&s->g);
     223       18173 :                 pi2 = bytestream2_get_byte(&s->g);
     224       18173 :                 pi3 = bytestream2_get_byte(&s->g);
     225       18173 :                 pi4 = bytestream2_get_byte(&s->g);
     226             : 
     227       18173 :                 CHECK_PIXEL_PTR(rle_code * 4);
     228             : 
     229      137927 :                 while (rle_code--) {
     230      101581 :                     rgb[pixel_ptr++] = pi1;
     231      101581 :                     rgb[pixel_ptr++] = pi2;
     232      101581 :                     rgb[pixel_ptr++] = pi3;
     233      101581 :                     rgb[pixel_ptr++] = pi4;
     234             :                 }
     235             :             } else {
     236             :                 /* copy the same pixel directly to output 4 times */
     237       93765 :                 rle_code *= 4;
     238       93765 :                 CHECK_PIXEL_PTR(rle_code);
     239             : 
     240       93765 :                 bytestream2_get_buffer(&s->g, &rgb[pixel_ptr], rle_code);
     241       93765 :                 pixel_ptr += rle_code;
     242             :             }
     243             :         }
     244       48311 :         row_ptr += row_inc;
     245             :     }
     246             : }
     247             : 
     248          83 : static void qtrle_decode_16bpp(QtrleContext *s, int row_ptr, int lines_to_change)
     249             : {
     250             :     int rle_code;
     251             :     int pixel_ptr;
     252          83 :     int row_inc = s->frame->linesize[0];
     253             :     uint16_t rgb16;
     254          83 :     uint8_t *rgb = s->frame->data[0];
     255          83 :     int pixel_limit = s->frame->linesize[0] * s->avctx->height;
     256             : 
     257       10126 :     while (lines_to_change--) {
     258        9960 :         pixel_ptr = row_ptr + (bytestream2_get_byte(&s->g) - 1) * 2;
     259        9960 :         CHECK_PIXEL_PTR(0);
     260             : 
     261      288622 :         while ((rle_code = (int8_t)bytestream2_get_byte(&s->g)) != -1) {
     262      268702 :             if (rle_code == 0) {
     263             :                 /* there's another skip code in the stream */
     264           0 :                 pixel_ptr += (bytestream2_get_byte(&s->g) - 1) * 2;
     265           0 :                 CHECK_PIXEL_PTR(0);  /* make sure pixel_ptr is positive */
     266      268702 :             } else if (rle_code < 0) {
     267             :                 /* decode the run length code */
     268      234583 :                 rle_code = -rle_code;
     269      234583 :                 rgb16 = bytestream2_get_be16(&s->g);
     270             : 
     271      234583 :                 CHECK_PIXEL_PTR(rle_code * 2);
     272             : 
     273     1998596 :                 while (rle_code--) {
     274     1529430 :                     *(uint16_t *)(&rgb[pixel_ptr]) = rgb16;
     275     1529430 :                     pixel_ptr += 2;
     276             :                 }
     277             :             } else {
     278       34119 :                 CHECK_PIXEL_PTR(rle_code * 2);
     279             : 
     280             :                 /* copy pixels directly to output */
     281      132408 :                 while (rle_code--) {
     282       64170 :                     rgb16 = bytestream2_get_be16(&s->g);
     283       64170 :                     *(uint16_t *)(&rgb[pixel_ptr]) = rgb16;
     284       64170 :                     pixel_ptr += 2;
     285             :                 }
     286             :             }
     287             :         }
     288        9960 :         row_ptr += row_inc;
     289             :     }
     290             : }
     291             : 
     292         250 : static void qtrle_decode_24bpp(QtrleContext *s, int row_ptr, int lines_to_change)
     293             : {
     294             :     int rle_code;
     295             :     int pixel_ptr;
     296         250 :     int row_inc = s->frame->linesize[0];
     297             :     uint8_t r, g, b;
     298         250 :     uint8_t *rgb = s->frame->data[0];
     299         250 :     int pixel_limit = s->frame->linesize[0] * s->avctx->height;
     300             : 
     301       51802 :     while (lines_to_change--) {
     302       51302 :         pixel_ptr = row_ptr + (bytestream2_get_byte(&s->g) - 1) * 3;
     303       51302 :         CHECK_PIXEL_PTR(0);
     304             : 
     305     1658461 :         while ((rle_code = (int8_t)bytestream2_get_byte(&s->g)) != -1) {
     306     1555857 :             if (rle_code == 0) {
     307             :                 /* there's another skip code in the stream */
     308      109372 :                 pixel_ptr += (bytestream2_get_byte(&s->g) - 1) * 3;
     309      109372 :                 CHECK_PIXEL_PTR(0);  /* make sure pixel_ptr is positive */
     310     1446485 :             } else if (rle_code < 0) {
     311             :                 /* decode the run length code */
     312      764625 :                 rle_code = -rle_code;
     313      764625 :                 r = bytestream2_get_byte(&s->g);
     314      764625 :                 g = bytestream2_get_byte(&s->g);
     315      764625 :                 b = bytestream2_get_byte(&s->g);
     316             : 
     317      764625 :                 CHECK_PIXEL_PTR(rle_code * 3);
     318             : 
     319     3902770 :                 while (rle_code--) {
     320     2373520 :                     rgb[pixel_ptr++] = r;
     321     2373520 :                     rgb[pixel_ptr++] = g;
     322     2373520 :                     rgb[pixel_ptr++] = b;
     323             :                 }
     324             :             } else {
     325      681860 :                 CHECK_PIXEL_PTR(rle_code * 3);
     326             : 
     327             :                 /* copy pixels directly to output */
     328    14868259 :                 while (rle_code--) {
     329    13504539 :                     rgb[pixel_ptr++] = bytestream2_get_byte(&s->g);
     330    13504539 :                     rgb[pixel_ptr++] = bytestream2_get_byte(&s->g);
     331    13504539 :                     rgb[pixel_ptr++] = bytestream2_get_byte(&s->g);
     332             :                 }
     333             :             }
     334             :         }
     335       51302 :         row_ptr += row_inc;
     336             :     }
     337             : }
     338             : 
     339          26 : static void qtrle_decode_32bpp(QtrleContext *s, int row_ptr, int lines_to_change)
     340             : {
     341             :     int rle_code;
     342             :     int pixel_ptr;
     343          26 :     int row_inc = s->frame->linesize[0];
     344             :     unsigned int argb;
     345          26 :     uint8_t *rgb = s->frame->data[0];
     346          26 :     int pixel_limit = s->frame->linesize[0] * s->avctx->height;
     347             : 
     348       12532 :     while (lines_to_change--) {
     349       12480 :         pixel_ptr = row_ptr + (bytestream2_get_byte(&s->g) - 1) * 4;
     350       12480 :         CHECK_PIXEL_PTR(0);
     351             : 
     352     1218452 :         while ((rle_code = (int8_t)bytestream2_get_byte(&s->g)) != -1) {
     353     1193492 :             if (rle_code == 0) {
     354             :                 /* there's another skip code in the stream */
     355      244756 :                 pixel_ptr += (bytestream2_get_byte(&s->g) - 1) * 4;
     356      244756 :                 CHECK_PIXEL_PTR(0);  /* make sure pixel_ptr is positive */
     357      948736 :             } else if (rle_code < 0) {
     358             :                 /* decode the run length code */
     359      565158 :                 rle_code = -rle_code;
     360      565158 :                 argb = bytestream2_get_be32(&s->g);
     361             : 
     362      565158 :                 CHECK_PIXEL_PTR(rle_code * 4);
     363             : 
     364     3333356 :                 while (rle_code--) {
     365     2203040 :                     AV_WN32A(rgb + pixel_ptr, argb);
     366     2203040 :                     pixel_ptr += 4;
     367             :                 }
     368             :             } else {
     369      383578 :                 CHECK_PIXEL_PTR(rle_code * 4);
     370             : 
     371             :                 /* copy pixels directly to output */
     372     1999084 :                 while (rle_code--) {
     373     1231928 :                     argb = bytestream2_get_be32(&s->g);
     374     1231928 :                     AV_WN32A(rgb + pixel_ptr, argb);
     375     1231928 :                     pixel_ptr  += 4;
     376             :                 }
     377             :             }
     378             :         }
     379       12480 :         row_ptr += row_inc;
     380             :     }
     381             : }
     382             : 
     383          39 : static av_cold int qtrle_decode_init(AVCodecContext *avctx)
     384             : {
     385          39 :     QtrleContext *s = avctx->priv_data;
     386             : 
     387          39 :     s->avctx = avctx;
     388          39 :     switch (avctx->bits_per_coded_sample) {
     389          17 :     case 1:
     390             :     case 2:
     391             :     case 4:
     392             :     case 8:
     393             :     case 33:
     394             :     case 34:
     395             :     case 36:
     396             :     case 40:
     397          17 :         avctx->pix_fmt = AV_PIX_FMT_PAL8;
     398          17 :         break;
     399             : 
     400           2 :     case 16:
     401           2 :         avctx->pix_fmt = AV_PIX_FMT_RGB555;
     402           2 :         break;
     403             : 
     404          18 :     case 24:
     405          18 :         avctx->pix_fmt = AV_PIX_FMT_RGB24;
     406          18 :         break;
     407             : 
     408           2 :     case 32:
     409           2 :         avctx->pix_fmt = AV_PIX_FMT_RGB32;
     410           2 :         break;
     411             : 
     412           0 :     default:
     413           0 :         av_log (avctx, AV_LOG_ERROR, "Unsupported colorspace: %d bits/sample?\n",
     414             :             avctx->bits_per_coded_sample);
     415           0 :         return AVERROR_INVALIDDATA;
     416             :     }
     417             : 
     418          39 :     s->frame = av_frame_alloc();
     419          39 :     if (!s->frame)
     420           0 :         return AVERROR(ENOMEM);
     421             : 
     422          39 :     return 0;
     423             : }
     424             : 
     425         828 : static int qtrle_decode_frame(AVCodecContext *avctx,
     426             :                               void *data, int *got_frame,
     427             :                               AVPacket *avpkt)
     428             : {
     429         828 :     QtrleContext *s = avctx->priv_data;
     430             :     int header, start_line;
     431             :     int height, row_ptr;
     432         828 :     int has_palette = 0;
     433             :     int ret;
     434             : 
     435         828 :     bytestream2_init(&s->g, avpkt->data, avpkt->size);
     436         828 :     if ((ret = ff_reget_buffer(avctx, s->frame)) < 0)
     437           0 :         return ret;
     438             : 
     439             :     /* check if this frame is even supposed to change */
     440         828 :     if (avpkt->size < 8)
     441         109 :         goto done;
     442             : 
     443             :     /* start after the chunk size */
     444         719 :     bytestream2_seek(&s->g, 4, SEEK_SET);
     445             : 
     446             :     /* fetch the header */
     447         719 :     header = bytestream2_get_be16(&s->g);
     448             : 
     449             :     /* if a header is present, fetch additional decoding parameters */
     450         719 :     if (header & 0x0008) {
     451         369 :         if (avpkt->size < 14)
     452           0 :             goto done;
     453         369 :         start_line = bytestream2_get_be16(&s->g);
     454         369 :         bytestream2_skip(&s->g, 2);
     455         369 :         height     = bytestream2_get_be16(&s->g);
     456         369 :         bytestream2_skip(&s->g, 2);
     457         369 :         if (height > s->avctx->height - start_line)
     458           0 :             goto done;
     459             :     } else {
     460         350 :         start_line = 0;
     461         350 :         height     = s->avctx->height;
     462             :     }
     463         719 :     row_ptr = s->frame->linesize[0] * start_line;
     464             : 
     465         719 :     switch (avctx->bits_per_coded_sample) {
     466          38 :     case 1:
     467             :     case 33:
     468          38 :         qtrle_decode_1bpp(s, row_ptr, height);
     469          38 :         has_palette = 1;
     470          38 :         break;
     471             : 
     472          38 :     case 2:
     473             :     case 34:
     474          38 :         qtrle_decode_2n4bpp(s, row_ptr, height, 2);
     475          38 :         has_palette = 1;
     476          38 :         break;
     477             : 
     478          76 :     case 4:
     479             :     case 36:
     480          76 :         qtrle_decode_2n4bpp(s, row_ptr, height, 4);
     481          76 :         has_palette = 1;
     482          76 :         break;
     483             : 
     484         208 :     case 8:
     485             :     case 40:
     486         208 :         qtrle_decode_8bpp(s, row_ptr, height);
     487         208 :         has_palette = 1;
     488         208 :         break;
     489             : 
     490          83 :     case 16:
     491          83 :         qtrle_decode_16bpp(s, row_ptr, height);
     492          83 :         break;
     493             : 
     494         250 :     case 24:
     495         250 :         qtrle_decode_24bpp(s, row_ptr, height);
     496         250 :         break;
     497             : 
     498          26 :     case 32:
     499          26 :         qtrle_decode_32bpp(s, row_ptr, height);
     500          26 :         break;
     501             : 
     502           0 :     default:
     503           0 :         av_log (s->avctx, AV_LOG_ERROR, "Unsupported colorspace: %d bits/sample?\n",
     504             :             avctx->bits_per_coded_sample);
     505           0 :         break;
     506             :     }
     507             : 
     508         719 :     if(has_palette) {
     509             :         int size;
     510         360 :         const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, &size);
     511             : 
     512         360 :         if (pal && size == AVPALETTE_SIZE) {
     513           8 :             s->frame->palette_has_changed = 1;
     514           8 :             memcpy(s->pal, pal, AVPALETTE_SIZE);
     515         352 :         } else if (pal) {
     516           0 :             av_log(avctx, AV_LOG_ERROR, "Palette size %d is wrong\n", size);
     517             :         }
     518             : 
     519             :         /* make the palette available on the way out */
     520         360 :         memcpy(s->frame->data[1], s->pal, AVPALETTE_SIZE);
     521             :     }
     522             : 
     523        1187 : done:
     524         828 :     if ((ret = av_frame_ref(data, s->frame)) < 0)
     525           0 :         return ret;
     526         828 :     *got_frame      = 1;
     527             : 
     528             :     /* always report that the buffer was completely consumed */
     529         828 :     return avpkt->size;
     530             : }
     531             : 
     532          39 : static av_cold int qtrle_decode_end(AVCodecContext *avctx)
     533             : {
     534          39 :     QtrleContext *s = avctx->priv_data;
     535             : 
     536          39 :     av_frame_free(&s->frame);
     537             : 
     538          39 :     return 0;
     539             : }
     540             : 
     541             : AVCodec ff_qtrle_decoder = {
     542             :     .name           = "qtrle",
     543             :     .long_name      = NULL_IF_CONFIG_SMALL("QuickTime Animation (RLE) video"),
     544             :     .type           = AVMEDIA_TYPE_VIDEO,
     545             :     .id             = AV_CODEC_ID_QTRLE,
     546             :     .priv_data_size = sizeof(QtrleContext),
     547             :     .init           = qtrle_decode_init,
     548             :     .close          = qtrle_decode_end,
     549             :     .decode         = qtrle_decode_frame,
     550             :     .capabilities   = AV_CODEC_CAP_DR1,
     551             : };

Generated by: LCOV version 1.13