| | 197 | ;;; image |
|---|
| | 198 | |
|---|
| | 199 | ;; contract-images are stored as store-images. The image slot of |
|---|
| | 200 | ;; contract-node points to the current store-image. |
|---|
| | 201 | |
|---|
| | 202 | (defun contract-node-store-image-name (node) |
|---|
| | 203 | (format nil "contract-node~{~D~}" (node-path node))) |
|---|
| | 204 | |
|---|
| | 205 | (defun contract-node-update-image (node) |
|---|
| | 206 | (labels ((find-contract-color (contract) |
|---|
| | 207 | (destructuring-bind (r g b) |
|---|
| | 208 | (contract-color contract) |
|---|
| | 209 | (cl-gd:find-color r g b :alpha 40)))) |
|---|
| | 210 | (let ((box (geo-box node)) |
|---|
| | 211 | (image-size *contract-tree-images-size*)) |
|---|
| | 212 | (cl-gd:with-image (cl-gd:*default-image* image-size image-size t) |
|---|
| | 213 | (setf (cl-gd:save-alpha-p) t |
|---|
| | 214 | (cl-gd:alpha-blending-p) nil) |
|---|
| | 215 | ;; (cl-gd:draw-rectangle* 0 0 127 127 :filled nil :color (cl-gd:find-color 255 0 0)) |
|---|
| | 216 | (let ((transparent (cl-gd:find-color 255 255 255 :alpha 127)) |
|---|
| | 217 | (subbox (make-geo-box 0d0 0d0 0d0 0d0))) |
|---|
| | 218 | (cl-gd:do-rows (y) |
|---|
| | 219 | (cl-gd:do-pixels-in-row (x) |
|---|
| | 220 | (let ((subbox (geo-subbox box x y image-size subbox))) |
|---|
| | 221 | (multiple-value-bind (m2x m2y) |
|---|
| | 222 | (geo-box-middle-m2coord subbox) |
|---|
| | 223 | (setf (cl-gd:raw-pixel) |
|---|
| | 224 | (let* ((m2 (ignore-errors (get-m2 m2x m2y))) |
|---|
| | 225 | (contract (and m2 (m2-contract m2)))) |
|---|
| | 226 | (if (and contract (contract-paidp contract)) |
|---|
| | 227 | (find-contract-color contract) |
|---|
| | 228 | transparent)))))))) |
|---|
| | 229 | (let* ((image-name (contract-node-store-image-name node)) |
|---|
| | 230 | (old-store-image (store-image-with-name image-name))) |
|---|
| | 231 | (when old-store-image (delete-object old-store-image)) |
|---|
| | 232 | (make-store-image :name image-name |
|---|
| | 233 | :type :png)))))) |
|---|
| | 234 | |
|---|
| | 235 | (defun contract-node-update-image-if-needed (node) |
|---|
| | 236 | (when (or (null (image node)) |
|---|
| | 237 | (> (timestamp node) (blob-timestamp (image node)))) |
|---|
| | 238 | (contract-node-update-image node))) |
|---|
| | 239 | |
|---|
| 202 | | (handle-if-node-modified |
|---|
| 203 | | (incf (image-req-count node)) |
|---|
| 204 | | (let ((box (geo-box node)) |
|---|
| 205 | | (image-size *contract-tree-images-size*)) |
|---|
| 206 | | (cl-gd:with-image (cl-gd:*default-image* image-size image-size t) |
|---|
| 207 | | (setf (cl-gd:save-alpha-p) t |
|---|
| 208 | | (cl-gd:alpha-blending-p) nil) |
|---|
| 209 | | ;; (cl-gd:draw-rectangle* 0 0 127 127 :filled nil :color (cl-gd:find-color 255 0 0)) |
|---|
| 210 | | (let ((white (cl-gd:find-color 255 255 255 :alpha 127)) |
|---|
| 211 | | (subbox (make-geo-box 0d0 0d0 0d0 0d0))) |
|---|
| 212 | | (cl-gd:do-rows (y) |
|---|
| 213 | | (cl-gd:do-pixels-in-row (x) |
|---|
| 214 | | (let ((subbox (geo-subbox box x y image-size subbox))) |
|---|
| 215 | | (multiple-value-bind (m2x m2y) |
|---|
| 216 | | (geo-box-middle-m2coord subbox) |
|---|
| 217 | | (setf (cl-gd:raw-pixel) |
|---|
| 218 | | (let* ((m2 (ignore-errors (get-m2 m2x m2y))) |
|---|
| 219 | | (%contract (m2-contract m2)) |
|---|
| 220 | | (contract (and m2 |
|---|
| 221 | | %contract |
|---|
| 222 | | (contract-paidp %contract) |
|---|
| 223 | | %contract))) |
|---|
| 224 | | (if contract |
|---|
| 225 | | (destructuring-bind (r g b) |
|---|
| 226 | | (contract-color contract) |
|---|
| 227 | | (cl-gd:find-color r g b :alpha 40)) |
|---|
| 228 | | white)))))))) |
|---|
| 229 | | (emit-image-to-browser cl-gd:*default-image* :png :date (timestamp node))))))) |
|---|
| | 246 | (let* ((path (parse-path path)) |
|---|
| | 247 | (node (find-node-with-path *contract-tree* path)) |
|---|
| | 248 | (image (image node))) |
|---|
| | 249 | (hunchentoot:handle-if-modified-since (timestamp image)) |
|---|
| | 250 | (with-store-image* (image) |
|---|
| | 251 | (emit-image-to-browser cl-gd:*default-image* :png :date (timestamp image)))))) |
|---|