Michael Niedermayer ha scritto:
On Mon, Aug 18, 2008 at 08:58:12PM +0200, Keiji Costantini wrote:
this should be the last post I make today (flu & headache are taking me to sleep)

for the moment the rgb24 conversion passed swscale-example.
tomorrow I shall work on the 32 and 16 bits too.
Good night everyone
[...]
/**
 * rgb24
 */
void gentable24(int srcRange, int/*?*/ v, uint8_t *r , uint8_t *g1, uint8_t *g2 
, uint8_t *b)
{
    int i, n, m;
    int32_t tr, tg1, tg2, tb;

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

I do not belive that this works, '^' is the bitwise xor operator in C and
not exponentiation.

corrected truely this time - sorry for the double post
--
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 <stdio.h>
#include "swscale_internal.h"

#define byteclamp(j)  do { if (j < 0) j = 0;else if (j > 255) j = 255; } while (0)
 
 
/**
 * function to generate int32_t rgbs, which are converted in the
 * gentable* functions
 */
inline void gentable(int srcRange, int i, int v, int32_t *tr, int32_t *tg1, int32_t tg2, int32_t *tb)
{
    *tr  = i + ((v-128)* 1402 / 1000);
    *tg1 = i - ((v-128)*34414 / 100000);
    *tb  = i + ((v-128)*1772  / 1000);
    byteclamp(*tr);
    byteclamp(*tb);
    if ((*tg1 + tg2) < 0)
        *tg1 = -(tg2);
    else if ((*tg1 + tg2) > 255)
        *tg1 = 255 - tg2;
}
 
/**
 * uses above formulas without floating points (tries) to convert
 * from generic(?) yuv to rgb32
 */
void gentable32(int srcRange, int/*?*/ v, uint32_t *r , uint32_t *g1, uint32_t *g2 , uint32_t *b)
{
    int i, n, m;
    int32_t tr, tg1, tg2, tb;
    if (srcRange)
    {
        n=16;
        m=235;
    } else
    {
        n=0;
        m=255;
    }

    tg2 = -((v-128)*71414 / 100000 );
    byteclamp(tg2);

    for (i=n;i<m;i++)
    {
        gentable(srcRange, i, v, &tr, &tg1, tg2, &tb);

        r[i] = tr << 16;
        g1[i] = tg1 << 8;
        b[i] = tb;
    }
    *g2 = tg2 << 8;
}

/**
 * rgb565
 */
void gentable16(int srcRange, int/*?*/ v, uint16_t *r , uint16_t *g1, uint16_t *g2 , uint16_t *b)
{
    int i, n, m;
    int32_t tr, tg1, tg2, tb;
    tg2 = -((v-128)*71414 / 100000);
    byteclamp(tg2);
    if (srcRange)
    {
        n=16;
        m=235;
    } else
    {
        n=0;
        m=255;
    }

    for (i=n;i<m;i++)
    {
        gentable(srcRange, i, v, &tr, &tg1, tg2, &tb);

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

        r[i]  = tr << 11;
        g1[i] = tg1 << 5;
        b[i]  = tb;

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

/**
 * rgb24
 */
void gentable24(int srcRange, int/*?*/ v, uint8_t *r , uint8_t *g1, uint8_t *g2 , uint8_t *b)
{
    int i, n, m;
    int32_t tr, tg1, tg2, tb;
    tg2 = -((v-128)*71414 / 100000 );
    byteclamp(tg2);
    if (srcRange)
    {
        n=16;
        m=235;
    } else
    {
        n=0;
        m=255;
    }

    for (i=n;i<m;i++)
    {
        gentable(srcRange, i, v, &tr, &tg1, tg2, &tb);

        r[i] = tr;
        g1[i] = tg1;
        b[i] = tb;
    }
    *g2 = tg2;
}

/**
 * rgb15
 */
void gentable15(int srcRange, int/*?*/ v, uint16_t *r , uint16_t *g1, uint16_t *g2 , uint16_t *b)
{
    int i, n, m;
    int32_t tr, tg1, tg2, tb;
    tg2 = -((v-128)*71414 / 100000 );
    byteclamp(tg2);
    if (srcRange)
    {
        n=16;
        m=235;
    } else
    {
        n=0;
        m=255;
    }

    for (i=n;i<m;i++)
    {
        gentable(srcRange, i, v, &tr, &tg1, tg2, &tb);

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

        r[i]  = tr << 10;
        g1[i] = tg1 << 5;
        b[i]  = tb;

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

/**
 * Generator - take things up and put here (dovrebbe?)
 *
 * in tal caso per sceglie quale formula di conversione usare, dovrebbe usare c->src/dstFormat
 */
void new_yuv2rgb_c_init_tables(SwsContext *c, int inv_table[4], int srcRange, int brightness, int contrast, int saturation)
{
    int sizeDstPixel=fmt_depth(c->dstFormat);

    int u, h;

    if (sizeDstPixel == 32)
    {
        uint32_t *the_table = av_malloc((sizeof(uint32_t)*256*256)*3);
        uint32_t *r, *g1, g2, *b;
        for (h=0; h<255;h++)
        {
            //printf("h = %d\n",h);
            c->table_rV[h]= (uint8_t*) &the_table[h];
            c->table_gU[h]= (uint8_t*) &the_table[256+h];
            c->table_bU[h]= (uint8_t*) &the_table[256*2+h];
        }
        for (u=0;u<255;u++)
        {
            r = (uint32_t*) &c->table_rV[u]; //this may (or may not) work?
            g1= (uint32_t*) &c->table_gU[u];
            b = (uint32_t*) &c->table_bU[u];
            gentable32(srcRange,u,r,g1,&g2,b);
            c->table_gV[u]=g2;
        }
    } else if (sizeDstPixel == 16)
    {
        /*
         * copy of the above, using uint16_t instead 32.
         * Conv function should be different too probably :/
         */
        uint16_t *the_table = av_malloc((sizeof(uint16_t)*256*256)*3);
        uint16_t *r, *g1, g2, *b;
//        av_log(c, AV_LOG_INFO, "table init\n");
        for (u=0;u<255;u++)
        {
 //           av_log(c, AV_LOG_INFO, "u = %d\n",u);
            r = (uint16_t*) &c->table_rV[u]; //this may (or may not) work?
            g1= (uint16_t*) &c->table_gU[u];
            b = (uint16_t*) &c->table_bU[u];
            gentable16(srcRange,u,r,g1,&g2,b);
            c->table_gV[u]=g2;
 //           av_log(c, AV_LOG_INFO, "size %d %d\n",sizeof(r), sizeof(c->table_rV[u]));
        }
        for (h=0; h<255;h++)
        {
            //printf("h = %d\n",h);
            c->table_rV[h]= (uint8_t*) &the_table[h];
            c->table_gU[h]= (uint8_t*) &the_table[256+h];
            c->table_bU[h]= (uint8_t*) &the_table[256*2+h];
        }
 //       av_log(c, AV_LOG_INFO, "table inited\n");
    } else if (sizeDstPixel == 24)
    {
        /*
         * seems like above, but with uint8_t and not sum of colors
         */
        uint8_t *the_table = av_malloc((sizeof(uint8_t)*256*256)*3);
        uint8_t *r, *g1, g2, *b;

        for (h=0; h<255;h++)
        {
            //printf("h = %d\n",h);
            c->table_rV[h]= (uint8_t*) &the_table[h];
            c->table_gU[h]= (uint8_t*) &the_table[256+h];
            c->table_bU[h]= (uint8_t*) &the_table[256*2+h];
        }
        for (u=0;u<255;u++)
        {
            r = &the_table[+u]; //this may (or may not) work?
            g1= &the_table[256+u];
            b = &the_table[256*2+u];
            gentable24(srcRange,u,r,g1,&g2,b);
            c->table_gV[u]=g2;
        }
    } else if (sizeDstPixel == 15)
    {
        uint16_t *the_table = av_malloc((sizeof(uint16_t)*256*256)*3);
        uint16_t *r, *g1, g2, *b;
        for (h=0; h<255;h++)
        {
            //printf("h = %d\n",h);
            c->table_rV[h]= (uint8_t*) &the_table[h];
            c->table_gU[h]= (uint8_t*) &the_table[256+h];
            c->table_bU[h]= (uint8_t*) &the_table[256*2+h];
        }
        for (u=0;u<255;u++)
        {
            r = &the_table[+u]; //this may (or may not) work?
            g1= &the_table[256+u];
            b = &the_table[256*2+u];
            gentable15(srcRange,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