| 91 | |
| 92 | SendFastGraphWarningSent = False |
| 93 | def SendFastGraph(id, data, name="", offset=0, flush=True): |
| 94 | global SendFastGraphWarningSent |
| 95 | |
| 96 | if EDITOR_MODE: |
| 97 | width = len(data) |
| 98 | |
| 99 | if width>=1000 and not SendFastGraphWarningSent: |
| 100 | LogErr("Warning: feeding a large array to SendFastGraph can take time to render.", True) |
| 101 | SendFastGraphWarningSent = True |
| 102 | |
| 103 | height = int(len(data)/2) |
| 104 | |
| 105 | _max = Math.MaxValue(data) |
| 106 | _min = Math.MinValue(data) |
| 107 | |
| 108 | #Log("_max: "+str(_max)) |
| 109 | |
| 110 | img = Image.new( 'RGBA', (width,height), "white") |
| 111 | pixels = img.load() |
| 112 | |
| 113 | for x in range(width): |
| 114 | val = data[x]-_min |
| 115 | |
| 116 | y = max(0, int(height*(val/abs(_max-_min)))) |
| 117 | y = min(height-1, y) |
| 118 | |
| 119 | pixels[x, int(height/2)] = (128, 0, 0, 255) # set the colour accordingly |
| 120 | |
| 121 | state = int(height/2) |
| 122 | |
| 123 | while state!=y: |
| 124 | if abs(state-y)>1: |
| 125 | pixels[x,state] = (128, 128, 255, 255) # set the colour accordingly |
| 126 | else: |
| 127 | pixels[x,state] = (0, 0, 255, 255) # set the colour accordingly |
| 128 | |
| 129 | if state<y: |
| 130 | state+=1 |
| 131 | else: |
| 132 | state-=1 |
| 133 | |
| 134 | IOHelpers.CarveNumber(pixels, _max, 10, 0) |
| 135 | IOHelpers.CarveNumber(pixels, _min, 10, height-7) |
| 136 | |
| 137 | tmpDir = tempfile.gettempdir() |
| 138 | imgPath = str(tmpDir)+"/"+name+"_out_"+str(id)+"_"+str(offset)+".png" |
| 139 | img.save(imgPath) |
| 140 | |
| 141 | Log("img_data,"+str(id)+","+imgPath+","+name, flush) |
| 142 | |
| 143 | def SendSpectrogram(id, times, frequencies, spectogram, name="", offset=0, flush=True): |
| 144 | if EDITOR_MODE: |