MLX-CL/IO/JPEG
Support JPEG file read and write
Table of Contents
1. About
MLX-CL/IO/JPEG add support for reading and writing mlx-array from and to
JPEG file via sharplispers/cl-jpeg.
NOTE: I haven't got enough time to test all the file formats, currently
only PNG and TIFF is well (as I thought) tested. (Since I have to use
them to write homework. Please persuade my teacher for forcing the target format
Well, just kidding. Please raise issue or pull request if you found issue
or have some ideas about how to improve it).
2. Usage
2.1. Loading
(ql:quickload :mlx-cl/io/jpeg)
NOTE: if you load mlx-cl/image, it would automatically load
mlx-cl/io/jpeg and other image file IO support.
2.2. Reading JPEG file
(mlx-array "./res/img/avatar.jpg")
array([[[254, 254, 254],
[254, 254, 254],
[254, 254, 254],
...,
[254, 254, 254],
[254, 254, 254],
[254, 254, 254]],
[[254, 254, 254],
[254, 254, 254],
[254, 254, 254],
...,
[254, 254, 254],
[254, 254, 254],
[254, 254, 254]],
[[254, 254, 254],
[254, 254, 254],
[254, 254, 254],
...,
[254, 254, 254],
[254, 254, 254],
[254, 254, 254]],
...,
[[254, 254, 254],
[254, 254, 254],
[254, 254, 254],
...,
[254, 254, 254],
[254, 254, 254],
[254, 254, 254]],
[[254, 254, 254],
[254, 254, 254],
[254, 254, 254],
...,
[254, 254, 254],
[254, 254, 254],
[254, 254, 254]],
[[254, 254, 254],
[254, 254, 254],
[254, 254, 254],
...,
[254, 254, 254],
[254, 254, 254],
[254, 254, 254]]], dtype=uint8)
NOTE: it's better if you load mlx-cl/image subsystem, you could
use mlx.img:image function to load image file.
(mlx.img:image "./res/img/avatar.jpg")
#<mlx-cl.image:image(240x241 :rgb)>
2.3. Write JPEG file
(->* (full #(200 200 3) ; 512x512 channels=3 RGB file
#(0 0 0) ; #x000 for black color
:dtype :uint8)
(setf (at *
'(:middle 60) ; 60px long
'(:middle 10)) ; 10px width
#(255 255 255)) ; white rectangle in the middle
(save * :output "./res/img/write-jpeg-example-1.jpg"))
NOTE: it's better if you use the following code via mlx-cl/image
subsystem (which is from my Image Processing homework):
(->* (mlx.img:image :black :w 512 :h 512) (setf (at * '(:middle 60) '(:middle 10)) :brightwhite) (save * :output "./res/img/write-jpeg-example-2.jpg"))