Functional Problem Solving (CSC 151 2015F) : EBoards

CSC151.01 2015F, Class 45: Pause for Breath


Overview

Preliminaries

Admin

Upcoming Work

Extra Credit Opportunities

Academic

Peer Support

Miscellaneous

Regular Peer Support

Upcoming Peer Support

Other Good Things (No Extra Credit)

Project Ideas and Questions

How do I copy and paste from one image to another?

;;; Procedure:
;;;   new-copy-paste!
;;; Parameters:
;;;   source, an image
;;;   source-left, a non-negative integer
;;;   source-top, a non-negative integer
;;;   source-width, a positive integer
;;;   source-height, a positive integer
;;;   target, an image
;;;   target-left, a non-negative integer
;;;   target-top, a non-negative integer
;;;   target-width, a positive integer
;;;   target-height, a positive integer
;;; Purpose:
;;;   Copy one rectangular region of the image to a rectangular
;;;   region in another image, resizing as necessary.
;;; Produces: 
;;;   [Nothing; called for the side effect]
;;; Preconditions:
;;;   0 <= source-left < (image-width source)
;;;   0 <= source-top < (image-height source)
;;;   (+ source-left source-width) < (image-width source)
;;;   (+ source-top source-height) < (image-height source)
;;;   0 <= target-left < (image-width target)
;;;   0 <= target-top < (image-height target)
;;;   (+ target-left target-width) < (image-width target)
;;;   (+ target-top target-height) < (image-height target)
;;; Postconditions:
;;;   The specified area of the target image now contains the same subimage
;;;   as the source area (scaled, as appropriate).
(define new-copy-paste!
  (lambda (source 
           source-left source-top source-width source-height
           target
           target-left target-top target-width target-height)
    (let ([source-layer (image-get-layer source)]
          [target-layer (image-get-layer target)])
      (image-select-rectangle! source REPLACE 
                               source-left source-top 
                               source-width source-height)
      (gimp-edit-copy source-layer)
      (image-select-rectangle! target REPLACE
                               target-left target-top
                               target-width target-height)
      (let ([pasted (car (gimp-edit-paste target-layer 1))])
        (image-select-nothing! source)
        (image-select-nothing! target)
        (gimp-layer-scale pasted target-width target-height 1)
        (gimp-image-flatten target)
        (context-update-displays!)))))

How can I select a non-rectangular region, such as a triangle?

(image-select-polygon! image REPLACE (cons x1 y1) (cons x2 y2) ... )

For example

    > (define kitten (image-show (image-load "/home/rebelsky/Desktop/kitten.jpg")))
    > (image-select-polygon! kitten REPLACE (cons 140 120) (cons 160 15) (cons 200 80))
    '()
    > (image-transform! kitten irgb-complement)

How can I get a semi-transparent overlay?

First, select a portion of the image.

Next, use (image-transform! image (lambda (col row) ...)).

Finally, select nothing.

Are there other things like image-transform!?

We also have image-recompute!, which is like image-compute!, but works on an existing image.

    > (image-recompute! kitten (lambda (col row)
                                 (modulo (* col row row col col) (irgb 255 255 255))))

Questions

Quiz

Project work time