24 #include <core/exceptions/software.h>
25 #include <fvutils/colormap/cmfile.h>
26 #include <fvutils/colormap/cmfile_yuvblock.h>
27 #include <fvutils/colormap/yuvcm.h>
28 #include <fvutils/ipc/shm_lut.h>
35 namespace firevision {
60 YuvColormap::YuvColormap(
unsigned int depth,
unsigned int width,
unsigned int height)
62 constructor(depth, width, height);
72 YuvColormap::YuvColormap(
const char * shmem_lut_id,
77 constructor(depth, width, height, shmem_lut_id);
88 YuvColormap::YuvColormap(
const char * shmem_lut_id,
94 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_);
118 memcpy(lut_, cm.lut_, lut_size_);
129 YuvColormap::constructor(
unsigned int depth,
132 const char * shmem_lut_id,
133 bool destroy_on_free)
138 if ((depth != 1) && (depth != 2) && (depth != 4) && (depth != 8) && (depth != 16) && (depth != 32)
139 && (depth != 64) && (depth != 128) && (depth != 256)) {
146 if ((width != 1) && (width != 2) && (width != 4) && (width != 8) && (width != 16) && (width != 32)
147 && (width != 64) && (width != 128) && (width != 256)) {
154 if ((height != 1) && (height != 2) && (height != 4) && (height != 8) && (height != 16)
155 && (height != 32) && (height != 64) && (height != 128) && (height != 256)) {
162 depth_div_ = 256 / depth_;
163 width_div_ = 256 / width_;
164 height_div_ = 256 / height_;
165 plane_size_ = width_ * height_;
167 if (shmem_lut_id != NULL) {
169 new SharedMemoryLookupTable(shmem_lut_id, width_, height_, depth_, 1);
170 shm_lut_->set_destroy_on_delete(destroy_on_free);
171 lut_ = shm_lut_->buffer();
172 lut_size_ = shm_lut_->data_size();
175 lut_size_ = (size_t)width_ * (
size_t)height_ * (size_t)depth_;
176 lut_ = (
unsigned char *)malloc(lut_size_);
178 memset(lut_, C_OTHER, lut_size_);
182 YuvColormap::~YuvColormap()
194 YuvColormap::set(
unsigned int y,
unsigned int u,
unsigned int v, color_t c)
196 *(lut_ + (y / depth_div_) * plane_size_ + (v / height_div_) * width_ + (u / width_div_)) = c;
202 memset(lut_, C_OTHER, lut_size_);
206 YuvColormap::set(
unsigned char *buffer)
208 memcpy(lut_, buffer, lut_size_);
217 std::list<ColormapFileBlock *>
218 YuvColormap::get_blocks()
220 std::list<ColormapFileBlock *> rv;
222 for (
unsigned int i = 0; i < depth_; ++i) {
231 YuvColormap::get_buffer()
const
243 YuvColormap::copy_uvplane(
unsigned char *uvplane,
unsigned int level)
245 if (level > depth_) {
249 memcpy(lut_ + level * plane_size_, uvplane, plane_size_);
267 if ((width_ != tc->width_) || (height_ != tc->height_) || (depth_ != tc->depth_)) {
271 unsigned char *this_lut = lut_;
272 unsigned char *other_lut = tc->lut_;
274 for (
unsigned int i = 0; i < plane_size_ * depth_; ++i) {
275 if ((*this_lut == C_OTHER) || (*this_lut == C_BACKGROUND)) {
277 if ((*other_lut != C_OTHER) && (*other_lut != C_BACKGROUND)) {
279 *this_lut = *other_lut;
298 if (lut_size_ != yuvcm.lut_size_) {
302 memcpy(lut_, yuvcm.lut_, lut_size_);
308 YuvColormap::operator+=(
const char *filename)
324 YuvColormap::width()
const
330 YuvColormap::height()
const
336 YuvColormap::depth()
const
342 YuvColormap::deepness()
const
351 YuvColormap::plane_size()
const
361 YuvColormap::replace_color(color_t from, color_t to)
363 unsigned char *this_lut = lut_;
365 for (
unsigned int i = 0; i < plane_size_ * depth_; ++i, ++this_lut) {
366 if (*this_lut == from)
Expected parameter is missing.
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.
virtual unsigned int height() const
Get height of colormap.
virtual unsigned int depth() const
Get depth of colormap.
virtual unsigned int width() const
Get width of colormap.
Fawkes library namespace.