blob: c4b034ec29e9eabcbeef9f7e749f210d8cabbcae [file] [log] [blame]
Jack Jansen6f1ee201996-10-04 15:22:37 +00001"""mac_image - Helper routines (hacks) for images"""
2import imgformat
3import Qd
4import time
5import struct
Jack Jansen4240b611997-04-03 14:44:07 +00006import MacOS
Jack Jansen6f1ee201996-10-04 15:22:37 +00007
8_fmt_to_mac = {
9 imgformat.macrgb16 : (16, 16, 3, 5),
10}
11
12def mkpixmap(w, h, fmt, data):
13 """kludge a pixmap together"""
14 fmtinfo = _fmt_to_mac[fmt]
15
16 rv = struct.pack("lhhhhhhhlllhhhhlll",
Jack Jansen4240b611997-04-03 14:44:07 +000017 id(data)+MacOS.string_id_to_buffer, # HACK HACK!!
Jack Jansen6f1ee201996-10-04 15:22:37 +000018 w*2 + 0x8000,
19 0, 0, h, w,
20 0,
21 0, 0, # XXXX?
22 72<<16, 72<<16,
23 fmtinfo[0], fmtinfo[1],
24 fmtinfo[2], fmtinfo[3],
25 0, 0, 0)
26## print 'Our pixmap, size %d:'%len(rv)
27## dumppixmap(rv)
28 return Qd.RawBitMap(rv)
29
30def dumppixmap(data):
31 baseAddr, \
32 rowBytes, \
33 t, l, b, r, \
34 pmVersion, \
35 packType, packSize, \
36 hRes, vRes, \
37 pixelType, pixelSize, \
38 cmpCount, cmpSize, \
39 planeBytes, pmTable, pmReserved \
40 = struct.unpack("lhhhhhhhlllhhhhlll", data)
41 print 'Base: 0x%x'%baseAddr
42 print 'rowBytes: %d (0x%x)'%(rowBytes&0x3fff, rowBytes)
43 print 'rect: %d, %d, %d, %d'%(t, l, b, r)
44 print 'pmVersion: 0x%x'%pmVersion
45 print 'packing: %d %d'%(packType, packSize)
46 print 'resolution: %f x %f'%(float(hRes)/0x10000, float(vRes)/0x10000)
47 print 'pixeltype: %d, size %d'%(pixelType, pixelSize)
48 print 'components: %d, size %d'%(cmpCount, cmpSize)
49 print 'planeBytes: %d (0x%x)'%(planeBytes, planeBytes)
50 print 'pmTable: 0x%x'%pmTable
51 print 'pmReserved: 0x%x'%pmReserved
52 for i in range(0, len(data), 16):
53 for j in range(16):
54 if i + j < len(data):
55 print '%02.2x'%ord(data[i+j]),
56 print