hahah
This commit is contained in:
1 parent
aff3ef22ab
commit
a3722c4d6b
2 files changed
+10
-12
No files matched your search
@@ -9,7 +9,7 @@ from visual_cryptography.visual_cryptography import ImageLayer, produce_image_la
|
|||||||
|
|
||||||
class TestImageLayer(TestCase):
|
class TestImageLayer(TestCase):
|
||||||
test_data = b'000001000100101010000100040028010000160000002800000010000000200000000100040000000000800000000000000000000000100000000000000000000000FF84000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111111111100000010000000010000001000000001000000000000000000000000000000000000000000000000000000000000000000000011100001110000001110000111000000111000011100000000000000000000000000000000000FFFF0000FFFF0000FFFF0000FFFF0000E0070000EFF70000EFF70000FFFF0000FFFF0000FFFF0000FFFF0000E3C70000E3C70000E3C70000FFFF0000FFFF0000'
|
test_data = b'000001000100101010000100040028010000160000002800000010000000200000000100040000000000800000000000000000000000100000000000000000000000FF84000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111111111100000010000000010000001000000001000000000000000000000000000000000000000000000000000000000000000000000011100001110000001110000111000000111000011100000000000000000000000000000000000FFFF0000FFFF0000FFFF0000FFFF0000E0070000EFF70000EFF70000FFFF0000FFFF0000FFFF0000FFFF0000E3C70000E3C70000E3C70000FFFF0000FFFF0000'
|
||||||
|
|
||||||
def get_test_image(self):
|
def get_test_image(self):
|
||||||
return BytesIO(b16decode(self.test_data))
|
return BytesIO(b16decode(self.test_data))
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ class TestImageLayer(TestCase):
|
|||||||
def test_produce_image_layer_from_real_image(self):
|
def test_produce_image_layer_from_real_image(self):
|
||||||
img = produce_image_layer_from_real_image(self.get_test_image())
|
img = produce_image_layer_from_real_image(self.get_test_image())
|
||||||
self.assertEqual(img.data[2][3], 0)
|
self.assertEqual(img.data[2][3], 0)
|
||||||
self.assertEqual(img.data[0][0], 1)
|
self.assertEqual(img.data[0][0], 0)
|
||||||
|
|
||||||
|
|
||||||
def test_get_empty_data(self):
|
def test_get_empty_data(self):
|
||||||
@@ -29,13 +29,13 @@ class TestImageLayer(TestCase):
|
|||||||
def test_produce_empty_shares(self):
|
def test_produce_empty_shares(self):
|
||||||
img = ImageLayer(5, 6)
|
img = ImageLayer(5, 6)
|
||||||
ret = img.produce_empty_shares()
|
ret = img.produce_empty_shares()
|
||||||
|
|
||||||
two_shares = 2
|
two_shares = 2
|
||||||
self.assertEqual(len(ret), two_shares)
|
self.assertEqual(len(ret), two_shares)
|
||||||
|
|
||||||
ten_pixels_width = 10
|
ten_pixels_width = 10
|
||||||
self.assertEqual(len(ret[0]), ten_pixels_width)
|
self.assertEqual(len(ret[0]), ten_pixels_width)
|
||||||
|
|
||||||
twelve_pixels_height = 12
|
twelve_pixels_height = 12
|
||||||
self.assertEqual(len(ret[0][0]), twelve_pixels_height)
|
self.assertEqual(len(ret[0][0]), twelve_pixels_height)
|
||||||
|
|
||||||
@@ -43,19 +43,19 @@ class TestImageLayer(TestCase):
|
|||||||
def test_place_sub_pixels_in_shares_position(self):
|
def test_place_sub_pixels_in_shares_position(self):
|
||||||
img = ImageLayer(2, 3)
|
img = ImageLayer(2, 3)
|
||||||
shares = img.produce_empty_shares()
|
shares = img.produce_empty_shares()
|
||||||
|
|
||||||
c = [[1, 1, 1, 1],[1, 1, 1, 1]]
|
c = [[1, 1, 1, 1],[1, 1, 1, 1]]
|
||||||
img.place_sub_pixels_in_shares(1,1, shares, c)
|
img.place_sub_pixels_in_shares(1,1, shares, c)
|
||||||
|
|
||||||
self.assertListEqual(shares[0][0].tolist(), [0,0,0,0,0,0])
|
self.assertListEqual(shares[0][0].tolist(), [0,0,0,0,0,0])
|
||||||
self.assertListEqual(shares[0][1].tolist(), [0,0,0,0,0,0])
|
self.assertListEqual(shares[0][1].tolist(), [0,0,0,0,0,0])
|
||||||
self.assertListEqual(shares[0][2].tolist(), [0,0,1,1,0,0])
|
self.assertListEqual(shares[0][2].tolist(), [0,0,1,1,0,0])
|
||||||
self.assertListEqual(shares[0][3].tolist(), [0,0,1,1,0,0])
|
self.assertListEqual(shares[0][3].tolist(), [0,0,1,1,0,0])
|
||||||
|
|
||||||
def test_place_sub_pixels_in_shares(self):
|
def test_place_sub_pixels_in_shares(self):
|
||||||
img = ImageLayer(2, 3)
|
img = ImageLayer(2, 3)
|
||||||
shares = img.produce_empty_shares()
|
shares = img.produce_empty_shares()
|
||||||
|
|
||||||
c = [[1, 0, 0, 1],[0, 1, 0, 1]]
|
c = [[1, 0, 0, 1],[0, 1, 0, 1]]
|
||||||
img.place_sub_pixels_in_shares(1,1, shares, c)
|
img.place_sub_pixels_in_shares(1,1, shares, c)
|
||||||
self.assertListEqual(shares[0][0].tolist(), [0,0,0,0,0,0])
|
self.assertListEqual(shares[0][0].tolist(), [0,0,0,0,0,0])
|
||||||
@@ -66,7 +66,7 @@ class TestImageLayer(TestCase):
|
|||||||
def test_get_pixel_value_in_share(self):
|
def test_get_pixel_value_in_share(self):
|
||||||
img = ImageLayer(10, 10)
|
img = ImageLayer(10, 10)
|
||||||
share = img.produce_empty_shares()[0]
|
share = img.produce_empty_shares()[0]
|
||||||
|
|
||||||
pixel = [1, 2, 3, 4]
|
pixel = [1, 2, 3, 4]
|
||||||
img.place_sub_pixels_in_shares(3,1, [share], [pixel])
|
img.place_sub_pixels_in_shares(3,1, [share], [pixel])
|
||||||
self.assertEqual(pixel, img.get_pixel_value_in_share(3,1, share))
|
self.assertEqual(pixel, img.get_pixel_value_in_share(3,1, share))
|
||||||
|
|||||||
@@ -114,11 +114,9 @@ def cmyk_to_black_and_white(r, g, b, a):
|
|||||||
def produce_image_layer_from_real_image(image_path):
|
def produce_image_layer_from_real_image(image_path):
|
||||||
im = Image.open(image_path).convert('RGBA')
|
im = Image.open(image_path).convert('RGBA')
|
||||||
ret = ImageLayer(*im.size)
|
ret = ImageLayer(*im.size)
|
||||||
d = {}
|
|
||||||
for i in range(im.size[0]):
|
for i in range(im.size[0]):
|
||||||
for j in range(im.size[1]):
|
for j in range(im.size[1]):
|
||||||
r, g, b, a = im.im.getpixel((i,j))
|
r, g, b, a = im.im.getpixel((i,j))
|
||||||
d[(r, g, b, a)] = cmyk_to_black_and_white(r, g, b, a)
|
|
||||||
ret.data[j][i] = cmyk_to_black_and_white(r, g, b, a)
|
ret.data[j][i] = cmyk_to_black_and_white(r, g, b, a)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user