Ejemplo n.º 1
0
 def test_sorted_chr_page(self):
   data = bytes(bytearray(range(64)))
   input = data[16:32] + data[48:64] + data[32:48] + data[48:64] + data[0:16]
   spage = chr_data.SortableChrPage.from_binary(input)
   self.assertEqual(spage.size(), 5)
   self.assertEqual(spage.num_idx(), 4)
   self.assertFalse(spage.is_full())
   self.assertEqual(spage.idx, [4,0,2,1])
   self.assertEqual(spage.index(0), 4)
   expect_tile = chr_data.ChrTile()
   expect_tile.set(bytes(bytearray(range(0,16))))
   self.assertEqual(spage.get(4), expect_tile)
   self.assertEqual(spage.k_smallest(0), expect_tile)
Ejemplo n.º 2
0
    def build_tile(self, xlat, did):
        """Lookup dot_profile, and translate it to create tile.

    xlat: Dot translator.
    did: Id for the dot profile.
    """
        dot_profile = self._dot_manifest.at(did)
        tile = chr_data.ChrTile()
        for row in xrange(8):
            for col in xrange(8):
                i = row * 8 + col
                val = xlat[dot_profile[i]]
                tile.put_pixel(row, col, val)
        return tile
Ejemplo n.º 3
0
 def test_flip(self):
   empty = [0] * 8
   origin = [0,1,2,3,4,5,6,7]
   golden = [0x00,0x80,0x40,0xc0,0x20,0xa0,0x60,0xe0]
   tile = chr_data.ChrTile()
   tile.set(bytes(bytearray(origin + empty)))
   horz = tile.flip('h')
   self.assertEqual(horz.low, golden)
   self.assertEqual(horz.hi, empty)
   vert = tile.flip('v')
   self.assertEqual(vert.low, origin[::-1])
   self.assertEqual(vert.hi, empty)
   spin = tile.flip('vh')
   self.assertEqual(spin.low, golden[::-1])
   self.assertEqual(spin.hi, empty)
Ejemplo n.º 4
0
 def build_tile_from_pixels_ignoring_unknown(self, tile_pixels, popt):
   pixels = tile_pixels.load()
   tile = chr_data.ChrTile()
   for row in range(8):
     for col in range(8):
       i = row * 8 + col
       p = pixels[col, row]
       color_val = (p[0] << 16) + (p[1] << 8) + p[2]
       if color_val in rgb.RGB_XLAT:
         nc = rgb.RGB_XLAT[color_val]
       else:
         nc = self.components_to_nescolor(p[0], p[1], p[2])
         if nc == -1:
           raise errors.CouldntConvertRGB(p, tile_y, tile_x, i, j)
       try:
         val = popt.index(nc)
       except ValueError:
         val = 0
       tile.put_pixel(row, col, val)
   return tile
Ejemplo n.º 5
0
 def test_put_pixel_get_pixel(self):
   tile = chr_data.ChrTile()
   self.assertEqual(tile.get_pixel(3, 4), 0)
   tile.put_pixel(3, 4, 1)
   self.assertEqual(tile.get_pixel(3, 4), 1)
Ejemplo n.º 6
0
 def test_set_get_pixel(self):
   tile = chr_data.ChrTile()
   tile.set(bytes(bytearray([0,1,2,3,4,5,6,7] + ([0] * 8))))
   self.assertEqual(tile.get_pixel(4, 5), 1)
Ejemplo n.º 7
0
 def test_set_bytes_to_low_hi(self):
   tile = chr_data.ChrTile()
   tile.set(bytes(bytearray([0,1,2,3,4,5,6,7] + ([0] * 8))))
   self.assertEqual(tile.low, [0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07])
   self.assertEqual(tile.hi,  [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00])