Cycle palettes

This commit is contained in:
Denis Molony 2017-01-12 08:26:28 +11:00
parent 152ac38ac8
commit d3a328405e
5 changed files with 54 additions and 3 deletions

View File

@ -125,7 +125,7 @@ public class DoubleHiResImage extends HiResImage
private final byte[] auxBuffer;
private DoubleScrunch doubleScrunch;
byte[] packedBuffer;
private final int paletteIndex = 2;
// private final int paletteIndex = 2;
public DoubleHiResImage (String name, byte[] buffer, byte[] auxBuffer)
{
@ -198,6 +198,8 @@ public class DoubleHiResImage extends HiResImage
@Override
protected void createColourImage ()
{
int paletteNdx = paletteIndex % palette2.length;
// image will be doubled horizontally
image = new BufferedImage (140 * 2, 192, BufferedImage.TYPE_INT_RGB);
DataBuffer dataBuffer = image.getRaster ().getDataBuffer ();
@ -217,8 +219,8 @@ public class DoubleHiResImage extends HiResImage
for (int px = 0; px < 28; px += 4)
{
int val = (value >> px) & 0x0F;
dataBuffer.setElem (ndx++, palette2[paletteIndex][val]);
dataBuffer.setElem (ndx++, palette2[paletteIndex][val]); // repeat pixel
dataBuffer.setElem (ndx++, palette2[paletteNdx][val]);
dataBuffer.setElem (ndx++, palette2[paletteNdx][val]); // repeat pixel
}
}
}

View File

@ -17,6 +17,7 @@ public abstract class HiResImage extends AbstractFile
protected static boolean colourQuirks;
protected static boolean monochrome;
protected static int paletteIndex;
protected int fileType;
protected int auxType;
@ -79,6 +80,13 @@ public abstract class HiResImage extends AbstractFile
protected abstract void createColourImage ();
public void cyclePalette ()
{
++paletteIndex;
if (!monochrome)
createImage ();
}
public void setColourQuirks (boolean value)
{
if (colourQuirks == value)

View File

@ -130,6 +130,17 @@ class DataPanel extends JTabbedPane
mh.colourQuirksItem.setAction (new ColourQuirksAction (this));
mh.monochromeItem.setAction (new MonochromeAction (this));
mh.debuggingItem.setAction (new DebuggingAction (this));
mh.paletteItem.setAction (new PaletteAction (this));
}
public void cyclePalette ()
{
if (currentDataSource instanceof HiResImage)
{
HiResImage image = (HiResImage) currentDataSource;
image.cyclePalette ();
imagePanel.setImage (image.getImage ());
}
}
public void setColourQuirks (boolean value)

View File

@ -60,6 +60,7 @@ public class MenuHandler
JMenuItem colourQuirksItem = new JCheckBoxMenuItem ("Colour quirks");
JMenuItem monochromeItem = new JCheckBoxMenuItem ("Monochrome");
JMenuItem debuggingItem = new JCheckBoxMenuItem ("Debugging");
JMenuItem paletteItem = new JMenuItem ("Cycle Palette");
public MenuHandler (Preferences prefs)
{
@ -109,6 +110,7 @@ public class MenuHandler
formatMenu.add (colourQuirksItem);
formatMenu.add (monochromeItem);
formatMenu.add (debuggingItem);
formatMenu.add (paletteItem);
helpMenu.add (new JMenuItem (new EnvironmentAction ()));

View File

@ -0,0 +1,28 @@
package com.bytezone.diskbrowser.gui;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.KeyStroke;
public class PaletteAction extends AbstractAction
{
private final DataPanel owner;
public PaletteAction (DataPanel owner)
{
super ("Cycle Palette");
putValue (Action.SHORT_DESCRIPTION, "Select next color palette");
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt P"));
putValue (Action.MNEMONIC_KEY, KeyEvent.VK_P);
this.owner = owner;
}
@Override
public void actionPerformed (ActionEvent e)
{
owner.cyclePalette ();
}
}