From 91d8136ad3425fdab5f399a158bdb57da7732c7f Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Tue, 27 Dec 2016 15:17:47 -0500 Subject: [PATCH] added bitmap tools --- tools/Makefile | 13 +++++++ tools/README | 17 +++++++++ tools/galois.c | 23 ++++++++++++ tools/images/ada-40.pbm | Bin 0 -> 970 bytes tools/images/ali-40.pbm | Bin 0 -> 970 bytes tools/images/ein-48.pbm | Bin 0 -> 357 bytes tools/images/scrappy-48.pbm | Bin 0 -> 432 bytes tools/images/thisisfine-48.pbm | Bin 0 -> 426 bytes tools/p4_to_48pix.py | 58 ++++++++++++++++++++++++++++++ tools/p4_to_pfbytes.py | 62 +++++++++++++++++++++++++++++++++ 10 files changed, 173 insertions(+) create mode 100644 tools/Makefile create mode 100644 tools/README create mode 100644 tools/galois.c create mode 100644 tools/images/ada-40.pbm create mode 100644 tools/images/ali-40.pbm create mode 100644 tools/images/ein-48.pbm create mode 100644 tools/images/scrappy-48.pbm create mode 100644 tools/images/thisisfine-48.pbm create mode 100644 tools/p4_to_48pix.py create mode 100644 tools/p4_to_pfbytes.py diff --git a/tools/Makefile b/tools/Makefile new file mode 100644 index 00000000..7b1ae43a --- /dev/null +++ b/tools/Makefile @@ -0,0 +1,13 @@ + +%-pf.hex: %-pf.pbm p4_to_pfbytes.py + python p4_to_pfbytes.py $< > $@ + +%-48.hex: %-48.pbm p4_to_48pix.py + python p4_to_48pix.py $< > $@ + +%-pf.pbm: %.jpg + convert $< -resize 40x192\! -colorspace Gray -dither FloydSteinberg $@ + +%-48.pbm: %.jpg + convert $< -resize 48x192\! -colorspace Gray -dither FloydSteinberg $@ + diff --git a/tools/README b/tools/README new file mode 100644 index 00000000..299fb117 --- /dev/null +++ b/tools/README @@ -0,0 +1,17 @@ + +This directory contains tools for bitmap conversion. + +Requires ImageMagick (convert) and Python 2.x. + +make .pf.hex + + Converts a .jpg into a 40-pixel wide playfield bitmap. + Cut-and-paste output into program. + (See Chapter 20, Asynchronous Bitmaps) + +make .48.hex + + Converts a .jpg into a 48-pixel wide sprite bitmap. + Cut-and-paste output into program. + (See Chapter 22, A Big 48-Pixel Sprite) + diff --git a/tools/galois.c b/tools/galois.c new file mode 100644 index 00000000..7d2dc288 --- /dev/null +++ b/tools/galois.c @@ -0,0 +1,23 @@ + +/* test of 16-bit Galois LFSR */ + +#include "stdio.h" + +int main() +{ + int n = 100; + unsigned short x = 1; + for (int i=0; i>= 1; + if (c) x ^= 0xd400; // 0b1101010000000000 + printf("%4x\n", x); + } + for (int i=0; iDCV}f6wytrC}on=)|lEPMDv`-@joLqi;wR==iGC-1GzTbIehNS;Dw=1 z;$J3wlgMGadk`VA)3DD62ABq(*C3RZq!$l}g7Phq|F8}-CUO*6YHU(udu-WR+bJ)P ztTq--2UaG^BTuyQnBJY-ap=S7#w0yZ?ILZdDSa)QoLkp&D@I(+jn0*n$|D+2wEMz# zqODO_wEHq7Vw$|=iF<2~GNi~G$^~D>Q64AcxOlJBE%ENEoD{pEj3u%m)TXtXC8{C0 zC}uOvX#D872^8*e#%CW?_i_rdwmP$Pz)zw1nS=`SE!fb)ZodeMD7``EIrj z*nTfi?Dv!1PD6x`i$GE)lKgFXK~1mtj?m7~Fl`5@c*Yg{5mihHsN`pqRr0 zH=3|E- z4uY3yJbKcjm(e<9j3U^Bcn}8NP}xb^+X}w@e*RwSdJqHoqK8eE!0f zi)rXyMSi5(a2w1vo7rL53LK5ZBCruG5Xi9$0v7~v^hg(fE$W%WMU=D}U9)=DTT6FK!^tr6+AP6<4Bt*toM3}Hk&fE*K1;VS#O9a` zNcJVB+v6HX#~CN(A^PXo`u7<^0^0#wP9KEOAJq4Y&6v@4i_N*jW(=@d6AUm9k?t87 zy|z!=b%tT|O^_%|-_dYALX(p}?e{iVy#*ItD=<8Q)aSkaf(Z_K`e~<~cSuQFye# zvAKaFre&N;tU~ij#BVoMsX~$RD$PYD8naPH>^0wa#8%^Jr?ek){Js>m1;wim#c%P1 z?OpWHrq=4TpjMQ(Y5$och-Y9Et-6d?{GU+NHIA;kM6w8j#IrI9%Wj6K2qT0RWH>r` zNt2M4csGATVikrYJ{abRFe)*0hh!Cb;HcaYz2>nE*xJt4NaaOXRp7I^c9rmyKQ0wy z8Rcw12&Hv4FPOu8_G(RCo61Q%BMJc){X$K-UNyk!xFGSg9|qw~ukaYles~#+v3!B| XeEBFWdU6I|zd7)+?8*D#aB1!jEaF~2 literal 0 HcmV?d00001 diff --git a/tools/images/ein-48.pbm b/tools/images/ein-48.pbm new file mode 100644 index 0000000000000000000000000000000000000000..b9afa7a071fb239b3d014cd91988df7bcee02aea GIT binary patch literal 357 zcmWlTKS)AR7{#w$_0em1G&SYB;7~zng{1^SVIsLGQZ$NCh!y>z6e{8w4h;>hZAy~` zqEm~NHaWIL(WKy1LrH^{&v#F^hEd>KC81@HPYIb^Tob4rJTZw~1=4GB4*)F?0%;k{*+@fm~PBvG#;1_VTQGV5N zPd|n45mbO2aSMJRY8~7liUwR0MI`4$iUR#a0{C9~pWle(3otIJV3cSb$HraEDQfmu zga$%Z!8svCq(DrA;>O&U)-+g2L+NlU%_|k8E!moQY%)D*z&+$wc52^ZM457-1qw0lCevF4o_!F>73Cq|-EBC4{7BaZ=+U2H(K@-R bp{2G3e_S-xBm7ELwS(?_&Q?IrT=MFFW5Ufu literal 0 HcmV?d00001 diff --git a/tools/images/scrappy-48.pbm b/tools/images/scrappy-48.pbm new file mode 100644 index 0000000000000000000000000000000000000000..894f9f69c776d111068aafbb5e4561c56715eff2 GIT binary patch literal 432 zcmYMwPfG$p7zXfXXU9fG+D$rm5S{*u@%uVX4$!5y4C76XDAMxFkD(*QZ2})sq)jks8h|#bvIn5i zSL$7p*&r5l8#8L#0R`BIh~BQp=`7Xai8;kVR0(BmF?+)x?7ZA{tP; zqN*~jA~Zti1S|={KnOH|l7=#T{H`=JkFdcrpK!Iocn;T$v^Av0w51_hXy*c-RE`&B zTLkfv;ShL*w!g5#$QH3RiwYx=pG6g2)WRsI z3pe}%8T6sYZjgqy5Yq=0uflgyFocg46kQJ*cU%rdcr_BpQUkJ|e=1No)Fld-=>65; zpi-${Cs0y#g}myijQ%12NrAoj>R2YSZYZ5@klC7X%b`t;F{cN0E;XN|cSF#)jHTBS Iyd*ln50{~8fB*mh literal 0 HcmV?d00001 diff --git a/tools/p4_to_48pix.py b/tools/p4_to_48pix.py new file mode 100644 index 00000000..e3ad5f82 --- /dev/null +++ b/tools/p4_to_48pix.py @@ -0,0 +1,58 @@ +#!/usr/bin/python + +import sys, struct + +# playfield bytes, one array for each of 6 columns +output = [[],[],[],[],[],[]] + +# reverse byte +def rev(n): + return int('{:08b}'.format(n)[::-1], 2) + +# output bits in given range +def out(i, pix, lb, hb, reverse=0, shift=0): + x = (pix >> lb) & ((1<<(hb-lb))-1) + if reverse: + x = rev(x) + if shift: + x = x << shift + assert(x>=0 and x<=255) + output[i].append(x) + +# read PBM (binary P4 format) file +with open(sys.argv[1],'rb') as f: + # read PBM header + header = f.readline().strip() + assert(header == 'P4') + dims = f.readline().strip() + if dims[0] == '#': + dims = f.readline().strip() + width,height = map(int, dims.split()) + assert(width==48) + # read bitmap rows + for y in range(0,height): + row = bytes(f.read(6) + '\0\0') # pad to 8 bytes + # convert to 64-bit integer + pix = struct.unpack('5: + print s diff --git a/tools/p4_to_pfbytes.py b/tools/p4_to_pfbytes.py new file mode 100644 index 00000000..21ad2241 --- /dev/null +++ b/tools/p4_to_pfbytes.py @@ -0,0 +1,62 @@ +#!/usr/bin/python + +import sys, struct + +# playfield bytes, one array for each of 6 columns +output = [[],[],[],[],[],[]] + +# reverse byte +def rev(n): + return int('{:08b}'.format(n)[::-1], 2) + +# output bits in given range +def out(i, pix, lb, hb, reverse=0, shift=0): + x = (pix >> lb) & ((1<<(hb-lb))-1) + if reverse: + x = rev(x) + if shift: + x = x << shift + assert(x>=0 and x<=255) + output[i].append(x) + +# read PBM (binary P4 format) file +with open(sys.argv[1],'rb') as f: + # read PBM header + header = f.readline().strip() + assert(header == 'P4') + dims = f.readline().strip() + if dims[0] == '#': + dims = f.readline().strip() + width,height = map(int, dims.split()) + assert(width==40) + # read bitmap rows + for y in range(0,height): + row = bytes(f.read(5) + '\0\0\0') # pad to 8 bytes + # convert bytes from MSB first to LSB first + row2 = '' + for i in range(0,8): + row2 += chr(rev(ord(row[i]))) + # convert to 64-bit integer + pix = struct.unpack('5: + print s