From e073f4add0a4ceb18f09c153b2b429f7dfe10c6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kul=C3=ADk?= Date: Mon, 20 May 2019 14:25:27 +0200 Subject: [PATCH] Fix SPARC memory alignment issues in Pack/Unpack functions --- src/libImaging/Pack.c | 10 ++++++++++ src/libImaging/Unpack.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/libImaging/Pack.c b/src/libImaging/Pack.c index 56aebf58e..000ee384a 100644 --- a/src/libImaging/Pack.c +++ b/src/libImaging/Pack.c @@ -251,6 +251,15 @@ ImagingPackRGB(UINT8* out, const UINT8* in, int pixels) { int i = 0; /* RGB triplets */ +#ifdef __sparc + /* SPARC CPUs cannot read integers from nonaligned addresses. */ + for (; i < pixels; i++) { + out[0] = in[R]; + out[1] = in[G]; + out[2] = in[B]; + out += 3; in += 4; + } +#else for (; i < pixels-1; i++) { ((UINT32*)out)[0] = ((UINT32*)in)[i]; out += 3; @@ -261,6 +270,7 @@ ImagingPackRGB(UINT8* out, const UINT8* in, int pixels) out[2] = in[i*4+B]; out += 3; } +#endif } void diff --git a/src/libImaging/Unpack.c b/src/libImaging/Unpack.c index 02196d255..cd72c9724 100644 --- a/src/libImaging/Unpack.c +++ b/src/libImaging/Unpack.c @@ -480,6 +480,16 @@ void ImagingUnpackRGB(UINT8* _out, const UINT8* in, int pixels) { int i = 0; +#ifdef __sparc + /* SPARC CPUs cannot read integers from nonaligned addresses. */ + for (; i < pixels; i++) { + _out[R] = in[0]; + _out[G] = in[1]; + _out[B] = in[2]; + _out[A] = 255; + _out += 4; in += 3; + } +#else UINT32* out = (UINT32*) _out; /* RGB triplets */ for (; i < pixels-1; i++) { @@ -490,6 +500,7 @@ ImagingUnpackRGB(UINT8* _out, const UINT8* in, int pixels) out[i] = MAKE_UINT32(in[0], in[1], in[2], 255); in += 3; } +#endif } void @@ -1085,22 +1096,44 @@ static void copy4skip1(UINT8* _out, const UINT8* in, int pixels) { int i; +#ifdef __sparc + /* SPARC CPUs cannot read integers from nonaligned addresses. */ + for (i = 0; i < pixels; i++) { + _out[0] = in[0]; + _out[1] = in[1]; + _out[2] = in[2]; + _out[3] = in[3]; + _out += 4; in += 5; + } +#else UINT32* out = (UINT32*) _out; for (i = 0; i < pixels; i++) { out[i] = *(UINT32*)&in[0]; in += 5; } +#endif } static void copy4skip2(UINT8* _out, const UINT8* in, int pixels) { int i; +#ifdef __sparc + /* SPARC CPUs cannot read integers from nonaligned addresses. */ + for (i = 0; i < pixels; i++) { + _out[0] = in[0]; + _out[1] = in[1]; + _out[2] = in[2]; + _out[3] = in[3]; + _out += 4; in += 6; + } +#else UINT32* out = (UINT32*) _out; for (i = 0; i < pixels; i++) { out[i] = *(UINT32*)&in[0]; in += 6; } +#endif }