青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

牽著老婆滿街逛

嚴(yán)以律己,寬以待人. 三思而后行.
GMail/GTalk: yanglinbo#google.com;
MSN/Email: tx7do#yahoo.com.cn;
QQ: 3 0 3 3 9 6 9 2 0 .

RGB24 轉(zhuǎn)換為 YUV12 的算法

頭文件:
#ifndef __rgb_2yuv_h__
#define __rgb_2yuv_h__

#ifdef __cplusplus
extern "C" 
{
#endif 

int RGB2YUV (int x_dim, int y_dim, void* bmp, void* y_out, void* u_out, void* v_out, int flip);

#ifdef __cplusplus
}

#endif


#endif

實(shí)現(xiàn)文件:
/**************************************************************************
*                                                                        *
* This code is developed by Adam Li.  This software is an                *
* implementation of a part of one or more MPEG-4 Video tools as          *
* specified in ISO/IEC 14496-2 standard.  Those intending to use this    *
* software module in hardware or software products are advised that its  *
* use may infringe existing patents or copyrights, and any such use      *
* would be at such party's own risk.  The original developer of this     *
* software module and his/her company, and subsequent editors and their  *
* companies (including Project Mayo), will have no liability for use of  *
* this software or modifications or derivatives thereof.                 *
*                                                                        *
* Project Mayo gives users of the Codec a license to this software       *
* module or modifications thereof for use in hardware or software        *
* products claiming conformance to the MPEG-4 Video Standard as          *
* described in the Open DivX license.                                    *
*                                                                        *
* The complete Open DivX license can be found at                         *
http://www.projectmayo.com/opendivx/license.php .                      *
*                                                                        *
*************************************************************************
*/


/**************************************************************************
*
*  rgb2yuv.c, 24-bit RGB bitmap to YUV converter
*
*  Copyright (C) 2001  Project Mayo
*
*  Adam Li
*
*  DivX Advance Research Center <darc@projectmayo.com>
*
*************************************************************************
*/


/* This file contains RGB to YUV transformation functions.                */

#include 
"stdlib.h"
#include 
"rgb2yuv.h"

static float RGBYUV02990[256], RGBYUV05870[256], RGBYUV01140[256];
static float RGBYUV01684[256], RGBYUV03316[256];
static float RGBYUV04187[256], RGBYUV00813[256];

void InitLookupTable();

/************************************************************************
*
*  int RGB2YUV (int x_dim, int y_dim, void *bmp, YUV *yuv)
*
*    Purpose :    It takes a 24-bit RGB bitmap and convert it into
*                YUV (4:2:0) format
*
*  Input :        x_dim    the x dimension of the bitmap
*                y_dim    the y dimension of the bitmap
*                bmp        pointer to the buffer of the bitmap
*                yuv        pointer to the YUV structure
*
*  Output :    0        OK
*                1        wrong dimension
*                2        memory allocation error
*
*    Side Effect :
*                None
*
*    Date :        09/28/2000
*
*  Contacts:
*
*  Adam Li
*
*  DivX Advance Research Center <darc@projectmayo.com>
*
***********************************************************************
*/


