Functional Problem Solving (CSC 151 2015F) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Taking Notes] [Rubric] [Remote Access]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Labs] [Outlines] [Readings] - [Examples] [Handouts]
Reference: [Setup] [VM] [Errors] - [Functions A-Z] [Functions By Topic] - [Racket] [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [Curtsinger (2015F)] [Davis (2013F)] [Rebelsky (2015S)] [Weinman (2014F)]
Misc: [Submit Questions] - [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] - [Issue Tracker (Course)]
Overview
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 likeimage-compute!, but works on an existing image.
> (image-recompute! kitten (lambda (col row)
(modulo (* col row row col col) (irgb 255 255 255))))