VideoTools
|
A holder for image data, having eight bits per sample and one or three channels. More...
#include <grimagedata.h>
Public Types | |
enum | Type { Segmented, Contiguous } |
Public Member Functions | |
ImageData (Type=Segmented) | |
Default constructor for a zero-size image. More... | |
ImageData (ImageBuffer &image_buffer, Type=Segmented) | |
Constructor for an empty ImageData object that wraps an empty ImageBuffer. More... | |
ImageData (ImageBuffer &, int dx, int dy, int channels) | |
Constructor for an ImageData object that wraps the given ImageBuffer. More... | |
~ImageData () | |
Destructor. | |
Type | type () const |
Returns the contiguous/segmented enumeration. More... | |
int | dx () const |
Returns the width. | |
int | dy () const |
Returns the height. | |
int | channels () const |
Returns the number of channels (zero, one or three). | |
bool | empty () const |
Returns true if the size() is zero. | |
size_t | size () const |
Returns the total image size, ie. dx()*dy()*channels(). | |
size_t | rowsize () const |
Returns the row size, ie. dx()*channels(). | |
void | resize (int dx, int dy, int channels) |
Resizes the image data. | |
unsigned char | r (int x, int y) const |
Returns the R-value for a point. | |
unsigned char | g (int x, int y) const |
Returns the G-value for a point. Returns the R-value if there is only one channel. | |
unsigned char | b (int x, int y) const |
Returns the B-value for a point. Returns the R-value if there is only one channel. | |
unsigned int | rgb (int x, int y) const |
Returns the colour of a pixel as rgb values packed into one integer. | |
void | rgb (int x, int y, unsigned char r, unsigned char g, unsigned char b) |
Sets a pixel colour. More... | |
void | fill (unsigned char r, unsigned char g, unsigned char b) |
Fills the image with a solid colour as if calling rgb() for every pixel. | |
ImageDataWriter | writer (int x, int y, Colour foreground, Colour background, bool draw_background, bool wrap_on_nl) |
Returns a functor that calls write(). | |
void | write (char c, int x, int y, Colour foreground, Colour background, bool draw_background) |
Draws a latin-1 character into the image at the given position. | |
unsigned char * | row (int y) |
Returns a pointer to the y'th row. | |
const unsigned char * | row (int y) const |
Returns a const pointer to the y'th row. | |
unsigned char ** | rowPointers () |
Returns a pointer to the array of row pointers. | |
const unsigned char *const * | rowPointers () const |
Returns a pointer to the array of const row pointers. | |
char ** | rowPointers (int) |
An overload returning a char pointer array. | |
const unsigned char * | p () const |
Returns a const pointer to the image data, but throws if the data is not contiguous. More... | |
unsigned char * | p () |
Returns a pointer to the image data, but throws if the data is not contiguous. More... | |
void | copyRowIn (int y, const unsigned char *row_buffer_in, size_t row_buffer_in_size, int channels_in, bool use_colourspace=false, int scale=1) |
Sets a row of pixels by copying, with channel-count adjustment and optional scaling. More... | |
void | copyIn (const char *data_in, size_t data_size_in, int dx_in, int dy_in, int channels_in, bool use_colourspace=false, int scale=1) |
Copies the image in from a raw buffer, with channel-count adjustment and optional scaling, but no resize(). More... | |
void | copyIn (const ImageBuffer &data_in, int dx_in, int dy_in, int channels_in, bool use_colourspace=false, int scale=1) |
Overload that copies from an ImageBuffer. More... | |
void | copyRowOut (int y, std::vector< char > &out, int scale=1, bool monochrome_out=false, bool use_colourspace=true) const |
Copies a row into the given output buffer, resizing the output vector as necessary. More... | |
void | copyTo (std::vector< char > &out) const |
Copies the image to the given output buffer, resizing the output vector as necessary. More... | |
void | copyTo (ImageBuffer &out) const |
Copies the image to the given ImageBuffer, resizing the output as necessary. More... | |
void | scale (int factor, bool monochrome, bool use_colourspace) |
Scales-down the image by sub-sampling. | |
void | dim (unsigned int shift) |
Dims the image by right-shifting all pixel values. | |
void | dim (unsigned int numerator, unsigned int denominator) |
Dims the image by multiplying all pixel values by the given fraction. More... | |
void | mix (const ImageData &_1, const ImageData &_2, unsigned int numerator_1, unsigned int numerator_2, unsigned int denominator) |
Creates a mixed image from two equally-shaped sources images. More... | |
void | add (const ImageData &other) |
Adds the given image data to this. | |
void | subtract (const ImageData &other) |
Subtracts the given image data from this. | |
void | crop (int dx, int dy) |
Crops the image so that it fits inside the given dimensions. More... | |
void | expand (int dx, int dy) |
Expands the image so that the new image has the dimensions given, with the original image centered inside using black borders. More... | |
A holder for image data, having eight bits per sample and one or three channels.
The data can be either contiguous or allocated row by row.
This class is primarily intended as an output target for the various decoders, and a data source for their encoders. See also Gr::JpegReader, Gr::PngReader, Gr::PnmReader.
Definition at line 46 of file grimagedata.h.
|
explicit |
Default constructor for a zero-size image.
After contstruction the object should normally be resize()d. The Contiguous/Segmented type does not change across resize(). A Contiguous object has a usable p() method that returns a single pointer to the whole image.
Definition at line 30 of file grimagedata.cpp.
Gr::ImageData::ImageData | ( | ImageBuffer & | image_buffer, |
Type | type = Segmented |
||
) |
Constructor for an empty ImageData object that wraps an empty ImageBuffer.
Precondition: image_buffer.empty()
Definition at line 41 of file grimagedata.cpp.
Gr::ImageData::ImageData | ( | ImageBuffer & | image_buffer, |
int | dx, | ||
int | dy, | ||
int | channels | ||
) |
Constructor for an ImageData object that wraps the given ImageBuffer.
The image buffer can be empty, but its dimensions must always match the other parameters. This ImageData object type() will be contiguous or segmented to match the supplied image buffer, or contiguous by default if dy is less than two.
Definition at line 52 of file grimagedata.cpp.
void Gr::ImageData::copyIn | ( | const char * | data_in, |
size_t | data_size_in, | ||
int | dx_in, | ||
int | dy_in, | ||
int | channels_in, | ||
bool | use_colourspace = false , |
||
int | scale = 1 |
||
) |
Copies the image in from a raw buffer, with channel-count adjustment and optional scaling, but no resize().
The 'monochrome-out' parameter is implicit in the current number of channels and the number of channels passed in.
If the number of channels is reduced then there is the option to just take the first channel or do a colourspace transform. Prefer a direct memcpy()s to row()s for speed where possible.
Definition at line 323 of file grimagedata.cpp.
void Gr::ImageData::copyIn | ( | const ImageBuffer & | data_in, |
int | dx_in, | ||
int | dy_in, | ||
int | channels_in, | ||
bool | use_colourspace = false , |
||
int | scale = 1 |
||
) |
Overload that copies from an ImageBuffer.
The dx and dy parameters are used as a sanity check against the dimensions of the ImageBuffer.
Definition at line 344 of file grimagedata.cpp.
void Gr::ImageData::copyRowIn | ( | int | y, |
const unsigned char * | row_buffer_in, | ||
size_t | row_buffer_in_size, | ||
int | channels_in, | ||
bool | use_colourspace = false , |
||
int | scale = 1 |
||
) |
Sets a row of pixels by copying, with channel-count adjustment and optional scaling.
If the number of channels is reduced then there is the option to either take the first channel or do a colourspace transform. Prefer a direct memcpy() to row() for speed where possible.
Definition at line 261 of file grimagedata.cpp.
void Gr::ImageData::copyRowOut | ( | int | y, |
std::vector< char > & | out, | ||
int | scale = 1 , |
||
bool | monochrome_out = false , |
||
bool | use_colourspace = true |
||
) | const |
Copies a row into the given output buffer, resizing the output vector as necessary.
Definition at line 219 of file grimagedata.cpp.
void Gr::ImageData::copyTo | ( | std::vector< char > & | out | ) | const |
Copies the image to the given output buffer, resizing the output vector as necessary.
Definition at line 380 of file grimagedata.cpp.
void Gr::ImageData::copyTo | ( | ImageBuffer & | out | ) | const |
Copies the image to the given ImageBuffer, resizing the output as necessary.
Definition at line 398 of file grimagedata.cpp.
void Gr::ImageData::crop | ( | int | dx, |
int | dy | ||
) |
Crops the image so that it fits inside the given dimensions.
Does nothing if the image is already small enough.
Definition at line 665 of file grimagedata.cpp.
void Gr::ImageData::dim | ( | unsigned int | numerator, |
unsigned int | denominator | ||
) |
Dims the image by multiplying all pixel values by the given fraction.
Use small numbers to avoid arithmetic overflow.
Definition at line 580 of file grimagedata.cpp.
void Gr::ImageData::expand | ( | int | dx, |
int | dy | ||
) |
Expands the image so that the new image has the dimensions given, with the original image centered inside using black borders.
Does nothing if the image is already big enough.
Definition at line 709 of file grimagedata.cpp.
void Gr::ImageData::mix | ( | const ImageData & | _1, |
const ImageData & | _2, | ||
unsigned int | numerator_1, | ||
unsigned int | numerator_2, | ||
unsigned int | denominator | ||
) |
Creates a mixed image from two equally-shaped sources images.
There is no colourspace subtelty; mixing is done separately for each channel so arithmetic overflow will create colour distortion.
Definition at line 616 of file grimagedata.cpp.
const unsigned char * Gr::ImageData::p | ( | ) | const |
Returns a const pointer to the image data, but throws if the data is not contiguous.
Definition at line 420 of file grimagedata.cpp.
unsigned char * Gr::ImageData::p | ( | ) |
Returns a pointer to the image data, but throws if the data is not contiguous.
Definition at line 411 of file grimagedata.cpp.
|
inline |
Sets a pixel colour.
The trailing 'g' and 'b' values are ignored if there is only one channel.
Definition at line 377 of file grimagedata.h.
Gr::ImageData::Type Gr::ImageData::type | ( | ) | const |
Returns the contiguous/segmented enumeration.
Contiguous objects have a usable p() method that returns a pointer to the whole image.
Definition at line 79 of file grimagedata.cpp.