📄 yuv2rgb.c
字号:
/* ***** BEGIN LICENSE BLOCK *****
* Version: RCSL 1.0/RPSL 1.0
*
* Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved.
*
* The contents of this file, and the files included with this file, are
* subject to the current version of the RealNetworks Public Source License
* Version 1.0 (the "RPSL") available at
* http://www.helixcommunity.org/content/rpsl unless you have licensed
* the file under the RealNetworks Community Source License Version 1.0
* (the "RCSL") available at http://www.helixcommunity.org/content/rcsl,
* in which case the RCSL will apply. You may also obtain the license terms
* directly from RealNetworks. You may not use this file except in
* compliance with the RPSL or, if you have a valid RCSL with RealNetworks
* applicable to this file, the RCSL. Please see the applicable RPSL or
* RCSL for the rights, obligations and limitations governing use of the
* contents of the file.
*
* This file is part of the Helix DNA Technology. RealNetworks is the
* developer of the Original Code and owns the copyrights in the portions
* it created.
*
* This file, and the files included with this file, is distributed and made
* available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
*
* Technology Compatibility Kit Test Suite(s) Location:
* http://www.helixcommunity.org/content/tck
*
* Contributor(s):
*
* ***** END LICENSE BLOCK ***** */
/*** #includes: ********************************************/
#include "env.h"
#include "rgb.h" /* basic RGB-data definitions & macros */
#include "yuv.h" /* YUV-to-RGB conversion tables & macros */
#include "clip.h" /* macros for clipping & dithering */
#include "scale.h" /* scale algorithms */
#include "colorlib.h" /* ensure that prototypes get extern C'ed */
#ifdef _MACINTOSH
#pragma require_prototypes off
#endif
static int YUVtoRGB2 (
int dest_format,
unsigned char *dest_ptr, int dest_width, int dest_height,
int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
unsigned char *pY, unsigned char *pU, unsigned char *pV,
int src_width, int src_height, int yPitch, int uPitch, int vPitch,
int src_x, int src_y, int src_dx, int src_dy);
/*** Additional pixel-level macros: ************************/
/*
* Add dither, clip and assign values to RGB pixels:
*/
#define RGBX_CLIP_X(f,rnd,x,v) (CLIP(rnd,BITS(f,x),v) << START(f,x))
#define RGBX_CLIP_SET(f,rnd,a,r,g,b) \
a##_rgb = RGBX_CLIP_X(f,rnd,R,r) | RGBX_CLIP_X(f,rnd,G,g) | RGBX_CLIP_X(f,rnd,B,b)
#define RGB32_CLIP_SET(rnd,a,r,g,b) RGBX_CLIP_SET(RGB32,rnd,a,r,g,b)
#define BGR32_CLIP_SET(rnd,a,r,g,b) RGBX_CLIP_SET(BGR32,rnd,a,r,g,b)
#define RGB24_CLIP_SET(rnd,a,r,g,b) \
a##_b = CLIP(rnd,8,b), a##_g = CLIP(rnd,8,g), a##_r = CLIP(rnd,8,r)
#define RGB565_CLIP_SET(rnd,a,r,g,b) RGBX_CLIP_SET(RGB565,rnd,a,r,g,b)
#define RGB555_CLIP_SET(rnd,a,r,g,b) RGBX_CLIP_SET(RGB555,rnd,a,r,g,b)
#define RGB444_CLIP_SET(rnd,a,r,g,b) RGBX_CLIP_SET(RGB444,rnd,a,r,g,b)
#define RGB8_CLIP_SET(rnd,a,r,g,b) \
a##_idx = pmap[(CLIP(rnd,4,r)<<8) | (CLIP(rnd,4,g)<<4) | CLIP(rnd,4,b)]
/*
* Generic RGB clipping & assignment macro:
*/
#define CLIP_SET(f,rnd,a,r,g,b) f##_CLIP_SET(rnd,a,r,g,b)
/*
* YUV 2x1-block load and convert macros:
*/
#define YUV_LOAD_CONVERT_2x1_FAST(df,a1,a2,sy1,sy2,su,sv) \
{ \
register int y1, y2, rv, guv, bu; \
bu = butab[su[0]]; \
guv = gutab[su[0]] + gvtab[sv[0]]; \
rv = rvtab[sv[0]]; \
y1 = ytab[sy1[0]]; \
y2 = ytab[sy2[0]]; \
CLIP_SET(df,ROUND,a1,y1+rv,y1+guv,y1+bu); \
CLIP_SET(df,ROUND,a2,y2+rv,y2+guv,y2+bu); \
}
/* with Hue rotation: */
#define YUV_LOAD_CONVERT_2x1_FULL(df,a1,a2,sy1,sy2,su,sv) \
{ \
register int y1, y2, ruv, guv, buv; \
buv = butab[su[0]] + bvtab[sv[0]]; \
guv = gutab[su[0]] + gvtab[sv[0]]; \
ruv = rutab[su[0]] + rvtab[sv[0]]; \
y1 = ytab[sy1[0]]; \
y2 = ytab[sy2[0]]; \
CLIP_SET(df,ROUND,a1,y1+ruv,y1+guv,y1+buv); \
CLIP_SET(df,ROUND,a2,y2+ruv,y2+guv,y2+buv); \
}
/*
* Generic YUV 2x1-block load & convert macro:
*/
#define YUV_LOAD_CONVERT_2x1(cc,df,a1,a2,sy1,sy2,su,sv) \
YUV_LOAD_CONVERT_2x1_##cc(df,a1,a2,sy1,sy2,su,sv)
/*
* YUV 2x2-block load and convert macros:
* (without dithering)
*/
#define YUV_LOAD_CONVERT_2x2_FAST(df,a11,a12,a21,a22,sy1,sy2,su,sv) \
{ \
register int y11, y12, y21, y22, rv, guv, bu; \
bu = butab[su[0]]; \
guv = gutab[su[0]] + gvtab[sv[0]]; \
rv = rvtab[sv[0]]; \
y11 = ytab[sy1[0]]; \
y21 = ytab[sy2[0]]; \
y12 = ytab[sy1[1]]; \
y22 = ytab[sy2[1]]; \
CLIP_SET(df,ROUND,a11,y11+rv,y11+guv,y11+bu); \
CLIP_SET(df,ROUND,a21,y21+rv,y21+guv,y21+bu); \
CLIP_SET(df,ROUND,a12,y12+rv,y12+guv,y12+bu); \
CLIP_SET(df,ROUND,a22,y22+rv,y22+guv,y22+bu); \
}
/* with Hue rotation: */
#define YUV_LOAD_CONVERT_2x2_FULL(df,a11,a12,a21,a22,sy1,sy2,su,sv) \
{ \
register int y11, y12, y21, y22, ruv, guv, buv; \
buv = butab[su[0]] + bvtab[sv[0]]; \
guv = gutab[su[0]] + gvtab[sv[0]]; \
ruv = rutab[su[0]] + rvtab[sv[0]]; \
y11 = ytab[sy1[0]]; \
y21 = ytab[sy2[0]]; \
y12 = ytab[sy1[1]]; \
y22 = ytab[sy2[1]]; \
CLIP_SET(df,ROUND,a11,y11+ruv,y11+guv,y11+buv); \
CLIP_SET(df,ROUND,a21,y21+ruv,y21+guv,y21+buv); \
CLIP_SET(df,ROUND,a12,y12+ruv,y12+guv,y12+buv); \
CLIP_SET(df,ROUND,a22,y22+ruv,y22+guv,y22+buv); \
}
/*
* Generic YUV 2x1-block load & convert macro:
*/
#define YUV_LOAD_CONVERT_2x2(cc,df,a11,a12,a21,a22,sy1,sy2,su,sv) \
YUV_LOAD_CONVERT_2x2_##cc(df,a11,a12,a21,a22,sy1,sy2,su,sv)
/*
* YUV 2x2-block load and convert macros:
* (adds symmetric 2x2 dither noise)
*/
#define YUV_LOAD_CONVERT_DITHER_2x2_FAST(df,a11,a12,a21,a22,sy1,sy2,su,sv) \
{ \
register int y11, y12, y21, y22, rv, guv, bu; \
bu = butab[su[0]]; \
guv = gutab[su[0]] + gvtab[sv[0]]; \
rv = rvtab[sv[0]]; \
y11 = ytab[sy1[0]]; \
y21 = ytab[sy2[0]]; \
y12 = ytab[sy1[1]]; \
y22 = ytab[sy2[1]]; \
CLIP_SET(df,HIGH,a11,y11+rv,y11+guv,y11+bu); \
CLIP_SET(df,LOW ,a21,y21+rv,y21+guv,y21+bu); \
CLIP_SET(df,LOW ,a12,y12+rv,y12+guv,y12+bu); \
CLIP_SET(df,HIGH,a22,y22+rv,y22+guv,y22+bu); \
}
/* with Hue rotation: */
#define YUV_LOAD_CONVERT_DITHER_2x2_FULL(df,a11,a12,a21,a22,sy1,sy2,su,sv) \
{ \
register int y11, y12, y21, y22, ruv, guv, buv; \
buv = butab[su[0]] + bvtab[sv[0]]; \
guv = gutab[su[0]] + gvtab[sv[0]]; \
ruv = rutab[su[0]] + rvtab[sv[0]]; \
y11 = ytab[sy1[0]]; \
y21 = ytab[sy2[0]]; \
y12 = ytab[sy1[1]]; \
y22 = ytab[sy2[1]]; \
CLIP_SET(df,HIGH,a11,y11+ruv,y11+guv,y11+buv); \
CLIP_SET(df,LOW ,a21,y21+ruv,y21+guv,y21+buv); \
CLIP_SET(df,LOW ,a12,y12+ruv,y12+guv,y12+buv); \
CLIP_SET(df,HIGH,a22,y22+ruv,y22+guv,y22+buv); \
}
/*
* Generic YUV 2x1-block load & convert macro:
*/
#define YUV_LOAD_CONVERT_DITHER_2x2(cc,df,a11,a12,a21,a22,sy1,sy2,su,sv) \
YUV_LOAD_CONVERT_DITHER_2x2_##cc(df,a11,a12,a21,a22,sy1,sy2,su,sv)
/*
* Generic YUV load-convert-store macros:
*/
#define YUV_LOAD_CONVERT_STORE_2x1(cc,df,d1,d2,sy1,sy2,su,sv) \
{ \
PIXEL(df,a1); PIXEL(df,a2); \
YUV_LOAD_CONVERT_2x1(cc,df,a1,a2,sy1,sy2,su,sv); \
sy1++; sy2++; su++; sv++; \
STORE(df,d1,a1); \
d1+=BPP(df); \
STORE(df,d2,a2); \
d2+=BPP(df); \
}
#define YUV_LOAD_CONVERT_STORE_2x2(cc,df,d1,d2,sy1,sy2,su,sv) \
{ \
PIXEL(df,a11); PIXEL(df,a12); \
PIXEL(df,a21); PIXEL(df,a22); \
YUV_LOAD_CONVERT_2x2(cc,df,a11,a12,a21,a22,sy1,sy2,su,sv); \
sy1+=2; sy2+=2; su++; sv++; \
STORE(df,d1,a11); \
STORE(df,d1+BPP(df),a12); \
d1+=2*BPP(df); \
STORE(df,d2,a21); \
STORE(df,d2+BPP(df),a22); \
d2+=2*BPP(df); \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -