1996-10-04 12:22:37 -03:00
|
|
|
"""mac_image - Helper routines (hacks) for images"""
|
|
|
|
import imgformat
|
2001-08-25 09:15:04 -03:00
|
|
|
from Carbon import Qd
|
1996-10-04 12:22:37 -03:00
|
|
|
import time
|
|
|
|
import struct
|
1997-04-03 10:44:07 -04:00
|
|
|
import MacOS
|
1996-10-04 12:22:37 -03:00
|
|
|
|
|
|
|
_fmt_to_mac = {
|
2004-07-18 03:16:08 -03:00
|
|
|
imgformat.macrgb16 : (16, 16, 3, 5),
|
1996-10-04 12:22:37 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
def mkpixmap(w, h, fmt, data):
|
2004-07-18 03:16:08 -03:00
|
|
|
"""kludge a pixmap together"""
|
|
|
|
fmtinfo = _fmt_to_mac[fmt]
|
|
|
|
|
|
|
|
rv = struct.pack("lHhhhhhhlllhhhhlll",
|
|
|
|
id(data)+MacOS.string_id_to_buffer, # HACK HACK!!
|
|
|
|
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)
|
1996-10-04 12:22:37 -03:00
|
|
|
|
|
|
|
def dumppixmap(data):
|
2004-07-18 03:16:08 -03:00
|
|
|
baseAddr, \
|
|
|
|
rowBytes, \
|
|
|
|
t, l, b, r, \
|
|
|
|
pmVersion, \
|
|
|
|
packType, packSize, \
|
|
|
|
hRes, vRes, \
|
|
|
|
pixelType, pixelSize, \
|
|
|
|
cmpCount, cmpSize, \
|
|
|
|
planeBytes, pmTable, pmReserved \
|
|
|
|
= struct.unpack("lhhhhhhhlllhhhhlll", data)
|
2007-08-30 15:39:28 -03:00
|
|
|
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)
|
2004-07-18 03:16:08 -03:00
|
|
|
for i in range(0, len(data), 16):
|
|
|
|
for j in range(16):
|
|
|
|
if i + j < len(data):
|
2007-08-30 15:39:28 -03:00
|
|
|
print('%02.2x'%ord(data[i+j]), end=' ')
|
|
|
|
print()
|