cmfile_yuvblock.cpp

00001
00002 /**************************************************************************
00003  *  cmfile_yuvblock.cpp - FVFF Colormap File YUV Block
00004  *
00005  *  Created: Mon Mar 31 18:10:01 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 #include <fvutils/colormap/cmfile_yuvblock.h>
00025 #include <fvutils/colormap/cmfile.h>
00026 #include <fvutils/colormap/yuvcm.h>
00027
00028 #include <core/exceptions/software.h>
00029 #include <cstring>
00030 
00031 /** @class ColormapFileYuvBlock <fvutils/colormap/cmfile_yuvblock.h>
00032  * YUV block for colormap file.
00033  * @author Tim Niemueller
00034  */
00035 
00036 /** Constructor.
00037  * @param cm YUV colormap that this block shall represent.
00038  * @param level Y level
00039  */
00040 ColormapFileYuvBlock::ColormapFileYuvBlock(YuvColormap *cm, unsigned int level)
00041   : ColormapFileBlock(CMFILE_TYPE_YUV, cm->plane_size(), sizeof(cmfile_yuvblock_header_t))
00042 {
00043   if ( level > cm->depth() ) {
00044     throw fawkes::OutOfBoundsException("YuvColormap level is out of bounds", level, 0, cm->depth());
00045   }
00046
00047   __cm    = cm;
00048   __level = level;
00049
00050   __header = (cmfile_yuvblock_header_t *)_spec_header;
00051   __header->range_from = level * cm->deepness() / cm->depth();
00052   __header->range_to   = ((level + 1) * cm->deepness() / cm->depth()) - 1;
00053
00054   memcpy(_data, __cm->get_buffer() + level * cm->plane_size(), _data_size);
00055 }
00056
00057 
00058 /** Copy Constructor.
00059  * It is assumed that the block actually is a rectification LUT info block. Check that
00060  * before calling this method.
00061  * @param block block to copy
00062  */
00063 ColormapFileYuvBlock::ColormapFileYuvBlock(FireVisionDataFileBlock *block)
00064   : ColormapFileBlock(block)
00065 {
00066   __header = (cmfile_yuvblock_header_t *)_spec_header;
00067 }
00068
00069 
00070 /** Range from value.
00071  * @return range from value
00072  */
00073 unsigned int
00074 ColormapFileYuvBlock::range_from() const
00075 {
00076   return __header->range_from;
00077 }
00078
00079 
00080 /** Range to value.
00081  * @return range to value
00082  */
00083 unsigned int
00084 ColormapFileYuvBlock::range_to() const
00085 {
00086   return __header->range_to;
00087 }