#include <archon/util/image.H>
Collaboration diagram for Archon::Utilities::Image:
Public Types | |
enum | ComponentSpecifier { components_l = 1, components_la = 2, components_rgb = 3, components_rgba = 4 } |
Public Member Functions | |
operator bool () const | |
Returns true unless the image is a null image. | |
Image () | |
Create a special null image. | |
Image (unsigned width, unsigned height, ComponentSpecifier components=components_rgba, unsigned bitsPerComponent=8, string comment="") | |
Create an image with an uninitialized pixel buffer. | |
unsigned | getWidth () const |
unsigned | getHeight () const |
unsigned | getBitsPerComponent () const |
unsigned | getCharsPerPixel () const |
unsigned | getCharsPerRow () const |
unsigned | getMaxComponentValue () const |
ComponentSpecifier | getComponentSpecifier () const |
string | getComment () const |
Fetch the image comment. | |
void | setComment (string c) |
Set a new image comment. | |
const char * | getPixelBuffer () const |
char * | getPixelBuffer () |
const char * | getPixelPtr (int x, int y) const |
char * | getPixelPtr (int x, int y) |
void | getPixel (int x, int y, unsigned &l) const |
void | setPixel (int x, int y, unsigned l) |
void | getPixel (int x, int y, unsigned &l, unsigned &a) const |
void | setPixel (int x, int y, unsigned l, unsigned a) |
void | getPixel (int x, int y, unsigned &r, unsigned &g, unsigned &b) const |
void | setPixel (int x, int y, unsigned r, unsigned g, unsigned b) |
void | getPixel (int x, int y, unsigned &r, unsigned &g, unsigned &b, unsigned &a) const |
void | setPixel (int x, int y, unsigned r, unsigned g, unsigned b, unsigned a) |
void | getPixel (int x, int y, double &l) const |
void | setPixel (int x, int y, double l) |
void | getPixel (int x, int y, double &l, double &a) const |
void | setPixel (int x, int y, double l, double a) |
void | getPixel (int x, int y, double &r, double &g, double &b) const |
void | setPixel (int x, int y, double r, double g, double b) |
void | getPixel (int x, int y, double &r, double &g, double &b, double &a) const |
void | setPixel (int x, int y, double r, double g, double b, double a) |
void | swap (Image &i) |
Efficient swapping that avoids access to the referenced object, in particular, its reference count. | |
Image (Ref< Stream::Reader > r, string sourceName, string formatSpecifier="", Logger *l=Logger::get(), const Context *c=0) throw (UnknownFormatException, InvalidFormatException, IOException, UnexpectedException) | |
Load an image from the specified reader. | |
Image (string filePath, string formatSpecifier="", Logger *l=Logger::get(), const Context *c=0) throw (UnknownFormatException, InvalidFormatException, IOException, UnexpectedException) | |
Load an image from the specified file. | |
void | load (Ref< Stream::Reader > r, string sourceName, string formatSpecifier="", ProgressTracker *t=0, Logger *l=Logger::get(), const Context *c=0) throw (UnknownFormatException, InvalidFormatException, IOException, UnexpectedException) |
Load an image from the specified reader. | |
void | load (string filePath, string formatSpecifier="", ProgressTracker *t=0, Logger *l=Logger::get(), const Context *c=0) throw (UnknownFormatException, InvalidFormatException, IOException, UnexpectedException) |
Load in image from the specified file. | |
void | save (Ref< Stream::Writer > w, string targetName, string formatSpecifier="", ProgressTracker *t=0, Logger *l=Logger::get(), const Context *c=0) const throw (UnknownFormatException, IOException, UnexpectedException) |
If an empty format specifier is passed the format is determined by the suffix of the target name. | |
void | save (string filePath, string formatSpecifier="", ProgressTracker *t=0, Logger *l=Logger::get(), const Context *c=0) const throw (UnknownFormatException, IOException, UnexpectedException) |
If an empty format specifier is passed the format is determined by the suffix of the file name. | |
Static Public Attributes | |
static const string | PNG = "png" |
Specifier for PNG format. | |
static const string | TIFF = "tiff" |
Specifier for TIFF format. | |
static const string | PNM = "pnm" |
Specifier for PNM format. | |
static const string | JPEG = "jpeg" |
Specifier for JPEG format. | |
static const string | GIF = "gif" |
Specifier for GIF format. | |
Classes | |
struct | Context |
Holds the list of known image formats. More... | |
struct | Format |
This class represents one single image format. More... | |
struct | ImageException |
struct | InvalidFormatException |
The image file contents is corrupt or of a different format than the one selected. More... | |
struct | ProgressTracker |
struct | Rep |
struct | UnknownFormatException |
Image format could not be detected. More... |
The class comes with a comprehensive set of manipulation functions and is able to read and write image files in various well-known image file formats such as PNG, JPEG and GIF.
This class offers direct access to the memory buffer holding the pixels. Pixels are stored in row major order starting with the left most pixel of the bottom most row. Pixel coordinates (x,y) should likewise be understood such that (0,0) is at the lower left corner of the image.
Each pixel consists of 1 or more chars. Each new pixel always starts on a char boundary (i.e. pixels are char aligned.)
There are two parameters of the Image that determine just how many chars are used per pixel: The number of components per pixel and the number of bits per component.
A pixel consistst of 1, 2, 3 or 4 components (or channels). The specific interpretation of the components is a function of the number as follows:
Number of components Interpretation (in given order) ----------------------------------------------- 1 L Luminance 2 LA Luminance, alpha 3 RGB Red, green, blue 4 RGBA Red, green, blue, alpha
Each component (or channel) consists of 1, 2, 4, 8, or 16 bits.
Assuming that chars are 8 bit wide we could have up to 8 chars per pixel. Assuming further the the target system is a little-endian system such as the Intel x86 family, we get the following pixel layouts:
Chars per Address offset Configuration pixel 3 2 1 0 ------------------------------------------------------------------ L(1) 1 0000000l L(2) 1 000000ll L(4) 1 0000llll L(8) 1 llllllll L(16) 2 LLLLLLLL llllllll
LA(1) 1 000000al LA(2) 1 0000aall LA(4) 1 aaaallll LA(8) 2 aaaaaaaa llllllll LA(16) 4 AAAAAAAA aaaaaaaa LLLLLLLL llllllll
RGB(1) 1 00000bgr RGB(2) 1 00bbggrr RGB(4) 2 0000bbbb ggggrrrr RGB(8) 3 bbbbbbbb gggggggg rrrrrrrr RGB(16) 6 ... GGGGGGGG gggggggg RRRRRRRR rrrrrrrr
RGBA(1) 1 0000abgr RGBA(2) 1 aabbggrr RGBA(4) 2 aaaabbbb ggggrrrr RGBA(8) 4 aaaaaaaa bbbbbbbb gggggggg rrrrrrrr RGBA(16) 8 ... GGGGGGGG gggggggg RRRRRRRR rrrrrrrr
Where capital letters indicate MBS (most significant byte.) On a big-endian system such as the PPC family seen in Macs we would for instance get this instead:
Chars per Address offset Configuration pixel 3 2 1 0 ------------------------------------------------------------------ LA(16) 4 aaaaaaaa AAAAAAAA llllllll LLLLLLLL
So please note that the exact byte ordering of the pixel buffer used in this class is not entirely fixed. It depends on the endianness of the platform.
Definition at line 143 of file image.H.
|
|
|
Create a special null image. A null image has no pixel buffer nor any attributes and thus, it requires a minimum of storage.
|
|
Load an image from the specified reader. If the format specifier is empty, an attempt to auto-detect the format will be done. First the initial part of the stream is examined against the various format signatures. If this yields no unique result then the suffix of the source name (if any) is used to try to dertermine the format.
|
|
Load an image from the specified file. If the format specifier is empty, an attempt to auto-detect the format will be done. First the initial part of the stream is examined against the various format signatures. If this yields no unique result then the suffix of the source name (if any) is used to try to dertermine the format.
Definition at line 482 of file image.H. References Archon::Utilities::Stream::makeFileReader(), and Archon::Utilities::File::nameOf(). |
|
Fetch the image comment.
|
|
Load in image from the specified file. The new image contents replaces the old contents.
Definition at line 553 of file image.H. References Archon::Utilities::Stream::makeFileReader(), and Archon::Utilities::File::nameOf(). |
|
Load an image from the specified reader. The new image contents replaces the old contents.
|
|
If an empty format specifier is passed the format is determined by the suffix of the file name.
Definition at line 609 of file image.H. References Archon::Utilities::Stream::makeFileWriter(), and Archon::Utilities::File::nameOf(). |
|
If an empty format specifier is passed the format is determined by the suffix of the target name.
Definition at line 581 of file image.H. Referenced by Archon::Raytracer::Engine::render(). |
|
Set a new image comment.
Definition at line 202 of file image.H. References Archon::Utilities::MutaRef< T >::mutate(). Referenced by Archon::Utilities::FormatLibjpeg::load(). |