vpu_live4.py 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744
  1. #!/usr/bin/python3
  2. import math
  3. import random
  4. import time
  5. import os
  6. import sys
  7. import traceback
  8. import gc
  9. sys.path.insert(0,"/opt/LibreLight/Xdesk/")
  10. from lib.cprint import cprint
  11. HOME = os.getenv('HOME')
  12. import _thread as thread
  13. from optparse import OptionParser
  14. ...
  15. parser = OptionParser()
  16. parser.add_option("-m", "--mode", dest="mode",
  17. help="pixel mode pix,x,y --mode 40,10,8") #, metavar="FILE")
  18. parser.add_option("-X", "--XX", dest="XX", #default=1,
  19. help="x-split") #, metavar="FILE")
  20. parser.add_option("-x", "--xx", dest="xsplit", #default=1,
  21. help="x-split") #, metavar="FILE")
  22. parser.add_option("-y", "--yy", dest="ysplit",#default=1,
  23. help="y-split") #, metavar="FILE")
  24. parser.add_option("", "--start-univ", dest="start_univ",default=2,
  25. help="set start-univers default=2") #, metavar="FILE")
  26. parser.add_option("", "--gobo-ch", dest="gobo_ch",default=0,
  27. help="gobo ch univ on 1") #, metavar="FILE")
  28. parser.add_option("", "--gobo-ch2", dest="gobo_ch2",default=0,
  29. help="gobo ch univ on 1") #, metavar="FILE")
  30. #os.environ['SDL_VIDEO_WINDOW_POS'] = '%i,%i' % (200,164)
  31. parser.add_option("", "--win-pos", dest="win_pos",default="200,164",
  32. help="SDL_VIDEO_WINDOW_POS --win-pos=200,164") #, metavar="FILE")
  33. # PIXEL_MAPPING ... for gobo
  34. parser.add_option("", "--pixel-mapping", dest="pixel_mapping",default=0,
  35. help="pixel_mapping file/on --pixel-mapping=_x") #, metavar="FILE")
  36. parser.add_option("", "--dual-vpu", dest="dual_vpu",default=0,
  37. help=" --dual-vpu=1/0") #, metavar="FILE")
  38. parser.add_option("", "--out-idim", dest="out_idim",default="",
  39. help=" out_idim") #, metavar="FILE")
  40. parser.add_option("", "--countdown", dest="countdown",#default=1,
  41. help="enable countdown") #, metavar="FILE")
  42. parser.add_option("", "--videoplayer", dest="videoplayer",#default=1,
  43. help="enable videoplayer") #, metavar="FILE")
  44. parser.add_option("", "--title", dest="title",default="SCREEN",
  45. help="set title") #, metavar="FILE")
  46. (options, args) = parser.parse_args()
  47. import numpy
  48. QUIT = 0
  49. for o in dir(options):
  50. if "_" in o:
  51. continue
  52. print(o,options.__getattribute__(o))
  53. START = time.time()
  54. # ===== ARTNET DMX =========
  55. import memcache
  56. mc = memcache.Client(['127.0.0.1:11211'], debug=0)
  57. def read_index():
  58. ips=mc.get("index")#cmd)
  59. if ips is None:
  60. ips = {}
  61. return ips
  62. def select_ip(ips, univ=2): # artnet univ
  63. _univ = ":{}".format(univ)
  64. for ip in ips: #high priority
  65. if "2.0.0" in ip and _univ in ip:
  66. return ip
  67. for ip in ips:
  68. if "ltp-out" in ip and _univ in ip:
  69. return ip
  70. INPUT_START_POS_X = 40
  71. INPUT_START_POS_Y = 236 #320
  72. FUNC = 0
  73. COUNTER = []
  74. if options.countdown:
  75. cdmx_start = options.countdown.split(",")
  76. for cdmx in cdmx_start:
  77. try:
  78. cdmx = int(cdmx)
  79. _tmp={"DMX":cdmx,"DIM":0,"PAN":127,"TILT":127
  80. ,"CONTROL":0,"SEC":10
  81. ,"RED":255,"GREEN":255,"BLUE":255
  82. ,"_time":time.time(),"_RUN":0,"_pause":0,"_start":0
  83. ,"_SEC":">{}<".format(cdmx)
  84. }
  85. COUNTER.append(_tmp)
  86. except Exception as e:
  87. cprint("EXCEPTION COUNTER INIT ",cdmx,color="red")
  88. def read_dmx(ip):
  89. r = ""
  90. if ip:
  91. #t = int(math.sin(time.time() - s)*10)
  92. r = mc.get(ip) #"2.0.0.13:2")
  93. rr = [0]*512
  94. for i,v in enumerate(r):
  95. try: #cleanup ltp-out to int
  96. v = int(v)
  97. rr[i] = v
  98. except:pass
  99. r = rr
  100. if not r:
  101. c = 0
  102. #time.sleep(0.1)
  103. r = [0] *512
  104. for i in range(12*8+1):
  105. dmx = i*4
  106. #print(dmx)
  107. r[dmx:dmx+4] = [255,10,10,40]
  108. return r
  109. # ===== ARTNET DMX =========
  110. MEDIALIST = []
  111. try:
  112. MEDIALIST = open_medialist()
  113. except:pass
  114. from tool.video_capture import scan_capture #as scan_capture
  115. def _rescale_frame_by_width(frame, width):
  116. #print(type(frame)) #np array
  117. height = int(frame.shape[0]/frame.shape[1] * width )
  118. dim = (width, height)
  119. #return cv2.resize(frame, dim, interpolation =cv2.INTER_AREA)
  120. return cv2.resize(frame, dim, interpolation =cv2.INTER_LINEAR)
  121. def _rescale_frame_by_procent(frame, percent=75):
  122. #print(type(frame))
  123. width = int(frame.shape[1] * percent/ 100)
  124. height = int(frame.shape[0] * percent/ 100)
  125. dim = (width, height)
  126. return cv2.resize(frame, dim, interpolation =cv2.INTER_LINEAR)
  127. def _moveImage(img,x=0,y=0,shape=None):
  128. #print(type(img)) #np.array
  129. # Creating a translation matrix
  130. np = numpy
  131. translation_matrix = np.float32([ [1,0,x], [0,1,y] ])
  132. if shape is None:
  133. num_cols,num_rows = img.shape[1::-1]
  134. else:
  135. num_cols,num_rows = shape #[1::-1]
  136. # Image translation
  137. frame = cv2.warpAffine(img, translation_matrix, (num_cols,num_rows))
  138. return frame
  139. def _rotateImage(image, angle):
  140. #print(type(image)) # nm.array
  141. if angle in [0,360]:
  142. pass#return image
  143. try:
  144. #print("EE",image.shape)
  145. #print("EE",dir(image))
  146. shape = list(image.shape[1::-1])
  147. bg_shape = shape[:]
  148. delta_x = 0 # + nach rechts
  149. delta_y = 0 # + nach unten
  150. r = []
  151. r.extend(list(range(0-3,0+3)))
  152. r.extend(list(range(180-3,180+3)))
  153. r.extend(list(range(360-3,360+3)))
  154. r2 = []
  155. r2.extend(list(range(90-3,90+3)))
  156. r2.extend(list(range(270-3,270+3)))
  157. if angle in r:
  158. pass
  159. elif 0:#angle in r2:
  160. bg_shape = bg_shape[::-1]
  161. delta_y = -65 #shape[1]/2 # # + nach unten
  162. delta_x = 30 #shape[1]/2 # # + nach unten
  163. delta_y -= bg_shape[1]/2 - 20
  164. delta_x = bg_shape[0]/2 - 10
  165. pass
  166. else:
  167. if shape[0] > shape[1]:
  168. # landscape video
  169. bg_shape = (shape[0],shape[0])
  170. delta_y = (shape[0]-shape[1])/2
  171. else:
  172. # portrait video
  173. bg_shape = (shape[1],shape[1])
  174. delta_x = (shape[1]-shape[0])/2
  175. center = (shape[0]/2+delta_x,shape[1]/2+delta_y)
  176. image = _moveImage(image,x=delta_x,y=delta_y,shape=bg_shape)
  177. bg_shape = tuple(bg_shape) # exception ... if angle 0 no tuple !!!
  178. rot_mat = cv2.getRotationMatrix2D(center,angle,1.0)
  179. frame = cv2.warpAffine(image, rot_mat, bg_shape ) #,flags=cv2.INTER_LINEAR)
  180. return frame
  181. except Exception as e:
  182. raise(e)
  183. def calc_dim(dim=1,rgb=[255,255,255]):
  184. rgb[0] = int(rgb[0]*dim/255)
  185. rgb[1] = int(rgb[1]*dim/255)
  186. rgb[2] = int(rgb[2]*dim/255)
  187. return rgb
  188. def draw_media_background(wn,x,y,w,h,rgb):
  189. hx=int(w/2)
  190. hy=int(h/2)
  191. p1 = [x-hx ,y-hy] # links oben
  192. p2 = [x+hx ,y+hy] # recht unten
  193. p3 = [x+hx ,y-hy] # rechts oben
  194. p4 = [x-hx ,y+hy] # links unten
  195. bg_on=0
  196. if bg_on:
  197. #pygame.draw.rect(wn,rgb ,[p1[0] ,p1[1] ,__xw ,__yw])
  198. #pygame.draw.rect(wn,[25,20,20],[p1[0]+1,p1[1]+1,hx-2,hx-2])
  199. pass
  200. # frame border
  201. pygame.draw.line(wn,rgb ,p1 ,p3) # top
  202. pygame.draw.line(wn,rgb ,p2 ,p3) # right
  203. pygame.draw.line(wn,rgb ,p2 ,p4) # bottom
  204. pygame.draw.line(wn,rgb ,p1 ,p4) # right
  205. # cross lines
  206. pygame.draw.line(wn,rgb ,p1 ,p2) # tl - br
  207. pygame.draw.line(wn,rgb ,p3 ,p4) # tr - bl
  208. class MediaImg():
  209. def __init__(self):
  210. pass
  211. class MediaCam():
  212. def __init__(self):
  213. pass
  214. def draw(self,wn,im,x,y):
  215. w2 = int(im.get_width()/2)
  216. h2 = int(im.get_height()/2)
  217. wn.blit(im, (int(x-w2), int(y-h2))) # draw frame
  218. def _open_cam(self,obj):
  219. # LIVE VIDEO INPUT UVC DEVICE
  220. cfg = self._cam_cfg()
  221. print("III",cfg)
  222. res = "HD"
  223. #res = "4K"
  224. #res = ""
  225. if res == "HD":
  226. # HD
  227. w = 1920
  228. h = 1080
  229. elif res == "4K":
  230. # 4K
  231. w = 3840
  232. h = 2160
  233. else:
  234. # LOW
  235. w = 1280
  236. h = 720
  237. d = 0 # VIDEO INPUT DEV
  238. for c in cfg:
  239. try:
  240. if c.startswith("d"):
  241. d = int(c[1:])
  242. if c.startswith("h"):
  243. h = int(c[1:])
  244. if c.startswith("w"):
  245. w = int(c[1:])
  246. if c.startswith("video"):
  247. d = int(c[-1])
  248. except Exception as e:
  249. cprint("Exception", "cam_cfg 878",e,color="red")
  250. df = "video{}".format(d)
  251. if obj._stop:
  252. df += "_stop"
  253. elif os.path.exists("/dev/{}".format(df)):
  254. obj.Rcap = cv2.VideoCapture(d)
  255. obj.Rcap.set(cv2.CAP_PROP_FRAME_WIDTH, w)
  256. obj.Rcap.set(cv2.CAP_PROP_FRAME_HEIGHT, h)
  257. else:
  258. #obj.Rcap = None
  259. #obj.end = 1
  260. df += "_error"
  261. if obj.fname.startswith("cam_"):
  262. obj.fname = "cam_{}".format(df)
  263. def _cam_cfg(self):
  264. fn = HOME+'/LibreLight/video_in.txt'
  265. if not os.path.isfile(fn):
  266. self._cam_cfg_new(fn)
  267. f = open(fn ,"r")
  268. lines = f.readlines()
  269. f.close()
  270. cfg = ""
  271. for i in lines:
  272. if i.startswith("d"):
  273. cfg = i
  274. cfg = cfg.split()
  275. capture = scan_capture(name="MiraBox",serial="")
  276. #capture = scan_capture(name="Integrated",serial="")
  277. if capture:
  278. print("capture",capture)
  279. try:
  280. cfg.append(capture[0][0])
  281. except Exception as e:
  282. cprint("except 2992",e,color="red")
  283. else:
  284. cprint("---- ERROR NO VIDEO CAPTURE DEV - FOUND ----",color="red")
  285. print("_cam_cfg:",len(cfg),[cfg])
  286. return cfg
  287. def _cam_cfg_new(self,fn):
  288. #fn = HOME+'/LibreLight/video_in.txt'
  289. txt = [
  290. "# Example",
  291. "d0 w640 h480 # PAL",
  292. "d0 w800 h600 # SVGA",
  293. "d0 w960 h540 # 540p",
  294. "d0 w1024 h768 # XGA <---",
  295. "d0 w1280 h720 # 720p",
  296. "d0 w1440 h900 # WSXGA+",
  297. "d0 w1600 h900 # WSXGA - Laptop 16:9",
  298. "d0 w1920 h1080 # HD 1080p",
  299. "",
  300. "# config",
  301. "d0 w1024 h768 # XGA",
  302. ]
  303. f = open(fn ,"w")
  304. f.write("\n".join(txt))
  305. f.close()
  306. class PixelMedia():
  307. def __init__(self,dmx=None,_id=None):
  308. global MEDIALIST
  309. self._id = _id
  310. self.fpath = HOME+'/Downloads/'
  311. self.fpath = HOME+'/LibreLight/video/'
  312. self.fname = '' #'bbb_sunflower_480x320.mp4'
  313. #self.fname = 'no-video.mp4'
  314. try:
  315. self.fname = MEDIALIST[0]
  316. except Exception as e:
  317. cprint("Exception set video from MEDIALIST 5543:",e,color="red")
  318. self.cam = MediaCam()
  319. self.img_meta = {}
  320. self.restart_t = time.time()
  321. self.fps = 0
  322. self.scale = 50 #%
  323. self.angle = 0 #%
  324. self.dmx=dmx
  325. if self._id >= 250:
  326. self.fname = "cam_"
  327. self.dim = 0
  328. self.x = 0
  329. self.y = 0
  330. self.init_count = 0
  331. self.cap = None
  332. self.shape = [200,200]
  333. self.img = None
  334. self.success = 1
  335. self._run = 0
  336. self.end = 0
  337. self._media_nr = 0
  338. self._stop = 0 # fix buffer-overflow ... ?? opencv
  339. self.shape_x = 370
  340. self.shape_y = 235
  341. self.dmx_change = 0
  342. self.frame_change = 0
  343. self.init()
  344. def update_dmx(self,x,y,scale,angle,dim):
  345. if int(self.x*100) != int(x*100):
  346. self.x = x
  347. self.dmx_change = 1
  348. if int(self.y*100) != int(y*100):
  349. self.y = y
  350. self.dmx_change = 1
  351. if int(self.scale*100) != int(scale*100):
  352. self.scale = scale
  353. self.dmx_change = 1
  354. if int(self.angle*100) != int(angle*100):
  355. self.angle = angle
  356. self.dmx_change = 1
  357. if int(self.dim*100) != int(dim*100):
  358. self.dim = dim
  359. self.dmx_change = 1
  360. def __repr__(self):
  361. sizeof = int(sys.getsizeof(self.buffer)/8)
  362. return "< id:{} buf:{} run:{} fps:{} scale:{} name:{} {}kb>".format(
  363. id(self),len(self.buffer),self._run,self.fps,self.scale
  364. ,self.fname,sizeof
  365. )
  366. def restart(self):
  367. print(self,"reset()")
  368. self.pos = 0
  369. self.restart_t = time.time()
  370. def init(self):
  371. print("---- ---- PixelMedia.init()",[self.fname,self._media_nr])
  372. #print(MEDIALIST)
  373. self.time = 0
  374. self.t_delta = 0
  375. self.t_last = time.time()
  376. self.im = None
  377. self.pos = 0
  378. self.buffer = []
  379. self._init()
  380. self.init_count = 1
  381. self.dmx_change = 0
  382. self.frame_change = 0
  383. def select_video(self,dmx_value):
  384. try:
  385. dmx_value = int(dmx_value/10)
  386. if self._media_nr != dmx_value:
  387. self._media_nr = dmx_value
  388. if self._media_nr >= 25:
  389. self.fname = "cam_"
  390. self.init()
  391. elif self._media_nr < len(MEDIALIST):
  392. self.fname = str(MEDIALIST[self._media_nr])
  393. self.init()
  394. #finally:pass
  395. except Exception as e:
  396. cprint("PixelMedia.select_video()",dmx_value,e,color="red")
  397. def _init(self):
  398. print(self)
  399. print("videoplayer.init()",self.fpath,self.fname)
  400. if not os.path.isfile(self.fpath+self.fname):
  401. print()
  402. cprint("video file does not exits !! >",self.fpath,self.fname,color="red")
  403. print()
  404. #exit()
  405. self.Rsuccess = 0
  406. if not cv2:
  407. return
  408. if self._stop:
  409. return
  410. if self.fname.endswith(".jpg"):
  411. self.img_meta = create_img_meta()
  412. if self.img_meta["fname"] == self.fname:
  413. return
  414. self.img_meta["_fpath"] = self.fpath
  415. self.img_meta["fname"] = self.fname
  416. img_open(self.img_meta)
  417. self.buffer = [1] #,2,3]
  418. return # STOP
  419. if self.fname.startswith("cam_"):
  420. self.cam._open_cam(obj=self)
  421. self.img_meta = {}
  422. else:
  423. self.Rcap = cv2.VideoCapture(self.fpath+self.fname, cv2.CAP_FFMPEG)
  424. #FFMPEG malloc(): unsorted double linked list corrupted ... Abgebrochen
  425. self.img_meta = {}
  426. print("_init ?",self.Rcap)
  427. print("open ?" ,self.Rcap.isOpened())
  428. self.Rcap.read()
  429. #self.Rfvs = FileVideoStream(self.fpath+self.fname).start()
  430. self.Rsuccess = 1
  431. self.read()
  432. def _del(self):
  433. if self.img_meta:
  434. return
  435. self._stop = 1
  436. self.buffer = [] #.append(self.img)
  437. self.Rcap.release()
  438. self.Rcap.retrieve()
  439. self.Rcap = None
  440. self.cap = None
  441. del self.Rcap #.release()
  442. gc.collect()
  443. def read(self):
  444. if self.img_meta:
  445. return
  446. success = self.Rsuccess
  447. ok = 0
  448. if success and self.fname:
  449. cap = self.Rcap
  450. #fvs = self.Rfvs
  451. _break = 0
  452. try:
  453. success, img = cap.read()
  454. if not success:
  455. self.Rcap.release()
  456. self.Rcap.retrieve()
  457. self.end = 1
  458. #j = json.dumps(self.buffer) #.append(img)
  459. #f = open("/tmp/buff")
  460. #f.write(j)
  461. #f.close()
  462. return
  463. if self.fps == 0:
  464. self.fps = cap.get(cv2.CAP_PROP_FPS)
  465. img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
  466. if self.fname.startswith("cam_"):
  467. pass
  468. #img = _rescale_frame_by_width(img, 1200)
  469. else:
  470. img = _rescale_frame_by_width(img, 200)
  471. #img = _rescale_frame_by_width(img, 1200)
  472. # store frame into buffer list
  473. if self.fname.startswith("cam_"):
  474. self.buffer = [ img ]
  475. else:
  476. self.buffer.append(img)
  477. ok = 1
  478. if len(self.buffer) % 100 == 0:
  479. _id = str(self.__repr__)[-5:-1]
  480. print(_id,"video read",self.dmx,len(self.buffer),self.fname,"fps",self.fps,self.dim)
  481. except Exception as e:
  482. cprint("Exception","_init",self,e,end="",color="red")
  483. self.success = 1
  484. return ok
  485. def prev(self):
  486. self.pos -= 1
  487. if self.pos < 0:
  488. self.pos = len(self.buffer)-1
  489. if self.pos >= len(self.buffer):
  490. self.pos = len(self.buffer)-1
  491. self.im = self.buffer[int(self.pos)]
  492. def _rotateImage(self,image, angle):
  493. if self.img_meta:
  494. return
  495. return _rotateImage(image, angle)
  496. def pause(self):
  497. if self.img_meta:
  498. return
  499. #print("pause",self.t_last)
  500. t = time.time()
  501. self.t_delta = 0
  502. self.t_last = t
  503. def next_frame(self):
  504. if self.img_meta:
  505. return
  506. #return 0
  507. if self._run and len(self.buffer) > 30:
  508. t = time.time()
  509. self.t_delta = t-self.t_last
  510. self.pos += int(self.t_delta*self.fps)
  511. self.t_last = t
  512. #self.frame_change = 1
  513. else:
  514. self.pause()
  515. if self.restart_t > time.time()-0.5:
  516. # prevent flickerung by reset
  517. #self.pause()
  518. self.pos = 5
  519. pass
  520. # restart at the end
  521. if int(self.pos) >= len(self.buffer)-1:
  522. self.pos = 0
  523. self.img = None
  524. if self.buffer:
  525. self._img = self.buffer[int(self.pos)]
  526. self.img = self._img
  527. def check_cv2_check(self):
  528. if not cv2:
  529. cprint("cv2 not importet ! no VIDEO support !",color="red")
  530. return 0
  531. return 1
  532. def next(self):
  533. if self.img_meta:
  534. self.next_frame()
  535. return
  536. try:
  537. self.next_frame()
  538. if self.img is None:
  539. return
  540. self.img = _rescale_frame_by_procent(self.img, percent=self.scale)
  541. # rotate frame BUG: x,y offset ??? !!!
  542. self.img = self._rotateImage(self.img, self.angle)
  543. self.shape = self.img.shape[1::-1]
  544. if len(self.buffer) % 100 == 0:
  545. _id = str(self.__repr__)[-5:-1]
  546. print("next",_id)
  547. # add DIMER to videplayer
  548. cv2.normalize(self.img, self.img, 0, self.dim, cv2.NORM_MINMAX)
  549. img = self.img
  550. if img is None:
  551. return
  552. self.im = None
  553. self.im = pygame.image.frombuffer(img.tobytes(), self.shape, "RGB")
  554. #self.next_frame()
  555. except AttributeError as e:
  556. time.sleep(.05)
  557. #if self.init_count % 100 == 0:
  558. cprint("except 776",e,color="red")
  559. #self.init()
  560. except Exception as e:
  561. cprint("except 756",e,color="red")
  562. cprint(traceback.format_exc(),color="red")
  563. cprint(sys.exc_info()[2],color="red")
  564. cprint()
  565. def calc_im_size(self):
  566. try:
  567. xx ,yy = self.im.get_size()[:2]
  568. self.shape_x = xx
  569. self.shape_y = yy
  570. except AttributeError as e:
  571. pass
  572. def calc_zoom(self,xx,yy):
  573. if self.scale < 255*.05:
  574. self.scale = 255*0.05
  575. xx = int(xx*self.scale/255)
  576. yy = int(yy*self.scale/255)
  577. return xx,yy
  578. def draw_video(self,wn,im,x,y):
  579. w2 = int(im.get_width()/2)
  580. h2 = int(im.get_height()/2)
  581. wn.blit(im, (int(x-w2), int(y-h2))) # draw frame
  582. def draw_img(self,wn,img_meta):
  583. self.img_meta["pos"] = [self.x,self.y]
  584. self.img_meta["scale"] = self.scale #= 50 #%
  585. self.img_meta["dim"] = self.dim #255
  586. self.img_meta["ang"] = self.angle # 0
  587. if 1: #self.is_change():
  588. im2 = self.img_meta["raw_img"]
  589. im2 = img_rescale(im2, percent=self.img_meta["scale"])
  590. # add DIMER to videplayer
  591. im2 = cv2.normalize(im2, im2, 0, self.img_meta["dim"], cv2.NORM_MINMAX)
  592. self.img_meta["img"] = im2
  593. img_draw_raw(self.img_meta)
  594. self.change_reset()
  595. def is_change(self):
  596. #if self.frame_change or self.dmx_change:
  597. if self.frame_change or self.dmx_change:
  598. #if self.dmx_change:
  599. return True
  600. def change_reset(self):
  601. if self.frame_change:
  602. print("media frame change")
  603. if self.dmx_change:
  604. print("media dmx change")
  605. self.frame_change = 0
  606. self.dmx_change = 0
  607. def draw(self,wn=None):
  608. if self.img_meta:
  609. self.draw_img(wn,self.img_meta)
  610. return
  611. if self.dim <= 1:
  612. return
  613. self.calc_im_size()
  614. im = self.im
  615. x=self.x
  616. y=self.y
  617. #w,h = self.calc_zoom(x,y)
  618. w = self.shape_x
  619. h = self.shape_y
  620. if self.success and wn and im:
  621. if self.fname.startswith("cam_"):
  622. self.cam.draw(wn,im,x,y)
  623. else:
  624. self.draw_video(wn,im,x,y)
  625. self.change_reset()
  626. def get_meta(self):
  627. out = {}
  628. mode="x"
  629. if self._run:
  630. mode = "run"
  631. else:
  632. mode = "pause"
  633. out["frames"] = len(self.buffer)
  634. out["mode"] = mode
  635. out["fname"] = self.fname
  636. out["scale"] =self.scale
  637. out["fps"] = int(self.fps)
  638. out["pos"] = self.pos
  639. out["dim"] = self.dim
  640. out["run"] = self._run
  641. out["cur"] = 0
  642. if self.fps > 0: # check if div zerro
  643. out["cur"] = (self.pos/self.fps)
  644. out["x"] = self.x
  645. out["y"] = self.y
  646. out["id"] = self._id
  647. out["nr"] = self._media_nr
  648. out["pz"] = 0
  649. return out
  650. def _overlay_text(self):
  651. meta = self.get_meta()
  652. keys = ["fps","pos","frames","cur","pz","x","y","scale","dim"]
  653. _line = create_format_line(meta,keys)
  654. keys= ["id","nr","mode","fname"]
  655. _line2 = create_format_line(meta,keys)
  656. return [_line,_line2]
  657. def create_format_line(meta,keys):
  658. _line = []
  659. for k in keys:
  660. v=meta.get(k,"-")
  661. _line.append(str(k))
  662. _line.append(":")
  663. if type(v) is float:
  664. _line.append("{:02f}".format(v))
  665. else:
  666. _line.append(str(v))
  667. _line.append(" ")
  668. _line = "".join(_line)
  669. return _line
  670. PixelMedia = PixelMedia
  671. VIDEO = []
  672. videoplayer=[]
  673. cv2 = None
  674. FileVideoStream = None
  675. _vid = 0
  676. if type(options.videoplayer) is str:
  677. try:
  678. import cv2
  679. except Exception as e:
  680. cprint("Except Import:",e,color="red")
  681. try:
  682. # faster video reading ... ???
  683. from imutils.video import FileVideoStream
  684. except Exception as e:
  685. cprint("Except Import:",e,color="red")
  686. max_videoplayer = 4
  687. dmx_start = options.videoplayer.split(",")
  688. for cdmx in dmx_start:
  689. if len(videoplayer) > max_videoplayer:
  690. print("-- videoplayer max count {} !! break".format(max_videoplayer))
  691. break
  692. print("-- videoplayer dmx:",cdmx)
  693. try:
  694. cdmx = int(cdmx)
  695. videoplayer.append( PixelMedia(cdmx,_id=_vid) )
  696. _vid += 1
  697. _tmp = {"DMX":cdmx,"DIM":0,"PAN":127,"TILT":127
  698. ,"CONTROL":0,"SEC":10,"VIDEO":"3"
  699. ,"RED":255,"GREEN":255,"BLUE":255
  700. ,"_time":time.time()
  701. ,"_RUN":0,"_SEC":">{}<".format(cdmx)
  702. }
  703. VIDEO.append(_tmp)
  704. except Exception as e:
  705. cprint("EXCEPTION COUNTER INIT ",cdmx,color="red")
  706. def loop_videoplayer():
  707. while 1:
  708. _videoplayer = videoplayer[:]
  709. #print(".")
  710. ok = 0
  711. for i in _videoplayer: #.append( PixelMedia(cdmx,_id=_vid) )
  712. try:
  713. r = i.read() # read next frame from file
  714. if r:
  715. ok = 1
  716. except Exception as e:
  717. cprint("EXCEPTION loop_videoplayer ",e,color="red")
  718. cprint(traceback.format_exc(),color="red")
  719. cprint(sys.exc_info()[2],color="red")
  720. cprint()
  721. if ok == 0:
  722. time.sleep(0.1)
  723. else:
  724. time.sleep(0.005)
  725. if QUIT:
  726. break
  727. thread.start_new_thread(loop_videoplayer,())
  728. p = 16
  729. block = [p,p]
  730. _x = 8
  731. _y = 8
  732. #HD = "0"
  733. if options.mode:
  734. try:
  735. HD = options.mode
  736. p,_x,_y = HD.split(",")
  737. _x = int(_x)
  738. _y = int(_y)
  739. p = int(p)
  740. block = [p,p]
  741. except Exception as e:
  742. cprint( "Exc",options.mode,e,color="red")
  743. # PARSE COMMANDLINE ARGUMENTS
  744. CFG_IN = {"name":"CFG_IN","x1":40,"y1":60,"x2":0,"y2":0 ,"w":0,"h":300}
  745. # OUTPUT CFG INIT
  746. CFG_OUT = []
  747. out_idim = options.out_idim
  748. if out_idim:
  749. out_idim = options.out_idim.split(",")
  750. x1 = 40
  751. for i,v in enumerate(out_idim):
  752. if type(v) is str:
  753. v=0
  754. _t = {"name":"CFG_OUT{}".format(i+1),"x1":x1,"y1":60,"x2":0,"y2":0 ,"w":30,"h":30,"on":1,"DMX-CH":v}
  755. CFG_OUT.append(_t)
  756. x1 += p*8
  757. CFG_BLOCK = {"name":"CFG_BLOCK","size":16,"h-split":2,"v-split":2,"h-count":8,"v-count":8}
  758. if _x < 1:
  759. _x = 1
  760. if _y < 1:
  761. _y = 1
  762. CFG_BLOCK["h-count"] = _x
  763. CFG_BLOCK["v-count"] = _y # int(8*8/_x) #/_x+0.5) #_y
  764. CFG_BLOCK["size"] = p
  765. print( [options.xsplit])
  766. print( [options.ysplit])
  767. try:
  768. if options.xsplit:
  769. CFG_BLOCK["h-split"] = int(options.xsplit)
  770. if options.ysplit:
  771. CFG_BLOCK["v-split"] = int(options.ysplit)
  772. except Exception as e:
  773. cprint( "Exc",options.mode,e,color="red")
  774. print("HD",CFG_BLOCK["h-split"],CFG_BLOCK["v-split"])
  775. print("xy",_x,_y)
  776. print("++++++++++++++++++", p,_x,_y)
  777. _x2 = _x
  778. try:
  779. if options.XX:
  780. pass#_x2 = int(options.XX)
  781. except Exception as e:
  782. cprint( "Exc",options.mode,e,color="red")
  783. print("_x2 , -X",_x2)
  784. # ===== GUI =========
  785. import pygame
  786. import pygame.gfxdraw
  787. import pygame.font
  788. clock = pygame.time.Clock()
  789. os.environ['SDL_VIDEO_WINDOW_POS'] = '%i,%i' % (200,164)
  790. if options.win_pos:
  791. if "," in options.win_pos:
  792. win_pos = options.win_pos.split(",")
  793. try:
  794. WIN_POS = '%i,%i' % (int(win_pos[0]),int(win_pos[1]) )
  795. os.environ['SDL_VIDEO_WINDOW_POS'] = WIN_POS
  796. except Excetpion as e:
  797. cprint("win_pos",win_pos,e,color="red")
  798. os.environ['SDL_VIDEO_CENTERED'] = '0'
  799. pg = pygame
  800. pygame.init()
  801. pygame.mixer.quit()
  802. f = pygame.font.get_fonts()
  803. for i in f:
  804. if "mono" in i.lower():
  805. print(i)
  806. font = pygame.font.SysFont("freemonobold",22)
  807. font10 = pygame.font.SysFont("freemonobold",10)
  808. font12 = pygame.font.SysFont("freemonobold",12)
  809. font12l = pygame.font.SysFont("freemono",12)
  810. font15 = pygame.font.SysFont("freemonobold",15)
  811. font40 = pygame.font.SysFont("freemonobold",40)
  812. font80 = pygame.font.SysFont("freemonobold",70)
  813. #font = pygame.font.SysFont(None,30)
  814. fr = font.render("hallo" ,1, (200,0,255))
  815. def clean_path(path):
  816. _path = path[:]
  817. _path = _path.replace("/","-")
  818. _path = _path.replace(".","-")
  819. _path = _path.replace("\"","-")
  820. _path = _path.replace("'","-")
  821. return _path
  822. PIXEL_MAPPING = 0
  823. vpu_wall_conf_file = HOME+"/LibreLight/vpu_wall_conf.csv"
  824. grid_file = "/tmp/vpu_grid_hd.csv"
  825. text_file = HOME+"/LibreLight/vpu_text_hd.csv"
  826. media_list = HOME+"/LibreLight/video/" #.format(path)
  827. pm_wy = 0
  828. if options.pixel_mapping:
  829. PIXEL_MAPPING = 1
  830. path = options.pixel_mapping
  831. path = clean_path(path)
  832. grid_file = HOME+"/LibreLight/vpu_grid_hd{}.csv".format(path)
  833. if options.dual_vpu:
  834. grid_file = HOME+"/LibreLight/vpu_grid_dual{}.csv".format(path)
  835. text_file = HOME+"/LibreLight/vpu_text_hd{}.csv".format(path)
  836. media_list = HOME+"/LibreLight/video/" #.format(path)
  837. if not options.out_idim:
  838. PIXEL_MAPPING = 0
  839. print(" ",[options.pixel_mapping],"grid_file",grid_file)
  840. #grid_file = HOME+"/LibreLight/vpu_grid_hd.csv"
  841. MAIN_SIZE=(600,500)
  842. try:
  843. if _x < 8 and PIXEL_MAPPING >= 1:
  844. wx = 30+30+block[0] * 8
  845. CFG_IN["w"] = CFG_BLOCK["size"] * 8
  846. else:
  847. wx = 30+30+block[0] * _x
  848. wy = 40+40+block[1] * _y
  849. if type(options.videoplayer) is str:
  850. wy += 150 # video medialist
  851. MAIN_SIZE=(wx,wy)
  852. if PIXEL_MAPPING >= 1:
  853. pm_wy = 11*p #+ p*3
  854. CFG_IN["y1"] += 11*p
  855. if options.dual_vpu:
  856. if wx < p*16+155:
  857. wx = p*16+155
  858. MAIN_SIZE=(wx,wy+pm_wy)
  859. except Exception as e:
  860. cprint("Exception:",e,color="red")
  861. CFG_IN["w"] = CFG_BLOCK["size"] * CFG_BLOCK["h-count"]
  862. CFG_IN["h"] = CFG_BLOCK["size"] * CFG_BLOCK["v-count"]
  863. for CFG_OUTx in CFG_OUT:
  864. CFG_OUTx["w"] = CFG_BLOCK["size"] * 8
  865. CFG_OUTx["h"] = CFG_BLOCK["size"] * 8
  866. def CFG_CALC_P(CFG):
  867. CFG["x2"] = CFG["x1"]+CFG["w"]
  868. CFG["y2"] = CFG["y1"]+CFG["h"]
  869. CFG["p1"] = [CFG["x1"] ,CFG["y1"]]
  870. CFG["p2"] = [CFG["x2"] ,CFG["y2"]]
  871. print("CFG",CFG)
  872. # ?
  873. #CFG_IN["w"] = int(CFG_BLOCK["v-count"]-2) * CFG_BLOCK["size"]
  874. CFG_CALC_P(CFG_IN)
  875. for CFG_OUTx in CFG_OUT:
  876. CFG_CALC_P(CFG_OUTx)
  877. print("CFG_BLOCK",CFG_BLOCK)
  878. print()
  879. print()
  880. print()
  881. print()
  882. print()
  883. window = pygame.display.set_mode(MAIN_SIZE,pg.RESIZABLE)#,32)#,pygame.FULLSCREEN) #x left->right ,y top-> bottom
  884. pg.display.set_caption('LibreLight VPU-{}'.format(options.title))
  885. class Fix():
  886. def __init__(self,_id,pos,block=[16,16],univ=0,dmx=0,ch=4):
  887. #print("Fix",_id)
  888. self._id = _id
  889. self.dmx = (_id-1) * ch +1 #dmx
  890. self.univ = univ
  891. self.ch = ch
  892. self.pos = pos
  893. self.rgb = [0,0,0]
  894. self.block = block #[10,10]
  895. self.x = pos[0]
  896. self.y = pos[1]
  897. self._x = 0
  898. self._y = 0
  899. self.strobo = time.time()
  900. self.bmp = 250
  901. self.sub_fix = []
  902. sub_block =[block[0]/CFG_BLOCK["h-split"],block[1]/CFG_BLOCK["v-split"]]
  903. if _id <= 0: #exit
  904. return
  905. spalte = (_id-1)%_y +1
  906. zeile = int((_id-1)/_x2) #+1
  907. add_row = _x*CFG_BLOCK["h-split"]*CFG_BLOCK["v-split"]
  908. #zeile 1
  909. sid = (_id-1)*2 + zeile*CFG_BLOCK["h-split"]*_x2
  910. sid = sid+1
  911. sub_pos= [pos[0]*block[0],pos[1]*block[1]]
  912. sub_fix = SubFix(sid,sub_pos,sub_block,univ,dmx,ch)
  913. self.sub_fix.append(sub_fix)
  914. sid = sid+1
  915. sub_pos= [pos[0]*block[0]+block[0]/2,pos[1]*block[1]]
  916. sub_fix = SubFix(sid,sub_pos,sub_block,univ,dmx,ch)
  917. self.sub_fix.append(sub_fix)
  918. #zeile 2
  919. sid = (_id-1)*2+1 + _x2*CFG_BLOCK["h-split"] + zeile*CFG_BLOCK["h-split"]*_x2 # int(add_row)
  920. sub_pos= [pos[0]*block[0],pos[1]*block[1]+block[1]/2]
  921. sub_fix = SubFix(sid,sub_pos,sub_block,univ,dmx,ch)
  922. self.sub_fix.append(sub_fix)
  923. #sid = sid+1
  924. sid = sid+1
  925. sub_pos= [pos[0]*block[0]+block[0]/2,pos[1]*block[1]+block[1]/2]
  926. sub_fix = SubFix(sid,sub_pos,sub_block,univ,dmx,ch)
  927. self.sub_fix.append(sub_fix)
  928. def __repr__(self):
  929. return "<Fix: {} {} {} {}>".format(id(self),self.x,self.y,self.dmx)
  930. def calc(self,data):
  931. _rgb = [0,255,0]
  932. return _rgb
  933. def sub_calc(self,data):
  934. _rgb = [0,255,0]
  935. for sub_fix in self.sub_fix:
  936. sub_fix.block = self.block[:]
  937. _rgb = sub_fix.dmx_calc(data)
  938. return _rgb
  939. def _calc(self,a,b):
  940. A = (self.pos[0])*self.block[0]
  941. B = (self.pos[1])*self.block[1]
  942. C = self.block[0]-a
  943. D = self.block[1]-b
  944. return A,B,C,D
  945. def POS(self,x=None,y=None,a=0,b=0):
  946. if type(x) is int:
  947. self._x=x
  948. if type(y) is int:
  949. self._y=y
  950. A,B,C,D = self._calc(a,b)
  951. return [self._x+A,self._y+B,C,D]
  952. def XXXsubPOS(self,x=0,y=0,a=0,b=0):
  953. __out = []
  954. for sub_fix in self.sub_fix:
  955. __out.append( sub_fix.POS(x,y,a,b) )
  956. return __out
  957. class SubFix():
  958. def __init__(self,_id,pos,block=[16,16],univ=0,dmx=0,ch=4):
  959. #print("Fix",_id)
  960. self._id = _id
  961. self.dmx = (_id-1) * ch +1 #dmx
  962. self.univ = univ
  963. self.ch = ch
  964. self.pos = pos
  965. self.rgb = [0,0,40]
  966. self.block = block #[10,10]
  967. self.x = pos[0]
  968. self.y = pos[1]
  969. self._x = 0
  970. self._y = 0
  971. self.strobo = time.time()
  972. self.bmp = 250
  973. def dmx_calc(self,data):
  974. #return [130,30,20]
  975. dmx_sub = [30]*10
  976. dmx = self.dmx -1
  977. _dmx_sub = []
  978. if self.dmx >= 0:
  979. dmx = rDMX(self.univ,self.dmx)-1
  980. if dmx+self.ch < len(data):
  981. _dmx_sub = data[dmx:dmx+self.ch]
  982. if _dmx_sub:
  983. dmx_sub = _dmx_sub
  984. dim = dmx_sub[0]/255
  985. r = dmx_sub[1]*dim
  986. g = dmx_sub[2]*dim
  987. b = dmx_sub[3]*dim
  988. r = int(r)
  989. g = int(g)
  990. b = int(b)
  991. self.rgb = [r,g,b]
  992. return self.rgb
  993. def _calc(self,a,b):
  994. A = (self.pos[0]) #+self.block[0]
  995. B = (self.pos[1]) #+self.block[1]
  996. C = self.block[0]-a
  997. D = self.block[1]-b
  998. return A,B,C,D
  999. def POS(self,x=None,y=None,a=0,b=0):
  1000. if type(x) is int:
  1001. self._x=x
  1002. if type(y) is int:
  1003. self._y=y
  1004. A,B,C,D = self._calc(a,b)
  1005. #if NR:
  1006. # C-=1
  1007. # D-=1
  1008. return [int(self._x+A),int(self._y+B),int(C),int(D)]
  1009. class POINTER():
  1010. def __init__(self):
  1011. self.pos = [0,0,0,0]
  1012. self.on = 0
  1013. self.rgb = [0,100,10]
  1014. self._x = 0
  1015. self._y = 0
  1016. self.x = 0
  1017. self.y = 0
  1018. self.fix = Fix(0 ,[999,999],[16,16],0,0,0)
  1019. def row_move(self,x,y):
  1020. self._x = x
  1021. self._y = y
  1022. def move(self,pos):
  1023. self.pos = pos
  1024. self.on = 1
  1025. def cross(self,x,y):
  1026. self.x = x
  1027. self.y = y
  1028. def draw(self,x,y):
  1029. pos = self.pos[:]
  1030. #print("draw",x,y,pos)
  1031. pos[0] += x
  1032. pos[1] += y
  1033. fix_x= self.fix.x
  1034. fix_y= self.fix.y +y
  1035. if 0:# self.on:
  1036. pygame.draw.rect(window,self.rgb,pos)
  1037. # mouse grid posision
  1038. fr = font15.render("{}/{}".format(fix_x+1,fix_y) ,1, (200,200,200))
  1039. _nr = fix_y * _x + fix_x +1
  1040. fr = font15.render("{:02}".format(_nr ) ,1, (200,200,200))
  1041. window.blit(fr,(pos[0]+2,pos[1]+2 ))
  1042. window.blit(fr,(130,1))
  1043. if 1:# lupe / looking-glass / lens
  1044. __t = 60
  1045. f_x = CFG_IN["y2"]+5
  1046. rgb=[255,0,0]
  1047. pos=[400,400,160,160]
  1048. pos=[400,f_x,160,160]
  1049. #pos=[400,400,f_x,f_x]
  1050. draw_box_frame(window,rgb,pos,offset=1)
  1051. r_sub = grab(x=self._x-__t/2,y=self._y-__t/2,w=__t,h=__t)
  1052. if r_sub:
  1053. r_sub = pygame.transform.scale(r_sub,(160,160))
  1054. if r_sub: # target
  1055. window.blit(r_sub, (400,f_x))
  1056. #pos=[400+40,400+40,80,80]
  1057. pos=[400+80,400+80,80,80]
  1058. pos=[400+80,f_x+80,80,80]
  1059. draw_box_frame(window,rgb,pos,offset=3)
  1060. draw_box_frame(window,rgb,pos,offset=2)
  1061. draw_box_frame(window,rgb,pos,offset=0)
  1062. draw_box_frame(window,rgb,pos,offset=1)
  1063. # fix pos
  1064. #txt=str(pos) #"[0, 0, 0, 0]"
  1065. #fr = font15.render(txt ,1, (200,200,200))
  1066. #window.blit(fr,(10,1))
  1067. # pointer
  1068. fr = font15.render("X:{:03}".format(self._x) ,1, (200,200,200))
  1069. window.blit(fr,(10,30))
  1070. fr = font15.render("Y:{:03}".format(self._y) ,1, (200,200,200))
  1071. window.blit(fr,(10,40))
  1072. if 1: #self._x > 30 and self._y > 230:
  1073. # pointer
  1074. _x = self._x-INPUT_START_POS_X
  1075. _y = self._y-INPUT_START_POS_Y
  1076. rgb = [200,200,200]
  1077. if _x < 0:
  1078. rgb = [200,0,0]
  1079. fr = font40.render("X:{:03}".format(_x) ,1, rgb)
  1080. f_x = CFG_IN["y2"]+8
  1081. window.blit(fr,(100,f_x))
  1082. rgb = [200,200,200]
  1083. if _y < 0:
  1084. rgb = [200,0,0]
  1085. fr = font40.render("Y:{:03}".format(_y) ,1, rgb)
  1086. window.blit(fr,(200,f_x))
  1087. p=110
  1088. # crosshair
  1089. self.rgb = [0,0,200]
  1090. pygame.draw.line(window,self.rgb, (self.x-p,self.y) , (self.x-2,self.y),2 )
  1091. #pygame.draw.line(window,self.rgb, (self.x,self.y-p) , (self.x,self.y-2),2 )
  1092. self.rgb = [0,100,200]
  1093. pygame.draw.line(window,self.rgb, (self.x,self.y-p/3) , (self.x,self.y-2),2 )
  1094. self.rgb = [0,200,0]
  1095. pygame.draw.line(window,self.rgb, (self.x+2,self.y) , (self.x+p,self.y),2 )
  1096. pygame.draw.line(window,self.rgb, (self.x,self.y+2) , (self.x,self.y+p),2 )
  1097. self.rgb = [200,0,0]
  1098. pointer = POINTER()
  1099. NR = 0
  1100. running = True
  1101. def event():
  1102. global NR,running
  1103. for event in pygame.event.get():
  1104. #print(event.dict)
  1105. _button = None
  1106. if "button" in event.dict:
  1107. _button = event.dict["button"]
  1108. _state = None
  1109. if "state" in event.dict:
  1110. _state = event.state
  1111. _key = None
  1112. if "key" in event.dict:
  1113. _key = event.key
  1114. _pos = None
  1115. if "pos" in event.dict:
  1116. _pos = event.pos
  1117. _type = None
  1118. if "type" in event.dict:
  1119. _type = event.type
  1120. _type = event.type
  1121. _mod = None
  1122. if "mod" in event.dict:
  1123. _mod = event.mod
  1124. if 0:
  1125. print( " ")
  1126. print( "{:.02f}".format( time.time() - START ))
  1127. print("button -",_button,end="\t| ")
  1128. #print("state -",_state)
  1129. print("pos -",_pos)
  1130. print("type -",_type, end="\t| ")
  1131. print("key -",_key)
  1132. print("mod -",_mod)
  1133. try:
  1134. if _type in [5,1025]:
  1135. if _button == 1:
  1136. NR += 1
  1137. if NR > 1:
  1138. NR = 0
  1139. if _button == 3:
  1140. NR -= 1
  1141. if NR < 0:
  1142. NR = 1
  1143. if _pos:
  1144. posA = _pos
  1145. fix = find_pix(_pos[0]-40,_pos[1]-60+pm_wy)
  1146. if fix:
  1147. #pos = fix.POS(40,60+pm_wy)
  1148. pos = fix.POS() #(CFG_IN["x1"],CFG_IN["y1"])#0,0) #+pm_wy)
  1149. rgb = [0,0,0]
  1150. pointer.move(pos)
  1151. pointer.fix = fix
  1152. else:
  1153. pointer.on = 0
  1154. pointer.row_move(_pos[0],_pos[1])
  1155. pointer.cross(_pos[0],_pos[1])
  1156. if event.type == pygame.VIDEORESIZE:
  1157. window = pygame.display.set_mode((event.w, event.h), pygame.RESIZABLE)
  1158. except Exception as e:
  1159. cprint(e,color="red")
  1160. if event.type==pygame.QUIT:
  1161. global QUIT
  1162. QUIT = 1
  1163. cprint("QUIT",color="red")
  1164. running=False
  1165. #time.sleep(1)
  1166. #sys.exit()
  1167. fps = 0
  1168. fps2 = 0
  1169. frame = 0
  1170. frame2 = 0
  1171. frame_t = time.time()
  1172. frame2_t = time.time()
  1173. IP = "yyy"
  1174. vplay=[]
  1175. vplay1=0
  1176. vplay2=0
  1177. if options.videoplayer:
  1178. try:
  1179. t=options.videoplayer.split(",")
  1180. vplay=t
  1181. vplay1=t[0]
  1182. vplay2=t[1]
  1183. except:pass
  1184. def output_mask(): # oben
  1185. RGB = [0,0,50]
  1186. #RGB = [120,0,0] # test
  1187. start = 0
  1188. # oben
  1189. pygame.draw.rect(window,RGB,[0,start,MAIN_SIZE[0]+200,57]) # background
  1190. # unten
  1191. pygame.draw.rect(window,RGB,[0,start+192,MAIN_SIZE[0]+200,35]) # background
  1192. # links
  1193. pygame.draw.rect(window,RGB,[0,start+0,35,235]) # background
  1194. def input_mask(): # unten
  1195. RGB = [0,0,50]
  1196. #RGB = [120,0,110] # test
  1197. start = 227
  1198. #f_x = CFG_IN["x2"]-50
  1199. f_x = CFG_IN["y2"]+3
  1200. # oben
  1201. pygame.draw.rect(window,RGB,[0,start,MAIN_SIZE[0]+200,7]) # background
  1202. # links
  1203. pygame.draw.rect(window,RGB,[0,start,35,200]) # background
  1204. # unten
  1205. #pygame.draw.rect(window,RGB,[0,start+173,MAIN_SIZE[0]+200,198]) # background
  1206. pygame.draw.rect(window,RGB,[0,f_x,MAIN_SIZE[0]+200,198]) # background
  1207. def draw_main_overlay():
  1208. global fps,fps2
  1209. fr = font15.render("DMX-FPS: {}".format(fps) ,1, (200,0,255))
  1210. window.blit(fr,(10,2))
  1211. fr = font15.render("GUI-FPS : {}".format(fps2) ,1, (200,0,255))
  1212. window.blit(fr,(10,12))
  1213. #fr = font15.render("ip:{}".format(IP) ,1, (200,0,255))
  1214. #window.blit(fr,(100,2))
  1215. fr = font15.render("start-uni: {:}.xx dRGB".format(START_UNIV) ,1, (200,0,255))
  1216. window.blit(fr,(90,2))
  1217. fr = font15.render("gobo_ch1: {}.{:}".format(START_UNIV_A,options.gobo_ch) ,1, (200,0,255))
  1218. window.blit(fr,(210,2))
  1219. fr = font15.render("gobo_ch2: {}.{:}".format(START_UNIV_A,options.gobo_ch2) ,1, (200,0,255))
  1220. window.blit(fr,(210,12))
  1221. for i,v in enumerate(vplay):
  1222. fr = font15.render("v-play{}: {}.{:}".format(i+1,START_UNIV_A,v) ,1, (200,0,255))
  1223. window.blit(fr,(300,2+12*i))
  1224. try:
  1225. global pointer
  1226. # pointer
  1227. fr = font15.render("X:{:03}".format(pointer._x) ,1, (200,200,200))
  1228. window.blit(fr,(10,30))
  1229. fr = font15.render("Y:{:03}".format(pointer._y) ,1, (200,200,200))
  1230. window.blit(fr,(10,40))
  1231. except Exception as e:
  1232. print("Overlay err:",e)
  1233. def draw_marker():
  1234. # kennlinie linker rand
  1235. # limit marker INPUT AREA
  1236. rgb = [0,127,255] # orange
  1237. for CFG_OUTx in CFG_OUT: #["y1"]
  1238. f_x = CFG_OUTx["y1"]
  1239. pygame.draw.line(window,rgb,[0,f_x],[20,f_x])
  1240. f_x = CFG_OUTx["y2"]
  1241. pygame.draw.line(window,rgb,[0,f_x],[20,f_x])
  1242. if CFG_OUT:
  1243. f_x = CFG_OUT[0]["y1"]
  1244. for i,v in enumerate("OUTPUT"):
  1245. fr = font15.render(v ,1, rgb) #(200,0,255))
  1246. if v == "I":
  1247. window.blit(fr,(10+2,f_x+i*15+15))
  1248. else:
  1249. window.blit(fr,(10,f_x+i*15+15))
  1250. # kennlinie linker rand
  1251. # limit marker INPUT AREA
  1252. rgb = [255,127,0] # orange
  1253. f_x = CFG_IN["y1"]
  1254. pygame.draw.line(window,rgb,[0,f_x],[20,f_x])
  1255. f_x = CFG_IN["y2"]
  1256. pygame.draw.line(window,rgb,[0,f_x],[20,f_x])
  1257. f_x = CFG_IN["y1"]
  1258. for i,v in enumerate("INPUT"):
  1259. fr = font15.render(v ,1, rgb) #(200,0,255))
  1260. if v == "I":
  1261. window.blit(fr,(10+2,f_x+i*15+15))
  1262. else:
  1263. window.blit(fr,(10,f_x+i*15+15))
  1264. def draw_box_frame(window,rgb,pos,offset=0):
  1265. p1 = [pos[0],pos[1]]
  1266. p2 = [pos[0]+pos[2],pos[1]+pos[3]]
  1267. o = offset
  1268. _p1 = [p1[0]-o,p1[1]-o]
  1269. _p2 = [p1[0]-o,p2[1]+o]
  1270. pygame.draw.line(window,rgb,_p1,_p2) # left
  1271. _p1 = [p2[0]+o,p2[1]+o]
  1272. pygame.draw.line(window,rgb,_p1,_p2) # bottom
  1273. _p2 = [p2[0]+o,p1[1]-o]
  1274. pygame.draw.line(window,rgb,_p1,_p2) # right
  1275. _p1 = [p1[0]-o,p1[1]-o]
  1276. pygame.draw.line(window,rgb,_p1,_p2) # top
  1277. def draw_frame(window,rgb,p1,p2,offset=0):
  1278. o = offset
  1279. _p1 = [p1[0]-o,p1[1]-o]
  1280. _p2 = [p1[0]-o,p2[1]+o]
  1281. #pygame.draw.line(window,rgb,_p1,_p2) # left
  1282. _p1 = [p2[0]+o,p2[1]+o]
  1283. pygame.draw.line(window,rgb,_p1,_p2) # bottom
  1284. _p2 = [p2[0]+o,p1[1]-o]
  1285. #pygame.draw.line(window,rgb,_p1,_p2) # right
  1286. _p1 = [p1[0]-o,p1[1]-o]
  1287. pygame.draw.line(window,rgb,_p1,_p2) # top
  1288. def calc_fps():
  1289. global fps,frame,frame_t
  1290. t = time.time()
  1291. if frame_t+1 < t:
  1292. fps = frame #frame_t- t #frame
  1293. frame = 1
  1294. frame_t = time.time()
  1295. def calc_fps2():
  1296. global fps2,frame2,frame2_t
  1297. t = time.time()
  1298. if frame2_t+0.1 < t:
  1299. fps2 = frame2*10 #frame_t- t #frame
  1300. frame2 = 1
  1301. frame2_t = t #time.time()
  1302. TEXT_BLOCK = []
  1303. def _create_text_block():
  1304. print("======== CREATE NEW TEXT FILE !!",text_file)
  1305. f = open(text_file,"w")
  1306. for i in range(10):
  1307. f.write("TEXT {}\n".format(i+1))
  1308. f.close()
  1309. def open_text_block():
  1310. print("======== OPEN TEXT FILE !!",text_file)
  1311. _lines = []
  1312. try:
  1313. f = open(text_file,"r")
  1314. _lines = f.readlines()
  1315. f.close()
  1316. except FileNotFoundError as e:
  1317. print("TEXT",e)
  1318. _create_text_block()
  1319. if len(_lines) <= 0:
  1320. _create_text_block()
  1321. lines = []
  1322. for l in _lines:
  1323. #print(">> ",l.strip())
  1324. lines.append(l.strip())
  1325. if len(lines) <= 10:
  1326. for i in range(10-len(lines)):
  1327. lines.append("LINE ERROR")
  1328. return lines
  1329. TEXT_BLOCK = open_text_block()
  1330. TEXT_BLOCK_TIME = time.time()
  1331. # video medialist
  1332. MEDIALIST = []
  1333. def open_medialist():
  1334. print("======== OPEN MEDIALIST DIR !!",media_list)
  1335. if not os.path.isdir(media_list):
  1336. os.system("mkdir -p {}".format(media_list))
  1337. _lines = os.listdir(media_list)
  1338. _lines.sort()
  1339. lines = ['']*25
  1340. i=0
  1341. for l in _lines:
  1342. l = l.strip()
  1343. if "_" in l:
  1344. ll = l.split("_",1)
  1345. #print(">> ",ll)
  1346. try:
  1347. lll = int(ll[0])
  1348. lines[lll] = l
  1349. except:pass
  1350. if len(lines) <= 10:
  1351. for i in range(10-len(lines)):
  1352. lines.append("")#"LINE ERROR")
  1353. return lines
  1354. MEDIALIST_TIME = time.time()
  1355. MEDIALIST = open_medialist()
  1356. # ===== GUI =========
  1357. def draw_circle(surface,color, pos, radius):
  1358. x,y=pos
  1359. pygame.gfxdraw.aacircle(surface, int(x), int(y), radius-1, color)
  1360. pygame.gfxdraw.filled_circle(surface, int(x), int(y), radius-1, color)
  1361. def rDMX(univ,dmx):
  1362. return univ*512+dmx
  1363. def generate_grid(mapping=0):
  1364. _log = []
  1365. #if PIXEL_MAPPING:
  1366. # log = open(grid_file,"w")
  1367. head = "i,univ,dmx,x,y,ch\n"
  1368. head = "i,univ,dmx,ch\n"
  1369. head = "univ,dmx,x,y,ch\n"
  1370. head = "nr,id,info\n"
  1371. print("csv:",head)
  1372. _log.append(head)
  1373. dmx = 1-1
  1374. ch = 4
  1375. y=0
  1376. x=0
  1377. for i in range((_y)*(_x)):
  1378. #if x > _x and i%_x == 0:
  1379. if x > 8 and i%8 == 0:
  1380. #print("--> -->")
  1381. x=0
  1382. y+=1
  1383. _univ = int(dmx/512)
  1384. _dmx = dmx - (_univ)*512
  1385. pos=[x,y]
  1386. line="{},{},x\n".format(i+1,i+1)
  1387. _log.append(line)
  1388. dmx += ch
  1389. x+=1
  1390. if mapping and PIXEL_MAPPING:
  1391. print("CREATE NEW PIXELMAP FILE !!",grid_file)
  1392. log = open(grid_file,"w")
  1393. log.writelines(_log)
  1394. log.close()
  1395. return _log[:] #GRID
  1396. def init_grid(mapping=0,_x=4,_y=4,_xp=0,_yp=0,start=0,name="init_gird"):
  1397. if mapping and PIXEL_MAPPING:
  1398. try:
  1399. log = open(grid_file,"r")
  1400. except:
  1401. generate_grid(mapping=mapping)
  1402. log = open(grid_file,"r")
  1403. lines = log.readlines()
  1404. else:
  1405. lines = generate_grid()
  1406. GRID = []
  1407. y=0
  1408. x=0
  1409. print("CSV header",[lines[0]],[PIXEL_MAPPING,"len:",len(lines),"start:",start,name])
  1410. for i,line in enumerate(lines[1+start:]): #exclude first line
  1411. #print("rcsv",[line])
  1412. line = line.strip()
  1413. line = line.split(",") # csv
  1414. if i >= _x and i%_x == 0:
  1415. x=0
  1416. y+=1
  1417. if y >= _y:
  1418. break
  1419. _id = int(line[1])
  1420. pos = [x+_xp,y+_yp]
  1421. f = Fix(_id,pos,block) #pos,univ,dmx,ch)
  1422. GRID.append(f)
  1423. x+=1
  1424. return GRID
  1425. def find_pix(x,y):
  1426. global GRID
  1427. for fix in GRID:
  1428. X = 0
  1429. Y = 0
  1430. pos = fix.POS()
  1431. if x > pos[0] and x < pos[0]+pos[2]:
  1432. X = 1
  1433. if y > pos[1] and y < pos[1]+pos[3]:
  1434. Y = 1
  1435. if X and Y:
  1436. return fix
  1437. GRID = []
  1438. GRID_A = []
  1439. NR = 0
  1440. START_UNIV_A=1
  1441. START_UNIV=2
  1442. if options.start_univ:
  1443. try:
  1444. START_UNIV=int(options.start_univ)
  1445. except Exception as e:
  1446. print("Exception START UNIV",e)
  1447. gobo_ch=1
  1448. if options.gobo_ch:
  1449. try:
  1450. gobo_ch=int(options.gobo_ch)
  1451. except Exception as e:
  1452. print("Exception gobo_ch",e)
  1453. if gobo_ch <= 0:
  1454. gobo_ch = 1
  1455. def grab(x=55,y=55,w=60,h=60):
  1456. crop = None
  1457. rect = pygame.Rect(x, y, w, h)
  1458. try:
  1459. sub = window.subsurface(rect)
  1460. crop = pygame.Surface((w,h))
  1461. crop.blit(sub, (0,0))
  1462. except ValueError as e:
  1463. #cprint("grab():",e,x,y,w,h,color="red")
  1464. pass
  1465. return crop
  1466. vpu_wall_txt="""---,quelle,,---,ziel,---,---
  1467. out,x,y,ang,row,col,info
  1468. Wall1,0,0,0,1,1,
  1469. Wall1,0,0,0,2,2,
  1470. Wall1,0,0,0,3,3,
  1471. Wall1,0,0,0,4,4,
  1472. Wall1,0,0,0,5,5,
  1473. Wall1,0,0,0,6,6,
  1474. Wall1,0,0,0,7,7,
  1475. ,,,,,,
  1476. Wall2,0,0,0,4,1,----
  1477. Wall2,0,0,0,5,2,
  1478. Wall2,4,4,0,6,3,
  1479. Wall2,0,0,0,7,4,
  1480. Wall2,0,0,0,8,5,
  1481. Wall2,0,0,0,9,6,
  1482. ,,,,,,
  1483. ,,,,,,
  1484. Wall3,64,48,0,12,1,----
  1485. Wall3,64,64,0,12,2,
  1486. Wall3,64,80,0,12,3,
  1487. Wall3,64,96,0,12,4,
  1488. Wall3,64,112,0,12,5,
  1489. Wall3,64,128,0,12,6,"""
  1490. def create_vpu_wall_conf():
  1491. f=open(vpu_wall_conf_file,"w")
  1492. f.write(vpu_wall_txt)
  1493. f.close()
  1494. print("CREATE VPU CONFIG !")
  1495. wall_data = []
  1496. _last_wall_config_time = time.time()
  1497. def read_wall_pix(init=0):
  1498. global _last_wall_config_time
  1499. global wall_data, NR
  1500. grid = []
  1501. #if not NR and init==0:
  1502. # return
  1503. ok = 0
  1504. if init:
  1505. ok = 1
  1506. if NR:
  1507. if time.time()-_last_wall_config_time > 3:
  1508. ok = 1
  1509. else:
  1510. if time.time()-_last_wall_config_time > 10:
  1511. ok = 1
  1512. if not ok:
  1513. return
  1514. print("read_wall_pix",vpu_wall_conf_file)
  1515. _last_wall_config_time = time.time()
  1516. if not os.path.isfile(vpu_wall_conf_file):
  1517. create_vpu_wall_conf()
  1518. f=open(vpu_wall_conf_file,"r")
  1519. lines = f.readlines()
  1520. for i,line in enumerate(lines):
  1521. line = line.strip()
  1522. if not line:
  1523. continue
  1524. line = line.split(",")
  1525. if not line[0]:
  1526. continue
  1527. #print(i,line)
  1528. if len(line) >= 3:
  1529. _l = []
  1530. for i in line:
  1531. try:
  1532. _l.append(int(i))
  1533. except Exception as e:
  1534. _l.append(i)
  1535. grid.append(_l)
  1536. #for i,v in enumerate(grid):
  1537. # print(i,v)
  1538. wall_data = grid
  1539. read_wall_pix(init=1)
  1540. def reshape2(GRID,GRID_OUT,_x,_y,name="GRID_Z"):
  1541. global W_ANG
  1542. _w = 16
  1543. _h = 16
  1544. from_x_min = INPUT_START_POS_X
  1545. from_y_min = INPUT_START_POS_Y
  1546. target_x = 40 # min
  1547. target_y = 60 # min
  1548. ang=0
  1549. #read_block_pix()
  1550. read_wall_pix()
  1551. _wall_data = wall_data[:]
  1552. for i,_wall in enumerate(_wall_data):
  1553. #print(_wall)
  1554. if len(_wall) <=6:
  1555. continue
  1556. try:
  1557. if type(_wall[1]) is str:
  1558. continue
  1559. if type(_wall[2]) is str:
  1560. continue
  1561. if type(_wall[3]) is str:
  1562. continue
  1563. if type(_wall[4]) is str:
  1564. continue
  1565. if type(_wall[5]) is str:
  1566. continue
  1567. from_x=from_x_min+_wall[1]#*_w
  1568. from_y=from_y_min+_wall[2]#*_h
  1569. _a= _wall[3]
  1570. ang=0
  1571. if _a < 0:
  1572. ang=0
  1573. elif _a > 0 and _a <= 90:
  1574. ang = 90
  1575. elif _a > 90 and _a <= 180:
  1576. ang = 180
  1577. elif _a > 180 and _a <= 270:
  1578. ang = 270
  1579. x_k = _wall[4]
  1580. y_k = _wall[5]
  1581. target_x=40+(x_k-1)*_w
  1582. target_y=60+(y_k-1)*_h
  1583. sub = grab(from_x,from_y,_w,_h)
  1584. key="{}:{}".format(x_k,y_k)
  1585. W_ANG[key] = ang
  1586. if sub:
  1587. #sub = grab(from_x,from_y,_w,_h)
  1588. sub = pygame.transform.rotate(sub,ang)
  1589. window.blit(sub,(target_x,target_y))
  1590. except Exception as e:
  1591. cprint(" ",_wall,color="red")
  1592. cprint("WALL err:",e,color="red")
  1593. def reload_grid():
  1594. print("==== reload_grid")
  1595. global GRID
  1596. global GRID_A
  1597. try:
  1598. GRID = init_grid(_x=_x,_y=_y,name="GRID") #init_gird()
  1599. GRID_A = init_grid(_x=8,_y=16,mapping=1,name="GRID_A") #init_gird()
  1600. except Exception as e:
  1601. cprint("Except: grid re init",e,color="red")
  1602. W_ANG = {}
  1603. def draw_kachel_nr(): #GRID,_x=0,_y=0):
  1604. if not NR:
  1605. return
  1606. n = 0
  1607. _max_row = 40
  1608. _y=0
  1609. for i in range(8): # ROW / ZEILEN -> ->
  1610. _x=0
  1611. OUT_COUNT = len(CFG_OUT)
  1612. for j in range(8*OUT_COUNT): # COLUMS / SPALTEN | |
  1613. #pygame.draw.rect(window,[10,20,10],[40+_x+2,60+_y+2,14,9]) #background
  1614. pygame.draw.rect(window,[10,20,10],[6,6,14,9]) #background
  1615. _j=j
  1616. key="{}:{}".format(_j+1,i+1)
  1617. fr = font12.render(key,1, (200,200,55))
  1618. window.blit(fr,(6,6))
  1619. #window.blit(fr,(40+_x+2,60+_y+2))
  1620. ang = W_ANG.get(key,0)
  1621. sub = grab(6,6,14,9)
  1622. if sub: # rotate nr label
  1623. sub = pygame.transform.rotate(sub,ang)
  1624. if ang == 270: # pos compensation
  1625. window.blit(sub,(40+_x+6,60+_y+1))
  1626. elif ang == 180:# pos compensation
  1627. window.blit(sub,(40+_x+1,60+_y+6))
  1628. else:
  1629. window.blit(sub,(40+_x+1,60+_y+1))
  1630. #if ang != 0:
  1631. # print("W_ANG",key,ang)
  1632. _x+=16 # pix
  1633. _y +=16 # pix
  1634. def draw_counter(COUNTER):
  1635. for count in COUNTER:
  1636. cpan = 0
  1637. ctilt = 0
  1638. cr=255
  1639. cg=255
  1640. cb=255
  1641. csize=10
  1642. cdim=0
  1643. k = "DIM"
  1644. if k in count:
  1645. cdim = int(count[k])
  1646. k = "RED"
  1647. if k in count:
  1648. cr = int(count[k])
  1649. k = "GREEN"
  1650. if k in count:
  1651. cg = int(count[k])
  1652. k = "BLUE"
  1653. if k in count:
  1654. cb = int(count[k])
  1655. k = "SIZE"
  1656. if k in count:
  1657. csize = int(count[k]) #/60*p)
  1658. if csize < 5:
  1659. csize = 5
  1660. k = "PAN"
  1661. if k in count:
  1662. cpan = int(count[k])/255*(block[0] *(_x))
  1663. #cpan = int(cpan * 1.2)
  1664. cpan = int(cpan)
  1665. k = "TILT"
  1666. if k in count:
  1667. ctilt = int(count[k])/255*(block[1] *(_y))
  1668. #ctilt = int(cpan * 1.2)
  1669. ctilt = int(ctilt)
  1670. ddim = cdim/255
  1671. if "DIM" in count and count["DIM"] > 0:
  1672. tmp_font = pygame.font.SysFont("freemonobold",int(p/100*csize))
  1673. rgb =(int(cr*ddim),int(cg*ddim),int(cb*ddim),cdim)
  1674. _sec = count["_SEC"]
  1675. try:
  1676. _sec = int(count["_SEC"])
  1677. except:
  1678. pass
  1679. if type(_sec) is int:
  1680. #print(_sec)
  1681. if _sec <= 60:
  1682. fr = tmp_font.render("{:0}".format(_sec) ,1, rgb)
  1683. else:
  1684. _xx = time.strftime("%M:%S",time.localtime(_sec))
  1685. #print("_xx",_xx)
  1686. fr = tmp_font.render("{}".format(_xx) ,1, rgb)
  1687. else:
  1688. fr = tmp_font.render("{}".format((count["_SEC"])) ,1, rgb)
  1689. fr_r = fr.get_rect(center=(40+cpan-(block[0]),60+ctilt+pm_wy))
  1690. pygame.draw.rect(window,[0,0,0],fr_r)
  1691. window.blit(fr,fr_r)
  1692. def video_overlay_draw(wn=None,lines=["line1","line2"],i=0):
  1693. # overlay
  1694. pygame.draw.rect(wn,[255,200,0],[5,MAIN_SIZE[1]-(i+1)*35,380,28])
  1695. font15 = pygame.font.SysFont("freemonobold",17)
  1696. rgb = [255,100,0]
  1697. pygame.draw.rect(wn,rgb,[5,MAIN_SIZE[1]-(i+1)*35,200,13])
  1698. _line = lines[0]
  1699. fr = font15.render(_line ,1, (0,0,0))
  1700. wn.blit(fr,(10,MAIN_SIZE[1]-(i+1)*35))
  1701. _line = lines[1]
  1702. fr = font15.render(_line ,1, (0,0,0))
  1703. wn.blit(fr,(10,MAIN_SIZE[1]-(i+1)*35+15))
  1704. #_line = lines[2]
  1705. #fr = font15.render(_line ,1, (0,0,0))
  1706. #wn.blit(fr,(75,MAIN_SIZE[1]-(i+1)*35+15))
  1707. def draw_all_video_overlay(VIDEO):
  1708. global videplayer
  1709. i=0
  1710. for count in VIDEO:
  1711. video1 = videoplayer[i]
  1712. #video1.overlay_draw(window,"run") # old
  1713. lines = video1._overlay_text()
  1714. video_overlay_draw(wn=window,lines=lines,i=i)
  1715. i += 1
  1716. def del_all_video():
  1717. global videplayer
  1718. i = 0
  1719. print()
  1720. cprint("del_all_video")
  1721. for video in videoplayer:
  1722. cprint("- del video",video)
  1723. video._del()
  1724. def draw_all_video(VIDEO):
  1725. global videplayer
  1726. i = 0
  1727. # set DMX-VALUE to videoplayer Object
  1728. for count in VIDEO:
  1729. cpan = 0
  1730. ctilt = 0
  1731. cr=255
  1732. cg=255
  1733. cb=255
  1734. csize=10
  1735. cang=0
  1736. cdim=0
  1737. video1 = videoplayer[i]
  1738. k = "VIDEO"
  1739. if k in count:
  1740. #video1.select_video(count[k])
  1741. if type(count[k]) is str:
  1742. cprint("ERR count[k] is str not int !")
  1743. continue
  1744. play_nr = int(count[k]/10)
  1745. if play_nr != video1._media_nr:
  1746. print( "+ + + + + + + + + + +", play_nr , video1._media_nr ,str(video1))
  1747. _vid = video1._id
  1748. _cdmx = video1.dmx
  1749. del_video1 = video1
  1750. video1 = PixelMedia(cdmx,_id=_vid)
  1751. video1.select_video(count[k])
  1752. videoplayer[i] = video1
  1753. del_video1._del()
  1754. del del_video1
  1755. k = "DIM"
  1756. if k in count:
  1757. cdim = int(count[k])
  1758. #video1.dim = cdim
  1759. #if i == 0:
  1760. # print(i,cdim)
  1761. k = "ANG"
  1762. if k in count:
  1763. cang = int(count[k])
  1764. k = "SIZE"
  1765. if k in count:
  1766. csize = int(count[k]/16*p)
  1767. if csize < 5:
  1768. csize = 5
  1769. k = "PAN"
  1770. cpan_max = block[0] *(_x) #+block[0]
  1771. if k in count:
  1772. cpan = int(count[k]) / 255*cpan_max
  1773. cpan = int(cpan)
  1774. k = "TILT"
  1775. ctilt_max = block[1] *(_y) #+block[1]
  1776. if k in count:
  1777. ctilt = int(count[k]) / 255*ctilt_max
  1778. ctilt = int(ctilt)
  1779. k = "_reset"
  1780. if k in count:
  1781. if count[k]:
  1782. count[k] = 0
  1783. video1.restart()
  1784. k = "_RUN"
  1785. if k in count:
  1786. video1._run = count[k]
  1787. #video1.pos
  1788. #video1.x=40+0+cpan
  1789. #video1.y=60+0+pm_wy+ctilt
  1790. x=CFG_IN["x1"]+cpan
  1791. y=CFG_IN["y1"]+ctilt
  1792. scale = int((csize))
  1793. angle = int(360-(cang))
  1794. video1.update_dmx(x,y,scale,angle,cdim)
  1795. if cdim:
  1796. video1.next()
  1797. i += 1
  1798. # draw
  1799. i=0
  1800. for count in VIDEO:
  1801. video1 = videoplayer[i]
  1802. video1.draw(window) #,x=0,y=0)
  1803. i+=1
  1804. def counter_dmx(COUNTER,dataA):
  1805. for count in COUNTER:
  1806. cDMX=count["DMX"]-1
  1807. try:
  1808. count["DIM"] = dataA[cDMX]
  1809. count["PAN"] = dataA[cDMX+1]
  1810. count["TILT"] = dataA[cDMX+2]
  1811. count["CONTROL"] = dataA[cDMX+3]
  1812. count["SIZE"] = dataA[cDMX+4]
  1813. count["SEC"] = dataA[cDMX+5]
  1814. count["RED"] = dataA[cDMX+6]
  1815. count["GREEN"] = dataA[cDMX+7]
  1816. count["BLUE"] = dataA[cDMX+8]
  1817. if count["CONTROL"] >= 10 and count["CONTROL"] < 20: # RESET COUNTER
  1818. count["_RUN"] = 0
  1819. count["_pause"] = 0
  1820. count["_time"] = time.time()
  1821. count["_start"] = int(count["SEC"])
  1822. count["_SEC"] = int(count["_start"])
  1823. if count["CONTROL"] >= 20 and count["CONTROL"] < 30: # PAUSE COUNTER
  1824. count["_RUN"] = 0
  1825. if count["CONTROL"] >= 30 and count["CONTROL"] < 40: # PLAY COUNTER
  1826. count["_RUN"] = 1
  1827. if count["_RUN"]:
  1828. try:
  1829. if count["_pause"] > 0:
  1830. count["_time"] += time.time()-count["_pause"]
  1831. count["_pause"] = 0
  1832. count["_SEC"] = int(count["_start"] - (time.time() - count["_time"]))
  1833. except Exception as e:
  1834. pass
  1835. else:
  1836. if count["_pause"] == 0:
  1837. count["_pause"] = time.time()
  1838. if type(count["_SEC"]) is int:
  1839. if count["_SEC"] < 0:
  1840. count["_SEC"] = 0
  1841. for ti in range(10):
  1842. #print(ti,(ti+6)*10)
  1843. if count["CONTROL"] >= (ti+6)*10 and count["CONTROL"] < (ti+7)*10:
  1844. count["_SEC"] = "----" #text 1
  1845. try:
  1846. count["_SEC"] = TEXT_BLOCK[ti]
  1847. except Exception as e:
  1848. pass
  1849. if count["CONTROL"] >= 250 and count["CONTROL"] < 256:
  1850. count["_SEC"] = "DMX:{}-{}".format(cDMX+1,cDMX+8+1)
  1851. except Exception as e:
  1852. cprint("EXC FUNC",e,count,color="red")
  1853. #print(count)
  1854. def video_dmx(VIDEO,dataA):
  1855. for count in VIDEO:
  1856. cDMX=count["DMX"]-1
  1857. try:
  1858. count["DIM"] = dataA[cDMX]
  1859. count["PAN"] = dataA[cDMX+1]
  1860. count["TILT"] = dataA[cDMX+2]
  1861. count["CONTROL"] = dataA[cDMX+3]
  1862. if count["CONTROL"] >= 10 and count["CONTROL"] < 20:
  1863. count["_reset"] = 1
  1864. if count["CONTROL"] >= 20 and count["CONTROL"] < 30:
  1865. if count["_RUN"] == 1:
  1866. print( "_RUN:0",count["DMX"]-1)
  1867. count["_RUN"] = 0
  1868. if count["CONTROL"] >= 30 and count["CONTROL"] < 40:
  1869. if count["_RUN"] == 0:
  1870. print( "_RUN:1",count["DMX"]-1)
  1871. count["_RUN"] = 1
  1872. count["SIZE"] = dataA[cDMX+4]#*2
  1873. count["SEC"] = dataA[cDMX+5]
  1874. #count["RED"] = dataA[cDMX+6]
  1875. count["VIDEO"] = dataA[cDMX+6]
  1876. #count["GREEN"] = dataA[cDMX+7]
  1877. count["ANG"] = (int(dataA[cDMX+7])/255*360)
  1878. #count["BLUE"] = dataA[cDMX+8]
  1879. except Exception as e:
  1880. cprint("VIDEOPLAYER EXCEPT FUNC",e,count,color="red")
  1881. #print(count)
  1882. def read_dmx_data(ip,ips):
  1883. ip = select_ip(ips,univ=START_UNIV)
  1884. IP = ip
  1885. data = read_dmx(ip)
  1886. ip = select_ip(ips,univ=START_UNIV+1)
  1887. data3 = read_dmx(ip)
  1888. data.extend(data3)
  1889. ip = select_ip(ips,univ=START_UNIV+2)
  1890. data3 = read_dmx(ip)
  1891. data.extend(data3)
  1892. ip = select_ip(ips,univ=START_UNIV+3)
  1893. data3 = read_dmx(ip)
  1894. data.extend(data3)
  1895. if options.dual_vpu:
  1896. ip = select_ip(ips,univ=START_UNIV+4)
  1897. data3 = read_dmx(ip)
  1898. data.extend(data3)
  1899. ip = select_ip(ips,univ=START_UNIV+5)
  1900. data3 = read_dmx(ip)
  1901. data.extend(data3)
  1902. return data
  1903. def set_pos(GRID,_x=0,_y=0):
  1904. for fix in GRID:
  1905. pos = fix.POS(_x,_y)#40,60+pm_wy)
  1906. for subfix in fix.sub_fix:
  1907. #subfix.dmc_calc(data)
  1908. spos = subfix.POS(_x,_y)
  1909. def draw_gobo(GRID,data,_x=0,_y=0):
  1910. i = 0
  1911. dmx = 1
  1912. h = 1
  1913. v = 1
  1914. for fix in GRID:
  1915. rgb = fix.rgb
  1916. pos = fix.POS() #CFG_IN["x1"],CFG_IN["y1"])
  1917. pygame.draw.rect(window,rgb,pos)
  1918. # DRAW SUB-FIXTURE
  1919. j = 0
  1920. for subfix in fix.sub_fix:#calc(data):
  1921. subfix.dmx_calc(data)
  1922. spos = subfix.POS() #_x,_y)#+pm_wy)
  1923. srgb = subfix.rgb
  1924. if FUNC > 10 and FUNC <= 20: # big dot
  1925. draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/2))
  1926. elif FUNC > 20 and FUNC <= 30:#small dot
  1927. draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  1928. elif FUNC > 30 and FUNC <= 40:#donut
  1929. draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/2))
  1930. draw_circle(window,[0,0,0],(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  1931. elif FUNC > 40 and FUNC <= 50: # rec with hole
  1932. pygame.draw.rect(window,srgb,spos)
  1933. draw_circle(window,[0,0,0],(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  1934. elif FUNC > 50 and FUNC <= 60: # rec with big hole
  1935. pygame.draw.rect(window,srgb,spos)
  1936. draw_circle(window,[0,0,0],(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/2))
  1937. elif FUNC > 60 and FUNC <= 70: # rec with donat
  1938. pygame.draw.rect(window,srgb,spos)
  1939. draw_circle(window,[0,0,0],(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/2))
  1940. draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  1941. elif FUNC > 70 and FUNC <= 80: # rec boarder
  1942. pygame.draw.rect(window,srgb,[spos[0]+1,spos[1]+1,spos[2]-2,spos[3]-2])
  1943. elif FUNC > 80 and FUNC <= 90: # rec big boarder
  1944. pygame.draw.rect(window,srgb,[spos[0]+2,spos[1]+2,spos[2]-4,spos[3]-4])
  1945. elif FUNC > 90 and FUNC <= 100: # rec thin line
  1946. pygame.draw.rect(window,srgb,spos)
  1947. pygame.draw.rect(window,[0,0,0],[spos[0]+1,spos[1]+1,spos[2]-2,spos[3]-2])
  1948. elif FUNC > 100 and FUNC <= 110: # rec big line
  1949. pygame.draw.rect(window,srgb,spos)
  1950. pygame.draw.rect(window,[0,0,0],[spos[0]+2,spos[1]+2,spos[2]-4,spos[3]-4])
  1951. elif FUNC > 110 and FUNC <= 120: # rec with dot
  1952. pygame.draw.rect(window,srgb,spos)
  1953. pygame.draw.rect(window,[0,0,0],[spos[0]+1,spos[1]+1,spos[2]-2,spos[3]-2])
  1954. draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  1955. elif FUNC > 120 and FUNC <= 130: # rec inline
  1956. pygame.draw.rect(window,srgb,[spos[0]+2,spos[1]+2,spos[2]-4,spos[3]-4])
  1957. pygame.draw.rect(window,[0,0,0],[spos[0]+3,spos[1]+3,spos[2]-6,spos[3]-6])
  1958. elif FUNC > 130 and FUNC <= 140: # 3 dot (heart)
  1959. draw_circle(window,srgb,(spos[0]+int(spos[2]/2)+2,spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  1960. draw_circle(window,srgb,(spos[0]+int(spos[2]/2)-2,spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  1961. draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)+2),int(spos[3]/3.5))
  1962. else:
  1963. pygame.draw.rect(window,srgb,spos)
  1964. i += 1
  1965. def grid_label(GRID,_x=0,_y=0):
  1966. for fix in GRID:
  1967. #pos = fix.POS(_x,_y)
  1968. pos = fix.POS() #CFG_IN["x1"],CFG_IN["y1"])
  1969. rgb = fix.rgb
  1970. # draw row/col grid number
  1971. if pos[0] == 0:
  1972. fr = font12.render("{}".format(pos[1]+1) ,1, (200,200,200))
  1973. window.blit(fr,(10,pos[1]+3 ))
  1974. if pos[1] == 0:
  1975. fr = font12.render("{}".format(pos[0]+1) ,1, (200,200,200))
  1976. window.blit(fr,(pos[0]+2,35 ))
  1977. def out_frame():
  1978. rgb = [255,255,0]
  1979. rgb = [255,0,0]
  1980. for CFG_OUTx in CFG_OUT:
  1981. if CFG_OUTx["on"]:
  1982. rgb = [255,0,0]
  1983. p1 = CFG_OUTx["p1"][:]
  1984. p2 = CFG_OUTx["p2"][:]
  1985. p1[0] += 4
  1986. p2[0] -= 4
  1987. draw_frame(window,rgb,p1,p2,offset=3)
  1988. ips=[]
  1989. dataA=[]
  1990. data=[]
  1991. def dmx_raw():
  1992. global frame
  1993. frame += 1
  1994. global ips,dataA,data
  1995. ips = read_index()
  1996. # ----
  1997. ip = select_ip(ips,univ=1) # univ 1 gobo
  1998. dataA = read_dmx(ip)
  1999. # ----
  2000. data = read_dmx_data(ip,ips)
  2001. if options.countdown:
  2002. counter_dmx(COUNTER,dataA)
  2003. if len(VIDEO) > 0:
  2004. video_dmx(VIDEO,dataA)
  2005. return ips,dataA,data
  2006. def dmx_loop():
  2007. while 1:
  2008. dmx_raw()
  2009. time.sleep(1/40) # fast high cpu
  2010. if QUIT:
  2011. break
  2012. thread.start_new_thread(dmx_loop,())
  2013. def draw_output_label(CFG,value,dmx="0.0",name="GRID_XX"):
  2014. dim_raw = value
  2015. pygame.draw.rect(window,[5,5,155],[CFG["x1"]+2,CFG["y2"]+5,CFG["w"]-6,25]) # background
  2016. # GRID_A1_DIM_LABEL
  2017. fr = font15.render("Name: "+name,1, (255,255,255))
  2018. fr_r = fr.get_rect(center=(int(wx/2),int(0+pm_wy-p*0-10)))
  2019. window.blit(fr,(CFG["x1"]+4,CFG["y2"]+5))
  2020. fr = font15.render("inv-dim: "+str(dim_raw) ,1, (255,255,255))
  2021. fr_r = fr.get_rect(center=(int(wx/2),int(0+pm_wy-p*0-10)))
  2022. window.blit(fr,(CFG["x1"]+64,CFG["y2"]+20))
  2023. fr = font15.render("dmx: {}.{}".format(START_UNIV_A,dmx) ,1, (255,255,255))
  2024. window.blit(fr,(CFG["x1"]+4,CFG["y2"]+20))
  2025. def _check_dim(_dim):
  2026. dim = 255
  2027. try:
  2028. dim = int(_dim)
  2029. if dim > 255:
  2030. dim = 255
  2031. if dim <=0:
  2032. dim = 0
  2033. except:
  2034. pass
  2035. return dim
  2036. def _GRID_DIM(dim,x,y):
  2037. dim = _check_dim(dim)
  2038. dim_raw = dim*-1
  2039. s = pygame.Surface((p*8,p*8)) # the size of your rect
  2040. s.set_alpha(dim) # alpha level
  2041. s.fill((0,0,0)) # this fills the entire surface
  2042. window.blit(s, (x,y))
  2043. def GRID_DIM():
  2044. for CFG in CFG_OUT:
  2045. dim_ch = int(CFG["DMX-CH"])
  2046. dim = dataA[dim_ch-1]
  2047. _GRID_DIM(dim,x=CFG["x1"],y=CFG["y2"]-p*8)
  2048. draw_output_label(CFG,dim,dim_ch,name=CFG["name"])
  2049. def cvImageToSurface(cvImage):
  2050. if cvImage.dtype.name == 'uint16':
  2051. cvImage = (cvImage / 256).astype('uint8')
  2052. size = cvImage.shape[1::-1]
  2053. if len(cvImage.shape) == 2:
  2054. cvImage = np.repeat(cvImage.reshape(size[1], size[0], 1), 3, axis = 2)
  2055. format = 'RGB'
  2056. else:
  2057. format = 'RGBA' if cvImage.shape[2] == 4 else 'RGB'
  2058. cvImage[:, :, [0, 2]] = cvImage[:, :, [2, 0]]
  2059. surface = pygame.image.frombuffer(cvImage.flatten(), size, format)
  2060. return surface.convert_alpha() if format == 'RGBA' else surface.convert()
  2061. def create_img_meta():
  2062. out = {}
  2063. #40 235
  2064. out["pos"] = (0,0) # x,y
  2065. out["ipos"] = (0,0) # x,y
  2066. out["scale"] = 50
  2067. out["dim"] = 100
  2068. out["ang"] = 0
  2069. out["_fpath"] = '/opt/LibreLight/Xdesk/icon/'
  2070. out["fname"] = "picker.png"
  2071. out["raw_img"] = ""
  2072. out["img"] = ""
  2073. out["err"] = []
  2074. return out
  2075. def img_open(img_meta):
  2076. cprint("img_open",img_meta["fname"],"-------")
  2077. fname = img_meta["_fpath"] +"/"+ img_meta["fname"] #'/opt/LibreLight/Xdesk/icon/picker.png'
  2078. im2 = cv2.imread(fname)
  2079. width = int(im2.shape[1])
  2080. height = int(im2.shape[0])
  2081. w_max = 480
  2082. h_max = 320
  2083. #w_max = 600
  2084. #h_max = 400
  2085. w_max = 4800 # max input jpg resolution
  2086. h_max = 3200 # max input jpg resolution
  2087. if width > w_max:
  2088. h = int(height*(w_max/width))
  2089. w = w_max
  2090. im2 = cv2.resize(im2, (w,h), interpolation =cv2.INTER_LINEAR)
  2091. if height > h_max:
  2092. w = int(width*(h_max/height))
  2093. h = h_max
  2094. if w < w_max:
  2095. im2 = cv2.resize(im2, (w,h), interpolation =cv2.INTER_LINEAR)
  2096. img_meta["raw_img"] = im2
  2097. img_meta["img"] = im2
  2098. return im2
  2099. def img_jitter(img_meta):
  2100. r1=random.randint(0,3)
  2101. r2=random.randint(0,3)
  2102. img_meta["ipos"] = [r1,r2]
  2103. def img_rescale_width(img_meta, _width):
  2104. frame = img_meta["raw_img"]
  2105. width = int(frame.shape[1])
  2106. height = int(frame.shape[0])
  2107. dim = (width, height)
  2108. if 1: #width > _width:
  2109. h = int(height*( width/_width))
  2110. dim = (_width, h)
  2111. im = cv2.resize(frame, dim, interpolation =cv2.INTER_LINEAR)
  2112. else:
  2113. im = cv2.resize(frame, dim, interpolation =cv2.INTER_LINEAR)
  2114. return im
  2115. def img_rescale(img, percent=75):
  2116. frame = img
  2117. #frame = img_meta["raw_img"]
  2118. width = int(frame.shape[1] * percent/ 100)
  2119. height = int(frame.shape[0] * percent/ 100)
  2120. dim = (width, height)
  2121. return cv2.resize(frame, dim, interpolation =cv2.INTER_LINEAR)
  2122. def img_draw_raw(img_meta):
  2123. #img_jitter(img_meta)
  2124. pos = img_meta["pos"]
  2125. ipos = img_meta["ipos"]
  2126. im2 = img_meta["img"]
  2127. dim = img_meta["dim"]
  2128. im2 = cvImageToSurface(im2)
  2129. w2 = int(im2.get_width()/2)
  2130. h2 = int(im2.get_height()/2)
  2131. x=pos[0]+ipos[0]
  2132. y=pos[1]+ipos[1]
  2133. window.blit(im2, (x-w2,y-h2))
  2134. img_meta_a = create_img_meta()
  2135. count_tilt = 0
  2136. def main():
  2137. global IP
  2138. global GRID
  2139. global GRID_A
  2140. global FUNC
  2141. global count_tilt
  2142. global TEXT_BLOCK
  2143. global TEXT_BLOCK_TIME
  2144. global MEDIALIST
  2145. global MEDIALIST_TIME
  2146. global dataA
  2147. global frame2
  2148. global runnung
  2149. reload_grid()
  2150. s=time.time()
  2151. r = ""
  2152. IP = "xx"
  2153. while running:
  2154. if TEXT_BLOCK_TIME+5 < time.time():
  2155. TEXT_BLOCK = open_text_block()
  2156. TEXT_BLOCK_TIME = time.time()
  2157. if MEDIALIST_TIME+6 < time.time():
  2158. MEDIALIST = open_medialist()
  2159. MEDIALIST_TIME = time.time()
  2160. pygame.display.flip()
  2161. set_pos(GRID,_x=CFG_IN["x1"],_y=CFG_IN["y1"])
  2162. event()
  2163. window.fill((10,0,30))
  2164. calc_fps()
  2165. calc_fps2()
  2166. # GRID loop
  2167. try:
  2168. FUNC = dataA[gobo_ch-1]
  2169. FUNC2 = FUNC
  2170. except Exception as e:
  2171. print("EXC FUNC",e)
  2172. draw_gobo(GRID,data) #,_x=CFG_IN["x1"],_y=CFG_IN["y1"])
  2173. grid_label(GRID,_x=CFG_IN["x1"],_y=CFG_IN["y1"])
  2174. if VIDEO:
  2175. draw_all_video(VIDEO)
  2176. if options.countdown:
  2177. draw_counter(COUNTER)
  2178. # output background mask
  2179. _w = 8*16
  2180. if len(out_idim):
  2181. _w = len(out_idim)*8*16
  2182. pygame.draw.rect(window,[0,0,0],[35,57,_w+16,135]) # background
  2183. pointer.draw(0,pm_wy) #wy
  2184. spos = [0,0,0,0]
  2185. if PIXEL_MAPPING >= 1:
  2186. #try:
  2187. if options.dual_vpu:
  2188. GRID_X = GRID_A[8*8:]
  2189. xx = p*8
  2190. reshape2(GRID,GRID_A,CFG_OUT[0]["x1"],CFG_OUT[0]["y1"],name="GRID_A1") #start pos
  2191. if options.out_idim:
  2192. out_frame()
  2193. # OUTPUT -> MAPING
  2194. if options.out_idim:
  2195. draw_kachel_nr()
  2196. if options.out_idim:
  2197. input_mask() # mask background
  2198. if options.out_idim:
  2199. output_mask() # mask background
  2200. GRID_DIM() # overlay
  2201. if VIDEO:
  2202. draw_all_video_overlay(VIDEO)
  2203. draw_main_overlay()
  2204. draw_marker()
  2205. pointer.draw(0,pm_wy) #wy
  2206. pygame.display.flip()
  2207. clock.tick(25)
  2208. if 'SDL_VIDEO_WINDOW_POS' in os.environ:
  2209. del os.environ['SDL_VIDEO_WINDOW_POS'] #= '%i,%i' % (200,164)
  2210. frame2 += 1
  2211. if __name__ == "__main__":
  2212. try:
  2213. main()
  2214. finally:
  2215. del_all_video()