Merge branch 'master' into tiff-jpeg-quality

This commit is contained in:
Oliver Tonnhofer 2019-07-01 11:00:06 +02:00 committed by GitHub
commit edeb8d69af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 496 additions and 344 deletions

View File

@ -5,6 +5,18 @@ Changelog (Pillow)
6.1.0 (unreleased) 6.1.0 (unreleased)
------------------ ------------------
- Improve encoding of TIFF tags #3861
[olt]
- Update Py_UNICODE to Py_UCS4 #3780
[nulano]
- Consider I;16 pixel size when drawing #3899
[radarhere]
- Add TIFFTAG_SAMPLEFORMAT to blocklist #3926
[cgohlke, radarhere]
- Create GIF deltas from background colour of GIF frames if disposal mode is 2 #3708 - Create GIF deltas from background colour of GIF frames if disposal mode is 2 #3708
[sircinnamon, radarhere] [sircinnamon, radarhere]

View File

@ -1,5 +1,5 @@
NotoNastaliqUrdu-Regular.ttf, from https://github.com/googlei18n/noto-fonts NotoNastaliqUrdu-Regular.ttf and NotoSansSymbols-Regular.ttf, from https://github.com/googlei18n/noto-fonts
NotoSansJP-Thin.otf, from https://www.google.com/get/noto/help/cjk/ NotoSansJP-Thin.otf, from https://www.google.com/get/noto/help/cjk/
AdobeVFPrototype.ttf, from https://github.com/adobe-fonts/adobe-variable-font-prototype AdobeVFPrototype.ttf, from https://github.com/adobe-fonts/adobe-variable-font-prototype
TINY5x3GX.ttf, from http://velvetyne.fr/fonts/tiny TINY5x3GX.ttf, from http://velvetyne.fr/fonts/tiny

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 181 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 999 B

View File

@ -4,7 +4,7 @@ import sys
from .helper import unittest, PillowTestCase, hopper from .helper import unittest, PillowTestCase, hopper
from PIL import Image, TiffImagePlugin from PIL import Image, TiffImagePlugin, features
from PIL._util import py3 from PIL._util import py3
from PIL.TiffImagePlugin import X_RESOLUTION, Y_RESOLUTION, RESOLUTION_UNIT from PIL.TiffImagePlugin import X_RESOLUTION, Y_RESOLUTION, RESOLUTION_UNIT
@ -587,6 +587,30 @@ class TestFileTiff(PillowTestCase):
im.load() im.load()
self.assertFalse(fp.closed) self.assertFalse(fp.closed)
@unittest.skipUnless(features.check("libtiff"), "libtiff not installed")
def test_sampleformat_not_corrupted(self):
# Assert that a TIFF image with SampleFormat=UINT tag is not corrupted
# when saving to a new file.
# Pillow 6.0 fails with "OSError: cannot identify image file".
import base64
tiff = BytesIO(
base64.b64decode(
b"SUkqAAgAAAAPAP4ABAABAAAAAAAAAAABBAABAAAAAQAAAAEBBAABAAAAAQAA"
b"AAIBAwADAAAAwgAAAAMBAwABAAAACAAAAAYBAwABAAAAAgAAABEBBAABAAAA"
b"4AAAABUBAwABAAAAAwAAABYBBAABAAAAAQAAABcBBAABAAAACwAAABoBBQAB"
b"AAAAyAAAABsBBQABAAAA0AAAABwBAwABAAAAAQAAACgBAwABAAAAAQAAAFMB"
b"AwADAAAA2AAAAAAAAAAIAAgACAABAAAAAQAAAAEAAAABAAAAAQABAAEAAAB4"
b"nGNgYAAAAAMAAQ=="
)
)
out = BytesIO()
with Image.open(tiff) as im:
im.save(out, format="tiff")
out.seek(0)
with Image.open(out) as im:
im.load()
@unittest.skipUnless(sys.platform.startswith("win32"), "Windows only") @unittest.skipUnless(sys.platform.startswith("win32"), "Windows only")
class TestFileTiffW32(PillowTestCase): class TestFileTiffW32(PillowTestCase):

View File

@ -479,6 +479,19 @@ class TestImageDraw(PillowTestCase):
# Assert # Assert
self.assert_image_equal(im, Image.open(expected)) self.assert_image_equal(im, Image.open(expected))
def test_rectangle_I16(self):
# Arrange
im = Image.new("I;16", (W, H))
draw = ImageDraw.Draw(im)
# Act
draw.rectangle(BBOX1, fill="black", outline="green")
# Assert
self.assert_image_equal(
im.convert("I"), Image.open("Tests/images/imagedraw_rectangle_I.png")
)
def test_floodfill(self): def test_floodfill(self):
red = ImageColor.getrgb("red") red = ImageColor.getrgb("red")

View File

@ -463,6 +463,26 @@ class TestImageFont(PillowTestCase):
with self.assertRaises(UnicodeEncodeError): with self.assertRaises(UnicodeEncodeError):
font.getsize(u"") font.getsize(u"")
@unittest.skipIf(
sys.platform.startswith("win32") and sys.version.startswith("2"),
"requires Python 3.x on Windows",
)
def test_unicode_extended(self):
# issue #3777
text = u"A\u278A\U0001F12B"
target = "Tests/images/unicode_extended.png"
ttf = ImageFont.truetype(
"Tests/fonts/NotoSansSymbols-Regular.ttf",
FONT_SIZE,
layout_engine=self.LAYOUT_ENGINE,
)
img = Image.new("RGB", (100, 60))
d = ImageDraw.Draw(img)
d.text((10, 10), text, font=ttf)
self.assert_image_similar_tofile(img, target, self.metrics["multiline"])
def _test_fake_loading_font(self, path_to_fake, fontname): def _test_fake_loading_font(self, path_to_fake, fontname):
# Make a copy of FreeTypeFont so we can patch the original # Make a copy of FreeTypeFont so we can patch the original
free_type_font = copy.deepcopy(ImageFont.FreeTypeFont) free_type_font = copy.deepcopy(ImageFont.FreeTypeFont)

View File

@ -242,8 +242,9 @@ LCMS_ROOT = None
def _pkg_config(name): def _pkg_config(name):
try: try:
command_libs = ["pkg-config", "--libs-only-L", name] command = os.environ.get("PKG_CONFIG", "pkg-config")
command_cflags = ["pkg-config", "--cflags-only-I", name] command_libs = [command, "--libs-only-L", name]
command_cflags = [command, "--cflags-only-I", name]
if not DEBUG: if not DEBUG:
command_libs.append("--silence-errors") command_libs.append("--silence-errors")
command_cflags.append("--silence-errors") command_cflags.append("--silence-errors")
@ -347,7 +348,7 @@ class pil_build_ext(build_ext):
_add_directory(include_dirs, "src/libImaging") _add_directory(include_dirs, "src/libImaging")
pkg_config = None pkg_config = None
if _cmd_exists("pkg-config"): if _cmd_exists(os.environ.get("PKG_CONFIG", "pkg-config")):
pkg_config = _pkg_config pkg_config = _pkg_config
# #

View File

