Skip to content

Commit 20860bc

Browse files
committed
access BGR;15/16 pixels as BGR, not RGB
1 parent 5576ea6 commit 20860bc

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

Tests/test_lib_pack.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,9 @@ def test_RGB(self) -> None:
362362
)
363363

364364
def test_BGR(self) -> None:
365-
self.assert_unpack("BGR;15", "BGR;15", 3, (8, 131, 0), (24, 0, 8), (41, 131, 8))
365+
self.assert_unpack("BGR;15", "BGR;15", 2, (0, 131, 8), (8, 0, 24), (8, 131, 41))
366366
self.assert_unpack(
367-
"BGR;16", "BGR;16", 3, (8, 64, 0), (24, 129, 0), (41, 194, 0)
367+
"BGR;16", "BGR;16", 2, (0, 64, 8), (0, 129, 24), (0, 194, 41)
368368
)
369369
self.assert_unpack("BGR;24", "BGR;24", 3, (1, 2, 3), (4, 5, 6), (7, 8, 9))
370370

src/libImaging/Access.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,19 @@ get_pixel_BGR15(Imaging im, int x, int y, void *color) {
8686
UINT8 *in = (UINT8 *)&im->image8[y][x * 2];
8787
UINT16 pixel = in[0] + (in[1] << 8);
8888
char *out = color;
89-
out[0] = (pixel & 31) * 255 / 31;
89+
out[0] = ((pixel >> 10) & 31) * 255 / 31;
9090
out[1] = ((pixel >> 5) & 31) * 255 / 31;
91-
out[2] = ((pixel >> 10) & 31) * 255 / 31;
91+
out[2] = (pixel & 31) * 255 / 31;
9292
}
9393

9494
static void
9595
get_pixel_BGR16(Imaging im, int x, int y, void *color) {
9696
UINT8 *in = (UINT8 *)&im->image8[y][x * 2];
9797
UINT16 pixel = in[0] + (in[1] << 8);
9898
char *out = color;
99-
out[0] = (pixel & 31) * 255 / 31;
99+
out[0] = ((pixel >> 11) & 31) * 255 / 31;
100100
out[1] = ((pixel >> 5) & 63) * 255 / 63;
101-
out[2] = ((pixel >> 11) & 31) * 255 / 31;
101+
out[2] = (pixel & 31) * 255 / 31;
102102
}
103103

104104
static void

0 commit comments

Comments
 (0)