LCOV - code coverage report
Current view: top level - libavcodec - ffv1dec_template.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 80 91 87.9 %
Date: 2017-12-17 16:07:53 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /*
       2             :  * FFV1 decoder template
       3             :  *
       4             :  * Copyright (c) 2003-2016 Michael Niedermayer <michaelni@gmx.at>
       5             :  *
       6             :  * This file is part of FFmpeg.
       7             :  *
       8             :  * FFmpeg is free software; you can redistribute it and/or
       9             :  * modify it under the terms of the GNU Lesser General Public
      10             :  * License as published by the Free Software Foundation; either
      11             :  * version 2.1 of the License, or (at your option) any later version.
      12             :  *
      13             :  * FFmpeg is distributed in the hope that it will be useful,
      14             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      16             :  * Lesser General Public License for more details.
      17             :  *
      18             :  * You should have received a copy of the GNU Lesser General Public
      19             :  * License along with FFmpeg; if not, write to the Free Software
      20             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      21             :  */
      22             : 
      23     1558692 : static av_always_inline int RENAME(decode_line)(FFV1Context *s, int w,
      24             :                                                  TYPE *sample[2],
      25             :                                                  int plane_index, int bits)
      26             : {
      27     1558692 :     PlaneContext *const p = &s->plane[plane_index];
      28     1558692 :     RangeCoder *const c   = &s->c;
      29             :     int x;
      30     1558692 :     int run_count = 0;
      31     1558692 :     int run_mode  = 0;
      32     1558692 :     int run_index = s->run_index;
      33             : 
      34     1558692 :     if (is_input_end(s))
      35           0 :         return AVERROR_INVALIDDATA;
      36             : 
      37     1558692 :     if (s->slice_coding_mode == 1) {
      38             :         int i;
      39           0 :         for (x = 0; x < w; x++) {
      40           0 :             int v = 0;
      41           0 :             for (i=0; i<bits; i++) {
      42           0 :                 uint8_t state = 128;
      43           0 :                 v += v + get_rac(c, &state);
      44             :             }
      45           0 :             sample[1][x] = v;
      46             :         }
      47           0 :         return 0;
      48             :     }
      49             : 
      50   243048366 :     for (x = 0; x < w; x++) {
      51             :         int diff, context, sign;
      52             : 
      53   241489674 :         context = RENAME(get_context)(p, sample[1] + x, sample[0] + x, sample[1] + x);
      54   241489674 :         if (context < 0) {
      55    98632670 :             context = -context;
      56    98632670 :             sign    = 1;
      57             :         } else
      58   142857004 :             sign = 0;
      59             : 
      60             :         av_assert2(context < p->context_count);
      61             : 
      62   241489674 :         if (s->ac != AC_GOLOMB_RICE) {
      63   124559340 :             diff = get_symbol_inline(c, p->state[context], 1);
      64             :         } else {
      65   116930334 :             if (context == 0 && run_mode == 0)
      66     1406364 :                 run_mode = 1;
      67             : 
      68   116930334 :             if (run_mode) {
      69     4941427 :                 if (run_count == 0 && run_mode == 1) {
      70     2648716 :                     if (get_bits1(&s->gb)) {
      71     1295521 :                         run_count = 1 << ff_log2_run[run_index];
      72     1295521 :                         if (x + run_count <= w)
      73     1260471 :                             run_index++;
      74             :                     } else {
      75     1353195 :                         if (ff_log2_run[run_index])
      76     1004563 :                             run_count = get_bits(&s->gb, ff_log2_run[run_index]);
      77             :                         else
      78      348632 :                             run_count = 0;
      79     1353195 :                         if (run_index)
      80     1249584 :                             run_index--;
      81     1353195 :                         run_mode = 2;
      82             :                     }
      83             :                 }
      84     4941427 :                 run_count--;
      85     4941427 :                 if (run_count < 0) {
      86     1353195 :                     run_mode  = 0;
      87     1353195 :                     run_count = 0;
      88     1353195 :                     diff      = get_vlc_symbol(&s->gb, &p->vlc_state[context],
      89             :                                                bits);
      90     1353195 :                     if (diff >= 0)
      91      631292 :                         diff++;
      92             :                 } else
      93     3588232 :                     diff = 0;
      94             :             } else
      95   111988907 :                 diff = get_vlc_symbol(&s->gb, &p->vlc_state[context], bits);
      96             : 
      97             :             ff_dlog(s->avctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n",
      98             :                     run_count, run_index, run_mode, x, get_bits_count(&s->gb));
      99             :         }
     100             : 
     101   241489674 :         if (sign)
     102    98632670 :             diff = -(unsigned)diff;
     103             : 
     104   241489674 :         sample[1][x] = av_mod_uintp2(RENAME(predict)(sample[1] + x, sample[0] + x) + (SUINT)diff, bits);
     105             :     }
     106     1558692 :     s->run_index = run_index;
     107     1558692 :     return 0;
     108             : }
     109             : 
     110        1632 : static void RENAME(decode_rgb_frame)(FFV1Context *s, uint8_t *src[3], int w, int h, int stride[3])
     111             : {
     112             :     int x, y, p;
     113             :     TYPE *sample[4][2];
     114        1632 :     int lbd    = s->avctx->bits_per_raw_sample <= 8;
     115        1632 :     int bits   = s->avctx->bits_per_raw_sample > 0 ? s->avctx->bits_per_raw_sample : 8;
     116        1632 :     int offset = 1 << bits;
     117             : 
     118        8160 :     for (x = 0; x < 4; x++) {
     119        6528 :         sample[x][0] = RENAME(s->sample_buffer) +  x * 2      * (w + 6) + 3;
     120        6528 :         sample[x][1] = RENAME(s->sample_buffer) + (x * 2 + 1) * (w + 6) + 3;
     121             :     }
     122             : 
     123        1632 :     s->run_index = 0;
     124             : 
     125        1632 :     memset(RENAME(s->sample_buffer), 0, 8 * (w + 6) * sizeof(*RENAME(s->sample_buffer)));
     126             : 
     127      184824 :     for (y = 0; y < h; y++) {
     128      732768 :         for (p = 0; p < 3 + s->transparency; p++) {
     129      549576 :             TYPE *temp = sample[p][0]; // FIXME: try a normal buffer
     130             : 
     131      549576 :             sample[p][0] = sample[p][1];
     132      549576 :             sample[p][1] = temp;
     133             : 
     134      549576 :             sample[p][1][-1]= sample[p][0][0  ];
     135      549576 :             sample[p][0][ w]= sample[p][0][w-1];
     136      549576 :             if (lbd && s->slice_coding_mode == 0)
     137      274788 :                 RENAME(decode_line)(s, w, sample[p], (p + 1)/2, 9);
     138             :             else
     139      274788 :                 RENAME(decode_line)(s, w, sample[p], (p + 1)/2, bits + (s->slice_coding_mode != 1));
     140             :         }
     141    31322160 :         for (x = 0; x < w; x++) {
     142    31138968 :             int g = sample[0][1][x];
     143    31138968 :             int b = sample[1][1][x];
     144    31138968 :             int r = sample[2][1][x];
     145    31138968 :             int a = sample[3][1][x];
     146             : 
     147    31138968 :             if (s->slice_coding_mode != 1) {
     148    31138968 :                 b -= offset;
     149    31138968 :                 r -= offset;
     150    31138968 :                 g -= (b * s->slice_rct_by_coef + r * s->slice_rct_ry_coef) >> 2;
     151    31138968 :                 b += g;
     152    31138968 :                 r += g;
     153             :             }
     154             : 
     155    31138968 :             if (lbd)
     156    15569484 :                 *((uint32_t*)(src[0] + x*4 + stride[0]*y)) = b + ((unsigned)g<<8) + ((unsigned)r<<16) + ((unsigned)a<<24);
     157             :             else if (sizeof(TYPE) == 4) {
     158    15569484 :                 *((uint16_t*)(src[0] + x*2 + stride[0]*y)) = g;
     159    15569484 :                 *((uint16_t*)(src[1] + x*2 + stride[1]*y)) = b;
     160    15569484 :                 *((uint16_t*)(src[2] + x*2 + stride[2]*y)) = r;
     161             :             } else {
     162           0 :                 *((uint16_t*)(src[0] + x*2 + stride[0]*y)) = b;
     163           0 :                 *((uint16_t*)(src[1] + x*2 + stride[1]*y)) = g;
     164           0 :                 *((uint16_t*)(src[2] + x*2 + stride[2]*y)) = r;
     165             :             }
     166             :         }
     167             :     }
     168        1632 : }

Generated by: LCOV version 1.13