Skip to content

Commit

Permalink
modules/png (bytevector->png-image): New procedure
Browse files Browse the repository at this point in the history
* modules/png.scm (bytevector->png-image): New procedure.
* tests/image.scm ("bytevector->png-image"): New test.
  • Loading branch information
artyom-poptsov committed Jan 7, 2024
1 parent f1b7a5e commit 7735fb6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
16 changes: 15 additions & 1 deletion modules/png.scm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
;;; png.scm -- GNU Guile PNG parser.

;; Copyright (C) 2022 Artyom V. Poptsov <[email protected]>
;; Copyright (C) 2022-2024 Artyom V. Poptsov <[email protected]>
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
Expand All @@ -27,13 +27,15 @@

(define-module (png)
#:use-module (oop goops)
#:use-module (rnrs io ports)
#:use-module (png image)
#:use-module (png fsm context)
#:use-module (png fsm png-context)
#:use-module (png fsm png-parser)
#:use-module (png core chunk)
#:use-module (png chunk-decoder)
#:export (png->scm
bytevector->png-image
scm->png))


Expand All @@ -58,6 +60,18 @@
(png-compressed-image-decompress image remove-filter?)
image)))))

(define* (bytevector->png-image bv
#:key
(decompress? #t)
(debug-mode? #f)
(remove-filter? #t))
"Convert a bytevector @var{bv} to a PNG image. return the new image."
(with-input-from-port (open-bytevector-input-port bv)
(lambda ()
(png->scm #:decompress? decompress?
#:debug-mode? debug-mode?
#:remove-filter? remove-filter?))))

(define* (scm->png image
#:optional
(port (current-output-port)))
Expand Down
9 changes: 9 additions & 0 deletions tests/image.scm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
(ice-9 iconv)
(rnrs bytevectors)
(oop goops)
(png)
(png image)
(png core chunk)
(png core chunk ihdr)
Expand Down Expand Up @@ -176,6 +177,14 @@
#:height 100)))
(png-image->bytevector image)))

(test-assert "bytevector->png-image"
(let ((image (make <png-image>
#:color-type 2
#:bit-depth 8
#:width 10
#:height 10)))
(bytevector->png-image (png-image->bytevector image))))


(define exit-status (test-runner-fail-count (test-runner-current)))

Expand Down

0 comments on commit 7735fb6

Please sign in to comment.