@ -1553,6 +1553,8 @@ def _save(im, fp, filename):
# optional types for non core tags # optional types for non core tags
types = {} types = {}
# SAMPLEFORMAT is determined by the image format and should not be copied
# from legacy_ifd.
# STRIPOFFSETS and STRIPBYTECOUNTS are added by the library # STRIPOFFSETS and STRIPBYTECOUNTS are added by the library
# based on the data in the strip. # based on the data in the strip.
# The other tags expect arrays with a certain length (fixed or depending on # The other tags expect arrays with a certain length (fixed or depending on
@ -1561,6 +1563,7 @@ def _save(im, fp, filename):
blocklist = [ blocklist = [
COLORMAP, COLORMAP,
REFERENCEBLACKWHITE, REFERENCEBLACKWHITE,
SAMPLEFORMAT,
STRIPBYTECOUNTS, STRIPBYTECOUNTS,
STRIPOFFSETS, STRIPOFFSETS,
TRANSFERFUNCTION, TRANSFERFUNCTION,

View File

@ -382,7 +382,8 @@ getlist(PyObject* arg, Py_ssize_t* length, const char* wrong_length, int type)
Py_ssize_t i, n; Py_ssize_t i, n;
int itemp; int itemp;
double dtemp; double dtemp;
void* list; FLOAT32 ftemp;
UINT8* list;
PyObject* seq; PyObject* seq;
PyObject* op; PyObject* op;
@ -416,19 +417,19 @@ getlist(PyObject* arg, Py_ssize_t* length, const char* wrong_length, int type)
switch (type) { switch (type) {
case TYPE_UINT8: case TYPE_UINT8:
itemp = PyInt_AsLong(op); itemp = PyInt_AsLong(op);
((UINT8*)list)[i] = CLIP8(itemp); list[i] = CLIP8(itemp);
break; break;
case TYPE_INT32: case TYPE_INT32:
itemp = PyInt_AsLong(op); itemp = PyInt_AsLong(op);
((INT32*)list)[i] = itemp; memcpy(list + i * sizeof(INT32), &itemp, sizeof(itemp));
break; break;
case TYPE_FLOAT32: case TYPE_FLOAT32:
dtemp = PyFloat_AsDouble(op); ftemp = (FLOAT32)PyFloat_AsDouble(op);
((FLOAT32*)list)[i] = (FLOAT32) dtemp; memcpy(list + i * sizeof(ftemp), &ftemp, sizeof(ftemp));
break; break;
case TYPE_DOUBLE: case TYPE_DOUBLE:
dtemp = PyFloat_AsDouble(op); dtemp = PyFloat_AsDouble(op);
((double*)list)[i] = (double) dtemp; memcpy(list + i * sizeof(dtemp), &dtemp, sizeof(dtemp));
break; break;
} }
} }
@ -532,6 +533,8 @@ getink(PyObject* color, Imaging im, char* ink)
to return it into a 32 bit C long to return it into a 32 bit C long
*/ */
PY_LONG_LONG r = 0; PY_LONG_LONG r = 0;
FLOAT32 ftmp;
INT32 itmp;
/* fill ink buffer (four bytes) with something that can /* fill ink buffer (four bytes) with something that can
be cast to either UINT8 or INT32 */ be cast to either UINT8 or INT32 */
@ -597,14 +600,16 @@ getink(PyObject* color, Imaging im, char* ink)
/* signed integer */ /* signed integer */
if (rIsInt != 1) if (rIsInt != 1)
return NULL; return NULL;
*(INT32*) ink = r; itmp = r;
memcpy(ink, &itmp, sizeof(itmp));
return ink; return ink;
case IMAGING_TYPE_FLOAT32: case IMAGING_TYPE_FLOAT32:
/* floating point */ /* floating point */
f = PyFloat_AsDouble(color); f = PyFloat_AsDouble(color);
if (f == -1.0 && PyErr_Occurred()) if (f == -1.0 && PyErr_Occurred())
return NULL; return NULL;
*(FLOAT32*) ink = (FLOAT32) f; ftmp = f;
memcpy(ink, &ftmp, sizeof(ftmp));
return ink; return ink;
case IMAGING_TYPE_SPECIAL: case IMAGING_TYPE_SPECIAL:
if (strncmp(im->mode, "I;16", 4) == 0) { if (strncmp(im->mode, "I;16", 4) == 0) {
@ -799,15 +804,19 @@ _prepare_lut_table(PyObject* table, Py_ssize_t table_size)
} }
for (i = 0; i < table_size; i++) { for (i = 0; i < table_size; i++) {
FLOAT16 htmp;
double dtmp;
switch (data_type) { switch (data_type) {
case TYPE_FLOAT16: case TYPE_FLOAT16:
item = float16tofloat32(((FLOAT16*) table_data)[i]); memcpy(&htmp, ((char*) table_data) + i * sizeof(htmp), sizeof(htmp));
item = float16tofloat32(htmp);
break; break;
case TYPE_FLOAT32: case TYPE_FLOAT32:
item = ((FLOAT32*) table_data)[i]; memcpy(&item, ((char*) table_data) + i * sizeof(FLOAT32), sizeof(FLOAT32));
break; break;
case TYPE_DOUBLE: case TYPE_DOUBLE:
item = ((double*) table_data)[i]; memcpy(&dtmp, ((char*) table_data) + i * sizeof(dtmp), sizeof(dtmp));
item = (FLOAT32) dtmp;
break; break;
} }
/* Max value for INT16 */ /* Max value for INT16 */

View File

@ -327,6 +327,7 @@ getfont(PyObject* self_, PyObject* args, PyObject* kw)
static int static int
font_getchar(PyObject* string, int index, FT_ULong* char_out) font_getchar(PyObject* string, int index, FT_ULong* char_out)
{ {
#if PY_VERSION_HEX < 0x03000000
if (PyUnicode_Check(string)) { if (PyUnicode_Check(string)) {
Py_UNICODE* p = PyUnicode_AS_UNICODE(string); Py_UNICODE* p = PyUnicode_AS_UNICODE(string);
int size = PyUnicode_GET_SIZE(string); int size = PyUnicode_GET_SIZE(string);
@ -336,7 +337,6 @@ font_getchar(PyObject* string, int index, FT_ULong* char_out)
return 1; return 1;
} }
#if PY_VERSION_HEX < 0x03000000
if (PyString_Check(string)) { if (PyString_Check(string)) {
unsigned char* p = (unsigned char*) PyString_AS_STRING(string); unsigned char* p = (unsigned char*) PyString_AS_STRING(string);
int size = PyString_GET_SIZE(string); int size = PyString_GET_SIZE(string);
@ -345,6 +345,13 @@ font_getchar(PyObject* string, int index, FT_ULong* char_out)
*char_out = (unsigned char) p[index]; *char_out = (unsigned char) p[index];
return 1; return 1;
} }
#else
if (PyUnicode_Check(string)) {
if (index >= PyUnicode_GET_LENGTH(string))
return 0;
*char_out = PyUnicode_READ_CHAR(string, index);
return 1;
}
#endif #endif
return 0; return 0;
@ -366,6 +373,7 @@ text_layout_raqm(PyObject* string, FontObject* self, const char* dir, PyObject *
goto failed; goto failed;
} }
#if PY_VERSION_HEX < 0x03000000
if (PyUnicode_Check(string)) { if (PyUnicode_Check(string)) {
Py_UNICODE *text = PyUnicode_AS_UNICODE(string); Py_UNICODE *text = PyUnicode_AS_UNICODE(string);
Py_ssize_t size = PyUnicode_GET_SIZE(string); Py_ssize_t size = PyUnicode_GET_SIZE(string);
@ -385,9 +393,7 @@ text_layout_raqm(PyObject* string, FontObject* self, const char* dir, PyObject *
} }
} }
} } else if (PyString_Check(string)) {
#if PY_VERSION_HEX < 0x03000000
else if (PyString_Check(string)) {
char *text = PyString_AS_STRING(string); char *text = PyString_AS_STRING(string);
int size = PyString_GET_SIZE(string); int size = PyString_GET_SIZE(string);
if (! size) { if (! size) {
@ -404,6 +410,28 @@ text_layout_raqm(PyObject* string, FontObject* self, const char* dir, PyObject *
} }
} }
} }
#else
if (PyUnicode_Check(string)) {
Py_UCS4 *text = PyUnicode_AsUCS4Copy(string);
Py_ssize_t size = PyUnicode_GET_LENGTH(string);
if (!text || !size) {
/* return 0 and clean up, no glyphs==no size,
and raqm fails with empty strings */
goto failed;
}
int set_text = (*p_raqm.set_text)(rq, (const uint32_t *)(text), size);
PyMem_Free(text);
if (!set_text) {
PyErr_SetString(PyExc_ValueError, "raqm_set_text() failed");
goto failed;
}
if (lang) {
if (!(*p_raqm.set_language)(rq, lang, start, size)) {
PyErr_SetString(PyExc_ValueError, "raqm_set_language() failed");
goto failed;
}
}
}
#endif #endif
else { else {
PyErr_SetString(PyExc_TypeError, "expected string"); PyErr_SetString(PyExc_TypeError, "expected string");

View File

@ -649,7 +649,6 @@ PyImaging_LibTiffEncoderNew(PyObject* self, PyObject* args)
Py_ssize_t tags_size; Py_ssize_t tags_size;
PyObject *item; PyObject *item;
if (! PyArg_ParseTuple(args, "sssnsOO", &mode, &rawmode, &compname, &fp, &filename, &tags, &types)) { if (! PyArg_ParseTuple(args, "sssnsOO", &mode, &rawmode, &compname, &fp, &filename, &tags, &types)) {
return NULL; return NULL;
} }
@ -1095,6 +1094,7 @@ PyImaging_JpegEncoderNew(PyObject* self, PyObject* args)
#endif #endif
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* JPEG 2000 */ /* JPEG 2000 */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */

View File

@ -94,11 +94,11 @@ 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];
UINT16* out = color;
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
out[0] = in[0] + (in[1]<<8); UINT16 out = in[0] + (in[1]<<8);
memcpy(color, &out, sizeof(out));
#else #else
out[0] = *(UINT16*) in; memcpy(color, in, sizeof(UINT16));
#endif #endif
} }
@ -106,30 +106,29 @@ static void
get_pixel_16B(Imaging im, int x, int y, void* color) get_pixel_16B(Imaging im, int x, int y, void* color)
{ {
UINT8* in = (UINT8*) &im->image[y][x+x]; UINT8* in = (UINT8*) &im->image[y][x+x];
UINT16* out = color;
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
out[0] = *(UINT16*) in; memcpy(color, in, sizeof(UINT16));
#else #else
out[0] = in[1] + (in[0]<<8); UINT16 out = in[1] + (in[0]<<8);
memcpy(color, &out, sizeof(out));
#endif #endif
} }
static void static void
get_pixel_32(Imaging im, int x, int y, void* color) get_pixel_32(Imaging im, int x, int y, void* color)
{ {
INT32* out = color; memcpy(color, &im->image32[y][x], sizeof(INT32));
out[0] = im->image32[y][x];
} }
static void 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];
INT32* out = color;
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
out[0] = in[0] + (in[1]<<8) + (in[2]<<16) + (in[3]<<24); INT32 out = in[0] + (in[1]<<8) + (in[2]<<16) + (in[3]<<24);
memcpy(color, &out, sizeof(out));
#else #else
out[0] = *(INT32*) in; memcpy(color, in, sizeof(INT32));
#endif #endif
} }
@ -137,11 +136,11 @@ static void
get_pixel_32B(Imaging im, int x, int y, void* color) get_pixel_32B(Imaging im, int x, int y, void* color)
{ {
UINT8* in = (UINT8*) &im->image[y][x*4]; UINT8* in = (UINT8*) &im->image[y][x*4];
INT32* out = color;
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
out[0] = *(INT32*) in; memcpy(color, in, sizeof(INT32));
#else #else
out[0] = in[3] + (in[2]<<8) + (in[1]<<16) + (in[0]<<24); INT32 out = in[3] + (in[2]<<8) + (in[1]<<16) + (in[0]<<24);
memcpy(color, &out, sizeof(out));
#endif #endif
} }
@ -153,7 +152,7 @@ put_pixel(Imaging im, int x, int y, const void* color)
if (im->image8) if (im->image8)
im->image8[y][x] = *((UINT8*) color); im->image8[y][x] = *((UINT8*) color);
else else
im->image32[y][x] = *((INT32*) color); memcpy(&im->image32[y][x], color, sizeof(INT32));
} }
static void static void
@ -165,10 +164,7 @@ put_pixel_8(Imaging im, int x, int y, const void* color)
static void static void
put_pixel_16L(Imaging im, int x, int y, const void* color) put_pixel_16L(Imaging im, int x, int y, const void* color)
{ {
const char* in = color; memcpy(&im->image8[y][x+x], color, 2);
UINT8* out = (UINT8*) &im->image8[y][x+x];
out[0] = in[0];
out[1] = in[1];
} }
static void static void
@ -183,12 +179,7 @@ put_pixel_16B(Imaging im, int x, int y, const void* color)
static void static void
put_pixel_32L(Imaging im, int x, int y, const void* color) put_pixel_32L(Imaging im, int x, int y, const void* color)
{ {
const char* in = color; memcpy(&im->image8[y][x*4], color, 4);
UINT8* out = (UINT8*) &im->image8[y][x*4];
out[0] = in[0];
out[1] = in[1];
out[2] = in[2];
out[3] = in[3];
} }
static void static void
@ -205,7 +196,7 @@ put_pixel_32B(Imaging im, int x, int y, const void* color)
static void static void
put_pixel_32(Imaging im, int x, int y, const void* color) put_pixel_32(Imaging im, int x, int y, const void* color)
{ {
im->image32[y][x] = *((INT32*) color); memcpy(&im->image32[y][x], color, sizeof(INT32));
} }
void void

View File

