Skip to content

Commit

Permalink
access BGR;15/16 pixels as BGR, not RGB
Browse files Browse the repository at this point in the history
  • Loading branch information
Yay295 committed Apr 16, 2024
1 parent 5576ea6 commit 20860bc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Tests/test_lib_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,9 @@ def test_RGB(self) -> None:
)

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

Expand Down
8 changes: 4 additions & 4 deletions src/libImaging/Access.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,19 @@ get_pixel_BGR15(Imaging im, int x, int y, void *color) {
UINT8 *in = (UINT8 *)&im->image8[y][x * 2];
UINT16 pixel = in[0] + (in[1] << 8);
char *out = color;
out[0] = (pixel & 31) * 255 / 31;
out[0] = ((pixel >> 10) & 31) * 255 / 31;
out[1] = ((pixel >> 5) & 31) * 255 / 31;
out[2] = ((pixel >> 10) & 31) * 255 / 31;
out[2] = (pixel & 31) * 255 / 31;
}

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

static void
Expand Down

0 comments on commit 20860bc

Please sign in to comment.