def test_getdata(self): # test getheader/getdata against legacy values # Create a 'P' image with holes in the palette im = Image._wedge().resize((16, 16)) im.putpalette(ImagePalette.ImagePalette('RGB')) im.info = {'background': 0} passed_palette = bytes(bytearray([255 - i // 3 for i in range(768)])) GifImagePlugin._FORCE_OPTIMIZE = True try: h = GifImagePlugin.getheader(im, passed_palette) d = GifImagePlugin.getdata(im) import pickle # Enable to get target values on pre-refactor version # with open('Tests/images/gif_header_data.pkl', 'wb') as f: # pickle.dump((h, d), f, 1) with open('Tests/images/gif_header_data.pkl', 'rb') as f: (h_target, d_target) = pickle.load(f) self.assertEqual(h, h_target) self.assertEqual(d, d_target) finally: GifImagePlugin._FORCE_OPTIMIZE = False
def wedge(self): w = Image._wedge() w90 = w.rotate(90) (px, h) = w.size r = Image.new('L', (px * 3, h)) g = r.copy() b = r.copy() r.paste(w, (0, 0)) r.paste(w90, (px, 0)) g.paste(w90, (0, 0)) g.paste(w, (2 * px, 0)) b.paste(w, (px, 0)) b.paste(w90, (2 * px, 0)) img = Image.merge('RGB', (r, g, b)) # print(("%d, %d -> "% (int(1.75*px),int(.25*px))) + \ # "(%s, %s, %s)"%img.getpixel((1.75*px, .25*px))) # print(("%d, %d -> "% (int(.75*px),int(.25*px))) + \ # "(%s, %s, %s)"%img.getpixel((.75*px, .25*px))) return img
def test_getdata(): # Test getheader/getdata against legacy values. # Create a 'P' image with holes in the palette. im = Image._wedge().resize((16, 16), Image.NEAREST) im.putpalette(ImagePalette.ImagePalette("RGB")) im.info = {"background": 0} passed_palette = bytes([255 - i // 3 for i in range(768)]) GifImagePlugin._FORCE_OPTIMIZE = True try: h = GifImagePlugin.getheader(im, passed_palette) d = GifImagePlugin.getdata(im) import pickle # Enable to get target values on pre-refactor version # with open('Tests/images/gif_header_data.pkl', 'wb') as f: # pickle.dump((h, d), f, 1) with open("Tests/images/gif_header_data.pkl", "rb") as f: (h_target, d_target) = pickle.load(f) assert h == h_target assert d == d_target finally: GifImagePlugin._FORCE_OPTIMIZE = False
def wedge(self): w = Image._wedge() w90 = w.rotate(90) (px, h) = w.size r = Image.new('L', (px*3, h)) g = r.copy() b = r.copy() r.paste(w, (0, 0)) r.paste(w90, (px, 0)) g.paste(w90, (0, 0)) g.paste(w, (2*px, 0)) b.paste(w, (px, 0)) b.paste(w90, (2*px, 0)) img = Image.merge('RGB', (r, g, b)) # print (("%d, %d -> "% (int(1.75*px),int(.25*px))) + \ # "(%s, %s, %s)"%img.getpixel((1.75*px, .25*px))) # print (("%d, %d -> "% (int(.75*px),int(.25*px))) + \ # "(%s, %s, %s)"%img.getpixel((.75*px, .25*px))) return img
def test_getdata(self): # test getheader/getdata against legacy values # Create a 'P' image with holes in the palette im = Image._wedge().resize((16, 16)) im.putpalette(ImagePalette.ImagePalette('RGB')) im.info = {'background': 0} passed_palette = bytes(bytearray([255-i//3 for i in range(768)])) GifImagePlugin._FORCE_OPTIMIZE = True try: h = GifImagePlugin.getheader(im, passed_palette) d = GifImagePlugin.getdata(im) import pickle # Enable to get target values on pre-refactor version # with open('Tests/images/gif_header_data.pkl', 'wb') as f: # pickle.dump((h, d), f, 1) with open('Tests/images/gif_header_data.pkl', 'rb') as f: (h_target, d_target) = pickle.load(f) self.assertEqual(h, h_target) self.assertEqual(d, d_target) finally: GifImagePlugin._FORCE_OPTIMIZE = False
def wedge(self): w = Image._wedge() w90 = w.rotate(90) (px, h) = w.size r = Image.new("L", (px * 3, h)) g = r.copy() b = r.copy() r.paste(w, (0, 0)) r.paste(w90, (px, 0)) g.paste(w90, (0, 0)) g.paste(w, (2 * px, 0)) b.paste(w, (px, 0)) b.paste(w90, (2 * px, 0)) img = Image.merge("RGB", (r, g, b)) return img
def wedge(self): w = Image._wedge() w90 = w.rotate(90) (px, h) = w.size r = Image.new('L', (px*3, h)) g = r.copy() b = r.copy() r.paste(w, (0, 0)) r.paste(w90, (px, 0)) g.paste(w90, (0, 0)) g.paste(w, (2*px, 0)) b.paste(w, (px, 0)) b.paste(w90, (2*px, 0)) img = Image.merge('RGB', (r, g, b)) return img