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/base/types.h>
28 #include <fvutils/colormap/colormap.h>
29 #include <sys/types.h>
30 
31 namespace firevision {
32 
33 class SharedMemoryLookupTable;
34 
35 class YuvColormap : public Colormap
36 {
37 public:
38  YuvColormap(unsigned int depth = 1, unsigned int width = 256, unsigned int height = 256);
39  YuvColormap(const char * shmem_lut_id,
40  unsigned int depth = 1,
41  unsigned int width = 256,
42  unsigned int height = 256);
43  YuvColormap(const char * shmem_lut_id,
44  bool destroy_on_free,
45  unsigned int depth = 1,
46  unsigned int width = 256,
47  unsigned int height = 256);
48  YuvColormap(YuvColormap *cm, const char *shmem_lut_id, bool destroy_on_free = false);
49  YuvColormap(const YuvColormap &cm);
50  virtual ~YuvColormap();
51 
52  virtual color_t determine(unsigned int y, unsigned int u, unsigned int v) const;
53  virtual void set(unsigned int y, unsigned int u, unsigned int v, color_t c);
54 
55  virtual void reset();
56  virtual void set(unsigned char *buffer);
57 
58  virtual size_t size();
59 
60  virtual unsigned char *get_buffer() const;
61 
62  virtual Colormap &operator+=(const Colormap &cmlt);
63  virtual Colormap &operator+=(const char *filename);
64  virtual Colormap &operator=(const YuvColormap &yuvcm);
65 
66  virtual unsigned int width() const;
67  virtual unsigned int height() const;
68  virtual unsigned int depth() const;
69  virtual unsigned int deepness() const;
70  unsigned int plane_size() const;
71 
72  virtual std::list<ColormapFileBlock *> get_blocks();
73 
74  void copy_uvplane(unsigned char *uvplane, unsigned int level);
75 
76  void replace_color(color_t from, color_t to);
77 
78 private:
79  void constructor(unsigned int depth,
80  unsigned int width,
81  unsigned int height,
82  const char * shmem_lut_id = 0,
83  bool destroy_on_free = false);
84 
85  SharedMemoryLookupTable *shm_lut_;
86  unsigned char * lut_;
87  size_t lut_size_;
88 
89  unsigned int width_;
90  unsigned int height_;
91  unsigned int depth_;
92  unsigned int depth_div_;
93  unsigned int width_div_;
94  unsigned int height_div_;
95  unsigned int plane_size_;
96 };
97 
98 inline color_t
99 YuvColormap::determine(unsigned int y, unsigned int u, unsigned int v) const
100 {
101  return (color_t)
102  * (lut_ + (y / depth_div_) * plane_size_ + (v / height_div_) * width_ + (u / width_div_));
103 }
104 
105 } // end namespace firevision
106 
107 #endif
firevision::YuvColormap::depth
virtual unsigned int depth() const
Definition: yuvcm.cpp:335
firevision::YuvColormap::operator=
virtual Colormap & operator=(const YuvColormap &yuvcm)
Assign operation.
Definition: yuvcm.cpp:295
firevision::YuvColormap::copy_uvplane
void copy_uvplane(unsigned char *uvplane, unsigned int level)
Copy single U/V plane.
Definition: yuvcm.cpp:242
firevision::YuvColormap::reset
virtual void reset()
Definition: yuvcm.cpp:199
firevision::YuvColormap
Definition: yuvcm.h:39
firevision::YuvColormap::plane_size
unsigned int plane_size() const
Get U/V plane size.
Definition: yuvcm.cpp:350
firevision::YuvColormap::get_buffer
virtual unsigned char * get_buffer() const
Definition: yuvcm.cpp:230
firevision::YuvColormap::get_blocks
virtual std::list< ColormapFileBlock * > get_blocks()
Definition: yuvcm.cpp:217
firevision::YuvColormap::width
virtual unsigned int width() const
Definition: yuvcm.cpp:323
firevision::YuvColormap::YuvColormap
YuvColormap(unsigned int depth=1, unsigned int width=256, unsigned int height=256)
Constructor.
Definition: yuvcm.cpp:59
firevision::YuvColormap::replace_color
void replace_color(color_t from, color_t to)
Replace a given color with another one.
Definition: yuvcm.cpp:360
firevision::YuvColormap::operator+=
virtual Colormap & operator+=(const Colormap &cmlt)
Adds the given colormap to this colormap.
Definition: yuvcm.cpp:259
firevision::YuvColormap::height
virtual unsigned int height() const
Definition: yuvcm.cpp:329
firevision::SharedMemoryLookupTable
Definition: shm_lut.h:111
firevision::YuvColormap::size
virtual size_t size()
Definition: yuvcm.cpp:211
firevision::Colormap
Definition: colormap.h:40
firevision::YuvColormap::determine
virtual color_t determine(unsigned int y, unsigned int u, unsigned int v) const
Definition: yuvcm.h:103
firevision::YuvColormap::set
virtual void set(unsigned int y, unsigned int u, unsigned int v, color_t c)
Definition: yuvcm.cpp:193
firevision::YuvColormap::deepness
virtual unsigned int deepness() const
Definition: yuvcm.cpp:341
firevision::YuvColormap::~YuvColormap
virtual ~YuvColormap()
Destructor.
Definition: yuvcm.cpp:181