direct図、画像の飽和度と輝度を変更


public class PaletteDirectExample {

    static Display display;

    public Image createIndexImage() {
        // ***                    PaletteData(redMask, greenMask, blueMask)
        PaletteData palette = new PaletteData(0xFF0000   , 0xFF00   , 0xFF);

        ImageData imageData = new ImageData(48,48,24,palette);
        for (int x=0;x<48;x++) {
            for(int y=0;y<48;y++) {
                if(y > 11 && y < 35 && x > 11 && x < 35) {
                    imageData.setPixel(x,y,0xdd3311);   // Set the center to green
                } else {
                    imageData.setPixel(x,y,0x33dd22);   // and everything else to red
                }
            }
        };
        return new Image(display,imageData);
    }

    private static void lightImage(ImageData imageData) {
        int pixel;
        RGB rgb;
        Float h,s,b;
        for (int x=0;x<48;x++) {
            for(int y=0;y<48;y++) {
                pixel = imageData.getPixel(x,y);
                rgb = imageData.palette.getRGB(pixel);
                System.out.println(rgb);
                if(rgb.getHSB()[1] != 0.0) {
                    s = rgb.getHSB()[1]+(1-1*rgb.getHSB()[1])/2;
                    b = rgb.getHSB()[2]+(1-1*rgb.getHSB()[2])/3;
                    rgb = new RGB(rgb.getHSB()[0],s,b);
                    pixel = imageData.palette.getPixel(rgb);
                    System.out.println("-- " +rgb);
                    imageData.setPixel(x, y, pixel);
                }
            }
        };
    }

    public static void main(String[] args) {
        display = new Display();
        PaletteDirectExample e = new PaletteDirectExample();
        Image image = e.createIndexImage();
        
        lightImage(image.getImageData());
    }

}

 
コード:直接図の明るさと飽和度を変更し、元の図のRGBは2種類あり、変換後:
RGB {221, 51, 17}--》 RGB {232, 46, 9}
RGB {51, 221, 34}--》 RGB {37, 232, 18}