def test_image_to_bitmap(self): qimage = QImage(32, 64, QImage.Format.Format_RGB32) qimage.fill(QColor(0x44, 0x88, 0xcc)) qpixmap = image_to_bitmap(qimage) self.assertIsInstance(qpixmap, QPixmap)
def test_resize_image_expand(self): qimage = QImage(32, 64, QImage.Format.Format_RGB32) qimage.fill(QColor(0x44, 0x88, 0xcc)) qimage = resize_image(qimage, (128, 128), AspectRatio.keep_expand) self.assertIsInstance(qimage, QImage) self.assertEqual(qimage.width(), 128) self.assertEqual(qimage.height(), 256)
def test_resize_image_smooth(self): qimage = QImage(32, 64, QImage.Format.Format_RGB32) qimage.fill(QColor(0x44, 0x88, 0xcc)) qimage = resize_image(qimage, (128, 128), mode=ScaleMode.smooth) self.assertIsInstance(qimage, QImage) self.assertEqual(qimage.width(), 128) self.assertEqual(qimage.height(), 128)
def test_image_to_array_rgba(self): qimage = QImage(32, 64, QImage.Format.Format_ARGB32) qimage.fill(QColor(0x44, 0x88, 0xcc, 0xee)) array = image_to_array(qimage) self.assertEqual(array.shape, (64, 32, 4)) self.assertEqual(array.dtype, np.dtype('uint8')) self.assertTrue(np.all(array[:, :, 0] == 0x44)) self.assertTrue(np.all(array[:, :, 1] == 0x88)) self.assertTrue(np.all(array[:, :, 2] == 0xcc)) self.assertTrue(np.all(array[:, :, 3] == 0xee))
def test_image_to_array_bad(self): qimage = QImage(32, 64, QImage.Format.Format_RGB30) qimage.fill(QColor(0x44, 0x88, 0xcc)) with self.assertRaises(ValueError): image_to_array(qimage)