2 from Carbon
import QuickTime
5 from Carbon
.QuickDraw
import srcCopy
6 from ExtPixMapWrapper
import ExtPixMapWrapper
7 from Carbon
.Qdoffs
import *
17 type=QuickTime
.VideoMediaType
19 flags
=QuickTime
.nextTimeMediaSample
20 flags
=flags
+QuickTime
.nextTimeEdgeOK
23 (theTime
,duration
)=m
.GetMovieNextInterestingTime(flags
,1,type,theTime
,0)
24 #print "theTime ",theTime," duration ",duration
25 frameCount
=frameCount
+1
26 flags
= QuickTime
.nextTimeMediaSample
31 def GetMovieFromOpenFile():
32 fss
, ok
= macfs
.StandardGetFile(QuickTime
.MovieFileType
)
35 movieResRef
= Qt
.OpenMovieFile(fss
, 1)
36 mov
, d1
, d2
= Qt
.NewMovieFromFile(movieResRef
, 0, QuickTime
.newMovieActive
)
42 def __init__(self
,mov
):
48 r
=self
.movie
.GetMovieBox()
49 self
.myRect
=(0,0,r
[2]-r
[0],r
[3]-r
[1])
50 self
.movie
.SetMovieBox(self
.myRect
)
51 self
.pm
=ExtPixMapWrapper()
54 self
.pm
.right
=r
[2]-r
[0]
55 self
.pm
.bottom
=r
[3]-r
[1]
56 self
.gw
=NewGWorld(32,self
.myRect
,None,None,0)
57 self
.movie
.SetMovieGWorld(self
.gw
.as_GrafPtr(), self
.gw
.GetGWorldDevice())
60 def _countFrames(self
):
61 #deve contare il numero di frame, creare un array con i tempi per ogni frame
63 #type=QuickTime.VIDEO_TYPE
64 type=QuickTime
.VideoMediaType
65 flags
=QuickTime
.nextTimeMediaSample
+QuickTime
.nextTimeEdgeOK
68 (theTime
,duration
)=self
.movie
.GetMovieNextInterestingTime(flags
,1,type,theTime
,0)
69 self
.frameArray
.append((theTime
,duration
))
70 flags
= QuickTime
.nextTimeMediaSample
71 self
.frames
=self
.frames
+1
75 def GotoFrame(self
,n
):
78 (port
,device
)=GetGWorld()
79 SetGWorld(self
.gw
.as_GrafPtr(),None)
80 (self
.now
,self
.duration
)=self
.frameArray
[n
]
81 self
.movie
.SetMovieTimeValue(self
.now
)
82 pixmap
=self
.gw
.GetGWorldPixMap()
84 if not LockPixels(pixmap
):
88 #Qd.EraseRect(self.myRect)
89 #this draws the frame inside the current gworld
90 self
.movie
.MoviesTask(0)
91 #this puts it in the buffer pixmap
92 self
.pm
.grab(0,0,self
.myRect
[2],self
.myRect
[3])
94 #self.im=self.pm.toImage()
95 SetGWorld(port
,device
)
98 self
.curFrame
=self
.curFrame
+1
99 if self
.curFrame
>self
.frames
:
101 self
.GotoFrame(self
.curFrame
)
104 return self
.curFrame
==self
.frames
108 return self
.pm
.toImage()
110 def GetImageN(self
,n
):
112 return self
.pm
.toImage()
114 def GetNumeric(self
):
115 return self
.pm
.toNumeric()
117 def GetNumericN(self
,n
):
119 return self
.pm
.toNumeric()
121 def Blit(self
,destRect
):
122 Qd
.RGBForeColor( (0,0,0) )
123 Qd
.RGBBackColor((65535, 65535, 65535))
127 Qd
.CopyBits(self
.gw
.portBits
,Qd
.GetPort().portBits
,self
.myRect
,destRect
,srcCopy
,None)
129 class MovieWin(W
.Window
):
131 def __init__(self
,eMovie
,title
="MovieWin"):
138 from Numeric
import *
140 m
=GetMovieFromOpenFile()
142 print "Total frames:",em
.frames
," Current frame:",em
.curFrame
143 #ImageMac.showImage(em.GetImage(),"frame 0",1)
145 #ImageMac.showImage(em.GetImage().filter(ImageFilter.SMOOTH),"frame 500",2)
146 #ImageMac.showImage(em.GetImageN(1000),"frame 1000",2)
147 #r=array(((1,0,0,0),(0,0,0,0),(0,0,0,0),(0,0,0,0)))
148 #g=array(((0,0,0,0),(0,1,0,0),(0,0,0,0),(0,0,0,0)))
149 #b=array(((0,0,0,0),(0,0,0,0),(0,0,1,0),(0,0,0,0)))
150 #bw=array(((0.3086,0.6094,0.0820,0)))
151 #r2=array(((1,0,0,0)))
152 #ImageMac.showNumeric(em.GetNumericN(0),"frame 0",1)
153 #print em.GetNumericN(500).shape
154 #print "original (1,1)",em.GetNumericN(0)[100,100]
155 #print "product shape ",innerproduct(em.GetNumericN(0),r).shape
156 #print "product (1,1) ",innerproduct(em.GetNumericN(0),r)[100,100]
158 #ImageMac.showNumeric(ImageMac.BWImage(em.GetNumericN(50)))
159 #ImageMac.showNumeric(innerproduct(em.GetNumericN(500),r),"frame 500r",2)
160 #ImageMac.showNumeric(innerproduct(em.GetNumericN(500),g),"frame 500g",2)
161 #ImageMac.showNumeric(innerproduct(em.GetNumericN(500),b),"frame 500b",2)
163 #ImageMac.showNumeric(innerproduct(em.GetNumericN(500),r2),"frame 500r2",2)
164 #ImageMac.showNumeric(innerproduct(em.GetNumericN(10),bw),"frame 0bw",1)
165 #ImageMac.showNumeric(innerproduct(em.GetNumericN(400),bw),"frame 10bw",1)
166 #colordif=(em.GetNumericN(100)-em.GetNumericN(10))+(255,255,255,255)
168 #ImageMac.showNumeric(colordif,"colordif",1)
169 #ImageMac.showNumeric(ImageMac.BWImage(colordif),"bwcolordif",1)
203 ImageMac
.showImage(em
.GetImageN(100),"provaImg",2)
204 ImageMac
.showNumeric(em
.GetNumericN(100),"provaNum",2)
205 ImageMac
.showImage(em
.GetImageN(100).filter(ImageFilter
.SMOOTH
),"frame 500",2)
206 #image=ImageMac.BWImage(em.GetNumericN(100))
207 #ImageMac.showNumeric(image)
216 #difimage=abs(image-ImageMac.BWImage(em.GetNumericN(10)))
217 #ImageMac.PlotHisto(difimage,32)
218 #ImageMac.showNumeric(difimage)
219 #difimage=127+(image-ImageMac.BWImage(em.GetNumericN(10)))/2
220 #ImageMac.PlotHisto(difimage,32)
221 #ImageMac.showNumeric(difimage)
222 #fimage=ImageMac.Filter3x3(16.0,(1,1,1,1,8,1,1,1,1),difimage)
223 #ImageMac.showNumeric(fimage)
224 #difimage2=choose(fimage.astype(UnsignedInt8),ilut)
225 #ImageMac.showNumeric(difimage2)
227 #(r,g,b,a)=ImageMac.SplitBands(em.GetNumericN(10))
228 #ImageMac.showNumeric(r,"r")
229 #ImageMac.showNumeric(g,"g")
230 #ImageMac.showNumeric(b,"b")
231 #ImageMac.showNumeric(a,"a")
232 #bwdif=abs(((innerproduct(em.GetNumericN(400),bw)-innerproduct(em.GetNumericN(10),bw))+255)/2)
233 #ImageMac.showNumeric(bwdif,"frame diff/bw",1)
234 #ImageMac.PlotHisto(bwdif)
235 #ImageMac.showNumeric(choose(bwdif.astype(UnsignedInt8),ilut),"frame diff/bw",1)
236 #ImageMac.PlotHisto(choose(bwdif.astype(UnsignedInt8),ilut))
237 #bwimage=ImageMac.BWImage(em.GetNumericN(100))
238 #ImageMac.showNumeric((ImageMac.BWImage(em.GetNumericN(90))+ImageMac.BWImage(em.GetNumericN(110))+ImageMac.BWImage(em.GetNumericN(130))+ImageMac.BWImage(em.GetNumericN(150))+ImageMac.BWImage(em.GetNumericN(170)))/5)
239 #bwdif=abs(((bwimage-ImageMac.BWImage(em.GetNumericN(10)))+255)/2)
240 #ImageMac.showNumeric(bwimage,"original frame",1)
241 #ImageMac.showNumeric(bwdif,"frame diff/bw",1)
242 #ImageMac.PlotHisto(bwdif)
243 #ImageMac.showNumeric(choose(bwdif.astype(UnsignedInt8),ilut),"frame diff/bw",1)
244 #mmask=choose(bwdif.astype(UnsignedInt8),mlut)
245 #ImageMac.showNumeric(255-255*mmask,"frame diff/bw",1)
246 #mmask.shape=bwimage.shape
247 #ImageMac.showNumeric(mmask*bwimage,"frame diff/bw",1)
249 #ImageMac.showNumeric((innerproduct(em.GetNumericN(300),bw)-innerproduct(em.GetNumericN(0),bw)),"frame diff/bw",1)
250 #ImageMac.showNumeric((innerproduct(em.GetNumericN(400)-em.GetNumericN(10),bw)),"frame diff2/bw",1)
251 #cdif=em.GetNumericN(400)-em.GetNumericN(10)
252 #ImageMac.showNumeric(,"frame diff2/bw",1)
254 #ImageMac.showNumeric(innerproduct(cdif,r),"frame 500r",1)
255 #ImageMac.showNumeric(innerproduct(cdif,g),"frame 500g",1)
256 #ImageMac.showNumeric(innerproduct(cdif,b),"frame 500b",1)
259 m
=GetMovieFromOpenFile()
261 print "no movie opened"
264 print "Total frames: ",em
.frames
," Current frame:",em
.curFrame
265 ImageMac
.showImage(em
.GetImage(),"frame 0",1)
267 if __name__
== '__main__':