Changing webcam-pixels to "nearest" color from color palette array

to give you a frame for editing your own palette
see this mod

import processing.video.*;
Capture video;

void setup() {
  size(640, 480);
  video = new Capture(this, width, height);
  video.start();
}

void draw() { 
  if (video.available()) {
    video.read();
    if ( !showfilter ) image(video, 0, 0);                 // show org or filtered picture
    video.loadPixels();
    int count = video.width * video.height;
    for (int i = 0; i < count; i++) 
      //video.pixels[i] = color(towebsafe(video.pixels[i]));
      video.pixels[i] = color(toUserPalette(video.pixels[i]));
    updatePixels();

    if ( showfilter ) image(video, 0, 0);                   // show mod picture
  }
}

color towebsafe( color in ) {
  return color( websafe((int)red(in)), websafe((int)red(in)), websafe((int)blue(in)) );
}

int websafe(int c) {
  //https://www.rapidtables.com/web/color/Web_Safe.html
  // c from 0 ..255 for r g bl / w in 6 steps for 255 step color space
  int w = 0;
  if       ( c < 25 ) w = 0;
  else if  ( c < 75 ) w = 51;
  else if  ( c <125 ) w = 102;
  else if  ( c <175 ) w = 153;
  else if  ( c <225 ) w = 204;
  else                w = 255;
  return w;
}

/*
color[] myColors = {#FF0000, #FFC000, #E0FF00};

                        0,   0, 0    // kll add
                      255,   0, 0
                      255, 192, 0
                      224, 255, 0
*/
int user_r(int c) {
  int w = 0;
  if       ( c <112 ) w = 0;
  else if  ( c <240 ) w = 224;
  else                w = 255;
  return w;
}
int user_g(int c) {
  int w = 0;
  if       ( c < 96 ) w = 0;
  else if  ( c <224 ) w = 192;
  else                w = 255;
  return w;
}
int user_b(int c) {
  int w = 0;
  return w;
}

color toUserPalette( color in ) {
  return color( user_r((int)red(in)), user_g((int)red(in)), user_b((int)blue(in)));
}

boolean showfilter = true;

void keyPressed() {
  if ( key == 'f' ) showfilter = ! showfilter;         // toggle show filtered or not
}