LCOV - code coverage report
Current view: top level - libavcodec - jpegls.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 31 40 77.5 %
Date: 2017-12-15 02:19:58 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /*
       2             :  * JPEG-LS common code
       3             :  * Copyright (c) 2003 Michael Niedermayer
       4             :  * Copyright (c) 2006 Konstantin Shishkov
       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             : /**
      24             :  * @file
      25             :  * JPEG-LS common code.
      26             :  */
      27             : 
      28             : #include "internal.h"
      29             : #include "jpegls.h"
      30             : 
      31         405 : void ff_jpegls_init_state(JLSState *state)
      32             : {
      33             :     int i;
      34             : 
      35         405 :     state->twonear = state->near * 2 + 1;
      36         405 :     state->range   = (state->maxval + state->twonear - 1) / state->twonear + 1;
      37             : 
      38             :     // QBPP = ceil(log2(RANGE))
      39         405 :     for (state->qbpp = 0; (1 << state->qbpp) < state->range; state->qbpp++)
      40             :         ;
      41             : 
      42         405 :     state->bpp   = FFMAX(av_log2(state->maxval) + 1, 2);
      43         405 :     state->limit = 2*(state->bpp + FFMAX(state->bpp, 8)) - state->qbpp;
      44             : 
      45      149040 :     for (i = 0; i < 367; i++) {
      46      148635 :         state->A[i] = FFMAX(state->range + 32 >> 6, 2);
      47      148635 :         state->N[i] = 1;
      48             :     }
      49         405 : }
      50             : 
      51             : /**
      52             :  * Custom value clipping function used in T1, T2, T3 calculation
      53             :  */
      54        1815 : static inline int iso_clip(int v, int vmin, int vmax)
      55             : {
      56        1815 :     if (v > vmax || v < vmin)
      57           0 :         return vmin;
      58             :     else
      59        1815 :         return v;
      60             : }
      61             : 
      62         605 : void ff_jpegls_reset_coding_parameters(JLSState *s, int reset_all)
      63             : {
      64         605 :     const int basic_t1 = 3;
      65         605 :     const int basic_t2 = 7;
      66         605 :     const int basic_t3 = 21;
      67             :     int factor;
      68             : 
      69         605 :     if (s->maxval == 0 || reset_all)
      70         605 :         s->maxval = (1 << s->bpp) - 1;
      71             : 
      72         605 :     if (s->maxval >= 128) {
      73         605 :         factor = FFMIN(s->maxval, 4095) + 128 >> 8;
      74             : 
      75         605 :         if (s->T1 == 0 || reset_all)
      76        1210 :             s->T1 = iso_clip(factor * (basic_t1 - 2) + 2 + 3 * s->near,
      77         605 :                              s->near + 1, s->maxval);
      78         605 :         if (s->T2 == 0 || reset_all)
      79         605 :             s->T2 = iso_clip(factor * (basic_t2 - 3) + 3 + 5 * s->near,
      80             :                              s->T1, s->maxval);
      81         605 :         if (s->T3 == 0 || reset_all)
      82         605 :             s->T3 = iso_clip(factor * (basic_t3 - 4) + 4 + 7 * s->near,
      83             :                              s->T2, s->maxval);
      84             :     } else {
      85           0 :         factor = 256 / (s->maxval + 1);
      86             : 
      87           0 :         if (s->T1 == 0 || reset_all)
      88           0 :             s->T1 = iso_clip(FFMAX(2, basic_t1 / factor + 3 * s->near),
      89           0 :                              s->near + 1, s->maxval);
      90           0 :         if (s->T2 == 0 || reset_all)
      91           0 :             s->T2 = iso_clip(FFMAX(3, basic_t2 / factor + 5 * s->near),
      92             :                              s->T1, s->maxval);
      93           0 :         if (s->T3 == 0 || reset_all)
      94           0 :             s->T3 = iso_clip(FFMAX(4, basic_t3 / factor + 7 * s->near),
      95             :                              s->T2, s->maxval);
      96             :     }
      97             : 
      98         605 :     if (s->reset == 0 || reset_all)
      99         605 :         s->reset = 64;
     100             :     ff_dlog(NULL, "[JPEG-LS RESET] T=%i,%i,%i\n", s->T1, s->T2, s->T3);
     101         605 : }

Generated by: LCOV version 1.13