ByteSwapRecolorer.java :  » Game » jbots » com » zonski » jbots » desktop » client » recolor » Java Open Source

Java Open Source » Game » jbots 
jbots » com » zonski » jbots » desktop » client » recolor » ByteSwapRecolorer.java
package com.zonski.jbots.desktop.client.recolor;

import com.zonski.jbots.desktop.client.Recolorer;

/**
 * Created by IntelliJ IDEA.
 * User: Chris Glover
 * Date: Oct 15, 2003
 * Time: 2:19:14 PM
 * To change this template use Options | File Templates.
 *
 * Recolorer that swaps two bytes in the source color
 */
public class ByteSwapRecolorer implements Recolorer
{
    private int sourceByte;
    private int targetByte;

    public ByteSwapRecolorer(int sourceByte, int targetByte)
    {
        this.sourceByte = sourceByte;
        this.targetByte = targetByte;
    }

    public int recolor(int color)
    {
        int result = color;
        int sourceColor = (result >> (this.sourceByte * 8)) & 0xFF;
        int targetColor = (result >> (this.targetByte * 8)) & 0xFF;
        result = result & ~(0xFF << (this.targetByte * 8)) & ~(0xFF << (this.sourceByte * 8));
        result = result | (sourceColor << (this.targetByte * 8)) | (targetColor << (this.sourceByte * 8));
        return result;
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.