ExPng.Image.Pixelation (ExPng v0.2.0)
This module contains code for converting between unfiltered bytestrings and
lists of ExPng.Pixel.t/0
.
Link to this section Summary
Functions
Parses a de-filtered line of pixel data into a list of ExPng.Pixel
structs
based on the bit depth and color mode of the image. For images that use the
ExPng.indexed/0
color mode, the image's ExPng.Chunks.Palette
data is passed
as an optional 4th argument.
Link to this section Functions
from_pixels(pixels, bit_depth, color_mode, palette \\ nil)
to_pixels(line, bit_depth, color_mode, palette \\ nil)
Specs
to_pixels( binary(), ExPng.bit_depth(), ExPng.color_mode(), ExPng.maybe(ExPng.Chunks.Palette.t()) ) :: [ExPng.Pixel.t(), ...]
Parses a de-filtered line of pixel data into a list of ExPng.Pixel
structs
based on the bit depth and color mode of the image. For images that use the
ExPng.indexed/0
color mode, the image's ExPng.Chunks.Palette
data is passed
as an optional 4th argument.
In the code below, in the call to new/2
, 0 represents the ExPng.filter_none/0
filter type. In the call to to_pixels/3
, 1 is the bit depth of the line --
each piece of a pixel's data is encoded in a single bit -- and 0 is the
reperesentation of the ExPng.grayscale/0
color mode.
iex> line = {0, <<21>>}
iex> ExPng.Image.Pixelation.to_pixels(line, 1, 0)
[
ExPng.Pixel.black(), ExPng.Pixel.black(),
ExPng.Pixel.black(), ExPng.Pixel.white(),
ExPng.Pixel.black(), ExPng.Pixel.white(),
ExPng.Pixel.black(), ExPng.Pixel.white()
]
Here, in the call to to_pixels/3
, 8 shows that each part of a pixel's
definition -- the red, green, and blue values -- is stored in 8 bits, or 1 byte,
and the 2 is the code for the ExPng.truecolor/0
color mode.
iex> line = {0, <<100, 100, 200, 30, 42, 89>>}
iex> ExPng.Image.Pixelation.to_pixels(line, 8, 2)
[
ExPng.Pixel.rgb(100, 100, 200),
ExPng.Pixel.rgb(30, 42, 89)
]