Skip to content

Instantly share code, notes, and snippets.

@eshamster
Last active January 1, 2018 16:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eshamster/e5937ccf1f3aa412287267ee09fafc46 to your computer and use it in GitHub Desktop.
Save eshamster/e5937ccf1f3aa412287267ee09fafc46 to your computer and use it in GitHub Desktop.
Create an alpha map png from a png file
#!/bin/sh
#|-*- mode:lisp -*-|#
#| <Put a one-line description here>
exec ros -Q -- $0 "$@"
|#
(progn ;;init forms
(ros:ensure-asdf)
#+quicklisp (ql:quickload '(opticl cl-cli) :silent t))
(defpackage :ros.script.create-alpha-map.lisp.3711282690
(:use :cl
:opticl))
(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
(8-bit-rgba-image
(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