Single header C++ code that resamples and resizes your pretty pictures. There's lots of frameworks out there that do something similar, but few that do only this one. simple. thing.
This is actually a simplified and minified version of the image resampling logic in the Imagine Framework. It could use some sprucing up, but it gets the job done.
This resampler supports the most common raw image format around: three channel with 8 bits per channel color (e.g. RGB24 aka RGB8). If you need support for other formats you could check out Imagine which supports a broad variety of configurable formats, or you could modify this header to suit your needs.
Choose from any of the following sampling methods. For more information about how each of these works, check out this blog post.
- Nearest
- Average
- Bilinear
- Bicubic
- Mitchell-Netravali
- Cardinal
- B-Spline
- Lanczos (1 through 5 steps)
- Catmull-Rom
- Gaussian
To get started include base_resample.h in your project and follow the super squeaky example below:
/* Resampling a 512x512 source image into a 128x128 destination image. */
unsigned char* src_image_data = /* up to you to allocate and fill this out. */
unsigned char* dst_image_data = /* up to you to allocate, resampler will fill out. */
/* Resize our image using bilinear resampling. */
ResampleImage24(src_image_data, 512, 512, dst_image_data, 128, 128, KernelTypeBilinear);
For a more comprehensive example, check out examples/Tutorial1.cpp, which demonstrates loading a bitmap image, resampling it, and saving it back to disk.
This software is released under the terms of the BSD 2-Clause “Simplified” License.
For more information visit http://www.bertolami.com.