00001 00002 /*************************************************************************** 00003 * rgb.h - RGB specific methods, macros and constants 00004 * 00005 * Created: Sat Aug 12 14:59:55 2006 00006 * based on colorspaces.h from Tue Feb 23 13:49:38 2005 00007 * Copyright 2005-2006 Tim Niemueller [www.niemueller.de] 00008 * 00009 ****************************************************************************/ 00010 00011 /* This program is free software; you can redistribute it and/or modify 00012 * it under the terms of the GNU General Public License as published by 00013 * the Free Software Foundation; either version 2 of the License, or 00014 * (at your option) any later version. A runtime exception applies to 00015 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00016 * 00017 * This program is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU Library General Public License for more details. 00021 * 00022 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 00023 */ 00024 00025 #include <fvutils/color/rgb.h> 00026 00027 namespace firevision { 00028 #if 0 /* just to make Emacs auto-indent happy */ 00029 } 00030 #endif 00031 00032 /** Convert RGB to RGB with alpha values. 00033 * This is plain C code without special optimizations. 00034 * @param rgb RGB source buffer 00035 * @param rgb_alpha RGB with alpha destination buffer 00036 * @param width width in pixels 00037 * @param height height in pixels 00038 */ 00039 void 00040 rgb_to_rgb_with_alpha_plainc(const unsigned char *rgb, unsigned char *rgb_alpha, 00041 unsigned int width, unsigned int height) 00042 { 00043 for ( unsigned int i = 0; i < width * height; ++i) { 00044 *rgb_alpha++ = *rgb++; 00045 *rgb_alpha++ = *rgb++; 00046 *rgb_alpha++ = *rgb++; 00047 *rgb_alpha++ = 255; 00048 } 00049 } 00050 00051 00052 /** Convert RGB to BGR with alpha values. 00053 * This is plain C code without special optimizations. 00054 * @param rgb RGB source buffer 00055 * @param bgr_alpha BGR with alpha values destination buffer 00056 * @param width width in pixels 00057 * @param height height in pixels 00058 */ 00059 void 00060 rgb_to_bgr_with_alpha_plainc(const unsigned char *rgb, unsigned char *bgr_alpha, 00061 unsigned int width, unsigned int height) 00062 { 00063 for ( unsigned int i = 0; i < width * height; ++i) { 00064 *bgr_alpha++ = rgb[2]; 00065 *bgr_alpha++ = rgb[1]; 00066 *bgr_alpha++ = rgb[0]; 00067 *bgr_alpha++ = 255; 00068 rgb += 3; 00069 } 00070 } 00071 00072 00073 /** Convert BGR to RGB 00074 * This is plain C code without special optimizations. 00075 * @param bgr BGR source buffer 00076 * @param rgb RGB destination buffer 00077 * @param width width in pixels 00078 * @param height height in pixels 00079 */ 00080 void 00081 bgr_to_rgb_plainc(const unsigned char *BGR, unsigned char *RGB, 00082 unsigned int width, unsigned int height) 00083 { 00084 RGB_t *rgb; 00085 BGR_t *bgr; 00086 for (register unsigned int i = 0; i < (width * height); ++i) { 00087 bgr = (BGR_t *)BGR; 00088 rgb = (RGB_t *)RGB; 00089 rgb->R = bgr->R; 00090 rgb->G = bgr->G; 00091 rgb->B = bgr->B; 00092 BGR += 3; 00093 RGB += 3; 00094 } 00095 } 00096 00097 /* Convert a line of a BGR buffer to a line in a planar RGB buffer, see above for general 00098 * notes about color space conversion from RGB to BGR 00099 * @param RGB where the RGB output will be written to, will have pixel after pixel, 3 bytes per pixel 00100 * (thus this is a 24bit RGB with one byte per color) line by line. 00101 * @param BGR unsigned char array that contains the pixels, 4 pixels in 6 byte macro pixel, line after 00102 * line 00103 * @param width Width of the image contained in the YUV buffer 00104 * @param height Height of the image contained in the YUV buffer 00105 * @param rgb_line the index of the line to be converted 00106 * @param yuv_line the index of the line to convert to in the YUV buffer 00107 */ 00108 00109 void convert_line_bgr_rgb(const unsigned char *BGR, unsigned char *RGB, 00110 unsigned int width, unsigned int height) 00111 { 00112 register unsigned int i = 0; 00113 register const unsigned char *r1, *r2, *r3; 00114 register unsigned char *n1, *n2, *n3; 00115 00116 while( i < width ) { 00117 00118 n1 = RGB++; 00119 n2 = RGB++; 00120 n3 = RGB++; 00121 00122 r1 = BGR++; 00123 r2 = BGR++; 00124 r3 = BGR++; 00125 00126 *n1 = *r3; 00127 *n2 = *r2; 00128 *n3 = *r1; 00129 00130 00131 i += 1; 00132 } 00133 } 00134 00135 } // end namespace firevision