diff --git a/src/com/bytezone/diskbrowser/applefile/HiResImage.java b/src/com/bytezone/diskbrowser/applefile/HiResImage.java index 0e1ba02..387b174 100644 --- a/src/com/bytezone/diskbrowser/applefile/HiResImage.java +++ b/src/com/bytezone/diskbrowser/applefile/HiResImage.java @@ -1,7 +1,6 @@ package com.bytezone.diskbrowser.applefile; -import java.awt.image.BufferedImage; -import java.awt.image.DataBuffer; +import java.awt.Color; import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.List; @@ -9,6 +8,7 @@ import java.util.List; import javax.imageio.ImageIO; import com.bytezone.diskbrowser.prodos.ProdosConstants; +import com.bytezone.diskbrowser.utilities.HexFormatter; public abstract class HiResImage extends AbstractFile { @@ -127,16 +127,17 @@ public abstract class HiResImage extends AbstractFile { String auxText = ""; StringBuilder text = new StringBuilder ("Image File : " + name); - text.append (String.format ("%nFile type : $%02X", fileType)); + text.append (String.format ("%nFile type : $%02X %s", fileType, + ProdosConstants.fileTypes[fileType])); switch (fileType) { - case ProdosConstants.FILE_TYPE_PICT: + case ProdosConstants.FILE_TYPE_PICT: // 0x08 if (auxType < 0x4000) { - auxText = "Graphics File"; + auxText = "Apple II Graphics File"; byte mode = buffer[0x78]; // 0-7 - System.out.println ("Prodos PICT, mode=" + mode); + System.out.println ("Prodos PICT, mode=" + mode); // see mode table above } else if (auxType == 0x4000) auxText = "Packed Hi-Res File"; @@ -144,8 +145,10 @@ public abstract class HiResImage extends AbstractFile auxText = "Packed Double Hi-Res File"; break; - case ProdosConstants.FILE_TYPE_PNT: - if (auxType == 1) + case ProdosConstants.FILE_TYPE_PNT: // 0xC0 + if (auxType == 0) + auxText = "Paintworks Packed SHR Image"; + else if (auxType == 1) auxText = "Packed Super Hi-Res Image"; else if (auxType == 2) auxText = "Super Hi-Res Image (Apple Preferred)"; @@ -153,7 +156,7 @@ public abstract class HiResImage extends AbstractFile auxText = "Packed QuickDraw II PICT File"; break; - case ProdosConstants.FILE_TYPE_PIC: + case ProdosConstants.FILE_TYPE_PIC: // 0xC1 if (auxType == 0) auxText = "Super Hi-res Screen Image"; else if (auxType == 1) @@ -176,27 +179,6 @@ public abstract class HiResImage extends AbstractFile return text.toString (); } - protected void makeScreen (byte[] buffer) - { - image = new BufferedImage (320, 200, BufferedImage.TYPE_BYTE_GRAY); - DataBuffer db = image.getRaster ().getDataBuffer (); - - int element = 0; - int ptr = 0; - for (int row = 0; row < 200; row++) - for (int col = 0; col < 160; col++) - { - int pix1 = (buffer[ptr] & 0xF0) >> 4; - int pix2 = buffer[ptr] & 0x0F; - if (pix1 > 0) - db.setElem (element, 255); - if (pix2 > 0) - db.setElem (element + 1, 255); - element += 2; - ptr++; - } - } - /* * Unpack the Apple PackBytes format. * @@ -216,7 +198,7 @@ public abstract class HiResImage extends AbstractFile { // routine found here - http://kpreid.livejournal.com/4319.html - byte[] newBuf = new byte[32768]; + byte[] newBuf = new byte[32768]; // this might be wrong byte[] fourBuf = new byte[4]; int ptr = 0, newPtr = 0; @@ -258,6 +240,58 @@ public abstract class HiResImage extends AbstractFile return newBuf; } + // Super Hi-res IIGS + protected int unpackLine (byte[] buffer, byte[] newBuf, int newPtr) + { + byte[] fourBuf = new byte[4]; + + int ptr = 0; + while (ptr < buffer.length) + { + int type = (buffer[ptr] & 0xC0) >> 6; // 0-3 + int count = (buffer[ptr++] & 0x3F) + 1; // 1-64 + + if (ptr >= buffer.length) + break; + + switch (type) + { + case 0: + while (count-- != 0) + if (newPtr < unpackedBuffer.length && ptr < buffer.length) + newBuf[newPtr++] = buffer[ptr++]; + break; + + case 1: + byte b = buffer[ptr++]; + while (count-- != 0) + if (newPtr < unpackedBuffer.length) + newBuf[newPtr++] = b; + break; + + case 2: + for (int i = 0; i < 4; i++) + if (ptr < buffer.length) + fourBuf[i] = buffer[ptr++]; + while (count-- != 0) + for (int i = 0; i < 4; i++) + if (newPtr < unpackedBuffer.length) + newBuf[newPtr++] = fourBuf[i]; + break; + + case 3: + b = buffer[ptr++]; + count *= 4; + while (count-- != 0) + if (newPtr < unpackedBuffer.length) + newBuf[newPtr++] = b; + break; + } + } + + return newPtr; + } + // Beagle Bros routine to expand a hi-res screen private byte[] unscrunch (byte[] src) { @@ -337,4 +371,114 @@ public abstract class HiResImage extends AbstractFile { return paletteFactory.getPalettes (); } + + class ColorTable + { + int id; + ColorEntry[] entries = new ColorEntry[16]; + + public ColorTable () + { + // default empty table + id = -1; + for (int i = 0; i < 16; i++) + { + entries[i] = new ColorEntry (); + } + } + + public ColorTable (int id, byte[] data, int offset) + { + this.id = id; + for (int i = 0; i < 16; i++) + { + entries[i] = new ColorEntry (data, offset); + offset += 2; + } + } + + String toLine () + { + + StringBuilder text = new StringBuilder (); + + text.append (String.format (" %X", id)); + for (int i = 0; i < 16; i++) + text.append (String.format (" %04X", entries[i].value)); + + return text.toString (); + } + + void reverse () + { + for (int i = 0; i < 8; i++) + { + ColorEntry temp = entries[i]; + entries[i] = entries[15 - i]; + entries[15 - i] = temp; + } + } + + @Override + public String toString () + { + StringBuilder text = new StringBuilder (); + + text.append (String.format ("%2d ColorTable%n", id)); + for (int i = 0; i < 8; i++) + text.append (String.format (" %2d: %04X", i, entries[i].value)); + text.append ("\n"); + for (int i = 8; i < 16; i++) + text.append (String.format (" %2d: %04X", i, entries[i].value)); + + return text.toString (); + } + } + + class ColorEntry + { + int value; // 0RGB + Color color; + + public ColorEntry () + { + // default empty entry + value = 0; + color = new Color (0, 0, 0); + } + + public ColorEntry (byte[] data, int offset) + { + value = HexFormatter.unsignedShort (data, offset); + + int red = ((value >> 8) & 0x0f) * 17; + int green = ((value >> 4) & 0x0f) * 17; + int blue = (value & 0x0f) * 17; + color = new Color (red, green, blue); + } + + @Override + public String toString () + { + return String.format ("ColorEntry: %04X", value); + } + } + + class DirEntry + { + int numBytes; + int mode; + + public DirEntry (byte[] data, int offset) + { + numBytes = HexFormatter.unsignedShort (data, offset); + mode = HexFormatter.unsignedShort (data, offset + 2); + } + + @Override + public String toString () + { + return String.format ("Bytes: %5d, mode: %02X", numBytes, mode); + } + } } \ No newline at end of file diff --git a/src/com/bytezone/diskbrowser/applefile/SHRPictureFile.java b/src/com/bytezone/diskbrowser/applefile/SHRPictureFile.java index 36b3cde..d404de6 100644 --- a/src/com/bytezone/diskbrowser/applefile/SHRPictureFile.java +++ b/src/com/bytezone/diskbrowser/applefile/SHRPictureFile.java @@ -1,6 +1,5 @@ package com.bytezone.diskbrowser.applefile; -import java.awt.Color; import java.awt.image.BufferedImage; import java.awt.image.DataBuffer; import java.util.ArrayList; @@ -48,7 +47,24 @@ public class SHRPictureFile extends HiResImage @Override protected void createMonochromeImage () { - makeScreen (unpackedBuffer); + // makeScreen (unpackedBuffer); + image = new BufferedImage (320, 200, BufferedImage.TYPE_BYTE_GRAY); + DataBuffer db = image.getRaster ().getDataBuffer (); + + int element = 0; + int ptr = 0; + for (int row = 0; row < 200; row++) + for (int col = 0; col < 160; col++) + { + int pix1 = (unpackedBuffer[ptr] & 0xF0) >> 4; + int pix2 = unpackedBuffer[ptr] & 0x0F; + if (pix1 > 0) + db.setElem (element, 255); + if (pix2 > 0) + db.setElem (element + 1, 255); + element += 2; + ptr++; + } } @Override @@ -220,58 +236,6 @@ public class SHRPictureFile extends HiResImage } } - // Super Hi-res IIGS - protected int unpackLine (byte[] buffer, byte[] newBuf, int newPtr) - { - byte[] fourBuf = new byte[4]; - - int ptr = 0; - while (ptr < buffer.length) - { - int type = (buffer[ptr] & 0xC0) >> 6; // 0-3 - int count = (buffer[ptr++] & 0x3F) + 1; // 1-64 - - if (ptr >= buffer.length) - break; - - switch (type) - { - case 0: - while (count-- != 0) - if (newPtr < unpackedBuffer.length && ptr < buffer.length) - newBuf[newPtr++] = buffer[ptr++]; - break; - - case 1: - byte b = buffer[ptr++]; - while (count-- != 0) - if (newPtr < unpackedBuffer.length) - newBuf[newPtr++] = b; - break; - - case 2: - for (int i = 0; i < 4; i++) - if (ptr < buffer.length) - fourBuf[i] = buffer[ptr++]; - while (count-- != 0) - for (int i = 0; i < 4; i++) - if (newPtr < unpackedBuffer.length) - newBuf[newPtr++] = fourBuf[i]; - break; - - case 3: - b = buffer[ptr++]; - count *= 4; - while (count-- != 0) - if (newPtr < unpackedBuffer.length) - newBuf[newPtr++] = b; - break; - } - } - - return newPtr; - } - private boolean isEmpty (byte[] buffer) { for (byte b : buffer) @@ -340,104 +304,4 @@ public class SHRPictureFile extends HiResImage return text.toString (); } } - - class ColorTable - { - int id; - ColorEntry[] entries = new ColorEntry[16]; - - public ColorTable () - { - // default empty table - id = -1; - for (int i = 0; i < 16; i++) - { - entries[i] = new ColorEntry (); - } - } - - public ColorTable (int id, byte[] data, int offset) - { - this.id = id; - for (int i = 0; i < 16; i++) - { - entries[i] = new ColorEntry (data, offset); - offset += 2; - } - } - - String toLine () - { - - StringBuilder text = new StringBuilder (); - - text.append (String.format (" %X", id)); - for (int i = 0; i < 16; i++) - text.append (String.format (" %04X", entries[i].value)); - - return text.toString (); - } - - @Override - public String toString () - { - StringBuilder text = new StringBuilder (); - - text.append (String.format ("%2d ColorTable%n", id)); - for (int i = 0; i < 8; i++) - text.append (String.format (" %2d: %04X", i, entries[i].value)); - text.append ("\n"); - for (int i = 8; i < 16; i++) - text.append (String.format (" %2d: %04X", i, entries[i].value)); - - return text.toString (); - } - } - - class ColorEntry - { - int value; // 0RGB - Color color; - - public ColorEntry () - { - // default empty entry - value = 0; - color = new Color (0, 0, 0); - } - - public ColorEntry (byte[] data, int offset) - { - value = HexFormatter.unsignedShort (data, offset); - - int red = ((value >> 8) & 0x0f) * 17; - int green = ((value >> 4) & 0x0f) * 17; - int blue = (value & 0x0f) * 17; - color = new Color (red, green, blue); - } - - @Override - public String toString () - { - return String.format ("ColorEntry: %04X", value); - } - } - - class DirEntry - { - int numBytes; - int mode; - - public DirEntry (byte[] data, int offset) - { - numBytes = HexFormatter.unsignedShort (data, offset); - mode = HexFormatter.unsignedShort (data, offset + 2); - } - - @Override - public String toString () - { - return String.format ("Bytes: %5d, mode: %02X", numBytes, mode); - } - } } \ No newline at end of file diff --git a/src/com/bytezone/diskbrowser/applefile/SHRPictureFile2.java b/src/com/bytezone/diskbrowser/applefile/SHRPictureFile2.java index d67d24a..9338f7f 100644 --- a/src/com/bytezone/diskbrowser/applefile/SHRPictureFile2.java +++ b/src/com/bytezone/diskbrowser/applefile/SHRPictureFile2.java @@ -1,16 +1,63 @@ package com.bytezone.diskbrowser.applefile; +import java.awt.image.BufferedImage; +import java.awt.image.DataBuffer; + +import com.bytezone.diskbrowser.prodos.ProdosConstants; + public class SHRPictureFile2 extends HiResImage { + ColorTable[] colorTables; + byte[] scb; public SHRPictureFile2 (String name, byte[] buffer, int fileType, int auxType, int eof) { super (name, buffer, fileType, auxType, eof); - // type $C0.0001 - packed SHR - // type $C1.0001 - unpacked SHR - // type $C1.0002 - - // System.out.println (buffer.length); + if (fileType == ProdosConstants.FILE_TYPE_PIC) // 0xC1 + { + if (auxType == 0) + { + scb = new byte[200]; + System.arraycopy (buffer, 32000, scb, 0, scb.length); + + colorTables = new ColorTable[16]; + for (int i = 0; i < colorTables.length; i++) + colorTables[i] = new ColorTable (i, buffer, 32256 + i * 32); + } + else if (auxType == 1) + { + System.out.println ("0xC1 aux 1 not written"); + } + else if (auxType == 2) // Brooks + { + colorTables = new ColorTable[200]; + for (int i = 0; i < colorTables.length; i++) + { + colorTables[i] = new ColorTable (i, buffer, 32000 + i * 32); + colorTables[i].reverse (); + } + } + else + System.out.println ("unknown aux " + auxType); + } + else if (fileType == ProdosConstants.FILE_TYPE_PNT) // 0xC0 + { + if (auxType == 0) + { + System.out.println ("0xC0 aux 0 not written"); + } + else if (auxType == 1) + { + System.out.println ("0xC0 aux 1 not written"); + } + else + System.out.println ("unknown aux " + auxType); + } + else + System.out.println ("unknown filetype " + fileType); + + createImage (); } @Override @@ -21,6 +68,48 @@ public class SHRPictureFile2 extends HiResImage @Override protected void createColourImage () { + image = new BufferedImage (320, 200, BufferedImage.TYPE_INT_RGB); + DataBuffer dataBuffer = image.getRaster ().getDataBuffer (); + + int element = 0; + int ptr = 0; + for (int row = 0; row < 200; row++) + { + ColorTable colorTable = + scb != null ? colorTables[scb[row] & 0x0F] : colorTables[row]; + + for (int col = 0; col < 160; col++) + { + int left = (buffer[ptr] & 0xF0) >> 4; + int right = buffer[ptr] & 0x0F; + + dataBuffer.setElem (element++, colorTable.entries[left].color.getRGB ()); + dataBuffer.setElem (element++, colorTable.entries[right].color.getRGB ()); + + ptr++; + } + } } + @Override + public String getText () + { + StringBuilder text = new StringBuilder (super.getText ()); + text.append ("\n\n"); + + if (scb != null) + for (int i = 0; i < scb.length; i++) + text.append (String.format ("%3d %02X%n", i, scb[i])); + + for (ColorTable colorTable : colorTables) + { + text.append (colorTable); + text.append ("\n\n"); + } + + text.deleteCharAt (text.length () - 1); + text.deleteCharAt (text.length () - 1); + + return text.toString (); + } } \ No newline at end of file diff --git a/src/com/bytezone/diskbrowser/gui/NextPaletteAction.java b/src/com/bytezone/diskbrowser/gui/NextPaletteAction.java index 042ce5d..69f2175 100644 --- a/src/com/bytezone/diskbrowser/gui/NextPaletteAction.java +++ b/src/com/bytezone/diskbrowser/gui/NextPaletteAction.java @@ -17,8 +17,7 @@ public class NextPaletteAction extends AbstractAction { super ("Next Palette"); putValue (Action.SHORT_DESCRIPTION, "Select next color palette"); - putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt N")); - // putValue (Action.MNEMONIC_KEY, KeyEvent.VK_N); + putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("meta alt N")); this.owner = owner; this.buttonGroup = buttonGroup; } @@ -27,7 +26,6 @@ public class NextPaletteAction extends AbstractAction public void actionPerformed (ActionEvent e) { Palette palette = owner.cyclePalette (CycleDirection.FORWARDS); - // owner.selectPalette (palette); if (palette != null) { diff --git a/src/com/bytezone/diskbrowser/gui/PreviousPaletteAction.java b/src/com/bytezone/diskbrowser/gui/PreviousPaletteAction.java index c92d485..c970810 100644 --- a/src/com/bytezone/diskbrowser/gui/PreviousPaletteAction.java +++ b/src/com/bytezone/diskbrowser/gui/PreviousPaletteAction.java @@ -17,8 +17,7 @@ public class PreviousPaletteAction extends AbstractAction { super ("Previous Palette"); putValue (Action.SHORT_DESCRIPTION, "Select previous color palette"); - putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt P")); - // putValue (Action.MNEMONIC_KEY, KeyEvent.VK_P); + putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("meta alt P")); this.owner = owner; this.buttonGroup = buttonGroup; } @@ -27,7 +26,6 @@ public class PreviousPaletteAction extends AbstractAction public void actionPerformed (ActionEvent e) { Palette palette = owner.cyclePalette (CycleDirection.BACKWARDS); - // owner.selectPalette (palette); if (palette != null) { diff --git a/src/com/bytezone/diskbrowser/prodos/FileEntry.java b/src/com/bytezone/diskbrowser/prodos/FileEntry.java index e20721b..8c6d81c 100755 --- a/src/com/bytezone/diskbrowser/prodos/FileEntry.java +++ b/src/com/bytezone/diskbrowser/prodos/FileEntry.java @@ -352,7 +352,9 @@ class FileEntry extends CatalogEntry implements ProdosConstants file = new IconFile (name, exactBuffer); break; case FILE_TYPE_PNT: - if (auxType == 1) + if (auxType == 0) + file = new SHRPictureFile2 (name, exactBuffer, fileType, auxType, endOfFile); + else if (auxType == 1) file = new SHRPictureFile2 (name, exactBuffer, fileType, auxType, endOfFile); else if (auxType == 2) file = new SHRPictureFile (name, exactBuffer, fileType, auxType, endOfFile); @@ -361,13 +363,13 @@ class FileEntry extends CatalogEntry implements ProdosConstants new OriginalHiResImage (name, exactBuffer, fileType, auxType, endOfFile); break; case FILE_TYPE_PIC: - if (auxType == 1) - file = new SHRPictureFile2 (name, exactBuffer, fileType, auxType, endOfFile); - else if (auxType == 2) - file = new SHRPictureFile2 (name, exactBuffer, fileType, auxType, endOfFile); - else - file = - new OriginalHiResImage (name, exactBuffer, fileType, auxType, endOfFile); + // if (auxType == 1) + file = new SHRPictureFile2 (name, exactBuffer, fileType, auxType, endOfFile); + // else if (auxType == 2) + // file = new SHRPictureFile2 (name, exactBuffer, fileType, auxType, endOfFile); + // else + // file = + // new OriginalHiResImage (name, exactBuffer, fileType, auxType, endOfFile); break; case FILE_TYPE_FONT: file = new QuickDrawFont (name, exactBuffer, fileType, auxType);