Fawkes API  Fawkes Development Version
yuvcm.h
1 
2 /**************************************************************************
3  * yuvcm.h - YUV colormap
4  *
5  * Created: Sat Mar 29 12:45:29 2008
6  * Copyright 2005-2008 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 #ifndef __FIREVISION_FVUTILS_COLORMAP_YUVCM_H_
25 #define __FIREVISION_FVUTILS_COLORMAP_YUVCM_H_
26 
27 #include <fvutils/colormap/colormap.h>
28 
29 #include <sys/types.h>
30 #include <fvutils/base/types.h>
31 
32 namespace firevision {
33 #if 0 /* just to make Emacs auto-indent happy */
34 }
35 #endif
36 
37 class SharedMemoryLookupTable;
38 
39 class YuvColormap : public Colormap
40 {
41  public:
42  YuvColormap(unsigned int depth = 1, unsigned int width = 256, unsigned int height = 256);
43  YuvColormap(const char *shmem_lut_id, unsigned int depth = 1, unsigned int width = 256, unsigned int height = 256);
44  YuvColormap(const char *shmem_lut_id, bool destroy_on_free, unsigned int depth = 1, unsigned int width = 256, unsigned int height = 256);
45  YuvColormap(YuvColormap *cm, const char *shmem_lut_id, bool destroy_on_free = false);
46  virtual ~YuvColormap();
47 
48  virtual color_t determine(unsigned int y, unsigned int u, unsigned int v) const;
49  virtual void set(unsigned int y, unsigned int u, unsigned int v, color_t c);
50 
51  virtual void reset();
52  virtual void set(unsigned char *buffer);
53 
54  virtual size_t size();
55 
56  virtual unsigned char * get_buffer() const;
57 
58  virtual Colormap & operator+=(const Colormap & cmlt);
59  virtual Colormap & operator+=(const char *filename);
60  virtual Colormap & operator=(const YuvColormap &yuvcm);
61 
62  virtual unsigned int width() const;
63  virtual unsigned int height() const;
64  virtual unsigned int depth() const;
65  virtual unsigned int deepness() const;
66  unsigned int plane_size() const;
67 
68  virtual std::list<ColormapFileBlock *> get_blocks();
69 
70  void copy_uvplane(unsigned char *uvplane, unsigned int level);
71 
72  void replace_color(color_t from, color_t to);
73 
74  private:
75  void constructor(unsigned int depth, unsigned int width, unsigned int height,
76  const char *shmem_lut_id = 0, bool destroy_on_free = false);
77 
78 
79  SharedMemoryLookupTable *__shm_lut;
80  unsigned char *__lut;
81  size_t __lut_size;
82 
83  unsigned int __width;
84  unsigned int __height;
85  unsigned int __depth;
86  unsigned int __depth_div;
87  unsigned int __width_div;
88  unsigned int __height_div;
89  unsigned int __plane_size;
90 };
91 
92 
93 inline color_t
94 YuvColormap::determine(unsigned int y, unsigned int u, unsigned int v) const
95 {
96  return (color_t) *(__lut + (y / __depth_div) * __plane_size + (v / __height_div) * __width + (u / __width_div));
97 }
98 
99 } // end namespace firevision
100 
101 #endif
virtual Colormap & operator=(const YuvColormap &yuvcm)
Assign operation.
Definition: yuvcm.cpp:292
virtual unsigned int deepness() const
Get deepness of colormap.
Definition: yuvcm.cpp:343
virtual unsigned int width() const
Get width of colormap.
Definition: yuvcm.cpp:322
YuvColormap(unsigned int depth=1, unsigned int width=256, unsigned int height=256)
Constructor.
Definition: yuvcm.cpp:64
void copy_uvplane(unsigned char *uvplane, unsigned int level)
Copy single U/V plane.
Definition: yuvcm.cpp:237
Colormap interface.
Definition: colormap.h:38
YUV Colormap.
Definition: yuvcm.h:39
virtual std::list< ColormapFileBlock * > get_blocks()
Get file blocks for this colormap.
Definition: yuvcm.cpp:210
virtual ~YuvColormap()
Destructor.
Definition: yuvcm.cpp:169
virtual unsigned char * get_buffer() const
Get the raw buffer of this colormap.
Definition: yuvcm.cpp:224
virtual unsigned int depth() const
Get depth of colormap.
Definition: yuvcm.cpp:336
virtual color_t determine(unsigned int y, unsigned int u, unsigned int v) const
Determine color class for given YUV value.
Definition: yuvcm.h:94
virtual void reset()
Reset colormap.
Definition: yuvcm.cpp:189
void replace_color(color_t from, color_t to)
Replace a given color with another one.
Definition: yuvcm.cpp:364
virtual size_t size()
Size in bytes of buffer returned by get_buffer().
Definition: yuvcm.cpp:203
virtual unsigned int height() const
Get height of colormap.
Definition: yuvcm.cpp:329
Shared memory lookup table.
Definition: shm_lut.h:113
unsigned int plane_size() const
Get U/V plane size.
Definition: yuvcm.cpp:353
virtual Colormap & operator+=(const Colormap &cmlt)
Adds the given colormap to this colormap.
Definition: yuvcm.cpp:255