User Tools

Site Tools


cs276:a16:tgc_-_hw1

/*
 * Posterize - reduce the number of reds, greens, blues to 4 each.
   number determined by array of 12,  first four are the reds, 
   the next the greens, and so on.
 */
 
void posterize(PImage img, int[] list) {
  img.loadPixels();
  for(int row = 0; row < img.height; row++)
    for(int col = 0; col < img.width; col++)
    {
      color c = img.get(col, row);
      float r = red(c);
      float g = green(c);
      float b = blue(c);
 
      if (r < 65) {
         r = list[0];
      }  else if (r < 128) {
         r = list[1];
      } else if (r < 192) {
         r = list[2];
      } else {
         r = list[3];
      }
 
      if (g < 65) {
        g = list[4];
      } else if (g < 128) {
        g = list[5];
      } else if (g < 192) {
        g = list[6];
      } else {
        g = list[7];
      }
 
      if (b < 65) {
        b = list[8];
      } else if (b < 128) {
        b = list[9];
      } else if (b < 192) {
        b = list[10];
      } else {
        b = list[11];
      }
 
     img.set(col, row, color(r, g, b));
    }
 
  img.updatePixels();
}

cs276/a16/tgc_-_hw1.txt · Last modified: 2016/09/27 18:44 by tom311