Module: Emfsvg::PngDecoder
- Defined in:
- lib/emfsvg/png_decoder.rb
Overview
Decode PNG bytes to RGBA pixels. Wraps the libpng simplified API. Returns a Result with width, height, and a packed RGBA pixel buffer.
Defined Under Namespace
Classes: Result
Class Method Summary collapse
Class Method Details
.decode(png_bytes) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/emfsvg/png_decoder.rb', line 13 def decode(png_bytes) return nil if png_bytes.nil? || png_bytes.empty? decoded = Libpng.decode(png_bytes, pixel_format: "RGBA") Result.new(width: decoded.width, height: decoded.height, pixels: decoded.pixels) rescue Libpng::Error nil end |