arsd.imageresize

Image resizing support for arsd.color.MemoryImage. Handles up and down scaling. See imageResize for the main function, all others are lower level if you need more control.

More...

Members

Functions

calculateSizeKeepingAspectRatio
Size calculateSizeKeepingAspectRatio(int currentWidth, int currentHeight, int maxWidth, int maxHeight)

Calculates a new size that fits inside the maximums while keeping the original aspect ratio.

imageResize
TrueColorImage imageResize(MemoryImage msrcimg, int dstwdt, int dsthgt, const(char)[] filter, float gamma, float filterScale)
TrueColorImage imageResize(MemoryImage msrcimg, int dstwdt, int dsthgt, int filter, float gamma, float filterScale)

Resize image.

imageResize
void imageResize(void delegate(Color[] destrow, int y) srcGetRow, void delegate(int y, const(Color)[] row) dstPutRow, int srcwdt, int srchgt, int dstwdt, int dsthgt, int filter, float gamma, float filterScale)

Resize image. Partial gamma correction looks better on mips; set to 1.0 to disable gamma correction. Filter scale: values < 1.0 cause aliasing, but create sharper looking mips (0.75f, for example).

imageResizeFilterName
string imageResizeFilterName(long idx)

Get filter name. Will return null for invalid index.

imageResizeFindFilter
int imageResizeFindFilter(const(char)[] name, const(char)[] defaultFilter)

Find filter index by name. Will use default filter for invalid names.

Manifest constants

ImageResizeDefaultFilter
enum ImageResizeDefaultFilter;

Default filter for image resampler.

ImageResizeMaxDimension
enum ImageResizeMaxDimension;

Maximum image width/height for image resampler.

Properties

imageResizeFilterCount
int imageResizeFilterCount [@property getter]

Number of known image resizer filters.

Detailed Description

Note that this focuses more on quality than speed. You can tweak the filterScale argument to speed things up at the expense of quality though (lower number = faster).

I've found:

auto size = calculateSizeKeepingAspectRatio(i.width, i.height, maxWidth, maxHeight);
if(size.width != i.width || size.height != i.height) {
	i = imageResize(i, size.width, size.height, null, 1.0, 0.6);
}

Gives decent results balancing quality and speed. Compiling with ldc or gdc can also speed up your program.

Meta

Authors

Originally written in C by Rich Geldreich, ported to D by ketmar.

License

Public Domain / Unlicense - http://unlicense.org/