ccvt_c.c
Go to the documentation of this file.
00001 /*  CCVT: ColourConVerT: simple library for converting colourspaces
00002     Copyright (C) 2002 Nemosoft Unv.
00003 
00004     This program is free software; you can redistribute it and/or modify
00005     it under the terms of the GNU General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or
00007     (at your option) any later version.
00008 
00009     This program is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with this program; if not, write to the Free Software
00016     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 
00018     For questions, remarks, patches, etc. for this program, the author can be
00019     reached at nemosoft@smcc.demon.nl.
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 /* This is a simplistic approach. */
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                 } /* ..for col */
00107                 if ((line & 1) == 0) { // even line: rewind
00108                         pu -= linewidth;
00109                         pv -= linewidth;
00110                 }
00111         } /* ..for line */
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 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


ar_recog
Author(s): Graylin Trevor Jay and Christopher Crick
autogenerated on Fri Jan 25 2013 12:14:59