int RGB2YUV (int x_dim, int y_dim, void *bmp, void *y_out, void *u_out, void *v_out, int flip)
{
    
static int init_done = 0;

    
long i, j, size;
    unsigned 
char *r, *g, *b;
    unsigned 
char *y, *u, *v;
    unsigned 
char *pu1, *pu2, *pv1, *pv2, *psu, *psv;
    unsigned 
char *y_buffer, *u_buffer, *v_buffer;
    unsigned 
char *sub_u_buf, *sub_v_buf;

    
if (init_done == 0)
    
{
        InitLookupTable();
        init_done 
= 1;
    }


    
// check to see if x_dim and y_dim are divisible by 2
    if ((x_dim % 2|| (y_dim % 2)) return 1;
    size 
= x_dim * y_dim;

    
// allocate memory
    y_buffer = (unsigned char *)y_out;
    sub_u_buf 
= (unsigned char *)u_out;
    sub_v_buf 
= (unsigned char *)v_out;
    u_buffer 
= (unsigned char *)malloc(size * sizeof(unsigned char));
    v_buffer 
= (unsigned char *)malloc(size * sizeof(unsigned char));
    
if (!(u_buffer && v_buffer))
    
{
        
if (u_buffer) free(u_buffer);
        
if (v_buffer) free(v_buffer);
        
return 2;
    }


    b 
= (unsigned char *)bmp;
    y 
= y_buffer;
    u 
= u_buffer;
    v 
= v_buffer;

    
// convert RGB to YUV
    if (!flip) {
        
for (j = 0; j < y_dim; j ++)
        
{
            y 
= y_buffer + (y_dim - j - 1* x_dim;
            u 
= u_buffer + (y_dim - j - 1* x_dim;
            v 
= v_buffer + (y_dim - j - 1* x_dim;

            
for (i = 0; i < x_dim; i ++{
                g 
= b + 1;
                r 
= b + 2;
                
*= (unsigned char)(  RGBYUV02990[*r] + RGBYUV05870[*g] + RGBYUV01140[*b]);
                
*= (unsigned char)(- RGBYUV01684[*r] - RGBYUV03316[*g] + (*b)/2          + 128);
                
*= (unsigned char)(  (*r)/2          - RGBYUV04187[*g] - RGBYUV00813[*b] + 128);
                b 
+= 3;
                y 
++;
                u 
++;
                v 
++;
            }

        }

    }
 else {
        
for (i = 0; i < size; i++)
        
{
            g 
= b + 1;
            r 
= b + 2;
            
*= (unsigned char)(  RGBYUV02990[*r] + RGBYUV05870[*g] + RGBYUV01140[*b]);
            
*= (unsigned char)(- RGBYUV01684[*r] - RGBYUV03316[*g] + (*b)/2          + 128);
            
*= (unsigned char)(  (*r)/2          - RGBYUV04187[*g] - RGBYUV00813[*b] + 128);
            b 
+= 3;
            y 
++;
            u 
++;
            v 
++;
        }

    }


    
// subsample UV
    for (j = 0; j < y_dim/2; j ++)
    
{
        psu 
= sub_u_buf + j * x_dim / 2;
        psv 
= sub_v_buf + j * x_dim / 2;
        pu1 
= u_buffer + 2 * j * x_dim;
        pu2 
= u_buffer + (2 * j + 1* x_dim;
        pv1 
= v_buffer + 2 * j * x_dim;
        pv2 
= v_buffer + (2 * j + 1* x_dim;
        
for (i = 0; i < x_dim/2; i ++)
        
{
            
*psu = (*pu1 + *(pu1+1+ *pu2 + *(pu2+1)) / 4;
            
*psv = (*pv1 + *(pv1+1+ *pv2 + *(pv2+1)) / 4;
            psu 
++;
            psv 
++;
            pu1 
+= 2;
            pu2 
+= 2;
            pv1 
+= 2;
            pv2 
+= 2;
        }

    }


    free(u_buffer);
    free(v_buffer);

    
return 0;
}



void InitLookupTable()
{
    
int i;

    
for (i = 0; i < 256; i++) RGBYUV02990[i] = (float)0.2990 * i;
    
for (i = 0; i < 256; i++) RGBYUV05870[i] = (float)0.5870 * i;
    
for (i = 0; i < 256; i++) RGBYUV01140[i] = (float)0.1140 * i;
    
for (i = 0; i < 256; i++) RGBYUV01684[i] = (float)0.1684 * i;
    
for (i = 0; i < 256; i++) RGBYUV03316[i] = (float)0.3316 * i;
    
for (i = 0; i < 256; i++) RGBYUV04187[i] = (float)0.4187 * i;
    
for (i = 0; i < 256; i++) RGBYUV00813[i] = (float)0.0813 * i;
}


測(cè)試程序:
/*
 * The contents of this file are subject to the Mozilla Public
 * License Version 1.1 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy of
 * the License at 
http://www.mozilla.org/MPL/
 * 
 * Software distributed under the License is distributed on an "AS
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * rights and limitations under the License.
 * 
 * The Original Code is MPEG4IP.
 * 
 * The Initial Developer of the Original Code is Cisco Systems Inc.
 * Portions created by Cisco Systems Inc. are
 * Copyright (C) Cisco Systems Inc. 2000, 2001.  All Rights Reserved.
 * 
 * Contributor(s): 
 *        Dave Mackie        dmackie@cisco.com
 
*/


#include 
<mpeg4ip.h>
#include 
<mpeg4ip_getopt.h>
#include 
"rgb2yuv.h"


/* globals */
char* progName;

/*
 * rgb2yuv
 * required arg1 should be the input RAW RGB24 file
 * required arg2 should be the output RAW YUV12 file
 
*/
 
static const char *usage = 
"\t--flip           - flip image\n"
"\t--height <value> - specify height\n"
"\t--width <value>  - specify width\n"
"\t--version        - display version\n";

int main(int argc, char** argv)
{
    
/* variables controlable from command line */
    u_int frameWidth 
= 320;            /* --width=<uint> */
    u_int frameHeight 
= 240;        /* --height=<uint> */
    
bool flip = FALSE;                /* --flip */

    
/* internal variables */
    
char* rgbFileName = NULL;
    
char* yuvFileName = NULL;
    FILE
* rgbFile = NULL;
    FILE
* yuvFile = NULL;
    u_int8_t
* rgbBuf = NULL;
    u_int8_t
* yBuf = NULL;
    u_int8_t
* uBuf = NULL;
    u_int8_t
* vBuf = NULL;
    u_int32_t videoFramesWritten 
= 0;
    
bool gotheight, gotwidth;

    gotheight 
= gotwidth = FALSE;

    
/* begin process command line */
    progName 
= argv[0];
    
while (1{
        
int c = -1;
        
int option_index = 0;
        
static struct option long_options[] = {
            
"flip"00'f' },
            
"height"10'h' },
            
"width"10'w' },
            
"version"00'V' },
            
{ NULL, 000 }
        }
;

        c 
= getopt_long_only(argc, argv, "fh:w:V",
            long_options, 
&option_index);

        
if (c == -1)
            
break;

        
switch (c) {
        
case 'f'{
            flip 
= TRUE;
            
break;
        }

        
case 'h'{
            
/* --height <pixels> */
            u_int i;
            gotheight 
= TRUE;
            
if (sscanf(optarg, "%u"&i) < 1{
                fprintf(stderr, 
                    
"%s: bad height specified: %s\n",
                     progName, optarg);
            }
 else if (i & 1{
                fprintf(stderr, 
                    
"%s: bad height specified, must be multiple of 2: %s\n",
                     progName, optarg);
            }
 else {
                
/* currently no range checking */
                frameHeight 
= i;
            }

            
break;
        }

        
case 'w'{
            
/* -width <pixels> */
            u_int i;
            gotwidth 
= TRUE;
            
if (sscanf(optarg, "%u"&i) < 1{
                fprintf(stderr, 
                    
"%s: bad width specified: %s\n",
                     progName, optarg);
            }
 else if (i & 1{
                fprintf(stderr, 
                    
"%s: bad width specified, must be multiple of 2: %s\n",
                     progName, optarg);
            }
 else {
                
/* currently no range checking */
                frameWidth 
= i;
            }

            
break;
        }

        
case '?':
          fprintf(stderr, 
              
"usage: %s <rgb-file> <yuv-file>\n%s",
              progName, usage);
          
return (0);
        
case 'V':
          fprintf(stderr, 
"%s - %s version %s\n",
              progName, MPEG4IP_PACKAGE, MPEG4IP_VERSION);
          
return (0);
        
default:
            fprintf(stderr, 
"%s: unknown option specified, ignoring: %c\n"
                progName, c);
        }

    }


    
/* check that we have at least two non-option arguments */
    
if ((argc - optind) < 2{
        fprintf(stderr, 
            
"usage: %s <rgb-file> <yuv-file>\n%s",
            progName, usage);
        exit(
1);
    }


    
if (gotheight == FALSE || gotwidth == FALSE) {
      fprintf(stderr, 
"%s - you haven't specified height or width - going with %dx%d"
          progName, frameWidth, frameHeight);
    }

    
/* point to the specified file names */
    rgbFileName 
= argv[optind++];
    yuvFileName 
= argv[optind++];

    
/* warn about extraneous non-option arguments */
    
if (optind < argc) {
        fprintf(stderr, 
"%s: unknown options specified, ignoring: ");
        
while (optind < argc) {
            fprintf(stderr, 
"%s ", argv[optind++]);
        }

        fprintf(stderr, 
"\n");
    }


    
/* end processing of command line */

    
/* open the RGB file */
    rgbFile 
= fopen(rgbFileName, "rb");
    
if (rgbFile == NULL) {
        fprintf(stderr, 
            
"%s: error %s: %s\n",
            progName, rgbFileName, strerror(errno));
        exit(
4);
    }


    
/* open the RAW file */
    yuvFile 
= fopen(yuvFileName, "wb");
    
if (yuvFile == NULL) {
        fprintf(stderr,
            
"%s: error opening %s: %s\n",
            progName, yuvFileName, strerror(errno));
        exit(
5);
    }


    
/* get an input buffer for a frame */
    rgbBuf 
= (u_int8_t*)malloc(frameWidth * frameHeight * 3);

    
/* get the output buffers for a frame */
    yBuf 
= (u_int8_t*)malloc(frameWidth * frameHeight);
    uBuf 
= (u_int8_t*)malloc((frameWidth * frameHeight) / 4);
    vBuf 
= (u_int8_t*)malloc((frameWidth * frameHeight) / 4);

    
if (rgbBuf == NULL || yBuf == NULL || uBuf == NULL || vBuf == NULL) {
        fprintf(stderr,
            
"%s: error allocating memory: %s\n",
            progName, strerror(errno));
        exit(
6);
    }


    
while (fread(rgbBuf, 1, frameWidth * frameHeight * 3, rgbFile)) {

        RGB2YUV(frameWidth, frameHeight, rgbBuf, yBuf, uBuf, vBuf, flip);

        fwrite(yBuf, 
1, frameWidth * frameHeight, yuvFile);
        fwrite(uBuf, 
1, (frameWidth * frameHeight) / 4, yuvFile);
        fwrite(vBuf, 
1, (frameWidth * frameHeight) / 4, yuvFile);

        videoFramesWritten
++;
    }


    printf(
"%u %ux%u video frames written\n"
        videoFramesWritten, frameWidth, frameHeight);

    
/* cleanup */
    fclose(rgbFile);
    fclose(yuvFile);

    
return(0);
}



posted on 2013-01-24 23:47 楊粼波 閱讀(1247) 評(píng)論(0)  編輯 收藏 引用


只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            欧美日韩另类字幕中文| 日韩视频一区二区| 一本色道久久综合精品竹菊| 久久国产精品99精品国产| 亚洲国产一区二区a毛片| 欧美亚洲免费在线| 久久精品99| 欧美顶级大胆免费视频| 麻豆乱码国产一区二区三区| 国产精品综合不卡av| 另类天堂av| 欧美在线免费一级片| **性色生活片久久毛片| 欧美日韩综合久久| 亚洲精品免费观看| 国产精品网红福利| 欧美在线|欧美| 欧美激情片在线观看| 欧美精品色网| 欧美成人久久| 国产综合香蕉五月婷在线| 欧美日韩伦理在线免费| 欧美激情一区二区三区| 国产一二精品视频| 亚洲精品国产无天堂网2021| 亚洲成人在线免费| 亚洲国产精品嫩草影院| 国产精品家教| 91久久亚洲| 亚洲乱码精品一二三四区日韩在线| 欧美综合国产| 亚洲在线视频观看| 国产日韩av一区二区| 亚洲视频在线一区| 国产精品青草综合久久久久99| 一区二区三欧美| 国产亚洲亚洲| 在线综合亚洲| 亚洲欧美中文日韩在线| 国产老肥熟一区二区三区| 欧美专区在线观看| 宅男在线国产精品| 久久精品123| 在线观看一区视频| 亚洲精品之草原avav久久| 尤妮丝一区二区裸体视频| 亚洲视频在线一区| 欧美激情综合色| 国产欧美日韩免费看aⅴ视频| 久久婷婷影院| 久久久久久高潮国产精品视| 亚洲尤物精选| 一区二区三区欧美日韩| 尹人成人综合网| 国产精品入口麻豆原神| 蜜月aⅴ免费一区二区三区| 日韩视频中午一区| 欧美在线高清视频| 国产精品久久久久久久久久尿 | 久久久精品国产免大香伊| 亚洲视频在线观看免费| 亚洲欧美中文字幕| 欧美一区二区三区在线| 欧美久久久久中文字幕| 久久久久久尹人网香蕉| 欧美高清不卡| 老司机久久99久久精品播放免费| 亚洲午夜电影在线观看| 亚洲日韩视频| 亚洲在线黄色| 欧美一区网站| 久久野战av| 久久伊人精品天天| 亚洲电影激情视频网站| 亚洲欧美www| 亚洲一区视频在线观看视频| 欧美aⅴ99久久黑人专区| 亚洲国产成人精品女人久久久 | 欧美日韩免费高清| 亚洲国产精品成人精品| 亚洲在线一区| 亚洲另类一区二区| 狠狠色狠色综合曰曰| 亚洲精品影院在线观看| 欧美激情一二三区| 9国产精品视频| 久久综合中文字幕| 精品成人国产在线观看男人呻吟| 免费亚洲电影| 欧美午夜精品久久久久久孕妇| 亚洲精品一区二区三区不| 欧美黄色大片网站| 久久嫩草精品久久久精品| 亚洲午夜一区| 久久久av网站| 午夜免费日韩视频| 亚洲视频图片小说| 亚洲在线中文字幕| 欧美aⅴ99久久黑人专区| 一区二区三区免费观看| 欧美激情亚洲自拍| 99精品视频免费观看视频| 欧美大片18| 香蕉久久国产| 亚洲性线免费观看视频成熟| 亚洲免费观看视频| 亚洲黄网站黄| 国产综合第一页| 亚洲电影第1页| 亚洲国产日韩在线一区模特| 欧美一区二区三区啪啪| 艳妇臀荡乳欲伦亚洲一区| 久久精品一区二区三区四区| 欧美午夜激情视频| 国产精品永久| 亚洲小说春色综合另类电影| 亚洲精品人人| 在线成人av网站| 亚洲美女电影在线| 最新国产拍偷乱拍精品| 亚洲婷婷综合久久一本伊一区| 国产精品久在线观看| 欧美日韩一区二区三区视频| 欧美欧美天天天天操| 亚洲三级电影在线观看| 亚洲午夜在线观看| 亚洲专区欧美专区| 久久精品99国产精品酒店日本| 久久精品国产亚洲5555| 午夜视频一区在线观看| 亚洲欧美中文另类| 欧美激情一区二区三区高清视频| 国产精品亚洲成人| 欧美一区二区在线播放| 国产精品久久久免费| 亚洲综合国产激情另类一区| 亚洲美女中出| 久久久综合视频| 亚洲乱码久久| 亚洲黄色免费| 欧美日本精品| 欧美 日韩 国产在线| 一本大道久久a久久综合婷婷 | 亚洲欧美国产日韩中文字幕| 免费观看国产成人| 免费av成人在线| 欧美三级视频| 欧美黄色影院| 国产视频欧美视频| 久久精品国产v日韩v亚洲| 久久久夜色精品亚洲| 亚洲国产1区| 亚洲欧美中文字幕| 亚洲成色www8888| 日韩一区二区高清| 伊人婷婷欧美激情| 久久黄色影院| 欧美va亚洲va日韩∨a综合色| 亚洲一区国产视频| 欧美精品久久久久久久免费观看| 亚洲黄色在线观看| 亚洲国产小视频在线观看| 一本色道久久综合狠狠躁篇怎么玩| 麻豆成人精品| 亚洲制服丝袜在线| 亚洲黄一区二区三区| 国外精品视频| 久久精品观看| 亚洲美女诱惑| 国语自产精品视频在线看| 亚洲精品在线电影| 在线观看视频一区二区欧美日韩| 99热免费精品| 一区二区三区不卡视频在线观看 | 久久国产福利国产秒拍| 欧美11—12娇小xxxx| 久久国产精品免费一区| 国产精品高潮呻吟久久av无限| 欧美国产激情| 一区二区三区在线观看欧美 | 亚洲剧情一区二区| 免费一级欧美在线大片| 久久蜜臀精品av| 国产午夜精品视频免费不卡69堂| 亚洲网站在线看| 亚洲欧美日韩成人高清在线一区| 欧美另类综合| 99国产精品视频免费观看| 99热这里只有精品8| 免费欧美网站| 亚洲精品色图| 一级日韩一区在线观看| 欧美日韩免费视频| 一区二区久久久久| 欧美一区二区三区在线观看| 国产欧美日韩亚洲精品| 久久精品夜色噜噜亚洲aⅴ| 久久露脸国产精品| 亚洲娇小video精品| 欧美成人自拍视频|