      ret#))
 
 (defn pixel-rectangle
-  	  "Converts the screen state coordinates to visible camera pixel coordinates."
-  	  [{:keys [x y width height zoom]}]
-  	  (Rectangle. (- x (/ width 2 zoom))
-                 	    (- y (/ height 2 zoom))
-                 	    (/ width zoom)
-                 	    (/ height zoom)))
+  "Converts the screen state coordinates to visible camera pixel coordinates."
+  [{:keys [x y width height zoom]}]
+  (Rectangle. (- x (/ width 2 zoom))
+              (- y (/ height 2 zoom))
+              (/ width zoom)
+              (/ height zoom)))
 
 (defn screen-rectangle
   "Returns a rectangle centered at x,y."

    (when (and x y)
      (doto graphics
        (.setColor Color/BLUE)
        (.drawRect (- x 25) (- y 25) 50 50)))))
)
  
(defn paint-tiles [^Graphics2D g overlay-tiles-atom screen-state]
  (let [pixel-rect (.getClipBounds g)
        tile-dimensions (screen-state :tile-dimensions)]
    (doseq [[nx ny] (tiles/tiles-in-pixel-rectangle pixel-rect tile-dimensions)]
      (let [tile-index {:nc :overlay
                        :zoom (screen-state :zoom)
                        :nx nx :ny ny :nt 0
                        :nz (screen-state :z)}]
;        (let [[x y] (tiles/tile-to-pixels [nx ny] tile-dimensions 1)]
;            (draw-test-tile g x y)
;          )
        (when-let [image (tile-cache/get-tile
                           overlay-tiles-atom
                           tile-index)]
          (let [[x y] (tiles/tile-to-pixels [nx ny] tile-dimensions 1)]
            (paint/draw-image g image x y)
            ))))))

(defn paint-stage-position [^Graphics2D g screen-state]
  (let [[x y] (:xy-stage-position screen-state)


;; testing

(defn big-region-contrast []
  (swap! ss assoc
         :channels {"Default" {:min 200 :max 800 :gamma 1.0 :color Color/WHITE}})
