(define drawable-begin-caching! pixel-begin) (define drawable-end-caching! pixel-end) (define drawable-set-pixel! set-pixel-rgb) ;;; Procedure: ;;; image-iterate! ;;; Parameters: ;;; image, an image ;;; colorfun, a function from two integers to colors ;;; Purpose: ;;; Iterate through all the positions in the image, using colorfun ;;; to compute the color at each position. ;;; Produces: ;;; [Nothing, called for the side effect.] ;;; Preconditions: ;;; image is a valid, open image ;;; colorfun is a function of the form (lambda (col row) ...) ;;; colorfun returns colors. ;;; Postconditions: ;;; image has been updated by applying the function at each position. ;;; Plus: ;;; If colorfun returns color-transparent, does not update the ;;; color at the specified position. (define image-iterate! (lambda (image fun) (let ((width (image-width image)) (height (image-height image)) (layer (image-get-drawable image))) (drawable-begin-caching! layer) (let kernel ((col 0) (row 0)) (cond ((>= row height) (drawable-end-caching! layer) image) ((>= col width) (kernel 0 (+ row 1))) (else (let ((color (fun col row))) (if (not (= color color-transparent)) (drawable-set-pixel! layer col row color)) (kernel (+ col 1) row))))))))