def test_offset_invertability(): picture = { "Y": new_array(8, 16, 123), "C1": new_array(4, 8, 456), "C2": new_array(4, 8, 789), } for row in picture["Y"]: for i in range(len(row)): row[i] = 123 for row in picture["C1"]: for i in range(len(row)): row[i] = 456 for row in picture["C2"]: for i in range(len(row)): row[i] = 789 state = { "luma_depth": 8, "color_diff_depth": 10, } remove_offset_picture(state, picture) assert picture["Y"][0][0] == 123 - 128 assert picture["C1"][0][0] == 456 - 512 assert picture["C2"][0][0] == 789 - 512 offset_picture(state, picture) assert picture["Y"][0][0] == 123 assert picture["C1"][0][0] == 456 assert picture["C2"][0][0] == 789
def vh_analysis(state, data): """ Interleaved vertical and horizontal analysis, inverse of vh_synthesis (15.4.3). Returns a tuple (LL_data, HL_data, LH_data, HH_data) """ # Bit shift, if required shift = filter_bit_shift(state) if shift > 0: for y in range(0, height(data)): for x in range(0, width(data)): data[y][x] = data[y][x] << shift # Analysis for y in range(0, height(data)): oned_analysis(row(data, y), state["wavelet_index_ho"]) for x in range(0, width(data)): oned_analysis(column(data, x), state["wavelet_index"]) # De-interleave the transform data LL_data = new_array(height(data) // 2, width(data) // 2) HL_data = new_array(height(data) // 2, width(data) // 2) LH_data = new_array(height(data) // 2, width(data) // 2) HH_data = new_array(height(data) // 2, width(data) // 2) for y in range(0, (height(data) // 2)): for x in range(0, (width(data) // 2)): LL_data[y][x] = data[2 * y][2 * x] HL_data[y][x] = data[2 * y][2 * x + 1] LH_data[y][x] = data[2 * y + 1][2 * x] HH_data[y][x] = data[2 * y + 1][2 * x + 1] return (LL_data, HL_data, LH_data, HH_data)
def h_analysis(state, data): """ Horizontal-only analysis, inverse of h_synthesis (15.4.2). Returns a tuple (L_data, H_data) """ # Bit shift, if required shift = filter_bit_shift(state) if shift > 0: for y in range(0, height(data)): for x in range(0, width(data)): data[y][x] = data[y][x] << shift # Analysis for y in range(0, height(data)): oned_analysis(row(data, y), state["wavelet_index_ho"]) # De-interleave the transform data L_data = new_array(height(data), width(data) // 2) H_data = new_array(height(data), width(data) // 2) for y in range(0, (height(data))): for x in range(0, (width(data) // 2)): L_data[y][x] = data[y][2 * x] H_data[y][x] = data[y][(2 * x) + 1] return (L_data, H_data)
def two_d_array(): """A 2D array of numbers for test purposes.""" a = new_array(16, 32) for y in range(height(a)): for x in range(width(a)): a[y][x] = (y * 100) + x return a
def test_2d(self): assert new_array(4, 3) == [ [None, None, None], [None, None, None], [None, None, None], [None, None, None], ]
def vh_synthesis(state, LL_data, HL_data, LH_data, HH_data): """(15.4.3) Interleaved vertical and horizontal synthesis.""" synth = new_array(2 * height(LL_data), 2 * width(LL_data)) # Interleave transform data (as expected by synthesis routine) for y in range(height(synth) // 2): for x in range(width(synth) // 2): synth[2 * y][2 * x] = LL_data[y][x] synth[2 * y][2 * x + 1] = HL_data[y][x] synth[2 * y + 1][2 * x] = LH_data[y][x] synth[2 * y + 1][2 * x + 1] = HH_data[y][x] # Synthesis for x in range(width(synth)): oned_synthesis(column(synth, x), state["wavelet_index"]) for y in range(height(synth)): oned_synthesis(row(synth, y), state["wavelet_index_ho"]) # Bit shift, if required shift = filter_bit_shift(state) if shift > 0: for y in range(height(synth)): for x in range(width(synth)): synth[y][x] = (synth[y][x] + (1 << (shift - 1))) >> shift return synth
def h_synthesis(state, L_data, H_data): """(15.4.2) Horizontal-only synthesis.""" synth = new_array(height(L_data), 2 * width(L_data)) # Interleave transform data (as expected by synthesis routine) for y in range(height(synth)): for x in range(width(synth) // 2): synth[y][2 * x] = L_data[y][x] synth[y][(2 * x) + 1] = H_data[y][x] # Synthesis for y in range(height(synth)): oned_synthesis(row(synth, y), state["wavelet_index_ho"]) # Bit shift, if required shift = filter_bit_shift(state) if shift > 0: for y in range(height(synth)): for x in range(width(synth)): synth[y][x] = (synth[y][x] + (1 << (shift - 1))) >> shift return synth
def num_array(): a = new_array(3, 5) for x in range(width(a)): for y in range(height(a)): a[y][x] = x + (y * 10) return a
def test_height(): assert height(new_array(0, 0)) == 0 assert height(new_array(20, 10)) == 20
def test_width(): assert width(new_array(0, 0)) == 0 assert width(new_array(20, 10)) == 10
def test_2d_singleton(self): assert new_array(1, 1) == [[None]]
def test_2d_empty(self): assert new_array(0, 0) == []
def test_1d(self): assert new_array(0) == [] assert new_array(3) == [None, None, None]