X-Git-Url: http://uxul.de/gitweb/?p=uxul-world.git;a=blobdiff_plain;f=files.lisp;fp=files.lisp;h=65918ae90e16f13cedf4ce6902046b91f8080434;hp=e8e50dbc8c44f1118dbf9d1a8a2b45e2b0d26733;hb=3a5b6fe5b066ace9e3d03ec20c96c224cdbeb0b8;hpb=bf3029cdab22e72b60b26e1fa23c1568dc78041d diff --git a/files.lisp b/files.lisp index e8e50db..65918ae 100755 --- a/files.lisp +++ b/files.lisp @@ -8,27 +8,73 @@ (defun si (var val) (setf (symbol-value (intern var)) val)) -(defun init-file (file) - "Load a file into a Variable. Access with |filename| (without .png -and path)." - (si (pathname-name file) - (with-open-file (in file :element-type '(unsigned-byte 8)) - (let* ((length (file-length in)) - (content (make-array (list length) - :element-type '(unsigned-byte 8) - :adjustable nil))) - (read-sequence content in) - content)))) - -(defun file-relevant-p (file) + +(defun stretch-image (x y img) + "Call ImageMagick to resize that file to 64x64." + (lisp-magick:with-magick-wand (mywand) + (lisp-magick::magick-read-image-blob mywand img) + (lisp-magick::magick-resize-image mywand x y #x00000000 1d0) + (lisp-magick::magick-set-format mywand "png") + (lisp-magick::magick-get-image-blob mywand))) + +(defun ash-sized-image (img a) + "Calculate an image of half of the size." + (lisp-magick:with-magick-wand (mywand) + (lisp-magick::magick-read-image-blob mywand img) + (let + ((w (lisp-magick::magick-get-image-width mywand)) + (h (lisp-magick::magick-get-image-height mywand))) + (lisp-magick::magick-resize-image mywand + (max 1 (floor (/ w a))) (max 1 (floor (/ h a))) ;; no ash here ... + #x00000000 1d0) + (lisp-magick::magick-set-format mywand "png") + (lisp-magick::magick-get-image-blob mywand)))) + +(defun all-sizes (img) + (list img + (ash-sized-image img 2) + (ash-sized-image img 4) + (ash-sized-image img 8))) + + +;; (defun init-file (file) +;; "Load a file into a Variable. Access with |filename| (without .png +;; and path)." +;; (si (pathname-name file) +;; (stretched-image +;; (with-open-file (in file :element-type '(unsigned-byte 8)) +;; (let* ((length (file-length in)) +;; (content (make-array (list length) +;; :element-type '(unsigned-byte 8) +;; :adjustable nil))) +;; (read-sequence content in) +;; content))))) + +(defun init-png-file (file) + "Load an image file into a Variable. Set |filename| (without .png +and path) to a list with all sizes of that image." + (si (pathname-name file) + (all-sizes + (with-open-file (in file :element-type '(unsigned-byte 8)) + (let* ((length (file-length in)) + (content (make-array (list length) + :element-type '(unsigned-byte 8) + :adjustable nil))) + (read-sequence content in) + content))))) + +(defun png-p (file) "Is the file relevant for initialization? So far only .png-files are relevant." (string= (pathname-type file) "png")) -(defun init-files () - "Load the relevant files into variables" +(defun init-png-files () (cl-fad:walk-directory (asdf:component-pathname (asdf:find-system :uxul-world)) - #'init-file :test #'file-relevant-p)) + #'init-png-file :test #'png-p)) + +(defun init-files () + "Load the relevant files into variables" + (init-png-files)) (init-files) \ No newline at end of file