mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-05 21:10:11 +03:00
get and set BGR pixels as BGR without scaling
This commit is contained in:
parent
1138ea5370
commit
7743e6268d
|
@ -137,10 +137,6 @@ class TestImageGetPixel(AccessTest):
|
||||||
bands = Image.getmodebands(mode)
|
bands = Image.getmodebands(mode)
|
||||||
if bands == 1:
|
if bands == 1:
|
||||||
return 1
|
return 1
|
||||||
if mode in ("BGR;15", "BGR;16"):
|
|
||||||
# These modes have less than 8 bits per band,
|
|
||||||
# so (1, 2, 3) cannot be roundtripped.
|
|
||||||
return (16, 32, 49)
|
|
||||||
return tuple(range(1, bands + 1))
|
return tuple(range(1, bands + 1))
|
||||||
|
|
||||||
def check(self, mode: str, expected_color_int: int | None = None) -> None:
|
def check(self, mode: str, expected_color_int: int | None = None) -> None:
|
||||||
|
|
|
@ -80,7 +80,7 @@ def test_mode_F() -> None:
|
||||||
|
|
||||||
@pytest.mark.parametrize("mode", ("BGR;15", "BGR;16", "BGR;24"))
|
@pytest.mark.parametrize("mode", ("BGR;15", "BGR;16", "BGR;24"))
|
||||||
def test_mode_BGR(mode: str) -> None:
|
def test_mode_BGR(mode: str) -> None:
|
||||||
data = [(16, 32, 49), (32, 32, 98)]
|
data = [(1, 2, 3), (10, 11, 12)]
|
||||||
im = Image.new(mode, (1, 2))
|
im = Image.new(mode, (1, 2))
|
||||||
im.putdata(data)
|
im.putdata(data)
|
||||||
|
|
||||||
|
|
|
@ -362,10 +362,8 @@ class TestLibUnpack:
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_BGR(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", 3, (0, 16, 1), (1, 0, 3), (1, 16, 5))
|
||||||
self.assert_unpack(
|
self.assert_unpack("BGR;16", "BGR;16", 3, (0, 16, 1), (0, 32, 3), (0, 48, 5))
|
||||||
"BGR;16", "BGR;16", 3, (8, 64, 0), (24, 129, 0), (41, 194, 0)
|
|
||||||
)
|
|
||||||
self.assert_unpack("BGR;24", "BGR;24", 3, (1, 2, 3), (4, 5, 6), (7, 8, 9))
|
self.assert_unpack("BGR;24", "BGR;24", 3, (1, 2, 3), (4, 5, 6), (7, 8, 9))
|
||||||
|
|
||||||
def test_RGBA(self) -> None:
|
def test_RGBA(self) -> None:
|
||||||
|
|
|
@ -605,18 +605,18 @@ getink(PyObject *color, Imaging im, char *ink) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (!strcmp(im->mode, "BGR;15")) {
|
if (!strcmp(im->mode, "BGR;15")) {
|
||||||
UINT16 v = ((((UINT16)r) << 7) & 0x7c00) +
|
UINT16 v = ((((UINT16)b) << 10) & 0x7c00) +
|
||||||
((((UINT16)g) << 2) & 0x03e0) +
|
((((UINT16)g) << 5) & 0x03e0) +
|
||||||
((((UINT16)b) >> 3) & 0x001f);
|
((((UINT16)r) >> 0) & 0x001f);
|
||||||
|
|
||||||
ink[0] = (UINT8)v;
|
ink[0] = (UINT8)v;
|
||||||
ink[1] = (UINT8)(v >> 8);
|
ink[1] = (UINT8)(v >> 8);
|
||||||
ink[2] = ink[3] = 0;
|
ink[2] = ink[3] = 0;
|
||||||
return ink;
|
return ink;
|
||||||
} else if (!strcmp(im->mode, "BGR;16")) {
|
} else if (!strcmp(im->mode, "BGR;16")) {
|
||||||
UINT16 v = ((((UINT16)r) << 8) & 0xf800) +
|
UINT16 v = ((((UINT16)b) << 11) & 0xf800) +
|
||||||
((((UINT16)g) << 3) & 0x07e0) +
|
((((UINT16)g) << 5) & 0x07e0) +
|
||||||
((((UINT16)b) >> 3) & 0x001f);
|
((((UINT16)r) >> 0) & 0x001f);
|
||||||
ink[0] = (UINT8)v;
|
ink[0] = (UINT8)v;
|
||||||
ink[1] = (UINT8)(v >> 8);
|
ink[1] = (UINT8)(v >> 8);
|
||||||
ink[2] = ink[3] = 0;
|
ink[2] = ink[3] = 0;
|
||||||
|
|
|
@ -86,9 +86,9 @@ get_pixel_BGR15(Imaging im, int x, int y, void *color) {
|
||||||
UINT8 *in = (UINT8 *)&im->image8[y][x * 2];
|
UINT8 *in = (UINT8 *)&im->image8[y][x * 2];
|
||||||
UINT16 pixel = in[0] + (in[1] << 8);
|
UINT16 pixel = in[0] + (in[1] << 8);
|
||||||
char *out = color;
|
char *out = color;
|
||||||
out[0] = (pixel & 31) * 255 / 31;
|
out[0] = (pixel >> 10) & 31;
|
||||||
out[1] = ((pixel >> 5) & 31) * 255 / 31;
|
out[1] = (pixel >> 5) & 31;
|
||||||
out[2] = ((pixel >> 10) & 31) * 255 / 31;
|
out[2] = pixel & 31;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -96,9 +96,9 @@ get_pixel_BGR16(Imaging im, int x, int y, void *color) {
|
||||||
UINT8 *in = (UINT8 *)&im->image8[y][x * 2];
|
UINT8 *in = (UINT8 *)&im->image8[y][x * 2];
|
||||||
UINT16 pixel = in[0] + (in[1] << 8);
|
UINT16 pixel = in[0] + (in[1] << 8);
|
||||||
char *out = color;
|
char *out = color;
|
||||||
out[0] = (pixel & 31) * 255 / 31;
|
out[0] = (pixel >> 11) & 31;
|
||||||
out[1] = ((pixel >> 5) & 63) * 255 / 63;
|
out[1] = (pixel >> 5) & 63;
|
||||||
out[2] = ((pixel >> 11) & 31) * 255 / 31;
|
out[2] = pixel & 31;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Reference in New Issue
Block a user