def test_pointer(self): im = hopper() (width, height) = im.size opath = self.tempfile('temp.png') imdib = ImageWin.Dib(im) hdr = BITMAPINFOHEADER() hdr.biSize = ctypes.sizeof(hdr) hdr.biWidth = width hdr.biHeight = height hdr.biPlanes = 1 hdr.biBitCount = 32 hdr.biCompression = BI_RGB hdr.biSizeImage = width * height * 4 hdr.biClrUsed = 0 hdr.biClrImportant = 0 hdc = CreateCompatibleDC(None) pixels = ctypes.c_void_p() dib = CreateDIBSection(hdc, ctypes.byref(hdr), DIB_RGB_COLORS, ctypes.byref(pixels), None, 0) SelectObject(hdc, dib) imdib.expose(hdc) bitmap = serialize_dib(hdr, pixels) DeleteObject(dib) DeleteDC(hdc) Image.open(BytesIO(bitmap)).save(opath)
def test_dib_image(self): # Arrange im = hopper() # Act dib = ImageWin.Dib(im) # Assert self.assertEqual(dib.size, im.size)
def test_dib_mode_string(self): # Arrange mode = "RGBA" size = (128, 128) # Act dib = ImageWin.Dib(mode, size) # Assert self.assertEqual(dib.size, (128, 128))
def test_hwnd(self): # Arrange wnd = 50 # Act hwnd = ImageWin.HWND(wnd) wnd2 = int(hwnd) # Assert self.assertEqual(wnd2, 50)
def test_hdc(self): # Arrange dc = 50 # Act hdc = ImageWin.HDC(dc) dc2 = int(hdc) # Assert self.assertEqual(dc2, 50)
def test_dib_frombytes_tobytes_roundtrip(self): # Arrange # Make two different DIB images im = hopper() dib1 = ImageWin.Dib(im) mode = "RGB" size = (128, 128) dib2 = ImageWin.Dib(mode, size) # Confirm they're different self.assertNotEqual(dib1.tobytes(), dib2.tobytes()) # Act # Make one the same as the using tobytes()/frombytes() test_buffer = dib1.tobytes() dib2.frombytes(test_buffer) # Assert # Confirm they're the same self.assertEqual(dib1.tobytes(), dib2.tobytes())
def test_dib_paste(self): # Arrange im = hopper() mode = "RGBA" size = (128, 128) dib = ImageWin.Dib(mode, size) # Act dib.paste(im) # Assert self.assertEqual(dib.size, (128, 128))