Пример #1
0
    def test_average_luminosity(self):
        img = HdrImage(2, 1)

        img.set_pixel(0, 0, Color(0.5e1, 1.0e1, 1.5e1))
        img.set_pixel(1, 0, Color(0.5e3, 1.0e3, 1.5e3))

        assert pytest.approx(100.0) == img.average_luminosity(delta=0.0)
Пример #2
0
    def test_normalize_image(self):
        img = HdrImage(2, 1)

        img.set_pixel(0, 0, Color(0.5e1, 1.0e1, 1.5e1))
        img.set_pixel(1, 0, Color(0.5e3, 1.0e3, 1.5e3))

        img.normalize_image(factor=1000.0, luminosity=100.0)
        assert img.get_pixel(0, 0).is_close(Color(0.5e2, 1.0e2, 1.5e2))
        assert img.get_pixel(1, 0).is_close(Color(0.5e4, 1.0e4, 1.5e4))
Пример #3
0
    def test_clamp_image(self):
        img = HdrImage(2, 1)

        img.set_pixel(0, 0, Color(0.5e1, 1.0e1, 1.5e1))
        img.set_pixel(1, 0, Color(0.5e3, 1.0e3, 1.5e3))

        img.clamp_image()

        for cur_pixel in img.pixels:
            assert (cur_pixel.r >= 0) and (cur_pixel.r <= 1)
            assert (cur_pixel.g >= 0) and (cur_pixel.g <= 1)
            assert (cur_pixel.b >= 0) and (cur_pixel.b <= 1)
Пример #4
0
    def testImagePigment(self):
        image = HdrImage(width=2, height=2)
        image.set_pixel(0, 0, Color(1.0, 2.0, 3.0))
        image.set_pixel(1, 0, Color(2.0, 3.0, 1.0))
        image.set_pixel(0, 1, Color(2.0, 1.0, 3.0))
        image.set_pixel(1, 1, Color(3.0, 2.0, 1.0))

        pigment = ImagePigment(image)
        assert pigment.get_color(Vec2d(0.0,
                                       0.0)).is_close(Color(1.0, 2.0, 3.0))
        assert pigment.get_color(Vec2d(1.0,
                                       0.0)).is_close(Color(2.0, 3.0, 1.0))
        assert pigment.get_color(Vec2d(0.0,
                                       1.0)).is_close(Color(2.0, 1.0, 3.0))
        assert pigment.get_color(Vec2d(1.0,
                                       1.0)).is_close(Color(3.0, 2.0, 1.0))
Пример #5
0
    def test_pfm_save(self):
        img = HdrImage(3, 2)

        img.set_pixel(0, 0, Color(1.0e1, 2.0e1, 3.0e1))
        img.set_pixel(1, 0, Color(4.0e1, 5.0e1, 6.0e1))
        img.set_pixel(2, 0, Color(7.0e1, 8.0e1, 9.0e1))
        img.set_pixel(0, 1, Color(1.0e2, 2.0e2, 3.0e2))
        img.set_pixel(1, 1, Color(4.0e2, 5.0e2, 6.0e2))
        img.set_pixel(2, 1, Color(7.0e2, 8.0e2, 9.0e2))

        le_buf = BytesIO()
        img.write_pfm(le_buf, endianness=Endianness.LITTLE_ENDIAN)
        assert le_buf.getvalue() == LE_REFERENCE_BYTES

        be_buf = BytesIO()
        img.write_pfm(be_buf, endianness=Endianness.BIG_ENDIAN)
        assert be_buf.getvalue() == BE_REFERENCE_BYTES
Пример #6
0
    def test_get_set_pixel(self):
        img = HdrImage(7, 4)

        reference_color = Color(1.0, 2.0, 3.0)
        img.set_pixel(3, 2, reference_color)
        assert reference_color.is_close(img.get_pixel(3, 2))