more graphics formats supported

This commit is contained in:
Denis Molony 2018-08-02 15:13:09 +10:00
parent 21db7541bd
commit 57070d94a0
4 changed files with 117 additions and 46 deletions

View File

@ -31,15 +31,16 @@ public abstract class HiResImage extends AbstractFile
// $08 PICT $4001 Packed Double Hi-Res file - ??? // $08 PICT $4001 Packed Double Hi-Res file - ???
// * $C0 PNT $0000 Paintworks Packed Super Hi-Res - SHRPictureFile2 // * $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 $0002 IIGS Super Hi-Res Picture File (APF) - SHRPictureFile
// $C0 PNT $0003 Packed IIGS QuickDraw II PICT File - SHRPictureFile2 * // $C0 PNT $0003 Packed IIGS QuickDraw II PICT File - SHRPictureFile2 *
// * $C0 PNT $0004 Packed Super Hi-Res 3200 (Brooks) .3201 - SHRPictureFile2 // * $C0 PNT $0004 Packed Super Hi-Res 3200 (Brooks) .3201 - SHRPictureFile2
// $C0 PNT $1000
// $C0 PNT $8001 GTv background picture // $C0 PNT $8001 GTv background picture
// $C0 PNT $8005 DreamGraphix document // $C0 PNT $8005 DreamGraphix document
// $C0 PNT $8006 GIF // $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 $0001 IIGS QuickDraw II PICT File - SHRPictureFile2 *
// * $C1 PIC $0002 Super Hi-Res 3200 (Brooks) .3200 - SHRPictureFile2 // * $C1 PIC $0002 Super Hi-Res 3200 (Brooks) .3200 - SHRPictureFile2
// $C1 PIC $8001 Allison raw image // $C1 PIC $8001 Allison raw image
@ -61,7 +62,7 @@ public abstract class HiResImage extends AbstractFile
int auxType; int auxType;
int eof; int eof;
byte[] unpackedBuffer; // byte[] unpackedBuffer;
int paletteIndex; int paletteIndex;
String failureReason = ""; 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 ("File size : %,d%n", buffer.length));
text.append (String.format ("EOF : %,d%n", eof)); text.append (String.format ("EOF : %,d%n", eof));
if (unpackedBuffer != null) // if (unpackedBuffer != null)
text.append (String.format ("Unpacked : %,d%n", unpackedBuffer.length)); // text.append (String.format ("Unpacked : %,d%n", unpackedBuffer.length));
if (!failureReason.isEmpty ()) if (!failureReason.isEmpty ())
text.append (String.format ("Failure : %s%n", failureReason)); text.append (String.format ("Failure : %s%n", failureReason));

View File

@ -78,8 +78,8 @@ public class SHRPictureFile1 extends HiResImage
for (int row = 0; row < 200; row++) for (int row = 0; row < 200; row++)
for (int col = 0; col < 160; col++) for (int col = 0; col < 160; col++)
{ {
int pix1 = (unpackedBuffer[ptr] & 0xF0) >> 4; int pix1 = (buffer[ptr] & 0xF0) >> 4;
int pix2 = unpackedBuffer[ptr] & 0x0F; int pix2 = buffer[ptr] & 0x0F;
if (pix1 > 0) if (pix1 > 0)
db.setElem (element, 255); db.setElem (element, 255);
if (pix2 > 0) if (pix2 > 0)
@ -92,16 +92,17 @@ public class SHRPictureFile1 extends HiResImage
@Override @Override
void createColourImage () void createColourImage ()
{ {
image = new BufferedImage (mainBlock.pixelsPerScanLine, mainBlock.numScanLines, image =
BufferedImage.TYPE_INT_RGB); new BufferedImage (640, mainBlock.numScanLines * 2, BufferedImage.TYPE_INT_RGB);
DataBuffer dataBuffer = image.getRaster ().getDataBuffer (); DataBuffer dataBuffer = image.getRaster ().getDataBuffer ();
if (mainBlock.pixelsPerScanLine != 320) if (mainBlock.pixelsPerScanLine != 320)
System.out.printf ("%s: Pixels per scanline: %d%n", name, System.out.printf ("%s: Pixels per scanline: %d%n", name,
mainBlock.pixelsPerScanLine); mainBlock.pixelsPerScanLine);
int element = 0; // index into dataBuffer int element1 = 0; // first line
int ptr = 0; // index into unpackedBuffer int element2 = 640; // second line
int ptr = 0; // index into buffer
for (int line = 0; line < mainBlock.numScanLines; line++) for (int line = 0; line < mainBlock.numScanLines; line++)
{ {
@ -122,14 +123,27 @@ public class SHRPictureFile1 extends HiResImage
// 320 mode // 320 mode
for (int i = 0; i < 160; i++) for (int i = 0; i < 160; i++)
{ {
int left = (unpackedBuffer[ptr] & 0xF0) >> 4; int left = (buffer[ptr] & 0xF0) >> 4;
int right = unpackedBuffer[ptr] & 0x0F; int right = buffer[ptr++] & 0x0F;
dataBuffer.setElem (element++, colorTable.entries[left].color.getRGB ()); // get left/right colors
dataBuffer.setElem (element++, colorTable.entries[right].color.getRGB ()); 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; ptr += len;
} }
if (true) byte[] unpackedBuffer = new byte[numScanLines * 160];
ptr = 0;
for (int line = 0; line < numScanLines; line++)
{ {
unpackedBuffer = new byte[numScanLines * 160]; byte[] lineBuffer = packedScanLines[line];
ptr = 0; if (lineBuffer.length % 2 == 1 && isEmpty (lineBuffer))
for (int line = 0; line < numScanLines; line++)
{ {
byte[] lineBuffer = packedScanLines[line]; System.out.println ("Odd number of bytes in empty buffer in " + name);
if (lineBuffer.length % 2 == 1 && isEmpty (lineBuffer)) break;
{
System.out.println ("Odd number of bytes in empty buffer in " + name);
break;
}
ptr = unpackLine (lineBuffer, unpackedBuffer, ptr);
} }
ptr = unpackLine (lineBuffer, unpackedBuffer, ptr);
} }
SHRPictureFile1.this.buffer = unpackedBuffer;
} }
private boolean isEmpty (byte[] buffer) private boolean isEmpty (byte[] buffer)

View File

@ -160,37 +160,95 @@ public class SHRPictureFile2 extends HiResImage
@Override @Override
void createColourImage () 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 (); DataBuffer dataBuffer = image.getRaster ().getDataBuffer ();
int element = 0; int element1 = 0; // first line
int element2 = 640; // second line
int ptr = 0; 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) if (controlBytes != null)
{ {
int controlByte = controlBytes[row]; int controlByte = controlBytes[line] & 0xFF;
int mode = controlByte & 0x80; colorTable = colorTables[controlByte & 0x0F];
int index = controlByte & 0x0F;
int fillMode = controlByte & 0x20; mode320 = (controlByte & 0x80) == 0;
colorTable = colorTables[index]; fillMode = (controlByte & 0x20) != 0;
if (mode != 0)
System.out.println ("640!!!"); // System.out.printf ("Line: %3d, cb: %02X, Mode: %-5s, Fill: %-5s%n", line,
// controlByte, mode320, fillMode);
} }
else else
colorTable = colorTables[row]; colorTable = colorTables[line];
for (int col = 0; col < 160; col++) if (mode320) // mode320
{ {
int left = (buffer[ptr] & 0xF0) >> 4; System.out.println (buffer.length);
int right = buffer[ptr] & 0x0F; 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 ()); // get left/right colors
dataBuffer.setElem (element++, colorTable.entries[right].color.getRGB ()); 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
} }
} }
} }

View File

@ -384,7 +384,7 @@ public class AppleDisk implements Disk
int bufferOffset = 0; int bufferOffset = 0;
for (DiskAddress da : daList) 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); readBuffer (da, buffer, bufferOffset);
bufferOffset += sectorSize; bufferOffset += sectorSize;
} }