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

📄 colorspace_macros.h

📁 这个库实现了录象功能
💻 H
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************* colorspace_macros.h libquicktime - A library for reading and writing quicktime/avi/mp4 files. http://libquicktime.sourceforge.net Copyright (C) 2002 Heroine Virtual Ltd. Copyright (C) 2002-2007 Members of the libquicktime project. This library 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. This library 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 this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA*******************************************************************************/#define RECLIP_8(color) (uint8_t)((color>0xFF)?0xff:((color<0)?0:color))#define RECLIP_16(color) (uint16_t)((color>0xFFFF)?0xFFFF:((color<0)?0:color))#define RECLIP_FLOAT(color) ((color>1.0)?1.0:((color<0.0)?0.0:color))#define RECLIP(color, min, max) ((color>max)?max:((color<min)?min:color))/* Masks for BGR16 and RGB16 formats */#define RGB16_LOWER_MASK  0x001f#define RGB16_MIDDLE_MASK 0x07e0#define RGB16_UPPER_MASK  0xf800/* Extract 8 bit RGB values from 15 bit pixels */#define RGB16_TO_R_8(pixel) rgb_5_to_8[(pixel & RGB16_UPPER_MASK)>>11]#define RGB16_TO_G_8(pixel) rgb_6_to_8[(pixel & RGB16_MIDDLE_MASK)>>5]#define RGB16_TO_B_8(pixel) rgb_5_to_8[(pixel & RGB16_LOWER_MASK)]#define BGR16_TO_B_8(pixel) RGB16_TO_R_8(pixel)#define BGR16_TO_G_8(pixel) RGB16_TO_G_8(pixel)#define BGR16_TO_R_8(pixel) RGB16_TO_B_8(pixel)/* Extract 16 bit RGB values from 15 bit pixels */#define RGB16_TO_R_16(pixel) rgb_5_to_16[(pixel & RGB16_UPPER_MASK)>>11]#define RGB16_TO_G_16(pixel) rgb_6_to_16[(pixel & RGB16_MIDDLE_MASK)>>5]#define RGB16_TO_B_16(pixel) rgb_5_to_16[(pixel & RGB16_LOWER_MASK)]#define BGR16_TO_B_16(pixel) RGB16_TO_R_16(pixel)#define BGR16_TO_G_16(pixel) RGB16_TO_G_16(pixel)#define BGR16_TO_R_16(pixel) RGB16_TO_B_16(pixel)/* Extract float RGB values from 15 bit pixels */#define RGB16_TO_R_FLOAT(pixel) rgb_5_to_float[(pixel & RGB16_UPPER_MASK)>>11]#define RGB16_TO_G_FLOAT(pixel) rgb_6_to_float[(pixel & RGB16_MIDDLE_MASK)>>5]#define RGB16_TO_B_FLOAT(pixel) rgb_5_to_float[(pixel & RGB16_LOWER_MASK)]#define BGR16_TO_B_FLOAT(pixel) RGB16_TO_R_FLOAT(pixel)#define BGR16_TO_G_FLOAT(pixel) RGB16_TO_G_FLOAT(pixel)#define BGR16_TO_R_FLOAT(pixel) RGB16_TO_B_FLOAT(pixel)/* Masks for BGR16 and RGB16 formats */#define RGB15_LOWER_MASK  0x001f#define RGB15_MIDDLE_MASK 0x03e0#define RGB15_UPPER_MASK  0x7C00/* Extract 8 bit RGB values from 16 bit pixels */#define RGB15_TO_R_8(pixel) rgb_5_to_8[(pixel & RGB15_UPPER_MASK)>>10]#define RGB15_TO_G_8(pixel) rgb_5_to_8[(pixel & RGB15_MIDDLE_MASK)>>5] #define RGB15_TO_B_8(pixel) rgb_5_to_8[(pixel & RGB15_LOWER_MASK)]#define BGR15_TO_B_8(pixel) RGB15_TO_R_8(pixel)#define BGR15_TO_G_8(pixel) RGB15_TO_G_8(pixel) #define BGR15_TO_R_8(pixel) RGB15_TO_B_8(pixel)#define RGB15_TO_R_16(pixel) rgb_5_to_16[(pixel & RGB15_UPPER_MASK)>>10]#define RGB15_TO_G_16(pixel) rgb_5_to_16[(pixel & RGB15_MIDDLE_MASK)>>5] #define RGB15_TO_B_16(pixel) rgb_5_to_16[(pixel & RGB15_LOWER_MASK)]#define BGR15_TO_B_16(pixel) RGB15_TO_R_16(pixel)#define BGR15_TO_G_16(pixel) RGB15_TO_G_16(pixel) #define BGR15_TO_R_16(pixel) RGB15_TO_B_16(pixel)#define RGB15_TO_R_FLOAT(pixel) rgb_5_to_float[(pixel & RGB15_UPPER_MASK)>>10]#define RGB15_TO_G_FLOAT(pixel) rgb_5_to_float[(pixel & RGB15_MIDDLE_MASK)>>5] #define RGB15_TO_B_FLOAT(pixel) rgb_5_to_float[(pixel & RGB15_LOWER_MASK)]#define BGR15_TO_B_FLOAT(pixel) RGB15_TO_R_FLOAT(pixel)#define BGR15_TO_G_FLOAT(pixel) RGB15_TO_G_FLOAT(pixel) #define BGR15_TO_R_FLOAT(pixel) RGB15_TO_B_FLOAT(pixel)/* Conversion from 8 bit */#define RGB_8_TO_16(val) (((uint32_t)(val))<<8)|(val)#define RGB_8_TO_FLOAT(val) ((float)(val)/255.0)/* Conversion from float */#define RGB_FLOAT_TO_8(val) (uint8_t)((val)*255.0+0.5)#define RGB_FLOAT_TO_16(val) (uint16_t)((val)*65535.0+0.5)/* Conversion from 16 bit */#define RGB_16_TO_8(val) ((val)>>8)#define RGB_16_TO_FLOAT(val) ((float)(val)/65535.0)/* Conversion from YUV float */#define Y_FLOAT_TO_8(val) (int)(val * 219.0) + 16;#define UV_FLOAT_TO_8(val) (int)(val * 224.0) + 128;#define Y_FLOAT_TO_16(val) (int)(val * 219.0 * (float)0x100) + 0x1000;#define UV_FLOAT_TO_16(val) (int)(val * 224.0 * (float)0x100) + 0x8000;#define YJ_FLOAT_TO_8(val) (int)(val * 255.0);#define UVJ_FLOAT_TO_8(val) (int)(val * 255.0) + 128;/* Conversion from YUV 16 */#define Y_16_TO_Y_8(val) ((val + 0x40)>>8)#define UV_16_TO_UV_8(val) ((val + 0x40)>>8)#define Y_16_TO_YJ_8(val)   (((((RECLIP(val, 0x1000, 0xEB00)-0x1000)*255)/219) + 0x40) >>8)#define UV_16_TO_UVJ_8(val) (((((RECLIP(val, 0x1000, 0xF000)-0x1000)*255)/224) + 0x40) >>8)/* Conversion from YUV 8 */#define Y_8_TO_16(val) ((val)<<8)#define UV_8_TO_16(val) ((val)<<8)#define Y_8_TO_YJ_8(val)   y_8_to_yj_8[val]#define UV_8_TO_UVJ_8(val) uv_8_to_uvj_8[val]#define YJ_8_TO_Y_8(val)   yj_8_to_y_8[val]#define UVJ_8_TO_UV_8(val) uvj_8_to_uv_8[val]#define YJ_8_TO_Y_16(val)   yj_8_to_y_16[val]#define UVJ_8_TO_UV_16(val) uvj_8_to_uv_16[val]/* RGB -> YUV conversion *//* 24 -> 8 */#define RGB_24_TO_Y_8(r,g,b,y) y=(r_to_y[r]+g_to_y[g]+b_to_y[b])>>16;#define RGB_24_TO_YUV_8(r,g,b,y,u,v)                                    \  RGB_24_TO_Y_8(r,g,b,y);                                               \  u=(r_to_u[r]+g_to_u[g]+b_to_u[b])>>16;                                \  v=(r_to_v[r]+g_to_v[g]+b_to_v[b])>>16;#define RGB_24_TO_YJ_8(r,g,b,y) y=(r_to_yj[r]+g_to_yj[g]+b_to_yj[b])>>16;#define RGB_24_TO_YUVJ_8(r,g,b,y,u,v) \  RGB_24_TO_YJ_8(r,g,b,y);                                              \  u=(r_to_uj[r]+g_to_uj[g]+b_to_uj[b])>>16;                             \  v=(r_to_vj[r]+g_to_vj[g]+b_to_vj[b])>>16;/* 24 -> 16 */#define RGB_24_TO_Y_16(r,g,b,y) y=(r_to_y[r]+g_to_y[g]+b_to_y[b])>>8;#define RGB_24_TO_YUV_16(r,g,b,y,u,v)                                    \  RGB_24_TO_Y_16(r,g,b,y);                                               \  u=(r_to_u[r]+g_to_u[g]+b_to_u[b])>>8;                                \  v=(r_to_v[r]+g_to_v[g]+b_to_v[b])>>8;/* 48 -> 8 */#define r_16_to_y (int64_t)((0.29900*219.0/255.0)*0x10000)#define g_16_to_y (int64_t)((0.58700*219.0/255.0)*0x10000)#define b_16_to_y (int64_t)((0.11400*219.0/255.0)*0x10000)#define r_16_to_u (int64_t)(-(0.16874*224.0/255.0)*0x10000)#define g_16_to_u (int64_t)(-(0.33126*224.0/255.0)*0x10000)#define b_16_to_u (int64_t)( (0.50000*224.0/255.0)*0x10000)#define r_16_to_v (int64_t)( (0.50000*224.0/255.0)*0x10000)#define g_16_to_v (int64_t)(-(0.41869*224.0/255.0)*0x10000)#define b_16_to_v (int64_t)(-(0.08131*224.0/255.0)*0x10000)#define r_16_to_yj (int64_t)((0.29900)*0x10000)#define g_16_to_yj (int64_t)((0.58700)*0x10000)#define b_16_to_yj (int64_t)((0.11400)*0x10000)#define r_16_to_uj (int64_t)(-(0.16874)*0x10000)#define g_16_to_uj (int64_t)(-(0.33126)*0x10000)#define b_16_to_uj (int64_t)( (0.50000)*0x10000)#define r_16_to_vj (int64_t)( (0.50000)*0x10000)#define g_16_to_vj (int64_t)(-(0.41869)*0x10000)#define b_16_to_vj (int64_t)(-(0.08131)*0x10000)#define RGB_48_TO_Y_8(r,g,b,y) \  y=(r_16_to_y * r + g_16_to_y * g + b_16_to_y * b + 16 * 0x1000000LL)>>24;#define RGB_48_TO_YUV_8(r,g,b,y,u,v)                                    \  RGB_48_TO_Y_8(r,g,b,y);                                               \  u=(r_16_to_u * r + g_16_to_u * g + b_16_to_u * b + 0x80000000LL)>>24;  \  v=(r_16_to_v * r + g_16_to_v * g + b_16_to_v * b + 0x80000000LL)>>24;#define RGB_48_TO_YJ_8(r,g,b,y) \  y=(r_16_to_yj * r + g_16_to_yj * g + b_16_to_yj * b)>>24;#define RGB_48_TO_YUVJ_8(r,g,b,y,u,v)                                    \  RGB_48_TO_YJ_8(r,g,b,y);                                               \  u=(r_16_to_uj * r + g_16_to_uj * g + b_16_to_uj * b + 0x80000000LL)>>24;  \  v=(r_16_to_vj * r + g_16_to_vj * g + b_16_to_vj * b + 0x80000000LL)>>24;/* 48 -> 16 */#define RGB_48_TO_Y_16(r,g,b,y) \  y=(r_16_to_y * r + g_16_to_y * g + b_16_to_y * b + 16 * 0x1000000LL)>>16;#define RGB_48_TO_YUV_16(r,g,b,y,u,v)                                    \  RGB_48_TO_Y_16(r,g,b,y);                                               \  u=(r_16_to_u * r + g_16_to_u * g + b_16_to_u * b + 0x80000000LL)>>16;  \  v=(r_16_to_v * r + g_16_to_v * g + b_16_to_v * b + 0x80000000LL)>>16;/* RGB Float -> YUV */#define r_float_to_y 0.29900#define g_float_to_y 0.58700#define b_float_to_y 0.11400#define r_float_to_u -0.16874#define g_float_to_u -0.33126#define b_float_to_u  0.50000#define r_float_to_v  0.50000#define g_float_to_v -0.41869#define b_float_to_v -0.08131#define INIT_RGB_FLOAT_TO_YUV \  float y_tmp, u_tmp, v_tmp;/* Float -> 8 */#define RGB_FLOAT_TO_Y_8(r, g, b, y)                              \  y_tmp = r_float_to_y * r + g_float_to_y * g + b_float_to_y * b; \  y = Y_FLOAT_TO_8(y_tmp);

⌨️ 快捷键说明

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