Created
October 26, 2010 09:16
-
-
Save angerman/646584 to your computer and use it in GitHub Desktop.
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
(defmacro my-amap | |
"Maps an expression across an array a, using an index named idx, and | |
return value named ret, initialized to a clone of a, then setting | |
each element of ret to the evaluation of expr, returning the new | |
array ret." | |
{:added "1.0"} | |
[a idx ret expr] | |
`(let [a# ~a | |
~ret (aclone a#)] | |
(loop [~idx (int 0)] | |
(if (< ~idx (alength a#)) | |
(do | |
(aset ~ret ~idx (~expr (aget a# ~idx))) | |
(recur (unchecked-inc ~idx))) | |
~ret)))) | |
(defn get-raster [^java.awt.image.BufferedImage img] | |
(.getRaster img)) | |
(defn get-samples [^java.awt.image.WritableRaster raster x y w h b ^ints a] | |
(.getSamples raster x y w h b a)) | |
(defn set-samples [^java.awt.image.WritableRaster raster x y w h b ^ints a] | |
(.setSamples raster x y w h b a)) | |
(set-samples (get-raster *luma*) 0 0 555 149 0 | |
(my-amap ^ints (get-samples (get-raster *luma*) 0 0 555 149 0 (int-array (* 555 149))) | |
idx | |
^ints ret (fn [x] (if (< 49 x) 255 x)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment