⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 predict.c

📁 在dsp上实现h.264编解码
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************** * predict.c: h264 encoder ***************************************************************************** * Copyright (C) 2003 Laurent Aimar
 * $Id: SHU264.h,v 1.1 2006/02/03 19:24:12 fenrir Exp $
 *
 * Authors: jsslq <jsslq@163.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA. *****************************************************************************//* XXX predict4x4 are inspired from ffmpeg h264 decoder */#ifdef HAVE_STDINT_H#include <stdint.h>#else#include <inttypes.h>#endif#include <stdlib.h>#include <stdarg.h>#include "common.h"#ifdef _MSC_VER#undef HAVE_MMXEXT  /* not finished now */#endif#ifdef HAVE_MMXEXT#   include "i386/predict.h"#endifstatic inline int clip_uint8( int a ){    if (a&(~255))        return (-a)>>31;    else        return a;}/**************************************************************************** * 16x16 prediction for intra block DC, H, V, P ****************************************************************************/static void predict_16x16_dc( uint8_t *src, int i_stride ){    int dc = 0;    int i, j;    /* calculate DC value */    for( i = 0; i < 16; i++ )    {        dc += src[-1 + i * i_stride];        dc += src[i - i_stride];    }    dc = ( dc + 16 ) >> 5;    for( i = 0; i < 16; i++ )    {        for( j = 0; j < 16; j++ )        {            src[j] = dc;        }        src += i_stride;    }}static void predict_16x16_dc_left( uint8_t *src, int i_stride ){    int dc = 0;    int i,j;    for( i = 0; i < 16; i++ )    {        dc += src[-1 + i * i_stride];    }    dc = ( dc + 8 ) >> 4;    for( i = 0; i < 16; i++ )    {        for( j = 0; j < 16; j++ )        {            src[j] = dc;        }        src += i_stride;    }}static void predict_16x16_dc_top( uint8_t *src, int i_stride ){    int dc = 0;    int i,j;    for( i = 0; i < 16; i++ )    {        dc += src[i - i_stride];    }    dc = ( dc + 8 ) >> 4;    for( i = 0; i < 16; i++ )    {        for( j = 0; j < 16; j++ )        {            src[j] = dc;        }        src += i_stride;    }}static void predict_16x16_dc_128( uint8_t *src, int i_stride ){    int i,j;    for( i = 0; i < 16; i++ )    {        for( j = 0; j < 16; j++ )        {            src[j] = 128;        }        src += i_stride;    }}static void predict_16x16_h( uint8_t *src, int i_stride ){    int i,j;    for( i = 0; i < 16; i++ )    {        uint8_t v;        v = src[-1];        for( j = 0; j < 16; j++ )        {            src[j] = v;        }        src += i_stride;    }}static void predict_16x16_v( uint8_t *src, int i_stride ){    int i,j;    for( i = 0; i < 16; i++ )    {        for( j = 0; j < 16; j++ )        {            src[i * i_stride +j] = src[j - i_stride];        }    }}static void predict_16x16_p( uint8_t *src, int i_stride ){    int x, y, i;    int a, b, c;    int H = 0;    int V = 0;    int i00;    /* calcule H and V */    for( i = 0; i <= 7; i++ )    {        H += ( i + 1 ) * ( src[ 8 + i - i_stride ] - src[6 -i -i_stride] );        V += ( i + 1 ) * ( src[-1 + (8+i)*i_stride] - src[-1 + (6-i)*i_stride] );    }    a = 16 * ( src[-1 + 15*i_stride] + src[15 - i_stride] );    b = ( 5 * H + 32 ) >> 6;    c = ( 5 * V + 32 ) >> 6;    i00 = a - b * 7 - c * 7 + 16;    for( y = 0; y < 16; y++ )    {        for( x = 0; x < 16; x++ )        {            int pix;            pix = (i00+b*x)>>5;            src[x] = clip_uint8( pix );        }        src += i_stride;        i00 += c;    }}/**************************************************************************** * 8x8 prediction for intra chroma block DC, H, V, P ****************************************************************************/static void predict_8x8c_dc_128( uint8_t *src, int i_stride ){    int x,y;    for( y = 0; y < 8; y++ )    {        for( x = 0; x < 8; x++ )        {            src[x] = 128;        }        src += i_stride;    }}static void predict_8x8c_dc_left( uint8_t *src, int i_stride ){    int x,y;    int dc0 = 0, dc1 = 0;    for( y = 0; y < 4; y++ )    {        dc0 += src[y * i_stride     - 1];        dc1 += src[(y+4) * i_stride - 1];    }    dc0 = ( dc0 + 2 ) >> 2;    dc1 = ( dc1 + 2 ) >> 2;    for( y = 0; y < 4; y++ )    {        for( x = 0; x < 8; x++ )        {            src[           x] = dc0;            src[4*i_stride+x] = dc1;        }        src += i_stride;    }}static void predict_8x8c_dc_top( uint8_t *src, int i_stride ){    int x,y;    int dc0 = 0, dc1 = 0;    for( x = 0; x < 4; x++ )    {        dc0 += src[x     - i_stride];        dc1 += src[x + 4 - i_stride];    }    dc0 = ( dc0 + 2 ) >> 2;    dc1 = ( dc1 + 2 ) >> 2;    for( y = 0; y < 8; y++ )    {        for( x = 0; x < 4; x++ )        {            src[x    ] = dc0;            src[x + 4] = dc1;        }        src += i_stride;    }}static void predict_8x8c_dc( uint8_t *src, int i_stride ){    int x,y;    int s0 = 0, s1 = 0, s2 = 0, s3 = 0;    int dc0, dc1, dc2, dc3;    int i;    /* First do :          s0 s1       s2       s3    */    for( i = 0; i < 4; i++ )    {        s0 += src[i - i_stride];        s1 += src[i + 4 - i_stride];        s2 += src[-1 + i * i_stride];        s3 += src[-1 + (i+4)*i_stride];    }    /* now calculate       dc0 dc1       dc2 dc3     */    dc0 = ( s0 + s2 + 4 ) >> 3;    dc1 = ( s1 + 2 ) >> 2;    dc2 = ( s3 + 2 ) >> 2;    dc3 = ( s1 + s3 + 4 ) >> 3;    for( y = 0; y < 4; y++ )    {        for( x = 0; x < 4; x++ )        {            src[             x    ] = dc0;            src[             x + 4] = dc1;            src[4*i_stride + x    ] = dc2;            src[4*i_stride + x + 4] = dc3;        }        src += i_stride;    }}static void predict_8x8c_h( uint8_t *src, int i_stride ){    int i,j;    for( i = 0; i < 8; i++ )    {        uint8_t v;        v = src[-1];        for( j = 0; j < 8; j++ )        {            src[j] = v;        }        src += i_stride;    }}static void predict_8x8c_v( uint8_t *src, int i_stride ){    int i,j;    for( i = 0; i < 8; i++ )    {        for( j = 0; j < 8; j++ )        {            src[i * i_stride +j] = src[j - i_stride];        }    }}static void predict_8x8c_p( uint8_t *src, int i_stride ){    int i;    int x,y;    int a, b, c;    int H = 0;    int V = 0;    int i00;    for( i = 0; i < 4; i++ )    {        H += ( i + 1 ) * ( src[4+i - i_stride] - src[2 - i -i_stride] );        V += ( i + 1 ) * ( src[-1 +(i+4)*i_stride] - src[-1+(2-i)*i_stride] );    }    a = 16 * ( src[-1+7*i_stride] + src[7 - i_stride] );    b = ( 17 * H + 16 ) >> 5;    c = ( 17 * V + 16 ) >> 5;    i00 = a -3*b -3*c + 16;    for( y = 0; y < 8; y++ )    {        for( x = 0; x < 8; x++ )        {            int pix;            pix = (i00 +b*x) >> 5;            src[x] = clip_uint8( pix );        }        src += i_stride;        i00 += c;    }}/**************************************************************************** * 4x4 prediction for intra luma block ****************************************************************************/static void predict_4x4_dc_128( uint8_t *src, int i_stride ){    int x,y;    for( y = 0; y < 4; y++ )    {        for( x = 0; x < 4; x++ )        {            src[x] = 128;        }        src += i_stride;    }}static void predict_4x4_dc_left( uint8_t *src, int i_stride ){    int x,y;    int dc = ( src[-1+0*i_stride] + src[-1+i_stride]+               src[-1+2*i_stride] + src[-1+3*i_stride] + 2 ) >> 2;    for( y = 0; y < 4; y++ )    {        for( x = 0; x < 4; x++ )        {            src[x] = dc;        }        src += i_stride;    }}static void predict_4x4_dc_top( uint8_t *src, int i_stride ){    int x,y;    int dc = ( src[0 - i_stride] + src[1 - i_stride] +               src[2 - i_stride] + src[3 - i_stride] + 2 ) >> 2;    for( y = 0; y < 4; y++ )    {        for( x = 0; x < 4; x++ )        {            src[x] = dc;        }        src += i_stride;    }}static void predict_4x4_dc( uint8_t *src, int i_stride ){    int x,y;    int dc = ( src[-1+0*i_stride] + src[-1+i_stride]+               src[-1+2*i_stride] + src[-1+3*i_stride] +               src[0 - i_stride]  + src[1 - i_stride] +               src[2 - i_stride]  + src[3 - i_stride] + 4 ) >> 3;    for( y = 0; y < 4; y++ )    {        for( x = 0; x < 4; x++ )        {            src[x] = dc;        }        src += i_stride;    }}static void predict_4x4_h( uint8_t *src, int i_stride ){    int i,j;    for( i = 0; i < 4; i++ )    {        uint8_t v;        v = src[-1];        for( j = 0; j < 4; j++ )        {            src[j] = v;        }        src += i_stride;    }}static void predict_4x4_v( uint8_t *src, int i_stride ){    int i,j;    for( i = 0; i < 4; i++ )    {        for( j = 0; j < 4; j++ )        {            src[i * i_stride +j] = src[j - i_stride];        }    }}#define PREDICT_4x4_LOAD_LEFT \    const int l0 = src[-1+0*i_stride];   \    const int l1 = src[-1+1*i_stride];   \    const int l2 = src[-1+2*i_stride];   \    const int l3 = src[-1+3*i_stride];#define PREDICT_4x4_LOAD_TOP \    const int t0 = src[0-1*i_stride];   \    const int t1 = src[1-1*i_stride];   \    const int t2 = src[2-1*i_stride];   \    const int t3 = src[3-1*i_stride];#define PREDICT_4x4_LOAD_TOP_RIGHT \    const int t4 = src[4-1*i_stride];   \    const int t5 = src[5-1*i_stride];   \    const int t6 = src[6-1*i_stride];   \    const int t7 = src[7-1*i_stride];static void predict_4x4_ddl( uint8_t *src, int i_stride ){    PREDICT_4x4_LOAD_TOP    PREDICT_4x4_LOAD_TOP_RIGHT    src[0*i_stride+0] = ( t0 + 2*t1+ t2 + 2 ) >> 2;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -