00001 #ifndef PLUGINCOLORS_H
00002 #define PLUGINCOLORS_H
00003
00004
00005
00006 #include "clip.h"
00007 #include "vframe.inc"
00008
00009 #include <stdint.h>
00010
00011
00012 #define R_TO_Y 0.29900
00013 #define G_TO_Y 0.58700
00014 #define B_TO_Y 0.11400
00015
00016 #define R_TO_U -0.16874
00017 #define G_TO_U -0.33126
00018 #define B_TO_U 0.50000
00019
00020 #define R_TO_V 0.50000
00021 #define G_TO_V -0.41869
00022 #define B_TO_V -0.08131
00023
00024
00025 #define V_TO_R 1.40200
00026 #define V_TO_G -0.71414
00027
00028 #define U_TO_G -0.34414
00029 #define U_TO_B 1.77200
00030
00031
00032 class YUV
00033 {
00034 public:
00035 YUV();
00036 ~YUV();
00037
00038 inline void rgb_to_yuv_8(int &y, int &u, int &v)
00039 {
00040 int r = y;
00041 int g = u;
00042 int b = v;
00043 y = (rtoy_tab_8[r] + gtoy_tab_8[g] + btoy_tab_8[b]) >> 8;
00044 u = (rtou_tab_8[r] + gtou_tab_8[g] + btou_tab_8[b]) >> 8;
00045 v = (rtov_tab_8[r] + gtov_tab_8[g] + btov_tab_8[b]) >> 8;
00046 };
00047
00048 inline void rgb_to_yuv_8(int r, int g, int b, int &y, int &u, int &v)
00049 {
00050 y = (rtoy_tab_8[r] + gtoy_tab_8[g] + btoy_tab_8[b]) >> 8;
00051 u = (rtou_tab_8[r] + gtou_tab_8[g] + btou_tab_8[b]) >> 8;
00052 v = (rtov_tab_8[r] + gtov_tab_8[g] + btov_tab_8[b]) >> 8;
00053 };
00054
00055 inline void rgb_to_yuv_8(int r, int g, int b, unsigned char &y, unsigned char &u, unsigned char &v)
00056 {
00057 y = (rtoy_tab_8[r] + gtoy_tab_8[g] + btoy_tab_8[b]) >> 8;
00058 u = (rtou_tab_8[r] + gtou_tab_8[g] + btou_tab_8[b]) >> 8;
00059 v = (rtov_tab_8[r] + gtov_tab_8[g] + btov_tab_8[b]) >> 8;
00060 };
00061
00062 static inline void rgb_to_yuv_f(float r, float g, float b, float &y, float &u, float &v)
00063 {
00064 y = r * R_TO_Y + g * G_TO_Y + b * B_TO_Y;
00065 u = r * R_TO_U + g * G_TO_U + b * B_TO_U;
00066 v = r * R_TO_V + g * G_TO_V + b * B_TO_V;
00067 };
00068
00069 inline void rgb_to_yuv_16(int r, int g, int b, int &y, int &u, int &v)
00070 {
00071 y = (rtoy_tab_16[r] + gtoy_tab_16[g] + btoy_tab_16[b]) >> 8;
00072 u = (rtou_tab_16[r] + gtou_tab_16[g] + btou_tab_16[b]) >> 8;
00073 v = (rtov_tab_16[r] + gtov_tab_16[g] + btov_tab_16[b]) >> 8;
00074 };
00075
00076
00077 inline void rgb_to_yuv_8(float r, float g, float b, float &y, float &u, float &v)
00078 {
00079 };
00080
00081 inline void rgb_to_yuv_16(float r, float g, float b, float &y, float &u, float &v)
00082 {
00083 };
00084
00085 static inline void rgb_to_yuv_f(int r, int g, int b, int &y, int &u, int &v)
00086 {
00087 };
00088
00089 inline void yuv_to_rgb_8(int &r, int &g, int &b)
00090 {
00091 int y = r;
00092 int u = g;
00093 int v = b;
00094 y = (y << 8) | y;
00095 r = (y + vtor_tab_8[v]) >> 8;
00096 g = (y + utog_tab_8[u] + vtog_tab_8[v]) >> 8;
00097 b = (y + utob_tab_8[u]) >> 8;
00098
00099 CLAMP(r, 0, 0xff);
00100 CLAMP(g, 0, 0xff);
00101 CLAMP(b, 0, 0xff);
00102 };
00103 inline void yuv_to_rgb_8(int &r, int &g, int &b, int y, int u, int v)
00104 {
00105 y = (y << 8) | y;
00106 r = (y + vtor_tab_8[v]) >> 8;
00107 g = (y + utog_tab_8[u] + vtog_tab_8[v]) >> 8;
00108 b = (y + utob_tab_8[u]) >> 8;
00109
00110 CLAMP(r, 0, 0xff);
00111 CLAMP(g, 0, 0xff);
00112 CLAMP(b, 0, 0xff);
00113 };
00114
00115 static inline void yuv_to_rgb_f(float &r, float &g, float &b, float y, float u, float v)
00116 {
00117 r = y + V_TO_R * v;
00118 g = y + U_TO_G * u + V_TO_G * v;
00119 b = y + U_TO_B * u;
00120 };
00121
00122 inline void rgb_to_yuv_16(int r, int g, int b, uint16_t &y, uint16_t &u, uint16_t &v)
00123 {
00124 y = (rtoy_tab_16[r] + gtoy_tab_16[g] + btoy_tab_16[b]) >> 8;
00125 u = (rtou_tab_16[r] + gtou_tab_16[g] + btou_tab_16[b]) >> 8;
00126 v = (rtov_tab_16[r] + gtov_tab_16[g] + btov_tab_16[b]) >> 8;
00127 };
00128
00129 inline void yuv_to_rgb_16(int &r, int &g, int &b, int y, int u, int v)
00130 {
00131 y = (y << 8) | y;
00132 r = (y + vtor_tab_16[v]) >> 8;
00133 g = (y + utog_tab_16[u] + vtog_tab_16[v]) >> 8;
00134 b = (y + utob_tab_16[u]) >> 8;
00135
00136 CLAMP(r, 0, 0xffff);
00137 CLAMP(g, 0, 0xffff);
00138 CLAMP(b, 0, 0xffff);
00139 };
00140
00141
00142 inline void yuv_to_rgb_8(float &r, float &g, float &b, float y, float u, float v)
00143 {
00144 };
00145
00146
00147 inline void yuv_to_rgb_16(float &r, float &g, float &b, float y, float u, float v)
00148 {
00149 };
00150
00151 static inline void yuv_to_rgb_f(int &r, int &g, int &b, int y, int u, int v)
00152 {
00153 };
00154
00155 private:
00156 int rtoy_tab_8[0x100], gtoy_tab_8[0x100], btoy_tab_8[0x100];
00157 int rtou_tab_8[0x100], gtou_tab_8[0x100], btou_tab_8[0x100];
00158 int rtov_tab_8[0x100], gtov_tab_8[0x100], btov_tab_8[0x100];
00159
00160 int vtor_tab_8[0x100], vtog_tab_8[0x100];
00161 int utog_tab_8[0x100], utob_tab_8[0x100];
00162 int *vtor_8, *vtog_8, *utog_8, *utob_8;
00163
00164 int rtoy_tab_16[0x10000], gtoy_tab_16[0x10000], btoy_tab_16[0x10000];
00165 int rtou_tab_16[0x10000], gtou_tab_16[0x10000], btou_tab_16[0x10000];
00166 int rtov_tab_16[0x10000], gtov_tab_16[0x10000], btov_tab_16[0x10000];
00167
00168 int vtor_tab_16[0x10000], vtog_tab_16[0x10000];
00169 int utog_tab_16[0x10000], utob_tab_16[0x10000];
00170 int *vtor_16, *vtog_16, *utog_16, *utob_16;
00171 };
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186 class HSV
00187 {
00188 public:
00189 HSV();
00190 ~HSV();
00191
00192
00193 static int rgb_to_hsv(float r, float g, float b, float &h, float &s, float &v);
00194 static int hsv_to_rgb(float &r, float &g, float &b, float h, float s, float v);
00195
00196
00197 static int yuv_to_hsv(int y, int u, int v, float &h, float &s, float &va, int max);
00198 static int hsv_to_yuv(int &y, int &u, int &v, float h, float s, float va, int max);
00199
00200 static int yuv_to_hsv(float y, float u, float v, float &h, float &s, float &va, float max) { return 0; };
00201 static int hsv_to_yuv(float &y, float &u, float &v, float h, float s, float va, float max) { return 0; };
00202 static YUV yuv_static;
00203 };
00204
00205
00206 #endif