Skip to content

Commit f5a7a9a

Browse files
authored
Merge pull request #1994 from avaxar/fix-color-swizzling
Fix color swizzling as per request in #1989
2 parents 21a1884 + 63b82fa commit f5a7a9a

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

docs/reST/ref/color.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424

2525
Color objects support swizzling for their ``RGBA`` attributes, which allows
2626
the creation of new color objects with the corresponding swizzled attributes
27-
as its ``RGBA`` attributes. For example, ``color.bgr`` provides a shortcut to
28-
doing ``Color(color.b, color.g, color.r)``. Swizzling with 2 or more than 4
29-
attributes will return a tuple consisting of the corresponding elements
27+
as its ``RGBA`` attributes. For example, ``color.bgra`` provides a shortcut to
28+
doing ``Color(color.b, color.g, color.r, color.a)``. Swizzling with other than
29+
4 attributes will return a tuple consisting of the corresponding elements
3030
instead of a color object.
3131

3232
Color objects support equality comparison with other color objects and 3 or

src_c/color.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,8 +2079,8 @@ _color_getAttr_swizzle(pgColorObject *self, PyObject *attr_name)
20792079
goto swizzle_failed;
20802080
}
20812081

2082-
if (len == 3 || len == 4) {
2083-
static Uint8 rgba[] = {0, 0, 0, 255};
2082+
if (len == 4) {
2083+
static Uint8 rgba[4];
20842084
res = (PyObject *)pgColor_New(rgba);
20852085
}
20862086
else {
@@ -2117,7 +2117,7 @@ _color_getAttr_swizzle(pgColorObject *self, PyObject *attr_name)
21172117
goto swizzle_failed;
21182118
}
21192119

2120-
if (len == 3 || len == 4) {
2120+
if (len == 4) {
21212121
((pgColorObject *)res)->data[i] = value;
21222122
}
21232123
else {

test/color_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ def test_swizzle_get(self):
12091209
def test_swizzle_return_types(self):
12101210
c = pygame.color.Color(10, 20, 30, 40)
12111211

1212-
self.assertEqual(type(c.rgb), pygame.color.Color)
1212+
self.assertEqual(type(c.rgb), tuple)
12131213
self.assertEqual(type(c.rgba), pygame.color.Color)
12141214
self.assertEqual(type(c.bgra), pygame.color.Color)
12151215
self.assertEqual(type(c.bg), tuple)

0 commit comments

Comments
 (0)