1 package org.ibex.graphics;
7 public static void main(String[] s) throws Exception {
8 FileOutputStream fos = new FileOutputStream("out.pcx");
9 int[] data = new int[104 * 104];
10 for(int i=0; i<104; i++) data[i*104+i] = 1;
11 for(int i=0; i<104; i++) data[i*104+(104-i)] = 1;
12 //for(int i=0; i<104*104; i++) data[i] = i%2==0?1:0;
13 dump(104, 104, data, new DataOutputStream(fos));
16 public static void writeLittleShort(DataOutputStream out, int i) throws IOException {
18 out.writeByte(s & 0xff);
19 out.writeByte((s & 0xff00) << 8);
22 public static void dump(int width, int height, int[] data, DataOutputStream out) throws IOException {
23 out.writeByte(0x0A); // PCX ID
24 out.writeByte(0); // Version
25 out.writeByte(1); // Encoding = RLE
26 out.writeByte(1); // 1bpp
27 writeLittleShort(out, 0); // XStart
28 writeLittleShort(out, 0); // YStart
29 //writeLittleShort(out, 203); // HDPI
30 //writeLittleShort(out, 203); // VDPI
31 writeLittleShort(out, width-1); // XEnd
32 writeLittleShort(out, height-1); // YEnd
33 writeLittleShort(out, width-1); // XEnd
34 writeLittleShort(out, height-1); // YEnd
35 for(int i=0; i<48; i++)
36 out.writeByte(0); // Pallette
37 out.writeByte(0); // Reserved
38 out.writeByte(1); // NumBitPlanes
39 writeLittleShort(out, (int)Math.ceil(((float)width)/8)); // bytes per line
40 writeLittleShort(out, 1); // PalleteType=Mono
41 writeLittleShort(out, 0); // HorizScreenSize (FIXME: maybe omit?)
42 writeLittleShort(out, 0); // VertScreenSize (FIXME: maybe omit?)
43 for(int i=0; i<54; i++)
44 out.writeByte(0); // Reserved
48 for(int y=0; y<height; y++) {
49 for(int x=0; x<width; x+=8) {
50 int i = y * width + x;
52 for(int j=i; j<Math.min(data.length, i+8); j++)
53 b |= (data[j]==0?0:1) << (7-(j-i));
54 if (dat==b && count < 63) count++;
57 out.writeByte(count | 0xc0);
65 out.writeByte(count | 0xc0);