|
Compute | average () const |
| Returns the average value of all elements of the map. More...
|
|
Compute | bicubic (float x, float y, WrapMode wrap) const |
|
Uses Catmull-Rom splines to interpolate between grid values. More...
|
|
Compute | bicubic (float x, float y) const |
|
Compute | bicubic (const Vector2 &p, WrapMode wrap) const |
|
Compute | bicubic (const Vector2 &p) const |
|
Compute | bilinear (float x, float y, WrapMode wrap) const |
|
Needs to access elements from (floor(x), floor(y)) to (floor(x) + 1, floor(y) + 1) and will use the wrap mode appropriately (possibly generating out of bounds errors). More...
|
|
Compute | bilinear (float x, float y) const |
|
Compute | bilinear (const Vector2 &p) const |
|
Compute | bilinear (const Vector2 &p, WrapMode wrap) const |
|
bool | changed () |
|
Returns true if this map has been written to since the last call to setChanged(false). More...
|
|
virtual void | crop (int newX, int newY, int newW, int newH) |
|
Crops this map so that it only contains pixels between (x, y) and (x + w - 1, y + h - 1) inclusive. More...
|
|
virtual void | crop (const Rect2D &rect) |
| iRounds to the nearest x0 and y0. More...
|
|
const Storage & | fastGet (int x, int y) const |
| Unsafe access to the underlying data structure with no wrapping support; requires that (x, y) is in bounds. More...
|
|
void | fastSet (int x, int y, const Storage &v) |
| Unsafe access to the underlying data structure with no wrapping support; requires that (x, y) is in bounds. More...
|
|
virtual void | flipHorizontal () |
|
virtual void | flipVertical () |
|
const Storage & | get (int x, int y, WrapMode wrap) const |
| Get the value at (x, y). More...
|
|
const Storage & | get (int x, int y) const |
|
const Storage & | get (const Vector2int16 &p) const |
|
const Storage & | get (const Vector2int16 &p, WrapMode wrap) const |
|
Storage & | get (int x, int y, WrapMode wrap) |
|
Storage & | get (int x, int y) |
|
Storage & | get (const Vector2int16 &p) |
|
Array< Storage > & | getArray () |
| Row-major array. More...
|
|
const Array< Storage > & | getArray () const |
|
Storage * | getCArray () |
| Returns a pointer to the underlying row-major data. More...
|
|
const Storage * | getCArray () const |
|
int32 | height () const |
| Pixel height. More...
|
|
bool | inBounds (int x, int y) const |
| is (x, y) strictly within the image bounds, or will it trigger some kind of wrap mode More...
|
|
bool | inBounds (const Vector2int16 &v) const |
| is (x, y) strictly within the image bounds, or will it trigger some kind of wrap mode More...
|
|
void | maybeFlipVertical (bool flip) |
| flips if flip is true More...
|
|
Compute | nearest (float x, float y, WrapMode wrap) const |
| Returns the nearest neighbor. More...
|
|
Compute | nearest (float x, float y) const |
|
Compute | nearest (const Vector2 &p) const |
|
Rect2D | rect2DBounds () const |
| Rectangle from (0, 0) to (w, h) More...
|
|
void | resize (uint32 newW, uint32 newH, uint32 newD=1) |
| Resizes without clearing, leaving garbage. More...
|
|
void | set (const Vector2int16 &p, const Storage &v) |
| Sets the changed flag to true. More...
|
|
void | set (int x, int y, const Storage &v, WrapMode wrap) |
| Sets the changed flag to true. More...
|
|
void | set (int x, int y, const Storage &v) |
|
template<class T > |
void | set (const shared_ptr< Map2D< Storage, T > > &src) |
| Copy values from src, which must have the same size. More...
|
|
void | setAll (const Storage &v) |
|
void | setChanged (bool c) |
| Set/unset the changed flag. More...
|
|
void | setWrapMode (WrapMode m) |
|
Vector2int16 | size () const |
| Dimensions in pixels. More...
|
|
size_t | sizeInMemory () const |
| Number of bytes occupied by the image data and this structure. More...
|
|
int32 | width () const |
| Pixel width. More...
|
|
WrapMode | wrapMode () const |
|
template<typename Storage, typename Compute = typename G3D::_internal::_GetComputeType<Storage>::Type>
class G3D::Map2D< Storage, Compute >
Map of values across a discrete 2D plane.
Can be thought of as a generic class for 2D images, allowing flexibility as to pixel format and convenient methods. In fact, the "pixels" can be any values on a grid that can be sensibly interpolated–RGB colors, scalars, 4D vectors, and so on.
Other "image" classes in G3D:
G3D::Image - Supports file formats, fast, Color3uint8 and Color4uint8 formats. No interpolation.
G3D::shared_ptr<Texture> - Represents image on the graphics card (not directly readable on the CPU). Supports 2D, 3D, and a variety of interpolation methods, loads file formats.
G3D::Image3 - A subclass of Map2D<Color3> that supports image loading and saving and conversion to Texture.
G3D::Image4 - A subclass of Map2D<Color4> that supports image loading and saving and conversion to Texture.
G3D::Image3uint8 - A subclass of Map2D<Color3uint8> that supports image loading and saving and conversion to Texture.
G3D::Image4uint8 - A subclass of Map2D<Color4uint8> that supports image loading and saving and conversion to Texture.
There are two type parameters– the first (@ Storage) is the type used to store the "pixel" values efficiently and the second (Compute) is the type operated on by computation. The Compute::Compute(Storage&) constructor is used to convert between storage and computation types. Storage is often an integer version of Compute, for example Map2D<double, uint8>
. By default, the computation type is:
Storage Computation
uint8 float32
uint16 float32
uint32 float64
uint64 float64
int8 float32
int16 float32
int32 float64
int64 float64
float32 float64
float64 float64
Vector2 Vector2
Vector2int16 Vector2
Vector3 Vector3
Vector3int16 Vector3
Vector4 Vector4
Color3 Color3
Color3uint8 Color3
Color4 Color4
Color4uint8 Color4
Any other storage type defaults to itself as the computation type.
The computation type can be any that supports lerp, +, -, *, /, and an empty constructor.
Assign value:
im->set(x, y, 7);
or im->get(x, y) = 7;
Read value:
int c = im(x, y);
Can also sample with nearest neighbor, bilinear, and bicubic interpolation.
Sampling follows OpenGL conventions, where pixel values represent grid points and (0.5, 0.5) is half-way between two vertical and two horizontal grid points.
To draw an image of dimensions w x h with nearest neighbor sampling, render pixels from [0, 0] to [w - 1, h - 1].
Under the WrapMode::CLAMP wrap mode, the value of bilinear interpolation becomes constant outside [1, w - 2] horizontally. Nearest neighbor interpolation is constant outside [0, w - 1] and bicubic outside [3, w - 4]. The class does not offer quadratic interpolation because the interpolation filter could not center over a pixel.
In order to allow subclasses to mimic layered textures, Map2Ds can have an optional depth. Only the constructor and resize() handles depth in this class, to access anything but layer 0 subclasses must implement the functionality themselves.
- Author
- Morgan McGuire, http://casual-effects.com