Fawkes API Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * colorspaces.cpp - This header defines utility functions to deal with 00004 * color spaces 00005 * 00006 * Generated: Sat Aug 12 15:26:23 2006 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/colorspaces.h> 00026 00027 #include <cstring> 00028 #include <cstdlib> 00029 00030 namespace firevision { 00031 #if 0 /* just to make Emacs auto-indent happy */ 00032 } 00033 #endif 00034 00035 colorspace_t 00036 colorspace_by_name(const char *mode) 00037 { 00038 00039 if (strcmp(mode, "RGB") == 0) { 00040 return RGB; 00041 } else if (strcmp(mode, "YUV411_PACKED") == 0) { 00042 return YUV411_PACKED; 00043 } else if (strcmp(mode, "YUV411_PLANAR") == 0) { 00044 return YUV411_PLANAR; 00045 } else if (strcmp(mode, "YUY2") == 0) { 00046 return YUY2; 00047 } else if (strcmp(mode, "YVY2") == 0) { 00048 return YVY2; 00049 } else if (strcmp(mode, "BGR") == 0) { 00050 return BGR; 00051 } else if (strcmp(mode, "YUV422_PACKED") == 0) { 00052 return YUV422_PACKED; 00053 } else if (strcmp(mode, "YUV444_PACKED") == 0) { 00054 return YUV444_PACKED; 00055 } else if (strcmp(mode, "YVU444_PACKED") == 0) { 00056 return YVU444_PACKED; 00057 } else if (strcmp(mode, "YUV422_PLANAR") == 0) { 00058 return YUV422_PLANAR; 00059 } else if (strcmp(mode, "YUV422_PLANAR_QUARTER") == 0) { 00060 return YUV422_PLANAR_QUARTER; 00061 } else if (strcmp(mode, "GRAY8") == 0) { 00062 return GRAY8; 00063 } else if (strcmp(mode, "RGB_WITH_ALPHA") == 0) { 00064 return RGB_WITH_ALPHA; 00065 } else if (strcmp(mode, "BGR_WITH_ALPHA") == 0) { 00066 return BGR_WITH_ALPHA; 00067 } else if (strcmp(mode, "BAYER_MOSAIC_RGGB") == 0) { 00068 return BAYER_MOSAIC_RGGB; 00069 } else if (strcmp(mode, "BAYER_MOSAIC_GBRG") == 0) { 00070 return BAYER_MOSAIC_GBRG; 00071 } else if (strcmp(mode, "BAYER_MOSAIC_GRBG") == 0) { 00072 return BAYER_MOSAIC_GRBG; 00073 } else if (strcmp(mode, "BAYER_MOSAIC_BGGR") == 0) { 00074 return BAYER_MOSAIC_BGGR; 00075 } else if (strcmp(mode, "RAW16") == 0) { 00076 return RAW16; 00077 } else if (strcmp(mode, "CARTESIAN_3D_FLOAT") == 0) { 00078 return CARTESIAN_3D_FLOAT; 00079 } else if (strcmp(mode, "CARTESIAN_3D_DOUBLE") == 0) { 00080 return CARTESIAN_3D_DOUBLE; 00081 } else { 00082 return CS_UNKNOWN; 00083 } 00084 00085 } 00086 00087 const char * 00088 colorspace_to_string(colorspace_t colorspace) 00089 { 00090 switch (colorspace) { 00091 case RGB: 00092 return "RGB"; 00093 case YUV411_PACKED: 00094 return "YUV411_PACKED"; 00095 case YUV411_PLANAR: 00096 return "YUV411_PLANAR"; 00097 case YUY2: 00098 return "YUY2"; 00099 case YVY2: 00100 return "YVY2"; 00101 case BGR: 00102 return "BGR"; 00103 case YUV422_PACKED: 00104 return "YUV422_PACKED"; 00105 case YUV444_PACKED: 00106 return "YUV444_PACKED"; 00107 case YVU444_PACKED: 00108 return "YVU444_PACKED"; 00109 case YUV422_PLANAR: 00110 return "YUV422_PLANAR"; 00111 case YUV422_PLANAR_QUARTER: 00112 return "YUV422_PLANAR_QUARTER"; 00113 case GRAY8: 00114 return "GRAY8"; 00115 case MONO8: 00116 return "MONO8"; 00117 case RGB_WITH_ALPHA: 00118 return "RGB_WITH_ALPHA"; 00119 case BGR_WITH_ALPHA: 00120 return "BGR_WITH_ALPHA"; 00121 case BAYER_MOSAIC_RGGB: 00122 return "BAYER_MOSAIC_RGGB"; 00123 case BAYER_MOSAIC_GBRG: 00124 return "BAYER_MOSAIC_GBRG"; 00125 case BAYER_MOSAIC_GRBG: 00126 return "BAYER_MOSAIC_GRBG"; 00127 case BAYER_MOSAIC_BGGR: 00128 return "BAYER_MOSAIC_BGGR"; 00129 case RAW16: 00130 return "RAW16"; 00131 case CARTESIAN_3D_FLOAT: 00132 return "CARTESIAN_3D_FLOAT"; 00133 case CARTESIAN_3D_DOUBLE: 00134 return "CARTESIAN_3D_DOUBLE"; 00135 default: 00136 return "CS_UNKNOWN"; 00137 } 00138 } 00139 00140 00141 unsigned char * 00142 malloc_buffer(colorspace_t colorspace, unsigned int width, unsigned int height) 00143 { 00144 return (unsigned char *)malloc(colorspace_buffer_size(colorspace, width, height)); 00145 } 00146 00147 size_t 00148 colorspace_buffer_size(colorspace_t cspace, unsigned int width, unsigned int height) 00149 { 00150 switch (cspace) { 00151 case RGB: 00152 case BGR: 00153 case YUV444_PACKED: 00154 case YVU444_PACKED: 00155 return (width * height * 3); 00156 00157 case RGB_WITH_ALPHA: 00158 case BGR_WITH_ALPHA: 00159 return (width * height * 4); 00160 00161 case YUV411_PACKED: 00162 case YUV411_PLANAR: 00163 return (width * height * 3 / 2); 00164 00165 case YUY2: 00166 case YVY2: 00167 case YUV422_PACKED: 00168 case YUV422_PLANAR: 00169 return (width * height * 2); 00170 00171 case RAW16: 00172 return (width * height * 2); 00173 00174 case GRAY8: 00175 case MONO8: 00176 case BAYER_MOSAIC_RGGB: 00177 case BAYER_MOSAIC_GBRG: 00178 case BAYER_MOSAIC_GRBG: 00179 case BAYER_MOSAIC_BGGR: 00180 return (width * height); 00181 00182 case YUV422_PLANAR_QUARTER: 00183 return (width * height) / 2; 00184 00185 case CARTESIAN_3D_FLOAT: 00186 return (3 * width * height * sizeof(float)); 00187 00188 case CARTESIAN_3D_DOUBLE: 00189 return (3 * width * height * sizeof(double)); 00190 00191 default: 00192 return 0; 00193 } 00194 } 00195 00196 } // end namespace firevision