LCOV - code coverage report
Current view: top level - libavcodec - dirac_dwt_template.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 73 388 18.8 %
Date: 2017-12-16 13:57:32 Functions: 18 93 19.4 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (C) 2004-2010 Michael Niedermayer <michaelni@gmx.at>
       3             :  * Copyright (C) 2008 David Conrad
       4             :  * Copyright (C) 2015 Open Broadcast Systems Ltd.
       5             :  * Author    (C) 2015 Rostislav Pehlivanov <atomnuker@gmail.com>
       6             :  *
       7             :  * This file is part of FFmpeg.
       8             :  *
       9             :  * FFmpeg is free software; you can redistribute it and/or
      10             :  * modify it under the terms of the GNU Lesser General Public
      11             :  * License as published by the Free Software Foundation; either
      12             :  * version 2.1 of the License, or (at your option) any later version.
      13             :  *
      14             :  * FFmpeg is distributed in the hope that it will be useful,
      15             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      16             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      17             :  * Lesser General Public License for more details.
      18             :  *
      19             :  * You should have received a copy of the GNU Lesser General Public
      20             :  * License along with FFmpeg; if not, write to the Free Software
      21             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      22             :  */
      23             : 
      24             : #if defined(TEMPLATE_8bit)
      25             : 
      26             : #    define RENAME(N)   N ## _8bit
      27             : #    define TYPE        int16_t
      28             : #    undef  TEMPLATE_8bit
      29             : 
      30             : #elif defined(TEMPLATE_10bit)
      31             : 
      32             : #    define RENAME(N)   N ## _10bit
      33             : #    define TYPE        int32_t
      34             : #    undef  TEMPLATE_10bit
      35             : 
      36             : #elif defined(TEMPLATE_12bit)
      37             : 
      38             : #    define RENAME(N)   N ## _12bit
      39             : #    define TYPE        int32_t
      40             : #    undef  TEMPLATE_12bit
      41             : 
      42             : #endif
      43             : 
      44      142680 : static void RENAME(vertical_compose53iL0)(uint8_t *_b0, uint8_t *_b1, uint8_t *_b2,
      45             :                                           int width)
      46             : {
      47             :     int i;
      48      142680 :     TYPE *b0 = (TYPE *)_b0;
      49      142680 :     TYPE *b1 = (TYPE *)_b1;
      50      142680 :     TYPE *b2 = (TYPE *)_b2;
      51    28459200 :     for (i = 0; i < width; i++)
      52    28316520 :         b1[i] -= (int)(b0[i] + (unsigned)b2[i] + 2) >> 2;
      53      142680 : }
      54             : 
      55           0 : static av_always_inline void RENAME(interleave)(TYPE *dst, TYPE *src0, TYPE *src1, int w2,
      56             :                                                 int add, int shift)
      57             : {
      58             :     int i;
      59           0 :     for (i = 0; i < w2; i++) {
      60           0 :         dst[2*i  ] = (src0[i] + add) >> shift;
      61           0 :         dst[2*i+1] = (src1[i] + add) >> shift;
      62             :     }
      63           0 : }
      64             : 
      65           0 : static void RENAME(horizontal_compose_dirac53i)(uint8_t *_b, uint8_t *_temp, int w)
      66             : {
      67             :     int x;
      68           0 :     const int w2 = w >> 1;
      69           0 :     TYPE *b     = (TYPE *)_b;
      70           0 :     TYPE *temp  = (TYPE *)_temp;
      71             : 
      72           0 :     temp[0] = COMPOSE_53iL0(b[w2], b[0], b[w2]);
      73           0 :     for (x = 1; x < w2; x++) {
      74           0 :         temp[x     ] = COMPOSE_53iL0     (b[x+w2-1], b[x     ], b[x+w2]);
      75           0 :         temp[x+w2-1] = COMPOSE_DIRAC53iH0(temp[x-1], b[x+w2-1], temp[x]);
      76             :     }
      77           0 :     temp[w-1] = COMPOSE_DIRAC53iH0(temp[w2-1], b[w-1], temp[w2-1]);
      78             : 
      79           0 :     RENAME(interleave)(b, temp, temp+w2, w2, 1, 1);
      80           0 : }
      81             : 
      82      285360 : static void RENAME(horizontal_compose_dd97i)(uint8_t *_b, uint8_t *_tmp, int w)
      83             : {
      84             :     int x;
      85      285360 :     const int w2 = w >> 1;
      86      285360 :     TYPE *b   = (TYPE *)_b;
      87      285360 :     TYPE *tmp = (TYPE *)_tmp;
      88             : 
      89      285360 :     tmp[0] = COMPOSE_53iL0(b[w2], b[0], b[w2]);
      90    28316520 :     for (x = 1; x < w2; x++)
      91    28031160 :         tmp[x] = COMPOSE_53iL0(b[x+w2-1], b[x], b[x+w2]);
      92             : 
      93             :     // extend the edges
      94      285360 :     tmp[-1]   = tmp[0];
      95      285360 :     tmp[w2+1] = tmp[w2] = tmp[w2-1];
      96             : 
      97    28601880 :     for (x = 0; x < w2; x++) {
      98    28316520 :         b[2*x  ] = (tmp[x] + 1)>>1;
      99    28316520 :         b[2*x+1] = (COMPOSE_DD97iH0(tmp[x-1], tmp[x], b[x+w2], tmp[x+1], tmp[x+2]) + 1)>>1;
     100             :     }
     101      285360 : }
     102             : 
     103           0 : static void RENAME(horizontal_compose_dd137i)(uint8_t *_b, uint8_t *_tmp, int w)
     104             : {
     105           0 :     const int w2 = w >> 1;
     106             :     int x;
     107           0 :     TYPE *b   = (TYPE *)_b;
     108           0 :     TYPE *tmp = (TYPE *)_tmp;
     109             : 
     110           0 :     tmp[0] = COMPOSE_DD137iL0(b[w2], b[w2], b[0], b[w2  ], b[w2+1]);
     111           0 :     tmp[1] = COMPOSE_DD137iL0(b[w2], b[w2], b[1], b[w2+1], b[w2+2]);
     112           0 :     for (x = 2; x < w2-1; x++)
     113           0 :         tmp[x] = COMPOSE_DD137iL0(b[x+w2-2], b[x+w2-1], b[x], b[x+w2], b[x+w2+1]);
     114           0 :     tmp[w2-1] = COMPOSE_DD137iL0(b[w-3], b[w-2], b[w2-1], b[w-1], b[w-1]);
     115             : 
     116             :     // extend the edges
     117           0 :     tmp[-1]   = tmp[0];
     118           0 :     tmp[w2+1] = tmp[w2] = tmp[w2-1];
     119             : 
     120           0 :     for (x = 0; x < w2; x++) {
     121           0 :         b[2*x  ] = (tmp[x] + 1)>>1;
     122           0 :         b[2*x+1] = (COMPOSE_DD97iH0(tmp[x-1], tmp[x], b[x+w2], tmp[x+1], tmp[x+2]) + 1)>>1;
     123             :     }
     124           0 : }
     125             : 
     126           0 : static av_always_inline void RENAME(horizontal_compose_haari)(TYPE *b, TYPE *temp,
     127             :                                                               int w, int shift)
     128             : {
     129           0 :     const int w2 = w >> 1;
     130             :     int x;
     131             : 
     132           0 :     for (x = 0; x < w2; x++) {
     133           0 :         temp[x   ] = COMPOSE_HAARiL0(b[x   ], b[x+w2]);
     134           0 :         temp[x+w2] = COMPOSE_HAARiH0(b[x+w2], temp[x]);
     135             :     }
     136             : 
     137           0 :     RENAME(interleave)(b, temp, temp+w2, w2, shift, shift);
     138           0 : }
     139             : 
     140           0 : static void RENAME(horizontal_compose_haar0i)(uint8_t *_b, uint8_t *_temp, int w)
     141             : {
     142           0 :     TYPE *b    = (TYPE *)_b;
     143           0 :     TYPE *temp = (TYPE *)_temp;
     144           0 :     RENAME(horizontal_compose_haari)(b, temp, w, 0);
     145           0 : }
     146             : 
     147           0 : static void RENAME(horizontal_compose_haar1i)(uint8_t *_b, uint8_t *_temp, int w)
     148             : {
     149           0 :     TYPE *b    = (TYPE *)_b;
     150           0 :     TYPE *temp = (TYPE *)_temp;
     151           0 :     RENAME(horizontal_compose_haari)(b, temp, w, 1);
     152           0 : }
     153             : 
     154           0 : static void RENAME(horizontal_compose_fidelityi)(uint8_t *_b, uint8_t *_tmp, int w)
     155             : {
     156           0 :     const int w2 = w >> 1;
     157             :     int i, x;
     158             :     TYPE v[8];
     159           0 :     TYPE *b   = (TYPE *)_b;
     160           0 :     TYPE *tmp = (TYPE *)_tmp;
     161             : 
     162           0 :     for (x = 0; x < w2; x++) {
     163           0 :         for (i = 0; i < 8; i++)
     164           0 :             v[i] = b[av_clip(x-3+i, 0, w2-1)];
     165           0 :         tmp[x] = COMPOSE_FIDELITYiH0(v[0], v[1], v[2], v[3], b[x+w2], v[4], v[5], v[6], v[7]);
     166             :     }
     167             : 
     168           0 :     for (x = 0; x < w2; x++) {
     169           0 :         for (i = 0; i < 8; i++)
     170           0 :             v[i] = tmp[av_clip(x-4+i, 0, w2-1)];
     171           0 :         tmp[x+w2] = COMPOSE_FIDELITYiL0(v[0], v[1], v[2], v[3], b[x], v[4], v[5], v[6], v[7]);
     172             :     }
     173             : 
     174           0 :     RENAME(interleave)(b, tmp+w2, tmp, w2, 0, 0);
     175           0 : }
     176             : 
     177           0 : static void RENAME(horizontal_compose_daub97i)(uint8_t *_b, uint8_t *_temp, int w)
     178             : {
     179           0 :     const int w2 = w >> 1;
     180             :     int x, b0, b1, b2;
     181           0 :     TYPE *b    = (TYPE *)_b;
     182           0 :     TYPE *temp = (TYPE *)_temp;
     183             : 
     184           0 :     temp[0] = COMPOSE_DAUB97iL1(b[w2], b[0], b[w2]);
     185           0 :     for (x = 1; x < w2; x++) {
     186           0 :         temp[x     ] = COMPOSE_DAUB97iL1(b[x+w2-1], b[x     ], b[x+w2]);
     187           0 :         temp[x+w2-1] = COMPOSE_DAUB97iH1(temp[x-1], b[x+w2-1], temp[x]);
     188             :     }
     189           0 :     temp[w-1] = COMPOSE_DAUB97iH1(temp[w2-1], b[w-1], temp[w2-1]);
     190             : 
     191             :     // second stage combined with interleave and shift
     192           0 :     b0 = b2 = COMPOSE_DAUB97iL0(temp[w2], temp[0], temp[w2]);
     193           0 :     b[0] = (b0 + 1) >> 1;
     194           0 :     for (x = 1; x < w2; x++) {
     195           0 :         b2 = COMPOSE_DAUB97iL0(temp[x+w2-1], temp[x     ], temp[x+w2]);
     196           0 :         b1 = COMPOSE_DAUB97iH0(          b0, temp[x+w2-1], b2        );
     197           0 :         b[2*x-1] = (b1 + 1) >> 1;
     198           0 :         b[2*x  ] = (b2 + 1) >> 1;
     199           0 :         b0 = b2;
     200             :     }
     201           0 :     b[w-1] = (COMPOSE_DAUB97iH0(b2, temp[w-1], b2) + 1) >> 1;
     202           0 : }
     203             : 
     204           0 : static void RENAME(vertical_compose_dirac53iH0)(uint8_t *_b0, uint8_t *_b1, uint8_t *_b2,
     205             :                                                 int width)
     206             : {
     207             :     int i;
     208           0 :     TYPE *b0  = (TYPE *)_b0;
     209           0 :     TYPE *b1 = (TYPE *)_b1;
     210           0 :     TYPE *b2 = (TYPE *)_b2;
     211           0 :     for(i=0; i<width; i++){
     212           0 :         b1[i] = COMPOSE_DIRAC53iH0(b0[i], b1[i], b2[i]);
     213             :     }
     214           0 : }
     215             : 
     216      142680 : static void RENAME(vertical_compose_dd97iH0)(uint8_t *_b0, uint8_t *_b1, uint8_t *_b2,
     217             :                                              uint8_t *_b3, uint8_t *_b4, int width)
     218             : {
     219             :     int i;
     220      142680 :     TYPE *b0 = (TYPE *)_b0;
     221      142680 :     TYPE *b1 = (TYPE *)_b1;
     222      142680 :     TYPE *b2 = (TYPE *)_b2;
     223      142680 :     TYPE *b3 = (TYPE *)_b3;
     224      142680 :     TYPE *b4 = (TYPE *)_b4;
     225    28459200 :     for(i=0; i<width; i++){
     226    28316520 :         b2[i] = COMPOSE_DD97iH0(b0[i], b1[i], b2[i], b3[i], b4[i]);
     227             :     }
     228      142680 : }
     229             : 
     230           0 : static void RENAME(vertical_compose_dd137iL0)(uint8_t *_b0, uint8_t *_b1, uint8_t *_b2,
     231             :                                               uint8_t *_b3, uint8_t *_b4, int width)
     232             : {
     233             :     int i;
     234           0 :     TYPE *b0 = (TYPE *)_b0;
     235           0 :     TYPE *b1 = (TYPE *)_b1;
     236           0 :     TYPE *b2 = (TYPE *)_b2;
     237           0 :     TYPE *b3 = (TYPE *)_b3;
     238           0 :     TYPE *b4 = (TYPE *)_b4;
     239           0 :     for(i=0; i<width; i++){
     240           0 :         b2[i] = COMPOSE_DD137iL0(b0[i], b1[i], b2[i], b3[i], b4[i]);
     241             :     }
     242           0 : }
     243             : 
     244           0 : static void RENAME(vertical_compose_haar)(uint8_t *_b0, uint8_t *_b1, int width)
     245             : {
     246             :     int i;
     247           0 :     TYPE *b0 = (TYPE *)_b0;
     248           0 :     TYPE *b1 = (TYPE *)_b1;
     249             : 
     250           0 :     for (i = 0; i < width; i++) {
     251           0 :         b0[i] = COMPOSE_HAARiL0(b0[i], b1[i]);
     252           0 :         b1[i] = COMPOSE_HAARiH0(b1[i], b0[i]);
     253             :     }
     254           0 : }
     255             : 
     256           0 : static void RENAME(vertical_compose_fidelityiH0)(uint8_t *_dst, uint8_t *_b[8], int width)
     257             : {
     258             :     int i;
     259           0 :     TYPE *dst = (TYPE *)_dst;
     260           0 :     TYPE *b0  = (TYPE *)_b[0];
     261           0 :     TYPE *b1  = (TYPE *)_b[1];
     262           0 :     TYPE *b2  = (TYPE *)_b[2];
     263           0 :     TYPE *b3  = (TYPE *)_b[3];
     264           0 :     TYPE *b4  = (TYPE *)_b[4];
     265           0 :     TYPE *b5  = (TYPE *)_b[5];
     266           0 :     TYPE *b6  = (TYPE *)_b[6];
     267           0 :     TYPE *b7  = (TYPE *)_b[7];
     268           0 :     for(i=0; i<width; i++){
     269           0 :         dst[i] = COMPOSE_FIDELITYiH0(b0[i], b1[i], b2[i], b3[i], dst[i], b4[i], b5[i], b6[i], b7[i]);
     270             :     }
     271           0 : }
     272             : 
     273           0 : static void RENAME(vertical_compose_fidelityiL0)(uint8_t *_dst, uint8_t *_b[8], int width)
     274             : {
     275             :     int i;
     276           0 :     TYPE *dst = (TYPE *)_dst;
     277           0 :     TYPE *b0  = (TYPE *)_b[0];
     278           0 :     TYPE *b1  = (TYPE *)_b[1];
     279           0 :     TYPE *b2  = (TYPE *)_b[2];
     280           0 :     TYPE *b3  = (TYPE *)_b[3];
     281           0 :     TYPE *b4  = (TYPE *)_b[4];
     282           0 :     TYPE *b5  = (TYPE *)_b[5];
     283           0 :     TYPE *b6  = (TYPE *)_b[6];
     284           0 :     TYPE *b7  = (TYPE *)_b[7];
     285             : 
     286           0 :     for(i=0; i<width; i++){
     287           0 :         dst[i] = COMPOSE_FIDELITYiL0(b0[i], b1[i], b2[i], b3[i], dst[i], b4[i], b5[i], b6[i], b7[i]);
     288             :     }
     289           0 : }
     290             : 
     291           0 : static void RENAME(vertical_compose_daub97iH0)(uint8_t *_b0, uint8_t *_b1, uint8_t *_b2, int width)
     292             : {
     293             :     int i;
     294           0 :     TYPE *b0 = (TYPE *)_b0;
     295           0 :     TYPE *b1 = (TYPE *)_b1;
     296           0 :     TYPE *b2 = (TYPE *)_b2;
     297             : 
     298           0 :     for(i=0; i<width; i++){
     299           0 :         b1[i] = COMPOSE_DAUB97iH0(b0[i], b1[i], b2[i]);
     300             :     }
     301           0 : }
     302             : 
     303           0 : static void RENAME(vertical_compose_daub97iH1)(uint8_t *_b0, uint8_t *_b1, uint8_t *_b2, int width)
     304             : {
     305             :     int i;
     306           0 :     TYPE *b0 = (TYPE *)_b0;
     307           0 :     TYPE *b1 = (TYPE *)_b1;
     308           0 :     TYPE *b2 = (TYPE *)_b2;
     309             : 
     310           0 :     for(i=0; i<width; i++){
     311           0 :         b1[i] = COMPOSE_DAUB97iH1(b0[i], b1[i], b2[i]);
     312             :     }
     313           0 : }
     314             : 
     315           0 : static void RENAME(vertical_compose_daub97iL0)(uint8_t *_b0, uint8_t *_b1, uint8_t *_b2, int width)
     316             : {
     317             :     int i;
     318           0 :     TYPE *b0 = (TYPE *)_b0;
     319           0 :     TYPE *b1 = (TYPE *)_b1;
     320           0 :     TYPE *b2 = (TYPE *)_b2;
     321             : 
     322           0 :     for(i=0; i<width; i++){
     323           0 :         b1[i] = COMPOSE_DAUB97iL0(b0[i], b1[i], b2[i]);
     324             :     }
     325           0 : }
     326             : 
     327           0 : static void RENAME(vertical_compose_daub97iL1)(uint8_t *_b0, uint8_t *_b1, uint8_t *_b2, int width)
     328             : {
     329             :     int i;
     330           0 :     TYPE *b0 = (TYPE *)_b0;
     331           0 :     TYPE *b1 = (TYPE *)_b1;
     332           0 :     TYPE *b2 = (TYPE *)_b2;
     333             : 
     334           0 :     for(i=0; i<width; i++){
     335           0 :         b1[i] = COMPOSE_DAUB97iL1(b0[i], b1[i], b2[i]);
     336             :     }
     337           0 : }
     338             : 
     339      150186 : static void RENAME(spatial_compose_dd97i_dy)(DWTContext *d, int level, int width, int height, int stride)
     340             : {
     341      150186 :     vertical_compose_3tap vertical_compose_l0 = (void*)d->vertical_compose_l0;
     342      150186 :     vertical_compose_5tap vertical_compose_h0 = (void*)d->vertical_compose_h0;
     343      150186 :     DWTCompose *cs = d->cs + level;
     344             : 
     345      150186 :     int i, y = cs->y;
     346             :     uint8_t *b[8];
     347     1051302 :     for (i = 0; i < 6; i++)
     348      901116 :         b[i] = cs->b[i];
     349      150186 :     b[6] = d->buffer + av_clip(y+5, 0, height-2)*stride;
     350      150186 :     b[7] = d->buffer + av_clip(y+6, 1, height-1)*stride;
     351             : 
     352      150186 :     if(y+5<(unsigned)height) vertical_compose_l0(      b[5], b[6], b[7],       width);
     353      150186 :     if(y+1<(unsigned)height) vertical_compose_h0(b[0], b[2], b[3], b[4], b[6], width);
     354             : 
     355      150186 :     if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width);
     356      150186 :     if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width);
     357             : 
     358     1051302 :     for (i = 0; i < 6; i++)
     359      901116 :         cs->b[i] = b[i+2];
     360      150186 :     cs->y += 2;
     361      150186 : }
     362             : 
     363           0 : static void RENAME(spatial_compose_dirac53i_dy)(DWTContext *d, int level, int width, int height, int stride)
     364             : {
     365           0 :     vertical_compose_3tap vertical_compose_l0 = (void*)d->vertical_compose_l0;
     366           0 :     vertical_compose_3tap vertical_compose_h0 = (void*)d->vertical_compose_h0;
     367           0 :     DWTCompose *cs = d->cs + level;
     368             : 
     369           0 :     int y= cs->y;
     370           0 :     uint8_t *b[4] = { cs->b[0], cs->b[1] };
     371           0 :     b[2] = d->buffer + avpriv_mirror(y+1, height-1)*stride;
     372           0 :     b[3] = d->buffer + avpriv_mirror(y+2, height-1)*stride;
     373             : 
     374           0 :     if(y+1<(unsigned)height) vertical_compose_l0(b[1], b[2], b[3], width);
     375           0 :     if(y+0<(unsigned)height) vertical_compose_h0(b[0], b[1], b[2], width);
     376             : 
     377           0 :     if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width);
     378           0 :     if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width);
     379             : 
     380           0 :     cs->b[0] = b[2];
     381           0 :     cs->b[1] = b[3];
     382           0 :     cs->y += 2;
     383           0 : }
     384             : 
     385           0 : static void RENAME(spatial_compose_dd137i_dy)(DWTContext *d, int level, int width, int height, int stride)
     386             : {
     387           0 :     vertical_compose_5tap vertical_compose_l0 = (void*)d->vertical_compose_l0;
     388           0 :     vertical_compose_5tap vertical_compose_h0 = (void*)d->vertical_compose_h0;
     389           0 :     DWTCompose *cs = d->cs + level;
     390             : 
     391           0 :     int i, y = cs->y;
     392             :     uint8_t *b[10];
     393           0 :     for (i = 0; i < 8; i++)
     394           0 :         b[i] = cs->b[i];
     395           0 :     b[8] = d->buffer + av_clip(y+7, 0, height-2)*stride;
     396           0 :     b[9] = d->buffer + av_clip(y+8, 1, height-1)*stride;
     397             : 
     398           0 :     if(y+5<(unsigned)height) vertical_compose_l0(b[3], b[5], b[6], b[7], b[9], width);
     399           0 :     if(y+1<(unsigned)height) vertical_compose_h0(b[0], b[2], b[3], b[4], b[6], width);
     400             : 
     401           0 :     if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width);
     402           0 :     if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width);
     403             : 
     404           0 :     for (i = 0; i < 8; i++)
     405           0 :         cs->b[i] = b[i+2];
     406           0 :     cs->y += 2;
     407           0 : }
     408             : 
     409             : // haar makes the assumption that height is even (always true for dirac)
     410           0 : static void RENAME(spatial_compose_haari_dy)(DWTContext *d, int level, int width, int height, int stride)
     411             : {
     412           0 :     vertical_compose_2tap vertical_compose = (void*)d->vertical_compose;
     413           0 :     int y = d->cs[level].y;
     414           0 :     uint8_t *b0 = d->buffer + (y-1)*stride;
     415           0 :     uint8_t *b1 = d->buffer + (y  )*stride;
     416             : 
     417           0 :     vertical_compose(b0, b1, width);
     418           0 :     d->horizontal_compose(b0, d->temp, width);
     419           0 :     d->horizontal_compose(b1, d->temp, width);
     420             : 
     421           0 :     d->cs[level].y += 2;
     422           0 : }
     423             : 
     424             : // Don't do sliced idwt for fidelity; the 9 tap filter makes it a bit annoying
     425             : // Fortunately, this filter isn't used in practice.
     426           0 : static void RENAME(spatial_compose_fidelity)(DWTContext *d, int level, int width, int height, int stride)
     427             : {
     428           0 :     vertical_compose_9tap vertical_compose_l0 = (void*)d->vertical_compose_l0;
     429           0 :     vertical_compose_9tap vertical_compose_h0 = (void*)d->vertical_compose_h0;
     430             :     int i, y;
     431             :     uint8_t *b[8];
     432             : 
     433           0 :     for (y = 1; y < height; y += 2) {
     434           0 :         for (i = 0; i < 8; i++)
     435           0 :             b[i] = d->buffer + av_clip((y-7 + 2*i), 0, height-2)*stride;
     436           0 :         vertical_compose_h0(d->buffer + y*stride, b, width);
     437             :     }
     438             : 
     439           0 :     for (y = 0; y < height; y += 2) {
     440           0 :         for (i = 0; i < 8; i++)
     441           0 :             b[i] = d->buffer + av_clip((y-7 + 2*i), 1, height-1)*stride;
     442           0 :         vertical_compose_l0(d->buffer + y*stride, b, width);
     443             :     }
     444             : 
     445           0 :     for (y = 0; y < height; y++)
     446           0 :         d->horizontal_compose(d->buffer + y*stride, d->temp, width);
     447             : 
     448           0 :     d->cs[level].y = height+1;
     449           0 : }
     450             : 
     451           0 : static void RENAME(spatial_compose_daub97i_dy)(DWTContext *d, int level, int width, int height, int stride)
     452             : {
     453           0 :     vertical_compose_3tap vertical_compose_l0 = (void*)d->vertical_compose_l0;
     454           0 :     vertical_compose_3tap vertical_compose_h0 = (void*)d->vertical_compose_h0;
     455           0 :     vertical_compose_3tap vertical_compose_l1 = (void*)d->vertical_compose_l1;
     456           0 :     vertical_compose_3tap vertical_compose_h1 = (void*)d->vertical_compose_h1;
     457           0 :     DWTCompose *cs = d->cs + level;
     458             : 
     459           0 :     int i, y = cs->y;
     460             :     uint8_t *b[6];
     461           0 :     for (i = 0; i < 4; i++)
     462           0 :         b[i] = cs->b[i];
     463           0 :     b[4] = d->buffer + avpriv_mirror(y+3, height-1)*stride;
     464           0 :     b[5] = d->buffer + avpriv_mirror(y+4, height-1)*stride;
     465             : 
     466           0 :     if(y+3<(unsigned)height) vertical_compose_l1(b[3], b[4], b[5], width);
     467           0 :     if(y+2<(unsigned)height) vertical_compose_h1(b[2], b[3], b[4], width);
     468           0 :     if(y+1<(unsigned)height) vertical_compose_l0(b[1], b[2], b[3], width);
     469           0 :     if(y+0<(unsigned)height) vertical_compose_h0(b[0], b[1], b[2], width);
     470             : 
     471           0 :     if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width);
     472           0 :     if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width);
     473             : 
     474           0 :     for (i = 0; i < 4; i++)
     475           0 :         cs->b[i] = b[i+2];
     476           0 :     cs->y += 2;
     477           0 : }
     478             : 
     479           0 : static void RENAME(spatial_compose97i_init)(DWTCompose *cs, uint8_t *buffer, int height, int stride)
     480             : {
     481           0 :     cs->b[0] = buffer + avpriv_mirror(-3-1, height-1)*stride;
     482           0 :     cs->b[1] = buffer + avpriv_mirror(-3  , height-1)*stride;
     483           0 :     cs->b[2] = buffer + avpriv_mirror(-3+1, height-1)*stride;
     484           0 :     cs->b[3] = buffer + avpriv_mirror(-3+2, height-1)*stride;
     485           0 :     cs->y = -3;
     486           0 : }
     487             : 
     488           0 : static void RENAME(spatial_compose53i_init)(DWTCompose *cs, uint8_t *buffer, int height, int stride)
     489             : {
     490           0 :     cs->b[0] = buffer + avpriv_mirror(-1-1, height-1)*stride;
     491           0 :     cs->b[1] = buffer + avpriv_mirror(-1  , height-1)*stride;
     492           0 :     cs->y = -1;
     493           0 : }
     494             : 
     495        2502 : static void RENAME(spatial_compose_dd97i_init)(DWTCompose *cs, uint8_t *buffer, int height, int stride)
     496             : {
     497        2502 :     cs->b[0] = buffer + av_clip(-5-1, 0, height-2)*stride;
     498        2502 :     cs->b[1] = buffer + av_clip(-5  , 1, height-1)*stride;
     499        2502 :     cs->b[2] = buffer + av_clip(-5+1, 0, height-2)*stride;
     500        2502 :     cs->b[3] = buffer + av_clip(-5+2, 1, height-1)*stride;
     501        2502 :     cs->b[4] = buffer + av_clip(-5+3, 0, height-2)*stride;
     502        2502 :     cs->b[5] = buffer + av_clip(-5+4, 1, height-1)*stride;
     503        2502 :     cs->y = -5;
     504        2502 : }
     505             : 
     506           0 : static void RENAME(spatial_compose_dd137i_init)(DWTCompose *cs, uint8_t *buffer, int height, int stride)
     507             : {
     508           0 :     cs->b[0] = buffer + av_clip(-5-1, 0, height-2)*stride;
     509           0 :     cs->b[1] = buffer + av_clip(-5  , 1, height-1)*stride;
     510           0 :     cs->b[2] = buffer + av_clip(-5+1, 0, height-2)*stride;
     511           0 :     cs->b[3] = buffer + av_clip(-5+2, 1, height-1)*stride;
     512           0 :     cs->b[4] = buffer + av_clip(-5+3, 0, height-2)*stride;
     513           0 :     cs->b[5] = buffer + av_clip(-5+4, 1, height-1)*stride;
     514           0 :     cs->b[6] = buffer + av_clip(-5+5, 0, height-2)*stride;
     515           0 :     cs->b[7] = buffer + av_clip(-5+6, 1, height-1)*stride;
     516           0 :     cs->y = -5;
     517           0 : }
     518             : 
     519         672 : static int RENAME(ff_spatial_idwt_init)(DWTContext *d, enum dwt_type type)
     520             : {
     521             :     int level;
     522             : 
     523         672 :     d->temp = (uint8_t *)(((TYPE *)d->temp) + 8);
     524             : 
     525        3174 :     for (level = d->decomposition_count - 1; level >= 0; level--){
     526        2502 :         int hl = d->height >> level;
     527        2502 :         int stride_l = d->stride << level;
     528             : 
     529        2502 :         switch(type){
     530        2502 :             case DWT_DIRAC_DD9_7:
     531        2502 :                 RENAME(spatial_compose_dd97i_init)(d->cs+level, d->buffer, hl, stride_l);
     532        2502 :                 break;
     533           0 :             case DWT_DIRAC_LEGALL5_3:
     534           0 :                 RENAME(spatial_compose53i_init)(d->cs+level, d->buffer, hl, stride_l);
     535           0 :                 break;
     536           0 :             case DWT_DIRAC_DD13_7:
     537           0 :                 RENAME(spatial_compose_dd137i_init)(d->cs+level, d->buffer, hl, stride_l);
     538           0 :                 break;
     539           0 :             case DWT_DIRAC_HAAR0:
     540             :             case DWT_DIRAC_HAAR1:
     541           0 :                 d->cs[level].y = 1;
     542           0 :                 break;
     543           0 :             case DWT_DIRAC_DAUB9_7:
     544           0 :                 RENAME(spatial_compose97i_init)(d->cs+level, d->buffer, hl, stride_l);
     545           0 :                 break;
     546           0 :             default:
     547           0 :                 d->cs[level].y = 0;
     548           0 :                 break;
     549             :         }
     550             :     }
     551             : 
     552         672 :     switch (type) {
     553         672 :         case DWT_DIRAC_DD9_7:
     554         672 :             d->spatial_compose = RENAME(spatial_compose_dd97i_dy);
     555         672 :             d->vertical_compose_l0 = (void*)RENAME(vertical_compose53iL0);
     556         672 :             d->vertical_compose_h0 = (void*)RENAME(vertical_compose_dd97iH0);
     557         672 :             d->horizontal_compose = RENAME(horizontal_compose_dd97i);
     558         672 :             d->support = 7;
     559         672 :             break;
     560           0 :         case DWT_DIRAC_LEGALL5_3:
     561           0 :             d->spatial_compose = RENAME(spatial_compose_dirac53i_dy);
     562           0 :             d->vertical_compose_l0 = (void*)RENAME(vertical_compose53iL0);
     563           0 :             d->vertical_compose_h0 = (void*)RENAME(vertical_compose_dirac53iH0);
     564           0 :             d->horizontal_compose = RENAME(horizontal_compose_dirac53i);
     565           0 :             d->support = 3;
     566           0 :             break;
     567           0 :         case DWT_DIRAC_DD13_7:
     568           0 :             d->spatial_compose = RENAME(spatial_compose_dd137i_dy);
     569           0 :             d->vertical_compose_l0 = (void*)RENAME(vertical_compose_dd137iL0);
     570           0 :             d->vertical_compose_h0 = (void*)RENAME(vertical_compose_dd97iH0);
     571           0 :             d->horizontal_compose = RENAME(horizontal_compose_dd137i);
     572           0 :             d->support = 7;
     573           0 :             break;
     574           0 :         case DWT_DIRAC_HAAR0:
     575             :         case DWT_DIRAC_HAAR1:
     576           0 :             d->spatial_compose = RENAME(spatial_compose_haari_dy);
     577           0 :             d->vertical_compose = (void*)RENAME(vertical_compose_haar);
     578           0 :             if (type == DWT_DIRAC_HAAR0)
     579           0 :                 d->horizontal_compose = RENAME(horizontal_compose_haar0i);
     580             :             else
     581           0 :                 d->horizontal_compose = RENAME(horizontal_compose_haar1i);
     582           0 :             d->support = 1;
     583           0 :             break;
     584           0 :         case DWT_DIRAC_FIDELITY:
     585           0 :             d->spatial_compose = RENAME(spatial_compose_fidelity);
     586           0 :             d->vertical_compose_l0 = (void*)RENAME(vertical_compose_fidelityiL0);
     587           0 :             d->vertical_compose_h0 = (void*)RENAME(vertical_compose_fidelityiH0);
     588           0 :             d->horizontal_compose = RENAME(horizontal_compose_fidelityi);
     589           0 :             d->support = 0; // not really used
     590           0 :             break;
     591           0 :         case DWT_DIRAC_DAUB9_7:
     592           0 :             d->spatial_compose = RENAME(spatial_compose_daub97i_dy);
     593           0 :             d->vertical_compose_l0 = (void*)RENAME(vertical_compose_daub97iL0);
     594           0 :             d->vertical_compose_h0 = (void*)RENAME(vertical_compose_daub97iH0);
     595           0 :             d->vertical_compose_l1 = (void*)RENAME(vertical_compose_daub97iL1);
     596           0 :             d->vertical_compose_h1 = (void*)RENAME(vertical_compose_daub97iH1);
     597           0 :             d->horizontal_compose = RENAME(horizontal_compose_daub97i);
     598           0 :             d->support = 5;
     599           0 :             break;
     600           0 :         default:
     601           0 :             return AVERROR_INVALIDDATA;
     602             :     }
     603             : 
     604         672 :     return 0;
     605             : }
     606             : 
     607             : #undef RENAME
     608             : #undef TYPE

Generated by: LCOV version 1.13