ยปCore Development>Code coverage>Mac/Demo/imgbrowse/mac_image.py

Python code coverage for Mac/Demo/imgbrowse/mac_image.py

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