##

Image.hh
Go to the documentation of this file.
/*
* Copyright (C) 2012 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/* Desc: Image class
* Author: Nate Koenig
* Date: 14 July 2008
*/
#ifndef _IMAGE_HH_
#define _IMAGE_HH_
#include <string>
#include <ignition/math/Color.hh>
#include "gazebo/common/Color.hh"
#include "gazebo/util/system.hh"
struct FIBITMAP;
namespace gazebo
{
namespace common
{
static std::string PixelFormatNames[] =
{
"UNKNOWN_PIXEL_FORMAT",
"L_INT8",
"L_INT16",
"RGB_INT8",
"RGBA_INT8",
"BGRA_INT8",
"RGB_INT16",
"RGB_INT32",
"BGR_INT8",
"BGR_INT16",
"BGR_INT32",
"R_FLOAT16",
"RGB_FLOAT16",
"R_FLOAT32",
"RGB_FLOAT32",
"BAYER_RGGB8",
"BAYER_RGGR8",
"BAYER_GBRG8",
"BAYER_GRBG8"
};
class GZ_COMMON_VISIBLE Image
{
public: enum PixelFormat
{
UNKNOWN_PIXEL_FORMAT = 0,
L_INT8,
L_INT16,
RGB_INT8,
RGBA_INT8,
BGRA_INT8,
RGB_INT16,
RGB_INT32,
BGR_INT8,
BGR_INT16,
BGR_INT32,
R_FLOAT16,
RGB_FLOAT16,
R_FLOAT32,
RGB_FLOAT32,
BAYER_RGGB8,
BAYER_RGGR8,
BAYER_GBRG8,
BAYER_GRBG8,
PIXEL_FORMAT_COUNT
};
public: static Image::PixelFormat ConvertPixelFormat(
const std::string &_format);
public: explicit Image(const std::string &_filename="");
public: virtual ~Image();
public: int Load(const std::string &_filename);
public: void SavePNG(const std::string &_filename);
public: void SetFromData(const unsigned char *_data,
unsigned int _width,
unsigned int _height,
Image::PixelFormat _format);
public: void GetData(unsigned char **_data,
unsigned int &_count) const;
public: void GetRGBData(unsigned char **_data,
unsigned int &_count) const;
public: unsigned int GetWidth() const;
public: unsigned int GetHeight() const;
public: unsigned int GetBPP() const;
// \brief Get the size of a row of pixel
public: int GetPitch() const;
public: std::string GetFilename() const;
public: PixelFormat GetPixelFormat() const;
public: Color GetPixel(unsigned int _x, unsigned int _y) const
GAZEBO_DEPRECATED(9.0);
public: ignition::math::Color Pixel(const unsigned int _x,
const unsigned int _y) const;
public: Color GetAvgColor() GAZEBO_DEPRECATED(9.0);
public: ignition::math::Color AvgColor();
public: Color GetMaxColor() const GAZEBO_DEPRECATED(9.0);
public: ignition::math::Color MaxColor() const;
public: void Rescale(int _width, int _height);
public: bool Valid() const;
private: void GetDataImpl(unsigned char **_data, unsigned int &_count,
FIBITMAP *_img) const;
private: static int count;
private: FIBITMAP *bitmap;
private: std::string fullName;
};
}
}
#endif
gazebo::common::Image::AvgColor
ignition::math::Color AvgColor()
Get the average color.
gazebo::common::Image::GetBPP
unsigned int GetBPP() const
Get the size of one pixel in bits.
gazebo::common::Image::GetAvgColor
Color GetAvgColor() GAZEBO_DEPRECATED(9.0)
Get the average color.
gazebo::common::Image::Valid
bool Valid() const
Returns whether this is a valid image.
ignition
Definition: Model.hh:40
gazebo
Forward declarations for the common classes.
Definition: Animation.hh:26
gazebo::common::Image::GetPixel
Color GetPixel(unsigned int _x, unsigned int _y) const GAZEBO_DEPRECATED(9.0)
Get a pixel color value.
gazebo::common::Image::R_FLOAT32
Definition: Image.hh:84
gazebo::common::Image::GetRGBData
void GetRGBData(unsigned char **_data, unsigned int &_count) const
Get only the RGB data from the image.
gazebo::common::Image::Image
Image(const std::string &_filename="")
Constructor.
gazebo::common::Image::RGBA_INT8
Definition: Image.hh:75
gazebo::common::Image::BGR_INT16
Definition: Image.hh:80
common
common
Definition: FuelModelDatabase.hh:37
gazebo::common::Image::Rescale
void Rescale(int _width, int _height)
Rescale the image.
gazebo::common::Image::PIXEL_FORMAT_COUNT
Definition: Image.hh:90
gazebo::common::Image::GetData
void GetData(unsigned char **_data, unsigned int &_count) const
Get the image as a data array.
gazebo::common::Image::RGB_INT32
Definition: Image.hh:78
gazebo::common::Image::R_FLOAT16
Definition: Image.hh:82
system.hh
gazebo::common::Image
Encapsulates an image.
Definition: Image.hh:66
gazebo::common::Image::ConvertPixelFormat
static Image::PixelFormat ConvertPixelFormat(const std::string &_format)
Convert a string to a Image::PixelFormat.
gazebo::common::Image::RGB_INT16
Definition: Image.hh:77
gazebo::common::Image::PixelFormat
PixelFormat
Pixel formats enumeration.
Definition: Image.hh:69
gazebo::common::Image::RGB_FLOAT16
Definition: Image.hh:83
gazebo::common::Image::BAYER_GBRG8
Definition: Image.hh:88
Color.hh
gazebo::common::Image::GetMaxColor
Color GetMaxColor() const GAZEBO_DEPRECATED(9.0)
Get the max color.
gazebo::common::Image::BGRA_INT8
Definition: Image.hh:76
gazebo::common::Image::GetPixelFormat
PixelFormat GetPixelFormat() const
Get the pixel format.
gazebo::common::Image::GetFilename
std::string GetFilename() const
Get the full filename of the image.
gazebo::common::Image::L_INT8
Definition: Image.hh:72
gazebo::common::Image::BAYER_RGGR8
Definition: Image.hh:87
gazebo::common::Image::SavePNG
void SavePNG(const std::string &_filename)
Save the image in PNG format.
gazebo::common::Image::L_INT16
Definition: Image.hh:73
gazebo::common::Image::BGR_INT32
Definition: Image.hh:81
gazebo::common::Image::~Image
virtual ~Image()
Destructor.
gazebo::common::Image::BAYER_RGGB8
Definition: Image.hh:86
gazebo::common::Image::BAYER_GRBG8
Definition: Image.hh:89
gazebo::common::Image::BGR_INT8
Definition: Image.hh:79
gazebo::common::Image::UNKNOWN_PIXEL_FORMAT
Definition: Image.hh:71
gazebo::common::Color
Defines a color.
Definition: Color.hh:36
gazebo::common::Image::GetWidth
unsigned int GetWidth() const
Get the width.
gazebo::common::Image::Pixel
ignition::math::Color Pixel(const unsigned int _x, const unsigned int _y) const
Get a pixel color value.
GAZEBO_DEPRECATED
#define GAZEBO_DEPRECATED(version)
Definition: system.hh:328
gazebo::common::Image::GetHeight
unsigned int GetHeight() const
Get the height.
gazebo::common::Image::GetPitch
int GetPitch() const
gazebo::common::Image::SetFromData
void SetFromData(const unsigned char *_data, unsigned int _width, unsigned int _height, Image::PixelFormat _format)
Set the image from raw data.
gazebo::common::PixelFormatNames
static std::string PixelFormatNames[]
String names for the pixel formats.
Definition: Image.hh:41
gazebo::common::Image::Load
int Load(const std::string &_filename)
Load an image.
gazebo::common::Image::MaxColor
ignition::math::Color MaxColor() const
Get the max color.
gazebo::common::Image::RGB_FLOAT32
Definition: Image.hh:85
gazebo::common::Image::RGB_INT8
Definition: Image.hh:74