chapel icon indicating copy to clipboard operation
chapel copied to clipboard

Expand Image support to PNG and JPG

Open jabraham17 opened this issue 6 months ago • 0 comments

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 and stb_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 of colorToPixel

[Reviewed by @DanilaFe]

jabraham17 avatar Jul 31 '24 20:07 jabraham17