11import math
2+ import struct
23from multiprocessing import Process , Queue , RLock
34
45class QueueStream (object ):
6+
7+ def __init__ (self , queue = None ):
8+ if not queue :
9+ queue = Queue ()
10+
11+ self .called = False
12+ self ._queue = queue
13+ self .stream = self .produce ()
14+
515 def produce_circle (self ):
616 RESIZE_SPEED_INV = 200
717 CMAX = 30000
@@ -73,13 +83,30 @@ def produce(self):
7383 while True :
7484 data = self .get_nowait ()
7585
76- if not data :
77- for pt in self .produce_circle ():
78- yield pt
86+ if data :
87+ # Index of instructions
88+ l = len (data )
89+ numPoints = (l - 3 )/ 18
90+ off = 3
91+ for i in xrange (numPoints ):
92+
93+ d = data [off :off + 18 ]
94+ off += 18
95+
96+ f , x , y , r , g , b , i , u1 , u2 = struct .unpack ("<HhhHHHHHH" , d )
97+ #print f, x, y, r, g, b, i, u1, u2
98+ yield (x , y , r , g , b )
99+ #flags, x, y, r, g, b, i, u1, u2)
100+
101+
102+
103+ #print 'Len data: ', l, m, type(data)
104+ #for pt in self.produce_circle2():
105+ # yield pt
79106 continue
80107
81- if data :
82- for pt in self .produce_circle2 ():
108+ if not data :
109+ for pt in self .produce_circle ():
83110 yield pt
84111 continue
85112
@@ -88,11 +115,6 @@ def produce(self):
88115 #print cmd, length
89116
90117
91- def __init__ (self ):
92- self .called = False
93- self ._queue = Queue ()
94- self .stream = self .produce ()
95-
96118 def read (self , n ):
97119 d = [self .stream .next () for i in xrange (n )]
98120 return d
0 commit comments