Skip to content

Instantly share code, notes, and snippets.

@duckyuck
Created September 3, 2019 17:07
Show Gist options
  • Save duckyuck/e4f675d0d7d44a71010cbd030de75551 to your computer and use it in GitHub Desktop.
Save duckyuck/e4f675d0d7d44a71010cbd030de75551 to your computer and use it in GitHub Desktop.
(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