vpu_live4.py 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715
  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. pass
  1464. return crop
  1465. vpu_wall_txt="""---,quelle,,---,ziel,---,---
  1466. out,x,y,ang,row,col,info
  1467. Wall1,0,0,0,1,1,
  1468. Wall1,0,0,0,2,2,
  1469. Wall1,0,0,0,3,3,
  1470. Wall1,0,0,0,4,4,
  1471. Wall1,0,0,0,5,5,
  1472. Wall1,0,0,0,6,6,
  1473. Wall1,0,0,0,7,7,
  1474. ,,,,,,
  1475. Wall2,0,0,0,4,1,----
  1476. Wall2,0,0,0,5,2,
  1477. Wall2,4,4,0,6,3,
  1478. Wall2,0,0,0,7,4,
  1479. Wall2,0,0,0,8,5,
  1480. Wall2,0,0,0,9,6,
  1481. ,,,,,,
  1482. ,,,,,,
  1483. Wall3,64,48,0,12,1,----
  1484. Wall3,64,64,0,12,2,
  1485. Wall3,64,80,0,12,3,
  1486. Wall3,64,96,0,12,4,
  1487. Wall3,64,112,0,12,5,
  1488. Wall3,64,128,0,12,6,"""
  1489. def create_vpu_wall_conf():
  1490. f=open(vpu_wall_conf_file,"w")
  1491. f.write(vpu_wall_txt)
  1492. f.close()
  1493. print("CREATE VPU CONFIG !")
  1494. wall_data = []
  1495. _last_wall_config_time = time.time()
  1496. def read_wall_pix(init=0):
  1497. global _last_wall_config_time
  1498. global wall_data, NR
  1499. grid = []
  1500. #if not NR and init==0:
  1501. # return
  1502. ok = 0
  1503. if init:
  1504. ok = 1
  1505. if NR:
  1506. if time.time()-_last_wall_config_time > 3:
  1507. ok = 1
  1508. else:
  1509. if time.time()-_last_wall_config_time > 10:
  1510. ok = 1
  1511. if not ok:
  1512. return
  1513. print("read_wall_pix",vpu_wall_conf_file)
  1514. _last_wall_config_time = time.time()
  1515. if not os.path.isfile(vpu_wall_conf_file):
  1516. create_vpu_wall_conf()
  1517. f=open(vpu_wall_conf_file,"r")
  1518. lines = f.readlines()
  1519. for i,line in enumerate(lines):
  1520. line = line.strip()
  1521. if not line:
  1522. continue
  1523. line = line.split(",")
  1524. if not line[0]:
  1525. continue
  1526. #print(i,line)
  1527. if len(line) >= 3:
  1528. _l = []
  1529. for i in line:
  1530. try:
  1531. _l.append(int(i))
  1532. except Exception as e:
  1533. _l.append(i)
  1534. grid.append(_l)
  1535. #for i,v in enumerate(grid):
  1536. # print(i,v)
  1537. wall_data = grid
  1538. read_wall_pix(init=1)
  1539. def reshape2(GRID,GRID_OUT,_x,_y,name="GRID_Z"):
  1540. _w = 16
  1541. _h = 16
  1542. from_x_min = INPUT_START_POS_X
  1543. from_y_min = INPUT_START_POS_Y
  1544. target_x = 40 # min
  1545. target_y = 60 # min
  1546. ang=0
  1547. #read_block_pix()
  1548. read_wall_pix()
  1549. _wall_data = wall_data[:]
  1550. for i,_wall in enumerate(_wall_data):
  1551. #print(_wall)
  1552. if len(_wall) <=6:
  1553. continue
  1554. try:
  1555. if type(_wall[1]) is str:
  1556. continue
  1557. if type(_wall[2]) is str:
  1558. continue
  1559. if type(_wall[3]) is str:
  1560. continue
  1561. if type(_wall[4]) is str:
  1562. continue
  1563. if type(_wall[5]) is str:
  1564. continue
  1565. from_x=from_x_min+_wall[1]#*_w
  1566. from_y=from_y_min+_wall[2]#*_h
  1567. _a= _wall[3]
  1568. ang=0
  1569. if _a < 0:
  1570. ang=0
  1571. elif _a > 0 and _a <= 90:
  1572. ang = 90
  1573. elif _a > 90 and _a <= 180:
  1574. ang = 180
  1575. elif _a > 180 and _a <= 270:
  1576. ang = 270
  1577. target_x=40+(_wall[4]-1)*_w
  1578. target_y=60+(_wall[5]-1)*_h
  1579. sub = grab(from_x,from_y,_w,_h)
  1580. if sub:
  1581. sub = pygame.transform.rotate(sub,ang)
  1582. window.blit(sub,(target_x,target_y))
  1583. except Exception as e:
  1584. cprint(" ",_wall,color="red")
  1585. cprint("WALL err:",e,color="red")
  1586. def reload_grid():
  1587. print("==== reload_grid")
  1588. global GRID
  1589. global GRID_A
  1590. try:
  1591. GRID = init_grid(_x=_x,_y=_y,name="GRID") #init_gird()
  1592. GRID_A = init_grid(_x=8,_y=16,mapping=1,name="GRID_A") #init_gird()
  1593. except Exception as e:
  1594. cprint("Except: grid re init",e,color="red")
  1595. def draw_kachel_nr(): #GRID,_x=0,_y=0):
  1596. if not NR:
  1597. return
  1598. n = 0
  1599. _max_row = 40
  1600. _y=0
  1601. for i in range(8): # ROW / ZEILEN -> ->
  1602. _x=0
  1603. OUT_COUNT = len(CFG_OUT)
  1604. for j in range(8*OUT_COUNT): # COLUMS / SPALTEN | |
  1605. pygame.draw.rect(window,[10,20,10],[40+_x+2,60+_y+2,14,9]) #background
  1606. _j=j
  1607. fr = font12.render("{}:{}".format(_j+1,i+1) ,1, (200,200,55))
  1608. window.blit(fr,(40+_x+2,60+_y+2))
  1609. _x+=16 # pix
  1610. _y +=16 # pix
  1611. def draw_counter(COUNTER):
  1612. for count in COUNTER:
  1613. cpan = 0
  1614. ctilt = 0
  1615. cr=255
  1616. cg=255
  1617. cb=255
  1618. csize=10
  1619. cdim=0
  1620. k = "DIM"
  1621. if k in count:
  1622. cdim = int(count[k])
  1623. k = "RED"
  1624. if k in count:
  1625. cr = int(count[k])
  1626. k = "GREEN"
  1627. if k in count:
  1628. cg = int(count[k])
  1629. k = "BLUE"
  1630. if k in count:
  1631. cb = int(count[k])
  1632. k = "SIZE"
  1633. if k in count:
  1634. csize = int(count[k]) #/60*p)
  1635. if csize < 5:
  1636. csize = 5
  1637. k = "PAN"
  1638. if k in count:
  1639. cpan = int(count[k])/255*(block[0] *(_x))
  1640. #cpan = int(cpan * 1.2)
  1641. cpan = int(cpan)
  1642. k = "TILT"
  1643. if k in count:
  1644. ctilt = int(count[k])/255*(block[1] *(_y))
  1645. #ctilt = int(cpan * 1.2)
  1646. ctilt = int(ctilt)
  1647. ddim = cdim/255
  1648. if "DIM" in count and count["DIM"] > 0:
  1649. tmp_font = pygame.font.SysFont("freemonobold",int(p/100*csize))
  1650. rgb =(int(cr*ddim),int(cg*ddim),int(cb*ddim),cdim)
  1651. _sec = count["_SEC"]
  1652. try:
  1653. _sec = int(count["_SEC"])
  1654. except:
  1655. pass
  1656. if type(_sec) is int:
  1657. #print(_sec)
  1658. if _sec <= 60:
  1659. fr = tmp_font.render("{:0}".format(_sec) ,1, rgb)
  1660. else:
  1661. _xx = time.strftime("%M:%S",time.localtime(_sec))
  1662. #print("_xx",_xx)
  1663. fr = tmp_font.render("{}".format(_xx) ,1, rgb)
  1664. else:
  1665. fr = tmp_font.render("{}".format((count["_SEC"])) ,1, rgb)
  1666. fr_r = fr.get_rect(center=(40+cpan-(block[0]),60+ctilt+pm_wy))
  1667. pygame.draw.rect(window,[0,0,0],fr_r)
  1668. window.blit(fr,fr_r)
  1669. def video_overlay_draw(wn=None,lines=["line1","line2"],i=0):
  1670. # overlay
  1671. pygame.draw.rect(wn,[255,200,0],[5,MAIN_SIZE[1]-(i+1)*35,380,28])
  1672. font15 = pygame.font.SysFont("freemonobold",17)
  1673. rgb = [255,100,0]
  1674. pygame.draw.rect(wn,rgb,[5,MAIN_SIZE[1]-(i+1)*35,200,13])
  1675. _line = lines[0]
  1676. fr = font15.render(_line ,1, (0,0,0))
  1677. wn.blit(fr,(10,MAIN_SIZE[1]-(i+1)*35))
  1678. _line = lines[1]
  1679. fr = font15.render(_line ,1, (0,0,0))
  1680. wn.blit(fr,(10,MAIN_SIZE[1]-(i+1)*35+15))
  1681. #_line = lines[2]
  1682. #fr = font15.render(_line ,1, (0,0,0))
  1683. #wn.blit(fr,(75,MAIN_SIZE[1]-(i+1)*35+15))
  1684. def draw_all_video_overlay(VIDEO):
  1685. global videplayer
  1686. i=0
  1687. for count in VIDEO:
  1688. video1 = videoplayer[i]
  1689. #video1.overlay_draw(window,"run") # old
  1690. lines = video1._overlay_text()
  1691. video_overlay_draw(wn=window,lines=lines,i=i)
  1692. i += 1
  1693. def del_all_video():
  1694. global videplayer
  1695. i = 0
  1696. print()
  1697. cprint("del_all_video")
  1698. for video in videoplayer:
  1699. cprint("- del video",video)
  1700. video._del()
  1701. def draw_all_video(VIDEO):
  1702. global videplayer
  1703. i = 0
  1704. # set DMX-VALUE to videoplayer Object
  1705. for count in VIDEO:
  1706. cpan = 0
  1707. ctilt = 0
  1708. cr=255
  1709. cg=255
  1710. cb=255
  1711. csize=10
  1712. cang=0
  1713. cdim=0
  1714. video1 = videoplayer[i]
  1715. k = "VIDEO"
  1716. if k in count:
  1717. #video1.select_video(count[k])
  1718. play_nr = int(count[k]/10)
  1719. if play_nr != video1._media_nr:
  1720. print( "+ + + + + + + + + + +", play_nr , video1._media_nr ,str(video1))
  1721. _vid = video1._id
  1722. _cdmx = video1.dmx
  1723. del_video1 = video1
  1724. video1 = PixelMedia(cdmx,_id=_vid)
  1725. video1.select_video(count[k])
  1726. videoplayer[i] = video1
  1727. del_video1._del()
  1728. del del_video1
  1729. k = "DIM"
  1730. if k in count:
  1731. cdim = int(count[k])
  1732. #video1.dim = cdim
  1733. #if i == 0:
  1734. # print(i,cdim)
  1735. k = "ANG"
  1736. if k in count:
  1737. cang = int(count[k])
  1738. k = "SIZE"
  1739. if k in count:
  1740. csize = int(count[k]/16*p)
  1741. if csize < 5:
  1742. csize = 5
  1743. k = "PAN"
  1744. cpan_max = block[0] *(_x) #+block[0]
  1745. if k in count:
  1746. cpan = int(count[k]) / 255*cpan_max
  1747. cpan = int(cpan)
  1748. k = "TILT"
  1749. ctilt_max = block[1] *(_y) #+block[1]
  1750. if k in count:
  1751. ctilt = int(count[k]) / 255*ctilt_max
  1752. ctilt = int(ctilt)
  1753. k = "_reset"
  1754. if k in count:
  1755. if count[k]:
  1756. count[k] = 0
  1757. video1.restart()
  1758. k = "_RUN"
  1759. if k in count:
  1760. video1._run = count[k]
  1761. #video1.pos
  1762. #video1.x=40+0+cpan
  1763. #video1.y=60+0+pm_wy+ctilt
  1764. x=CFG_IN["x1"]+cpan
  1765. y=CFG_IN["y1"]+ctilt
  1766. scale = int((csize))
  1767. angle = int(360-(cang))
  1768. video1.update_dmx(x,y,scale,angle,cdim)
  1769. if cdim:
  1770. video1.next()
  1771. i += 1
  1772. # draw
  1773. i=0
  1774. for count in VIDEO:
  1775. video1 = videoplayer[i]
  1776. video1.draw(window) #,x=0,y=0)
  1777. i+=1
  1778. def counter_dmx(COUNTER,dataA):
  1779. for count in COUNTER:
  1780. cDMX=count["DMX"]-1
  1781. try:
  1782. count["DIM"] = dataA[cDMX]
  1783. count["PAN"] = dataA[cDMX+1]
  1784. count["TILT"] = dataA[cDMX+2]
  1785. count["CONTROL"] = dataA[cDMX+3]
  1786. count["SIZE"] = dataA[cDMX+4]
  1787. count["SEC"] = dataA[cDMX+5]
  1788. count["RED"] = dataA[cDMX+6]
  1789. count["GREEN"] = dataA[cDMX+7]
  1790. count["BLUE"] = dataA[cDMX+8]
  1791. if count["CONTROL"] >= 10 and count["CONTROL"] < 20: # RESET COUNTER
  1792. count["_RUN"] = 0
  1793. count["_pause"] = 0
  1794. count["_time"] = time.time()
  1795. count["_start"] = int(count["SEC"])
  1796. count["_SEC"] = int(count["_start"])
  1797. if count["CONTROL"] >= 20 and count["CONTROL"] < 30: # PAUSE COUNTER
  1798. count["_RUN"] = 0
  1799. if count["CONTROL"] >= 30 and count["CONTROL"] < 40: # PLAY COUNTER
  1800. count["_RUN"] = 1
  1801. if count["_RUN"]:
  1802. try:
  1803. if count["_pause"] > 0:
  1804. count["_time"] += time.time()-count["_pause"]
  1805. count["_pause"] = 0
  1806. count["_SEC"] = int(count["_start"] - (time.time() - count["_time"]))
  1807. except Exception as e:
  1808. pass
  1809. else:
  1810. if count["_pause"] == 0:
  1811. count["_pause"] = time.time()
  1812. if type(count["_SEC"]) is int:
  1813. if count["_SEC"] < 0:
  1814. count["_SEC"] = 0
  1815. for ti in range(10):
  1816. #print(ti,(ti+6)*10)
  1817. if count["CONTROL"] >= (ti+6)*10 and count["CONTROL"] < (ti+7)*10:
  1818. count["_SEC"] = "----" #text 1
  1819. try:
  1820. count["_SEC"] = TEXT_BLOCK[ti]
  1821. except Exception as e:
  1822. pass
  1823. if count["CONTROL"] >= 250 and count["CONTROL"] < 256:
  1824. count["_SEC"] = "DMX:{}-{}".format(cDMX+1,cDMX+8+1)
  1825. except Exception as e:
  1826. cprint("EXC FUNC",e,count,color="red")
  1827. #print(count)
  1828. def video_dmx(VIDEO,dataA):
  1829. for count in VIDEO:
  1830. cDMX=count["DMX"]-1
  1831. try:
  1832. count["DIM"] = dataA[cDMX]
  1833. count["PAN"] = dataA[cDMX+1]
  1834. count["TILT"] = dataA[cDMX+2]
  1835. count["CONTROL"] = dataA[cDMX+3]
  1836. if count["CONTROL"] >= 10 and count["CONTROL"] < 20:
  1837. count["_reset"] = 1
  1838. if count["CONTROL"] >= 20 and count["CONTROL"] < 30:
  1839. if count["_RUN"] == 1:
  1840. print( "_RUN:0",count["DMX"]-1)
  1841. count["_RUN"] = 0
  1842. if count["CONTROL"] >= 30 and count["CONTROL"] < 40:
  1843. if count["_RUN"] == 0:
  1844. print( "_RUN:1",count["DMX"]-1)
  1845. count["_RUN"] = 1
  1846. count["SIZE"] = dataA[cDMX+4]#*2
  1847. count["SEC"] = dataA[cDMX+5]
  1848. #count["RED"] = dataA[cDMX+6]
  1849. count["VIDEO"] = dataA[cDMX+6]
  1850. #count["GREEN"] = dataA[cDMX+7]
  1851. count["ANG"] = (int(dataA[cDMX+7])/255*360)
  1852. #count["BLUE"] = dataA[cDMX+8]
  1853. except Exception as e:
  1854. cprint("VIDEOPLAYER EXCEPT FUNC",e,count,color="red")
  1855. #print(count)
  1856. def read_dmx_data(ip,ips):
  1857. ip = select_ip(ips,univ=START_UNIV)
  1858. IP = ip
  1859. data = read_dmx(ip)
  1860. ip = select_ip(ips,univ=START_UNIV+1)
  1861. data3 = read_dmx(ip)
  1862. data.extend(data3)
  1863. ip = select_ip(ips,univ=START_UNIV+2)
  1864. data3 = read_dmx(ip)
  1865. data.extend(data3)
  1866. ip = select_ip(ips,univ=START_UNIV+3)
  1867. data3 = read_dmx(ip)
  1868. data.extend(data3)
  1869. if options.dual_vpu:
  1870. ip = select_ip(ips,univ=START_UNIV+4)
  1871. data3 = read_dmx(ip)
  1872. data.extend(data3)
  1873. ip = select_ip(ips,univ=START_UNIV+5)
  1874. data3 = read_dmx(ip)
  1875. data.extend(data3)
  1876. return data
  1877. def set_pos(GRID,_x=0,_y=0):
  1878. for fix in GRID:
  1879. pos = fix.POS(_x,_y)#40,60+pm_wy)
  1880. for subfix in fix.sub_fix:
  1881. #subfix.dmc_calc(data)
  1882. spos = subfix.POS(_x,_y)
  1883. def draw_gobo(GRID,data,_x=0,_y=0):
  1884. i = 0
  1885. dmx = 1
  1886. h = 1
  1887. v = 1
  1888. for fix in GRID:
  1889. rgb = fix.rgb
  1890. pos = fix.POS() #CFG_IN["x1"],CFG_IN["y1"])
  1891. pygame.draw.rect(window,rgb,pos)
  1892. # DRAW SUB-FIXTURE
  1893. j = 0
  1894. for subfix in fix.sub_fix:#calc(data):
  1895. subfix.dmx_calc(data)
  1896. spos = subfix.POS() #_x,_y)#+pm_wy)
  1897. srgb = subfix.rgb
  1898. if FUNC > 10 and FUNC <= 20: # big dot
  1899. draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/2))
  1900. elif FUNC > 20 and FUNC <= 30:#small dot
  1901. draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  1902. elif FUNC > 30 and FUNC <= 40:#donut
  1903. draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/2))
  1904. draw_circle(window,[0,0,0],(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  1905. elif FUNC > 40 and FUNC <= 50: # rec with hole
  1906. pygame.draw.rect(window,srgb,spos)
  1907. draw_circle(window,[0,0,0],(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  1908. elif FUNC > 50 and FUNC <= 60: # rec with big hole
  1909. pygame.draw.rect(window,srgb,spos)
  1910. draw_circle(window,[0,0,0],(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/2))
  1911. elif FUNC > 60 and FUNC <= 70: # rec with donat
  1912. pygame.draw.rect(window,srgb,spos)
  1913. draw_circle(window,[0,0,0],(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/2))
  1914. draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  1915. elif FUNC > 70 and FUNC <= 80: # rec boarder
  1916. pygame.draw.rect(window,srgb,[spos[0]+1,spos[1]+1,spos[2]-2,spos[3]-2])
  1917. elif FUNC > 80 and FUNC <= 90: # rec big boarder
  1918. pygame.draw.rect(window,srgb,[spos[0]+2,spos[1]+2,spos[2]-4,spos[3]-4])
  1919. elif FUNC > 90 and FUNC <= 100: # rec thin line
  1920. pygame.draw.rect(window,srgb,spos)
  1921. pygame.draw.rect(window,[0,0,0],[spos[0]+1,spos[1]+1,spos[2]-2,spos[3]-2])
  1922. elif FUNC > 100 and FUNC <= 110: # rec big line
  1923. pygame.draw.rect(window,srgb,spos)
  1924. pygame.draw.rect(window,[0,0,0],[spos[0]+2,spos[1]+2,spos[2]-4,spos[3]-4])
  1925. elif FUNC > 110 and FUNC <= 120: # rec with dot
  1926. pygame.draw.rect(window,srgb,spos)
  1927. pygame.draw.rect(window,[0,0,0],[spos[0]+1,spos[1]+1,spos[2]-2,spos[3]-2])
  1928. draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  1929. elif FUNC > 120 and FUNC <= 130: # rec inline
  1930. pygame.draw.rect(window,srgb,[spos[0]+2,spos[1]+2,spos[2]-4,spos[3]-4])
  1931. pygame.draw.rect(window,[0,0,0],[spos[0]+3,spos[1]+3,spos[2]-6,spos[3]-6])
  1932. elif FUNC > 130 and FUNC <= 140: # 3 dot (heart)
  1933. draw_circle(window,srgb,(spos[0]+int(spos[2]/2)+2,spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  1934. draw_circle(window,srgb,(spos[0]+int(spos[2]/2)-2,spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  1935. draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)+2),int(spos[3]/3.5))
  1936. else:
  1937. pygame.draw.rect(window,srgb,spos)
  1938. i += 1
  1939. def grid_label(GRID,_x=0,_y=0):
  1940. for fix in GRID:
  1941. #pos = fix.POS(_x,_y)
  1942. pos = fix.POS() #CFG_IN["x1"],CFG_IN["y1"])
  1943. rgb = fix.rgb
  1944. # draw row/col grid number
  1945. if pos[0] == 0:
  1946. fr = font12.render("{}".format(pos[1]+1) ,1, (200,200,200))
  1947. window.blit(fr,(10,pos[1]+3 ))
  1948. if pos[1] == 0:
  1949. fr = font12.render("{}".format(pos[0]+1) ,1, (200,200,200))
  1950. window.blit(fr,(pos[0]+2,35 ))
  1951. def out_frame():
  1952. rgb = [255,255,0]
  1953. rgb = [255,0,0]
  1954. for CFG_OUTx in CFG_OUT:
  1955. if CFG_OUTx["on"]:
  1956. rgb = [255,0,0]
  1957. p1 = CFG_OUTx["p1"][:]
  1958. p2 = CFG_OUTx["p2"][:]
  1959. p1[0] += 4
  1960. p2[0] -= 4
  1961. draw_frame(window,rgb,p1,p2,offset=3)
  1962. ips=[]
  1963. dataA=[]
  1964. data=[]
  1965. def dmx_raw():
  1966. global frame
  1967. frame += 1
  1968. global ips,dataA,data
  1969. ips = read_index()
  1970. # ----
  1971. ip = select_ip(ips,univ=1) # univ 1 gobo
  1972. dataA = read_dmx(ip)
  1973. # ----
  1974. data = read_dmx_data(ip,ips)
  1975. if options.countdown:
  1976. counter_dmx(COUNTER,dataA)
  1977. if len(VIDEO) > 0:
  1978. video_dmx(VIDEO,dataA)
  1979. return ips,dataA,data
  1980. def dmx_loop():
  1981. while 1:
  1982. dmx_raw()
  1983. time.sleep(1/40) # fast high cpu
  1984. if QUIT:
  1985. break
  1986. thread.start_new_thread(dmx_loop,())
  1987. def draw_output_label(CFG,value,dmx="0.0",name="GRID_XX"):
  1988. dim_raw = value
  1989. pygame.draw.rect(window,[5,5,155],[CFG["x1"]+2,CFG["y2"]+5,CFG["w"]-6,25]) # background
  1990. # GRID_A1_DIM_LABEL
  1991. fr = font15.render("Name: "+name,1, (255,255,255))
  1992. fr_r = fr.get_rect(center=(int(wx/2),int(0+pm_wy-p*0-10)))
  1993. window.blit(fr,(CFG["x1"]+4,CFG["y2"]+5))
  1994. fr = font15.render("inv-dim: "+str(dim_raw) ,1, (255,255,255))
  1995. fr_r = fr.get_rect(center=(int(wx/2),int(0+pm_wy-p*0-10)))
  1996. window.blit(fr,(CFG["x1"]+64,CFG["y2"]+20))
  1997. fr = font15.render("dmx: {}.{}".format(START_UNIV_A,dmx) ,1, (255,255,255))
  1998. window.blit(fr,(CFG["x1"]+4,CFG["y2"]+20))
  1999. def _check_dim(_dim):
  2000. dim = 255
  2001. try:
  2002. dim = int(_dim)
  2003. if dim > 255:
  2004. dim = 255
  2005. if dim <=0:
  2006. dim = 0
  2007. except:
  2008. pass
  2009. return dim
  2010. def _GRID_DIM(dim,x,y):
  2011. dim = _check_dim(dim)
  2012. dim_raw = dim*-1
  2013. s = pygame.Surface((p*8,p*8)) # the size of your rect
  2014. s.set_alpha(dim) # alpha level
  2015. s.fill((0,0,0)) # this fills the entire surface
  2016. window.blit(s, (x,y))
  2017. def GRID_DIM():
  2018. for CFG in CFG_OUT:
  2019. dim_ch = int(CFG["DMX-CH"])
  2020. dim = dataA[dim_ch-1]
  2021. _GRID_DIM(dim,x=CFG["x1"],y=CFG["y2"]-p*8)
  2022. draw_output_label(CFG,dim,dim_ch,name=CFG["name"])
  2023. def cvImageToSurface(cvImage):
  2024. if cvImage.dtype.name == 'uint16':
  2025. cvImage = (cvImage / 256).astype('uint8')
  2026. size = cvImage.shape[1::-1]
  2027. if len(cvImage.shape) == 2:
  2028. cvImage = np.repeat(cvImage.reshape(size[1], size[0], 1), 3, axis = 2)
  2029. format = 'RGB'
  2030. else:
  2031. format = 'RGBA' if cvImage.shape[2] == 4 else 'RGB'
  2032. cvImage[:, :, [0, 2]] = cvImage[:, :, [2, 0]]
  2033. surface = pygame.image.frombuffer(cvImage.flatten(), size, format)
  2034. return surface.convert_alpha() if format == 'RGBA' else surface.convert()
  2035. def create_img_meta():
  2036. out = {}
  2037. #40 235
  2038. out["pos"] = (0,0) # x,y
  2039. out["ipos"] = (0,0) # x,y
  2040. out["scale"] = 50
  2041. out["dim"] = 100
  2042. out["ang"] = 0
  2043. out["_fpath"] = '/opt/LibreLight/Xdesk/icon/'
  2044. out["fname"] = "picker.png"
  2045. out["raw_img"] = ""
  2046. out["img"] = ""
  2047. out["err"] = []
  2048. return out
  2049. def img_open(img_meta):
  2050. cprint("img_open",img_meta["fname"],"-------")
  2051. fname = img_meta["_fpath"] +"/"+ img_meta["fname"] #'/opt/LibreLight/Xdesk/icon/picker.png'
  2052. im2 = cv2.imread(fname)
  2053. width = int(im2.shape[1])
  2054. height = int(im2.shape[0])
  2055. w_max = 480
  2056. h_max = 320
  2057. #w_max = 600
  2058. #h_max = 400
  2059. w_max = 4800 # max input jpg resolution
  2060. h_max = 3200 # max input jpg resolution
  2061. if width > w_max:
  2062. h = int(height*(w_max/width))
  2063. w = w_max
  2064. im2 = cv2.resize(im2, (w,h), interpolation =cv2.INTER_LINEAR)
  2065. if height > h_max:
  2066. w = int(width*(h_max/height))
  2067. h = h_max
  2068. if w < w_max:
  2069. im2 = cv2.resize(im2, (w,h), interpolation =cv2.INTER_LINEAR)
  2070. img_meta["raw_img"] = im2
  2071. img_meta["img"] = im2
  2072. return im2
  2073. def img_jitter(img_meta):
  2074. r1=random.randint(0,3)
  2075. r2=random.randint(0,3)
  2076. img_meta["ipos"] = [r1,r2]
  2077. def img_rescale_width(img_meta, _width):
  2078. frame = img_meta["raw_img"]
  2079. width = int(frame.shape[1])
  2080. height = int(frame.shape[0])
  2081. dim = (width, height)
  2082. if 1: #width > _width:
  2083. h = int(height*( width/_width))
  2084. dim = (_width, h)
  2085. im = cv2.resize(frame, dim, interpolation =cv2.INTER_LINEAR)
  2086. else:
  2087. im = cv2.resize(frame, dim, interpolation =cv2.INTER_LINEAR)
  2088. return im
  2089. def img_rescale(img, percent=75):
  2090. frame = img
  2091. #frame = img_meta["raw_img"]
  2092. width = int(frame.shape[1] * percent/ 100)
  2093. height = int(frame.shape[0] * percent/ 100)
  2094. dim = (width, height)
  2095. return cv2.resize(frame, dim, interpolation =cv2.INTER_LINEAR)
  2096. def img_draw_raw(img_meta):
  2097. #img_jitter(img_meta)
  2098. pos = img_meta["pos"]
  2099. ipos = img_meta["ipos"]
  2100. im2 = img_meta["img"]
  2101. dim = img_meta["dim"]
  2102. im2 = cvImageToSurface(im2)
  2103. w2 = int(im2.get_width()/2)
  2104. h2 = int(im2.get_height()/2)
  2105. x=pos[0]+ipos[0]
  2106. y=pos[1]+ipos[1]
  2107. window.blit(im2, (x-w2,y-h2))
  2108. img_meta_a = create_img_meta()
  2109. count_tilt = 0
  2110. def main():
  2111. global IP
  2112. global GRID
  2113. global GRID_A
  2114. global FUNC
  2115. global count_tilt
  2116. global TEXT_BLOCK
  2117. global TEXT_BLOCK_TIME
  2118. global MEDIALIST
  2119. global MEDIALIST_TIME
  2120. global dataA
  2121. global frame2
  2122. global runnung
  2123. reload_grid()
  2124. s=time.time()
  2125. r = ""
  2126. IP = "xx"
  2127. while running:
  2128. if TEXT_BLOCK_TIME+5 < time.time():
  2129. TEXT_BLOCK = open_text_block()
  2130. TEXT_BLOCK_TIME = time.time()
  2131. if MEDIALIST_TIME+6 < time.time():
  2132. MEDIALIST = open_medialist()
  2133. MEDIALIST_TIME = time.time()
  2134. pygame.display.flip()
  2135. set_pos(GRID,_x=CFG_IN["x1"],_y=CFG_IN["y1"])
  2136. event()
  2137. window.fill((10,0,30))
  2138. calc_fps()
  2139. calc_fps2()
  2140. # GRID loop
  2141. try:
  2142. FUNC = dataA[gobo_ch-1]
  2143. FUNC2 = FUNC
  2144. except Exception as e:
  2145. print("EXC FUNC",e)
  2146. draw_gobo(GRID,data) #,_x=CFG_IN["x1"],_y=CFG_IN["y1"])
  2147. grid_label(GRID,_x=CFG_IN["x1"],_y=CFG_IN["y1"])
  2148. if VIDEO:
  2149. draw_all_video(VIDEO)
  2150. if options.countdown:
  2151. draw_counter(COUNTER)
  2152. # output background mask
  2153. _w = 8*16
  2154. if len(out_idim):
  2155. _w = len(out_idim)*8*16
  2156. pygame.draw.rect(window,[0,0,0],[35,57,_w+16,135]) # background
  2157. pointer.draw(0,pm_wy) #wy
  2158. spos = [0,0,0,0]
  2159. if PIXEL_MAPPING >= 1:
  2160. #try:
  2161. if options.dual_vpu:
  2162. GRID_X = GRID_A[8*8:]
  2163. xx = p*8
  2164. reshape2(GRID,GRID_A,CFG_OUT[0]["x1"],CFG_OUT[0]["y1"],name="GRID_A1") #start pos
  2165. if options.out_idim:
  2166. out_frame()
  2167. # OUTPUT -> MAPING
  2168. if options.out_idim:
  2169. draw_kachel_nr()
  2170. if options.out_idim:
  2171. input_mask() # mask background
  2172. if options.out_idim:
  2173. output_mask() # mask background
  2174. GRID_DIM() # overlay
  2175. if VIDEO:
  2176. draw_all_video_overlay(VIDEO)
  2177. draw_main_overlay()
  2178. draw_marker()
  2179. pointer.draw(0,pm_wy) #wy
  2180. pygame.display.flip()
  2181. clock.tick(25)
  2182. if 'SDL_VIDEO_WINDOW_POS' in os.environ:
  2183. del os.environ['SDL_VIDEO_WINDOW_POS'] #= '%i,%i' % (200,164)
  2184. frame2 += 1
  2185. if __name__ == "__main__":
  2186. try:
  2187. main()
  2188. finally:
  2189. del_all_video()