liveBook · Manning

DynamicImage

As explained in Learn Haskell by Example

DynamicImage is the JuicyPixels image type that represents images while retaining their pixel depth and color model at runtime.

DynamicImage is JuicyPixels’ runtime image representation. It preserves the image’s bit depth and color model, allowing grayscale and RGB images to share an output type. section 13.1.1 section 13.3.2

Its constructors distinguish the supported image forms:

  • ImageY8 and ImageY16 represent 8-bit and 16-bit grayscale images. section 13.3.2
  • ImageRGB8 and ImageRGB16 represent 8-bit and 16-bit color images. section 13.3.2
  • The type is a simple algebraic data type rather than a GADT or existential wrapper. section 13.3.2

Converting a PNM image for PNG output

A conversion function pattern-matches on the dynamic PNM image, builds an Image value with generateImage, and selects the matching DynamicImage constructor. The resulting value can be written with writeDynamicPng. section 13.3.2

How Learn Haskell by Example covers it

How deep it goes
Explains constructors and conversion mechanics, including generateImage, but stops short of library implementation internals.
Examples
Uses ImageY8, ImageY16, ImageRGB8, ImageRGB16, generateImage, and writeDynamicPng in a PNM-to-PNG pipeline.
What it assumes
Assumes image dimensions, pixel representations, and pattern matching; teaches how type refinement guides each constructor branch.
What you can do after
Build PNG output by converting pixel-specific images into the appropriate DynamicImage constructor.
How it connects
Connects PNM images, pixel types, pattern matching, image generation, and PNG encoding.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Haskell by Example. The section links point to the parts of the book it draws on.