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