Fawkes API  Fawkes Development Version
cmfile_yuvblock.cpp
1 
2 /**************************************************************************
3  * cmfile_yuvblock.cpp - FVFF Colormap File YUV Block
4  *
5  * Created: Mon Mar 31 18:10:01 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 #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 
29 #include <cstring>
30 
31 namespace firevision {
32 
33 /** @class ColormapFileYuvBlock <fvutils/colormap/cmfile_yuvblock.h>
34  * YUV block for colormap file.
35  * @author Tim Niemueller
36  */
37 
38 /** Constructor.
39  * @param cm YUV colormap that this block shall represent.
40  * @param level Y level
41  */
43 : ColormapFileBlock(CMFILE_TYPE_YUV, cm->plane_size(), sizeof(cmfile_yuvblock_header_t))
44 {
45  if (level > cm->depth()) {
46  throw fawkes::OutOfBoundsException("YuvColormap level is out of bounds", level, 0, cm->depth());
47  }
48 
49  cm_ = cm;
50  level_ = level;
51 
53  header_->range_from = level * cm->deepness() / cm->depth();
54  header_->range_to = ((level + 1) * cm->deepness() / cm->depth()) - 1;
55 
56  memcpy(_data, cm_->get_buffer() + level * cm->plane_size(), _data_size);
57 }
58 
59 /** Copy Constructor.
60  * It is assumed that the block actually is a rectification LUT info block. Check that
61  * before calling this method.
62  * @param block block to copy
63  */
65 : ColormapFileBlock(block)
66 {
68 }
69 
70 /** Range from value.
71  * @return range from value
72  */
73 unsigned int
75 {
76  return header_->range_from;
77 }
78 
79 /** Range to value.
80  * @return range to value
81  */
82 unsigned int
84 {
85  return header_->range_to;
86 }
87 
88 } // end namespace firevision
virtual unsigned int deepness() const
Get deepness of colormap.
Definition: yuvcm.cpp:342
void * _data
Pointer to the internal data segment.
Definition: fvfile_block.h:54
unsigned int range_from() const
Range from value.
FireVision File Format data block.
Definition: fvfile_block.h:33
ColormapFileYuvBlock(YuvColormap *cm, unsigned int level=0)
Constructor.
YUV Colormap.
Definition: yuvcm.h:35
unsigned int range_to() const
Range to value.
void * _spec_header
Pointer to the content specific block header.
Definition: fvfile_block.h:56
FireVision data file block for colormap files.
Definition: cmfile_block.h:33
virtual unsigned char * get_buffer() const
Get the raw buffer of this colormap.
Definition: yuvcm.cpp:231
Block header for a YUV block in a ColormapFile.
virtual unsigned int depth() const
Get depth of colormap.
Definition: yuvcm.cpp:336
Index out of bounds.
Definition: software.h:85
size_t _data_size
Size of _data in bytes.
Definition: fvfile_block.h:55
unsigned int plane_size() const
Get U/V plane size.
Definition: yuvcm.cpp:351