Slick Forums

Discuss the Slick 2D Library
It is currently Wed Dec 11, 2019 4:48 pm

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: RFE: Palette Swap?
PostPosted: Sat Dec 01, 2007 6:43 pm 
Offline
Oldbie

Joined: Tue Nov 28, 2006 6:18 pm
Posts: 429
I recall there being a test of that a long time ago, but I can't seem to locate it at all.

(RFE: See Dantarion's suggestion)


Last edited by Jon on Sun Dec 02, 2007 8:02 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 01, 2007 8:05 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1482
I think Kev had some code in ROY that adjusted the hue of an image and produced a new image.

http://slick.javaunlimited.net/viewtopic.php?t=325


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 02, 2007 7:07 pm 
Offline

Joined: Sun Feb 11, 2007 9:25 pm
Posts: 92
Maybe this code can be thrown into a Slick util package?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 22, 2007 8:23 pm 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
My solution for this was a bit hacky and relied on modifing textures before sending to the card. Still haven't found a good solution for this, be nice to get the card to do it.

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 06, 2008 1:24 pm 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
Anyone got a good solution?

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 30, 2009 1:55 pm 
Offline
Regular

Joined: Mon Dec 08, 2008 2:17 pm
Posts: 160
Can slick use a paletted texture? and where is the source code for roy?


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 30, 2009 2:16 pm 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
There's no paletted texture support in Slick.

ROY source code isn't open.

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 26, 2011 9:35 pm 
Offline

Joined: Sun Jun 26, 2011 9:32 pm
Posts: 11
Sorry for the late answer, but the following does the job for me :

Code:
        final BufferedImage source = new Store("data/sheets").newBufferedImage("garbage.png");
        final WritableRaster clone = source.copyData(null);
        final DataBufferInt dataBuffer = (DataBufferInt) clone.getDataBuffer();

        final ImageBuffer destinationbuffer = new ImageBuffer(source.getWidth(), source.getHeight());
        for (int y = 0; y < destinationbuffer.getHeight(); y++) {
            for (int x = 0; x < destinationbuffer.getWidth(); x++) {
                // Base color is always blue
                final Color pixel = new Color(dataBuffer.getData()[x + (y * destinationbuffer.getWidth())]);
                final float[] hsbColor = java.awt.Color.RGBtoHSB(pixel.getRed(), pixel.getGreen(), pixel.getBlue(), null);
                final Color rgbColor = new Color(java.awt.Color.HSBtoRGB(palette.getHue(), hsbColor[1], hsbColor[2]));
                destinationbuffer.setRGBA(x, y, rgbColor.getRed(), rgbColor.getGreen(), rgbColor.getBlue(), rgbColor.getAlpha());
            }
        }
        sheet = Store.newSpriteSheet(destinationbuffer.getImage(), WIDTH, HEIGHT);


Where Palette is:

Code:

public enum Palette {
    BLUE(Color.BLUE), //
    RED(Color.RED), //
    GREEN(Color.GREEN), //
    YELLOW(Color.YELLOW), //
    PINK(0.9F), //
    ORANGE(Color.ORANGE), //
    MAGENTA(Color.MAGENTA), //
    CYAN(Color.CYAN);

    private final float hue;

    private Palette(final Color color) {
        this(Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null)[0]);
    }

    private Palette(final float hue) {
        this.hue = hue;
    }

    public final float getHue() {
        return hue;
    }
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group