chapel
chapel copied to clipboard
Expand Image support to PNG and JPG
Expands the Image module support to also work with PNG and JPG. With this effort, I have also added the ability to read images with Chapel code as well. This allows users to read, write, and manipulate several popular image formats.
The following code will read and write a PNG image.
use Image;
var pixels = readImage("input.png", imageType.png);
var colors = pixelToColor(pixels); // 2D array of RGB values as (int,int,int)
// manipulate the image as needed
writeImage("output.jpg", imageType.jpg, colorToPixel(colors));
Summary of Changes
- Bundled
stb_image.h
andstb_image_write.h
, which are portable, header-only C libraries for reading/writing images - Added PNG and JPG implementations based on
stb_image
, with a framework to use other implementions in the future if desired. - Refactored the native BMP implementation to cleanup the code
- Added
pixelToColor
, which does the reverse ofcolorToPixel
[Reviewed by @DanilaFe]