colormodel.cpp
00001 00002 /*************************************************************************** 00003 * colormodel.cpp - Abstract class defining a color model 00004 * 00005 * Generated: 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 /** @class ColorModel <models/color/colormodel.h> 00029 * Color model interface. 00030 * This interface defines the API for color models. 00031 * 00032 * @fn color_t ColorModel::determine(unsigned int y, unsigned int u, unsigned int v) const 00033 * Determine classification of YUV pixel. 00034 * Given a pixel in the YUV colorspace the colormodel determines the color 00035 * classification based on some a-priori knowledge. 00036 * @param y Y value 00037 * @param u U value 00038 * @param v V value 00039 * 00040 * @fn const char * ColorModel::get_name() 00041 * Get name of color model. 00042 * @return name of color model. 00043 * 00044 * @author Tim Niemueller 00045 */ 00046 00047 00048 /** Virtual empty destructor. */ 00049 ColorModel::~ColorModel() 00050 { 00051 } 00052 00053 00054 /** Create image from color model. 00055 * Create image from color model, useful for debugging and analysing. 00056 * This method produces a representation of the color model for the full U/V plane 00057 * at the given value of Y for visual inspection of the colormap. 00058 * The dimensions of the resulting image are 512x512 pixels. It uses 00059 * strong colors as defined by ColorObjectMap. 00060 * Color models may override this method, but they must produce a 512x512 00061 * YUV422_PLANAR image. 00062 * @param yuv422_planar_buffer contains the image upon return, must be initialized 00063 * with the appropriate memory size before calling, dimensions are 512x512 pixels. 00064 * @param y Brightness value of the color 00065 */ 00066 void 00067 ColorModel::uv_to_image(unsigned char *yuv422_planar_buffer, unsigned int y) 00068 { 00069 unsigned char *yp = yuv422_planar_buffer; 00070 unsigned char *up = YUV422_PLANAR_U_PLANE(yuv422_planar_buffer, 512, 512); 00071 unsigned char *vp = YUV422_PLANAR_V_PLANE(yuv422_planar_buffer, 512, 512); 00072 00073 YUV_t c; 00074 for (unsigned int v = 256; v > 0 ; --v) { 00075 for (unsigned int u = 0; u < 256; ++u) { 00076 c = ColorObjectMap::get_color(determine(y, u, v)); 00077 00078 *yp++ = c.Y; 00079 *yp++ = c.Y; 00080 *up++ = c.U; 00081 *vp++ = c.V; 00082 } 00083 // Double line 00084 memcpy(yp, (yp - 512), 512); 00085 yp += 512; 00086 memcpy(up, (up - 256), 256); 00087 memcpy(vp, (vp - 256), 256); 00088 up += 256; 00089 vp += 256; 00090 } 00091 }

