yuvcm.h

00001
00002 /**************************************************************************
00003  *  yuvcm.h - YUV colormap
00004  *
00005  *  Created: Sat Mar 29 12:45:29 2008
00006  *  Copyright  2005-2008  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 #ifndef __FIREVISION_FVUTILS_COLORMAP_YUVCM_H_
00025 #define __FIREVISION_FVUTILS_COLORMAP_YUVCM_H_
00026 
00027 #include <fvutils/colormap/colormap.h>
00028
00029 #include <sys/types.h>
00030 #include <fvutils/base/types.h>
00031
00032 class SharedMemoryLookupTable;
00033
00034 class YuvColormap : public Colormap
00035 {
00036  public:
00037   YuvColormap(unsigned int depth = 1, unsigned int width = 256, unsigned int height = 256);
00038   YuvColormap(const char *shmem_lut_id, unsigned int depth = 1, unsigned int width = 256, unsigned int height = 256);
00039   YuvColormap(const char *shmem_lut_id, bool destroy_on_free, unsigned int depth = 1, unsigned int width = 256, unsigned int height = 256);
00040   YuvColormap(YuvColormap *cm, const char *shmem_lut_id, bool destroy_on_free = false);
00041   virtual ~YuvColormap();
00042
00043   virtual color_t          determine(unsigned int y, unsigned int u, unsigned int v) const;
00044   virtual void             set(unsigned int y, unsigned int u, unsigned int v, color_t c);
00045
00046   virtual void             reset();
00047   virtual void             set(unsigned char *buffer);
00048
00049   virtual size_t           size();
00050
00051   virtual unsigned char *  get_buffer() const;
00052
00053   virtual Colormap &  operator+=(const Colormap & cmlt);
00054   virtual Colormap &  operator+=(const char *filename);
00055   virtual Colormap &  operator=(const YuvColormap &yuvcm);
00056
00057   virtual unsigned int     width() const;
00058   virtual unsigned int     height() const;
00059   virtual unsigned int     depth() const;
00060   virtual unsigned int     deepness() const;
00061   unsigned int             plane_size() const;
00062
00063   virtual std::list<ColormapFileBlock *>  get_blocks();
00064
00065   void copy_uvplane(unsigned char *uvplane, unsigned int level);
00066
00067  private:
00068   void constructor(unsigned int depth, unsigned int width, unsigned int height,
00069                    const char *shmem_lut_id = 0, bool destroy_on_free = false);
00070
00071
00072   SharedMemoryLookupTable *__shm_lut;
00073   unsigned char *__lut;
00074   size_t         __lut_size;
00075
00076   unsigned int __width;
00077   unsigned int __height;
00078   unsigned int __depth;
00079   unsigned int __depth_div;
00080   unsigned int __width_div;
00081   unsigned int __height_div;
00082   unsigned int __plane_size;
00083 };
00084
00085
00086 inline color_t
00087 YuvColormap::determine(unsigned int y, unsigned int u, unsigned int v) const
00088 {
00089   return (color_t) *(__lut + (y / __depth_div) * __plane_size + (v / __height_div) * __width + (u / __width_div));
00090 }
00091
00092 #endif