mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-10-20 18:54:31 +03:00
Cast before additional shifting
This commit is contained in:
parent
1d4cda65cf
commit
a2ef220b32
|
@ -64,7 +64,7 @@ static void
|
||||||
get_pixel_16L(Imaging im, int x, int y, void *color) {
|
get_pixel_16L(Imaging im, int x, int y, void *color) {
|
||||||
UINT8 *in = (UINT8 *)&im->image[y][x + x];
|
UINT8 *in = (UINT8 *)&im->image[y][x + x];
|
||||||
#ifdef WORDS_BIGENDIAN
|
#ifdef WORDS_BIGENDIAN
|
||||||
UINT16 out = in[0] + (in[1] << 8);
|
UINT16 out = in[0] + ((UINT16)in[1] << 8);
|
||||||
memcpy(color, &out, sizeof(out));
|
memcpy(color, &out, sizeof(out));
|
||||||
#else
|
#else
|
||||||
memcpy(color, in, sizeof(UINT16));
|
memcpy(color, in, sizeof(UINT16));
|
||||||
|
@ -77,7 +77,7 @@ get_pixel_16B(Imaging im, int x, int y, void *color) {
|
||||||
#ifdef WORDS_BIGENDIAN
|
#ifdef WORDS_BIGENDIAN
|
||||||
memcpy(color, in, sizeof(UINT16));
|
memcpy(color, in, sizeof(UINT16));
|
||||||
#else
|
#else
|
||||||
UINT16 out = in[1] + (in[0] << 8);
|
UINT16 out = in[1] + ((UINT16)in[0] << 8);
|
||||||
memcpy(color, &out, sizeof(out));
|
memcpy(color, &out, sizeof(out));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,8 @@ static void
|
||||||
get_pixel_32L(Imaging im, int x, int y, void *color) {
|
get_pixel_32L(Imaging im, int x, int y, void *color) {
|
||||||
UINT8 *in = (UINT8 *)&im->image[y][x * 4];
|
UINT8 *in = (UINT8 *)&im->image[y][x * 4];
|
||||||
#ifdef WORDS_BIGENDIAN
|
#ifdef WORDS_BIGENDIAN
|
||||||
INT32 out = in[0] + (in[1] << 8) + (in[2] << 16) + (in[3] << 24);
|
INT32 out =
|
||||||
|
in[0] + ((INT32)in[1] << 8) + ((INT32)in[2] << 16) + ((INT32)in[3] << 24);
|
||||||
memcpy(color, &out, sizeof(out));
|
memcpy(color, &out, sizeof(out));
|
||||||
#else
|
#else
|
||||||
memcpy(color, in, sizeof(INT32));
|
memcpy(color, in, sizeof(INT32));
|
||||||
|
@ -104,7 +105,8 @@ get_pixel_32B(Imaging im, int x, int y, void *color) {
|
||||||
#ifdef WORDS_BIGENDIAN
|
#ifdef WORDS_BIGENDIAN
|
||||||
memcpy(color, in, sizeof(INT32));
|
memcpy(color, in, sizeof(INT32));
|
||||||
#else
|
#else
|
||||||
INT32 out = in[3] + (in[2] << 8) + (in[1] << 16) + (in[0] << 24);
|
INT32 out =
|
||||||
|
in[3] + ((INT32)in[2] << 8) + ((INT32)in[1] << 16) + ((INT32)in[0] << 24);
|
||||||
memcpy(color, &out, sizeof(out));
|
memcpy(color, &out, sizeof(out));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,10 +36,9 @@ decode_565(UINT16 x) {
|
||||||
|
|
||||||
static UINT16
|
static UINT16
|
||||||
encode_565(rgba item) {
|
encode_565(rgba item) {
|
||||||
UINT8 r, g, b;
|
UINT16 r = item.color[0] >> (8 - 5);
|
||||||
r = item.color[0] >> (8 - 5);
|
UINT8 g = item.color[1] >> (8 - 6);
|
||||||
g = item.color[1] >> (8 - 6);
|
UINT8 b = item.color[2] >> (8 - 5);
|
||||||
b = item.color[2] >> (8 - 5);
|
|
||||||
return (r << (5 + 6)) | (g << 5) | b;
|
return (r << (5 + 6)) | (g << 5) | b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,7 +156,8 @@ encode_bc1_color(Imaging im, ImagingCodecState state, UINT8 *dst, int separate_a
|
||||||
static void
|
static void
|
||||||
encode_bc2_block(Imaging im, ImagingCodecState state, UINT8 *dst) {
|
encode_bc2_block(Imaging im, ImagingCodecState state, UINT8 *dst) {
|
||||||
int i, j;
|
int i, j;
|
||||||
UINT8 block[16], current_alpha;
|
UINT8 block[16];
|
||||||
|
UINT32 current_alpha;
|
||||||
for (i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
for (j = 0; j < 4; j++) {
|
for (j = 0; j < 4; j++) {
|
||||||
int x = state->x + i * im->pixelsize;
|
int x = state->x + i * im->pixelsize;
|
||||||
|
|
|
@ -16,9 +16,11 @@
|
||||||
|
|
||||||
#include "Imaging.h"
|
#include "Imaging.h"
|
||||||
|
|
||||||
#define I16(ptr) ((ptr)[0] + ((ptr)[1] << 8))
|
#define I16(ptr) ((ptr)[0] + ((int)(ptr)[1] << 8))
|
||||||
|
|
||||||
#define I32(ptr) ((ptr)[0] + ((ptr)[1] << 8) + ((ptr)[2] << 16) + ((ptr)[3] << 24))
|
#define I32(ptr) \
|
||||||
|
((ptr)[0] + ((INT32)(ptr)[1] << 8) + ((INT32)(ptr)[2] << 16) + \
|
||||||
|
((INT32)(ptr)[3] << 24))
|
||||||
|
|
||||||
#define ERR_IF_DATA_OOB(offset) \
|
#define ERR_IF_DATA_OOB(offset) \
|
||||||
if ((data + (offset)) > ptr + bytes) { \
|
if ((data + (offset)) > ptr + bytes) { \
|
||||||
|
|
|
@ -212,7 +212,7 @@ ImagingGetExtrema(Imaging im, void *extrema) {
|
||||||
UINT16 v;
|
UINT16 v;
|
||||||
UINT8 *pixel = *im->image8;
|
UINT8 *pixel = *im->image8;
|
||||||
#ifdef WORDS_BIGENDIAN
|
#ifdef WORDS_BIGENDIAN
|
||||||
v = pixel[0] + (pixel[1] << 8);
|
v = pixel[0] + ((UINT16)pixel[1] << 8);
|
||||||
#else
|
#else
|
||||||
memcpy(&v, pixel, sizeof(v));
|
memcpy(&v, pixel, sizeof(v));
|
||||||
#endif
|
#endif
|
||||||
|
@ -221,7 +221,7 @@ ImagingGetExtrema(Imaging im, void *extrema) {
|
||||||
for (x = 0; x < im->xsize; x++) {
|
for (x = 0; x < im->xsize; x++) {
|
||||||
pixel = (UINT8 *)im->image[y] + x * sizeof(v);
|
pixel = (UINT8 *)im->image[y] + x * sizeof(v);
|
||||||
#ifdef WORDS_BIGENDIAN
|
#ifdef WORDS_BIGENDIAN
|
||||||
v = pixel[0] + (pixel[1] << 8);
|
v = pixel[0] + ((UINT16)pixel[1] << 8);
|
||||||
#else
|
#else
|
||||||
memcpy(&v, pixel, sizeof(v));
|
memcpy(&v, pixel, sizeof(v));
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user