24 #include <fvutils/colormap/yuvcm.h>
26 #include <fvutils/colormap/cmfile.h>
27 #include <fvutils/colormap/cmfile_yuvblock.h>
28 #include <fvutils/ipc/shm_lut.h>
29 #include <core/exceptions/software.h>
34 using namespace fawkes;
36 namespace firevision {
64 YuvColormap::YuvColormap(
unsigned int depth,
unsigned int width,
unsigned int height)
66 constructor(depth, width, height);
77 YuvColormap::YuvColormap(
const char *shmem_lut_id,
unsigned int depth,
unsigned int width,
unsigned int height)
79 constructor(depth, width, height, shmem_lut_id);
91 YuvColormap::YuvColormap(
const char *shmem_lut_id,
bool destroy_on_free,
unsigned int depth,
unsigned int width,
unsigned int height)
93 constructor(depth, width, height, shmem_lut_id, destroy_on_free);
104 YuvColormap::YuvColormap(
YuvColormap *cm,
const char *shmem_lut_id,
bool destroy_on_free)
106 constructor(cm->
depth(), cm->
width(), cm->
height(), shmem_lut_id, destroy_on_free);
107 memcpy(__lut, cm->__lut, __lut_size);
119 YuvColormap::constructor(
unsigned int depth,
unsigned int width,
unsigned int height,
120 const char *shmem_lut_id,
bool destroy_on_free)
125 if ( (depth != 1) && (depth != 2) && (depth != 4) && (depth != 8) && (depth != 16) &&
126 (depth != 32) && (depth != 64) && (depth != 128) && (depth != 256) ) {
133 if ( (width != 1) && (width != 2) && (width != 4) && (width != 8) && (width != 16) &&
134 (width != 32) && (width != 64) && (width != 128) && (width != 256) ) {
138 if ( height > 256 ) {
141 if ( (height != 1) && (height != 2) && (height != 4) && (height != 8) && (height != 16) &&
142 (height != 32) && (height != 64) && (height != 128) && (height != 256) ) {
149 __depth_div = 256 / __depth;
150 __width_div = 256 / __width;
151 __height_div = 256 / __height;
152 __plane_size = __width * __height;
154 if ( shmem_lut_id != NULL ) {
155 __shm_lut =
new SharedMemoryLookupTable(shmem_lut_id, __width, __height, __depth, 1);
156 __shm_lut->set_destroy_on_delete( destroy_on_free );
157 __lut = __shm_lut->buffer();
158 __lut_size = __shm_lut->data_size();
161 __lut_size = __width * __height * __depth;
162 __lut = (
unsigned char *)malloc( __lut_size );
164 memset(__lut, C_OTHER, __lut_size);
169 YuvColormap::~YuvColormap()
182 YuvColormap::set(
unsigned int y,
unsigned int u,
unsigned int v, color_t c)
184 *(__lut + (y / __depth_div) * __plane_size + (v / __height_div) * __width + (u / __width_div)) = c;
191 memset(__lut, C_OTHER, __lut_size);
196 YuvColormap::set(
unsigned char *buffer)
198 memcpy(__lut, buffer, __lut_size);
209 std::list<ColormapFileBlock *>
210 YuvColormap::get_blocks()
212 std::list<ColormapFileBlock *> rv;
214 for (
unsigned int i = 0; i < __depth; ++i) {
224 YuvColormap::get_buffer()
const
237 YuvColormap::copy_uvplane(
unsigned char *uvplane,
unsigned int level)
239 if ( level > __depth ) {
243 memcpy(__lut + level * __plane_size, uvplane, __plane_size);
262 if ( (__width != tc->__width) || (__height != tc->__height) || (__depth != tc->__depth) ) {
266 unsigned char *this_lut = __lut;
267 unsigned char *other_lut = tc->__lut;
269 for (
unsigned int i = 0; i < __plane_size * __depth; ++i) {
270 if ( (*this_lut == C_OTHER) || (*this_lut == C_BACKGROUND) ) {
272 if ( (*other_lut != C_OTHER) && (*other_lut != C_BACKGROUND) ) {
274 *this_lut = *other_lut;
294 if ( __lut_size != yuvcm.__lut_size ) {
298 memcpy(__lut, yuvcm.__lut, __lut_size);
305 YuvColormap::operator+=(
const char *filename)
322 YuvColormap::width()
const
329 YuvColormap::height()
const
336 YuvColormap::depth()
const
343 YuvColormap::deepness()
const
353 YuvColormap::plane_size()
const
364 YuvColormap::replace_color(color_t from, color_t to)
366 unsigned char *this_lut = __lut;
368 for (
unsigned int i = 0; i < __plane_size * __depth; ++i, ++this_lut) {
369 if (*this_lut == from) *this_lut = to;
virtual unsigned int width() const
Get width of colormap.
virtual unsigned int height() const
Get height of colormap.
virtual unsigned int depth() const
Get depth of colormap.
YUV block for colormap file.
Colormap * get_colormap()
Get a freshly generated colormap based on current file content.
virtual void read(const char *file_name)
Read file.
Expected parameter is missing.