sinterface Decolorizer { int toGrayScale(int rgb); default int toGrayScale(Color color) { ret toGrayScale(colorToRGBInt(color)); } srecord Red is Decolorizer { public int toGrayScale(int rgb) { ret (rgb >> 16) & 0xFF; } } srecord Green is Decolorizer { public int toGrayScale(int rgb) { ret (rgb >> 8) & 0xFF; } } srecord Blue is Decolorizer { public int toGrayScale(int rgb) { ret rgb & 0xFF; } } srecord Alpha is Decolorizer { public int toGrayScale(int rgb) { ret (rgb >> 24) & 0xFF; } } // just the average of the 3 channels srecord Simple is Decolorizer { public int toGrayScale(int rgb) { int r = (rgb >> 16) & 0xFF; int g = (rgb >> 8) & 0xFF; int b = rgb & 0xFF; ret (r+g+b+1)/3; } } }