Fawkes API  Fawkes Development Version
colormodel.cpp
1 
2 /***************************************************************************
3  * colormodel.cpp - Abstract class defining a color model
4  *
5  * Created: Wed Mar 21 18:38:17 2007
6  * Copyright 2005-2007 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #include <fvmodels/color/colormodel.h>
25 #include <fvutils/color/color_object_map.h>
26 #include <cstring>
27 
28 namespace firevision {
29 #if 0 /* just to make Emacs auto-indent happy */
30 }
31 #endif
32 
33 /** @class ColorModel <fvmodels/color/colormodel.h>
34  * Color model interface.
35  * This interface defines the API for color models.
36  *
37  * @fn color_t ColorModel::determine(unsigned int y, unsigned int u, unsigned int v) const
38  * Determine classification of YUV pixel.
39  * Given a pixel in the YUV colorspace the colormodel determines the color
40  * classification based on some a-priori knowledge.
41  * @param y Y value
42  * @param u U value
43  * @param v V value
44  * @return color classification
45  *
46  * @fn const char * ColorModel::get_name()
47  * Get name of color model.
48  * @return name of color model.
49  *
50  * @author Tim Niemueller
51  */
52 
53 
54 /** Virtual empty destructor. */
56 {
57 }
58 
59 
60 /** Create image from color model.
61  * Create image from color model, useful for debugging and analysing.
62  * This method produces a representation of the color model for the full U/V plane
63  * at the given value of Y for visual inspection of the colormap.
64  * The dimensions of the resulting image are 512x512 pixels. It uses
65  * strong colors as defined by ColorObjectMap.
66  * Color models may override this method, but they must produce a 512x512
67  * YUV422_PLANAR image.
68  * @param yuv422_planar_buffer contains the image upon return, must be initialized
69  * with the appropriate memory size before calling, dimensions are 512x512 pixels.
70  * @param y Brightness value of the color
71  */
72 void
73 ColorModel::uv_to_image(unsigned char *yuv422_planar_buffer, unsigned int y)
74 {
75  unsigned char *yp = yuv422_planar_buffer;
76  unsigned char *up = YUV422_PLANAR_U_PLANE(yuv422_planar_buffer, 512, 512);
77  unsigned char *vp = YUV422_PLANAR_V_PLANE(yuv422_planar_buffer, 512, 512);
78 
79  YUV_t c;
80  for (unsigned int v = 256; v > 0 ; --v) {
81  for (unsigned int u = 0; u < 256; ++u) {
83 
84  *yp++ = c.Y;
85  *yp++ = c.Y;
86  *up++ = c.U;
87  *vp++ = c.V;
88  }
89  // Double line
90  memcpy(yp, (yp - 512), 512);
91  yp += 512;
92  memcpy(up, (up - 256), 256);
93  memcpy(vp, (vp - 256), 256);
94  up += 256;
95  vp += 256;
96  }
97 }
98 
99 } // end namespace firevision
unsigned char V
V component.
Definition: yuv.h:62
unsigned char Y
Y component.
Definition: yuv.h:60
virtual ~ColorModel()
Virtual empty destructor.
Definition: colormodel.cpp:55
virtual void uv_to_image(unsigned char *yuv422_planar_buffer, unsigned int y)
Create image from color model.
Definition: colormodel.cpp:73
unsigned char U
U component.
Definition: yuv.h:61
YUV pixel.
Definition: yuv.h:59
static YUV_t get_color(color_t color)
YUV_t getter.
virtual color_t determine(unsigned int y, unsigned int u, unsigned int v) const =0
Determine classification of YUV pixel.