#lang racket
(require gigls/unsafe)
(provide (all-defined-out))

;;; File:
;;;   procedures-rgb-lab.rkt
;;; Authors:
;;;   Samuel A. Rebelsky
;;;   YOUR NAME HERE
;;; Summary:
;;;   Code for the lab entitled "Writing Your Own Procedures"

; +--------+---------------------------------------------------------
; | Values |
; +--------+

; Some interesting colors
(define fave4 (irgb 200 10 150))
(define fave5 (irgb 200 100 255))

; A useful image
(define kitten (image-load "/home/rebelsky/Desktop/kitten.jpg"))

; +------------+-----------------------------------------------------
; | Procedures |
; +------------+

(define my-irgb-rotate
  (lambda (color)
    (irgb (irgb-green color)
          (irgb-blue color)
          (irgb-red color))))

(define my-irgb-rotate2
  (lambda (color)
    (irgb (irgb-blue color)
          (irgb-red color)
          (irgb-green color))))

(define irgb-greyscale-1
  (lambda (color)
    (irgb (* 1/3 (+ (irgb-red color) (irgb-green color) (irgb-blue color)))
          (* 1/3 (+ (irgb-red color) (irgb-green color) (irgb-blue color)))
          (* 1/3 (+ (irgb-red color) (irgb-green color) (irgb-blue color))))))

;;; Procedure:
;;;   irgb-average-component
;;; Parameters:
;;;   color, an integer-encoded RGB color with components r, g, and b.
;;; Purpose:
;;;   Compute the average of the three components in color
;;; Produces:
;;;   ave-component, a non-negative rational number
;;; Preconditions:
;;;   [No additional]
;;; Postconditions:
;;;   ave-component = (* 1/3 (+ r g b))
(define irgb-average-component
  (lambda (color)
    (* 1/3 (+ (irgb-red color) (irgb-green color) (irgb-blue color)))))

;;; Procedure:
;;;   irgb-grey
;;; Parameters:
;;;   brightness, a non-negative rational number
;;; Purpose:
;;;   Create a grey color of the appropriate brightness
;;; Produces:
;;;   grey, an integer-encoded RGB color
;;; Preconditions:
;;;   [No additional]
;;; Postconditions:
;;;   The three components of grey are equal.  That is,
;;;     (irgb-red grey) = (irgb-green grey) = (irgb-blue grey)
;;;   All three components are close to brightness.  That is
;;;     (abs (- (irgb-red grey) brightness)) &lt; 1
(define irgb-grey
  (lambda (brightness)
    (irgb brightness brightness brightness)))

(define irgb-greyscale-2 
  (lambda (color)
    (irgb-grey (irgb-average-component color))))

(define irgb-greyscale-3 (compose irgb-grey irgb-average-component))

(define my-square
  (lambda (x)
    (* x x)))
