1 """imgbrowse - Display pictures using img"""
18 # Where is the picture window?
33 pixelType
, pixelSize
, \
35 planeBytes
, pmTable
, pmReserved \
36 = struct
.unpack("lhhhhhhhlllhhhhlll", data
)
37 print 'Base: 0x%x'%baseAddr
38 print 'rowBytes: %d (0x%x)'%(rowBytes
&0x3fff, rowBytes
)
39 print 'rect: %d, %d, %d, %d'%(t
, l
, b
, r
)
40 print 'pmVersion: 0x%x'%pmVersion
41 print 'packing: %d %d'%(packType
, packSize
)
42 print 'resolution: %f x %f'%(float(hRes
)/0x10000, float(vRes
)/0x10000)
43 print 'pixeltype: %d, size %d'%(pixelType
, pixelSize
)
44 print 'components: %d, size %d'%(cmpCount
, cmpSize
)
45 print 'planeBytes: %d (0x%x)'%(planeBytes
, planeBytes
)
46 print 'pmTable: 0x%x'%pmTable
47 print 'pmReserved: 0x%x'%pmReserved
49 def mk16pixmap(w
, h
, data
):
50 """kludge a pixmap together"""
51 rv
= struct
.pack("lhhhhhhhlllhhhhlll",
61 print 'Our pixmap, size %d:'%len(rv
)
63 return Qd
.RawBitMap(rv
)
69 class imgbrowse(FrameWork
.Application
):
71 # First init menus, etc.
72 FrameWork
.Application
.__init
__(self
)
74 # Finally, go into the event loop
77 def makeusermenus(self
):
78 self
.filemenu
= m
= FrameWork
.Menu(self
.menubar
, "File")
79 self
.openitem
= FrameWork
.MenuItem(m
, "Open...", "O", self
.opendoc
)
80 self
.infoitem
= FrameWork
.MenuItem(m
, "Info", "I", self
.info
)
81 self
.quititem
= FrameWork
.MenuItem(m
, "Quit", "Q", self
.quit
)
83 def quit(self
, *args
):
86 def opendoc(self
, *args
):
87 fss
, ok
= macfs
.StandardGetFile() # Any file type
90 bar
= EasyDialogs
.ProgressBar('Reading and converting...')
91 pathname
= fss
.as_pathname()
93 rdr
= img
.reader(imgformat
.macrgb16
, pathname
)
94 except img
.error
, arg
:
95 EasyDialogs
.Message(`arg`
)
97 w
, h
= rdr
.width
, rdr
.height
101 pixmap
= mk16pixmap(w
, h
, data
)
102 self
.showimg(w
, h
, pixmap
)
104 def showimg(self
, w
, h
, pixmap
):
105 win
= imgwindow(self
)
106 win
.open(w
, h
, pixmap
)
109 def info(self
, *args
):
113 class imgwindow(FrameWork
.Window
):
114 def open(self
, width
, height
, pixmap
):
116 self
.pictrect
= (0, 0, width
, height
)
117 bounds
= (LEFT
, TOP
, LEFT
+width
, TOP
+height
)
119 self
.wid
= Win
.NewCWindow(bounds
, "Picture", 1, 0, -1, 1, 0)
122 def do_update(self
, *args
):
124 currect
= self
.fitrect()
125 print 'PICT:', self
.pictrect
126 print 'WIND:', currect
127 print 'ARGS:', (self
.pixmap
, self
.wid
.GetWindowPort().portBits
, self
.pictrect
,
128 currect
, QuickDraw
.srcCopy
, None)
130 Qd
.CopyBits(self
.pixmap
, self
.wid
.GetWindowPort().portBits
, self
.pictrect
,
131 currect
, QuickDraw
.srcCopy
, None)
132 ## Qd.DrawPicture(self.picture, currect)
135 """Return self.pictrect scaled to fit in window"""
136 graf
= self
.wid
.GetWindowPort()
137 screenrect
= graf
.portRect
138 picwidth
= self
.pictrect
[2] - self
.pictrect
[0]
139 picheight
= self
.pictrect
[3] - self
.pictrect
[1]
140 if picwidth
> screenrect
[2] - screenrect
[0]:
141 factor
= float(picwidth
) / float(screenrect
[2]-screenrect
[0])
142 picwidth
= picwidth
/ factor
143 picheight
= picheight
/ factor
144 if picheight
> screenrect
[3] - screenrect
[1]:
145 factor
= float(picheight
) / float(screenrect
[3]-screenrect
[1])
146 picwidth
= picwidth
/ factor
147 picheight
= picheight
/ factor
148 return (screenrect
[0], screenrect
[1], screenrect
[0]+int(picwidth
),
149 screenrect
[1]+int(picheight
))
152 graf
= self
.wid
.GetWindowPort()
154 dumppixmap(bits
.pixmap_data
)