Skip to content

Commit 626f72c

Browse files
authored
Remove RGBa -> RGB conversion (#67)
Pillow `9.4.0` should support this
1 parent a839c84 commit 626f72c

File tree

5 files changed

+1
-78
lines changed

5 files changed

+1
-78
lines changed

docs/image-modes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,4 @@ Modes with premultiplied Alpha:
7878
* ``RGBa;12`` --> ``RGBa;16`` or ``BGRa;16``
7979
* ``RGBa;10`` --> ``RGBa;16`` or ``BGRa;16``
8080
* ``BGRa`` --> ``RGBa``
81-
* ``RGBa`` --> ``RGB``, ``BGR``, ``RGBa;16`` or ``BGRa;16``
81+
* ``RGBa`` --> ``BGRa``, ``RGBa;16`` or ``BGRa;16``

pillow_heif/helpers.c

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -484,44 +484,6 @@ void convert_bgr_rgb(const uint8_t *in, int in_stride, uint8_t *out, int out_str
484484
}
485485
}
486486

487-
void convert_rgba_premultiplied_to_rgb(const uint8_t *in, int in_stride, uint8_t *out, int out_stride, int n_rows)
488-
{
489-
const uint32_t* in_row = (uint32_t*)in;
490-
uint8_t* out_row = out;
491-
in_stride = in_stride / 4;
492-
int stride_elements = out_stride / 3 > in_stride ? in_stride : out_stride / 3;
493-
for (int i = 0; i < n_rows; i++) {
494-
for (int i2 = 0; i2 < stride_elements; i2++) {
495-
uint32_t p = in_row[i2];
496-
uint8_t a = (p >> 24) & 0xFF;
497-
out_row[i2 * 3 + 0] = (((p >> 0) & 0xFF) * a) / 255;
498-
out_row[i2 * 3 + 1] = (((p >> 8) & 0xFF) * a) / 255;
499-
out_row[i2 * 3 + 2] = (((p >> 16) & 0xFF) * a) / 255;
500-
}
501-
in_row += in_stride;
502-
out_row += out_stride;
503-
}
504-
}
505-
506-
void convert_rgba_premultiplied_to_bgr(const uint8_t *in, int in_stride, uint8_t *out, int out_stride, int n_rows)
507-
{
508-
const uint32_t* in_row = (uint32_t*)in;
509-
uint8_t* out_row = out;
510-
in_stride = in_stride / 4;
511-
int stride_elements = out_stride / 3 > in_stride ? in_stride : out_stride / 3;
512-
for (int i = 0; i < n_rows; i++) {
513-
for (int i2 = 0; i2 < stride_elements; i2++) {
514-
uint32_t p = in_row[i2];
515-
uint8_t a = (p >> 24) & 0xFF;
516-
out_row[i2 * 3 + 0] = (((p >> 16) & 0xFF) * a) / 255;
517-
out_row[i2 * 3 + 1] = (((p >> 8) & 0xFF) * a) / 255;
518-
out_row[i2 * 3 + 2] = (((p >> 0) & 0xFF) * a) / 255;
519-
}
520-
in_row += in_stride;
521-
out_row += out_stride;
522-
}
523-
}
524-
525487
#ifdef __cplusplus
526488
}
527489
#endif

pillow_heif/helpers.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,3 @@ void convert_rgb_to_bgr16(const uint8_t *in, int in_stride, uint8_t *out, int ou
4949
void convert_bgra_rgba(const uint8_t *in, int in_stride, uint8_t *out, int out_stride, int n_rows);
5050

5151
void convert_bgr_rgb(const uint8_t *in, int in_stride, uint8_t *out, int out_stride, int n_rows);
52-
53-
void convert_rgba_premultiplied_to_rgb(const uint8_t *in, int in_stride, uint8_t *out, int out_stride, int n_rows);
54-
55-
void convert_rgba_premultiplied_to_bgr(const uint8_t *in, int in_stride, uint8_t *out, int out_stride, int n_rows);

pillow_heif/private.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ def get_pure_stride(mode: str, width: int) -> int:
7171
"BGRa": lib.convert_bgra_rgba,
7272
"RGBa;16": lib.convert_rgba_to_rgba16,
7373
"BGRa;16": lib.convert_rgba_to_bgra16,
74-
"RGB": lib.convert_rgba_premultiplied_to_rgb,
75-
"BGR": lib.convert_rgba_premultiplied_to_bgr,
7674
},
7775
"RGB": {"BGR": lib.convert_bgr_rgb, "RGB;16": lib.convert_rgb_to_rgb16, "BGR;16": lib.convert_rgb_to_bgr16},
7876
}

tests/mode_convert_test.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -116,36 +116,3 @@ def test_rgba16_to_rgba_color_mode():
116116
heif_file.convert_to("RGBA;16")
117117
heif_file.convert_to("RGBA")
118118
helpers.assert_image_similar(heif_file.to_pillow(), heif_file_orig.to_pillow())
119-
120-
121-
def test_rgba_premultiplied_to_rgb():
122-
im_heif = from_pillow(helpers.gradient_rgba().crop((124, 124, 132, 132)))
123-
im_heif.premultiplied_alpha = True
124-
assert im_heif.mode == "RGBa"
125-
im_heif.convert_to("RGB")
126-
assert im_heif.mode == "RGB"
127-
assert (
128-
im_heif.to_pillow().tobytes().hex()
129-
== "3f3f433f3f423e3f423e3f413d3f413d3f403c3f403c3f3f403f423f3f423f3f413e3f413e3f4"
130-
"03d3f403d3f3f3c3f3f403f42403f413f3f413f3f403e3f403e3f3f3d3f3f3d3f3e413f41403f"
131-
"41403f403f3f403f3f3f3e3f3f3e3f3e3d3f3e413f41413f40403f40403f3f3f3f3f3f3f3e3e3"
132-
"f3e3e3f3d423f40413f40413f3f403f3f403f3e3f3f3e3f3f3d3e3f3d423f40423f3f413f3f41"
133-
"3f3e403f3e403f3d3f3f3d3f3f3c433f3f423f3f423f3e413f3e413f3d403f3d403f3c3f3f3c"
134-
)
135-
136-
137-
def test_rgba_premultiplied_to_bgr():
138-
im_heif = from_pillow(helpers.gradient_rgba().crop((124, 124, 132, 132)))
139-
im_heif.premultiplied_alpha = True
140-
assert im_heif.mode == "RGBa"
141-
im_heif.convert_to("BGR")
142-
assert im_heif.mode == "BGR"
143-
im_heif.convert_to("RGB")
144-
assert (
145-
im_heif.to_pillow().tobytes().hex()
146-
== "3f3f433f3f423e3f423e3f413d3f413d3f403c3f403c3f3f403f423f3f423f3f413e3f413e3f4"
147-
"03d3f403d3f3f3c3f3f403f42403f413f3f413f3f403e3f403e3f3f3d3f3f3d3f3e413f41403f"
148-
"41403f403f3f403f3f3f3e3f3f3e3f3e3d3f3e413f41413f40403f40403f3f3f3f3f3f3f3e3e3"
149-
"f3e3e3f3d423f40413f40413f3f403f3f403f3e3f3f3e3f3f3d3e3f3d423f40423f3f413f3f41"
150-
"3f3e403f3e403f3d3f3f3d3f3f3c433f3f423f3f423f3e413f3e413f3d403f3d403f3c3f3f3c"
151-
)

0 commit comments

Comments
 (0)