@ -50,7 +50,8 @@ ImagingGetBand(Imaging imIn, int band)
UINT8* out = imOut->image8[y]; UINT8* out = imOut->image8[y];
x = 0; x = 0;
for (; x < imIn->xsize - 3; x += 4) { for (; x < imIn->xsize - 3; x += 4) {
*((UINT32*) (out + x)) = MAKE_UINT32(in[0], in[4], in[8], in[12]); UINT32 v = MAKE_UINT32(in[0], in[4], in[8], in[12]);
memcpy(out + x, &v, sizeof(v));
in += 16; in += 16;
} }
for (; x < imIn->xsize; x++) { for (; x < imIn->xsize; x++) {
@ -98,8 +99,10 @@ ImagingSplit(Imaging imIn, Imaging bands[4])
UINT8* out1 = bands[1]->image8[y]; UINT8* out1 = bands[1]->image8[y];
x = 0; x = 0;
for (; x < imIn->xsize - 3; x += 4) { for (; x < imIn->xsize - 3; x += 4) {
*((UINT32*) (out0 + x)) = MAKE_UINT32(in[0], in[4], in[8], in[12]); UINT32 v = MAKE_UINT32(in[0], in[4], in[8], in[12]);
*((UINT32*) (out1 + x)) = MAKE_UINT32(in[0+3], in[4+3], in[8+3], in[12+3]); memcpy(out0 + x, &v, sizeof(v));
v = MAKE_UINT32(in[0+3], in[4+3], in[8+3], in[12+3]);
memcpy(out1 + x, &v, sizeof(v));
in += 16; in += 16;
} }
for (; x < imIn->xsize; x++) { for (; x < imIn->xsize; x++) {
@ -116,9 +119,12 @@ ImagingSplit(Imaging imIn, Imaging bands[4])
UINT8* out2 = bands[2]->image8[y]; UINT8* out2 = bands[2]->image8[y];
x = 0; x = 0;
for (; x < imIn->xsize - 3; x += 4) { for (; x < imIn->xsize - 3; x += 4) {
*((UINT32*) (out0 + x)) = MAKE_UINT32(in[0], in[4], in[8], in[12]); UINT32 v = MAKE_UINT32(in[0], in[4], in[8], in[12]);
*((UINT32*) (out1 + x)) = MAKE_UINT32(in[0+1], in[4+1], in[8+1], in[12+1]); memcpy(out0 + x, &v, sizeof(v));
*((UINT32*) (out2 + x)) = MAKE_UINT32(in[0+2], in[4+2], in[8+2], in[12+2]); v = MAKE_UINT32(in[0+1], in[4+1], in[8+1], in[12+1]);
memcpy(out1 + x, &v, sizeof(v));
v = MAKE_UINT32(in[0+2], in[4+2], in[8+2], in[12+2]);
memcpy(out2 + x, &v, sizeof(v));
in += 16; in += 16;
} }
for (; x < imIn->xsize; x++) { for (; x < imIn->xsize; x++) {
@ -137,10 +143,14 @@ ImagingSplit(Imaging imIn, Imaging bands[4])
UINT8* out3 = bands[3]->image8[y]; UINT8* out3 = bands[3]->image8[y];
x = 0; x = 0;
for (; x < imIn->xsize - 3; x += 4) { for (; x < imIn->xsize - 3; x += 4) {
*((UINT32*) (out0 + x)) = MAKE_UINT32(in[0], in[4], in[8], in[12]); UINT32 v = MAKE_UINT32(in[0], in[4], in[8], in[12]);
*((UINT32*) (out1 + x)) = MAKE_UINT32(in[0+1], in[4+1], in[8+1], in[12+1]); memcpy(out0 + x, &v, sizeof(v));
*((UINT32*) (out2 + x)) = MAKE_UINT32(in[0+2], in[4+2], in[8+2], in[12+2]); v = MAKE_UINT32(in[0+1], in[4+1], in[8+1], in[12+1]);
*((UINT32*) (out3 + x)) = MAKE_UINT32(in[0+3], in[4+3], in[8+3], in[12+3]); memcpy(out1 + x, &v, sizeof(v));
v = MAKE_UINT32(in[0+2], in[4+2], in[8+2], in[12+2]);
memcpy(out2 + x, &v, sizeof(v));
v = MAKE_UINT32(in[0+3], in[4+3], in[8+3], in[12+3]);
memcpy(out3 + x, &v, sizeof(v));
in += 16; in += 16;
} }
for (; x < imIn->xsize; x++) { for (; x < imIn->xsize; x++) {

View File

@ -105,7 +105,7 @@ ImagingColorLUT3D_linear(Imaging imOut, Imaging imIn, int table_channels,
ImagingSectionEnter(&cookie); ImagingSectionEnter(&cookie);
for (y = 0; y < imOut->ysize; y++) { for (y = 0; y < imOut->ysize; y++) {
UINT8* rowIn = (UINT8 *)imIn->image[y]; UINT8* rowIn = (UINT8 *)imIn->image[y];
UINT32* rowOut = (UINT32 *)imOut->image[y]; char* rowOut = (char *)imOut->image[y];
for (x = 0; x < imOut->xsize; x++) { for (x = 0; x < imOut->xsize; x++) {
UINT32 index1D = rowIn[x*4 + 0] * scale1D; UINT32 index1D = rowIn[x*4 + 0] * scale1D;
UINT32 index2D = rowIn[x*4 + 1] * scale2D; UINT32 index2D = rowIn[x*4 + 1] * scale2D;
@ -120,6 +120,7 @@ ImagingColorLUT3D_linear(Imaging imOut, Imaging imIn, int table_channels,
INT16 leftleft[4], leftright[4], rightleft[4], rightright[4]; INT16 leftleft[4], leftright[4], rightleft[4], rightright[4];
if (table_channels == 3) { if (table_channels == 3) {
UINT32 v;
interpolate3(leftleft, &table[idx + 0], &table[idx + 3], shift1D); interpolate3(leftleft, &table[idx + 0], &table[idx + 3], shift1D);
interpolate3(leftright, &table[idx + size1D*3], interpolate3(leftright, &table[idx + size1D*3],
&table[idx + size1D*3 + 3], shift1D); &table[idx + size1D*3 + 3], shift1D);
@ -133,12 +134,14 @@ ImagingColorLUT3D_linear(Imaging imOut, Imaging imIn, int table_channels,
interpolate3(result, left, right, shift3D); interpolate3(result, left, right, shift3D);
rowOut[x] = MAKE_UINT32( v = MAKE_UINT32(
clip8(result[0]), clip8(result[1]), clip8(result[0]), clip8(result[1]),
clip8(result[2]), rowIn[x*4 + 3]); clip8(result[2]), rowIn[x*4 + 3]);
memcpy(rowOut + x * sizeof(v), &v, sizeof(v));
} }
if (table_channels == 4) { if (table_channels == 4) {
UINT32 v;
interpolate4(leftleft, &table[idx + 0], &table[idx + 4], shift1D); interpolate4(leftleft, &table[idx + 0], &table[idx + 4], shift1D);
interpolate4(leftright, &table[idx + size1D*4], interpolate4(leftright, &table[idx + size1D*4],
&table[idx + size1D*4 + 4], shift1D); &table[idx + size1D*4 + 4], shift1D);
@ -152,9 +155,10 @@ ImagingColorLUT3D_linear(Imaging imOut, Imaging imIn, int table_channels,
interpolate4(result, left, right, shift3D); interpolate4(result, left, right, shift3D);
rowOut[x] = MAKE_UINT32( v = MAKE_UINT32(
clip8(result[0]), clip8(result[1]), clip8(result[0]), clip8(result[1]),
clip8(result[2]), clip8(result[3])); clip8(result[2]), clip8(result[3]));
memcpy(rowOut + x * sizeof(v), &v, sizeof(v));
} }
} }
} }

View File

@ -229,42 +229,46 @@ static void
rgb2i(UINT8* out_, const UINT8* in, int xsize) rgb2i(UINT8* out_, const UINT8* in, int xsize)
{ {
int x; int x;
INT32* out = (INT32*) out_; for (x = 0; x < xsize; x++, in += 4, out_ += 4) {
for (x = 0; x < xsize; x++, in += 4) INT32 v = L24(in) >> 16;
*out++ = L24(in) >> 16; memcpy(out_, &v, sizeof(v));
}
} }
static void static void
rgb2f(UINT8* out_, const UINT8* in, int xsize) rgb2f(UINT8* out_, const UINT8* in, int xsize)
{ {
int x; int x;
FLOAT32* out = (FLOAT32*) out_; for (x = 0; x < xsize; x++, in += 4, out_ += 4) {
for (x = 0; x < xsize; x++, in += 4) FLOAT32 v = (float) L(in) / 1000.0F;
*out++ = (float) L(in) / 1000.0F; memcpy(out_, &v, sizeof(v));
}
} }
static void static void
rgb2bgr15(UINT8* out_, const UINT8* in, int xsize) rgb2bgr15(UINT8* out_, const UINT8* in, int xsize)
{ {
int x; int x;
UINT16* out = (UINT16*) out_; for (x = 0; x < xsize; x++, in += 4, out_ += 2) {
for (x = 0; x < xsize; x++, in += 4) UINT16 v =
*out++ =
((((UINT16)in[0])<<7)&0x7c00) + ((((UINT16)in[0])<<7)&0x7c00) +
((((UINT16)in[1])<<2)&0x03e0) + ((((UINT16)in[1])<<2)&0x03e0) +
((((UINT16)in[2])>>3)&0x001f); ((((UINT16)in[2])>>3)&0x001f);
memcpy(out_, &v, sizeof(v));
}
} }
static void static void
rgb2bgr16(UINT8* out_, const UINT8* in, int xsize) rgb2bgr16(UINT8* out_, const UINT8* in, int xsize)
{ {
int x; int x;
UINT16* out = (UINT16*) out_; for (x = 0; x < xsize; x++, in += 4, out_ += 2) {
for (x = 0; x < xsize; x++, in += 4) UINT16 v =
*out++ =
((((UINT16)in[0])<<8)&0xf800) + ((((UINT16)in[0])<<8)&0xf800) +
((((UINT16)in[1])<<3)&0x07e0) + ((((UINT16)in[1])<<3)&0x07e0) +
((((UINT16)in[2])>>3)&0x001f); ((((UINT16)in[2])>>3)&0x001f);
memcpy(out_, &v, sizeof(v));
}
} }
static void static void
@ -490,12 +494,13 @@ rgbT2rgba(UINT8* out, int xsize, int r, int g, int b)
UINT32 repl = trns & 0x00ffffff; UINT32 repl = trns & 0x00ffffff;
#endif #endif
UINT32* tmp = (UINT32 *)out;
int i; int i;
for (i=0; i < xsize; i++ ,tmp++) { for (i=0; i < xsize; i++ ,out += sizeof(trns)) {
if (tmp[0]==trns) { UINT32 v;
tmp[0]=repl; memcpy(&v, out, sizeof(v));
if (v==trns) {
memcpy(out, &repl, sizeof(repl));
} }
} }
} }
@ -565,32 +570,35 @@ static void
bit2i(UINT8* out_, const UINT8* in, int xsize) bit2i(UINT8* out_, const UINT8* in, int xsize)
{ {
int x; int x;
INT32* out = (INT32*) out_; for (x = 0; x < xsize; x++, out_ += 4) {
for (x = 0; x < xsize; x++) INT32 v = (*in++ != 0) ? 255 : 0;
*out++ = (*in++ != 0) ? 255 : 0; memcpy(out_, &v, sizeof(v));
}
} }
static void static void
l2i(UINT8* out_, const UINT8* in, int xsize) l2i(UINT8* out_, const UINT8* in, int xsize)
{ {
int x; int x;
INT32* out = (INT32*) out_; for (x = 0; x < xsize; x++, out_ += 4) {
for (x = 0; x < xsize; x++) INT32 v = *in++;
*out++ = (INT32) *in++; memcpy(out_, &v, sizeof(v));
}
} }
static void static void
i2l(UINT8* out, const UINT8* in_, int xsize) i2l(UINT8* out, const UINT8* in_, int xsize)
{ {
int x; int x;
INT32* in = (INT32*) in_; for (x = 0; x < xsize; x++, out++, in_ += 4) {
for (x = 0; x < xsize; x++, in++, out++) { INT32 v;
if (*in <= 0) memcpy(&v, in_, sizeof(v));
if (v <= 0)
*out = 0; *out = 0;
else if (*in >= 255) else if (v >= 255)
*out = 255; *out = 255;
else else
*out = (UINT8) *in; *out = (UINT8) v;
} }
} }
@ -598,10 +606,13 @@ static void
i2f(UINT8* out_, const UINT8* in_, int xsize) i2f(UINT8* out_, const UINT8* in_, int xsize)
{ {
int x; int x;
INT32* in = (INT32*) in_; for (x = 0; x < xsize; x++, in_ += 4, out_ += 4) {
FLOAT32* out = (FLOAT32*) out_; INT32 i;
for (x = 0; x < xsize; x++) FLOAT32 f;
*out++ = (FLOAT32) *in++; memcpy(&i, in_, sizeof(i));
f = i;
memcpy(out_, &f, sizeof(f));
}
} }
static void static void
@ -628,32 +639,35 @@ static void
bit2f(UINT8* out_, const UINT8* in, int xsize) bit2f(UINT8* out_, const UINT8* in, int xsize)
{ {
int x; int x;
FLOAT32* out = (FLOAT32*) out_; for (x = 0; x < xsize; x++, out_ += 4) {
for (x = 0; x < xsize; x++) FLOAT32 f = (*in++ != 0) ? 255.0F : 0.0F;
*out++ = (*in++ != 0) ? 255.0F : 0.0F; memcpy(out_, &f, sizeof(f));
}
} }
static void static void
l2f(UINT8* out_, const UINT8* in, int xsize) l2f(UINT8* out_, const UINT8* in, int xsize)
{ {
int x; int x;
FLOAT32* out = (FLOAT32*) out_; for (x = 0; x < xsize; x++, out_ += 4) {
for (x = 0; x < xsize; x++) FLOAT32 f = (FLOAT32) *in++;
*out++ = (FLOAT32) *in++; memcpy(out_, &f, sizeof(f));
}
} }
static void static void
f2l(UINT8* out, const UINT8* in_, int xsize) f2l(UINT8* out, const UINT8* in_, int xsize)
{ {
int x; int x;
FLOAT32* in = (FLOAT32*) in_; for (x = 0; x < xsize; x++, out++, in_ += 4) {
for (x = 0; x < xsize; x++, in++, out++) { FLOAT32 v;
if (*in <= 0.0) memcpy(&v, in_, sizeof(v));
if (v <= 0.0)
*out = 0; *out = 0;
else if (*in >= 255.0) else if (v >= 255.0)
*out = 255; *out = 255;
else else
*out = (UINT8) *in; *out = (UINT8) v;
} }
} }
@ -661,10 +675,13 @@ static void
f2i(UINT8* out_, const UINT8* in_, int xsize) f2i(UINT8* out_, const UINT8* in_, int xsize)
{ {
int x; int x;
FLOAT32* in = (FLOAT32*) in_; for (x = 0; x < xsize; x++, in_ += 4, out_ += 4) {
INT32* out = (INT32*) out_; FLOAT32 f;
for (x = 0; x < xsize; x++) INT32 i;
*out++ = (INT32) *in++; memcpy(&f, in_, sizeof(f));
i = f;
memcpy(out_, &i, sizeof(i));
}
} }
/* ----------------- */ /* ----------------- */
@ -723,9 +740,10 @@ static void
I_I16L(UINT8* out, const UINT8* in_, int xsize) I_I16L(UINT8* out, const UINT8* in_, int xsize)
{ {
int x, v; int x, v;
INT32* in = (INT32*) in_; for (x = 0; x < xsize; x++, in_ += 4) {
for (x = 0; x < xsize; x++, in++) { INT32 i;
v = CLIP16(*in); memcpy(&i, in_, sizeof(i));
v = CLIP16(i);
*out++ = (UINT8) v; *out++ = (UINT8) v;
*out++ = (UINT8) (v >> 8); *out++ = (UINT8) (v >> 8);
} }
@ -735,9 +753,10 @@ static void
I_I16B(UINT8* out, const UINT8* in_, int xsize) I_I16B(UINT8* out, const UINT8* in_, int xsize)
{ {
int x, v; int x, v;
INT32* in = (INT32*) in_; for (x = 0; x < xsize; x++, in_ += 4) {
for (x = 0; x < xsize; x++, in++) { INT32 i;
v = CLIP16(*in); memcpy(&i, in_, sizeof(i));
v = CLIP16(i);
*out++ = (UINT8) (v >> 8); *out++ = (UINT8) (v >> 8);
*out++ = (UINT8) v; *out++ = (UINT8) v;
} }
@ -748,9 +767,10 @@ static void
I16L_I(UINT8* out_, const UINT8* in, int xsize) I16L_I(UINT8* out_, const UINT8* in, int xsize)
{ {
int x; int x;
INT32* out = (INT32*) out_; for (x = 0; x < xsize; x++, in += 2, out_ += 4) {
for (x = 0; x < xsize; x++, in += 2) INT32 v = in[0] + ((int) in[1] << 8);
*out++ = in[0] + ((int) in[1] << 8); memcpy(out_, &v, sizeof(v));
}
} }
@ -758,18 +778,20 @@ static void
I16B_I(UINT8* out_, const UINT8* in, int xsize) I16B_I(UINT8* out_, const UINT8* in, int xsize)
{ {
int x; int x;
INT32* out = (INT32*) out_; for (x = 0; x < xsize; x++, in += 2, out_ += 4) {
for (x = 0; x < xsize; x++, in += 2) INT32 v = in[1] + ((int) in[0] << 8);
*out++ = in[1] + ((int) in[0] << 8); memcpy(out_, &v, sizeof(v));
}
} }
static void static void
I16L_F(UINT8* out_, const UINT8* in, int xsize) I16L_F(UINT8* out_, const UINT8* in, int xsize)
{ {
int x; int x;
FLOAT32* out = (FLOAT32*) out_; for (x = 0; x < xsize; x++, in += 2, out_ += 4) {
for (x = 0; x < xsize; x++, in += 2) FLOAT32 v = in[0] + ((int) in[1] << 8);
*out++ = (FLOAT32) (in[0] + ((int) in[1] << 8)); memcpy(out_, &v, sizeof(v));
}
} }
@ -777,9 +799,10 @@ static void
I16B_F(UINT8* out_, const UINT8* in, int xsize) I16B_F(UINT8* out_, const UINT8* in, int xsize)
{ {
int x; int x;
FLOAT32* out = (FLOAT32*) out_; for (x = 0; x < xsize; x++, in += 2, out_ += 4) {
for (x = 0; x < xsize; x++, in += 2) FLOAT32 v = in[1] + ((int) in[0] << 8);
*out++ = (FLOAT32) (in[1] + ((int) in[0] << 8)); memcpy(out_, &v, sizeof(v));
}
} }
static void static void
@ -1018,9 +1041,10 @@ static void
p2i(UINT8* out_, const UINT8* in, int xsize, const UINT8* palette) p2i(UINT8* out_, const UINT8* in, int xsize, const UINT8* palette)
{ {
int x; int x;
INT32* out = (INT32*) out_; for (x = 0; x < xsize; x++, in += 2, out_ += 4) {
for (x = 0; x < xsize; x++) INT32 v = L(&palette[in[x]*4]) / 1000;
*out++ = L(&palette[in[x]*4]) / 1000; memcpy(out_, &v, sizeof(v));
}
} }
static void static void
@ -1036,9 +1060,10 @@ static void
p2f(UINT8* out_, const UINT8* in, int xsize, const UINT8* palette) p2f(UINT8* out_, const UINT8* in, int xsize, const UINT8* palette)
{ {
int x; int x;
FLOAT32* out = (FLOAT32*) out_; for (x = 0; x < xsize; x++, in += 2, out_ += 4) {
for (x = 0; x < xsize; x++) FLOAT32 v = L(&palette[in[x]*4]) / 1000.0F;
*out++ = (float) L(&palette[in[x]*4]) / 1000.0F; memcpy(out_, &v, sizeof(v));
}
} }
static void static void

View File

@ -40,7 +40,6 @@
#define FLOOR(v) ((v) >= 0.0 ? (int) (v) : (int) floor(v)) #define FLOOR(v) ((v) >= 0.0 ? (int) (v) : (int) floor(v))
#define INK8(ink) (*(UINT8*)ink) #define INK8(ink) (*(UINT8*)ink)
#define INK32(ink) (*(INT32*)ink)
/* /*
* Rounds around zero (up=away from zero, down=torwards zero) * Rounds around zero (up=away from zero, down=torwards zero)
@ -68,8 +67,13 @@ static inline void
point8(Imaging im, int x, int y, int ink) point8(Imaging im, int x, int y, int ink)
{ {
if (x >= 0 && x < im->xsize && y >= 0 && y < im->ysize) if (x >= 0 && x < im->xsize && y >= 0 && y < im->ysize)
if (strncmp(im->mode, "I;16", 4) == 0) {
im->image8[y][x*2] = (UINT8) ink;
im->image8[y][x*2+1] = (UINT8) ink;
} else {
im->image8[y][x] = (UINT8) ink; im->image8[y][x] = (UINT8) ink;
} }
}
static inline void static inline void
point32(Imaging im, int x, int y, int ink) point32(Imaging im, int x, int y, int ink)
@ -95,7 +99,7 @@ point32rgba(Imaging im, int x, int y, int ink)
static inline void static inline void
hline8(Imaging im, int x0, int y0, int x1, int ink) hline8(Imaging im, int x0, int y0, int x1, int ink)
{ {
int tmp; int tmp, pixelwidth;
if (y0 >= 0 && y0 < im->ysize) { if (y0 >= 0 && y0 < im->ysize) {
if (x0 > x1) if (x0 > x1)
@ -108,8 +112,11 @@ hline8(Imaging im, int x0, int y0, int x1, int ink)
return; return;
else if (x1 >= im->xsize) else if (x1 >= im->xsize)
x1 = im->xsize-1; x1 = im->xsize-1;
if (x0 <= x1) if (x0 <= x1) {
memset(im->image8[y0] + x0, (UINT8) ink, x1 - x0 + 1); pixelwidth = strncmp(im->mode, "I;16", 4) == 0 ? 2 : 1;
memset(im->image8[y0] + x0 * pixelwidth, (UINT8) ink,
(x1 - x0 + 1) * pixelwidth);
}
} }
} }
@ -555,7 +562,7 @@ DRAW draw32rgba = { point32rgba, hline32rgba, line32rgba, polygon32rgba };
ink = INK8(ink_);\ ink = INK8(ink_);\
} else {\ } else {\
draw = (op) ? &draw32rgba : &draw32; \ draw = (op) ? &draw32rgba : &draw32; \
ink = INK32(ink_);\ memcpy(&ink, ink_, sizeof(ink)); \
} }
int int

View File

@ -122,26 +122,29 @@ ImagingFilter3x3(Imaging imOut, Imaging im, const float* kernel,
UINT8* in_1 = (UINT8*) im->image[y-1]; UINT8* in_1 = (UINT8*) im->image[y-1];
UINT8* in0 = (UINT8*) im->image[y]; UINT8* in0 = (UINT8*) im->image[y];
UINT8* in1 = (UINT8*) im->image[y+1]; UINT8* in1 = (UINT8*) im->image[y+1];
UINT32* out = (UINT32*) imOut->image[y]; UINT8* out = (UINT8*) imOut->image[y];
out[0] = ((UINT32*) in0)[0]; memcpy(out, in0, sizeof(UINT32));
if (im->bands == 2) { if (im->bands == 2) {
for (x = 1; x < im->xsize-1; x++) { for (x = 1; x < im->xsize-1; x++) {
float ss0 = offset; float ss0 = offset;
float ss3 = offset; float ss3 = offset;
UINT32 v;
ss0 += KERNEL1x3(in1, x*4+0, &kernel[0], 4); ss0 += KERNEL1x3(in1, x*4+0, &kernel[0], 4);
ss3 += KERNEL1x3(in1, x*4+3, &kernel[0], 4); ss3 += KERNEL1x3(in1, x*4+3, &kernel[0], 4);
ss0 += KERNEL1x3(in0, x*4+0, &kernel[3], 4); ss0 += KERNEL1x3(in0, x*4+0, &kernel[3], 4);
ss3 += KERNEL1x3(in0, x*4+3, &kernel[3], 4); ss3 += KERNEL1x3(in0, x*4+3, &kernel[3], 4);
ss0 += KERNEL1x3(in_1, x*4+0, &kernel[6], 4); ss0 += KERNEL1x3(in_1, x*4+0, &kernel[6], 4);
ss3 += KERNEL1x3(in_1, x*4+3, &kernel[6], 4); ss3 += KERNEL1x3(in_1, x*4+3, &kernel[6], 4);
out[x] = MAKE_UINT32(clip8(ss0), 0, 0, clip8(ss3)); v = MAKE_UINT32(clip8(ss0), 0, 0, clip8(ss3));
memcpy(out + x * sizeof(v), &v, sizeof(v));
} }
} else if (im->bands == 3) { } else if (im->bands == 3) {
for (x = 1; x < im->xsize-1; x++) { for (x = 1; x < im->xsize-1; x++) {
float ss0 = offset; float ss0 = offset;
float ss1 = offset; float ss1 = offset;
float ss2 = offset; float ss2 = offset;
UINT32 v;
ss0 += KERNEL1x3(in1, x*4+0, &kernel[0], 4); ss0 += KERNEL1x3(in1, x*4+0, &kernel[0], 4);
ss1 += KERNEL1x3(in1, x*4+1, &kernel[0], 4); ss1 += KERNEL1x3(in1, x*4+1, &kernel[0], 4);
ss2 += KERNEL1x3(in1, x*4+2, &kernel[0], 4); ss2 += KERNEL1x3(in1, x*4+2, &kernel[0], 4);
@ -151,8 +154,9 @@ ImagingFilter3x3(Imaging imOut, Imaging im, const float* kernel,
ss0 += KERNEL1x3(in_1, x*4+0, &kernel[6], 4); ss0 += KERNEL1x3(in_1, x*4+0, &kernel[6], 4);
ss1 += KERNEL1x3(in_1, x*4+1, &kernel[6], 4); ss1 += KERNEL1x3(in_1, x*4+1, &kernel[6], 4);
ss2 += KERNEL1x3(in_1, x*4+2, &kernel[6], 4); ss2 += KERNEL1x3(in_1, x*4+2, &kernel[6], 4);
out[x] = MAKE_UINT32( v = MAKE_UINT32(
clip8(ss0), clip8(ss1), clip8(ss2), 0); clip8(ss0), clip8(ss1), clip8(ss2), 0);
memcpy(out + x * sizeof(v), &v, sizeof(v));
} }
} else if (im->bands == 4) { } else if (im->bands == 4) {
for (x = 1; x < im->xsize-1; x++) { for (x = 1; x < im->xsize-1; x++) {
@ -160,6 +164,7 @@ ImagingFilter3x3(Imaging imOut, Imaging im, const float* kernel,
float ss1 = offset; float ss1 = offset;
float ss2 = offset; float ss2 = offset;
float ss3 = offset; float ss3 = offset;
UINT32 v;
ss0 += KERNEL1x3(in1, x*4+0, &kernel[0], 4); ss0 += KERNEL1x3(in1, x*4+0, &kernel[0], 4);
ss1 += KERNEL1x3(in1, x*4+1, &kernel[0], 4); ss1 += KERNEL1x3(in1, x*4+1, &kernel[0], 4);
ss2 += KERNEL1x3(in1, x*4+2, &kernel[0], 4); ss2 += KERNEL1x3(in1, x*4+2, &kernel[0], 4);
@ -172,11 +177,12 @@ ImagingFilter3x3(Imaging imOut, Imaging im, const float* kernel,
ss1 += KERNEL1x3(in_1, x*4+1, &kernel[6], 4); ss1 += KERNEL1x3(in_1, x*4+1, &kernel[6], 4);
ss2 += KERNEL1x3(in_1, x*4+2, &kernel[6], 4); ss2 += KERNEL1x3(in_1, x*4+2, &kernel[6], 4);
ss3 += KERNEL1x3(in_1, x*4+3, &kernel[6], 4); ss3 += KERNEL1x3(in_1, x*4+3, &kernel[6], 4);
out[x] = MAKE_UINT32( v = MAKE_UINT32(
clip8(ss0), clip8(ss1), clip8(ss2), clip8(ss3)); clip8(ss0), clip8(ss1), clip8(ss2), clip8(ss3));
memcpy(out + x * sizeof(v), &v, sizeof(v));
} }
} }
out[x] = ((UINT32*) in0)[x]; memcpy(out + x * sizeof(UINT32), in0 + x * sizeof(UINT32), sizeof(UINT32));
} }
} }
memcpy(imOut->image[y], im->image[y], im->linesize); memcpy(imOut->image[y], im->image[y], im->linesize);
@ -232,14 +238,14 @@ ImagingFilter5x5(Imaging imOut, Imaging im, const float* kernel,
UINT8* in0 = (UINT8*) im->image[y]; UINT8* in0 = (UINT8*) im->image[y];
UINT8* in1 = (UINT8*) im->image[y+1]; UINT8* in1 = (UINT8*) im->image[y+1];
UINT8* in2 = (UINT8*) im->image[y+2]; UINT8* in2 = (UINT8*) im->image[y+2];
UINT32* out = (UINT32*) imOut->image[y]; UINT8* out = (UINT8*) imOut->image[y];
out[0] = ((UINT32*) in0)[0]; memcpy(out, in0, sizeof(UINT32) * 2);
out[1] = ((UINT32*) in0)[1];
if (im->bands == 2) { if (im->bands == 2) {
for (x = 2; x < im->xsize-2; x++) { for (x = 2; x < im->xsize-2; x++) {
float ss0 = offset; float ss0 = offset;
float ss3 = offset; float ss3 = offset;
UINT32 v;
ss0 += KERNEL1x5(in2, x*4+0, &kernel[0], 4); ss0 += KERNEL1x5(in2, x*4+0, &kernel[0], 4);
ss3 += KERNEL1x5(in2, x*4+3, &kernel[0], 4); ss3 += KERNEL1x5(in2, x*4+3, &kernel[0], 4);
ss0 += KERNEL1x5(in1, x*4+0, &kernel[5], 4); ss0 += KERNEL1x5(in1, x*4+0, &kernel[5], 4);
@ -250,13 +256,15 @@ ImagingFilter5x5(Imaging imOut, Imaging im, const float* kernel,
ss3 += KERNEL1x5(in_1, x*4+3, &kernel[15], 4); ss3 += KERNEL1x5(in_1, x*4+3, &kernel[15], 4);
ss0 += KERNEL1x5(in_2, x*4+0, &kernel[20], 4); ss0 += KERNEL1x5(in_2, x*4+0, &kernel[20], 4);
ss3 += KERNEL1x5(in_2, x*4+3, &kernel[20], 4); ss3 += KERNEL1x5(in_2, x*4+3, &kernel[20], 4);
out[x] = MAKE_UINT32(clip8(ss0), 0, 0, clip8(ss3)); v = MAKE_UINT32(clip8(ss0), 0, 0, clip8(ss3));
memcpy(out + x * sizeof(v), &v, sizeof(v));
} }
} else if (im->bands == 3) { } else if (im->bands == 3) {
for (x = 2; x < im->xsize-2; x++) { for (x = 2; x < im->xsize-2; x++) {
float ss0 = offset; float ss0 = offset;
float ss1 = offset; float ss1 = offset;
float ss2 = offset; float ss2 = offset;
UINT32 v;
ss0 += KERNEL1x5(in2, x*4+0, &kernel[0], 4); ss0 += KERNEL1x5(in2, x*4+0, &kernel[0], 4);
ss1 += KERNEL1x5(in2, x*4+1, &kernel[0], 4); ss1 += KERNEL1x5(in2, x*4+1, &kernel[0], 4);
ss2 += KERNEL1x5(in2, x*4+2, &kernel[0], 4); ss2 += KERNEL1x5(in2, x*4+2, &kernel[0], 4);
@ -272,8 +280,9 @@ ImagingFilter5x5(Imaging imOut, Imaging im, const float* kernel,
ss0 += KERNEL1x5(in_2, x*4+0, &kernel[20], 4); ss0 += KERNEL1x5(in_2, x*4+0, &kernel[20], 4);
ss1 += KERNEL1x5(in_2, x*4+1, &kernel[20], 4); ss1 += KERNEL1x5(in_2, x*4+1, &kernel[20], 4);
ss2 += KERNEL1x5(in_2, x*4+2, &kernel[20], 4); ss2 += KERNEL1x5(in_2, x*4+2, &kernel[20], 4);
out[x] = MAKE_UINT32( v = MAKE_UINT32(
clip8(ss0), clip8(ss1), clip8(ss2), 0); clip8(ss0), clip8(ss1), clip8(ss2), 0);
memcpy(out + x * sizeof(v), &v, sizeof(v));
} }
} else if (im->bands == 4) { } else if (im->bands == 4) {
for (x = 2; x < im->xsize-2; x++) { for (x = 2; x < im->xsize-2; x++) {
@ -281,6 +290,7 @@ ImagingFilter5x5(Imaging imOut, Imaging im, const float* kernel,
float ss1 = offset; float ss1 = offset;
float ss2 = offset; float ss2 = offset;
float ss3 = offset; float ss3 = offset;
UINT32 v;
ss0 += KERNEL1x5(in2, x*4+0, &kernel[0], 4); ss0 += KERNEL1x5(in2, x*4+0, &kernel[0], 4);
ss1 += KERNEL1x5(in2, x*4+1, &kernel[0], 4); ss1 += KERNEL1x5(in2, x*4+1, &kernel[0], 4);
ss2 += KERNEL1x5(in2, x*4+2, &kernel[0], 4); ss2 += KERNEL1x5(in2, x*4+2, &kernel[0], 4);
@ -301,12 +311,12 @@ ImagingFilter5x5(Imaging imOut, Imaging im, const float* kernel,
ss1 += KERNEL1x5(in_2, x*4+1, &kernel[20], 4); ss1 += KERNEL1x5(in_2, x*4+1, &kernel[20], 4);
ss2 += KERNEL1x5(in_2, x*4+2, &kernel[20], 4); ss2 += KERNEL1x5(in_2, x*4+2, &kernel[20], 4);
ss3 += KERNEL1x5(in_2, x*4+3, &kernel[20], 4); ss3 += KERNEL1x5(in_2, x*4+3, &kernel[20], 4);
out[x] = MAKE_UINT32( v = MAKE_UINT32(
clip8(ss0), clip8(ss1), clip8(ss2), clip8(ss3)); clip8(ss0), clip8(ss1), clip8(ss2), clip8(ss3));
memcpy(out + x * sizeof(v), &v, sizeof(v));
} }
} }
out[x] = ((UINT32*) in0)[x]; memcpy(out + x * sizeof(UINT32), in0 + x * sizeof(UINT32), sizeof(UINT32) * 2);
out[x+1] = ((UINT32*) in0)[x+1];
} }
} }
memcpy(imOut->image[y], im->image[y], im->linesize); memcpy(imOut->image[y], im->image[y], im->linesize);

View File

@ -428,7 +428,7 @@ nearest_filter16(void* out, Imaging im, double xin, double yin)
int y = COORD(yin); int y = COORD(yin);
if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize)
return 0; return 0;
((INT16*)out)[0] = ((INT16*)(im->image8[y]))[x]; memcpy(out, im->image8[y] + x * sizeof(INT16), sizeof(INT16));
return 1; return 1;
} }
@ -439,7 +439,7 @@ nearest_filter32(void* out, Imaging im, double xin, double yin)
int y = COORD(yin); int y = COORD(yin);
if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize)
return 0; return 0;
((INT32*)out)[0] = im->image32[y][x]; memcpy(out, &im->image32[y][x], sizeof(INT32));
return 1; return 1;
} }
@ -489,18 +489,22 @@ bilinear_filter8(void* out, Imaging im, double xin, double yin)
static int static int
bilinear_filter32I(void* out, Imaging im, double xin, double yin) bilinear_filter32I(void* out, Imaging im, double xin, double yin)
{ {
INT32 k;
BILINEAR_HEAD(INT32); BILINEAR_HEAD(INT32);
BILINEAR_BODY(INT32, im->image32, 1, 0); BILINEAR_BODY(INT32, im->image32, 1, 0);
((INT32*)out)[0] = (INT32) v1; k = v1;
memcpy(out, &k, sizeof(k));
return 1; return 1;
} }
static int static int
bilinear_filter32F(void* out, Imaging im, double xin, double yin) bilinear_filter32F(void* out, Imaging im, double xin, double yin)
{ {
FLOAT32 k;
BILINEAR_HEAD(FLOAT32); BILINEAR_HEAD(FLOAT32);
BILINEAR_BODY(FLOAT32, im->image32, 1, 0); BILINEAR_BODY(FLOAT32, im->image32, 1, 0);
((FLOAT32*)out)[0] = (FLOAT32) v1; k = v1;
memcpy(out, &k, sizeof(k));
return 1; return 1;
} }
@ -601,18 +605,22 @@ bicubic_filter8(void* out, Imaging im, double xin, double yin)
static int static int
bicubic_filter32I(void* out, Imaging im, double xin, double yin) bicubic_filter32I(void* out, Imaging im, double xin, double yin)
{ {
INT32 k;
BICUBIC_HEAD(INT32); BICUBIC_HEAD(INT32);
BICUBIC_BODY(INT32, im->image32, 1, 0); BICUBIC_BODY(INT32, im->image32, 1, 0);
((INT32*)out)[0] = (INT32) v1; k = v1;
memcpy(out, &k, sizeof(k));
return 1; return 1;
} }
static int static int
bicubic_filter32F(void* out, Imaging im, double xin, double yin) bicubic_filter32F(void* out, Imaging im, double xin, double yin)
{ {
FLOAT32 k;
BICUBIC_HEAD(FLOAT32); BICUBIC_HEAD(FLOAT32);
BICUBIC_BODY(FLOAT32, im->image32, 1, 0); BICUBIC_BODY(FLOAT32, im->image32, 1, 0);
((FLOAT32*)out)[0] = (FLOAT32) v1; k = v1;
memcpy(out, &k, sizeof(k));
return 1; return 1;
} }

View File

@ -146,8 +146,8 @@ ImagingGetExtrema(Imaging im, void *extrema)
imax = in[x]; imax = in[x];
} }
} }
((INT32*) extrema)[0] = imin; memcpy(extrema, &imin, sizeof(imin));
((INT32*) extrema)[1] = imax; memcpy(((char*)extrema) + sizeof(imin), &imax, sizeof(imax));
break; break;
case IMAGING_TYPE_FLOAT32: case IMAGING_TYPE_FLOAT32:
fmin = fmax = ((FLOAT32*) im->image32[0])[0]; fmin = fmax = ((FLOAT32*) im->image32[0])[0];
@ -160,23 +160,27 @@ ImagingGetExtrema(Imaging im, void *extrema)
fmax = in[x]; fmax = in[x];
} }
} }
((FLOAT32*) extrema)[0] = fmin; memcpy(extrema, &fmin, sizeof(fmin));
((FLOAT32*) extrema)[1] = fmax; memcpy(((char*)extrema) + sizeof(fmin), &fmax, sizeof(fmax));
break; break;
case IMAGING_TYPE_SPECIAL: case IMAGING_TYPE_SPECIAL:
if (strcmp(im->mode, "I;16") == 0) { if (strcmp(im->mode, "I;16") == 0) {
imin = imax = ((UINT16*) im->image8[0])[0]; UINT16 v;
memcpy(&v, *im->image8, sizeof(v));
imin = imax = v;
for (y = 0; y < im->ysize; y++) { for (y = 0; y < im->ysize; y++) {
UINT16* in = (UINT16 *) im->image[y];
for (x = 0; x < im->xsize; x++) { for (x = 0; x < im->xsize; x++) {
if (imin > in[x]) memcpy(&v, im->image[y] + x * sizeof(v), sizeof(v));
imin = in[x]; if (imin > v)
else if (imax < in[x]) imin = v;
imax = in[x]; else if (imax < v)
imax = v;
} }
} }
((UINT16*) extrema)[0] = (UINT16) imin; v = (UINT16) imin;
((UINT16*) extrema)[1] = (UINT16) imax; memcpy(extrema, &v, sizeof(v));
v = (UINT16) imax;
memcpy(((char*)extrema) + sizeof(v), &v, sizeof(v));
break; break;
} }
/* FALL THROUGH */ /* FALL THROUGH */

View File

@ -130,8 +130,8 @@ ImagingGetHistogram(Imaging im, Imaging imMask, void* minmax)
} }
if (!im->xsize || !im->ysize) if (!im->xsize || !im->ysize)
break; break;
imin = ((INT32*) minmax)[0]; memcpy(&imin, minmax, sizeof(imin));
imax = ((INT32*) minmax)[1]; memcpy(&imax, ((char*)minmax) + sizeof(imin), sizeof(imax));
if (imin >= imax) if (imin >= imax)
break; break;
ImagingSectionEnter(&cookie); ImagingSectionEnter(&cookie);
@ -153,8 +153,8 @@ ImagingGetHistogram(Imaging im, Imaging imMask, void* minmax)
} }
if (!im->xsize || !im->ysize) if (!im->xsize || !im->ysize)
break; break;
fmin = ((FLOAT32*) minmax)[0]; memcpy(&fmin, minmax, sizeof(fmin));
fmax = ((FLOAT32*) minmax)[1]; memcpy(&fmax, ((char*)minmax) + sizeof(fmin), sizeof(fmax));
if (fmin >= fmax) if (fmin >= fmax)
break; break;
ImagingSectionEnter(&cookie); ImagingSectionEnter(&cookie);

View File

@ -261,7 +261,7 @@ ImagingPackRGB(UINT8* out, const UINT8* in, int pixels)
} }
#else #else
for (; i < pixels-1; i++) { for (; i < pixels-1; i++) {
((UINT32*)out)[0] = ((UINT32*)in)[i]; memcpy(out, in + i * 4, 4);
out += 3; out += 3;
} }
for (; i < pixels; i++) { for (; i < pixels; i++) {
@ -402,18 +402,19 @@ static void
packI16B(UINT8* out, const UINT8* in_, int pixels) packI16B(UINT8* out, const UINT8* in_, int pixels)
{ {
int i; int i;
INT32* in = (INT32*) in_;
UINT16 tmp_; UINT16 tmp_;
UINT8* tmp = (UINT8*) &tmp_; UINT8* tmp = (UINT8*) &tmp_;
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
if (in[0] <= 0) INT32 in;
memcpy(&in, in_, sizeof(in));
if (in <= 0)
tmp_ = 0; tmp_ = 0;
else if (in[0] > 65535) else if (in > 65535)
tmp_ = 65535; tmp_ = 65535;
else else
tmp_ = in[0]; tmp_ = in;
C16B; C16B;
out += 2; in++; out += 2; in_ += sizeof(in);
} }
} }

View File

@ -99,12 +99,12 @@ im_point_8_32(Imaging imOut, Imaging imIn, im_point_context* context)
{ {
int x, y; int x, y;
/* 8-bit source, 32-bit destination */ /* 8-bit source, 32-bit destination */
INT32* table = (INT32*) context->table; char* table = (char*) context->table;
for (y = 0; y < imIn->ysize; y++) { for (y = 0; y < imIn->ysize; y++) {
UINT8* in = imIn->image8[y]; UINT8* in = imIn->image8[y];
INT32* out = imOut->image32[y]; INT32* out = imOut->image32[y];
for (x = 0; x < imIn->xsize; x++) for (x = 0; x < imIn->xsize; x++)
out[x] = table[in[x]]; memcpy(out + x, table + in[x] * sizeof(INT32), sizeof(INT32));
} }
} }
@ -242,11 +242,15 @@ ImagingPointTransform(Imaging imIn, double scale, double offset)
if (strcmp(imIn->mode,"I;16") == 0) { if (strcmp(imIn->mode,"I;16") == 0) {
ImagingSectionEnter(&cookie); ImagingSectionEnter(&cookie);
for (y = 0; y < imIn->ysize; y++) { for (y = 0; y < imIn->ysize; y++) {
UINT16* in = (UINT16 *)imIn->image[y]; char* in = (char*)imIn->image[y];
UINT16* out = (UINT16 *)imOut->image[y]; char* out = (char*)imOut->image[y];
/* FIXME: add clipping? */ /* FIXME: add clipping? */
for (x = 0; x < imIn->xsize; x++) for (x = 0; x < imIn->xsize; x++) {
out[x] = in[x] * scale + offset; UINT16 v;
memcpy(&v, in + x * sizeof(v), sizeof(v));
v = v * scale + offset;
memcpy(out + x * sizeof(UINT16), &v, sizeof(v));
}
} }
ImagingSectionLeave(&cookie); ImagingSectionLeave(&cookie);
break; break;

View File

@ -304,6 +304,7 @@ ImagingResampleHorizontal_8bpc(Imaging imOut, Imaging imIn, int offset,
if (imIn->bands == 2) { if (imIn->bands == 2) {
for (yy = 0; yy < imOut->ysize; yy++) { for (yy = 0; yy < imOut->ysize; yy++) {
for (xx = 0; xx < imOut->xsize; xx++) { for (xx = 0; xx < imOut->xsize; xx++) {
UINT32 v;
xmin = bounds[xx * 2 + 0]; xmin = bounds[xx * 2 + 0];
xmax = bounds[xx * 2 + 1]; xmax = bounds[xx * 2 + 1];
k = &kk[xx * ksize]; k = &kk[xx * ksize];
@ -312,13 +313,14 @@ ImagingResampleHorizontal_8bpc(Imaging imOut, Imaging imIn, int offset,
ss0 += ((UINT8) imIn->image[yy + offset][(x + xmin)*4 + 0]) * k[x]; ss0 += ((UINT8) imIn->image[yy + offset][(x + xmin)*4 + 0]) * k[x];
ss3 += ((UINT8) imIn->image[yy + offset][(x + xmin)*4 + 3]) * k[x]; ss3 += ((UINT8) imIn->image[yy + offset][(x + xmin)*4 + 3]) * k[x];
} }
((UINT32 *) imOut->image[yy])[xx] = MAKE_UINT32( v = MAKE_UINT32(clip8(ss0), 0, 0, clip8(ss3));
clip8(ss0), 0, 0, clip8(ss3)); memcpy(imOut->image[yy] + xx * sizeof(v), &v, sizeof(v));
} }
} }
} else if (imIn->bands == 3) { } else if (imIn->bands == 3) {
for (yy = 0; yy < imOut->ysize; yy++) { for (yy = 0; yy < imOut->ysize; yy++) {
for (xx = 0; xx < imOut->xsize; xx++) { for (xx = 0; xx < imOut->xsize; xx++) {
UINT32 v;
xmin = bounds[xx * 2 + 0]; xmin = bounds[xx * 2 + 0];
xmax = bounds[xx * 2 + 1]; xmax = bounds[xx * 2 + 1];
k = &kk[xx * ksize]; k = &kk[xx * ksize];
@ -328,13 +330,14 @@ ImagingResampleHorizontal_8bpc(Imaging imOut, Imaging imIn, int offset,
ss1 += ((UINT8) imIn->image[yy + offset][(x + xmin)*4 + 1]) * k[x]; ss1 += ((UINT8) imIn->image[yy + offset][(x + xmin)*4 + 1]) * k[x];
ss2 += ((UINT8) imIn->image[yy + offset][(x + xmin)*4 + 2]) * k[x]; ss2 += ((UINT8) imIn->image[yy + offset][(x + xmin)*4 + 2]) * k[x];
} }
((UINT32 *) imOut->image[yy])[xx] = MAKE_UINT32( v = MAKE_UINT32(clip8(ss0), clip8(ss1), clip8(ss2), 0);
clip8(ss0), clip8(ss1), clip8(ss2), 0); memcpy(imOut->image[yy] + xx * sizeof(v), &v, sizeof(v));
} }
} }
} else { } else {
for (yy = 0; yy < imOut->ysize; yy++) { for (yy = 0; yy < imOut->ysize; yy++) {
for (xx = 0; xx < imOut->xsize; xx++) { for (xx = 0; xx < imOut->xsize; xx++) {
UINT32 v;
xmin = bounds[xx * 2 + 0]; xmin = bounds[xx * 2 + 0];
xmax = bounds[xx * 2 + 1]; xmax = bounds[xx * 2 + 1];
k = &kk[xx * ksize]; k = &kk[xx * ksize];
@ -345,8 +348,8 @@ ImagingResampleHorizontal_8bpc(Imaging imOut, Imaging imIn, int offset,
ss2 += ((UINT8) imIn->image[yy + offset][(x + xmin)*4 + 2]) * k[x]; ss2 += ((UINT8) imIn->image[yy + offset][(x + xmin)*4 + 2]) * k[x];
ss3 += ((UINT8) imIn->image[yy + offset][(x + xmin)*4 + 3]) * k[x]; ss3 += ((UINT8) imIn->image[yy + offset][(x + xmin)*4 + 3]) * k[x];
} }
((UINT32 *) imOut->image[yy])[xx] = MAKE_UINT32( v = MAKE_UINT32(clip8(ss0), clip8(ss1), clip8(ss2), clip8(ss3));
clip8(ss0), clip8(ss1), clip8(ss2), clip8(ss3)); memcpy(imOut->image[yy] + xx * sizeof(v), &v, sizeof(v));
} }
} }
} }
@ -388,13 +391,14 @@ ImagingResampleVertical_8bpc(Imaging imOut, Imaging imIn, int offset,
ymin = bounds[yy * 2 + 0]; ymin = bounds[yy * 2 + 0];
ymax = bounds[yy * 2 + 1]; ymax = bounds[yy * 2 + 1];
for (xx = 0; xx < imOut->xsize; xx++) { for (xx = 0; xx < imOut->xsize; xx++) {
UINT32 v;
ss0 = ss3 = 1 << (PRECISION_BITS -1); ss0 = ss3 = 1 << (PRECISION_BITS -1);
for (y = 0; y < ymax; y++) { for (y = 0; y < ymax; y++) {
ss0 += ((UINT8) imIn->image[y + ymin][xx*4 + 0]) * k[y]; ss0 += ((UINT8) imIn->image[y + ymin][xx*4 + 0]) * k[y];
ss3 += ((UINT8) imIn->image[y + ymin][xx*4 + 3]) * k[y]; ss3 += ((UINT8) imIn->image[y + ymin][xx*4 + 3]) * k[y];
} }
((UINT32 *) imOut->image[yy])[xx] = MAKE_UINT32( v = MAKE_UINT32(clip8(ss0), 0, 0, clip8(ss3));
clip8(ss0), 0, 0, clip8(ss3)); memcpy(imOut->image[yy] + xx * sizeof(v), &v, sizeof(v));
} }
} }
} else if (imIn->bands == 3) { } else if (imIn->bands == 3) {
@ -403,14 +407,15 @@ ImagingResampleVertical_8bpc(Imaging imOut, Imaging imIn, int offset,
ymin = bounds[yy * 2 + 0]; ymin = bounds[yy * 2 + 0];
ymax = bounds[yy * 2 + 1]; ymax = bounds[yy * 2 + 1];
for (xx = 0; xx < imOut->xsize; xx++) { for (xx = 0; xx < imOut->xsize; xx++) {
UINT32 v;
ss0 = ss1 = ss2 = 1 << (PRECISION_BITS -1); ss0 = ss1 = ss2 = 1 << (PRECISION_BITS -1);
for (y = 0; y < ymax; y++) { for (y = 0; y < ymax; y++) {
ss0 += ((UINT8) imIn->image[y + ymin][xx*4 + 0]) * k[y]; ss0 += ((UINT8) imIn->image[y + ymin][xx*4 + 0]) * k[y];
ss1 += ((UINT8) imIn->image[y + ymin][xx*4 + 1]) * k[y]; ss1 += ((UINT8) imIn->image[y + ymin][xx*4 + 1]) * k[y];
ss2 += ((UINT8) imIn->image[y + ymin][xx*4 + 2]) * k[y]; ss2 += ((UINT8) imIn->image[y + ymin][xx*4 + 2]) * k[y];
} }
((UINT32 *) imOut->image[yy])[xx] = MAKE_UINT32( v = MAKE_UINT32(clip8(ss0), clip8(ss1), clip8(ss2), 0);
clip8(ss0), clip8(ss1), clip8(ss2), 0); memcpy(imOut->image[yy] + xx * sizeof(v), &v, sizeof(v));
} }
} }
} else { } else {
@ -419,6 +424,7 @@ ImagingResampleVertical_8bpc(Imaging imOut, Imaging imIn, int offset,
ymin = bounds[yy * 2 + 0]; ymin = bounds[yy * 2 + 0];
ymax = bounds[yy * 2 + 1]; ymax = bounds[yy * 2 + 1];
for (xx = 0; xx < imOut->xsize; xx++) { for (xx = 0; xx < imOut->xsize; xx++) {
UINT32 v;
ss0 = ss1 = ss2 = ss3 = 1 << (PRECISION_BITS -1); ss0 = ss1 = ss2 = ss3 = 1 << (PRECISION_BITS -1);
for (y = 0; y < ymax; y++) { for (y = 0; y < ymax; y++) {
ss0 += ((UINT8) imIn->image[y + ymin][xx*4 + 0]) * k[y]; ss0 += ((UINT8) imIn->image[y + ymin][xx*4 + 0]) * k[y];
@ -426,8 +432,8 @@ ImagingResampleVertical_8bpc(Imaging imOut, Imaging imIn, int offset,
ss2 += ((UINT8) imIn->image[y + ymin][xx*4 + 2]) * k[y]; ss2 += ((UINT8) imIn->image[y + ymin][xx*4 + 2]) * k[y];
ss3 += ((UINT8) imIn->image[y + ymin][xx*4 + 3]) * k[y]; ss3 += ((UINT8) imIn->image[y + ymin][xx*4 + 3]) * k[y];
} }
((UINT32 *) imOut->image[yy])[xx] = MAKE_UINT32( v = MAKE_UINT32(clip8(ss0), clip8(ss1), clip8(ss2), clip8(ss3));
clip8(ss0), clip8(ss1), clip8(ss2), clip8(ss3)); memcpy(imOut->image[yy] + xx * sizeof(v), &v, sizeof(v));
} }
} }
} }

View File

@ -56,15 +56,15 @@ static int expandrow(UINT8* dest, UINT8* src, int n, int z)
return 0; return 0;
} }
static int expandrow2(UINT16* dest, UINT16* src, int n, int z) static int expandrow2(UINT8* dest, const UINT8* src, int n, int z)
{ {
UINT8 pixel, count; UINT8 pixel, count;
for (;n > 0; n--) for (;n > 0; n--)
{ {
pixel = ((UINT8*)src)[1]; pixel = src[1];
++src; src+=2;
if (n == 1 && pixel != 0) if (n == 1 && pixel != 0)
return n; return n;
count = pixel & RLE_MAX_RUN; count = pixel & RLE_MAX_RUN;
@ -72,16 +72,17 @@ static int expandrow2(UINT16* dest, UINT16* src, int n, int z)
return count; return count;
if (pixel & RLE_COPY_FLAG) { if (pixel & RLE_COPY_FLAG) {
while(count--) { while(count--) {
*dest = *src++; memcpy(dest, src, 2);
dest += z; src += 2;
dest += z * 2;
} }
} }
else { else {
while (count--) { while (count--) {
*dest = *src; memcpy(dest, src, 2);
dest += z; dest += z * 2;
} }
++src; src+=2;
} }
} }
return 0; return 0;
@ -162,7 +163,7 @@ ImagingSgiRleDecode(Imaging im, ImagingCodecState state,
goto sgi_finish_decode; goto sgi_finish_decode;
} }
else { else {
if(expandrow2((UINT16*)&state->buffer[c->channo * 2], (UINT16*)&ptr[c->rleoffset], c->rlelength, im->bands)) if(expandrow2(&state->buffer[c->channo * 2], &ptr[c->rleoffset], c->rlelength, im->bands))
goto sgi_finish_decode; goto sgi_finish_decode;
} }

View File

@ -530,7 +530,7 @@ int ImagingLibTiffMergeFieldInfo(ImagingCodecState state, TIFFDataType field_typ
// custom fields added with ImagingLibTiffMergeFieldInfo are only used for // custom fields added with ImagingLibTiffMergeFieldInfo are only used for
// decoding, ignore readcount; // decoding, ignore readcount;
int readcount = 0; int readcount = 0;
// we support writing single value, or a variable number of values // we support writing a single value, or a variable number of values
int writecount = 1; int writecount = 1;
// whether the first value should encode the number of values. // whether the first value should encode the number of values.
int passcount = 0; int passcount = 0;

View File

@ -32,7 +32,6 @@
#include "Imaging.h" #include "Imaging.h"
#define R 0 #define R 0
#define G 1 #define G 1
#define B 2 #define B 2
@ -327,11 +326,11 @@ static void
unpackLA(UINT8* _out, const UINT8* in, int pixels) unpackLA(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* LA, pixel interleaved */ /* LA, pixel interleaved */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
out[i] = MAKE_UINT32(in[0], in[0], in[0], in[1]); UINT32 iv = MAKE_UINT32(in[0], in[0], in[0], in[1]);
in += 2; memcpy(_out, &iv, sizeof(iv));
in += 2; _out += 4;
} }
} }
@ -339,10 +338,10 @@ static void
unpackLAL(UINT8* _out, const UINT8* in, int pixels) unpackLAL(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* LA, line interleaved */ /* LA, line interleaved */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++, _out+=4) {
out[i] = MAKE_UINT32(in[i], in[i], in[i], in[i+pixels]); UINT32 iv = MAKE_UINT32(in[i], in[i], in[i], in[i+pixels]);
memcpy(_out, &iv, sizeof(iv));
} }
} }
@ -480,38 +479,30 @@ void
ImagingUnpackRGB(UINT8* _out, const UINT8* in, int pixels) ImagingUnpackRGB(UINT8* _out, const UINT8* in, int pixels)
{ {
int i = 0; 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 */ /* RGB triplets */
for (; i < pixels-1; i++) { for (; i < pixels-1; i++) {
out[i] = MASK_UINT32_CHANNEL_3 | *(UINT32*)&in[0]; UINT32 iv;
in += 3; memcpy(&iv, in, sizeof(iv));
iv |= MASK_UINT32_CHANNEL_3;
memcpy(_out, &iv, sizeof(iv));
in += 3; _out += 4;
} }
for (; i < pixels; i++) { for (; i < pixels; i++) {
out[i] = MAKE_UINT32(in[0], in[1], in[2], 255); UINT32 iv = MAKE_UINT32(in[0], in[1], in[2], 255);
in += 3; memcpy(_out, &iv, sizeof(iv));
in += 3; _out += 4;
} }
#endif
} }
void void
unpackRGB16L(UINT8* _out, const UINT8* in, int pixels) unpackRGB16L(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* 16-bit RGB triplets, little-endian order */ /* 16-bit RGB triplets, little-endian order */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
out[i] = MAKE_UINT32(in[1], in[3], in[5], 255); UINT32 iv = MAKE_UINT32(in[1], in[3], in[5], 255);
in += 6; memcpy(_out, &iv, sizeof(iv));
in += 6; _out += 4;
} }
} }
@ -519,11 +510,11 @@ void
unpackRGB16B(UINT8* _out, const UINT8* in, int pixels) unpackRGB16B(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* 16-bit RGB triplets, big-endian order */ /* 16-bit RGB triplets, big-endian order */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
out[i] = MAKE_UINT32(in[0], in[2], in[4], 255); UINT32 iv = MAKE_UINT32(in[0], in[2], in[4], 255);
in += 6; memcpy(_out, &iv, sizeof(iv));
in += 6; _out += 4;
} }
} }
@ -531,10 +522,10 @@ static void
unpackRGBL(UINT8* _out, const UINT8* in, int pixels) unpackRGBL(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* RGB, line interleaved */ /* RGB, line interleaved */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++, _out+=4) {
out[i] = MAKE_UINT32(in[i], in[i+pixels], in[i+pixels+pixels], 255); UINT32 iv = MAKE_UINT32(in[i], in[i+pixels], in[i+pixels+pixels], 255);
memcpy(_out, &iv, sizeof(iv));
} }
} }
@ -542,12 +533,12 @@ static void
unpackRGBR(UINT8* _out, const UINT8* in, int pixels) unpackRGBR(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* RGB, bit reversed */ /* RGB, bit reversed */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
out[i] = MAKE_UINT32(BITFLIP[in[0]], BITFLIP[in[1]], UINT32 iv = MAKE_UINT32(BITFLIP[in[0]], BITFLIP[in[1]],
BITFLIP[in[2]], 255); BITFLIP[in[2]], 255);
in += 3; memcpy(_out, &iv, sizeof(iv));
in += 3; _out += 4;
} }
} }
@ -555,11 +546,11 @@ void
ImagingUnpackBGR(UINT8* _out, const UINT8* in, int pixels) ImagingUnpackBGR(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* RGB, reversed bytes */ /* RGB, reversed bytes */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
out[i] = MAKE_UINT32(in[2], in[1], in[0], 255); UINT32 iv = MAKE_UINT32(in[2], in[1], in[0], 255);
in += 3; memcpy(_out, &iv, sizeof(iv));
in += 3; _out += 4;
} }
} }
@ -687,11 +678,11 @@ static void
ImagingUnpackBGRX(UINT8* _out, const UINT8* in, int pixels) ImagingUnpackBGRX(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* RGB, reversed bytes with padding */ /* RGB, reversed bytes with padding */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
out[i] = MAKE_UINT32(in[2], in[1], in[0], 255); UINT32 iv = MAKE_UINT32(in[2], in[1], in[0], 255);
in += 4; memcpy(_out, &iv, sizeof(iv));
in += 4; _out += 4;
} }
} }
@ -699,11 +690,11 @@ static void
ImagingUnpackXRGB(UINT8* _out, const UINT8* in, int pixels) ImagingUnpackXRGB(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* RGB, leading pad */ /* RGB, leading pad */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
out[i] = MAKE_UINT32(in[1], in[2], in[3], 255); UINT32 iv = MAKE_UINT32(in[1], in[2], in[3], 255);
in += 4; memcpy(_out, &iv, sizeof(iv));
in += 4; _out += 4;
} }
} }
@ -711,11 +702,11 @@ static void
ImagingUnpackXBGR(UINT8* _out, const UINT8* in, int pixels) ImagingUnpackXBGR(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* RGB, reversed bytes, leading pad */ /* RGB, reversed bytes, leading pad */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
out[i] = MAKE_UINT32(in[3], in[2], in[1], 255); UINT32 iv = MAKE_UINT32(in[3], in[2], in[1], 255);
in += 4; memcpy(_out, &iv, sizeof(iv));
in += 4; _out += 4;
} }
} }
@ -725,11 +716,11 @@ static void
unpackRGBALA(UINT8* _out, const UINT8* in, int pixels) unpackRGBALA(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* greyscale with alpha */ /* greyscale with alpha */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
out[i] = MAKE_UINT32(in[0], in[0], in[0], in[1]); UINT32 iv = MAKE_UINT32(in[0], in[0], in[0], in[1]);
in += 2; memcpy(_out, &iv, sizeof(iv));
in += 2; _out += 4;
} }
} }
@ -737,11 +728,11 @@ static void
unpackRGBALA16B(UINT8* _out, const UINT8* in, int pixels) unpackRGBALA16B(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* 16-bit greyscale with alpha, big-endian */ /* 16-bit greyscale with alpha, big-endian */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
out[i] = MAKE_UINT32(in[0], in[0], in[0], in[2]); UINT32 iv = MAKE_UINT32(in[0], in[0], in[0], in[2]);
in += 4; memcpy(_out, &iv, sizeof(iv));
in += 4; _out += 4;
} }
} }
@ -749,20 +740,21 @@ static void
unpackRGBa16L(UINT8* _out, const UINT8* in, int pixels) unpackRGBa16L(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* premultiplied 16-bit RGBA, little-endian */ /* premultiplied 16-bit RGBA, little-endian */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
int a = in[7]; int a = in[7];
UINT32 iv;
if ( ! a) { if ( ! a) {
out[i] = 0; iv = 0;
} else if (a == 255) { } else if (a == 255) {
out[i] = MAKE_UINT32(in[1], in[3], in[5], a); iv = MAKE_UINT32(in[1], in[3], in[5], a);
} else { } else {
out[i] = MAKE_UINT32(CLIP8(in[1] * 255 / a), iv = MAKE_UINT32(CLIP8(in[1] * 255 / a),
CLIP8(in[3] * 255 / a), CLIP8(in[3] * 255 / a),
CLIP8(in[5] * 255 / a), a); CLIP8(in[5] * 255 / a), a);
} }
in += 8; memcpy(_out, &iv, sizeof(iv));
in += 8; _out += 4;
} }
} }
@ -770,20 +762,21 @@ static void
unpackRGBa16B(UINT8* _out, const UINT8* in, int pixels) unpackRGBa16B(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* premultiplied 16-bit RGBA, big-endian */ /* premultiplied 16-bit RGBA, big-endian */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
int a = in[6]; int a = in[6];
UINT32 iv;
if ( ! a) { if ( ! a) {
out[i] = 0; iv = 0;
} else if (a == 255) { } else if (a == 255) {
out[i] = MAKE_UINT32(in[0], in[2], in[4], a); iv = MAKE_UINT32(in[0], in[2], in[4], a);
} else { } else {
out[i] = MAKE_UINT32(CLIP8(in[0] * 255 / a), iv = MAKE_UINT32(CLIP8(in[0] * 255 / a),
CLIP8(in[2] * 255 / a), CLIP8(in[2] * 255 / a),
CLIP8(in[4] * 255 / a), a); CLIP8(in[4] * 255 / a), a);
} }
in += 8; memcpy(_out, &iv, sizeof(iv));
in += 8; _out += 4;
} }
} }
@ -791,20 +784,21 @@ static void
unpackRGBa(UINT8* _out, const UINT8* in, int pixels) unpackRGBa(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* premultiplied RGBA */ /* premultiplied RGBA */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
int a = in[3]; int a = in[3];
UINT32 iv;
if ( ! a) { if ( ! a) {
out[i] = 0; iv = 0;
} else if (a == 255) { } else if (a == 255) {
out[i] = MAKE_UINT32(in[0], in[1], in[2], a); iv = MAKE_UINT32(in[0], in[1], in[2], a);
} else { } else {
out[i] = MAKE_UINT32(CLIP8(in[0] * 255 / a), iv = MAKE_UINT32(CLIP8(in[0] * 255 / a),
CLIP8(in[1] * 255 / a), CLIP8(in[1] * 255 / a),
CLIP8(in[2] * 255 / a), a); CLIP8(in[2] * 255 / a), a);
} }
in += 4; memcpy(_out, &iv, sizeof(iv));
in += 4; _out += 4;
} }
} }
@ -854,20 +848,21 @@ static void
unpackBGRa(UINT8* _out, const UINT8* in, int pixels) unpackBGRa(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* premultiplied BGRA */ /* premultiplied BGRA */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
int a = in[3]; int a = in[3];
UINT32 iv;
if ( ! a) { if ( ! a) {
out[i] = 0; iv = 0;
} else if (a == 255) { } else if (a == 255) {
out[i] = MAKE_UINT32(in[2], in[1], in[0], a); iv = MAKE_UINT32(in[2], in[1], in[0], a);
} else { } else {
out[i] = MAKE_UINT32(CLIP8(in[2] * 255 / a), iv = MAKE_UINT32(CLIP8(in[2] * 255 / a),
CLIP8(in[1] * 255 / a), CLIP8(in[1] * 255 / a),
CLIP8(in[0] * 255 / a), a); CLIP8(in[0] * 255 / a), a);
} }
in += 4; memcpy(_out, &iv, sizeof(iv));
in += 4; _out += 4;
} }
} }
@ -889,11 +884,11 @@ static void
unpackRGBAL(UINT8* _out, const UINT8* in, int pixels) unpackRGBAL(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* RGBA, line interleaved */ /* RGBA, line interleaved */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++, _out+=4) {
out[i] = MAKE_UINT32(in[i], in[i+pixels], in[i+pixels+pixels], UINT32 iv = MAKE_UINT32(in[i], in[i+pixels], in[i+pixels+pixels],
in[i+pixels+pixels+pixels]); in[i+pixels+pixels+pixels]);
memcpy(_out, &iv, sizeof(iv));
} }
} }
@ -901,10 +896,10 @@ void
unpackRGBA16L(UINT8* _out, const UINT8* in, int pixels) unpackRGBA16L(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* 16-bit RGBA, little-endian order */ /* 16-bit RGBA, little-endian order */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++, _out+=4) {
out[i] = MAKE_UINT32(in[1], in[3], in[5], in[7]); UINT32 iv = MAKE_UINT32(in[1], in[3], in[5], in[7]);
memcpy(_out, &iv, sizeof(iv));
in += 8; in += 8;
} }
} }
@ -913,10 +908,10 @@ void
unpackRGBA16B(UINT8* _out, const UINT8* in, int pixels) unpackRGBA16B(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* 16-bit RGBA, big-endian order */ /* 16-bit RGBA, big-endian order */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++, _out+=4) {
out[i] = MAKE_UINT32(in[0], in[2], in[4], in[6]); UINT32 iv = MAKE_UINT32(in[0], in[2], in[4], in[6]);
memcpy(_out, &iv, sizeof(iv));
in += 8; in += 8;
} }
} }
@ -925,11 +920,11 @@ static void
unpackARGB(UINT8* _out, const UINT8* in, int pixels) unpackARGB(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* RGBA, leading pad */ /* RGBA, leading pad */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
out[i] = MAKE_UINT32(in[1], in[2], in[3], in[0]); UINT32 iv = MAKE_UINT32(in[1], in[2], in[3], in[0]);
in += 4; memcpy(_out, &iv, sizeof(iv));
in += 4; _out += 4;
} }
} }
@ -937,11 +932,11 @@ static void
unpackABGR(UINT8* _out, const UINT8* in, int pixels) unpackABGR(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* RGBA, reversed bytes */ /* RGBA, reversed bytes */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
out[i] = MAKE_UINT32(in[3], in[2], in[1], in[0]); UINT32 iv = MAKE_UINT32(in[3], in[2], in[1], in[0]);
in += 4; memcpy(_out, &iv, sizeof(iv));
in += 4; _out += 4;
} }
} }
@ -949,11 +944,11 @@ static void
unpackBGRA(UINT8* _out, const UINT8* in, int pixels) unpackBGRA(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* RGBA, reversed bytes */ /* RGBA, reversed bytes */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
out[i] = MAKE_UINT32(in[2], in[1], in[0], in[3]); UINT32 iv = MAKE_UINT32(in[2], in[1], in[0], in[3]);
in += 4; memcpy(_out, &iv, sizeof(iv));
in += 4; _out += 4;
} }
} }
@ -964,11 +959,11 @@ static void
unpackCMYKI(UINT8* _out, const UINT8* in, int pixels) unpackCMYKI(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* CMYK, inverted bytes (Photoshop 2.5) */ /* CMYK, inverted bytes (Photoshop 2.5) */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
out[i] = ~MAKE_UINT32(in[0], in[1], in[2], in[3]); UINT32 iv = ~MAKE_UINT32(in[0], in[1], in[2], in[3]);
in += 4; memcpy(_out, &iv, sizeof(iv));
in += 4; _out += 4;
} }
} }
@ -1042,30 +1037,30 @@ unpackI12_I16(UINT8* out, const UINT8* in, int pixels){
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
UINT8* tmp = (UINT8 *)&pixel; UINT8* tmp = (UINT8 *)&pixel;
#endif #endif
UINT16* out16 = (UINT16 *)out;
for (i = 0; i < pixels-1; i+=2) { for (i = 0; i < pixels-1; i+=2) {
pixel = (((UINT16) in[0]) << 4 ) + (in[1] >>4); pixel = (((UINT16) in[0]) << 4 ) + (in[1] >>4);
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
out[0] = tmp[1]; out[1] = tmp[0]; out[0] = tmp[1]; out[1] = tmp[0];
#else #else
out16[0] = pixel; memcpy(out, &pixel, sizeof(pixel));
#endif #endif
out+=2;
pixel = (((UINT16) (in[1] & 0x0F)) << 8) + in[2]; pixel = (((UINT16) (in[1] & 0x0F)) << 8) + in[2];
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
out[2] = tmp[1]; out[3] = tmp[0]; out[0] = tmp[1]; out[1] = tmp[0];
#else #else
out16[1] = pixel; memcpy(out, &pixel, sizeof(pixel));
#endif #endif
in += 3; out16 += 2; out+=4; in += 3; out+=2;
} }
if (i == pixels-1) { if (i == pixels-1) {
pixel = (((UINT16) in[0]) << 4 ) + (in[1] >>4); pixel = (((UINT16) in[0]) << 4 ) + (in[1] >>4);
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
out[0] = tmp[1]; out[1] = tmp[0]; out[0] = tmp[1]; out[1] = tmp[0];
#else #else
out16[0] = pixel; memcpy(out, &pixel, sizeof(pixel));
#endif #endif
} }
} }
@ -1096,44 +1091,20 @@ static void
copy4skip1(UINT8* _out, const UINT8* in, int pixels) copy4skip1(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
#ifdef __sparc
/* SPARC CPUs cannot read integers from nonaligned addresses. */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
_out[0] = in[0]; memcpy(_out, in, 4);
_out[1] = in[1]; in += 5; _out += 4;
_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 static void
copy4skip2(UINT8* _out, const UINT8* in, int pixels) copy4skip2(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
#ifdef __sparc
/* SPARC CPUs cannot read integers from nonaligned addresses. */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
_out[0] = in[0]; memcpy(_out, in, 4);
_out[1] = in[1]; in += 6; _out += 4;
_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
} }