Fawkes API Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * colormodel.cpp - Abstract class defining a color model 00004 * 00005 * Created: Wed Mar 21 18:38:17 2007 00006 * Copyright 2005-2007 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. A runtime exception applies to 00014 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Library General Public License for more details. 00020 * 00021 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 00022 */ 00023 00024 #include <models/color/colormodel.h> 00025 #include <fvutils/color/color_object_map.h> 00026 #include <cstring> 00027 00028 namespace firevision { 00029 #if 0 /* just to make Emacs auto-indent happy */ 00030 } 00031 #endif 00032 00033 /** @class ColorModel <models/color/colormodel.h> 00034 * Color model interface. 00035 * This interface defines the API for color models. 00036 * 00037 * @fn color_t ColorModel::determine(unsigned int y, unsigned int u, unsigned int v) const 00038 * Determine classification of YUV pixel. 00039 * Given a pixel in the YUV colorspace the colormodel determines the color 00040 * classification based on some a-priori knowledge. 00041 * @param y Y value 00042 * @param u U value 00043 * @param v V value 00044 * @return color classification 00045 * 00046 * @fn const char * ColorModel::get_name() 00047 * Get name of color model. 00048 * @return name of color model. 00049 * 00050 * @author Tim Niemueller 00051 */ 00052 00053 00054 /** Virtual empty destructor. */ 00055 ColorModel::~ColorModel() 00056 { 00057 } 00058 00059 00060 /** Create image from color model. 00061 * Create image from color model, useful for debugging and analysing. 00062 * This method produces a representation of the color model for the full U/V plane 00063 * at the given value of Y for visual inspection of the colormap. 00064 * The dimensions of the resulting image are 512x512 pixels. It uses 00065 * strong colors as defined by ColorObjectMap. 00066 * Color models may override this method, but they must produce a 512x512 00067 * YUV422_PLANAR image. 00068 * @param yuv422_planar_buffer contains the image upon return, must be initialized 00069 * with the appropriate memory size before calling, dimensions are 512x512 pixels. 00070 * @param y Brightness value of the color 00071 */ 00072 void 00073 ColorModel::uv_to_image(unsigned char *yuv422_planar_buffer, unsigned int y) 00074 { 00075 unsigned char *yp = yuv422_planar_buffer; 00076 unsigned char *up = YUV422_PLANAR_U_PLANE(yuv422_planar_buffer, 512, 512); 00077 unsigned char *vp = YUV422_PLANAR_V_PLANE(yuv422_planar_buffer, 512, 512); 00078 00079 YUV_t c; 00080 for (unsigned int v = 256; v > 0 ; --v) { 00081 for (unsigned int u = 0; u < 256; ++u) { 00082 c = ColorObjectMap::get_color(determine(y, u, v)); 00083 00084 *yp++ = c.Y; 00085 *yp++ = c.Y; 00086 *up++ = c.U; 00087 *vp++ = c.V; 00088 } 00089 // Double line 00090 memcpy(yp, (yp - 512), 512); 00091 yp += 512; 00092 memcpy(up, (up - 256), 256); 00093 memcpy(vp, (vp - 256), 256); 00094 up += 256; 00095 vp += 256; 00096 } 00097 } 00098 00099 } // end namespace firevision