Created
September 3, 2019 17:07
-
-
Save duckyuck/e4f675d0d7d44a71010cbd030de75551 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(defn duotone-filter [^java.awt.image.Raster raster] | |
(let [dest (.createCompatibleWritableRaster raster) | |
bands (.getNumBands dest) | |
dest-pixel (int-array bands) | |
w (.getWidth raster) | |
h (.getHeight raster) | |
] | |
(loop [y 0] | |
(when (< y h) | |
(loop [x 0 | |
^ints pixel nil] | |
(when (< x w) | |
(let [pixel (.getPixel raster (int x) (int y) pixel)] | |
(aset dest-pixel 0 (int (aget pixel 2))) | |
(aset dest-pixel 1 (int (aget pixel 1))) | |
(aset dest-pixel 2 (int (aget pixel 0))) | |
(.setPixel dest x y dest-pixel) | |
(recur (inc x) pixel)))) | |
(recur (inc y)))) | |
dest)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment