def _get_cavern_udgs(self, addr, guardians=1, willy=1): # Collect block graphics block_graphics = {} bg_udg = Udg(self.snapshot[addr + 544], self.snapshot[addr + 545:addr + 553]) block_graphics[bg_udg.attr] = bg_udg for a in range(addr + 553, addr + 616, 9): attr = self.snapshot[a] block_graphics[attr] = Udg(attr, self.snapshot[a + 1:a + 9]) # Build the cavern UDG array udg_array = [] for a in range(addr, addr + 512, 32): udg_array.append([block_graphics.get(attr, bg_udg) for attr in self.snapshot[a:a + 32]]) if addr == 64512: # The Final Barrier (top half) udg_array[:8] = self.screenshot(h=8, df_addr=40960, af_addr=64512) # Cavern name name_udgs = [Udg(48, self.font[b]) for b in self.snapshot[addr + 512:addr + 544]] udg_array.append(name_udgs) self._place_items(udg_array, addr) if guardians: self._place_guardians(udg_array, addr) if willy: self._place_willy(udg_array, addr) # Portal attr = self.snapshot[addr + 655] portal_udgs = self._get_graphic(addr + 656, attr) x, y = self._get_coords(addr + 688) udg_array[y][x:x + 2] = portal_udgs[0] udg_array[y + 1][x:x + 2] = portal_udgs[1] return udg_array
def test_bd2_mask2_flashing(self): # AND-OR mask, 2 colours + trans, one UDG flashing udg1 = Udg(56, (1, ) * 8) # INK 0: PAPER 7: FLASH 0 udg2 = Udg(184, (0, ) * 8, (255, 129, 129, 129, 129, 129, 129, 255)) # INK 0: PAPER 7: FLASH 1 udg_array = [[udg1, udg2]] self._test_scales(udg_array, mask=2)
def test_animation_mask1(self): # 2 frames, transparency on frame 2 iw_args = {'options': self.alpha_option} frame1 = Frame([[Udg(49, (64,) * 8)]]) frame2 = Frame([[Udg(184, (240,) * 8, (243,) * 8)]], mask=1) frames = [frame1, frame2] self._test_animated_image(frames, iw_args)
def test_option_p_multiple(self, mock_open): scr = [0] * 6912 exp_udgs = [[Udg(0, [0] * 8)] * 32 for i in range(24)] exp_udgs[0][0] = Udg(0, [255, 0, 0, 0, 0, 0, 0, 0]) exp_udgs[0][1] = Udg(0, [170, 0, 0, 0, 0, 0, 0, 0]) self._test_sna2img(mock_open, '-p 16384,255 --poke 16385,170', scr, exp_udgs)
def test_bd2_mask2_cropped_flashing(self): # AND-OR mask, 2 colours + trans, cropped, one UDG flashing udg1 = Udg(56, (1, ) * 8) # INK 0: PAPER 7: FLASH 0 udg2 = Udg(184, (0, ) * 8, (255, 255, 195, 195, 195, 195, 255, 255)) # INK 0: PAPER 7: FLASH 1 udg_array = [[udg1, udg2]] self._test_scales(udg_array, mask=2, x=1, y=1, width=14, height=6)
def test_bd4_mask2(self): # AND-OR mask, 5 colours + trans udg1 = Udg(46, (15,) * 8) # INK 6: PAPER 5 udg2 = Udg(120, (0,) * 8, (240,) * 8) # PAPER 7: BRIGHT 1 udg3 = Udg(74, (15,) * 8) # INK 2: PAPER 1: BRIGHT 1 udg_array = [[udg1, udg2, udg3]] self._test_scales(udg_array, mask=2)
def test_bd4_mask2_flashing(self): # AND-OR mask, 6 colours + trans, flashing udg1 = Udg(184, (240,) * 8, (243,) * 8) # INK 0: PAPER 7: FLASH 1 udg2 = Udg(49, (170,) * 8) # INK 1: PAPER 6 udg3 = Udg(170, (195,) * 8) # INK 2: PAPER 5: FLASH 1 udg_array = [[udg1, udg2, udg3]] self._test_scales(udg_array, mask=2)
def test_bd4_flashing(self): # No mask, 6 colours, flashing udg1 = Udg(49, (136,) * 8) # INK 1: PAPER 6 udg2 = Udg(170, (68,) * 8) # INK 2: PAPER 5 udg3 = Udg(35, (34,) * 8) # INK 3: PAPER 4 udg_array = [[udg1, udg2, udg3]] self._test_scales(udg_array)
def test_bd4_cropped(self): # No mask, 5 colours, cropped udg1 = Udg(30, (170,) * 8) # INK 6: PAPER 3 udg2 = Udg(28, (81,) * 8) # INK 4: PAPER 3 udg3 = Udg(5, (129,) * 8) # INK 5: PAPER 0 udg_array = [[udg1, udg2], [udg3, udg1]] self._test_scales(udg_array, x=2, y=1, width=11, height=9)
def test_bd2_cropped_height_less_than_scale(self): # No mask, 3 colours, cropped, height less than scale udg1 = Udg(30, (170,) * 8) # INK 6: PAPER 3 udg2 = Udg(28, (81,) * 8) # INK 4: PAPER 3 udg_array = [[udg1, udg2]] * 2 self._test_image(udg_array, scale=3, y=4, height=1) self._test_image(udg_array, scale=10, y=1, height=1)
def test_bd1_attribute_with_same_ink_and_paper(self): # No mask, 2 colours, 2 UDGs, 2 attributes - one with INK and PAPER the # same colour udg1 = Udg(7, (1,) * 8) # INK 7: PAPER 0 udg2 = Udg(63, (2,) * 8) # INK 7: PAPER 7 udg_array = [[udg1], [udg2]] self._test_image(udg_array)
def test_bd2_cropped_width_less_than_scale(self): # No mask, 3 colours, cropped, width less than scale udg1 = Udg(30, (170,) * 8) # INK 6: PAPER 3 udg2 = Udg(28, (81,) * 8) # INK 4: PAPER 3 udg_array = [[udg1, udg2]] * 2 self._test_image(udg_array, scale=3, x=4, width=1) self._test_image(udg_array, scale=10, x=1, width=1)
def test_option_e_font(self, mock_open): addr = 30000 attr = 5 char1 = Udg(attr, [170] * 8) char2 = Udg(attr, [129] * 8) exp_udgs = [[char1, char2]] chars = len(exp_udgs[0]) scale = 3 x, y = 1, 2 width, height = 40, 19 data = char1.data + char2.data macro = 'FONT{},{},{},{}{{{},{},{},{}}}(ignored.gif)'.format( addr, chars, attr, scale, x, y, width, height) self._test_sna2img(mock_open, '-e {}'.format(macro), data, exp_udgs, scale, 0, x, y, width, height, addr, ftype='sna')
def test_animation_with_frames_of_different_sizes(self): # First frame 16x8, second frame 8x16, third frame 8x8 frame1 = Frame([[Udg(1, (0,) * 8)] * 2]) frame2 = Frame([[Udg(1, (0,) * 8)]] * 2) frame3 = Frame([[Udg(1, (0,) * 8)]]) frames = [frame1, frame2, frame3] self._test_animated_image(frames)
def test_bd4_cropped_flashing(self): # No mask, 6 colours, cropped, flashing udg1 = Udg(129, (0,) * 8) # INK 1: PAPER 0: FLASH 1 udg2 = Udg(147, (255,) * 8) # INK 3: PAPER 2: FLASH 1 udg3 = Udg(165, (0,) * 8) # INK 5: PAPER 4: FLASH 1 udg_array = [[udg1, udg2, udg3]] * 3 self._test_scales(udg_array, x=1, y=2, width=20, height=21)
def test_animation_with_alternative_transparent_colour_on_first_frame_only(self): # White (PAPER) as transparent colour on first frame iw_args = {'options': self.alpha_option} frame1 = Frame([[Udg(56, (15,) * 8)]], tindex=8) frame2 = Frame([[Udg(1, (15,) * 8)]]) frames = [frame1, frame2] self._test_animated_image(frames, iw_args)
def test_eq(self): udg1 = Udg(1, [7] * 8) udg2 = Udg(1, [7] * 8) udg3 = Udg(2, [7] * 8) self.assertTrue(udg1 == udg2) self.assertFalse(udg1 == udg3) self.assertFalse(udg1 == 1)
def test_animation_with_alternative_transparent_colour_on_second_frame_only(self): # Yellow (PAPER) as transparent colour on second frame iw_args = {'options': self.alpha_option} frame1 = Frame([[Udg(56, (15,) * 8)]], tindex=7) frame2 = Frame([[Udg(48, (15,) * 8)]]) frames = [frame1, frame2] self._test_animated_image(frames, iw_args)
def test_bd4_cropped_width_less_than_scale(self): # No mask, 5 colours, cropped, width less than scale udg1 = Udg(30, (170,) * 8) # INK 6: PAPER 3 udg2 = Udg(28, (81,) * 8) # INK 4: PAPER 3 udg3 = Udg(5, (129,) * 8) # INK 5: PAPER 0 udg_array = [[udg1], [udg2], [udg3]] self._test_image(udg_array, scale=3, x=4, width=1) self._test_image(udg_array, scale=10, x=1, width=1)
def test_repr(self): udg1 = Udg(1, [2, 3, 4, 5, 6, 7, 8, 9]) self.assertEqual(repr(udg1), 'Udg(1, [2, 3, 4, 5, 6, 7, 8, 9])') udg2 = Udg(1, [2] * 8, [3, 4, 5, 6, 7, 8, 9, 10]) self.assertEqual( repr(udg2), 'Udg(1, [2, 2, 2, 2, 2, 2, 2, 2], [3, 4, 5, 6, 7, 8, 9, 10])')
def test_animation_with_alternative_transparent_colour_overridden_by_mask(self): # White (PAPER) as transparent colour on first frame, overridden by # mask on second frame iw_args = {'options': self.alpha_option} frame1 = Frame([[Udg(56, (15,) * 8)]], tindex=8) frame2 = Frame([[Udg(56, (15,) * 8, (207,) * 8)]], mask=1) frames = [frame1, frame2] self._test_animated_image(frames, iw_args)
def test_rotate_udgs_with_duplicates(self): base_udg = Udg(1, [2, 3, 5, 7, 11, 13, 17, 19]) udg = base_udg.copy() udgs = [[udg, udg]] rotate_udgs(udgs, 1) udg_r = base_udg.copy() udg_r.rotate(1) self.assertEqual([[udg_r], [udg_r]], udgs)
def test_flip_udgs_with_duplicates(self): base_udg = Udg(1, [2, 3, 5, 7, 11, 13, 17, 19]) udg = base_udg.copy() udgs = [[udg, udg]] flip_udgs(udgs, 1) udg_f = base_udg.copy() udg_f.flip(1) self.assertEqual([[udg_f, udg_f]], udgs)
def test_option_e_font_with_text(self, mock_open): font_addr = 25000 text = 'ab' addr = font_addr + 8 * (ord(text[0]) - 32) char1 = Udg(56, [85] * 8) char2 = Udg(56, [240] * 8) exp_udgs = [[char1, char2]] scale = 2 data = char1.data + char2.data macro = '#FONT:({}){}'.format(text, font_addr) self._test_sna2img(mock_open, '--expand {}'.format(macro), data, exp_udgs, scale, address=addr, ftype='sna')
def test_mask1_cropped_flashing_one_udg_all_transparent(self): # OR-AND mask, cropped, flashing, one UDG all transparent udg1 = Udg(135, (0, ) * 8, (255, ) * 8) udg2 = Udg(184, (240, ) * 8) udg_array = [[udg1, udg2]] self._test_image(udg_array, scale=2, mask=1, x=1, y=1, width=27, height=13)
def parse_udgarray(text, index, snapshot=None, req_fname=True): # #UDGARRAYwidth[,attr,scale,step,inc,flip,rotate,mask];addr[,attr,step,inc][:addr[,step]];...[{x,y,width,height}](fname) names = ('width', 'attr', 'scale', 'step', 'inc', 'flip', 'rotate', 'mask') defaults = (56, 2, 1, 0, 0, 0, 1) end, width, attr, scale, step, inc, flip, rotate, mask = parse_ints(text, index, defaults=defaults, names=names) udg_array = [[]] has_masks = False while end < len(text) and text[end] == ';': names = ('attr', 'step', 'inc') defaults = (attr, step, inc) end, udg_addresses = parse_address_range(text, end + 1, width) if udg_addresses is None: raise MacroParsingError('Expected UDG address range specification: #UDGARRAY{}'.format(text[index:end])) if end < len(text) and text[end] == ',': end, udg_attr, udg_step, udg_inc = parse_ints(text, end + 1, defaults=defaults, names=names) else: udg_attr, udg_step, udg_inc = defaults mask_addresses = [] if end < len(text) and text[end] == ':': end, mask_addresses = parse_address_range(text, end + 1, width) if mask_addresses is None: raise MacroParsingError('Expected mask address range specification: #UDGARRAY{}'.format(text[index:end])) if not mask: mask_addresses = [] if end < len(text) and text[end] == ',': end, mask_step = parse_ints(text, end + 1, defaults=(udg_step,), names=('step',)) else: mask_step = udg_step if snapshot: has_masks = has_masks or len(mask_addresses) > 0 mask_addresses += [None] * (len(udg_addresses) - len(mask_addresses)) for u, m in zip(udg_addresses, mask_addresses): udg_bytes = [(snapshot[u + n * udg_step] + udg_inc) % 256 for n in range(8)] udg = Udg(udg_attr, udg_bytes) if m is not None and mask: udg.mask = [snapshot[m + n * mask_step] for n in range(8)] if len(udg_array[-1]) == width: udg_array.append([udg]) else: udg_array[-1].append(udg) if len(udg_array) > 1 and len(udg_array[-1]) < width: udg_array[-1].extend((FILL_UDG,) * (width - len(udg_array[-1]))) if not has_masks: mask = 0 end, crop_rect = _parse_crop_spec(text, end) end, fname, frame, alt = _parse_image_fname(text, end) if req_fname: if not fname and frame is None: raise MacroParsingError('Missing filename: #UDGARRAY{}'.format(text[index:end])) if not fname and not frame: raise MacroParsingError('Missing filename or frame ID: #UDGARRAY{}'.format(text[index:end])) return end, crop_rect, fname, frame, alt, (udg_array, scale, flip, rotate, mask)
def _shift_graphic(self, graphic, y_delta): attr = graphic[0][0].attr blank_udg = Udg(attr, [0] * 8) width = len(graphic[0]) prev_row = [blank_udg] * width shifted_graphic = [] for row in graphic + [[blank_udg] * width]: shifted_graphic.append([]) for i, udg in enumerate(row): shifted_udg_data = prev_row[i].data[-y_delta:] + udg.data[:-y_delta] shifted_graphic[-1].append(Udg(attr, shifted_udg_data)) prev_row[i] = udg return shifted_graphic
def parse_udgarray(text, index, snapshot=None): # #UDGARRAYwidth[,attr,scale,step,inc,flip,rotate,mask];addr[,attr,step,inc][:addr[,step]];...[{x,y,width,height}](fname) names = ('width', 'attr', 'scale', 'step', 'inc', 'flip', 'rotate', 'mask') defaults = (56, 2, 1, 0, 0, 0, 1) end, width, attr, scale, step, inc, flip, rotate, mask = parse_ints(text, index, defaults=defaults, names=names) udg_array = [[]] has_masks = False while end < len(text) and text[end] == ';': names = ('attr', 'step', 'inc') defaults = (attr, step, inc) end, udg_addresses = parse_address_range(text, end + 1, width) if udg_addresses is None: raise MacroParsingError('Expected UDG address range specification: #UDGARRAY{}'.format(text[index:end])) if end < len(text) and text[end] == ',': end, udg_attr, udg_step, udg_inc = parse_ints(text, end + 1, defaults=defaults, names=names) else: udg_attr, udg_step, udg_inc = defaults mask_addresses = [] if end < len(text) and text[end] == ':': end, mask_addresses = parse_address_range(text, end + 1, width) if mask_addresses is None: raise MacroParsingError('Expected mask address range specification: #UDGARRAY{}'.format(text[index:end])) if not mask: mask_addresses = [] if end < len(text) and text[end] == ',': end, mask_step = parse_ints(text, end + 1, defaults=(udg_step,), names=('step',)) else: mask_step = udg_step if snapshot: has_masks = has_masks or len(mask_addresses) > 0 mask_addresses += [None] * (len(udg_addresses) - len(mask_addresses)) for u, m in zip(udg_addresses, mask_addresses): udg_bytes = [(snapshot[u + n * udg_step] + udg_inc) % 256 for n in range(8)] udg = Udg(udg_attr, udg_bytes) if m is not None and mask: udg.mask = [snapshot[m + n * mask_step] for n in range(8)] if len(udg_array[-1]) == width: udg_array.append([udg]) else: udg_array[-1].append(udg) if len(udg_array) > 1 and len(udg_array[-1]) < width: udg_array[-1].extend((FILL_UDG,) * (width - len(udg_array[-1]))) if not has_masks: mask = 0 end, crop_rect = _parse_crop_spec(text, end) end, fname, frame, alt = _parse_image_fname(text, end) if not fname and frame is None: raise MacroParsingError('Missing filename: #UDGARRAY{}'.format(text[index:end])) if not fname and not frame: raise MacroParsingError('Missing filename or frame ID: #UDGARRAY{}'.format(text[index:end])) return end, crop_rect, fname, frame, alt, (udg_array, scale, flip, rotate, mask)
def __init__(self, attr, data, mask=None, attr_addr=None, q_addr=None, q=None, ref_addr=None, ref=None, udg_page=None, x=None, y=None): BaseUdg.__init__(self, attr, data, mask) self.attr_addr = attr_addr self.q_addr = q_addr self.q = q self.ref_addr = ref_addr # We store the UDG reference now in case the snapshot changes before # the reference is looked up via self.snapshot[udg.ref_addr] (e.g. # because a saved snapshot is restored after alter_skool_udgs() has # been called) self.ref = ref self.udg_page = udg_page self.udg_addr = None if udg_page is None else ref + 256 * udg_page self.x = x self.y = y
def test_copy(self): udg = Udg(23, [1] * 8) replica = udg.copy() self.assertEqual(udg.attr, replica.attr) self.assertEqual(udg.data, replica.data) self.assertEqual(udg.mask, replica.mask) self.assertFalse(udg.data is replica.data) udg = Udg(47, [2] * 8, [3] * 8) replica = udg.copy() self.assertEqual(udg.attr, replica.attr) self.assertEqual(udg.data, replica.data) self.assertEqual(udg.mask, replica.mask) self.assertFalse(udg.data is replica.data) self.assertFalse(udg.mask is replica.mask)
def _tile(self, cwd, tile_index, supertile_index, colour_supertiles, override_bright): """ Tile and supertile index -> Udg. """ if supertile_index < 45: data = 0x8590 # ext tiles 1 attr = ZX_ATTRIBUTE_BRIGHT_YELLOW_OVER_BLACK elif supertile_index < 139 or supertile_index >= 204: data = 0x8A18 # ext tiles 2 attr = ZX_ATTRIBUTE_BRIGHT_GREEN_OVER_BLACK else: data = 0x90F8 # ext tiles 3 attr = ZX_ATTRIBUTE_BRIGHT_CYAN_OVER_BLACK if colour_supertiles == 0: # assume coloured tiles unless off attr = ZX_ATTRIBUTE_WHITE_OVER_BLACK if override_bright is not None: # force bright bit to the specified state attr = (attr & ~ZX_ATTRIBUTE_BRIGHT) | (override_bright * ZX_ATTRIBUTE_BRIGHT) offset = data + tile_index * 8 return Udg(attr, self.snapshot[offset:offset + 8])
def _mask_tile(self, cwd, tile_index): """ Mask tile -> Udg. """ data = 0x8218 attr = 7 a = data + tile_index * 8 return Udg(attr, self.snapshot[a:a + 8])
def test_option_e_udg(self, mock_open): addr = 25000 attr = 4 scale = 3 step = 2 inc = 1 flip = 1 rotate = 2 mask = 1 mask_addr = addr + 8 * step udg = Udg(attr, [239] * 8, [248] * 8) exp_udg = Udg(attr, [b + inc for b in udg.data], udg.mask[:]) exp_udg.flip(flip) exp_udg.rotate(rotate) exp_udgs = [[exp_udg]] data = [0] * (16 * step) data[0:16 * step:step] = udg.data + udg.mask macro = 'UDG{},{},{},{},{},{},{},{}:{}(ignored)'.format(addr, attr, scale, step, inc, flip, rotate, mask, mask_addr) self._test_sna2img(mock_open, '-e {}'.format(macro), data, exp_udgs, scale, mask, address=addr, ftype='sna')
def test_option_e_udgarray(self, mock_open): addr = 24576 attr = 49 scale = 1 step = 3 inc = 2 flip = 2 rotate = 1 mask = 2 mask_addr = addr + 8 * step udg = Udg(attr, [126] * 8, [192] * 8) exp_udg = Udg(attr, [b + inc for b in udg.data], udg.mask[:]) exp_udg.flip(flip) exp_udg.rotate(rotate) exp_udgs = [[exp_udg]] data = [0] * (16 * step) data[0:16 * step:step] = udg.data + udg.mask macro = 'UDGARRAY1,{},{},{},{},{},{},{};{}:{}(ignored)'.format(attr, scale, step, inc, flip, rotate, mask, addr, mask_addr) self._test_sna2img(mock_open, '--expand {}'.format(macro), data, exp_udgs, scale, mask, address=addr, ftype='sna')
def test_rotate_udgs_with_rows_of_different_sizes(self): base_udg1 = Udg(1, [170] * 8) base_udg2 = Udg(2, [85] * 8) udg1 = base_udg1.copy() udg2 = base_udg2.copy() udg1_r1 = Udg(1, [255, 0] * 4) udg2_r1 = Udg(2, [0, 255] * 4) udgs = [[udg1], [udg2, udg1]] rotate_udgs(udgs, 1) self.assertEqual([[udg2_r1, udg1_r1], [udg1_r1]], udgs) udg1 = base_udg1.copy() udg2 = base_udg2.copy() udg1_r3 = Udg(1, [0, 255] * 4) udg2_r3 = Udg(2, [255, 0] * 4) udgs = [[udg1, udg2], [udg2]] rotate_udgs(udgs, 3) self.assertEqual([[udg2_r3], [udg1_r3, udg2_r3]], udgs)
def test_rotate_udgs(self): udg1 = Udg(0, [1, 2, 4, 8, 16, 32, 64, 128], [1, 2, 4, 8, 16, 32, 64, 128]) udg2 = Udg(0, [1, 2, 3, 4, 5, 6, 7, 8], [2, 4, 6, 8, 10, 12, 14, 16]) udg3 = Udg(0, [1, 2, 3, 4, 5, 6, 7, 8], [8, 7, 6, 5, 4, 3, 2, 1]) udg4 = Udg(0, [8, 7, 6, 5, 4, 3, 2, 1], [255, 254, 253, 252, 251, 250, 249, 248]) udgs = [[udg1.copy(), udg2.copy()], [udg3.copy(), udg4.copy()]] rotate_udgs(udgs, 0) self.assertEqual(udgs, [[udg1, udg2], [udg3, udg4]]) udgs = [[udg1.copy(), udg2.copy()], [udg3.copy(), udg4.copy()]] rotate_udgs(udgs, 1) udg1_r, udg2_r, udg3_r, udg4_r = udg1.copy(), udg2.copy(), udg3.copy(), udg4.copy() udg1_r.rotate(1) udg2_r.rotate(1) udg3_r.rotate(1) udg4_r.rotate(1) self.assertEqual(udgs, [[udg3_r, udg1_r], [udg4_r, udg2_r]]) udgs = [[udg1.copy(), udg2.copy()], [udg3.copy(), udg4.copy()]] rotate_udgs(udgs, 2) udg1_r, udg2_r, udg3_r, udg4_r = udg1.copy(), udg2.copy(), udg3.copy(), udg4.copy() udg1_r.rotate(2) udg2_r.rotate(2) udg3_r.rotate(2) udg4_r.rotate(2) self.assertEqual(udgs, [[udg4_r, udg3_r], [udg2_r, udg1_r]]) udgs = [[udg1.copy(), udg2.copy()], [udg3.copy(), udg4.copy()]] rotate_udgs(udgs, 3) udg1_r, udg2_r, udg3_r, udg4_r = udg1.copy(), udg2.copy(), udg3.copy(), udg4.copy() udg1_r.rotate(3) udg2_r.rotate(3) udg3_r.rotate(3) udg4_r.rotate(3) self.assertEqual(udgs, [[udg2_r, udg4_r], [udg1_r, udg3_r]])
def test_rotate(self): udg = Udg(0, [1, 2, 4, 8, 16, 32, 64, 128], [1, 2, 4, 8, 16, 32, 64, 128]) udg.rotate(0) self.assertEqual(udg.data, [1, 2, 4, 8, 16, 32, 64, 128]) self.assertEqual(udg.mask, [1, 2, 4, 8, 16, 32, 64, 128]) udg = Udg(0, [1, 2, 4, 8, 16, 32, 64, 128], [1, 2, 4, 8, 16, 32, 64, 128]) udg.rotate(1) self.assertEqual(udg.data, [128, 64, 32, 16, 8, 4, 2, 1]) self.assertEqual(udg.mask, [128, 64, 32, 16, 8, 4, 2, 1]) udg = Udg(0, [1, 2, 3, 4, 5, 6, 7, 8], [8, 7, 6, 5, 4, 3, 2, 1]) udg.rotate(2) self.assertEqual(udg.data, [16, 224, 96, 160, 32, 192, 64, 128]) self.assertEqual(udg.mask, [128, 64, 192, 32, 160, 96, 224, 16]) udg = Udg(0, [1, 2, 3, 4, 5, 6, 7, 8], [255, 254, 253, 252, 251, 250, 249, 248]) udg.rotate(3) self.assertEqual(udg.data, [170, 102, 30, 1, 0, 0, 0, 0]) self.assertEqual(udg.mask, [170, 204, 240, 255, 255, 255, 255, 255])
def test_flip(self): udg = Udg(0, [1, 2, 4, 8, 16, 32, 64, 128], [1, 2, 4, 8, 16, 32, 64, 128]) udg.flip(0) self.assertEqual(udg.data, [1, 2, 4, 8, 16, 32, 64, 128]) self.assertEqual(udg.mask, [1, 2, 4, 8, 16, 32, 64, 128]) udg = Udg(0, [1, 2, 4, 8, 16, 32, 64, 128], [1, 2, 4, 8, 16, 32, 64, 128]) udg.flip(1) self.assertEqual(udg.data, [128, 64, 32, 16, 8, 4, 2, 1]) self.assertEqual(udg.mask, [128, 64, 32, 16, 8, 4, 2, 1]) udg = Udg(0, [1, 2, 3, 4, 5, 6, 7, 8], [2, 4, 6, 8, 10, 12, 14, 16]) udg.flip(2) self.assertEqual(udg.data, [8, 7, 6, 5, 4, 3, 2, 1]) self.assertEqual(udg.mask, [16, 14, 12, 10, 8, 6, 4, 2]) udg = Udg(0, [1, 2, 3, 4, 5, 6, 7, 8], [8, 7, 6, 5, 4, 3, 2, 1]) udg.flip(3) self.assertEqual(udg.data, [16, 224, 96, 160, 32, 192, 64, 128]) self.assertEqual(udg.mask, [128, 64, 192, 32, 160, 96, 224, 16])
def test_flip_udgs(self): udg1 = Udg(0, [1, 2, 4, 8, 16, 32, 64, 128], [1, 2, 4, 8, 16, 32, 64, 128]) udg2 = Udg(0, [1, 2, 3, 4, 5, 6, 7, 8], [2, 4, 6, 8, 10, 12, 14, 16]) udg3 = Udg(0, [1, 2, 3, 4, 5, 6, 7, 8], [8, 7, 6, 5, 4, 3, 2, 1]) udg4 = Udg(0, [8, 7, 6, 5, 4, 3, 2, 1], [255, 254, 253, 252, 251, 250, 249, 248]) udgs = [[udg1.copy(), udg2.copy()], [udg3.copy(), udg4.copy()]] flip_udgs(udgs, 0) self.assertEqual(udgs, [[udg1, udg2], [udg3, udg4]]) udgs = [[udg1.copy(), udg2.copy()], [udg3.copy(), udg4.copy()]] flip_udgs(udgs, 1) udg1_f, udg2_f, udg3_f, udg4_f = udg1.copy(), udg2.copy(), udg3.copy(), udg4.copy() udg1_f.flip(1) udg2_f.flip(1) udg3_f.flip(1) udg4_f.flip(1) self.assertEqual(udgs, [[udg2_f, udg1_f], [udg4_f, udg3_f]]) udgs = [[udg1.copy(), udg2.copy()], [udg3.copy(), udg4.copy()]] flip_udgs(udgs, 2) udg1_f, udg2_f, udg3_f, udg4_f = udg1.copy(), udg2.copy(), udg3.copy(), udg4.copy() udg1_f.flip(2) udg2_f.flip(2) udg3_f.flip(2) udg4_f.flip(2) self.assertEqual(udgs, [[udg3_f, udg4_f], [udg1_f, udg2_f]]) udgs = [[udg1.copy(), udg2.copy()], [udg3.copy(), udg4.copy()]] flip_udgs(udgs, 3) udg1_f, udg2_f, udg3_f, udg4_f = udg1.copy(), udg2.copy(), udg3.copy(), udg4.copy() udg1_f.flip(3) udg2_f.flip(3) udg3_f.flip(3) udg4_f.flip(3) self.assertEqual(udgs, [[udg4_f, udg3_f], [udg2_f, udg1_f]])