def _prepare_light(self, img): # Creation of 1D distributions for sampling c_distr = [] values = [0.0] * img.height for i in range(img.height): # 1D Distribution lums = get_lums(img, i) tmp_distr = create_1d_distribution(lums) c_distr.append(tmp_distr) values[i] = tmp_distr.max_cdf r_distr = create_1d_distribution(values) #prepare structure for shader arr = FloatArray() for v in r_distr.cdfs: arr.append(v) arr.append(1.0) self._arr1 = arr arr2d = FloatArray2D(img.width + 1, img.height) for y in range(img.height): d = c_distr[y] for x in range(img.width): arr2d[x, y] = d.cdfs[x] arr2d[x, y] = 1.0 self._arr2 = arr2d
def test_get_item(self): arr = FloatArray(values=(2, 3, 4, 5, 6, 7)) code = """ index = 3 num = get_item(arr, index) """ props = {'arr': arr, 'num': 2.3} bs = BasicShader(code, props) runtime = Runtime() bs.prepare([runtime]) #print (bs.shader._code) bs.execute() val = bs.shader.get_value('num') self.assertAlmostEqual(val, 5.0, places=5)
from renmas3.base import FloatArray, FloatArray2D arr = FloatArray(values=[4, 5, 6, 7, 8]) arr.append(3) arr.extend((9, 9, 99, 1, 2, 4)) print(arr[10]) print(len(arr)) print(arr[2]) arr2 = FloatArray2D(3, 4) arr2[2, 2] = 3 print(arr2[2, 2])