| 40 | |
| 41 | #data contains an array or normalized inputs (from 0 to 1) |
| 42 | def SendImageData(id, data, width=32, height=32, name="", rgba=False, flush=True, invert=False, offset=0, resize=[]): |
| 43 | if EDITOR_MODE: |
| 44 | img = Image.new( 'RGBA', (width,height), "white") |
| 45 | pixels = img.load() |
| 46 | |
| 47 | for i in range(len(data)): # for every pixel: |
| 48 | y = int(np.floor(i/width)) |
| 49 | x = i-y*width |
| 50 | #print("coord: "+str(x)+"_"+str(y)+":"+str(data[i])) |
| 51 | if rgba: |
| 52 | pixel = max(0, data[i]) |
| 53 | else: |
| 54 | pixel = [max(0, data[i]), max(0, data[i]), max(0, data[i]), 1] |
| 55 | if invert: |
| 56 | pixels[x,height-y-1] = (int(pixel[0]*255), int(pixel[1]*255), int(pixel[2]*255), 255) # set the colour accordingly |
| 57 | else: |
| 58 | pixels[x,y] = (int(pixel[0]*255), int(pixel[1]*255), int(pixel[2]*255), 255) # set the colour accordingly |
| 59 | |
| 60 | if len(resize)>0: |
| 61 | img = img.resize((resize[0], resize[1]), Image.NEAREST) |
| 62 | |
| 63 | tmpDir = tempfile.gettempdir() |
| 64 | imgPath = str(tmpDir)+"/"+name+"_out_"+str(id)+"_"+str(offset)+".png" |
| 65 | img.save(imgPath) |
| 66 | |
| 67 | Log("img_data,"+str(id)+","+imgPath+","+name, flush) |
| 68 | |
| 69 | def SendAudioData(id, data, name, samplerate=4410, offset=0): |
| 70 | if EDITOR_MODE: |