-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #32 This adds the ability to: - Create a histogram given a literal string encoding of one. - Create a histogram from a rectangle of pixels on the screen. - A condition comparing whether two histograms are sufficiently similar. This allows branching based on the contents on the screen compared a known earlier state (which must be precomputed and encoded for now.)
- Loading branch information
Showing
3 changed files
with
59 additions
and
6 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,27 @@ | ||
(ns cljck.io.images | ||
(:require [cljck.io.sync :refer [robot]]) | ||
(:import | ||
[java.awt Rectangle Toolkit] | ||
[java.awt.image BufferedImage] | ||
[java.io File] | ||
[javax.imageio ImageIO])) | ||
|
||
(defn screen-resolution | ||
"Returns the current width and height of the screen." | ||
[] | ||
((juxt (memfn getWidth) (memfn getHeight)) | ||
(.. Toolkit getDefaultToolkit getScreenSize))) | ||
|
||
(defn buffered-image | ||
"Takes a path to an image file, which is assumed available on the class path, | ||
and constructs and returns a BufferedImage from it." | ||
[path] | ||
(ImageIO/read (File. ^String path))) | ||
|
||
(defn fetch-screen | ||
"Returns a BufferedImage of the pixels currently on the screen. Optionally | ||
takes a rectangle to limit the fetching to." | ||
([] | ||
(apply fetch-screen 0 0 (screen-resolution))) | ||
([x y width height] | ||
(.createScreenCapture robot (Rectangle. x y width height)))) |