LCOV - code coverage report
Current view: top level - src/libswscale - hscale.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 155 162 95.7 %
Date: 2017-01-19 23:52:33 Functions: 10 10 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (C) 2015 Pedro Arthur <bygrandao@gmail.com>
       3             :  *
       4             :  * This file is part of FFmpeg.
       5             :  *
       6             :  * FFmpeg is free software; you can redistribute it and/or
       7             :  * modify it under the terms of the GNU Lesser General Public
       8             :  * License as published by the Free Software Foundation; either
       9             :  * version 2.1 of the License, or (at your option) any later version.
      10             :  *
      11             :  * FFmpeg is distributed in the hope that it will be useful,
      12             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14             :  * Lesser General Public License for more details.
      15             :  *
      16             :  * You should have received a copy of the GNU Lesser General Public
      17             :  * License along with FFmpeg; if not, write to the Free Software
      18             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      19             :  */
      20             : 
      21             : #include "swscale_internal.h"
      22             : 
      23             : /// Scaler instance data
      24             : typedef struct FilterContext
      25             : {
      26             :     uint16_t *filter;
      27             :     int *filter_pos;
      28             :     int filter_size;
      29             :     int xInc;
      30             : } FilterContext;
      31             : 
      32             : /// Color conversion instance data
      33             : typedef struct ColorContext
      34             : {
      35             :     uint32_t *pal;
      36             : } ColorContext;
      37             : 
      38     1295124 : static int lum_h_scale(SwsContext *c, SwsFilterDescriptor *desc, int sliceY, int sliceH)
      39             : {
      40     1295124 :     FilterContext *instance = desc->instance;
      41     1295124 :     int srcW = desc->src->width;
      42     1295124 :     int dstW = desc->dst->width;
      43     1295124 :     int xInc = instance->xInc;
      44             : 
      45             :     int i;
      46     8620652 :     for (i = 0; i < sliceH; ++i) {
      47     7325528 :         uint8_t ** src = desc->src->plane[0].line;
      48     7325528 :         uint8_t ** dst = desc->dst->plane[0].line;
      49     7325528 :         int src_pos = sliceY+i - desc->src->plane[0].sliceY;
      50     7325528 :         int dst_pos = sliceY+i - desc->dst->plane[0].sliceY;
      51             : 
      52             : 
      53     7325528 :         if (c->hyscale_fast) {
      54           0 :             c->hyscale_fast(c, (int16_t*)dst[dst_pos], dstW, src[src_pos], srcW, xInc);
      55             :         } else {
      56    14651056 :             c->hyScale(c, (int16_t*)dst[dst_pos], dstW, (const uint8_t *)src[src_pos], instance->filter,
      57     7325528 :                        instance->filter_pos, instance->filter_size);
      58             :         }
      59             : 
      60     7325528 :         if (c->lumConvertRange)
      61      726829 :             c->lumConvertRange((int16_t*)dst[dst_pos], dstW);
      62             : 
      63     7325528 :         desc->dst->plane[0].sliceH += 1;
      64             : 
      65     7325528 :         if (desc->alpha) {
      66      165790 :             src = desc->src->plane[3].line;
      67      165790 :             dst = desc->dst->plane[3].line;
      68             : 
      69      165790 :             src_pos = sliceY+i - desc->src->plane[3].sliceY;
      70      165790 :             dst_pos = sliceY+i - desc->dst->plane[3].sliceY;
      71             : 
      72      165790 :             desc->dst->plane[3].sliceH += 1;
      73             : 
      74      165790 :             if (c->hyscale_fast) {
      75           0 :                 c->hyscale_fast(c, (int16_t*)dst[dst_pos], dstW, src[src_pos], srcW, xInc);
      76             :             } else {
      77      331580 :                 c->hyScale(c, (int16_t*)dst[dst_pos], dstW, (const uint8_t *)src[src_pos], instance->filter,
      78      165790 :                             instance->filter_pos, instance->filter_size);
      79             :             }
      80             :         }
      81             :     }
      82             : 
      83     1295124 :     return sliceH;
      84             : }
      85             : 
      86      243808 : static int lum_convert(SwsContext *c, SwsFilterDescriptor *desc, int sliceY, int sliceH)
      87             : {
      88      243808 :     int srcW = desc->src->width;
      89      243808 :     ColorContext * instance = desc->instance;
      90      243808 :     uint32_t * pal = instance->pal;
      91             :     int i;
      92             : 
      93      243808 :     desc->dst->plane[0].sliceY = sliceY;
      94      243808 :     desc->dst->plane[0].sliceH = sliceH;
      95      243808 :     desc->dst->plane[3].sliceY = sliceY;
      96      243808 :     desc->dst->plane[3].sliceH = sliceH;
      97             : 
      98     1689367 :     for (i = 0; i < sliceH; ++i) {
      99     1445559 :         int sp0 = sliceY+i - desc->src->plane[0].sliceY;
     100     1445559 :         int sp1 = ((sliceY+i) >> desc->src->v_chr_sub_sample) - desc->src->plane[1].sliceY;
     101     5782236 :         const uint8_t * src[4] = { desc->src->plane[0].line[sp0],
     102     1445559 :                         desc->src->plane[1].line[sp1],
     103     1445559 :                         desc->src->plane[2].line[sp1],
     104     1445559 :                         desc->src->plane[3].line[sp0]};
     105     1445559 :         uint8_t * dst = desc->dst->plane[0].line[i];
     106             : 
     107     1445559 :         if (c->lumToYV12) {
     108     1395091 :             c->lumToYV12(dst, src[0], src[1], src[2], srcW, pal);
     109       50468 :         } else if (c->readLumPlanar) {
     110       50468 :             c->readLumPlanar(dst, src, srcW, c->input_rgb2yuv_table);
     111             :         }
     112             : 
     113             : 
     114     1445559 :         if (desc->alpha) {
     115      162334 :             dst = desc->dst->plane[3].line[i];
     116      162334 :             if (c->alpToYV12) {
     117      160318 :                 c->alpToYV12(dst, src[3], src[1], src[2], srcW, pal);
     118        2016 :             } else if (c->readAlpPlanar) {
     119        2016 :                 c->readAlpPlanar(dst, src, srcW, NULL);
     120             :             }
     121             :         }
     122             :     }
     123             : 
     124      243808 :     return sliceH;
     125             : }
     126             : 
     127         229 : int ff_init_desc_fmt_convert(SwsFilterDescriptor *desc, SwsSlice * src, SwsSlice *dst, uint32_t *pal)
     128             : {
     129         229 :     ColorContext * li = av_malloc(sizeof(ColorContext));
     130         229 :     if (!li)
     131           0 :         return AVERROR(ENOMEM);
     132         229 :     li->pal = pal;
     133         229 :     desc->instance = li;
     134             : 
     135         229 :     desc->alpha = isALPHA(src->fmt) && isALPHA(dst->fmt);
     136         229 :     desc->src =src;
     137         229 :     desc->dst = dst;
     138         229 :     desc->process = &lum_convert;
     139             : 
     140         229 :     return 0;
     141             : }
     142             : 
     143             : 
     144        2247 : int ff_init_desc_hscale(SwsFilterDescriptor *desc, SwsSlice *src, SwsSlice *dst, uint16_t *filter, int * filter_pos, int filter_size, int xInc)
     145             : {
     146        2247 :     FilterContext *li = av_malloc(sizeof(FilterContext));
     147        2247 :     if (!li)
     148           0 :         return AVERROR(ENOMEM);
     149             : 
     150        2247 :     li->filter = filter;
     151        2247 :     li->filter_pos = filter_pos;
     152        2247 :     li->filter_size = filter_size;
     153        2247 :     li->xInc = xInc;
     154             : 
     155        2247 :     desc->instance = li;
     156             : 
     157        2247 :     desc->alpha = isALPHA(src->fmt) && isALPHA(dst->fmt);
     158        2247 :     desc->src = src;
     159        2247 :     desc->dst = dst;
     160             : 
     161        2247 :     desc->process = &lum_h_scale;
     162             : 
     163        2247 :     return 0;
     164             : }
     165             : 
     166     1030259 : static int chr_h_scale(SwsContext *c, SwsFilterDescriptor *desc, int sliceY, int sliceH)
     167             : {
     168     1030259 :     FilterContext *instance = desc->instance;
     169     1030259 :     int srcW = AV_CEIL_RSHIFT(desc->src->width, desc->src->h_chr_sub_sample);
     170     1030259 :     int dstW = AV_CEIL_RSHIFT(desc->dst->width, desc->dst->h_chr_sub_sample);
     171     1030259 :     int xInc = instance->xInc;
     172             : 
     173     1030259 :     uint8_t ** src1 = desc->src->plane[1].line;
     174     1030259 :     uint8_t ** dst1 = desc->dst->plane[1].line;
     175     1030259 :     uint8_t ** src2 = desc->src->plane[2].line;
     176     1030259 :     uint8_t ** dst2 = desc->dst->plane[2].line;
     177             : 
     178     1030259 :     int src_pos1 = sliceY - desc->src->plane[1].sliceY;
     179     1030259 :     int dst_pos1 = sliceY - desc->dst->plane[1].sliceY;
     180             : 
     181     1030259 :     int src_pos2 = sliceY - desc->src->plane[2].sliceY;
     182     1030259 :     int dst_pos2 = sliceY - desc->dst->plane[2].sliceY;
     183             : 
     184             :     int i;
     185     5760371 :     for (i = 0; i < sliceH; ++i) {
     186     4730112 :         if (c->hcscale_fast) {
     187           0 :             c->hcscale_fast(c, (uint16_t*)dst1[dst_pos1+i], (uint16_t*)dst2[dst_pos2+i], dstW, src1[src_pos1+i], src2[src_pos2+i], srcW, xInc);
     188             :         } else {
     189     4730112 :             c->hcScale(c, (uint16_t*)dst1[dst_pos1+i], dstW, src1[src_pos1+i], instance->filter, instance->filter_pos, instance->filter_size);
     190     4730112 :             c->hcScale(c, (uint16_t*)dst2[dst_pos2+i], dstW, src2[src_pos2+i], instance->filter, instance->filter_pos, instance->filter_size);
     191             :         }
     192             : 
     193     4730112 :         if (c->chrConvertRange)
     194      323208 :             c->chrConvertRange((uint16_t*)dst1[dst_pos1+i], (uint16_t*)dst2[dst_pos2+i], dstW);
     195             : 
     196     4730112 :         desc->dst->plane[1].sliceH += 1;
     197     4730112 :         desc->dst->plane[2].sliceH += 1;
     198             :     }
     199     1030259 :     return sliceH;
     200             : }
     201             : 
     202      306756 : static int chr_convert(SwsContext *c, SwsFilterDescriptor *desc, int sliceY, int sliceH)
     203             : {
     204      306756 :     int srcW = AV_CEIL_RSHIFT(desc->src->width, desc->src->h_chr_sub_sample);
     205      306756 :     ColorContext * instance = desc->instance;
     206      306756 :     uint32_t * pal = instance->pal;
     207             : 
     208      306756 :     int sp0 = (sliceY - (desc->src->plane[0].sliceY >> desc->src->v_chr_sub_sample)) << desc->src->v_chr_sub_sample;
     209      306756 :     int sp1 = sliceY - desc->src->plane[1].sliceY;
     210             : 
     211             :     int i;
     212             : 
     213      306756 :     desc->dst->plane[1].sliceY = sliceY;
     214      306756 :     desc->dst->plane[1].sliceH = sliceH;
     215      306756 :     desc->dst->plane[2].sliceY = sliceY;
     216      306756 :     desc->dst->plane[2].sliceH = sliceH;
     217             : 
     218     1646653 :     for (i = 0; i < sliceH; ++i) {
     219     5359588 :         const uint8_t * src[4] = { desc->src->plane[0].line[sp0+i],
     220     1339897 :                         desc->src->plane[1].line[sp1+i],
     221     1339897 :                         desc->src->plane[2].line[sp1+i],
     222     1339897 :                         desc->src->plane[3].line[sp0+i]};
     223             : 
     224     1339897 :         uint8_t * dst1 = desc->dst->plane[1].line[i];
     225     1339897 :         uint8_t * dst2 = desc->dst->plane[2].line[i];
     226     1339897 :         if (c->chrToYV12) {
     227     1311879 :             c->chrToYV12(dst1, dst2, src[0], src[1], src[2], srcW, pal);
     228       28018 :         } else if (c->readChrPlanar) {
     229       28018 :             c->readChrPlanar(dst1, dst2, src, srcW, c->input_rgb2yuv_table);
     230             :         }
     231             :     }
     232      306756 :     return sliceH;
     233             : }
     234             : 
     235         213 : int ff_init_desc_cfmt_convert(SwsFilterDescriptor *desc, SwsSlice * src, SwsSlice *dst, uint32_t *pal)
     236             : {
     237         213 :     ColorContext * li = av_malloc(sizeof(ColorContext));
     238         213 :     if (!li)
     239           0 :         return AVERROR(ENOMEM);
     240         213 :     li->pal = pal;
     241         213 :     desc->instance = li;
     242             : 
     243         213 :     desc->src =src;
     244         213 :     desc->dst = dst;
     245         213 :     desc->process = &chr_convert;
     246             : 
     247         213 :     return 0;
     248             : }
     249             : 
     250        2162 : int ff_init_desc_chscale(SwsFilterDescriptor *desc, SwsSlice *src, SwsSlice *dst, uint16_t *filter, int * filter_pos, int filter_size, int xInc)
     251             : {
     252        2162 :     FilterContext *li = av_malloc(sizeof(FilterContext));
     253        2162 :     if (!li)
     254           0 :         return AVERROR(ENOMEM);
     255             : 
     256        2162 :     li->filter = filter;
     257        2162 :     li->filter_pos = filter_pos;
     258        2162 :     li->filter_size = filter_size;
     259        2162 :     li->xInc = xInc;
     260             : 
     261        2162 :     desc->instance = li;
     262             : 
     263        2162 :     desc->alpha = isALPHA(src->fmt) && isALPHA(dst->fmt);
     264        2162 :     desc->src = src;
     265        2162 :     desc->dst = dst;
     266             : 
     267        2162 :     desc->process = &chr_h_scale;
     268             : 
     269        2162 :     return 0;
     270             : }
     271             : 
     272       26522 : static int no_chr_scale(SwsContext *c, SwsFilterDescriptor *desc, int sliceY, int sliceH)
     273             : {
     274       26522 :     desc->dst->plane[1].sliceY = sliceY + sliceH - desc->dst->plane[1].available_lines;
     275       26522 :     desc->dst->plane[1].sliceH = desc->dst->plane[1].available_lines;
     276       26522 :     desc->dst->plane[2].sliceY = sliceY + sliceH - desc->dst->plane[2].available_lines;
     277       26522 :     desc->dst->plane[2].sliceH = desc->dst->plane[2].available_lines;
     278       26522 :     return 0;
     279             : }
     280             : 
     281          85 : int ff_init_desc_no_chr(SwsFilterDescriptor *desc, SwsSlice * src, SwsSlice *dst)
     282             : {
     283          85 :     desc->src = src;
     284          85 :     desc->dst = dst;
     285          85 :     desc->alpha = 0;
     286          85 :     desc->instance = NULL;
     287          85 :     desc->process = &no_chr_scale;
     288          85 :     return 0;
     289             : }

Generated by: LCOV version 1.12