|
yage.resource.image
Authors:
Eric Poggel
License:
LGPL v3
- class
Image
;
- A class for loading and manipulating images.
Supports loading images from any channels supported by SDL_Image.
Currently supports grayscale, RGB, and RGBA image data.
BUGS:
An RGB image will often be returned when loading grayscale images. Use setFormat(IMAGE_FORMAT_GRAYSCALE) to correct this.
TODO:
Add convolution support: http://www.php.net/manual/en/function.imageconvolution.php#77818
TODO:
Convert to struct?
- enum
Format
;
- The pixel format, also the bytes-per-pixel
- this(int channels, int width, int height, ubyte[] lookaside = null);
- Create a new emtpy image.
Params:
int channels |
number of color channels. |
int width |
width in pixels |
int height |
height in pixel |
- this(ubyte[] data, int channels, int width, int height = 0);
- Construct from image data in memory. This does not create a copy of the data.
Params:
image |
array of raw image data |
int channels |
number of color channels. |
int width |
width in pixels |
int height |
height in pixels, if 0 it is auto-calculated from width, channels, and data's length. |
- this(char[] filename);
- Construct and load image data from a file.
Params:
char[] filename |
absolute or relative path of an image file supported by sdl_image. |
Returns:
An image with the number of channels of the source image. Paletted images are converted to nonpaletted.
- Pixel!(4)
bilinearFilter
(float u, float v);
- Get the pixel color value at the coordinates using bilinear interpolation.
See:
http:
//en.wikipedia.org/wiki/Bilinear_filtering
Params:
float u |
A value betwen 0 and 1. |
float v |
A value betwen 0 and 1. |
- Image
crop
(int left, int top, int right, int bottom);
- Crop the image.
The four parameters define a box, in coordinates relative to the top left of the source image.
For example,
crop
(0, 0, width, height) would return an exact copy of the original image.
Params:
int left |
left side of the cropping box. This and the other parameters can be positive or negative. |
int top |
top side of the cropping box. |
int right |
right side of the cropping box |
int bottom |
bottom side of the cropping box. |
Returns:
A new image of the size right-left, bottom-top
- ubyte[]
getData
();
- Return the raw image data.
The array length is always width*height*C.
Row-major order is used. This means that the array contains all of row 1's
pixels, followed by row 2's pixels, etc.
- int
getChannels
();
- Get the number of color channels.
- int
getWidth
();
- Get the width or height of the image in pixels.
- int
getHeight
();
- ditto.
- ubyte[]
opIndex
(int i);
ubyte[]
opIndexAssign
(ubyte[] val, int i);
- Get or set the ith pixel in the image.
- ubyte[]
opIndex
(int x, int y);
ubyte[]
opIndexAssign
(ubyte[] val, int x, int y);
- Get or set the pixel at the given coordinates.
- void
overlay
(Image img, int xoffset = 0, int yoffset = 0);
- Paste another image on top of this one.
This operation is performed in-place and does not generate any heap activity.
This also does not perform proper overlays of images with an alpha channel.
Params:
Image img |
Image to add to this one. |
int xoffset |
x-offset of img from this image's left side. Out of bounds values will be cropped. |
int yoffset |
y-offset of img from this image's top side. Out of bounds values will be cropped. |
- void
add
(Image img, int xoffset = 0, int yoffset = 0);
- Overlay another image on top of this one, adding color channel values.
This operation is performed in-place and does not generate any heap activity.
Params:
Image img |
Image to
add
to this one. |
int xoffset |
x-offset of img from this image's left side. Out of bounds values will be cropped. |
int yoffset |
y-offset of img from this image's top side. Out of bounds values will be cropped. |
- void
overlayAndColor
(Image img, Color color, int xoffset = 0, int yoffset = 0);
- Convert a monochrome image to color and paste it over this image.
This operation is performed in-place and does not generate any heap activity.
This somewhat specialized function is used to accelerate text rendering.
Params:
Image img |
a monochrome image |
Color color |
img will be converted to an RGBA image of this color before pasting. |
int xoffset |
x-offset of img from this image's left side. Out of bounds values will be cropped. |
int yoffset |
y-offset of img from this image's top side. Out of bounds values will be cropped. |
TODO:
Make the top go to the right instead of taking the bottom to the left when skewing
- void*
ptr
();
- Return a c-style pointer to the image data.
The length of the array is always width*height*channels.
- Image
resize
(int width, int height = 0);
- Resize this image using bilinear interpolation.
Params:
int width |
The new width. |
int height |
The new height. If 0, height will be calculated automatically with aspect ratio maintained. |
Returns:
A new image of the same type and of the new size, or an exact copy if the dimensions are the same.
- Image
subImage
(int top, int left, int bottom, int right);
- Return a new image that is a sub-image of this image.
TODO:
Replace this with crop.
The four parameters should be in pixels.
The sub-image will start with the pixels including top and left
and stop just before pixels specified by bottom and right.
- abstract class
ImageBase
;
- ubyte[]
getBytes
();
- Image2!(T2,C2)
convert
(T2 : real, int C2)();
- class
Image2
(T : real,int C): ImageBase;
- Successor to the Image class.
TODO:
The rest of Image's functionality should be migrated to
Image2
, Image deleted, and
Image2
renamed as Image.
@param T Type of each pixel component
@param C number of channels.
- this(int width, int height, T[C][] data = null);
- ubyte[]
getBytes
();
|
|