liveBook · Manning

PNG

As explained in Learn Go with Pocket-Sized Projects

PNG is a lossless raster image file format that supports indexed, grayscale, and truecolor images with optional transparency.

PNG is a lossless raster image format: it stores a two-dimensional grid of colored pixels while preserving exact values needed for walls, paths, entrances, and treasures. section 9.1.1

PNG fits image-processing tasks that depend on precise pixel data:

  • Represents indexed, grayscale, or truecolor images, with optional transparency. section 9.0
  • Decodes through Go’s image/png package into an image.Image, often accessed as RGBA or NRGBA. section 9.7
  • Reads pixels with At or RGBAAt and writes RGBA pixels with Set. section 9.7

Concurrent maze solver

A command-line Go tool reads a PNG RGBA maze, explores its branches concurrently, and writes another PNG with the entrance-to-treasure path highlighted. section 9.0

> go doc image
package image // import "image"

[...]

type Image interface{ ... }
    func Decode(r io.Reader) (Image, string, error)

type Point struct{ ... }

type RGBA struct{ ... }
    func NewRGBA(r Rectangle) *RGBA

> go doc image.Point
type Point struct {
    X, Y int
}
    A Point is an X, Y coordinate pair. The axes increase right and down.

Browse Go’s image interfaces, RGBA type, decoding function, and coordinate representation for working with PNG pixels. section 9.1.1

How Learn Go with Pocket-Sized Projects covers it

How deep it goes
Explains raster pixels, RGBA access, decoding, encoding, and scan order without detailing PNG compression internals.
Examples
Uses a PNG RGBA maze whose explored path is highlighted in a second image.
What it assumes
Assumes familiarity with two-dimensional grids and colors while explaining raster pixels and Go image access.
What you can do after
Build a Go tool that decodes, inspects, modifies, and encodes PNG images through standard image packages.
How it connects
Connects PNG with raster images, JPEG, SVG, RGBA, image.Image, color models, and GIF.

Also explained in

Compare how 2 books explain PNG →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Go with Pocket-Sized Projects. The section links point to the parts of the book it draws on.