At the moment it's still incomplete, developement is continuing in the wiki page ( http://strites.altervista.org/wiki3/doku.php?id=generator )

Todo: possible other variants of rgb
give a sense to [inv_table, srcRange, brightness, contrast, saturation] arguments, which aren't actually used and I have no idea of how to use them.
Pro: the first 19 lines ^^'

I need someone to test this, to find possible bugs (seems flu returned to me and I can't guarantee that things I wrote aren't broken ^^')

--
Keiji Costantini
/*
 * Copyright (C) 2001-2003 Michael Niedermayer <[EMAIL PROTECTED]>
 *
 * This file is part of FFmpeg.
 *
 * FFmpeg is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * FFmpeg is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with FFmpeg; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include <math.h>
#include <stdint.h>
#include <stdlib.h>
#include "swscale_internal.h"

#define byteclamp(j)  do { if (j < 0) j = 0;else if (j > 255) j = 255; } while (0)

void gentable32(int/*?*/ v, uint32_t *r , uint32_t *g1, uint32_t *g2 , uint32_t *b)
{
    int i;
    int32_t tr, tg1, tg2, tb;

    tg2 = -((v-128)*71414 / 5^5 ) / 2^5;
    byteclamp(tg2);

    for (i=0;i<255;i++)
    {
        tr  = i + ((v-128)* 1402 / 5^3 ) / 2^3;
        tg1 = i - ((v-128)*34414 / 5^5 ) / 2^5;
        tb  = i + ((v-128)*1772  / 5^3 ) / 2^3;
        byteclamp(tr);
        byteclamp(tb);
        if ((tg1 + tg2) < 0)
            tg1 = -(tg2);
        else if ((tg1 + tg2) > 255)
            tg1 = 255 - tg2;
        r[i] = tr << 16;
        g1[i] = tg1 << 8;
        b[i] = tb;
    }
    *g2 = tg2 << 8;
}

/**
 * rgb565
 */
void gentable16(int/*?*/ v, uint16_t *r , uint16_t *g1, uint16_t *g2 , uint16_t *b)
{
    int i;
    int32_t tr, tg1, tg2, tb;
    tg2 = -((v-128)*71414 / 5^5 ) / 2^5;
    byteclamp(tg2);

    for (i=0;i<255;i++)
    {
        tr  = i + ((v-128)* 1402 / 5^3 ) / 2^3;
        tg1 = i - ((v-128)*34414 / 5^5 ) / 2^5;
        tb  = i + ((v-128)*1772  / 5^3 ) / 2^3;
        byteclamp(tr);
        byteclamp(tb);
        if ((tg1 + tg2) < 0)
            tg1 = -(tg2);
        else if ((tg1 + tg2) > 255)
            tg1 = 255 - tg2;

        tr  = tr >> 3;
        tg1 = tg1 >> 2;
        tb  = tb >> 3;

        *r  = tr << 11;
        *g1 = tg1 << 5;
        *b  = tb;

    }
    tg2 = tg2 >> 2;
    *g2 = tg2 << 5;
}

/**
 * rgb24
 */
void gentable24(int/*?*/ v, uint8_t *r , uint8_t *g1, uint8_t *g2 , uint8_t *b)
{
    int i;
    int32_t tr, tg1, tg2, tb;
    tg2 = -((v-128)*71414 / 5^5 ) / 2^5;
    byteclamp(tg2);

    for (i=0;i<255;i++)
    {
        tr  = i + ((v-128)* 1402 / 5^3 ) / 2^3;
        tg1 = i - ((v-128)*34414 / 5^5 ) / 2^5;
        tb  = i + ((v-128)*1772  / 5^3 ) / 2^3;
        byteclamp(tr);
        byteclamp(tb);
        if ((tg1 + tg2) < 0)
            tg1 = -(tg2);
        else if ((tg1 + tg2) > 255)
            tg1 = 255 - tg2;
        r[i] = tr;
        g1[i] = tg1;
        b[i] = tb;
    }
    *g2 = tg2;
}

/**
 * the infamus generator
 *
 * TODO: give a sense to inv_table, srcRange, brightness, contrast, saturation arguments (unused atm)
 */
void new_yuv2rgb_c_init_tables(SwsContext *c, inv_table, srcRange, brightness, contrast, saturation)
{

    int sizeDstPixel=fmt_depth(c->dstFormat);

    int y, u, v, h;

    if (sizeDstPixel == 32)
    {
        uint32_t *the_table = malloc((sizeof(uint32_t)*256*256)*3);
        uint32_t *r, *g1, *g2, *b;
        for (h=0; h<256;h++)
        {
            c->table_rV[h]= the_table[h];
            c->table_gU[h]= the_table[256+h];
            c->table_bU[h]= the_table[256*2+h];
        }
        for (u=0;u<256;u++)
        {
            r =&c->table_rV[u];
            g1=&c->table_gU[u];
            b =&c->table_bU[u];
            gentable32(u,r,g1,g2,b);
            c->table_gV[u]=g2;
        }
    } else if (sizeDstPixel == 16)
    {
        uint16_t *the_table = malloc((sizeof(uint16_t)*256*256)*3);
        uint16_t *r, *g1, *g2, *b;
        for (h=0; h<256;h++)
        {
            c->table_rV[h]= the_table[h];
            c->table_gU[h]= the_table[256+h];
            c->table_bU[h]= the_table[256*2+h];
        }
        for (u=0;u<256;u++)
        {
            r =&c->table_rV[u];
            g1=&c->table_gU[u];
            b =&c->table_bU[u];
            gentable16(u,r,g1,g2,b);
            c->table_gV[u]=g2;
        }
    } else if (sizeDstPixel == 24)
    {
        uint8_t *the_table = malloc((sizeof(uint8_t)*256*256)*3);
        uint8_t *r, *g1, *g2, *b;
        for (h=0; h<256;h++)
        {
            c->table_rV[h]= the_table[h];
            c->table_gU[h]= the_table[256+h];
            c->table_bU[h]= the_table[256*2+h];
        }
        for (u=0;u<256;u++)
        {
            r =&c->table_rV[u];
            g1=&c->table_gU[u];
            b =&c->table_bU[u];
            gentable24(u,r,g1,g2,b);
            c->table_gV[u]=g2;
        }
    }
}
_______________________________________________
FFmpeg-soc mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc

Reply via email to