00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "ccvt.h"
00023
00024 #define PUSH_RGB24 1
00025 #define PUSH_BGR24 2
00026 #define PUSH_RGB32 3
00027 #define PUSH_BGR32 4
00028
00029
00030
00031 static void ccvt_420p(int width, int height, const unsigned char *src, unsigned char *dst, int push)
00032 {
00033 int line, col, linewidth;
00034 int y, u, v, yy, vr, ug, vg, ub;
00035 int r, g, b;
00036 const unsigned char *py, *pu, *pv;
00037
00038 linewidth = width >> 1;
00039 py = src;
00040 pu = py + (width * height);
00041 pv = pu + (width * height) / 4;
00042
00043 y = *py++;
00044 yy = y << 8;
00045 u = *pu - 128;
00046 ug = 88 * u;
00047 ub = 454 * u;
00048 v = *pv - 128;
00049 vg = 183 * v;
00050 vr = 359 * v;
00051
00052 for (line = 0; line < height; line++) {
00053 for (col = 0; col < width; col++) {
00054 r = (yy + vr) >> 8;
00055 g = (yy - ug - vg) >> 8;
00056 b = (yy + ub ) >> 8;
00057
00058 if (r < 0) r = 0;
00059 if (r > 255) r = 255;
00060 if (g < 0) g = 0;
00061 if (g > 255) g = 255;
00062 if (b < 0) b = 0;
00063 if (b > 255) b = 255;
00064
00065 switch(push) {
00066 case PUSH_RGB24:
00067 *dst++ = r;
00068 *dst++ = g;
00069 *dst++ = b;
00070 break;
00071
00072 case PUSH_BGR24:
00073 *dst++ = b;
00074 *dst++ = g;
00075 *dst++ = r;
00076 break;
00077
00078 case PUSH_RGB32:
00079 *dst++ = r;
00080 *dst++ = g;
00081 *dst++ = b;
00082 *dst++ = 0;
00083 break;
00084
00085 case PUSH_BGR32:
00086 *dst++ = b;
00087 *dst++ = g;
00088 *dst++ = r;
00089 *dst++ = 0;
00090 break;
00091 }
00092
00093 y = *py++;
00094 yy = y << 8;
00095 if (col & 1) {
00096 pu++;
00097 pv++;
00098
00099 u = *pu - 128;
00100 ug = 88 * u;
00101 ub = 454 * u;
00102 v = *pv - 128;
00103 vg = 183 * v;
00104 vr = 359 * v;
00105 }
00106 }
00107 if ((line & 1) == 0) {
00108 pu -= linewidth;
00109 pv -= linewidth;
00110 }
00111 }
00112 }
00113
00114 void ccvt_420p_rgb24(int width, int height, const void *src, void *dst)
00115 {
00116 ccvt_420p(width, height, (const unsigned char *)src, (unsigned char *)dst, PUSH_RGB24);
00117 }
00118
00119 void ccvt_420p_bgr24(int width, int height, const void *src, void *dst)
00120 {
00121 ccvt_420p(width, height, (const unsigned char *)src, (unsigned char *)dst, PUSH_BGR24);
00122 }
00123
00124 void ccvt_420p_rgb32(int width, int height, const void *src, void *dst)
00125 {
00126 ccvt_420p(width, height, (const unsigned char *)src, (unsigned char *)dst, PUSH_RGB32);
00127 }
00128
00129 void ccvt_420p_bgr32(int width, int height, const void *src, void *dst)
00130 {
00131 ccvt_420p(width, height, (const unsigned char *)src, (unsigned char *)dst, PUSH_BGR32);
00132 }