Update of /cvsroot/robotflow/RobotFlow/Vision/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14574
Added Files:
RGB5552RGB24.cc
Log Message:
RGB555 to RGB24 color space conversion.
--- NEW FILE: RGB5552RGB24.cc ---
/* Copyright (C) 2004 Pierre Moisan (Pie...@US...)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _RGB5552RGB24_CC_
#define _RGB5552RGB24_CC_
#include "BufferedNode.h"
#include "Image.h"
using namespace std;
using namespace FD;
namespace RobotFlow {
class RGB5552RGB24;
DECLARE_NODE(RGB5552RGB24)
/*Node
*
* @name RGB5552RGB24
* @category RobotFlow:Vision
* @description Simple conversion from RGB555 color format to RGB24 color format.
*
* @input_name RGB555IMAGE
* @input_type Image
* @input_description RGB555 image
*
* @output_name RGB24IMAGE
* @output_type IMAGE
* @output_description RGB24 image
*
END*/
class RGB5552RGB24 : public BufferedNode {
int m_imageInID;
int m_imageOutID;
unsigned char m_red_conversion_table[32768];
unsigned char m_green_conversion_table[32768];
unsigned char m_blue_conversion_table[32768];
public:
RGB5552RGB24(string nodeName, ParameterSet params)
: BufferedNode(nodeName, params)
{
m_imageInID = addInput("RGB555IMAGE");
m_imageOutID = addOutput("RGB24IMAGE");
build_table();
}
void calculate(int output_id, int count, Buffer &out)
{
Image &input_image = object_cast<Image>(getInput(m_imageInID,count));
int width = input_image.get_width();
int height = input_image.get_height();
unsigned short* input_data = (unsigned short*) input_image.get_data();
//creating new image (rgb24)
Image *output_image = Image::alloc(width,height,3);
unsigned char* output_data = output_image->get_data();
//copying data
for (unsigned int i = 0; i < width * height; i++) {
*output_data++ = m_blue_conversion_table[*input_data];
*output_data++ = m_green_conversion_table[*input_data];
*output_data++ = m_red_conversion_table[*input_data];
*input_data++;
}
out[count] = ObjectRef(output_image);
}//calculate
private:
void build_table () {
for (unsigned int i = 0; i < 32768; i++) {
float red = ((float)((i >> 10) & 0x1f)) / 31.0;
float green = ((float)((i >> 5) & 0x1f)) / 31.0;
float blue = ((float)(i & 0x1f)) / 31.0;
m_red_conversion_table[i] = (unsigned char) (red * 255.0);
m_green_conversion_table[i] = (unsigned char) (green * 255.0);
m_blue_conversion_table[i] = (unsigned char) (blue * 255.0);
}
}//build_table
};
}
#endif
|