diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 1996-10-04 15:22:37 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 1996-10-04 15:22:37 (GMT) |
commit | 6f1ee20501ff95077ee98f38235a284c148cbb90 (patch) | |
tree | f16bf874def5de48607b0f223a90cd629a0ea974 /Mac/Demo/imgbrowse/mac_image.py | |
parent | 30fe363fd8957d833aa913a2af375d275c581c15 (diff) | |
download | cpython-6f1ee20501ff95077ee98f38235a284c148cbb90.zip cpython-6f1ee20501ff95077ee98f38235a284c148cbb90.tar.gz cpython-6f1ee20501ff95077ee98f38235a284c148cbb90.tar.bz2 |
Use mac_image (from cmif stuff)
Fixed off-by-four error
Keep data around so it won't get reclaimed
Diffstat (limited to 'Mac/Demo/imgbrowse/mac_image.py')
-rw-r--r-- | Mac/Demo/imgbrowse/mac_image.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/Mac/Demo/imgbrowse/mac_image.py b/Mac/Demo/imgbrowse/mac_image.py new file mode 100644 index 0000000..e2639c9 --- /dev/null +++ b/Mac/Demo/imgbrowse/mac_image.py @@ -0,0 +1,55 @@ +"""mac_image - Helper routines (hacks) for images""" +import imgformat +import Qd +import time +import struct + +_fmt_to_mac = { + imgformat.macrgb16 : (16, 16, 3, 5), +} + +def mkpixmap(w, h, fmt, data): + """kludge a pixmap together""" + fmtinfo = _fmt_to_mac[fmt] + + rv = struct.pack("lhhhhhhhlllhhhhlll", + id(data)+16, + w*2 + 0x8000, + 0, 0, h, w, + 0, + 0, 0, # XXXX? + 72<<16, 72<<16, + fmtinfo[0], fmtinfo[1], + fmtinfo[2], fmtinfo[3], + 0, 0, 0) +## print 'Our pixmap, size %d:'%len(rv) +## dumppixmap(rv) + return Qd.RawBitMap(rv) + +def dumppixmap(data): + baseAddr, \ + rowBytes, \ + t, l, b, r, \ + pmVersion, \ + packType, packSize, \ + hRes, vRes, \ + pixelType, pixelSize, \ + cmpCount, cmpSize, \ + planeBytes, pmTable, pmReserved \ + = struct.unpack("lhhhhhhhlllhhhhlll", data) + print 'Base: 0x%x'%baseAddr + print 'rowBytes: %d (0x%x)'%(rowBytes&0x3fff, rowBytes) + print 'rect: %d, %d, %d, %d'%(t, l, b, r) + print 'pmVersion: 0x%x'%pmVersion + print 'packing: %d %d'%(packType, packSize) + print 'resolution: %f x %f'%(float(hRes)/0x10000, float(vRes)/0x10000) + print 'pixeltype: %d, size %d'%(pixelType, pixelSize) + print 'components: %d, size %d'%(cmpCount, cmpSize) + print 'planeBytes: %d (0x%x)'%(planeBytes, planeBytes) + print 'pmTable: 0x%x'%pmTable + print 'pmReserved: 0x%x'%pmReserved + for i in range(0, len(data), 16): + for j in range(16): + if i + j < len(data): + print '%02.2x'%ord(data[i+j]), + print |