diff --git a/modules/png.scm b/modules/png.scm index 43399a1..4e4c38e 100644 --- a/modules/png.scm +++ b/modules/png.scm @@ -1,6 +1,6 @@ ;;; png.scm -- GNU Guile PNG parser. -;; Copyright (C) 2022 Artyom V. Poptsov +;; Copyright (C) 2022-2024 Artyom V. Poptsov ;; ;; 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 @@ -27,6 +27,7 @@ (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) @@ -34,6 +35,7 @@ #:use-module (png core chunk) #:use-module (png chunk-decoder) #:export (png->scm + bytevector->png-image scm->png)) @@ -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))) diff --git a/tests/image.scm b/tests/image.scm index 49a49c2..f4178c9 100644 --- a/tests/image.scm +++ b/tests/image.scm @@ -3,6 +3,7 @@ (ice-9 iconv) (rnrs bytevectors) (oop goops) + (png) (png image) (png core chunk) (png core chunk ihdr) @@ -176,6 +177,14 @@ #:height 100))) (png-image->bytevector image))) +(test-assert "bytevector->png-image" + (let ((image (make + #: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)))