dmolony-DiskBrowser/src/com/bytezone/diskbrowser/applefile/SHRPictureFile2.java

245 lines
7.3 KiB
Java
Raw Normal View History

2017-01-25 11:02:50 +00:00
package com.bytezone.diskbrowser.applefile;
2017-01-26 04:19:23 +00:00
import java.awt.image.BufferedImage;
import java.awt.image.DataBuffer;
import com.bytezone.diskbrowser.prodos.ProdosConstants;
2017-02-01 21:15:30 +00:00
import com.bytezone.diskbrowser.utilities.HexFormatter;
2017-01-26 04:19:23 +00:00
2017-01-25 11:02:50 +00:00
public class SHRPictureFile2 extends HiResImage
{
2017-01-26 04:19:23 +00:00
ColorTable[] colorTables;
2018-07-30 08:44:29 +00:00
byte[] controlBytes;
2017-01-25 11:02:50 +00:00
2018-07-25 05:48:14 +00:00
// see Graphics & Animation.2mg
2017-01-25 11:02:50 +00:00
public SHRPictureFile2 (String name, byte[] buffer, int fileType, int auxType, int eof)
{
super (name, buffer, fileType, auxType, eof);
2018-07-25 05:48:14 +00:00
switch (fileType)
2017-01-26 04:19:23 +00:00
{
2018-07-31 07:02:19 +00:00
case ProdosConstants.FILE_TYPE_PNT: // packed images
doPnt (buffer);
break;
case ProdosConstants.FILE_TYPE_PIC: // unpacked images
doPic ();
break;
default:
System.out.println ("unknown filetype " + fileType);
}
if (colorTables != null)
createImage ();
}
private void doPnt (byte[] buffer)
{
switch (auxType)
{
2018-08-01 07:23:12 +00:00
case 0: // packed Paintworks SHR
controlBytes = new byte[200]; // all pointing to 0th color table
colorTables = new ColorTable[1];
colorTables[0] = new ColorTable (0, this.buffer, 0);
2018-07-31 07:02:19 +00:00
byte[] data = new byte[buffer.length - 0x222];
System.arraycopy (buffer, 0x0222, data, 0, data.length);
this.buffer = unpackBytes (data);
2018-08-01 07:23:12 +00:00
2018-07-31 07:02:19 +00:00
break;
case 1: // packed version of PIC/$00
this.buffer = unpackBytes (buffer);
controlBytes = new byte[200];
System.arraycopy (this.buffer, 32000, controlBytes, 0, controlBytes.length);
colorTables = new ColorTable[16];
for (int i = 0; i < colorTables.length; i++)
colorTables[i] = new ColorTable (i, this.buffer, 32256 + i * 32);
break;
case 2: // handled in SHRPictureFile1
break;
case 3: // packed version of PIC/$01
2018-08-01 07:23:12 +00:00
System.out.printf ("%s: PNT aux 3 (QuickDraw PICT) not written yet%n", name);
failureReason = "not written yet";
2018-07-31 07:02:19 +00:00
// Apple IIGS Tech Note #46
// https://www.prepressure.com/library/file-formats/pict
this.buffer = unpackBytes (buffer);
int mode = HexFormatter.unsignedShort (this.buffer, 0);
int rect1 = HexFormatter.unsignedLong (this.buffer, 2);
int rect2 = HexFormatter.unsignedLong (this.buffer, 6);
int version = HexFormatter.unsignedShort (this.buffer, 10); // $8211
2018-08-01 07:23:12 +00:00
2018-07-31 07:02:19 +00:00
break;
case 4: // packed version of PIC/$02
System.out.printf ("%s: PNT aux 4 (Packed SHR Brooks Image) not tested yet%n",
name);
2018-08-01 07:23:12 +00:00
case 99: // testing .3201 binary files
// 00000 - 00003 'APP' 0x00
// 00004 - 06403 200 color tables of 32 bytes each (one color table per scan line)
// 06404 - eof packed pixel data --> 32,000 bytes
2018-07-31 07:02:19 +00:00
colorTables = new ColorTable[200];
for (int i = 0; i < colorTables.length; i++)
2018-07-25 05:48:14 +00:00
{
2018-08-01 07:23:12 +00:00
colorTables[i] = new ColorTable (i, this.buffer, 4 + i * 32);
2018-07-31 07:02:19 +00:00
colorTables[i].reverse ();
2018-07-25 05:48:14 +00:00
}
2018-08-01 07:23:12 +00:00
data = new byte[buffer.length - 6404]; // skip APP. and color tables
System.arraycopy (buffer, 6404, data, 0, data.length);
this.buffer = unpackBytes (data);
2018-07-25 05:48:14 +00:00
break;
2017-01-27 07:11:00 +00:00
2018-07-31 07:02:19 +00:00
default:
System.out.printf ("%s: PNT unknown aux: %04X%n", name, auxType);
2018-08-01 07:23:12 +00:00
failureReason = "unknown PNT aux";
2018-07-31 07:02:19 +00:00
}
}
private void doPic ()
{
switch (auxType)
{
case 0: // unpacked version of PNT/$01
2018-08-01 07:23:12 +00:00
case 0x4100: // no idea what this is
2018-07-31 07:02:19 +00:00
// 00000 - 31999 pixel data 32,000 bytes
// 32000 - 32199 200 control bytes (one per scan line)
// 32200 - 32255 empty
// 32256 - 32767 16 color tables of 32 bytes each
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;
case 1: // unpacked version of PNT/$03
2018-08-01 07:23:12 +00:00
System.out.printf ("%s: PIC aux 1 (QuickDraw PICT) not written yet%n", name);
failureReason = "not written yet";
2018-07-31 07:02:19 +00:00
break;
case 2: // unpacked version of PNT/$04, .3200
// 00000 - 31999 pixel data 32,000 bytes
// 32000 - 38399 200 color tables of 32 bytes each (one color table per scan line)
if (buffer.length < 38400)
2018-07-25 05:48:14 +00:00
{
2018-07-31 07:02:19 +00:00
failureReason = "Buffer should be 38,400 bytes";
return;
2018-07-25 05:48:14 +00:00
}
2018-07-31 07:02:19 +00:00
colorTables = new ColorTable[200];
for (int i = 0; i < colorTables.length; i++)
2017-01-26 04:19:23 +00:00
{
2018-07-31 07:02:19 +00:00
int ptr = 32000 + i * 32;
colorTables[i] = new ColorTable (i, buffer, ptr);
colorTables[i].reverse ();
2017-01-26 04:19:23 +00:00
}
2018-07-25 05:48:14 +00:00
break;
2018-07-31 07:02:19 +00:00
2018-07-25 05:48:14 +00:00
default:
2018-07-31 07:02:19 +00:00
System.out.println ("PIC unknown aux " + auxType);
2018-08-01 07:23:12 +00:00
failureReason = "unknown PIC aux";
2017-01-26 04:19:23 +00:00
}
2017-01-25 11:02:50 +00:00
}
@Override
2018-07-30 08:44:29 +00:00
void createMonochromeImage ()
2017-01-25 11:02:50 +00:00
{
}
@Override
2018-07-30 08:44:29 +00:00
void createColourImage ()
2017-01-25 11:02:50 +00:00
{
2017-01-26 04:19:23 +00:00
image = new BufferedImage (320, 200, BufferedImage.TYPE_INT_RGB);
DataBuffer dataBuffer = image.getRaster ().getDataBuffer ();
int element = 0;
int ptr = 0;
2018-08-01 07:23:12 +00:00
ColorTable colorTable = null;
2017-01-26 04:19:23 +00:00
for (int row = 0; row < 200; row++)
{
2018-08-01 07:23:12 +00:00
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!!!");
}
else
colorTable = colorTables[row];
2017-01-26 04:19:23 +00:00
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++;
}
}
2017-01-25 11:02:50 +00:00
}
2017-01-26 04:19:23 +00:00
@Override
public String getText ()
{
StringBuilder text = new StringBuilder (super.getText ());
2018-08-01 07:23:12 +00:00
text.append ("\n");
2017-01-26 04:19:23 +00:00
2018-07-30 08:44:29 +00:00
if (controlBytes != null)
2017-01-26 11:30:16 +00:00
{
text.append ("SCB\n---\n");
2018-07-30 08:44:29 +00:00
for (int i = 0; i < controlBytes.length; i += 8)
2017-01-26 11:30:16 +00:00
{
for (int j = 0; j < 8; j++)
2018-07-30 08:44:29 +00:00
text.append (String.format (" %3d: %02X ", i + j, controlBytes[i + j]));
2017-01-26 11:30:16 +00:00
text.append ("\n");
}
text.append ("\n");
}
2017-01-26 04:19:23 +00:00
2017-01-27 07:11:00 +00:00
if (colorTables != null)
2017-02-01 21:15:30 +00:00
{
text.append ("Color Table\n\n #");
for (int i = 0; i < 16; i++)
text.append (String.format (" %02X ", i));
text.append ("\n--");
for (int i = 0; i < 16; i++)
text.append (" ----");
text.append ("\n");
2017-01-27 07:11:00 +00:00
for (ColorTable colorTable : colorTables)
{
2017-02-01 21:15:30 +00:00
text.append (colorTable.toLine ());
text.append ("\n");
2017-01-27 07:11:00 +00:00
}
2017-02-01 21:15:30 +00:00
}
text.append ("\nScreen lines\n\n");
for (int i = 0; i < 200; i++)
{
2018-07-28 12:00:02 +00:00
text.append (String.format ("Line: %02X %<3d%n", i));
2017-02-01 21:15:30 +00:00
text.append (HexFormatter.format (buffer, i * 160, 160));
text.append ("\n\n");
}
2017-01-26 04:19:23 +00:00
text.deleteCharAt (text.length () - 1);
text.deleteCharAt (text.length () - 1);
return text.toString ();
}
2017-01-25 11:02:50 +00:00
}