Class: Libpng::SimplifiedEncoder

Inherits:
Object
  • Object
show all
Defined in:
lib/libpng/simplified_encoder.rb

Overview

Encodes raw pixel data as a PNG via libpng's "simplified" write API (png_image_write_to_memory). By default the output is then walked chunk-by-chunk to strip the sRGB/gAMA/cHRM/iCCP chunks the simplified API emits -- this matches the byte layout of the classic libpng write path (libemf2svg's rgb2png).

One instance per encode call. Ractor-safe: no shared mutable state.

Instance Method Summary collapse

Constructor Details

#initialize(width, height, pixels, pixel_format: 'RGBA', convert_to_8bit: false, strip_colorspace: true) ⇒ SimplifiedEncoder

Returns a new instance of SimplifiedEncoder.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/libpng/simplified_encoder.rb', line 12

def initialize(width, height, pixels,
               pixel_format: 'RGBA',
               convert_to_8bit: false,
               strip_colorspace: true)
  @width = width
  @height = height
  @pixels = pixels
  @pixel_format = pixel_format
  @convert_to_8bit = convert_to_8bit
  @strip_colorspace = strip_colorspace
  validate!
end

Instance Method Details

#callObject

Returns a binary String of PNG file bytes.



26
27
28
29
# File 'lib/libpng/simplified_encoder.rb', line 26

def call
  raw = write_via_simplified_api
  @strip_colorspace ? ChunkWalker.new(raw).strip_ancillary : raw
end