From 57070d94a046a89ba753ba1c88c6bc3a94079372 Mon Sep 17 00:00:00 2001 From: Denis Molony Date: Thu, 2 Aug 2018 15:13:09 +1000 Subject: [PATCH] more graphics formats supported --- .../diskbrowser/applefile/HiResImage.java | 11 ++- .../applefile/SHRPictureFile1.java | 56 ++++++----- .../applefile/SHRPictureFile2.java | 94 +++++++++++++++---- .../bytezone/diskbrowser/disk/AppleDisk.java | 2 +- 4 files changed, 117 insertions(+), 46 deletions(-) diff --git a/src/com/bytezone/diskbrowser/applefile/HiResImage.java b/src/com/bytezone/diskbrowser/applefile/HiResImage.java index f3b8a50..aa5dfd4 100644 --- a/src/com/bytezone/diskbrowser/applefile/HiResImage.java +++ b/src/com/bytezone/diskbrowser/applefile/HiResImage.java @@ -31,15 +31,16 @@ public abstract class HiResImage extends AbstractFile // $08 PICT $4001 Packed Double Hi-Res file - ??? // * $C0 PNT $0000 Paintworks Packed Super Hi-Res - SHRPictureFile2 - // * $C0 PNT $0001 Packed IIGS Super Hi-Res Image (xx) - SHRPictureFile2 + // * $C0 PNT $0001 Packed IIGS Super Hi-Res Image - SHRPictureFile2 // * $C0 PNT $0002 IIGS Super Hi-Res Picture File (APF) - SHRPictureFile // $C0 PNT $0003 Packed IIGS QuickDraw II PICT File - SHRPictureFile2 * // * $C0 PNT $0004 Packed Super Hi-Res 3200 (Brooks) .3201 - SHRPictureFile2 + // $C0 PNT $1000 // $C0 PNT $8001 GTv background picture // $C0 PNT $8005 DreamGraphix document // $C0 PNT $8006 GIF - // * $C1 PIC $0000 IIGS Super Hi-Res Image (xx) - SHRPictureFile2 + // * $C1 PIC $0000 IIGS Super Hi-Res Image - SHRPictureFile2 // $C1 PIC $0001 IIGS QuickDraw II PICT File - SHRPictureFile2 * // * $C1 PIC $0002 Super Hi-Res 3200 (Brooks) .3200 - SHRPictureFile2 // $C1 PIC $8001 Allison raw image @@ -61,7 +62,7 @@ public abstract class HiResImage extends AbstractFile int auxType; int eof; - byte[] unpackedBuffer; + // byte[] unpackedBuffer; int paletteIndex; String failureReason = ""; @@ -230,8 +231,8 @@ public abstract class HiResImage extends AbstractFile text.append (String.format ("File size : %,d%n", buffer.length)); text.append (String.format ("EOF : %,d%n", eof)); - if (unpackedBuffer != null) - text.append (String.format ("Unpacked : %,d%n", unpackedBuffer.length)); + // if (unpackedBuffer != null) + // text.append (String.format ("Unpacked : %,d%n", unpackedBuffer.length)); if (!failureReason.isEmpty ()) text.append (String.format ("Failure : %s%n", failureReason)); diff --git a/src/com/bytezone/diskbrowser/applefile/SHRPictureFile1.java b/src/com/bytezone/diskbrowser/applefile/SHRPictureFile1.java index 1540f63..023cca4 100644 --- a/src/com/bytezone/diskbrowser/applefile/SHRPictureFile1.java +++ b/src/com/bytezone/diskbrowser/applefile/SHRPictureFile1.java @@ -78,8 +78,8 @@ public class SHRPictureFile1 extends HiResImage 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; + int pix1 = (buffer[ptr] & 0xF0) >> 4; + int pix2 = buffer[ptr] & 0x0F; if (pix1 > 0) db.setElem (element, 255); if (pix2 > 0) @@ -92,16 +92,17 @@ public class SHRPictureFile1 extends HiResImage @Override void createColourImage () { - image = new BufferedImage (mainBlock.pixelsPerScanLine, mainBlock.numScanLines, - BufferedImage.TYPE_INT_RGB); + image = + new BufferedImage (640, mainBlock.numScanLines * 2, BufferedImage.TYPE_INT_RGB); DataBuffer dataBuffer = image.getRaster ().getDataBuffer (); if (mainBlock.pixelsPerScanLine != 320) System.out.printf ("%s: Pixels per scanline: %d%n", name, mainBlock.pixelsPerScanLine); - int element = 0; // index into dataBuffer - int ptr = 0; // index into unpackedBuffer + int element1 = 0; // first line + int element2 = 640; // second line + int ptr = 0; // index into buffer for (int line = 0; line < mainBlock.numScanLines; line++) { @@ -122,14 +123,27 @@ public class SHRPictureFile1 extends HiResImage // 320 mode for (int i = 0; i < 160; i++) { - int left = (unpackedBuffer[ptr] & 0xF0) >> 4; - int right = unpackedBuffer[ptr] & 0x0F; + 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 ()); + // get left/right colors + int rgbLeft = colorTable.entries[left].color.getRGB (); + int rgbRight = colorTable.entries[right].color.getRGB (); - ptr++; + // draw left/right pixels on current line + dataBuffer.setElem (element1++, rgbLeft); + dataBuffer.setElem (element1++, rgbLeft); + dataBuffer.setElem (element1++, rgbRight); + dataBuffer.setElem (element1++, rgbRight); + + // draw same left/right pixels on next line + dataBuffer.setElem (element2++, rgbLeft); + dataBuffer.setElem (element2++, rgbLeft); + dataBuffer.setElem (element2++, rgbRight); + dataBuffer.setElem (element2++, rgbRight); } + element1 += 640; // skip line already drawn + element2 += 640; // one line ahead } } @@ -253,21 +267,19 @@ public class SHRPictureFile1 extends HiResImage ptr += len; } - if (true) + byte[] unpackedBuffer = new byte[numScanLines * 160]; + ptr = 0; + for (int line = 0; line < numScanLines; line++) { - unpackedBuffer = new byte[numScanLines * 160]; - ptr = 0; - for (int line = 0; line < numScanLines; line++) + byte[] lineBuffer = packedScanLines[line]; + if (lineBuffer.length % 2 == 1 && isEmpty (lineBuffer)) { - byte[] lineBuffer = packedScanLines[line]; - if (lineBuffer.length % 2 == 1 && isEmpty (lineBuffer)) - { - System.out.println ("Odd number of bytes in empty buffer in " + name); - break; - } - ptr = unpackLine (lineBuffer, unpackedBuffer, ptr); + System.out.println ("Odd number of bytes in empty buffer in " + name); + break; } + ptr = unpackLine (lineBuffer, unpackedBuffer, ptr); } + SHRPictureFile1.this.buffer = unpackedBuffer; } private boolean isEmpty (byte[] buffer) diff --git a/src/com/bytezone/diskbrowser/applefile/SHRPictureFile2.java b/src/com/bytezone/diskbrowser/applefile/SHRPictureFile2.java index 6678db7..f08e0ed 100644 --- a/src/com/bytezone/diskbrowser/applefile/SHRPictureFile2.java +++ b/src/com/bytezone/diskbrowser/applefile/SHRPictureFile2.java @@ -160,37 +160,95 @@ public class SHRPictureFile2 extends HiResImage @Override void createColourImage () { - image = new BufferedImage (320, 200, BufferedImage.TYPE_INT_RGB); + image = new BufferedImage (640, 400, BufferedImage.TYPE_INT_RGB); DataBuffer dataBuffer = image.getRaster ().getDataBuffer (); - int element = 0; + int element1 = 0; // first line + int element2 = 640; // second line int ptr = 0; - ColorTable colorTable = null; - for (int row = 0; row < 200; row++) + boolean mode320 = true; + boolean fillMode = false; + ColorTable colorTable = null; + boolean flag = false; + + for (int line = 0; line < 200; line++) { if (controlBytes != null) { - int controlByte = controlBytes[row]; - int mode = controlByte & 0x80; - int index = controlByte & 0x0F; - int fillMode = controlByte & 0x20; - colorTable = colorTables[index]; - if (mode != 0) - System.out.println ("640!!!"); + int controlByte = controlBytes[line] & 0xFF; + colorTable = colorTables[controlByte & 0x0F]; + + mode320 = (controlByte & 0x80) == 0; + fillMode = (controlByte & 0x20) != 0; + + // System.out.printf ("Line: %3d, cb: %02X, Mode: %-5s, Fill: %-5s%n", line, + // controlByte, mode320, fillMode); } else - colorTable = colorTables[row]; + colorTable = colorTables[line]; - for (int col = 0; col < 160; col++) + if (mode320) // mode320 { - int left = (buffer[ptr] & 0xF0) >> 4; - int right = buffer[ptr] & 0x0F; + System.out.println (buffer.length); + for (int col = 0; col < 160; col++) // two pixels per 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 ()); + // get left/right colors + int rgbLeft = colorTable.entries[left].color.getRGB (); + int rgbRight = colorTable.entries[right].color.getRGB (); - ptr++; + // draw left/right pixels on current line + dataBuffer.setElem (element1++, rgbLeft); + dataBuffer.setElem (element1++, rgbLeft); + dataBuffer.setElem (element1++, rgbRight); + dataBuffer.setElem (element1++, rgbRight); + + // draw same left/right pixels on next line + dataBuffer.setElem (element2++, rgbLeft); + dataBuffer.setElem (element2++, rgbLeft); + dataBuffer.setElem (element2++, rgbRight); + dataBuffer.setElem (element2++, rgbRight); + } + element1 += 640; // skip line already drawn + element2 += 640; // one line ahead + } + else // mode640 + { + if (!flag) + { + flag = true; + System.out.printf ("640 mode: %s%n", name); + } + for (int col = 0; col < 160; col++) // four pixels per col + { + int p1 = (buffer[ptr] & 0xC0) >> 6; + int p2 = (buffer[ptr] & 0x30) >> 4; + int p3 = (buffer[ptr] & 0x0C) >> 2; + int p4 = (buffer[ptr++] & 0x03); + + // get pixel colors + int rgb1 = colorTable.entries[p1 + 8].color.getRGB (); + int rgb2 = colorTable.entries[p2 + 12].color.getRGB (); + int rgb3 = colorTable.entries[p3].color.getRGB (); + int rgb4 = colorTable.entries[p4 + 4].color.getRGB (); + + // draw pixels on current line + dataBuffer.setElem (element1++, rgb1); + dataBuffer.setElem (element1++, rgb2); + dataBuffer.setElem (element1++, rgb3); + dataBuffer.setElem (element1++, rgb4); + + // draw same pixels on next line + dataBuffer.setElem (element2++, rgb1); + dataBuffer.setElem (element2++, rgb2); + dataBuffer.setElem (element2++, rgb3); + dataBuffer.setElem (element2++, rgb4); + } + element1 += 640; // skip line already drawn + element2 += 640; // one line ahead } } } diff --git a/src/com/bytezone/diskbrowser/disk/AppleDisk.java b/src/com/bytezone/diskbrowser/disk/AppleDisk.java index ca07ea5..1642a9c 100755 --- a/src/com/bytezone/diskbrowser/disk/AppleDisk.java +++ b/src/com/bytezone/diskbrowser/disk/AppleDisk.java @@ -384,7 +384,7 @@ public class AppleDisk implements Disk int bufferOffset = 0; for (DiskAddress da : daList) { - if (da != null) // sparse text files may have gaps + if (da != null && da.getBlock () > 0) // sparse text files may have gaps readBuffer (da, buffer, bufferOffset); bufferOffset += sectorSize; }