From 3fc0193d90b6ac22c21b3e0c3c129ed9c3e089bc Mon Sep 17 00:00:00 2001 From: adam Date: Mon, 1 Jan 2007 03:12:59 +0000 Subject: [PATCH] added PCX code (incomplete) darcs-hash:20070101031259-5007d-4ed539cda5d7183c9d0bfe36a4cbc02c01b801be.gz --- src/org/ibex/graphics/PCX.java | 75 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/org/ibex/graphics/PCX.java diff --git a/src/org/ibex/graphics/PCX.java b/src/org/ibex/graphics/PCX.java new file mode 100644 index 0000000..e737cae --- /dev/null +++ b/src/org/ibex/graphics/PCX.java @@ -0,0 +1,75 @@ +package org.ibex.graphics; +import java.io.*; +import java.util.*; + +public class PCX { + + public static void main(String[] s) throws Exception { + FileOutputStream fos = new FileOutputStream("out.pcx"); + int[] data = new int[104 * 104]; + for(int i=0; i<104; i++) data[i*104+i] = 1; + for(int i=0; i<104; i++) data[i*104+(104-i)] = 1; + //for(int i=0; i<104*104; i++) data[i] = i%2==0?1:0; + dump(104, 104, data, new DataOutputStream(fos)); + } + + public static void writeLittleShort(DataOutputStream out, int i) throws IOException { + short s = (short)i; + out.writeByte(s & 0xff); + out.writeByte((s & 0xff00) << 8); + } + + public static void dump(int width, int height, int[] data, DataOutputStream out) throws IOException { + out.writeByte(0x0A); // PCX ID + out.writeByte(0); // Version + out.writeByte(1); // Encoding = RLE + out.writeByte(1); // 1bpp + writeLittleShort(out, 0); // XStart + writeLittleShort(out, 0); // YStart + //writeLittleShort(out, 203); // HDPI + //writeLittleShort(out, 203); // VDPI + writeLittleShort(out, width-1); // XEnd + writeLittleShort(out, height-1); // YEnd + writeLittleShort(out, width-1); // XEnd + writeLittleShort(out, height-1); // YEnd + for(int i=0; i<48; i++) + out.writeByte(0); // Pallette + out.writeByte(0); // Reserved + out.writeByte(1); // NumBitPlanes + writeLittleShort(out, (int)Math.ceil(((float)width)/8)); // bytes per line + writeLittleShort(out, 1); // PalleteType=Mono + writeLittleShort(out, 0); // HorizScreenSize (FIXME: maybe omit?) + writeLittleShort(out, 0); // VertScreenSize (FIXME: maybe omit?) + for(int i=0; i<54; i++) + out.writeByte(0); // Reserved + + byte dat = 0; + int count = 0; + for(int y=0; y 0) { + out.writeByte(count | 0xc0); + out.writeByte(dat); + } + dat = b; + count = 1; + } + } + if (count > 0) { + out.writeByte(count | 0xc0); + out.writeByte(dat); + count = 0; + dat = 0; + } + } + out.flush(); + out.close(); + } + +} -- 1.7.10.4