示例#1
0
    def test_all_modes_correctness(self):
        """Test that all modes work the way they advertise"""
        # Test each mode in turn
        for mode in xrange(mypaintlib.NumCombineModes):
            mode_info = mypaintlib.combine_mode_get_info(mode)
            mode_name = mode_info["name"]

            src = self.src
            dst = np.empty((N, N, 4), dtype='uint16')
            dst[...] = self.dst_orig[...]

            # Combine using the current mode
            mypaintlib.tile_combine(mode, src, dst, True, 1.0)

            # Tests
            zero_alpha_has_effect = False
            zero_alpha_clears_backdrop = True  # means: "*always* clears b."
            can_decrease_alpha = False
            for i in xrange(len(self.sample_data)):
                for j in xrange(len(self.sample_data)):
                    old = tuple(self.dst_orig[i, j])
                    new = tuple(dst[i, j])
                    if src[i][j][3] == 0:
                        if new[3] != 0 and old[3] != 0:
                            zero_alpha_clears_backdrop = False
                        if old != new:
                            zero_alpha_has_effect = True
                    if (not can_decrease_alpha) and (new[3] < old[3]):
                        can_decrease_alpha = True
                    self.assertFalse(
                        (new[0] > new[3] or new[1] > new[3]
                         or new[2] > new[3]),
                        msg="%s isn't writing premultiplied data properly" %
                        (mode_name, ),
                    )
                    self.assertFalse(
                        (new[0] > FIX15_ONE or new[1] > FIX15_ONE
                         or new[2] > FIX15_ONE or new[3] > FIX15_ONE),
                        msg="%s isn't writing fix15 data properly" %
                        (mode_name, ),
                    )

            flag_test_results = [
                ("zero_alpha_has_effect", zero_alpha_has_effect),
                ("zero_alpha_clears_backdrop", zero_alpha_clears_backdrop),
                ("can_decrease_alpha", can_decrease_alpha),
            ]
            for info_str, tested_value in flag_test_results:
                current_value = bool(mode_info[info_str])
                self.assertEqual(
                    current_value,
                    tested_value,
                    msg="%s's %r is wrong: should be %r, not %r" %
                    (mode_name, info_str, tested_value, current_value),
                )
            self.assertTrue(
                mode in MODE_STRINGS,
                msg="%s needs localizable UI strings" % (mode_name, ),
            )
示例#2
0
    def test_all_modes_correctness(self):
        """Test that all modes work the way they advertise"""
        # Test each mode in turn
        for mode in xrange(mypaintlib.NumCombineModes):
            mode_info = mypaintlib.combine_mode_get_info(mode)
            mode_name = mode_info["name"]

            src = self.src
            dst = np.empty((N, N, 4), dtype='uint16')
            dst[...] = self.dst_orig[...]

            # Combine using the current mode
            mypaintlib.tile_combine(mode, src, dst, True, 1.0)

            # Tests
            zero_alpha_has_effect = False
            zero_alpha_clears_backdrop = True  # means: "*always* clears b."
            can_decrease_alpha = False
            for i in xrange(len(self.sample_data)):
                for j in xrange(len(self.sample_data)):
                    old = tuple(self.dst_orig[i, j])
                    new = tuple(dst[i, j])
                    if src[i][j][3] == 0:
                        if new[3] != 0 and old[3] != 0:
                            zero_alpha_clears_backdrop = False
                        if old != new:
                            zero_alpha_has_effect = True
                    if (not can_decrease_alpha) and (new[3] < old[3]):
                        can_decrease_alpha = True
                    self.assertFalse(
                        (new[0] > new[3] or
                         new[1] > new[3] or
                         new[2] > new[3]),
                        msg="%s isn't writing premultiplied data properly"
                            % (mode_name,),
                    )
                    self.assertFalse(
                        (new[0] > FIX15_ONE or new[1] > FIX15_ONE or
                         new[2] > FIX15_ONE or new[3] > FIX15_ONE),
                        msg="%s isn't writing fix15 data properly"
                            % (mode_name,),
                    )

            flag_test_results = [
                ("zero_alpha_has_effect", zero_alpha_has_effect),
                ("zero_alpha_clears_backdrop", zero_alpha_clears_backdrop),
                ("can_decrease_alpha", can_decrease_alpha),
            ]
            for info_str, tested_value in flag_test_results:
                current_value = bool(mode_info[info_str])
                self.assertEqual(
                    current_value, tested_value,
                    msg="%s's %r is wrong: should be %r, not %r"
                        % (mode_name, info_str, tested_value, current_value),
                )
            self.assertTrue(
                mode in MODE_STRINGS,
                msg="%s needs localizable UI strings" % (mode_name,),
            )
示例#3
0
    assert b1 <= a1
    for j in xrange(len(SAMPLE_DATA)):
        src[i, j, :] = (r1, g1, b1, a1)
        dst_orig[j, i, :] = (r1, g1, b1, a1)

# Test each mode in turn
for mode in xrange(mypaintlib.NumCombineModes):
    mode_info = mypaintlib.combine_mode_get_info(mode)
    mode_name = mode_info["name"]
    print mode_name,

    dst = numpy.empty((N, N, 4), dtype='uint16')
    dst[...] = dst_orig[...]

    # Combine using the current mode
    mypaintlib.tile_combine(mode, src, dst, True, 1.0)

    # Tests
    all_ok = True
    zero_alpha_has_effect = False
    can_decrease_alpha = False
    for i in xrange(len(SAMPLE_DATA)):
        for j in xrange(len(SAMPLE_DATA)):
            old = tuple(dst_orig[i, j])
            new = tuple(dst[i, j])
            if (not zero_alpha_has_effect) and (src[i][j][3] == 0):
                if old != new:
                    zero_alpha_has_effect = True
            if (not can_decrease_alpha) and (new[3] < old[3]):
                can_decrease_alpha = True
            if all_ok:
示例#4
0
    assert b1 <= a1
    for j in xrange(len(SAMPLE_DATA)):
        src[i, j, :] = (r1, g1, b1, a1)
        dst_orig[j, i, :] = (r1, g1, b1, a1)

# Test each mode in turn
for mode in xrange(mypaintlib.NumCombineModes):
    mode_info = mypaintlib.combine_mode_get_info(mode)
    mode_name = mode_info["name"]
    print mode_name,

    dst = numpy.empty((N, N, 4), dtype='uint16')
    dst[...] = dst_orig[...]

    # Combine using the current mode
    mypaintlib.tile_combine(mode, src, dst, True, 1.0)

    # Tests
    all_ok = True
    zero_alpha_has_effect = False
    can_decrease_alpha = False
    for i in xrange(len(SAMPLE_DATA)):
        for j in xrange(len(SAMPLE_DATA)):
            old = tuple(dst_orig[i, j])
            new = tuple(dst[i, j])
            if (not zero_alpha_has_effect) and (src[i][j][3] == 0):
                if old != new:
                    zero_alpha_has_effect = True
            if (not can_decrease_alpha) and (new[3] < old[3]):
                can_decrease_alpha = True
            if all_ok: