graphics tweaking

This commit is contained in:
Denis Molony 2018-08-03 08:13:49 +10:00
parent 57070d94a0
commit cabc613e9a
4 changed files with 104 additions and 51 deletions

View File

@ -36,6 +36,7 @@ public abstract class HiResImage extends AbstractFile
// $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 $8000 Drawplus ?
// $C0 PNT $8001 GTv background picture
// $C0 PNT $8005 DreamGraphix document
// $C0 PNT $8006 GIF
@ -62,7 +63,6 @@ public abstract class HiResImage extends AbstractFile
int auxType;
int eof;
// byte[] unpackedBuffer;
int paletteIndex;
String failureReason = "";
@ -231,8 +231,6 @@ 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 (!failureReason.isEmpty ())
text.append (String.format ("Failure : %s%n", failureReason));
@ -266,9 +264,10 @@ public abstract class HiResImage extends AbstractFile
}
catch (ArrayIndexOutOfBoundsException e)
{
// try again with a bigger buffer
}
System.out.println ("unpackBytes()");
System.out.println ("unpackBytes() failed");
failureReason = "buffer too small";
return new byte[0];
}
@ -322,13 +321,14 @@ public abstract class HiResImage extends AbstractFile
{
byte[] fourBuf = new byte[4];
int oldPtr = newPtr;
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)
if (ptr >= buffer.length) // needed for NAGELxx
break;
switch (type)
@ -365,6 +365,7 @@ public abstract class HiResImage extends AbstractFile
break;
}
}
// System.out.println (HexFormatter.format (newBuf, oldPtr, newPtr - oldPtr));
return newPtr;
}
@ -459,6 +460,12 @@ public abstract class HiResImage extends AbstractFile
return text.equals ("BM") && size <= buffer.length;
}
public static boolean isAPP (byte[] buffer)
{
return buffer[0] == (byte) 0xC1 && buffer[1] == (byte) 0xD0
&& buffer[2] == (byte) 0xD0 && buffer[3] == 0;
}
public static PaletteFactory getPaletteFactory ()
{
return paletteFactory;

View File

@ -12,6 +12,7 @@ public class SHRPictureFile1 extends HiResImage
private final List<Block> blocks = new ArrayList<Block> ();
private Main mainBlock;
private Multipal multipalBlock;
private final boolean debug = false;
// 0xC0/02 - Apple IIGS Super Hi-Res Picture File (APF)
public SHRPictureFile1 (String name, byte[] buffer, int fileType, int auxType, int eof)
@ -45,7 +46,8 @@ public class SHRPictureFile1 extends HiResImage
case "MASK":
case "PATS":
case "SCIB":
System.out.println (kind + " not written");
if (debug)
System.out.println (kind + " not written");
blocks.add (new Block (kind, data));
break;
@ -92,16 +94,13 @@ public class SHRPictureFile1 extends HiResImage
@Override
void createColourImage ()
{
int width = mainBlock.pixelsPerScanLine == 320 ? 640 : mainBlock.pixelsPerScanLine;
image =
new BufferedImage (640, mainBlock.numScanLines * 2, BufferedImage.TYPE_INT_RGB);
new BufferedImage (width, 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 element1 = 0; // first line
int element2 = 640; // second line
int element2 = width; // second line
int ptr = 0; // index into buffer
for (int line = 0; line < mainBlock.numScanLines; line++)
@ -121,29 +120,63 @@ public class SHRPictureFile1 extends HiResImage
// System.out.println ("fillmode " + fillMode);
// 320 mode
for (int i = 0; i < 160; i++)
if (mainBlock.pixelsPerScanLine == 320)
{
int left = (buffer[ptr] & 0xF0) >> 4;
int right = buffer[ptr++] & 0x0F;
for (int i = 0; i < 160; i++) // two pixels per col
{
int left = (buffer[ptr] & 0xF0) >> 4;
int right = buffer[ptr++] & 0x0F;
// get left/right colors
int rgbLeft = colorTable.entries[left].color.getRGB ();
int rgbRight = colorTable.entries[right].color.getRGB ();
// get left/right colors
int rgbLeft = colorTable.entries[left].color.getRGB ();
int rgbRight = colorTable.entries[right].color.getRGB ();
// draw left/right pixels on current line
dataBuffer.setElem (element1++, rgbLeft);
dataBuffer.setElem (element1++, rgbLeft);
dataBuffer.setElem (element1++, rgbRight);
dataBuffer.setElem (element1++, rgbRight);
// 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);
// 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 += width; // skip line already drawn
element2 += width; // one line ahead
}
else
{
int max = mainBlock.pixelsPerScanLine / 4;
for (int col = 0; col < max; 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 += width; // skip line already drawn
element2 += width; // one line ahead
}
element1 += 640; // skip line already drawn
element2 += 640; // one line ahead
}
}
@ -234,7 +267,8 @@ public class SHRPictureFile1 extends HiResImage
pixelsPerScanLine = HexFormatter.unsignedShort (data, ptr + 2);
numColorTables = HexFormatter.unsignedShort (data, ptr + 4);
System.out.printf ("mm %d, pix %d%n", masterMode, pixelsPerScanLine);
// System.out.printf ("mm %02X, pix %d%n", masterMode, pixelsPerScanLine);
// System.out.printf ("color tables: %d%n", numColorTables);
ptr += 6;
colorTables = new ColorTable[numColorTables];
@ -245,10 +279,11 @@ public class SHRPictureFile1 extends HiResImage
}
numScanLines = HexFormatter.unsignedShort (data, ptr);
ptr += 2;
scanLineDirectory = new DirEntry[numScanLines];
packedScanLines = new byte[numScanLines][];
ptr += 2;
for (int i = 0; i < numScanLines; i++)
{
DirEntry dirEntry = new DirEntry (data, ptr);
@ -267,23 +302,33 @@ public class SHRPictureFile1 extends HiResImage
ptr += len;
}
byte[] unpackedBuffer = new byte[numScanLines * 160];
int width = pixelsPerScanLine == 320 ? 160 : pixelsPerScanLine / 4;
byte[] unpackedBuffer = new byte[numScanLines * width];
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 (isOddAndEmpty (packedScanLines[line]))
{
System.out.println ("Odd number of bytes in empty buffer in " + name);
break;
}
ptr = unpackLine (lineBuffer, unpackedBuffer, ptr);
// System.out.printf ("Line: %3d%n", line);
// System.out.println (scanLineDirectory[line]);
ptr = unpackLine (packedScanLines[line], unpackedBuffer, ptr);
// something strange happening here
if (line == 102 && name.equals ("DRAGON.SHR"))
ptr -= 132;
}
SHRPictureFile1.this.buffer = unpackedBuffer;
}
private boolean isEmpty (byte[] buffer)
private boolean isOddAndEmpty (byte[] buffer)
{
if (buffer.length % 2 == 0)
return false;
for (byte b : buffer)
if (b != 0)
return false;

View File

@ -80,6 +80,7 @@ public class SHRPictureFile2 extends HiResImage
case 4: // packed version of PIC/$02
System.out.printf ("%s: PNT aux 4 (Packed SHR Brooks Image) not tested yet%n",
name);
// haven't seen one to test yet, for now drop through to .3201
case 99: // testing .3201 binary files
// 00000 - 00003 'APP' 0x00
@ -98,6 +99,15 @@ public class SHRPictureFile2 extends HiResImage
this.buffer = unpackBytes (data);
break;
case 4096: // seems to be a PIC/$00
controlBytes = new byte[200];
System.arraycopy (buffer, 32000, controlBytes, 0, controlBytes.length);
colorTables = new ColorTable[16];
for (int i = 0; i < colorTables.length; i++)
colorTables[i] = new ColorTable (i, buffer, 32256 + i * 32);
break;
default:
System.out.printf ("%s: PNT unknown aux: %04X%n", name, auxType);
failureReason = "unknown PNT aux";
@ -170,7 +180,7 @@ public class SHRPictureFile2 extends HiResImage
boolean mode320 = true;
boolean fillMode = false;
ColorTable colorTable = null;
boolean flag = false;
// boolean flag = false;
for (int line = 0; line < 200; line++)
{
@ -181,16 +191,12 @@ public class SHRPictureFile2 extends HiResImage
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[line];
if (mode320) // mode320
{
System.out.println (buffer.length);
for (int col = 0; col < 160; col++) // two pixels per col
{
int left = (buffer[ptr] & 0xF0) >> 4;
@ -217,11 +223,6 @@ public class SHRPictureFile2 extends HiResImage
}
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;

View File

@ -195,10 +195,10 @@ class FileEntry extends CatalogEntry implements ProdosConstants
private boolean isValid (int blockNo)
{
if (true)
if (false)
{
if (!disk.isValidAddress (blockNo))
System.out.println ("--Invalid Address: " + blockNo);
System.out.println ("--Invalid Block Address: " + blockNo);
if (parentDisk.isSectorFree (blockNo))
System.out.println ("--Free block: " + blockNo);
}
@ -242,8 +242,8 @@ class FileEntry extends CatalogEntry implements ProdosConstants
file = new OriginalHiResImage (name, exactBuffer, auxType);
else if (name.endsWith (".3200")) // $C1/02
file = new SHRPictureFile2 (name, exactBuffer, 0xC1, 0x02, endOfFile);
else if (name.endsWith (".3201")) // $C0/04
// file = new DefaultAppleFile (name, exactBuffer);
else if (name.endsWith (".3201") || HiResImage.isAPP (exactBuffer)) // $C0/04
// I made up aux=99 to test it without stepping on aux==04
file = new SHRPictureFile2 (name, exactBuffer, 0xC0, 99, endOfFile);
else if (name.endsWith (".FNT") && FontFile.isFont (exactBuffer))
file = new FontFile (name, exactBuffer);