MLX-CL/IO/PNG
Support PNG file read and write

Table of Contents

1. About

MLX-CL/IO/PNG add support for reading and writing mlx-array from and to PNG file via pngload and zpng.

2. Usage

2.1. Loading

(ql:quickload :mlx-cl/io/png)

NOTE: if you load mlx-cl/image, it would automatically load mlx-cl/io/png and other image file IO support.

2.2. Reading PNG file

(mlx-array "xxx.png")

2.3. Writing PNG file

(destructuring-bind (x y)
    (mlx:meshgrid (linspace 0 1 width)
                  (linspace 0 1 height))
  (flet ((mask (ch) (where (<= (+ x y) 1) ch 0)))
    (->* (stack (mask x)                ; R
                (mask y)                ; G
                (mask (- 1 x y))        ; B
                :axis 2)                ; on channel axis
      (as-dtype (* * 255) :uint8)
      (save * :output "./res/img/write-png-example.png"))))

write-png-example.png

Figure 1: Write an colorful triangle to the PNG file, just for fun :P

Author: 凉凉

Created: 2025-11-20 Thu 19:58

Validate