CSC151 2007S, Class 37: Color Palettes * Normal start-of-class time for discussion of campus issues. Admin: * EC for + Attending Wednesday evening Con Brio concert (DEFINITELY 9:30 in the pub). + Attending Thursday noon applied studio recital in Sebring-Lewis. + Attending Thursday 4:15 talk on Calculus for Dogs. + Attending Friday evening talk by Patch Adams. + Attending Saturday evening 10 p.m. RHPS (Jillian IS Columbia) * Given the slew of email I received last night, I expect that we should talk about Assignment 8. * Reading for tomorrow: Vectors. Overview: * Saving space by approximating colors. * One strategy: Web-safe colors. * Another strategy: Color palettes. * Choosing palette colors. * Using different palettes. * Lab! ==Assignment 8== Approaching the problem: * Kernel has *four* parameters * Current column * Current row * Color most recently seen * Count of times we've seen that color (let kernel ((col _) (row _) (color _) (count _)) ... * Four possibilities * Reached end of row Move on to beginning of next row * Current row and column suggest that you've reached the end of the image, so ... * Color at current (col,row) matches current color. Recurse on the next position, incrementing the count and color (kernel ... (+ count 1)) * Color at current (col,row) is a new color, so ... Write the previous information (color and count), APPROXIMATELY (write-rgb color) (write-int count) Recurse with: Next column, same row, color just seen, count of 1 (kernel (+ 1 col) row (image-get-pixel image col row) 1) ==Context: Representing Colors with Fewer Characters== * Storing images in files * Attempting to make more concise * To make files more concise, SACRIFICE * Computation time * Human readability * Today, Sacrifice accuracy for even smaller files * Goal: represent each color with ONE number between 0 and 255. * Strategy: Approximate colors ==Strategy: Web-Safe Colors== * Component to level Turn 0..255 into 0..5 * Multilply by 5/255 and then round * Turn three levels into an integer between 0 and 255 * Treat as three digits in a base 6 number rgb 36*r + 6*g + 1*b * Now, given one of these numbers, how do we go in the reverse direction? * Extract levels from the integer We have 36*r + 6*g + 1*b * Red: Throw away the 6*g + 1*b and then divide by 36 * AKA divide by 36, rounding down: quotient * Green: Throw away 36*r and 1*b and then divide by 6 * AKA modula by 36 (or subtract red-just-computed * 36) quotient by 6 * Blue: Throw away 36*r + 6*g * Turn levels (0..5) back into components (0..255) (let ((red-compononent (* red-level (/ 255 5)))) * Turn components back into colors (rgb-new red-component green-component blue-component) ==Strategy: Color Palettes== * Instead of starting with the computed set of colors above, choose the colors based on the image * List all the colors in your chosen set * The list gives an encoding: To encode the nth color, use the value n * To decode, use list-ref * A LOT LIKE CHARACTERS * What if you want to encode a color not in the list? Use the code of the closest color in the list * HOw do we find that closest color? * Generalize problem from last exam ==Lab Notes== * HA HA HA. We had no time left for lab.