Create an alpha map png from a png file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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