| 1 | """PixMapWrapper - defines the PixMapWrapper class, which wraps an opaque
|
|---|
| 2 | QuickDraw PixMap data structure in a handy Python class. Also provides
|
|---|
| 3 | methods to convert to/from pixel data (from, e.g., the img module) or a
|
|---|
| 4 | Python Imaging Library Image object.
|
|---|
| 5 |
|
|---|
| 6 | J. Strout <[email protected]> February 1999"""
|
|---|
| 7 |
|
|---|
| 8 | from Carbon import Qd
|
|---|
| 9 | from Carbon import QuickDraw
|
|---|
| 10 | import struct
|
|---|
| 11 | import MacOS
|
|---|
| 12 | import img
|
|---|
| 13 | import imgformat
|
|---|
| 14 |
|
|---|
| 15 | # PixMap data structure element format (as used with struct)
|
|---|
| 16 | _pmElemFormat = {
|
|---|
| 17 | 'baseAddr':'l', # address of pixel data
|
|---|
| 18 | 'rowBytes':'H', # bytes per row, plus 0x8000
|
|---|
| 19 | 'bounds':'hhhh', # coordinates imposed over pixel data
|
|---|
| 20 | 'top':'h',
|
|---|
| 21 | 'left':'h',
|
|---|
| 22 | 'bottom':'h',
|
|---|
| 23 | 'right':'h',
|
|---|
| 24 | 'pmVersion':'h', # flags for Color QuickDraw
|
|---|
| 25 | 'packType':'h', # format of compression algorithm
|
|---|
| 26 | 'packSize':'l', # size after compression
|
|---|
| 27 | 'hRes':'l', # horizontal pixels per inch
|
|---|
| 28 | 'vRes':'l', # vertical pixels per inch
|
|---|
| 29 | 'pixelType':'h', # pixel format
|
|---|
| 30 | 'pixelSize':'h', # bits per pixel
|
|---|
| 31 | 'cmpCount':'h', # color components per pixel
|
|---|
| 32 | 'cmpSize':'h', # bits per component
|
|---|
| 33 | 'planeBytes':'l', # offset in bytes to next plane
|
|---|
| 34 | 'pmTable':'l', # handle to color table
|
|---|
| 35 | 'pmReserved':'l' # reserved for future use
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | # PixMap data structure element offset
|
|---|
| 39 | _pmElemOffset = {
|
|---|
| 40 | 'baseAddr':0,
|
|---|
| 41 | 'rowBytes':4,
|
|---|
| 42 | 'bounds':6,
|
|---|
| 43 | 'top':6,
|
|---|
| 44 | 'left':8,
|
|---|
| 45 | 'bottom':10,
|
|---|
| 46 | 'right':12,
|
|---|
| 47 | 'pmVersion':14,
|
|---|
|
|---|