LCOV - code coverage report
Current view: top level - libswscale - hscale.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 155 162 95.7 %
Date: 2017-10-24 00:14:43 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     1360519 : static int lum_h_scale(SwsContext *c, SwsFilterDescriptor *desc, int sliceY, int sliceH)
      39             : {
      40     1360519 :     FilterContext *instance = desc->instance;
      41     1360519 :     int srcW = desc->src->width;
      42     1360519 :     int dstW = desc->dst->width;
      43     1360519 :     int xInc = instance->xInc;
      44             : 
      45             :     int i;
      46     9046786 :     for (i = 0; i < sliceH; ++i) {
      47     7686267 :         uint8_t ** src = desc->src->plane[0].line;
      48     7686267 :         uint8_t ** dst = desc->dst->plane[0].line;
      49     7686267 :         int src_pos = sliceY+i - desc->src->plane[0].sliceY;
      50     7686267 :         int dst_pos = sliceY+i - desc->dst->plane[0].sliceY;
      51             : 
      52             : 
      53     7686267 :         if (c->hyscale_fast) {
      54           0 :             c->hyscale_fast(c, (int16_t*)dst[dst_pos], dstW, src[src_pos], srcW, xInc);
      55             :         } else {
      56    15372534 :             c->hyScale(c, (int16_t*)dst[dst_pos], dstW, (const uint8_t *)src[src_pos], instance->filter,
      57     7686267 :                        instance->filter_pos, instance->filter_size);
      58             :         }
      59             : 
      60     7686267 :         if (c->lumConvertRange)
      61      967605 :             c->lumConvertRange((int16_t*)dst[dst_pos], dstW);
      62             : 
      63     7686267 :         desc->dst->plane[0].sliceH += 1;
      64             : 
      65     7686267 :         if (desc->alpha) {
      66      178694 :             src = desc->src->plane[3].line;
      67      178694 :             dst = desc->dst->plane[3].line;
      68             : 
      69      178694 :             src_pos = sliceY+i - desc->src->plane[3].sliceY;
      70      178694 :             dst_pos = sliceY+i - desc->dst->plane[3].sliceY;
      71             : 
      72      178694 :             desc->dst->plane[3].sliceH += 1;
      73             : 
      74      178694 :             if (c->hyscale_fast) {
      75           0 :                 c->hyscale_fast(c, (int16_t*)dst[dst_pos], dstW, src[src_pos], srcW, xInc);
      76             :             } else {
      77      357388 :                 c->hyScale(c, (int16_t*)dst[dst_pos], dstW, (const uint8_t *)src[src_pos], instance->filter,
      78      178694 :                             instance->filter_pos, instance->filter_size);
      79             :             }
      80             :         }
      81             :     }
      82             : 
      83     1360519 :     return sliceH;
      84             : }
      85             : 
      86      246364 : static int lum_convert(SwsContext *c, SwsFilterDescriptor *desc, int sliceY, int sliceH)
      87             : {
      88      246364 :     int srcW = desc->src->width;
      89      246364 :     ColorContext * instance = desc->instance;
      90      246364 :     uint32_t * pal = instance->pal;
      91             :     int i;
      92             : 
      93      246364 :     desc->dst->plane[0].sliceY = sliceY;
      94      246364 :     desc->dst->plane[0].sliceH = sliceH;
      95      246364 :     desc->dst->plane[3].sliceY = sliceY;
      96      246364 :     desc->dst->plane[3].sliceH = sliceH;
      97             : 
      98     1708666 :     for (i = 0; i < sliceH; ++i) {
      99     1462302 :         int sp0 = sliceY+i - desc->src->plane[0].sliceY;
     100     1462302 :         int sp1 = ((sliceY+i) >> desc->src->v_chr_sub_sample) - desc->src->plane[1].sliceY;
     101     5849208 :         const uint8_t * src[4] = { desc->src->plane[0].line[sp0],
     102     1462302 :                         desc->src->plane[1].line[sp1],
     103     1462302 :                         desc->src->plane[2].line[sp1],
     104     1462302 :                         desc->src->plane[3].line[sp0]};
     105     1462302 :         uint8_t * dst = desc->dst->plane[0].line[i];
     106             : 
     107     1462302 :         if (c->lumToYV12) {
     108     1411114 :             c->lumToYV12(dst, src[0], src[1], src[2], srcW, pal);
     109       51188 :         } else if (c->readLumPlanar) {
     110       51188 :             c->readLumPlanar(dst, src, srcW, c->input_rgb2yuv_table);
     111             :         }
     112             : 
     113             : 
     114     1462302 :         if (desc->alpha) {
     115      175238 :             dst = desc->dst->plane[3].line[i];
     116      175238 :             if (c->alpToYV12) {
     117      173042 :                 c->alpToYV12(dst, src[3], src[1], src[2], srcW, pal);
     118        2196 :             } else if (c->readAlpPlanar) {
     119        2196 :                 c->readAlpPlanar(dst, src, srcW, NULL);
     120             :             }
     121             :         }
     122             :     }
     123             : 
     124      246364 :     return sliceH;
     125             : }
     126             : 
     127         242 : int ff_init_desc_fmt_convert(SwsFilterDescriptor *desc, SwsSlice * src, SwsSlice *dst, uint32_t *pal)
     128             : {
     129         242 :     ColorContext * li = av_malloc(sizeof(ColorContext));
     130         242 :     if (!li)
     131           0 :         return AVERROR(ENOMEM);
     132         242 :     li->pal = pal;
     133         242 :     desc->instance = li;
     134             : 
     135         242 :     desc->alpha = isALPHA(src->fmt) && isALPHA(dst->fmt);
     136         242 :     desc->src =src;
     137         242 :     desc->dst = dst;
     138         242 :     desc->process = &lum_convert;
     139             : 
     140         242 :     return 0;
     141             : }
     142             : 
     143             : 
     144        2406 : int ff_init_desc_hscale(SwsFilterDescriptor *desc, SwsSlice *src, SwsSlice *dst, uint16_t *filter, int * filter_pos, int filter_size, int xInc)
     145             : {
     146        2406 :     FilterContext *li = av_malloc(sizeof(FilterContext));
     147        2406 :     if (!li)
     148           0 :         return AVERROR(ENOMEM);
     149             : 
     150        2406 :     li->filter = filter;
     151        2406 :     li->filter_pos = filter_pos;
     152        2406 :     li->filter_size = filter_size;
     153        2406 :     li->xInc = xInc;
     154             : 
     155        2406 :     desc->instance = li;
     156             : 
     157        2406 :     desc->alpha = isALPHA(src->fmt) && isALPHA(dst->fmt);
     158        2406 :     desc->src = src;
     159        2406 :     desc->dst = dst;
     160             : 
     161        2406 :     desc->process = &lum_h_scale;
     162             : 
     163        2406 :     return 0;
     164             : }
     165             : 
     166     1061719 : static int chr_h_scale(SwsContext *c, SwsFilterDescriptor *desc, int sliceY, int sliceH)
     167             : {
     168     1061719 :     FilterContext *instance = desc->instance;
     169     1061719 :     int srcW = AV_CEIL_RSHIFT(desc->src->width, desc->src->h_chr_sub_sample);
     170     1061719 :     int dstW = AV_CEIL_RSHIFT(desc->dst->width, desc->dst->h_chr_sub_sample);
     171     1061719 :     int xInc = instance->xInc;
     172             : 
     173     1061719 :     uint8_t ** src1 = desc->src->plane[1].line;
     174     1061719 :     uint8_t ** dst1 = desc->dst->plane[1].line;
     175     1061719 :     uint8_t ** src2 = desc->src->plane[2].line;
     176     1061719 :     uint8_t ** dst2 = desc->dst->plane[2].line;
     177             : 
     178     1061719 :     int src_pos1 = sliceY - desc->src->plane[1].sliceY;
     179     1061719 :     int dst_pos1 = sliceY - desc->dst->plane[1].sliceY;
     180             : 
     181     1061719 :     int src_pos2 = sliceY - desc->src->plane[2].sliceY;
     182     1061719 :     int dst_pos2 = sliceY - desc->dst->plane[2].sliceY;
     183             : 
     184             :     int i;
     185     5952636 :     for (i = 0; i < sliceH; ++i) {
     186     4890917 :         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     4890917 :             c->hcScale(c, (uint16_t*)dst1[dst_pos1+i], dstW, src1[src_pos1+i], instance->filter, instance->filter_pos, instance->filter_size);
     190     4890917 :             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     4890917 :         if (c->chrConvertRange)
     194      415912 :             c->chrConvertRange((uint16_t*)dst1[dst_pos1+i], (uint16_t*)dst2[dst_pos2+i], dstW);
     195             : 
     196     4890917 :         desc->dst->plane[1].sliceH += 1;
     197     4890917 :         desc->dst->plane[2].sliceH += 1;
     198             :     }
     199     1061719 :     return sliceH;
     200             : }
     201             : 
     202      309572 : static int chr_convert(SwsContext *c, SwsFilterDescriptor *desc, int sliceY, int sliceH)
     203             : {
     204      309572 :     int srcW = AV_CEIL_RSHIFT(desc->src->width, desc->src->h_chr_sub_sample);
     205      309572 :     ColorContext * instance = desc->instance;
     206      309572 :     uint32_t * pal = instance->pal;
     207             : 
     208      309572 :     int sp0 = (sliceY - (desc->src->plane[0].sliceY >> desc->src->v_chr_sub_sample)) << desc->src->v_chr_sub_sample;
     209      309572 :     int sp1 = sliceY - desc->src->plane[1].sliceY;
     210             : 
     211             :     int i;
     212             : 
     213      309572 :     desc->dst->plane[1].sliceY = sliceY;
     214      309572 :     desc->dst->plane[1].sliceH = sliceH;
     215      309572 :     desc->dst->plane[2].sliceY = sliceY;
     216      309572 :     desc->dst->plane[2].sliceH = sliceH;
     217             : 
     218     1665924 :     for (i = 0; i < sliceH; ++i) {
     219     5425408 :         const uint8_t * src[4] = { desc->src->plane[0].line[sp0+i],
     220     1356352 :                         desc->src->plane[1].line[sp1+i],
     221     1356352 :                         desc->src->plane[2].line[sp1+i],
     222     1356352 :                         desc->src->plane[3].line[sp0+i]};
     223             : 
     224     1356352 :         uint8_t * dst1 = desc->dst->plane[1].line[i];
     225     1356352 :         uint8_t * dst2 = desc->dst->plane[2].line[i];
     226     1356352 :         if (c->chrToYV12) {
     227     1327614 :             c->chrToYV12(dst1, dst2, src[0], src[1], src[2], srcW, pal);
     228       28738 :         } else if (c->readChrPlanar) {
     229       28738 :             c->readChrPlanar(dst1, dst2, src, srcW, c->input_rgb2yuv_table);
     230             :         }
     231             :     }
     232      309572 :     return sliceH;
     233             : }
     234             : 
     235         225 : int ff_init_desc_cfmt_convert(SwsFilterDescriptor *desc, SwsSlice * src, SwsSlice *dst, uint32_t *pal)
     236             : {
     237         225 :     ColorContext * li = av_malloc(sizeof(ColorContext));
     238         225 :     if (!li)
     239           0 :         return AVERROR(ENOMEM);
     240         225 :     li->pal = pal;
     241         225 :     desc->instance = li;
     242             : 
     243         225 :     desc->src =src;
     244         225 :     desc->dst = dst;
     245         225 :     desc->process = &chr_convert;
     246             : 
     247         225 :     return 0;
     248             : }
     249             : 
     250        2250 : int ff_init_desc_chscale(SwsFilterDescriptor *desc, SwsSlice *src, SwsSlice *dst, uint16_t *filter, int * filter_pos, int filter_size, int xInc)
     251             : {
     252        2250 :     FilterContext *li = av_malloc(sizeof(FilterContext));
     253        2250 :     if (!li)
     254           0 :         return AVERROR(ENOMEM);
     255             : 
     256        2250 :     li->filter = filter;
     257        2250 :     li->filter_pos = filter_pos;
     258        2250 :     li->filter_size = filter_size;
     259        2250 :     li->xInc = xInc;
     260             : 
     261        2250 :     desc->instance = li;
     262             : 
     263        2250 :     desc->alpha = isALPHA(src->fmt) && isALPHA(dst->fmt);
     264        2250 :     desc->src = src;
     265        2250 :     desc->dst = dst;
     266             : 
     267        2250 :     desc->process = &chr_h_scale;
     268             : 
     269        2250 :     return 0;
     270             : }
     271             : 
     272       32237 : static int no_chr_scale(SwsContext *c, SwsFilterDescriptor *desc, int sliceY, int sliceH)
     273             : {
     274       32237 :     desc->dst->plane[1].sliceY = sliceY + sliceH - desc->dst->plane[1].available_lines;
     275       32237 :     desc->dst->plane[1].sliceH = desc->dst->plane[1].available_lines;
     276       32237 :     desc->dst->plane[2].sliceY = sliceY + sliceH - desc->dst->plane[2].available_lines;
     277       32237 :     desc->dst->plane[2].sliceH = desc->dst->plane[2].available_lines;
     278       32237 :     return 0;
     279             : }
     280             : 
     281         156 : int ff_init_desc_no_chr(SwsFilterDescriptor *desc, SwsSlice * src, SwsSlice *dst)
     282             : {
     283         156 :     desc->src = src;
     284         156 :     desc->dst = dst;
     285         156 :     desc->alpha = 0;
     286         156 :     desc->instance = NULL;
     287         156 :     desc->process = &no_chr_scale;
     288         156 :     return 0;
     289             : }

Generated by: LCOV version 1.13