CSC 151: Extra Session 4 (Thursday, 25 Sept. 2014)
==================================================

What is going to be on the quiz tomorrow?

* Integer-encoded RGB colors and the basic operations on those colors.
* Standard color transformations.
* Image and pixel operations, including `image-variant` and `image-transform!`.
* `compose` and `o`.
* (Possibly): lambda expressions, as used with the image transformations.
* (Not): `map` and the other subjects we did yesterday.

What do you see as the standard color transformations and what do
we need to do with them?

* irgb-redder, irgb-greener, irgb-bluer
    * Makes the color redder/greener/bluer by increasing the corresponding
      component.
    * We could also achieve a similar effect by decreasing the other
      components.  We won't worry about that.
* irgb-complement
    * Inverts all of the components, as in (- 255 component)
* irgb-lighter and irgb-darker
    * Lighter: Increases color values
    * Darker: Decreases color values
* Relevant questions might include
    * What is the effect of [this set of color transformations]?
    * Given an image, transform it in [this way]


Could you give us some sample quiz questions?

* This picture of Casey (image name is `casey`) has not enough red and 
  is a bit too dark.  Write code to make an improved version of that 
  picture.

        (define temp (image-variant casey irgb-redder))
        (image-variant temp irgb-lighter)

        (image-variant (image-variant casey irgb-redder) irgb-lighter)

        (image-variant casey (o irgb-lighter irgb-redder))

* This picture of Casey (image name is `casey`) has not enough red and 
  is a bit too dark.  Write code to make the picture better.

        (image-transform! casey irgb-redder)
        (image-transform! casey irgb-lighter)

        (image-transform! (image-transform! casey irgb-redder) irgb-lighter)

        (image-transform! casey (o irgb-lighter irgb-redder))

* This picture of Casey (image name is `casey`) has too much red and 
  is a bit too dark.  Write code to make the picture better.

        (image-transform! casey (o irgb-greener irgb-bluer irgb-lighter))
        (image-transform! casey (o irgb-greener irgb-bluer))

* Are there colors for which `(irgb-lighter (irgb-darker color))` is
  not the same as `(irgb-darker (irgb-lighter color))`?
     * For really dark colors, like black, `(irgb-darker color)` is just
       black, making them lighter will then make them really dark grey
     * For really light colors, like white, we see something similar.
     
* Are there colors for which `(irgb-lighter (irgb-redder color))`
  is different than `(irgb-redder (irgb-lighter color))`?
     * Suppose we have (250 250 250).  Suppose that lighter adds 16
       to each component and redder adds 32 to the red component.
         * Redder first: (250 250 250) -> (255 250 250) -> (255 255 255)
         * Lighter first: (250 250 250) -> (255 255 255) -> (255 255 255)
     * Suppose we have (12 11 10)
         * Redder first: (12 11 10) -> (44 11 10) -> (60 27 26)
         * Lighter first: (12 11 10) -> (28 27 26) -> (60 27 26)

Additional Questions
--------------------

* What qualifies a color as "blue" rather than something else?
    * We convert from RGB to HSV and look at the hue.

* When might we use lambda?
    * When you define functions (as you've been doing for a few weeks)
    * When you are using `image-variant` or `image-transform!` and you
      need to generate a new transformation on the fly.

* Quiz question: Write an instruction to transform the image of casey so
  that the green component is set to 0 and the red component is 
  (approximate) halved.

         (define irgb-damage 
           (lambda (color)
             (irgb (round (/ (rgb-red color) 2))
                   0
                   (irgb-blue color))))
         (image-transform! casey irgb-damage)

         (image-transform! casey 
                           (lambda (color) (irgb (round (/ (irgb-red color) 2))
                                                 0
                                                 (irgb-blue color))))

* Over the longer term, you'll use lambdas almost any time you need a
  "one time use" function.
* In HW 4, you'll sometimes use lambdas in cases in which you cannot
  easily use named functions.

Example: Write a function, `(redder-by! image amount)`, which increases the
red component of the given image by the specified amount.  For example,
`(redder-by! casey 20)`, the red component of each pixel should increase
by 20 (up to 255).  Similarly, `(redder-by! casey -5)1, the red component
of each pixel should decrease by 5 (increase by -5)

    (define redder-by!
       (lambda (image amount)
          (image-transform! image
                            (lambda (color) (irgb (+ amount (rgb-red color))
                                                  (irgb-green color)
                                                  (irgb-blue color))))))
vs.

    (define redder-by!
      (lambda (image amount)
        (image-transform! image somewhat-redder)))
    (define somewhat-redder
      (lambda (color)
        (irgb (+ amount (irgb-red color))
              (irgb-green color)
              (irgb-blue color))))

The problem in the second is that `somewhat-redder` doesn't have access
to `amount`.
