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 
27 #include <cstring>
28 
29 namespace firevision {
30 
31 /** @class ColorModel <fvmodels/color/colormodel.h>
32  * Color model interface.
33  * This interface defines the API for color models.
34  *
35  * @fn color_t ColorModel::determine(unsigned int y, unsigned int u, unsigned int v) const
36  * Determine classification of YUV pixel.
37  * Given a pixel in the YUV colorspace the colormodel determines the color
38  * classification based on some a-priori knowledge.
39  * @param y Y value
40  * @param u U value
41  * @param v V value
42  * @return color classification
43  *
44  * @fn const char * ColorModel::get_name()
45  * Get name of color model.
46  * @return name of color model.
47  *
48  * @author Tim Niemueller
49  */
50 
51 /** Virtual empty destructor. */
53 {
54 }
55 
56 /** Create image from color model.
57  * Create image from color model, useful for debugging and analysing.
58  * This method produces a representation of the color model for the full U/V plane
59  * at the given value of Y for visual inspection of the colormap.
60  * The dimensions of the resulting image are 512x512 pixels. It uses
61  * strong colors as defined by ColorObjectMap.
62  * Color models may override this method, but they must produce a 512x512
63  * YUV422_PLANAR image.
64  * @param yuv422_planar_buffer contains the image upon return, must be initialized
65  * with the appropriate memory size before calling, dimensions are 512x512 pixels.
66  * @param y Brightness value of the color
67  */
68 void
69 ColorModel::uv_to_image(unsigned char *yuv422_planar_buffer, unsigned int y)
70 {
71  unsigned char *yp = yuv422_planar_buffer;
72  unsigned char *up = YUV422_PLANAR_U_PLANE(yuv422_planar_buffer, 512, 512);
73  unsigned char *vp = YUV422_PLANAR_V_PLANE(yuv422_planar_buffer, 512, 512);
74 
75  YUV_t c;
76  for (unsigned int v = 256; v > 0; --v) {
77  for (unsigned int u = 0; u < 256; ++u) {
79 
80  *yp++ = c.Y;
81  *yp++ = c.Y;
82  *up++ = c.U;
83  *vp++ = c.V;
84  }
85  // Double line
86  memcpy(yp, (yp - 512), 512);
87  yp += 512;
88  memcpy(up, (up - 256), 256);
89  memcpy(vp, (vp - 256), 256);
90  up += 256;
91  vp += 256;
92  }
93 }
94 
95 } // end namespace firevision
unsigned char V
V component.
Definition: yuv.h:61
unsigned char Y
Y component.
Definition: yuv.h:59
virtual ~ColorModel()
Virtual empty destructor.
Definition: colormodel.cpp:52
virtual void uv_to_image(unsigned char *yuv422_planar_buffer, unsigned int y)
Create image from color model.
Definition: colormodel.cpp:69
unsigned char U
U component.
Definition: yuv.h:60
YUV pixel.
Definition: yuv.h:57
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.