Added BGXR and BGAR unpackers

This commit is contained in:
Andrew Murray 2024-04-08 23:58:03 +10:00 committed by Jonah Jeleniewski
parent 9e5b9fb18f
commit 98ae91a65d
2 changed files with 28 additions and 0 deletions

View File

@ -184,9 +184,11 @@ class BmpImageFile(ImageFile.ImageFile):
32: [
(0xFF0000, 0xFF00, 0xFF, 0x0),
(0xFF000000, 0xFF0000, 0xFF00, 0x0),
(0xFF000000, 0xFF00, 0xFF, 0x0),
(0xFF000000, 0xFF0000, 0xFF00, 0xFF),
(0xFF, 0xFF00, 0xFF0000, 0xFF000000),
(0xFF0000, 0xFF00, 0xFF, 0xFF000000),
(0xFF000000, 0xFF00, 0xFF, 0xFF0000),
(0x0, 0x0, 0x0, 0x0),
],
24: [(0xFF0000, 0xFF00, 0xFF)],
@ -195,9 +197,11 @@ class BmpImageFile(ImageFile.ImageFile):
MASK_MODES = {
(32, (0xFF0000, 0xFF00, 0xFF, 0x0)): "BGRX",
(32, (0xFF000000, 0xFF0000, 0xFF00, 0x0)): "XBGR",
(32, (0xFF000000, 0xFF00, 0xFF, 0x0)): "BGXR",
(32, (0xFF000000, 0xFF0000, 0xFF00, 0xFF)): "ABGR",
(32, (0xFF, 0xFF00, 0xFF0000, 0xFF000000)): "RGBA",
(32, (0xFF0000, 0xFF00, 0xFF, 0xFF000000)): "BGRA",
(32, (0xFF000000, 0xFF00, 0xFF, 0xFF0000)): "BGAR",
(32, (0x0, 0x0, 0x0, 0x0)): "BGRA",
(24, (0xFF0000, 0xFF00, 0xFF)): "BGR",
(16, (0xF800, 0x7E0, 0x1F)): "BGR;16",

View File

@ -790,6 +790,17 @@ ImagingUnpackBGRX(UINT8 *_out, const UINT8 *in, int pixels) {
}
}
static void
ImagingUnpackBGXR(UINT8 *_out, const UINT8 *in, int pixels) {
int i;
for (i = 0; i < pixels; i++) {
UINT32 iv = MAKE_UINT32(in[3], in[1], in[0], 255);
memcpy(_out, &iv, sizeof(iv));
in += 4;
_out += 4;
}
}
static void
ImagingUnpackXRGB(UINT8 *_out, const UINT8 *in, int pixels) {
int i;
@ -1090,6 +1101,17 @@ unpackBGRA16B(UINT8 *_out, const UINT8 *in, int pixels) {
}
}
static void
unpackBGAR(UINT8 *_out, const UINT8 *in, int pixels) {
int i;
for (i = 0; i < pixels; i++) {
UINT32 iv = MAKE_UINT32(in[3], in[1], in[0], in[2]);
memcpy(_out, &iv, sizeof(iv));
in += 4;
_out += 4;
}
}
/* Unpack to "CMYK" image */
static void
@ -1584,6 +1606,7 @@ static struct {
{"RGB", "RGBA;L", 32, unpackRGBAL},
{"RGB", "RGBA;15", 16, ImagingUnpackRGBA15},
{"RGB", "BGRX", 32, ImagingUnpackBGRX},
{"RGB", "BGXR", 32, ImagingUnpackBGXR},
{"RGB", "XRGB", 32, ImagingUnpackXRGB},
{"RGB", "XBGR", 32, ImagingUnpackXBGR},
{"RGB", "YCC;P", 24, ImagingUnpackYCC},
@ -1624,6 +1647,7 @@ static struct {
{"RGBA", "BGRA", 32, unpackBGRA},
{"RGBA", "BGRA;16L", 64, unpackBGRA16L},
{"RGBA", "BGRA;16B", 64, unpackBGRA16B},
{"RGBA", "BGAR", 32, unpackBGAR},
{"RGBA", "ARGB", 32, unpackARGB},
{"RGBA", "ABGR", 32, unpackABGR},
{"RGBA", "YCCA;P", 32, ImagingUnpackYCCA},