/*1* Copyright (C) 2015 Pedro Arthur <[email protected]>2*3* This file is part of FFmpeg.4*5* FFmpeg is free software; you can redistribute it and/or6* modify it under the terms of the GNU Lesser General Public7* License as published by the Free Software Foundation; either8* version 2.1 of the License, or (at your option) any later version.9*10* FFmpeg is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU13* Lesser General Public License for more details.14*15* You should have received a copy of the GNU Lesser General Public16* License along with FFmpeg; if not, write to the Free Software17* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA18*/1920#include "swscale_internal.h"2122typedef struct GammaContext23{24uint16_t *table;25} GammaContext;2627// gamma_convert expects 16 bit rgb format28// it writes directly in src slice thus it must be modifiable (done through cascade context)29static int gamma_convert(SwsContext *c, SwsFilterDescriptor *desc, int sliceY, int sliceH)30{31GammaContext *instance = desc->instance;32uint16_t *table = instance->table;33int srcW = desc->src->width;3435int i;36for (i = 0; i < sliceH; ++i) {37uint8_t ** src = desc->src->plane[0].line;38int src_pos = sliceY+i - desc->src->plane[0].sliceY;3940uint16_t *src1 = (uint16_t*)*(src+src_pos);41int j;42for (j = 0; j < srcW; ++j) {43uint16_t r = AV_RL16(src1 + j*4 + 0);44uint16_t g = AV_RL16(src1 + j*4 + 1);45uint16_t b = AV_RL16(src1 + j*4 + 2);4647AV_WL16(src1 + j*4 + 0, table[r]);48AV_WL16(src1 + j*4 + 1, table[g]);49AV_WL16(src1 + j*4 + 2, table[b]);50}5152}53return sliceH;54}555657int ff_init_gamma_convert(SwsFilterDescriptor *desc, SwsSlice * src, uint16_t *table)58{59GammaContext *li = av_malloc(sizeof(GammaContext));60if (!li)61return AVERROR(ENOMEM);62li->table = table;6364desc->instance = li;65desc->src = src;66desc->dst = NULL;67desc->process = &gamma_convert;6869return 0;70}71727374