Skip to content

Instantly share code, notes, and snippets.

Last active January 1, 2018 16:31
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Create an alpha map png from a png file
#|-*- mode:lisp -*-|#
#| <Put a one-line description here>
exec ros -Q -- $0 "$@"
(progn ;;init forms
#+quicklisp (ql:quickload '(opticl cl-cli) :silent t))
(defpackage :ros.script.create-alpha-map.lisp.3711282690
(:use :cl
(in-package :ros.script.create-alpha-map.lisp.3711282690)
(defparameter *input-path* nil)
(defparameter *output-path* nil)
(defparameter *options*
'((*input-path* nil "[Required] Input image file path" :alias ("-i") :params ("FILE"))
(*output-path* "/tmp/temp.png" "Input image file path" :alias ("-o") :params ("FILE"))))
(defun run (input-path output-path)
(let ((img (read-png-file input-path)))
(typecase img
(with-image-bounds (height width) img
(loop for y below height do
(loop for x below width do
(multiple-value-bind (r g b a) (pixel img y x)
(declare (ignore r g b))
(setf (pixel img y x)
(values a a a #xff)))))))
(t (error "The png file is not 8-bit-rgba-image")))
(write-png-file output-path img)))
(defun main (&rest argv)
(print argv)
(multiple-value-bind (vars values)
(cl-cli:parse-cli (cons "" argv) *options*)
(cl-cli:with-environment vars values
(unless *input-path*
(cl-cli:help *options* nil)
(return-from main 1))
(run *input-path* *output-path*))))
;;; vim: set ft=lisp lisp:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment