def test_raw_rgb32(): qimg = QtGui.QImage(320, 240, QtGui.QImage.Format_RGB32) qimg.fill(0) v = qimage2ndarray.raw_view(qimg) qimg.fill(23) qimg.setPixel(12, 10, 42) assert_equal(v.shape, (240, 320)) assert_equal(v[10,10], 23 | 0xff000000) assert_equal(v[10,12], 42 | 0xff000000) assert_equal(v.nbytes, numBytes(qimg))
def test_raw_rgba64(): qimg = QtGui.QImage(320, 240, QtGui.QImage.Format_RGBA64) qimg.fill(0) v = qimage2ndarray.raw_view(qimg) qimg.fill(1) qimg.setPixel(12, 10, QtGui.qRgb(0x12, 0x34, 0x56)) assert_equal(v.shape, (240, 320)) assert_equal(v[10, 10], 0x010100000000) assert_equal(v[10, 12], 0xffff565634341212) assert_equal(v.nbytes, numBytes(qimg))
def test_raw_grayscale8(): qimg = QtGui.QImage(320, 240, QtGui.QImage.Format_Grayscale8) qimg.fill(0) v = qimage2ndarray.raw_view(qimg) qimg.fill(1) qimg.setPixel(12, 10, QtGui.qRgb(42, 42, 42)) assert_equal(v.shape, (240, 320)) assert_equal(v[10, 10], 1) assert_equal(v[10, 12], 42) assert_equal(v.nbytes, numBytes(qimg))
def test_raw_rgb16(): qimg = QtGui.QImage(320, 240, QtGui.QImage.Format_RGB16) qimg.fill(0) v = qimage2ndarray.raw_view(qimg) qimg.fill(23) qimg.setPixel(12, 10, QtGui.qRgb(0, 0, 91)) assert_equal(v.shape, (240, 320)) assert_equal(v[10, 10], 23) assert_equal(v[10, 12], 91 >> 3) assert_equal(v.nbytes, numBytes(qimg))
def test_raw_indexed8(): qimg = QtGui.QImage(320, 240, QtGui.QImage.Format_Indexed8) setNumColors(qimg, 256) qimg.fill(0) v = qimage2ndarray.raw_view(qimg) qimg.fill(23) qimg.setPixel(12, 10, 42) assert_equal(v.shape, (240, 320)) assert_equal(v[10,10], 23) assert_equal(v[10,12], 42) assert_equal(v.nbytes, numBytes(qimg))
def test_raw_view(): for filename in all_test_images: assert isinstance(qimage2ndarray.raw_view(filename), numpy.ndarray)
def test_gray2qimage_normalize_dont_touch_0_255(): a = numpy.zeros((100, 256), dtype = float) a[:] = numpy.arange(256) qImg = qimage2ndarray.gray2qimage(a, normalize = True) b = qimage2ndarray.raw_view(qImg) assert numpy.all(a == b)