Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SPARC memory alignment issues in Pack/Unpack functions #3858

Merged
merged 1 commit into from Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/libImaging/Pack.c
Expand Up @@ -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;
Expand All @@ -261,6 +270,7 @@ ImagingPackRGB(UINT8* out, const UINT8* in, int pixels)
out[2] = in[i*4+B];
out += 3;
}
#endif
}

void
Expand Down
33 changes: 33 additions & 0 deletions src/libImaging/Unpack.c
Expand Up @@ -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++) {
Expand All @@ -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
Expand Down Expand Up @@ -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
}


Expand Down