4 changed files with 66 additions and 5 deletions
@ -0,0 +1,36 @@ |
|||
;; Image |
|||
;; Interface for loading images of various formats |
|||
;; Currently, stb_image.h does all the heavy lifting |
|||
(import &comptime-only "STB.cake") |
|||
(use-stb-image clone-stb-headers-image) |
|||
|
|||
(comptime-cond |
|||
('auto-test |
|||
(defun-nodecl test--stb-image (&return int) |
|||
(var image-to-load (* (const char)) "assets/town.jpg") |
|||
(var width int 0) |
|||
(var height int 0) |
|||
(var num-pixel-components int 0) |
|||
(var num-desired-channels int 0) ;; Default |
|||
(var pixel-data (* (unsigned char)) |
|||
(stbi_load image-to-load (addr width) (addr height) (addr num-pixel-components) |
|||
num-desired-channels)) |
|||
(unless pixel-data |
|||
(fprintf stderr "error: failed to load %s\n" image-to-load) |
|||
(return 1)) |
|||
|
|||
(fprintf stderr "size of %s: %dx%d\n" image-to-load width height) |
|||
(fprintf stderr "num components in %s: %d\n" image-to-load num-pixel-components) |
|||
(fprintf stderr "first three pixels:\n") |
|||
(each-in-range 3 i |
|||
(var rgb-components ([] 3 (unsigned char)) (array 0)) |
|||
(memcpy rgb-components (addr (at (* i num-pixel-components) pixel-data)) |
|||
(sizeof rgb-components)) |
|||
(fprintf stderr "[%d] %d %d %d\n" |
|||
i |
|||
(at 0 rgb-components) |
|||
(at 1 rgb-components) |
|||
(at 2 rgb-components))) |
|||
|
|||
(stbi_image_free pixel-data) |
|||
(return 0)))) |
After Width: | Height: | Size: 86 KiB |
Loading…
Reference in new issue