Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 659460
Collapse All | Expand All

(-)a/_imaging.c (-17 / +22 lines)
Lines 375-380 getlist(PyObject* arg, Py_ssize_t* length, const char* wrong_length, int type) Link Here
375
    Py_ssize_t i, n;
375
    Py_ssize_t i, n;
376
    int itemp;
376
    int itemp;
377
    double dtemp;
377
    double dtemp;
378
    FLOAT32 ftemp;
378
    void* list;
379
    void* list;
379
    PyObject* seq;
380
    PyObject* seq;
380
    PyObject* op;
381
    PyObject* op;
Lines 414-428 getlist(PyObject* arg, Py_ssize_t* length, const char* wrong_length, int type) Link Here
414
            break;
415
            break;
415
        case TYPE_INT32:
416
        case TYPE_INT32:
416
            itemp = PyInt_AsLong(op);
417
            itemp = PyInt_AsLong(op);
417
            ((INT32*)list)[i] = itemp;
418
            memcpy(list + i * sizeof(INT32), &itemp, sizeof(itemp));
418
            break;
419
            break;
419
        case TYPE_FLOAT32:
420
        case TYPE_FLOAT32:
420
            dtemp = PyFloat_AsDouble(op);
421
            ftemp = PyFloat_AsDouble(op);
421
            ((FLOAT32*)list)[i] = (FLOAT32) dtemp;
422
            memcpy(list + i * sizeof(ftemp), &ftemp, sizeof(ftemp));
422
            break;
423
            break;
423
        case TYPE_DOUBLE:
424
        case TYPE_DOUBLE:
424
            dtemp = PyFloat_AsDouble(op);
425
            dtemp = PyFloat_AsDouble(op);
425
            ((double*)list)[i] = (double) dtemp;
426
            memcpy(list + i * sizeof(dtemp), &dtemp, sizeof(dtemp));
426
            break;
427
            break;
427
        }
428
        }
428
    }
429
    }
Lines 491-496 getink(PyObject* color, Imaging im, char* ink) Link Here
491
       to return it into a 32 bit C long
492
       to return it into a 32 bit C long
492
    */
493
    */
493
    PY_LONG_LONG r = 0;
494
    PY_LONG_LONG r = 0;
495
    INT32 rtmp;
496
    FLOAT32 ftmp;
494
497
495
    /* fill ink buffer (four bytes) with something that can
498
    /* fill ink buffer (four bytes) with something that can
496
       be cast to either UINT8 or INT32 */
499
       be cast to either UINT8 or INT32 */
Lines 556-569 getink(PyObject* color, Imaging im, char* ink) Link Here
556
        /* signed integer */
559
        /* signed integer */
557
        if (rIsInt != 1)
560
        if (rIsInt != 1)
558
            return NULL;
561
            return NULL;
559
        *(INT32*) ink = r;
562
        rtmp = r;
563
        memcpy(ink, &rtmp, sizeof(rtmp));
560
        return ink;
564
        return ink;
561
    case IMAGING_TYPE_FLOAT32:
565
    case IMAGING_TYPE_FLOAT32:
562
        /* floating point */
566
        /* floating point */
563
        f = PyFloat_AsDouble(color);
567
        f = PyFloat_AsDouble(color);
564
        if (f == -1.0 && PyErr_Occurred())
568
        if (f == -1.0 && PyErr_Occurred())
565
            return NULL;
569
            return NULL;
566
        *(FLOAT32*) ink = (FLOAT32) f;
570
        ftmp = (FLOAT32) f;
571
        memcpy(ink, &ftmp, sizeof(ftmp));
567
        return ink;
572
        return ink;
568
    case IMAGING_TYPE_SPECIAL:
573
    case IMAGING_TYPE_SPECIAL:
569
        if (strncmp(im->mode, "I;16", 4) == 0) {
574
        if (strncmp(im->mode, "I;16", 4) == 0) {
Lines 1499-1509 _resize(ImagingObject* self, PyObject* args) Link Here
1499
    int xsize, ysize;
1504
    int xsize, ysize;
1500
    int filter = IMAGING_TRANSFORM_NEAREST;
1505
    int filter = IMAGING_TRANSFORM_NEAREST;
1501
    float box[4] = {0, 0, 0, 0};
1506
    float box[4] = {0, 0, 0, 0};
1502
    
1507
1503
    imIn = self->image;
1508
    imIn = self->image;
1504
    box[2] = imIn->xsize;
1509
    box[2] = imIn->xsize;
1505
    box[3] = imIn->ysize;
1510
    box[3] = imIn->ysize;
1506
    
1511
1507
    if (!PyArg_ParseTuple(args, "(ii)|i(ffff)", &xsize, &ysize, &filter,
1512
    if (!PyArg_ParseTuple(args, "(ii)|i(ffff)", &xsize, &ysize, &filter,
1508
                          &box[0], &box[1], &box[2], &box[3]))
1513
                          &box[0], &box[1], &box[2], &box[3]))
1509
        return NULL;
1514
        return NULL;
Lines 2235-2241 void _font_text_asBytes(PyObject* encoded_string, unsigned char** text){ Link Here
2235
        }
2240
        }
2236
        return;
2241
        return;
2237
    }
2242
    }
2238
        
2243
2239
#endif
2244
#endif
2240
}
2245
}
2241
2246
Lines 3355-3361 _reset_stats(PyObject* self, PyObject* args) Link Here
3355
3360
3356
    if (!PyArg_ParseTuple(args, ":reset_stats"))
3361
    if (!PyArg_ParseTuple(args, ":reset_stats"))
3357
        return NULL;
3362
        return NULL;
3358
    
3363
3359
    arena->stats_new_count = 0;
3364
    arena->stats_new_count = 0;
3360
    arena->stats_allocated_blocks = 0;
3365
    arena->stats_allocated_blocks = 0;
3361
    arena->stats_reused_blocks = 0;
3366
    arena->stats_reused_blocks = 0;
Lines 3371-3377 _get_alignment(PyObject* self, PyObject* args) Link Here
3371
{
3376
{
3372
    if (!PyArg_ParseTuple(args, ":get_alignment"))
3377
    if (!PyArg_ParseTuple(args, ":get_alignment"))
3373
        return NULL;
3378
        return NULL;
3374
    
3379
3375
    return PyInt_FromLong(ImagingDefaultArena.alignment);
3380
    return PyInt_FromLong(ImagingDefaultArena.alignment);
3376
}
3381
}
3377
3382
Lines 3380-3386 _get_block_size(PyObject* self, PyObject* args) Link Here
3380
{
3385
{
3381
    if (!PyArg_ParseTuple(args, ":get_block_size"))
3386
    if (!PyArg_ParseTuple(args, ":get_block_size"))
3382
        return NULL;
3387
        return NULL;
3383
    
3388
3384
    return PyInt_FromLong(ImagingDefaultArena.block_size);
3389
    return PyInt_FromLong(ImagingDefaultArena.block_size);
3385
}
3390
}
3386
3391
Lines 3389-3395 _get_blocks_max(PyObject* self, PyObject* args) Link Here
3389
{
3394
{
3390
    if (!PyArg_ParseTuple(args, ":get_blocks_max"))
3395
    if (!PyArg_ParseTuple(args, ":get_blocks_max"))
3391
        return NULL;
3396
        return NULL;
3392
    
3397
3393
    return PyInt_FromLong(ImagingDefaultArena.blocks_max);
3398
    return PyInt_FromLong(ImagingDefaultArena.blocks_max);
3394
}
3399
}
3395
3400
Lines 3399-3405 _set_alignment(PyObject* self, PyObject* args) Link Here
3399
    int alignment;
3404
    int alignment;
3400
    if (!PyArg_ParseTuple(args, "i:set_alignment", &alignment))
3405
    if (!PyArg_ParseTuple(args, "i:set_alignment", &alignment))
3401
        return NULL;
3406
        return NULL;
3402
    
3407
3403
    if (alignment < 1 || alignment > 128) {
3408
    if (alignment < 1 || alignment > 128) {
3404
        PyErr_SetString(PyExc_ValueError, "alignment should be from 1 to 128");
3409
        PyErr_SetString(PyExc_ValueError, "alignment should be from 1 to 128");
3405
        return NULL;
3410
        return NULL;
Lines 3422-3428 _set_block_size(PyObject* self, PyObject* args) Link Here
3422
    int block_size;
3427
    int block_size;
3423
    if (!PyArg_ParseTuple(args, "i:set_block_size", &block_size))
3428
    if (!PyArg_ParseTuple(args, "i:set_block_size", &block_size))
3424
        return NULL;
3429
        return NULL;
3425
    
3430
3426
    if (block_size <= 0) {
3431
    if (block_size <= 0) {
3427
        PyErr_SetString(PyExc_ValueError,
3432
        PyErr_SetString(PyExc_ValueError,
3428
            "block_size should be greater than 0");
3433
            "block_size should be greater than 0");
Lines 3447-3453 _set_blocks_max(PyObject* self, PyObject* args) Link Here
3447
    int blocks_max;
3452
    int blocks_max;
3448
    if (!PyArg_ParseTuple(args, "i:set_blocks_max", &blocks_max))
3453
    if (!PyArg_ParseTuple(args, "i:set_blocks_max", &blocks_max))
3449
        return NULL;
3454
        return NULL;
3450
    
3455
3451
    if (blocks_max < 0) {
3456
    if (blocks_max < 0) {
3452
        PyErr_SetString(PyExc_ValueError,
3457
        PyErr_SetString(PyExc_ValueError,
3453
            "blocks_max should be greater than 0");
3458
            "blocks_max should be greater than 0");
Lines 3470-3476 _clear_cache(PyObject* self, PyObject* args) Link Here
3470
3475
3471
    if (!PyArg_ParseTuple(args, "|i:clear_cache", &i))
3476
    if (!PyArg_ParseTuple(args, "|i:clear_cache", &i))
3472
        return NULL;
3477
        return NULL;
3473
    
3478
3474
    ImagingMemoryClearCache(&ImagingDefaultArena, i);
3479
    ImagingMemoryClearCache(&ImagingDefaultArena, i);
3475
3480
3476
    Py_INCREF(Py_None);
3481
    Py_INCREF(Py_None);
(-)a/libImaging/Access.c (-16 / +15 lines)
Lines 94-104 static void Link Here
94
get_pixel_16L(Imaging im, int x, int y, void* color)
94
get_pixel_16L(Imaging im, int x, int y, void* color)
95
{
95
{
96
    UINT8* in = (UINT8*) &im->image[y][x+x];
96
    UINT8* in = (UINT8*) &im->image[y][x+x];
97
    UINT16* out = color;
98
#ifdef WORDS_BIGENDIAN
97
#ifdef WORDS_BIGENDIAN
99
    out[0] = in[0] + (in[1]<<8);
98
    UINT16 v = in[0] + (in[1]<<8);
99
    memcpy(color, &v, sizeof(v));
100
#else
100
#else
101
    out[0] = *(UINT16*) in;
101
    memcpy(color, in, sizeof(UINT16));
102
#endif
102
#endif
103
}
103
}
104
104
Lines 106-135 static void Link Here
106
get_pixel_16B(Imaging im, int x, int y, void* color)
106
get_pixel_16B(Imaging im, int x, int y, void* color)
107
{
107
{
108
    UINT8* in = (UINT8*) &im->image[y][x+x];
108
    UINT8* in = (UINT8*) &im->image[y][x+x];
109
    UINT16* out = color;
110
#ifdef WORDS_BIGENDIAN
109
#ifdef WORDS_BIGENDIAN
111
    out[0] = *(UINT16*) in;
110
    memcpy(color, in, sizeof(UINT16));
112
#else
111
#else
113
    out[0] = in[1] + (in[0]<<8);
112
    UINT16 v = in[1] + (in[0]<<8);
113
    memcpy(color, &v, sizeof(v));
114
#endif
114
#endif
115
}
115
}
116
116
117
static void
117
static void
118
get_pixel_32(Imaging im, int x, int y, void* color)
118
get_pixel_32(Imaging im, int x, int y, void* color)
119
{
119
{
120
    INT32* out = color;
120
    memcpy(color, &im->image32[y][x], sizeof(INT32));
121
    out[0] = im->image32[y][x];
122
}
121
}
123
122
124
static void
123
static void
125
get_pixel_32L(Imaging im, int x, int y, void* color)
124
get_pixel_32L(Imaging im, int x, int y, void* color)
126
{
125
{
127
    UINT8* in = (UINT8*) &im->image[y][x*4];
126
    UINT8* in = (UINT8*) &im->image[y][x*4];
128
    INT32* out = color;
129
#ifdef WORDS_BIGENDIAN
127
#ifdef WORDS_BIGENDIAN
130
    out[0] = in[0] + (in[1]<<8) + (in[2]<<16) + (in[3]<<24);
128
    INT32 v = in[0] + (in[1]<<8) + (in[2]<<16) + (in[3]<<24);
129
    memcpy(color, &v, sizeof(v));
131
#else
130
#else
132
    out[0] = *(INT32*) in;
131
    memcpy(color, in, sizeof(INT32));
133
#endif
132
#endif
134
}
133
}
135
134
Lines 137-147 static void Link Here
137
get_pixel_32B(Imaging im, int x, int y, void* color)
136
get_pixel_32B(Imaging im, int x, int y, void* color)
138
{
137
{
139
    UINT8* in = (UINT8*) &im->image[y][x*4];
138
    UINT8* in = (UINT8*) &im->image[y][x*4];
140
    INT32* out = color;
141
#ifdef WORDS_BIGENDIAN
139
#ifdef WORDS_BIGENDIAN
142
    out[0] = *(INT32*) in;
140
    memcpy(color, in, sizeof(INT32));
143
#else
141
#else
144
    out[0] = in[3] + (in[2]<<8) + (in[1]<<16) + (in[0]<<24);
142
    INT32 v = in[3] + (in[2]<<8) + (in[1]<<16) + (in[0]<<24);
143
    memcpy(color, &v, sizeof(v));
145
#endif
144
#endif
146
}
145
}
147
146
Lines 153-159 put_pixel(Imaging im, int x, int y, const void* color) Link Here
153
    if (im->image8)
152
    if (im->image8)
154
        im->image8[y][x] = *((UINT8*) color);
153
        im->image8[y][x] = *((UINT8*) color);
155
    else
154
    else
156
        im->image32[y][x] = *((INT32*) color);
155
        memcpy(&im->image32[y][x], color, sizeof(INT32));
157
}
156
}
158
157
159
static void
158
static void
Lines 205-211 put_pixel_32B(Imaging im, int x, int y, const void* color) Link Here
205
static void
204
static void
206
put_pixel_32(Imaging im, int x, int y, const void* color)
205
put_pixel_32(Imaging im, int x, int y, const void* color)
207
{
206
{
208
    im->image32[y][x] = *((INT32*) color);
207
    memcpy(&im->image32[y][x], color, sizeof(INT32));
209
}
208
}
210
209
211
void
210
void
(-)a/libImaging/Bands.c (-10 / +20 lines)
Lines 53-59 ImagingGetBand(Imaging imIn, int band) Link Here
53
        UINT8* out = imOut->image8[y];
53
        UINT8* out = imOut->image8[y];
54
        x = 0;
54
        x = 0;
55
        for (; x < imIn->xsize - 3; x += 4) {
55
        for (; x < imIn->xsize - 3; x += 4) {
56
            *((UINT32*) (out + x)) = MAKE_UINT32(in[0], in[4], in[8], in[12]);
56
            UINT32 v = MAKE_UINT32(in[0], in[4], in[8], in[12]);
57
            memcpy(out + x, &v, sizeof(v));
57
            in += 16;
58
            in += 16;
58
        }
59
        }
59
        for (; x < imIn->xsize; x++) {
60
        for (; x < imIn->xsize; x++) {
Lines 101-108 ImagingSplit(Imaging imIn, Imaging bands[4]) Link Here
101
            UINT8* out1 = bands[1]->image8[y];
102
            UINT8* out1 = bands[1]->image8[y];
102
            x = 0;
103
            x = 0;
103
            for (; x < imIn->xsize - 3; x += 4) {
104
            for (; x < imIn->xsize - 3; x += 4) {
104
                *((UINT32*) (out0 + x)) = MAKE_UINT32(in[0], in[4], in[8], in[12]);
105
                UINT32 v = MAKE_UINT32(in[0], in[4], in[8], in[12]);
105
                *((UINT32*) (out1 + x)) = MAKE_UINT32(in[0+3], in[4+3], in[8+3], in[12+3]);
106
                memcpy(out0 + x, &v, sizeof(v));
107
                v = MAKE_UINT32(in[0+3], in[4+3], in[8+3], in[12+3]);
108
                memcpy(out1 + x, &v, sizeof(v));
106
                in += 16;
109
                in += 16;
107
            }
110
            }
108
            for (; x < imIn->xsize; x++) {
111
            for (; x < imIn->xsize; x++) {
Lines 119-127 ImagingSplit(Imaging imIn, Imaging bands[4]) Link Here
119
            UINT8* out2 = bands[2]->image8[y];
122
            UINT8* out2 = bands[2]->image8[y];
120
            x = 0;
123
            x = 0;
121
            for (; x < imIn->xsize - 3; x += 4) {
124
            for (; x < imIn->xsize - 3; x += 4) {
122
                *((UINT32*) (out0 + x)) = MAKE_UINT32(in[0], in[4], in[8], in[12]);
125
                UINT32 v = MAKE_UINT32(in[0], in[4], in[8], in[12]);
123
                *((UINT32*) (out1 + x)) = MAKE_UINT32(in[0+1], in[4+1], in[8+1], in[12+1]);
126
                memcpy(out0 + x, &v, sizeof(v));
124
                *((UINT32*) (out2 + x)) = MAKE_UINT32(in[0+2], in[4+2], in[8+2], in[12+2]);
127
                v = MAKE_UINT32(in[0+1], in[4+1], in[8+1], in[12+1]);
128
                memcpy(out1 + x, &v, sizeof(v));
129
                v = MAKE_UINT32(in[0+2], in[4+2], in[8+2], in[12+2]);
130
                memcpy(out2 + x, &v, sizeof(v));
125
                in += 16;
131
                in += 16;
126
            }
132
            }
127
            for (; x < imIn->xsize; x++) {
133
            for (; x < imIn->xsize; x++) {
Lines 140-149 ImagingSplit(Imaging imIn, Imaging bands[4]) Link Here
140
            UINT8* out3 = bands[3]->image8[y];
146
            UINT8* out3 = bands[3]->image8[y];
141
            x = 0;
147
            x = 0;
142
            for (; x < imIn->xsize - 3; x += 4) {
148
            for (; x < imIn->xsize - 3; x += 4) {
143
                *((UINT32*) (out0 + x)) = MAKE_UINT32(in[0], in[4], in[8], in[12]);
149
                UINT32 v = MAKE_UINT32(in[0], in[4], in[8], in[12]);
144
                *((UINT32*) (out1 + x)) = MAKE_UINT32(in[0+1], in[4+1], in[8+1], in[12+1]);
150
                memcpy(out0 + x, &v, sizeof(v));
145
                *((UINT32*) (out2 + x)) = MAKE_UINT32(in[0+2], in[4+2], in[8+2], in[12+2]);
151
                v = MAKE_UINT32(in[0+1], in[4+1], in[8+1], in[12+1]);
146
                *((UINT32*) (out3 + x)) = MAKE_UINT32(in[0+3], in[4+3], in[8+3], in[12+3]);
152
                memcpy(out1 + x, &v, sizeof(v));
153
                v = MAKE_UINT32(in[0+2], in[4+2], in[8+2], in[12+2]);
154
                memcpy(out2 + x, &v, sizeof(v));
155
                v = MAKE_UINT32(in[0+3], in[4+3], in[8+3], in[12+3]);
156
                memcpy(out3 + x, &v, sizeof(v));
147
                in += 16;
157
                in += 16;
148
            }
158
            }
149
            for (; x < imIn->xsize; x++) {
159
            for (; x < imIn->xsize; x++) {
(-)a/libImaging/Convert.c (-70 / +95 lines)
Lines 230-271 static void Link Here
230
rgb2i(UINT8* out_, const UINT8* in, int xsize)
230
rgb2i(UINT8* out_, const UINT8* in, int xsize)
231
{
231
{
232
    int x;
232
    int x;
233
    INT32* out = (INT32*) out_;
233
    for (x = 0; x < xsize; x++, in += 4) {
234
    for (x = 0; x < xsize; x++, in += 4)
234
        INT32 v = L24(in) >> 16;
235
        *out++ = L24(in) >> 16;
235
        memcpy(out_ + x * sizeof(v), &v, sizeof(v));
236
    }
236
}
237
}
237
238
238
static void
239
static void
239
rgb2f(UINT8* out_, const UINT8* in, int xsize)
240
rgb2f(UINT8* out_, const UINT8* in, int xsize)
240
{
241
{
241
    int x;
242
    int x;
242
    FLOAT32* out = (FLOAT32*) out_;
243
    for (x = 0; x < xsize; x++, in += 4) {
243
    for (x = 0; x < xsize; x++, in += 4)
244
        FLOAT32 v = (float) L(in) / 1000.0F;
244
        *out++ = (float) L(in) / 1000.0F;
245
        memcpy(out_ + x * sizeof(v), &v, sizeof(v));
246
    }
245
}
247
}
246
248
247
static void
249
static void
248
rgb2bgr15(UINT8* out_, const UINT8* in, int xsize)
250
rgb2bgr15(UINT8* out_, const UINT8* in, int xsize)
249
{
251
{
250
    int x;
252
    int x;
251
    UINT16* out = (UINT16*) out_;
253
    for (x = 0; x < xsize; x++, in += 4) {
252
    for (x = 0; x < xsize; x++, in += 4)
254
        UINT16 v =
253
        *out++ =
254
            ((((UINT16)in[0])<<7)&0x7c00) +
255
            ((((UINT16)in[0])<<7)&0x7c00) +
255
            ((((UINT16)in[1])<<2)&0x03e0) +
256
            ((((UINT16)in[1])<<2)&0x03e0) +
256
            ((((UINT16)in[2])>>3)&0x001f);
257
            ((((UINT16)in[2])>>3)&0x001f);
258
        memcpy(out_ + x * sizeof(v), &v, sizeof(v));
259
    }
257
}
260
}
258
261
259
static void
262
static void
260
rgb2bgr16(UINT8* out_, const UINT8* in, int xsize)
263
rgb2bgr16(UINT8* out_, const UINT8* in, int xsize)
261
{
264
{
262
    int x;
265
    int x;
263
    UINT16* out = (UINT16*) out_;
266
    for (x = 0; x < xsize; x++, in += 4) {
264
    for (x = 0; x < xsize; x++, in += 4)
267
        UINT16 v =
265
        *out++ =
266
            ((((UINT16)in[0])<<8)&0xf800) +
268
            ((((UINT16)in[0])<<8)&0xf800) +
267
            ((((UINT16)in[1])<<3)&0x07e0) +
269
            ((((UINT16)in[1])<<3)&0x07e0) +
268
            ((((UINT16)in[2])>>3)&0x001f);
270
            ((((UINT16)in[2])>>3)&0x001f);
271
        memcpy(out_ + x * sizeof(v), &v, sizeof(v));
272
    }
269
}
273
}
270
274
271
static void
275
static void
Lines 491-502 rgbT2rgba(UINT8* out, int xsize, int r, int g, int b) Link Here
491
    UINT32 repl = trns & 0x00ffffff;
495
    UINT32 repl = trns & 0x00ffffff;
492
#endif
496
#endif
493
497
494
    UINT32* tmp = (UINT32 *)out;
495
    int i;
498
    int i;
496
499
497
    for (i=0; i < xsize; i++ ,tmp++) {
500
    for (i=0; i < xsize; i++ ,out += sizeof(trns)) {
498
        if (tmp[0]==trns) {
501
        UINT32 v;
499
            tmp[0]=repl;
502
        memcpy(&v, out, sizeof(v));
503
        if (v==trns) {
504
            memcpy(out, &repl, sizeof(repl));
500
        }
505
        }
501
    }
506
    }
502
}
507
}
Lines 554-585 static void Link Here
554
bit2i(UINT8* out_, const UINT8* in, int xsize)
559
bit2i(UINT8* out_, const UINT8* in, int xsize)
555
{
560
{
556
    int x;
561
    int x;
557
    INT32* out = (INT32*) out_;
562
    for (x = 0; x < xsize; x++) {
558
    for (x = 0; x < xsize; x++)
563
        INT32 v = (*in++ != 0) ? 255 : 0;
559
        *out++ = (*in++ != 0) ? 255 : 0;
564
        memcpy(out_ + x * sizeof(v), &v, sizeof(v));
565
    }
560
}
566
}
561
567
562
static void
568
static void
563
l2i(UINT8* out_, const UINT8* in, int xsize)
569
l2i(UINT8* out_, const UINT8* in, int xsize)
564
{
570
{
565
    int x;
571
    int x;
566
    INT32* out = (INT32*) out_;
572
    for (x = 0; x < xsize; x++) {
567
    for (x = 0; x < xsize; x++)
573
        INT32 v = *in++;
568
        *out++ = (INT32) *in++;
574
        memcpy(out_ + x * sizeof(v), &v, sizeof(v));
575
    }
569
}
576
}
570
577
571
static void
578
static void
572
i2l(UINT8* out, const UINT8* in_, int xsize)
579
i2l(UINT8* out, const UINT8* in_, int xsize)
573
{
580
{
574
    int x;
581
    int x;
575
    INT32* in = (INT32*) in_;
582
    for (x = 0; x < xsize; x++, out++) {
576
    for (x = 0; x < xsize; x++, in++, out++) {
583
        INT32 v;
577
        if (*in <= 0)
584
        memcpy(&v, in_ + x * sizeof(v), sizeof(v));
585
        if (v <= 0)
578
            *out = 0;
586
            *out = 0;
579
        else if (*in >= 255)
587
        else if (v >= 255)
580
            *out = 255;
588
            *out = 255;
581
        else
589
        else
582
            *out = (UINT8) *in;
590
            *out = (UINT8) v;
583
    }
591
    }
584
}
592
}
585
593
Lines 587-596 static void Link Here
587
i2f(UINT8* out_, const UINT8* in_, int xsize)
595
i2f(UINT8* out_, const UINT8* in_, int xsize)
588
{
596
{
589
    int x;
597
    int x;
590
    INT32* in = (INT32*) in_;
598
    for (x = 0; x < xsize; x++) {
591
    FLOAT32* out = (FLOAT32*) out_;
599
        INT32 i;
592
    for (x = 0; x < xsize; x++)
600
        FLOAT32 f;
593
        *out++ = (FLOAT32) *in++;
601
        memcpy(&i, in_ + x * sizeof(i), sizeof(i));
602
        f = i;
603
        memcpy(out_ + x * sizeof(f), &f, sizeof(f));
604
    }
594
}
605
}
595
606
596
/* ------------- */
607
/* ------------- */
Lines 601-632 static void Link Here
601
bit2f(UINT8* out_, const UINT8* in, int xsize)
612
bit2f(UINT8* out_, const UINT8* in, int xsize)
602
{
613
{
603
    int x;
614
    int x;
604
    FLOAT32* out = (FLOAT32*) out_;
615
    for (x = 0; x < xsize; x++) {
605
    for (x = 0; x < xsize; x++)
616
        FLOAT32 f = (*in++ != 0) ? 255.0F : 0.0F;
606
        *out++ = (*in++ != 0) ? 255.0F : 0.0F;
617
        memcpy(out_ + x * sizeof(f), &f, sizeof(f));
618
    }
607
}
619
}
608
620
609
static void
621
static void
610
l2f(UINT8* out_, const UINT8* in, int xsize)
622
l2f(UINT8* out_, const UINT8* in, int xsize)
611
{
623
{
612
    int x;
624
    int x;
613
    FLOAT32* out = (FLOAT32*) out_;
625
    for (x = 0; x < xsize; x++) {
614
    for (x = 0; x < xsize; x++)
626
        FLOAT32 f = (FLOAT32) *in++;
615
        *out++ = (FLOAT32) *in++;
627
        memcpy(out_ + x * sizeof(f), &f, sizeof(f));
628
    }
616
}
629
}
617
630
618
static void
631
static void
619
f2l(UINT8* out, const UINT8* in_, int xsize)
632
f2l(UINT8* out, const UINT8* in_, int xsize)
620
{
633
{
621
    int x;
634
    int x;
622
    FLOAT32* in = (FLOAT32*) in_;
635
    for (x = 0; x < xsize; x++, out++) {
623
    for (x = 0; x < xsize; x++, in++, out++) {
636
        FLOAT32 v;
624
        if (*in <= 0.0)
637
        memcpy(&v, in_ + x * sizeof(v), sizeof(v));
638
        if (v <= 0.0)
625
            *out = 0;
639
            *out = 0;
626
        else if (*in >= 255.0)
640
        else if (v >= 255.0)
627
            *out = 255;
641
            *out = 255;
628
        else
642
        else
629
            *out = (UINT8) *in;
643
            *out = (UINT8) v;
630
    }
644
    }
631
}
645
}
632
646
Lines 634-643 static void Link Here
634
f2i(UINT8* out_, const UINT8* in_, int xsize)
648
f2i(UINT8* out_, const UINT8* in_, int xsize)
635
{
649
{
636
    int x;
650
    int x;
637
    FLOAT32* in = (FLOAT32*) in_;
651
    for (x = 0; x < xsize; x++) {
638
    INT32* out = (INT32*) out_;
652
        FLOAT32 f;
639
    for (x = 0; x < xsize; x++)
653
        INT32 i;
640
        *out++ = (INT32) *in++;
654
        memcpy(&f, in_ + x * sizeof(f), sizeof(f));
655
        i = f;
656
        memcpy(out_ + x * sizeof(f), &i, sizeof(i));
657
    }
641
}
658
}
642
659
643
/* ----------------- */
660
/* ----------------- */
Lines 674-682 static void Link Here
674
I_I16L(UINT8* out, const UINT8* in_, int xsize)
691
I_I16L(UINT8* out, const UINT8* in_, int xsize)
675
{
692
{
676
    int x, v;
693
    int x, v;
677
    INT32* in = (INT32*) in_;
694
    for (x = 0; x < xsize; x++) {
678
    for (x = 0; x < xsize; x++, in++) {
695
        INT32 i;
679
        v = CLIP16(*in);
696
        memcpy(&i, in_ + x * sizeof(i), sizeof(i));
697
        v = CLIP16(i);
680
        *out++ = (UINT8) v;
698
        *out++ = (UINT8) v;
681
        *out++ = (UINT8) (v >> 8);
699
        *out++ = (UINT8) (v >> 8);
682
    }
700
    }
Lines 686-694 static void Link Here
686
I_I16B(UINT8* out, const UINT8* in_, int xsize)
704
I_I16B(UINT8* out, const UINT8* in_, int xsize)
687
{
705
{
688
    int x, v;
706
    int x, v;
689
    INT32* in = (INT32*) in_;
707
    for (x = 0; x < xsize; x++) {
690
    for (x = 0; x < xsize; x++, in++) {
708
        INT32 i;
691
        v = CLIP16(*in);
709
        memcpy(&i, in_ + x * sizeof(i), sizeof(i));
710
        v = CLIP16(i);
692
        *out++ = (UINT8) (v >> 8);
711
        *out++ = (UINT8) (v >> 8);
693
        *out++ = (UINT8) v;
712
        *out++ = (UINT8) v;
694
    }
713
    }
Lines 699-707 static void Link Here
699
I16L_I(UINT8* out_, const UINT8* in, int xsize)
718
I16L_I(UINT8* out_, const UINT8* in, int xsize)
700
{
719
{
701
    int x;
720
    int x;
702
    INT32* out = (INT32*) out_;
721
    for (x = 0; x < xsize; x++, in += 2) {
703
    for (x = 0; x < xsize; x++, in += 2)
722
        INT32 v = in[0] + ((int) in[1] << 8);
704
        *out++ = in[0] + ((int) in[1] << 8);
723
        memcpy(out_ + x * sizeof(v), &v, sizeof(v));
724
    }
705
}
725
}
706
726
707
727
Lines 709-726 static void Link Here
709
I16B_I(UINT8* out_, const UINT8* in, int xsize)
729
I16B_I(UINT8* out_, const UINT8* in, int xsize)
710
{
730
{
711
    int x;
731
    int x;
712
    INT32* out = (INT32*) out_;
732
    for (x = 0; x < xsize; x++, in += 2) {
713
    for (x = 0; x < xsize; x++, in += 2)
733
        INT32 v = in[1] + ((int) in[0] << 8);
714
        *out++ = in[1] + ((int) in[0] << 8);
734
        memcpy(out_ + x * sizeof(v), &v, sizeof(v));
735
    }
715
}
736
}
716
737
717
static void
738
static void
718
I16L_F(UINT8* out_, const UINT8* in, int xsize)
739
I16L_F(UINT8* out_, const UINT8* in, int xsize)
719
{
740
{
720
    int x;
741
    int x;
721
    FLOAT32* out = (FLOAT32*) out_;
742
    for (x = 0; x < xsize; x++, in += 2) {
722
    for (x = 0; x < xsize; x++, in += 2)
743
        FLOAT32 v = in[0] + ((int) in[1] << 8);
723
        *out++ = (FLOAT32) (in[0] + ((int) in[1] << 8));
744
        memcpy(out_ + x * sizeof(v), &v, sizeof(v));
745
    }
724
}
746
}
725
747
726
748
Lines 728-736 static void Link Here
728
I16B_F(UINT8* out_, const UINT8* in, int xsize)
750
I16B_F(UINT8* out_, const UINT8* in, int xsize)
729
{
751
{
730
    int x;
752
    int x;
731
    FLOAT32* out = (FLOAT32*) out_;
753
    for (x = 0; x < xsize; x++, in += 2) {
732
    for (x = 0; x < xsize; x++, in += 2)
754
        FLOAT32 v = in[1] + ((int) in[0] << 8);
733
        *out++ = (FLOAT32) (in[1] + ((int) in[0] << 8));
755
        memcpy(out_ + x * sizeof(v), &v, sizeof(v));
756
    }
734
}
757
}
735
758
736
static void
759
static void
Lines 931-948 static void Link Here
931
p2i(UINT8* out_, const UINT8* in, int xsize, const UINT8* palette)
954
p2i(UINT8* out_, const UINT8* in, int xsize, const UINT8* palette)
932
{
955
{
933
    int x;
956
    int x;
934
    INT32* out = (INT32*) out_;
957
    for (x = 0; x < xsize; x++, in += 2) {
935
    for (x = 0; x < xsize; x++)
958
        INT32 v = L(&palette[in[x]*4]) / 1000;
936
        *out++ = L(&palette[in[x]*4]) / 1000;
959
        memcpy(out_ + x * sizeof(v), &v, sizeof(v));
960
    }
937
}
961
}
938
962
939
static void
963
static void
940
p2f(UINT8* out_, const UINT8* in, int xsize, const UINT8* palette)
964
p2f(UINT8* out_, const UINT8* in, int xsize, const UINT8* palette)
941
{
965
{
942
    int x;
966
    int x;
943
    FLOAT32* out = (FLOAT32*) out_;
967
    for (x = 0; x < xsize; x++, in += 2) {
944
    for (x = 0; x < xsize; x++)
968
        FLOAT32 v = L(&palette[in[x]*4]) / 1000.0F;
945
        *out++ = (float) L(&palette[in[x]*4]) / 1000.0F;
969
        memcpy(out_ + x * sizeof(v), &v, sizeof(v));
970
    }
946
}
971
}
947
972
948
static void
973
static void
(-)a/libImaging/Draw.c (-2 / +1 lines)
Lines 40-46 Link Here
40
#define FLOOR(v) ((v) >= 0.0 ? (int) (v) : (int) floor(v))
40
#define FLOOR(v) ((v) >= 0.0 ? (int) (v) : (int) floor(v))
41
41
42
#define INK8(ink) (*(UINT8*)ink)
42
#define INK8(ink) (*(UINT8*)ink)
43
#define INK32(ink) (*(INT32*)ink)
44
43
45
/*
44
/*
46
 * Rounds around zero (up=away from zero, down=torwards zero)
45
 * Rounds around zero (up=away from zero, down=torwards zero)
Lines 555-561 DRAW draw32rgba = { point32rgba, hline32rgba, line32rgba, polygon32rgba }; Link Here
555
        ink = INK8(ink_);\
554
        ink = INK8(ink_);\
556
    } else {\
555
    } else {\
557
        draw = (op) ? &draw32rgba : &draw32;    \
556
        draw = (op) ? &draw32rgba : &draw32;    \
558
        ink = INK32(ink_);\
557
        memcpy(&ink, ink_, sizeof(ink)); \
559
    }
558
    }
560
559
561
int
560
int
(-)a/libImaging/Filter.c (-14 / +24 lines)
Lines 122-147 ImagingFilter3x3(Imaging imOut, Imaging im, const float* kernel, Link Here
122
            UINT8* in_1 = (UINT8*) im->image[y-1];
122
            UINT8* in_1 = (UINT8*) im->image[y-1];
123
            UINT8* in0 = (UINT8*) im->image[y];
123
            UINT8* in0 = (UINT8*) im->image[y];
124
            UINT8* in1 = (UINT8*) im->image[y+1];
124
            UINT8* in1 = (UINT8*) im->image[y+1];
125
            UINT32* out = (UINT32*) imOut->image[y];
125
            UINT8* out = (UINT8*) imOut->image[y];
126
126
127
            out[0] = ((UINT32*) in0)[0];
127
            memcpy(out, in0, sizeof(UINT32));
128
            if (im->bands == 2) {
128
            if (im->bands == 2) {
129
                for (x = 1; x < im->xsize-1; x++) {
129
                for (x = 1; x < im->xsize-1; x++) {
130
                    float ss0 = offset;
130
                    float ss0 = offset;
131
                    float ss3 = offset;
131
                    float ss3 = offset;
132
                    UINT32 v;
132
                    ss0 += KERNEL1x3(in1, x*4+0, &kernel[0], 4);
133
                    ss0 += KERNEL1x3(in1, x*4+0, &kernel[0], 4);
133
                    ss3 += KERNEL1x3(in1, x*4+3, &kernel[0], 4);
134
                    ss3 += KERNEL1x3(in1, x*4+3, &kernel[0], 4);
134
                    ss0 += KERNEL1x3(in0, x*4+0, &kernel[3], 4);
135
                    ss0 += KERNEL1x3(in0, x*4+0, &kernel[3], 4);
135
                    ss3 += KERNEL1x3(in0, x*4+3, &kernel[3], 4);
136
                    ss3 += KERNEL1x3(in0, x*4+3, &kernel[3], 4);
136
                    ss0 += KERNEL1x3(in_1, x*4+0, &kernel[6], 4);
137
                    ss0 += KERNEL1x3(in_1, x*4+0, &kernel[6], 4);
137
                    ss3 += KERNEL1x3(in_1, x*4+3, &kernel[6], 4);
138
                    ss3 += KERNEL1x3(in_1, x*4+3, &kernel[6], 4);
138
                    out[x] = MAKE_UINT32(clip8(ss0), 0, 0, clip8(ss3));
139
                    v = MAKE_UINT32(clip8(ss0), 0, 0, clip8(ss3));
140
                    memcpy(out + x * sizeof(v), &v, sizeof(v));
139
                }
141
                }
140
            } else if (im->bands == 3) {
142
            } else if (im->bands == 3) {
141
                for (x = 1; x < im->xsize-1; x++) {
143
                for (x = 1; x < im->xsize-1; x++) {
142
                    float ss0 = offset;
144
                    float ss0 = offset;
143
                    float ss1 = offset;
145
                    float ss1 = offset;
144
                    float ss2 = offset;
146
                    float ss2 = offset;
147
                    UINT32 v;
145
                    ss0 += KERNEL1x3(in1, x*4+0, &kernel[0], 4);
148
                    ss0 += KERNEL1x3(in1, x*4+0, &kernel[0], 4);
146
                    ss1 += KERNEL1x3(in1, x*4+1, &kernel[0], 4);
149
                    ss1 += KERNEL1x3(in1, x*4+1, &kernel[0], 4);
147
                    ss2 += KERNEL1x3(in1, x*4+2, &kernel[0], 4);
150
                    ss2 += KERNEL1x3(in1, x*4+2, &kernel[0], 4);
Lines 151-158 ImagingFilter3x3(Imaging imOut, Imaging im, const float* kernel, Link Here
151
                    ss0 += KERNEL1x3(in_1, x*4+0, &kernel[6], 4);
154
                    ss0 += KERNEL1x3(in_1, x*4+0, &kernel[6], 4);
152
                    ss1 += KERNEL1x3(in_1, x*4+1, &kernel[6], 4);
155
                    ss1 += KERNEL1x3(in_1, x*4+1, &kernel[6], 4);
153
                    ss2 += KERNEL1x3(in_1, x*4+2, &kernel[6], 4);
156
                    ss2 += KERNEL1x3(in_1, x*4+2, &kernel[6], 4);
154
                    out[x] = MAKE_UINT32(
157
                    v = MAKE_UINT32(
155
                        clip8(ss0), clip8(ss1), clip8(ss2), 0);
158
                        clip8(ss0), clip8(ss1), clip8(ss2), 0);
159
                    memcpy(out + x * sizeof(v), &v, sizeof(v));
156
                }
160
                }
157
            } else if (im->bands == 4) {
161
            } else if (im->bands == 4) {
158
                for (x = 1; x < im->xsize-1; x++) {
162
                for (x = 1; x < im->xsize-1; x++) {
Lines 160-165 ImagingFilter3x3(Imaging imOut, Imaging im, const float* kernel, Link Here
160
                    float ss1 = offset;
164
                    float ss1 = offset;
161
                    float ss2 = offset;
165
                    float ss2 = offset;
162
                    float ss3 = offset;
166
                    float ss3 = offset;
167
                    UINT32 v;
163
                    ss0 += KERNEL1x3(in1, x*4+0, &kernel[0], 4);
168
                    ss0 += KERNEL1x3(in1, x*4+0, &kernel[0], 4);
164
                    ss1 += KERNEL1x3(in1, x*4+1, &kernel[0], 4);
169
                    ss1 += KERNEL1x3(in1, x*4+1, &kernel[0], 4);
165
                    ss2 += KERNEL1x3(in1, x*4+2, &kernel[0], 4);
170
                    ss2 += KERNEL1x3(in1, x*4+2, &kernel[0], 4);
Lines 172-182 ImagingFilter3x3(Imaging imOut, Imaging im, const float* kernel, Link Here
172
                    ss1 += KERNEL1x3(in_1, x*4+1, &kernel[6], 4);
177
                    ss1 += KERNEL1x3(in_1, x*4+1, &kernel[6], 4);
173
                    ss2 += KERNEL1x3(in_1, x*4+2, &kernel[6], 4);
178
                    ss2 += KERNEL1x3(in_1, x*4+2, &kernel[6], 4);
174
                    ss3 += KERNEL1x3(in_1, x*4+3, &kernel[6], 4);
179
                    ss3 += KERNEL1x3(in_1, x*4+3, &kernel[6], 4);
175
                    out[x] = MAKE_UINT32(
180
                    v = MAKE_UINT32(
176
                        clip8(ss0), clip8(ss1), clip8(ss2), clip8(ss3));
181
                        clip8(ss0), clip8(ss1), clip8(ss2), clip8(ss3));
182
                    memcpy(out + x * sizeof(v), &v, sizeof(v));
177
                }
183
                }
178
            }
184
            }
179
            out[x] = ((UINT32*) in0)[x];
185
            memcpy(out + x * sizeof(UINT32), in0 + x * sizeof(UINT32), sizeof(UINT32));
180
        }
186
        }
181
    }
187
    }
182
    memcpy(imOut->image[y], im->image[y], im->linesize);
188
    memcpy(imOut->image[y], im->image[y], im->linesize);
Lines 232-245 ImagingFilter5x5(Imaging imOut, Imaging im, const float* kernel, Link Here
232
            UINT8* in0 = (UINT8*) im->image[y];
238
            UINT8* in0 = (UINT8*) im->image[y];
233
            UINT8* in1 = (UINT8*) im->image[y+1];
239
            UINT8* in1 = (UINT8*) im->image[y+1];
234
            UINT8* in2 = (UINT8*) im->image[y+2];
240
            UINT8* in2 = (UINT8*) im->image[y+2];
235
            UINT32* out = (UINT32*) imOut->image[y];
241
            UINT8* out = (UINT8*) imOut->image[y];
236
242
237
            out[0] = ((UINT32*) in0)[0];
243
            memcpy(out, in0, sizeof(UINT32) * 2);
238
            out[1] = ((UINT32*) in0)[1];
239
            if (im->bands == 2) {
244
            if (im->bands == 2) {
240
                for (x = 2; x < im->xsize-2; x++) {
245
                for (x = 2; x < im->xsize-2; x++) {
241
                    float ss0 = offset;
246
                    float ss0 = offset;
242
                    float ss3 = offset;
247
                    float ss3 = offset;
248
                    UINT32 v;
243
                    ss0 += KERNEL1x5(in2, x*4+0, &kernel[0], 4);
249
                    ss0 += KERNEL1x5(in2, x*4+0, &kernel[0], 4);
244
                    ss3 += KERNEL1x5(in2, x*4+3, &kernel[0], 4);
250
                    ss3 += KERNEL1x5(in2, x*4+3, &kernel[0], 4);
245
                    ss0 += KERNEL1x5(in1, x*4+0, &kernel[5], 4);
251
                    ss0 += KERNEL1x5(in1, x*4+0, &kernel[5], 4);
Lines 250-262 ImagingFilter5x5(Imaging imOut, Imaging im, const float* kernel, Link Here
250
                    ss3 += KERNEL1x5(in_1, x*4+3, &kernel[15], 4);
256
                    ss3 += KERNEL1x5(in_1, x*4+3, &kernel[15], 4);
251
                    ss0 += KERNEL1x5(in_2, x*4+0, &kernel[20], 4);
257
                    ss0 += KERNEL1x5(in_2, x*4+0, &kernel[20], 4);
252
                    ss3 += KERNEL1x5(in_2, x*4+3, &kernel[20], 4);
258
                    ss3 += KERNEL1x5(in_2, x*4+3, &kernel[20], 4);
253
                    out[x] = MAKE_UINT32(clip8(ss0), 0, 0, clip8(ss3));
259
                    v = MAKE_UINT32(clip8(ss0), 0, 0, clip8(ss3));
260
                    memcpy(out + x * sizeof(v), &v, sizeof(v));
254
                }
261
                }
255
            } else if (im->bands == 3) {
262
            } else if (im->bands == 3) {
256
                for (x = 2; x < im->xsize-2; x++) {
263
                for (x = 2; x < im->xsize-2; x++) {
257
                    float ss0 = offset;
264
                    float ss0 = offset;
258
                    float ss1 = offset;
265
                    float ss1 = offset;
259
                    float ss2 = offset;
266
                    float ss2 = offset;
267
                    UINT32 v;
260
                    ss0 += KERNEL1x5(in2, x*4+0, &kernel[0], 4);
268
                    ss0 += KERNEL1x5(in2, x*4+0, &kernel[0], 4);
261
                    ss1 += KERNEL1x5(in2, x*4+1, &kernel[0], 4);
269
                    ss1 += KERNEL1x5(in2, x*4+1, &kernel[0], 4);
262
                    ss2 += KERNEL1x5(in2, x*4+2, &kernel[0], 4);
270
                    ss2 += KERNEL1x5(in2, x*4+2, &kernel[0], 4);
Lines 272-279 ImagingFilter5x5(Imaging imOut, Imaging im, const float* kernel, Link Here
272
                    ss0 += KERNEL1x5(in_2, x*4+0, &kernel[20], 4);
280
                    ss0 += KERNEL1x5(in_2, x*4+0, &kernel[20], 4);
273
                    ss1 += KERNEL1x5(in_2, x*4+1, &kernel[20], 4);
281
                    ss1 += KERNEL1x5(in_2, x*4+1, &kernel[20], 4);
274
                    ss2 += KERNEL1x5(in_2, x*4+2, &kernel[20], 4);
282
                    ss2 += KERNEL1x5(in_2, x*4+2, &kernel[20], 4);
275
                    out[x] = MAKE_UINT32(
283
                    v = MAKE_UINT32(
276
                        clip8(ss0), clip8(ss1), clip8(ss2), 0);
284
                        clip8(ss0), clip8(ss1), clip8(ss2), 0);
285
                    memcpy(out + x * sizeof(v), &v, sizeof(v));
277
                }
286
                }
278
            } else if (im->bands == 4) {
287
            } else if (im->bands == 4) {
279
                for (x = 2; x < im->xsize-2; x++) {
288
                for (x = 2; x < im->xsize-2; x++) {
Lines 281-286 ImagingFilter5x5(Imaging imOut, Imaging im, const float* kernel, Link Here
281
                    float ss1 = offset;
290
                    float ss1 = offset;
282
                    float ss2 = offset;
291
                    float ss2 = offset;
283
                    float ss3 = offset;
292
                    float ss3 = offset;
293
                    UINT32 v;
284
                    ss0 += KERNEL1x5(in2, x*4+0, &kernel[0], 4);
294
                    ss0 += KERNEL1x5(in2, x*4+0, &kernel[0], 4);
285
                    ss1 += KERNEL1x5(in2, x*4+1, &kernel[0], 4);
295
                    ss1 += KERNEL1x5(in2, x*4+1, &kernel[0], 4);
286
                    ss2 += KERNEL1x5(in2, x*4+2, &kernel[0], 4);
296
                    ss2 += KERNEL1x5(in2, x*4+2, &kernel[0], 4);
Lines 301-312 ImagingFilter5x5(Imaging imOut, Imaging im, const float* kernel, Link Here
301
                    ss1 += KERNEL1x5(in_2, x*4+1, &kernel[20], 4);
311
                    ss1 += KERNEL1x5(in_2, x*4+1, &kernel[20], 4);
302
                    ss2 += KERNEL1x5(in_2, x*4+2, &kernel[20], 4);
312
                    ss2 += KERNEL1x5(in_2, x*4+2, &kernel[20], 4);
303
                    ss3 += KERNEL1x5(in_2, x*4+3, &kernel[20], 4);
313
                    ss3 += KERNEL1x5(in_2, x*4+3, &kernel[20], 4);
304
                    out[x] = MAKE_UINT32(
314
                    v = MAKE_UINT32(
305
                        clip8(ss0), clip8(ss1), clip8(ss2), clip8(ss3));
315
                        clip8(ss0), clip8(ss1), clip8(ss2), clip8(ss3));
316
                    memcpy(out + x * sizeof(v), &v, sizeof(v));
306
                }
317
                }
307
            }
318
            }
308
            out[x] = ((UINT32*) in0)[x];
319
            memcpy(out + x * sizeof(UINT32), in0 + x * sizeof(UINT32), sizeof(UINT32) * 2);
309
            out[x+1] = ((UINT32*) in0)[x+1];
310
        }
320
        }
311
    }
321
    }
312
    memcpy(imOut->image[y], im->image[y], im->linesize);
322
    memcpy(imOut->image[y], im->image[y], im->linesize);
(-)a/libImaging/Geometry.c (-6 / +14 lines)
Lines 396-402 nearest_filter16(void* out, Imaging im, double xin, double yin) Link Here
396
    int y = COORD(yin);
396
    int y = COORD(yin);
397
    if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize)
397
    if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize)
398
        return 0;
398
        return 0;
399
    ((INT16*)out)[0] = ((INT16*)(im->image8[y]))[x];
399
    memcpy(out, im->image8[y] + x * sizeof(INT16), sizeof(INT16));
400
    return 1;
400
    return 1;
401
}
401
}
402
402
Lines 407-413 nearest_filter32(void* out, Imaging im, double xin, double yin) Link Here
407
    int y = COORD(yin);
407
    int y = COORD(yin);
408
    if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize)
408
    if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize)
409
        return 0;
409
        return 0;
410
    ((INT32*)out)[0] = im->image32[y][x];
410
    memcpy(out, &im->image32[y][x], sizeof(INT32));
411
    return 1;
411
    return 1;
412
}
412
}
413
413
Lines 457-474 bilinear_filter8(void* out, Imaging im, double xin, double yin) Link Here
457
static int
457
static int
458
bilinear_filter32I(void* out, Imaging im, double xin, double yin)
458
bilinear_filter32I(void* out, Imaging im, double xin, double yin)
459
{
459
{
460
    INT32 k;
460
    BILINEAR_HEAD(INT32);
461
    BILINEAR_HEAD(INT32);
461
    BILINEAR_BODY(INT32, im->image32, 1, 0);
462
    BILINEAR_BODY(INT32, im->image32, 1, 0);
462
    ((INT32*)out)[0] = (INT32) v1;
463
    k = v1;
464
    memcpy(out, &k, sizeof(k));
463
    return 1;
465
    return 1;
464
}
466
}
465
467
466
static int
468
static int
467
bilinear_filter32F(void* out, Imaging im, double xin, double yin)
469
bilinear_filter32F(void* out, Imaging im, double xin, double yin)
468
{
470
{
471
    FLOAT32 k;
469
    BILINEAR_HEAD(FLOAT32);
472
    BILINEAR_HEAD(FLOAT32);
470
    BILINEAR_BODY(FLOAT32, im->image32, 1, 0);
473
    BILINEAR_BODY(FLOAT32, im->image32, 1, 0);
471
    ((FLOAT32*)out)[0] = (FLOAT32) v1;
474
    k = v1;
475
    memcpy(out, &k, sizeof(k));
472
    return 1;
476
    return 1;
473
}
477
}
474
478
Lines 569-586 bicubic_filter8(void* out, Imaging im, double xin, double yin) Link Here
569
static int
573
static int
570
bicubic_filter32I(void* out, Imaging im, double xin, double yin)
574
bicubic_filter32I(void* out, Imaging im, double xin, double yin)
571
{
575
{
576
    INT32 k;
572
    BICUBIC_HEAD(INT32);
577
    BICUBIC_HEAD(INT32);
573
    BICUBIC_BODY(INT32, im->image32, 1, 0);
578
    BICUBIC_BODY(INT32, im->image32, 1, 0);
574
    ((INT32*)out)[0] = (INT32) v1;
579
    k = v1;
580
    memcpy(out, &k, sizeof(k));
575
    return 1;
581
    return 1;
576
}
582
}
577
583
578
static int
584
static int
579
bicubic_filter32F(void* out, Imaging im, double xin, double yin)
585
bicubic_filter32F(void* out, Imaging im, double xin, double yin)
580
{
586
{
587
    FLOAT32 k;
581
    BICUBIC_HEAD(FLOAT32);
588
    BICUBIC_HEAD(FLOAT32);
582
    BICUBIC_BODY(FLOAT32, im->image32, 1, 0);
589
    BICUBIC_BODY(FLOAT32, im->image32, 1, 0);
583
    ((FLOAT32*)out)[0] = (FLOAT32) v1;
590
    k = v1;
591
    memcpy(out, &k, sizeof(k));
584
    return 1;
592
    return 1;
585
}
593
}
586
594
(-)a/libImaging/GetBBox.c (-12 / +16 lines)
Lines 146-153 ImagingGetExtrema(Imaging im, void *extrema) Link Here
146
                    imax = in[x];
146
                    imax = in[x];
147
            }
147
            }
148
        }
148
        }
149
        ((INT32*) extrema)[0] = imin;
149
        memcpy(extrema, &imin, sizeof(imin));
150
        ((INT32*) extrema)[1] = imax;
150
        memcpy(((char*)extrema) + sizeof(imin), &imax, sizeof(imax));
151
        break;
151
        break;
152
    case IMAGING_TYPE_FLOAT32:
152
    case IMAGING_TYPE_FLOAT32:
153
        fmin = fmax = ((FLOAT32*) im->image32[0])[0];
153
        fmin = fmax = ((FLOAT32*) im->image32[0])[0];
Lines 160-182 ImagingGetExtrema(Imaging im, void *extrema) Link Here
160
                    fmax = in[x];
160
                    fmax = in[x];
161
            }
161
            }
162
        }
162
        }
163
        ((FLOAT32*) extrema)[0] = fmin;
163
        memcpy(extrema, &fmin, sizeof(fmin));
164
        ((FLOAT32*) extrema)[1] = fmax;
164
        memcpy(((char*)extrema) + sizeof(fmin), &fmax, sizeof(fmax));
165
        break;
165
        break;
166
    case IMAGING_TYPE_SPECIAL:
166
    case IMAGING_TYPE_SPECIAL:
167
      if (strcmp(im->mode, "I;16") == 0) {
167
      if (strcmp(im->mode, "I;16") == 0) {
168
          imin = imax = ((UINT16*) im->image8[0])[0];
168
          UINT16 v;
169
          memcpy(&v, im->image8, sizeof(v));
170
          imin = imax = v;
169
          for (y = 0; y < im->ysize; y++) {
171
          for (y = 0; y < im->ysize; y++) {
170
              UINT16* in = (UINT16 *) im->image[y];
171
              for (x = 0; x < im->xsize; x++) {
172
              for (x = 0; x < im->xsize; x++) {
172
                  if (imin > in[x])
173
                  memcpy(&v, im->image[y] + x * sizeof(v), sizeof(v));
173
                      imin = in[x];
174
                  if (imin > v)
174
                  else if (imax < in[x])
175
                      imin = v;
175
                      imax = in[x];
176
                  else if (imax < v)
177
                      imax = v;
176
              }
178
              }
177
          }
179
          }
178
          ((UINT16*) extrema)[0] = (UINT16) imin;
180
          v = (UINT16) imin;
179
          ((UINT16*) extrema)[1] = (UINT16) imax;
181
          memcpy(extrema, &v, sizeof(v));
182
          v = (UINT16) imax;
183
          memcpy(((char*)extrema) + sizeof(v), &v, sizeof(v));
180
	  break;
184
	  break;
181
      }
185
      }
182
      /* FALL THROUGH */
186
      /* FALL THROUGH */
(-)a/libImaging/Histo.c (-4 / +4 lines)
Lines 124-131 ImagingGetHistogram(Imaging im, Imaging imMask, void* minmax) Link Here
124
                    return ImagingError_ValueError("min/max not given");
124
                    return ImagingError_ValueError("min/max not given");
125
                if (!im->xsize || !im->ysize)
125
                if (!im->xsize || !im->ysize)
126
                    break;
126
                    break;
127
                imin = ((INT32*) minmax)[0];
127
                memcpy(&imin, minmax, sizeof(imin));
128
                imax = ((INT32*) minmax)[1];
128
                memcpy(&imax, ((char*)minmax) + sizeof(imin), sizeof(imax));
129
                if (imin >= imax)
129
                if (imin >= imax)
130
                    break;
130
                    break;
131
                ImagingSectionEnter(&cookie);
131
                ImagingSectionEnter(&cookie);
Lines 145-152 ImagingGetHistogram(Imaging im, Imaging imMask, void* minmax) Link Here
145
                    return ImagingError_ValueError("min/max not given");
145
                    return ImagingError_ValueError("min/max not given");
146
                if (!im->xsize || !im->ysize)
146
                if (!im->xsize || !im->ysize)
147
                    break;
147
                    break;
148
                fmin = ((FLOAT32*) minmax)[0];
148
                memcpy(&fmin, minmax, sizeof(fmin));
149
                fmax = ((FLOAT32*) minmax)[1];
149
                memcpy(&fmax, ((char*)minmax) + sizeof(fmin), sizeof(fmax));
150
                if (fmin >= fmax)
150
                if (fmin >= fmax)
151
                    break;
151
                    break;
152
                ImagingSectionEnter(&cookie);
152
                ImagingSectionEnter(&cookie);
(-)a/libImaging/Pack.c (-6 / +7 lines)
Lines 252-258 ImagingPackRGB(UINT8* out, const UINT8* in, int pixels) Link Here
252
    int i = 0;
252
    int i = 0;
253
    /* RGB triplets */
253
    /* RGB triplets */
254
    for (; i < pixels-1; i++) {
254
    for (; i < pixels-1; i++) {
255
        ((UINT32*)out)[0] = ((UINT32*)in)[i];
255
        memcpy(out, in + i * 4, 4);
256
        out += 3;
256
        out += 3;
257
    }
257
    }
258
    for (; i < pixels; i++) {
258
    for (; i < pixels; i++) {
Lines 392-409 static void Link Here
392
packI16B(UINT8* out, const UINT8* in_, int pixels)
392
packI16B(UINT8* out, const UINT8* in_, int pixels)
393
{
393
{
394
    int i;
394
    int i;
395
    INT32* in = (INT32*) in_;
396
    UINT16 tmp_;
395
    UINT16 tmp_;
397
    UINT8* tmp = (UINT8*) &tmp_;
396
    UINT8* tmp = (UINT8*) &tmp_;
398
    for (i = 0; i < pixels; i++) {
397
    for (i = 0; i < pixels; i++) {
399
        if (in[0] <= 0)
398
        INT32 in;
399
        memcpy(&in, in_, sizeof(in));
400
        if (in <= 0)
400
            tmp_ = 0;
401
            tmp_ = 0;
401
        else if (in[0] > 65535)
402
        else if (in > 65535)
402
            tmp_ = 65535;
403
            tmp_ = 65535;
403
        else
404
        else
404
            tmp_ = in[0];
405
            tmp_ = in;
405
        C16B;
406
        C16B;
406
        out += 2; in++;
407
        out += 2; in_ += sizeof(in);
407
    }
408
    }
408
}
409
}
409
410
(-)a/libImaging/Point.c (-6 / +10 lines)
Lines 99-110 im_point_8_32(Imaging imOut, Imaging imIn, im_point_context* context) Link Here
99
{
99
{
100
    int x, y;
100
    int x, y;
101
    /* 8-bit source, 32-bit destination */
101
    /* 8-bit source, 32-bit destination */
102
    INT32* table = (INT32*) context->table;
102
    char* table = (char*) context->table;
103
    for (y = 0; y < imIn->ysize; y++) {
103
    for (y = 0; y < imIn->ysize; y++) {
104
        UINT8* in = imIn->image8[y];
104
        UINT8* in = imIn->image8[y];
105
        INT32* out = imOut->image32[y];
105
        INT32* out = imOut->image32[y];
106
        for (x = 0; x < imIn->xsize; x++)
106
        for (x = 0; x < imIn->xsize; x++)
107
            out[x] = table[in[x]];
107
            memcpy(out + x, table + in[x] * sizeof(INT32), sizeof(INT32));
108
    }
108
    }
109
}
109
}
110
110
Lines 242-252 ImagingPointTransform(Imaging imIn, double scale, double offset) Link Here
242
        if (strcmp(imIn->mode,"I;16") == 0) {
242
        if (strcmp(imIn->mode,"I;16") == 0) {
243
            ImagingSectionEnter(&cookie);
243
            ImagingSectionEnter(&cookie);
244
            for (y = 0; y < imIn->ysize; y++) {
244
            for (y = 0; y < imIn->ysize; y++) {
245
                UINT16* in  = (UINT16 *)imIn->image[y];
245
                char* in  = (char*)imIn->image[y];
246
                UINT16* out = (UINT16 *)imOut->image[y];
246
                char* out = (char*)imOut->image[y];
247
                /* FIXME: add clipping? */
247
                /* FIXME: add clipping? */
248
                for (x = 0; x < imIn->xsize; x++)
248
                for (x = 0; x < imIn->xsize; x++) {
249
                    out[x] = in[x] * scale + offset;
249
                    UINT16 v;
250
                    memcpy(&v, in + x * sizeof(v), sizeof(v));
251
                    v = v * scale + offset;
252
                    memcpy(out + x * sizeof(UINT16), &v, sizeof(v));
253
                }
250
            }
254
            }
251
            ImagingSectionLeave(&cookie);
255
            ImagingSectionLeave(&cookie);
252
            break;
256
            break;
(-)a/libImaging/Resample.c (-12 / +18 lines)
Lines 256-261 ImagingResampleHorizontal_8bpc(Imaging imOut, Imaging imIn, int offset, Link Here
256
        if (imIn->bands == 2) {
256
        if (imIn->bands == 2) {
257
            for (yy = 0; yy < imOut->ysize; yy++) {
257
            for (yy = 0; yy < imOut->ysize; yy++) {
258
                for (xx = 0; xx < imOut->xsize; xx++) {
258
                for (xx = 0; xx < imOut->xsize; xx++) {
259
                    UINT32 v;
259
                    xmin = bounds[xx * 2 + 0];
260
                    xmin = bounds[xx * 2 + 0];
260
                    xmax = bounds[xx * 2 + 1];
261
                    xmax = bounds[xx * 2 + 1];
261
                    k = &kk[xx * ksize];
262
                    k = &kk[xx * ksize];
Lines 264-276 ImagingResampleHorizontal_8bpc(Imaging imOut, Imaging imIn, int offset, Link Here
264
                        ss0 += ((UINT8) imIn->image[yy + offset][(x + xmin)*4 + 0]) * k[x];
265
                        ss0 += ((UINT8) imIn->image[yy + offset][(x + xmin)*4 + 0]) * k[x];
265
                        ss3 += ((UINT8) imIn->image[yy + offset][(x + xmin)*4 + 3]) * k[x];
266
                        ss3 += ((UINT8) imIn->image[yy + offset][(x + xmin)*4 + 3]) * k[x];
266
                    }
267
                    }
267
                    ((UINT32 *) imOut->image[yy])[xx] = MAKE_UINT32(
268
                    v = MAKE_UINT32(clip8(ss0), 0, 0, clip8(ss3));
268
                        clip8(ss0), 0, 0, clip8(ss3));
269
                    memcpy(imOut->image[yy] + xx * sizeof(v), &v, sizeof(v));
269
                }
270
                }
270
            }
271
            }
271
        } else if (imIn->bands == 3) {
272
        } else if (imIn->bands == 3) {
272
            for (yy = 0; yy < imOut->ysize; yy++) {
273
            for (yy = 0; yy < imOut->ysize; yy++) {
273
                for (xx = 0; xx < imOut->xsize; xx++) {
274
                for (xx = 0; xx < imOut->xsize; xx++) {
275
                    UINT32 v;
274
                    xmin = bounds[xx * 2 + 0];
276
                    xmin = bounds[xx * 2 + 0];
275
                    xmax = bounds[xx * 2 + 1];
277
                    xmax = bounds[xx * 2 + 1];
276
                    k = &kk[xx * ksize];
278
                    k = &kk[xx * ksize];
Lines 280-292 ImagingResampleHorizontal_8bpc(Imaging imOut, Imaging imIn, int offset, Link Here
280
                        ss1 += ((UINT8) imIn->image[yy + offset][(x + xmin)*4 + 1]) * k[x];
282
                        ss1 += ((UINT8) imIn->image[yy + offset][(x + xmin)*4 + 1]) * k[x];
281
                        ss2 += ((UINT8) imIn->image[yy + offset][(x + xmin)*4 + 2]) * k[x];
283
                        ss2 += ((UINT8) imIn->image[yy + offset][(x + xmin)*4 + 2]) * k[x];
282
                    }
284
                    }
283
                    ((UINT32 *) imOut->image[yy])[xx] = MAKE_UINT32(
285
                    v = MAKE_UINT32(clip8(ss0), clip8(ss1), clip8(ss2), 0);
284
                        clip8(ss0), clip8(ss1), clip8(ss2), 0);
286
                    memcpy(imOut->image[yy] + xx * sizeof(v), &v, sizeof(v));
285
                }
287
                }
286
            }
288
            }
287
        } else {
289
        } else {
288
            for (yy = 0; yy < imOut->ysize; yy++) {
290
            for (yy = 0; yy < imOut->ysize; yy++) {
289
                for (xx = 0; xx < imOut->xsize; xx++) {
291
                for (xx = 0; xx < imOut->xsize; xx++) {
292
                    UINT32 v;
290
                    xmin = bounds[xx * 2 + 0];
293
                    xmin = bounds[xx * 2 + 0];
291
                    xmax = bounds[xx * 2 + 1];
294
                    xmax = bounds[xx * 2 + 1];
292
                    k = &kk[xx * ksize];
295
                    k = &kk[xx * ksize];
Lines 297-304 ImagingResampleHorizontal_8bpc(Imaging imOut, Imaging imIn, int offset, Link Here
297
                        ss2 += ((UINT8) imIn->image[yy + offset][(x + xmin)*4 + 2]) * k[x];
300
                        ss2 += ((UINT8) imIn->image[yy + offset][(x + xmin)*4 + 2]) * k[x];
298
                        ss3 += ((UINT8) imIn->image[yy + offset][(x + xmin)*4 + 3]) * k[x];
301
                        ss3 += ((UINT8) imIn->image[yy + offset][(x + xmin)*4 + 3]) * k[x];
299
                    }
302
                    }
300
                    ((UINT32 *) imOut->image[yy])[xx] = MAKE_UINT32(
303
                    v = MAKE_UINT32(clip8(ss0), clip8(ss1), clip8(ss2), clip8(ss3));
301
                        clip8(ss0), clip8(ss1), clip8(ss2), clip8(ss3));
304
                    memcpy(imOut->image[yy] + xx * sizeof(v), &v, sizeof(v));
302
                }
305
                }
303
            }
306
            }
304
        }
307
        }
Lines 340-352 ImagingResampleVertical_8bpc(Imaging imOut, Imaging imIn, int offset, Link Here
340
                ymin = bounds[yy * 2 + 0];
343
                ymin = bounds[yy * 2 + 0];
341
                ymax = bounds[yy * 2 + 1];
344
                ymax = bounds[yy * 2 + 1];
342
                for (xx = 0; xx < imOut->xsize; xx++) {
345
                for (xx = 0; xx < imOut->xsize; xx++) {
346
                    UINT32 v;
343
                    ss0 = ss3 = 1 << (PRECISION_BITS -1);
347
                    ss0 = ss3 = 1 << (PRECISION_BITS -1);
344
                    for (y = 0; y < ymax; y++) {
348
                    for (y = 0; y < ymax; y++) {
345
                        ss0 += ((UINT8) imIn->image[y + ymin][xx*4 + 0]) * k[y];
349
                        ss0 += ((UINT8) imIn->image[y + ymin][xx*4 + 0]) * k[y];
346
                        ss3 += ((UINT8) imIn->image[y + ymin][xx*4 + 3]) * k[y];
350
                        ss3 += ((UINT8) imIn->image[y + ymin][xx*4 + 3]) * k[y];
347
                    }
351
                    }
348
                    ((UINT32 *) imOut->image[yy])[xx] = MAKE_UINT32(
352
                    v = MAKE_UINT32(clip8(ss0), 0, 0, clip8(ss3));
349
                        clip8(ss0), 0, 0, clip8(ss3));
353
                    memcpy(imOut->image[yy] + xx * sizeof(v), &v, sizeof(v));
350
                }
354
                }
351
            }
355
            }
352
        } else if (imIn->bands == 3) {
356
        } else if (imIn->bands == 3) {
Lines 355-368 ImagingResampleVertical_8bpc(Imaging imOut, Imaging imIn, int offset, Link Here
355
                ymin = bounds[yy * 2 + 0];
359
                ymin = bounds[yy * 2 + 0];
356
                ymax = bounds[yy * 2 + 1];
360
                ymax = bounds[yy * 2 + 1];
357
                for (xx = 0; xx < imOut->xsize; xx++) {
361
                for (xx = 0; xx < imOut->xsize; xx++) {
362
                    UINT32 v;
358
                    ss0 = ss1 = ss2 = 1 << (PRECISION_BITS -1);
363
                    ss0 = ss1 = ss2 = 1 << (PRECISION_BITS -1);
359
                    for (y = 0; y < ymax; y++) {
364
                    for (y = 0; y < ymax; y++) {
360
                        ss0 += ((UINT8) imIn->image[y + ymin][xx*4 + 0]) * k[y];
365
                        ss0 += ((UINT8) imIn->image[y + ymin][xx*4 + 0]) * k[y];
361
                        ss1 += ((UINT8) imIn->image[y + ymin][xx*4 + 1]) * k[y];
366
                        ss1 += ((UINT8) imIn->image[y + ymin][xx*4 + 1]) * k[y];
362
                        ss2 += ((UINT8) imIn->image[y + ymin][xx*4 + 2]) * k[y];
367
                        ss2 += ((UINT8) imIn->image[y + ymin][xx*4 + 2]) * k[y];
363
                    }
368
                    }
364
                    ((UINT32 *) imOut->image[yy])[xx] = MAKE_UINT32(
369
                    v = MAKE_UINT32(clip8(ss0), clip8(ss1), clip8(ss2), 0);
365
                        clip8(ss0), clip8(ss1), clip8(ss2), 0);
370
                    memcpy(imOut->image[yy] + xx * sizeof(v), &v, sizeof(v));
366
                }
371
                }
367
            }
372
            }
368
        } else {
373
        } else {
Lines 371-376 ImagingResampleVertical_8bpc(Imaging imOut, Imaging imIn, int offset, Link Here
371
                ymin = bounds[yy * 2 + 0];
376
                ymin = bounds[yy * 2 + 0];
372
                ymax = bounds[yy * 2 + 1];
377
                ymax = bounds[yy * 2 + 1];
373
                for (xx = 0; xx < imOut->xsize; xx++) {
378
                for (xx = 0; xx < imOut->xsize; xx++) {
379
                    UINT32 v;
374
                    ss0 = ss1 = ss2 = ss3 = 1 << (PRECISION_BITS -1);
380
                    ss0 = ss1 = ss2 = ss3 = 1 << (PRECISION_BITS -1);
375
                    for (y = 0; y < ymax; y++) {
381
                    for (y = 0; y < ymax; y++) {
376
                        ss0 += ((UINT8) imIn->image[y + ymin][xx*4 + 0]) * k[y];
382
                        ss0 += ((UINT8) imIn->image[y + ymin][xx*4 + 0]) * k[y];
Lines 378-385 ImagingResampleVertical_8bpc(Imaging imOut, Imaging imIn, int offset, Link Here
378
                        ss2 += ((UINT8) imIn->image[y + ymin][xx*4 + 2]) * k[y];
384
                        ss2 += ((UINT8) imIn->image[y + ymin][xx*4 + 2]) * k[y];
379
                        ss3 += ((UINT8) imIn->image[y + ymin][xx*4 + 3]) * k[y];
385
                        ss3 += ((UINT8) imIn->image[y + ymin][xx*4 + 3]) * k[y];
380
                    }
386
                    }
381
                    ((UINT32 *) imOut->image[yy])[xx] = MAKE_UINT32(
387
                    v = MAKE_UINT32(clip8(ss0), clip8(ss1), clip8(ss2), clip8(ss3));
382
                        clip8(ss0), clip8(ss1), clip8(ss2), clip8(ss3));
388
                    memcpy(imOut->image[yy] + xx * sizeof(v), &v, sizeof(v));
383
                }
389
                }
384
            }
390
            }
385
        }
391
        }
(-)a/libImaging/SgiRleDecode.c (-19 / +20 lines)
Lines 28-34 static void read4B(UINT32* dest, UINT8* buf) Link Here
28
static int expandrow(UINT8* dest, UINT8* src, int n, int z)
28
static int expandrow(UINT8* dest, UINT8* src, int n, int z)
29
{
29
{
30
    UINT8 pixel, count;
30
    UINT8 pixel, count;
31
    
31
32
    for (;n > 0; n--)
32
    for (;n > 0; n--)
33
    {
33
    {
34
        pixel = *src++;
34
        pixel = *src++;
Lines 42-48 static int expandrow(UINT8* dest, UINT8* src, int n, int z) Link Here
42
                *dest = *src++;
42
                *dest = *src++;
43
                dest += z;
43
                dest += z;
44
            }
44
            }
45
                
45
46
        }
46
        }
47
        else {
47
        else {
48
            pixel = *src++;
48
            pixel = *src++;
Lines 51-70 static int expandrow(UINT8* dest, UINT8* src, int n, int z) Link Here
51
                dest += z;
51
                dest += z;
52
            }
52
            }
53
        }
53
        }
54
        
54
55
    }
55
    }
56
    return 0;
56
    return 0;
57
}
57
}
58
58
59
static int expandrow2(UINT16* dest, UINT16* src, int n, int z)
59
static int expandrow2(UINT8* dest, const UINT8* src, int n, int z)
60
{
60
{
61
    UINT8 pixel, count;
61
    UINT8 pixel, count;
62
62
63
   
63
64
    for (;n > 0; n--)
64
    for (;n > 0; n--)
65
    {
65
    {
66
        pixel = ((UINT8*)src)[1];
66
        pixel = src[1];
67
        ++src;
67
        src+=2;
68
        if (n == 1 && pixel != 0)
68
        if (n == 1 && pixel != 0)
69
            return n;
69
            return n;
70
        count = pixel & RLE_MAX_RUN;
70
        count = pixel & RLE_MAX_RUN;
Lines 72-87 static int expandrow2(UINT16* dest, UINT16* src, int n, int z) Link Here
72
            return count;
72
            return count;
73
        if (pixel & RLE_COPY_FLAG) {
73
        if (pixel & RLE_COPY_FLAG) {
74
            while(count--) {
74
            while(count--) {
75
                *dest = *src++;
75
                memcpy(dest, src, 2);
76
                dest += z;
76
                src += 2;
77
                dest += z * 2;
77
            }
78
            }
78
        }
79
        }
79
        else {
80
        else {
80
            while (count--) {
81
            while (count--) {
81
                *dest = *src;
82
                memcpy(dest, src, 2);
82
                dest += z;
83
                dest += z * 2;
83
            }
84
            }
84
            ++src;
85
            src+=2;
85
        }
86
        }
86
    }
87
    }
87
    return 0;
88
    return 0;
Lines 96-102 ImagingSgiRleDecode(Imaging im, ImagingCodecState state, Link Here
96
    SGISTATE *c;
97
    SGISTATE *c;
97
    int err = 0;
98
    int err = 0;
98
99
99
    /* Get all data from File descriptor */    
100
    /* Get all data from File descriptor */
100
    c = (SGISTATE*)state->context;
101
    c = (SGISTATE*)state->context;
101
    _imaging_seek_pyFd(state->fd, 0L, SEEK_END);
102
    _imaging_seek_pyFd(state->fd, 0L, SEEK_END);
102
    c->bufsize = _imaging_tell_pyFd(state->fd);
103
    c->bufsize = _imaging_tell_pyFd(state->fd);
Lines 155-183 ImagingSgiRleDecode(Imaging im, ImagingCodecState state, Link Here
155
            c->rleoffset = c->starttab[c->rowno + c->channo * im->ysize];
156
            c->rleoffset = c->starttab[c->rowno + c->channo * im->ysize];
156
            c->rlelength = c->lengthtab[c->rowno + c->channo * im->ysize];
157
            c->rlelength = c->lengthtab[c->rowno + c->channo * im->ysize];
157
            c->rleoffset -= SGI_HEADER_SIZE;
158
            c->rleoffset -= SGI_HEADER_SIZE;
158
            
159
159
            /* row decompression */
160
            /* row decompression */
160
            if (c->bpc ==1) {
161
            if (c->bpc ==1) {
161
                if(expandrow(&state->buffer[c->channo], &ptr[c->rleoffset], c->rlelength, im->bands))
162
                if(expandrow(&state->buffer[c->channo], &ptr[c->rleoffset], c->rlelength, im->bands))
162
                    goto sgi_finish_decode;
163
                    goto sgi_finish_decode;
163
            }
164
            }
164
            else {
165
            else {
165
                if(expandrow2((UINT16*)&state->buffer[c->channo * 2], (UINT16*)&ptr[c->rleoffset], c->rlelength, im->bands))
166
                if(expandrow2(&state->buffer[c->channo * 2], &ptr[c->rleoffset], c->rlelength, im->bands))
166
                    goto sgi_finish_decode;
167
                    goto sgi_finish_decode;
167
            }
168
            }
168
            
169
169
            state->count += c->rlelength;
170
            state->count += c->rlelength;
170
        }
171
        }
171
        
172
172
        /* store decompressed data in image */
173
        /* store decompressed data in image */
173
        state->shuffle((UINT8*)im->image[state->y], state->buffer, im->xsize);
174
        state->shuffle((UINT8*)im->image[state->y], state->buffer, im->xsize);
174
        
175
175
    }
176
    }
176
177
177
    c->bufsize++;
178
    c->bufsize++;
178
179
179
sgi_finish_decode: ;
180
sgi_finish_decode: ;
180
    
181
181
    free(c->starttab);
182
    free(c->starttab);
182
    free(c->lengthtab);
183
    free(c->lengthtab);
183
    free(ptr);
184
    free(ptr);
(-)a/libImaging/Unpack.c (-75 / +79 lines)
Lines 32-38 Link Here
32
32
33
#include "Imaging.h"
33
#include "Imaging.h"
34
34
35
36
#define R 0
35
#define R 0
37
#define G 1
36
#define G 1
38
#define B 2
37
#define B 2
Lines 188-194 unpack1IR(UINT8* out, const UINT8* in, int pixels) Link Here
188
static void
187
static void
189
unpack18(UINT8* out, const UINT8* in, int pixels)
188
unpack18(UINT8* out, const UINT8* in, int pixels)
190
{
189
{
191
    /* Unpack a '|b1' image, which is a numpy boolean. 
190
    /* Unpack a '|b1' image, which is a numpy boolean.
192
       1 == true, 0==false, in bytes */
191
       1 == true, 0==false, in bytes */
193
192
194
    int i;
193
    int i;
Lines 329-338 static void Link Here
329
unpackLA(UINT8* _out, const UINT8* in, int pixels)
328
unpackLA(UINT8* _out, const UINT8* in, int pixels)
330
{
329
{
331
    int i;
330
    int i;
332
    UINT32* out = (UINT32*) _out;
333
    /* LA, pixel interleaved */
331
    /* LA, pixel interleaved */
334
    for (i = 0; i < pixels; i++) {
332
    for (i = 0; i < pixels; i++) {
335
        out[i] = MAKE_UINT32(in[0], in[0], in[0], in[1]);
333
        UINT32 iv = MAKE_UINT32(in[0], in[0], in[0], in[1]);
334
        memcpy(_out + i + sizeof(iv), &iv, sizeof(iv));
336
        in += 2;
335
        in += 2;
337
    }
336
    }
338
}
337
}
Lines 341-350 static void Link Here
341
unpackLAL(UINT8* _out, const UINT8* in, int pixels)
340
unpackLAL(UINT8* _out, const UINT8* in, int pixels)
342
{
341
{
343
    int i;
342
    int i;
344
    UINT32* out = (UINT32*) _out;
345
    /* LA, line interleaved */
343
    /* LA, line interleaved */
346
    for (i = 0; i < pixels; i++) {
344
    for (i = 0; i < pixels; i++) {
347
        out[i] = MAKE_UINT32(in[i], in[i], in[i], in[i+pixels]);
345
        UINT32 iv = MAKE_UINT32(in[i], in[i], in[i], in[i+pixels]);
346
        memcpy(_out + i + sizeof(iv), &iv, sizeof(iv));
348
    }
347
    }
349
}
348
}
350
349
Lines 482-495 void Link Here
482
ImagingUnpackRGB(UINT8* _out, const UINT8* in, int pixels)
481
ImagingUnpackRGB(UINT8* _out, const UINT8* in, int pixels)
483
{
482
{
484
    int i = 0;
483
    int i = 0;
485
    UINT32* out = (UINT32*) _out;
486
    /* RGB triplets */
484
    /* RGB triplets */
487
    for (; i < pixels-1; i++) {
485
    for (; i < pixels-1; i++) {
488
        out[i] = MASK_UINT32_CHANNEL_3 | *(UINT32*)&in[0];
486
        UINT32 iv;
487
        memcpy(&iv, in, sizeof(iv));
488
        iv |= MASK_UINT32_CHANNEL_3;
489
        memcpy(_out + i * sizeof(iv), &iv, sizeof(iv));
489
        in += 3;
490
        in += 3;
490
    }
491
    }
491
    for (; i < pixels; i++) {
492
    for (; i < pixels; i++) {
492
        out[i] = MAKE_UINT32(in[0], in[1], in[2], 255);
493
        UINT32 iv = MAKE_UINT32(in[0], in[1], in[2], 255);
494
        memcpy(_out + i * sizeof(iv), &iv, sizeof(iv));
493
        in += 3;
495
        in += 3;
494
    }
496
    }
495
}
497
}
Lines 498-507 void Link Here
498
unpackRGB16L(UINT8* _out, const UINT8* in, int pixels)
500
unpackRGB16L(UINT8* _out, const UINT8* in, int pixels)
499
{
501
{
500
    int i;
502
    int i;
501
    UINT32* out = (UINT32*) _out;
502
    /* 16-bit RGB triplets, little-endian order */
503
    /* 16-bit RGB triplets, little-endian order */
503
    for (i = 0; i < pixels; i++) {
504
    for (i = 0; i < pixels; i++) {
504
        out[i] = MAKE_UINT32(in[1], in[3], in[5], 255);
505
        UINT32 iv = MAKE_UINT32(in[1], in[3], in[5], 255);
506
        memcpy(_out + i * sizeof(iv), &iv, sizeof(iv));
505
        in += 6;
507
        in += 6;
506
    }
508
    }
507
}
509
}
Lines 510-519 void Link Here
510
unpackRGB16B(UINT8* _out, const UINT8* in, int pixels)
512
unpackRGB16B(UINT8* _out, const UINT8* in, int pixels)
511
{
513
{
512
    int i;
514
    int i;
513
    UINT32* out = (UINT32*) _out;
514
    /* 16-bit RGB triplets, big-endian order */
515
    /* 16-bit RGB triplets, big-endian order */
515
    for (i = 0; i < pixels; i++) {
516
    for (i = 0; i < pixels; i++) {
516
        out[i] = MAKE_UINT32(in[0], in[2], in[4], 255);
517
        UINT32 iv = MAKE_UINT32(in[0], in[2], in[4], 255);
518
        memcpy(_out + i * sizeof(iv), &iv, sizeof(iv));
517
        in += 6;
519
        in += 6;
518
    }
520
    }
519
}
521
}
Lines 522-531 static void Link Here
522
unpackRGBL(UINT8* _out, const UINT8* in, int pixels)
524
unpackRGBL(UINT8* _out, const UINT8* in, int pixels)
523
{
525
{
524
    int i;
526
    int i;
525
    UINT32* out = (UINT32*) _out;
526
    /* RGB, line interleaved */
527
    /* RGB, line interleaved */
527
    for (i = 0; i < pixels; i++) {
528
    for (i = 0; i < pixels; i++) {
528
        out[i] = MAKE_UINT32(in[i], in[i+pixels], in[i+pixels+pixels], 255);
529
        UINT32 iv = MAKE_UINT32(in[i], in[i+pixels], in[i+pixels+pixels], 255);
530
        memcpy(_out + i * sizeof(iv), &iv, sizeof(iv));
529
    }
531
    }
530
}
532
}
531
533
Lines 533-543 static void Link Here
533
unpackRGBR(UINT8* _out, const UINT8* in, int pixels)
535
unpackRGBR(UINT8* _out, const UINT8* in, int pixels)
534
{
536
{
535
    int i;
537
    int i;
536
    UINT32* out = (UINT32*) _out;
537
    /* RGB, bit reversed */
538
    /* RGB, bit reversed */
538
    for (i = 0; i < pixels; i++) {
539
    for (i = 0; i < pixels; i++) {
539
        out[i] = MAKE_UINT32(BITFLIP[in[0]], BITFLIP[in[1]],
540
        UINT32 iv = MAKE_UINT32(BITFLIP[in[0]], BITFLIP[in[1]],
540
                             BITFLIP[in[2]], 255);
541
                                BITFLIP[in[2]], 255);
542
        memcpy(_out + i * sizeof(iv), &iv, sizeof(iv));
541
        in += 3;
543
        in += 3;
542
    }
544
    }
543
}
545
}
Lines 546-555 void Link Here
546
ImagingUnpackBGR(UINT8* _out, const UINT8* in, int pixels)
548
ImagingUnpackBGR(UINT8* _out, const UINT8* in, int pixels)
547
{
549
{
548
    int i;
550
    int i;
549
    UINT32* out = (UINT32*) _out;
550
    /* RGB, reversed bytes */
551
    /* RGB, reversed bytes */
551
    for (i = 0; i < pixels; i++) {
552
    for (i = 0; i < pixels; i++) {
552
        out[i] = MAKE_UINT32(in[2], in[1], in[0], 255);
553
        UINT32 iv = MAKE_UINT32(in[2], in[1], in[0], 255);
554
        memcpy(_out + i * sizeof(iv), &iv, sizeof(iv));
553
        in += 3;
555
        in += 3;
554
    }
556
    }
555
}
557
}
Lines 678-687 static void Link Here
678
ImagingUnpackBGRX(UINT8* _out, const UINT8* in, int pixels)
680
ImagingUnpackBGRX(UINT8* _out, const UINT8* in, int pixels)
679
{
681
{
680
    int i;
682
    int i;
681
    UINT32* out = (UINT32*) _out;
682
    /* RGB, reversed bytes with padding */
683
    /* RGB, reversed bytes with padding */
683
    for (i = 0; i < pixels; i++) {
684
    for (i = 0; i < pixels; i++) {
684
        out[i] = MAKE_UINT32(in[2], in[1], in[0], 255);
685
        UINT32 iv = MAKE_UINT32(in[2], in[1], in[0], 255);
686
        memcpy(_out + i * sizeof(iv), &iv, sizeof(iv));
685
        in += 4;
687
        in += 4;
686
    }
688
    }
687
}
689
}
Lines 690-699 static void Link Here
690
ImagingUnpackXRGB(UINT8* _out, const UINT8* in, int pixels)
692
ImagingUnpackXRGB(UINT8* _out, const UINT8* in, int pixels)
691
{
693
{
692
    int i;
694
    int i;
693
    UINT32* out = (UINT32*) _out;
694
    /* RGB, leading pad */
695
    /* RGB, leading pad */
695
    for (i = 0; i < pixels; i++) {
696
    for (i = 0; i < pixels; i++) {
696
        out[i] = MAKE_UINT32(in[1], in[2], in[3], 255);
697
        UINT32 iv = MAKE_UINT32(in[1], in[2], in[3], 255);
698
        memcpy(_out + i * sizeof(iv), &iv, sizeof(iv));
697
        in += 4;
699
        in += 4;
698
    }
700
    }
699
}
701
}
Lines 702-711 static void Link Here
702
ImagingUnpackXBGR(UINT8* _out, const UINT8* in, int pixels)
704
ImagingUnpackXBGR(UINT8* _out, const UINT8* in, int pixels)
703
{
705
{
704
    int i;
706
    int i;
705
    UINT32* out = (UINT32*) _out;
706
    /* RGB, reversed bytes, leading pad */
707
    /* RGB, reversed bytes, leading pad */
707
    for (i = 0; i < pixels; i++) {
708
    for (i = 0; i < pixels; i++) {
708
        out[i] = MAKE_UINT32(in[3], in[2], in[1], 255);
709
        UINT32 iv = MAKE_UINT32(in[3], in[2], in[1], 255);
710
        memcpy(_out + i * sizeof(iv), &iv, sizeof(iv));
709
        in += 4;
711
        in += 4;
710
    }
712
    }
711
}
713
}
Lines 716-725 static void Link Here
716
unpackRGBALA(UINT8* _out, const UINT8* in, int pixels)
718
unpackRGBALA(UINT8* _out, const UINT8* in, int pixels)
717
{
719
{
718
    int i;
720
    int i;
719
    UINT32* out = (UINT32*) _out;
720
    /* greyscale with alpha */
721
    /* greyscale with alpha */
721
    for (i = 0; i < pixels; i++) {
722
    for (i = 0; i < pixels; i++) {
722
        out[i] = MAKE_UINT32(in[0], in[0], in[0], in[1]);
723
        UINT32 iv = MAKE_UINT32(in[0], in[0], in[0], 255);
724
        memcpy(_out + i * sizeof(iv), &iv, sizeof(iv));
723
        in += 2;
725
        in += 2;
724
    }
726
    }
725
}
727
}
Lines 728-737 static void Link Here
728
unpackRGBALA16B(UINT8* _out, const UINT8* in, int pixels)
730
unpackRGBALA16B(UINT8* _out, const UINT8* in, int pixels)
729
{
731
{
730
    int i;
732
    int i;
731
    UINT32* out = (UINT32*) _out;
732
    /* 16-bit greyscale with alpha, big-endian */
733
    /* 16-bit greyscale with alpha, big-endian */
733
    for (i = 0; i < pixels; i++) {
734
    for (i = 0; i < pixels; i++) {
734
        out[i] = MAKE_UINT32(in[0], in[0], in[0], in[2]);
735
        UINT32 iv = MAKE_UINT32(in[0], in[0], in[0], in[2]);
736
        memcpy(_out + i * sizeof(iv), &iv, sizeof(iv));
735
        in += 4;
737
        in += 4;
736
    }
738
    }
737
}
739
}
Lines 740-758 static void Link Here
740
unpackRGBa16L(UINT8* _out, const UINT8* in, int pixels)
742
unpackRGBa16L(UINT8* _out, const UINT8* in, int pixels)
741
{
743
{
742
    int i;
744
    int i;
743
    UINT32* out = (UINT32*) _out;
744
    /* premultiplied 16-bit RGBA, little-endian */
745
    /* premultiplied 16-bit RGBA, little-endian */
745
    for (i = 0; i < pixels; i++) {
746
    for (i = 0; i < pixels; i++) {
746
        int a = in[7];
747
        int a = in[7];
748
        UINT32 iv;
747
        if ( ! a) {
749
        if ( ! a) {
748
            out[i] = 0;
750
            iv = 0;
749
        } else if (a == 255) {
751
        } else if (a == 255) {
750
            out[i] = MAKE_UINT32(in[1], in[3], in[5], a);
752
            iv = MAKE_UINT32(in[1], in[3], in[5], a);
751
        } else {
753
        } else {
752
            out[i] = MAKE_UINT32(CLIP(in[1] * 255 / a),
754
            iv = MAKE_UINT32(CLIP(in[1] * 255 / a),
753
                                 CLIP(in[3] * 255 / a),
755
                             CLIP(in[3] * 255 / a),
754
                                 CLIP(in[5] * 255 / a), a);
756
                             CLIP(in[5] * 255 / a), a);
755
        }
757
        }
758
        memcpy(_out + i * sizeof(iv), &iv, sizeof(iv));
756
        in += 8;
759
        in += 8;
757
    }
760
    }
758
}
761
}
Lines 761-779 static void Link Here
761
unpackRGBa16B(UINT8* _out, const UINT8* in, int pixels)
764
unpackRGBa16B(UINT8* _out, const UINT8* in, int pixels)
762
{
765
{
763
    int i;
766
    int i;
764
    UINT32* out = (UINT32*) _out;
765
    /* premultiplied 16-bit RGBA, big-endian */
767
    /* premultiplied 16-bit RGBA, big-endian */
766
    for (i = 0; i < pixels; i++) {
768
    for (i = 0; i < pixels; i++) {
767
        int a = in[6];
769
        int a = in[6];
770
        UINT32 iv;
768
        if ( ! a) {
771
        if ( ! a) {
769
            out[i] = 0;
772
            iv = 0;
770
        } else if (a == 255) {
773
        } else if (a == 255) {
771
            out[i] = MAKE_UINT32(in[0], in[2], in[4], a);
774
            iv = MAKE_UINT32(in[0], in[2], in[4], a);
772
        } else {
775
        } else {
773
            out[i] = MAKE_UINT32(CLIP(in[0] * 255 / a),
776
            iv = MAKE_UINT32(CLIP(in[0] * 255 / a),
774
                                 CLIP(in[2] * 255 / a),
777
                             CLIP(in[2] * 255 / a),
775
                                 CLIP(in[4] * 255 / a), a);
778
                             CLIP(in[4] * 255 / a), a);
776
        }
779
        }
780
        memcpy(_out + i * sizeof(iv), &iv, sizeof(iv));
777
        in += 8;
781
        in += 8;
778
    }
782
    }
779
}
783
}
Lines 782-800 static void Link Here
782
unpackRGBa(UINT8* _out, const UINT8* in, int pixels)
786
unpackRGBa(UINT8* _out, const UINT8* in, int pixels)
783
{
787
{
784
    int i;
788
    int i;
785
    UINT32* out = (UINT32*) _out;
786
    /* premultiplied RGBA */
789
    /* premultiplied RGBA */
787
    for (i = 0; i < pixels; i++) {
790
    for (i = 0; i < pixels; i++) {
788
        int a = in[3];
791
        int a = in[3];
792
        UINT32 iv;
789
        if ( ! a) {
793
        if ( ! a) {
790
            out[i] = 0;
794
            iv = 0;
791
        } else if (a == 255) {
795
        } else if (a == 255) {
792
            out[i] = MAKE_UINT32(in[0], in[1], in[2], a);
796
            iv = MAKE_UINT32(in[0], in[1], in[2], a);
793
        } else {
797
        } else {
794
            out[i] = MAKE_UINT32(CLIP(in[0] * 255 / a),
798
            iv = MAKE_UINT32(CLIP(in[0] * 255 / a),
795
                                 CLIP(in[1] * 255 / a),
799
                             CLIP(in[1] * 255 / a),
796
                                 CLIP(in[2] * 255 / a), a);
800
                             CLIP(in[2] * 255 / a), a);
797
        }
801
        }
802
        memcpy(_out + i * sizeof(iv), &iv, sizeof(iv));
798
        in += 4;
803
        in += 4;
799
    }
804
    }
800
}
805
}
Lines 803-821 static void Link Here
803
unpackBGRa(UINT8* _out, const UINT8* in, int pixels)
808
unpackBGRa(UINT8* _out, const UINT8* in, int pixels)
804
{
809
{
805
    int i;
810
    int i;
806
    UINT32* out = (UINT32*) _out;
807
    /* premultiplied BGRA */
811
    /* premultiplied BGRA */
808
    for (i = 0; i < pixels; i++) {
812
    for (i = 0; i < pixels; i++) {
809
        int a = in[3];
813
        int a = in[3];
814
        UINT32 iv;
810
        if ( ! a) {
815
        if ( ! a) {
811
            out[i] = 0;
816
            iv = 0;
812
        } else if (a == 255) {
817
        } else if (a == 255) {
813
            out[i] = MAKE_UINT32(in[2], in[1], in[0], a);
818
            iv = MAKE_UINT32(in[2], in[1], in[0], a);
814
        } else {
819
        } else {
815
            out[i] = MAKE_UINT32(CLIP(in[2] * 255 / a),
820
            iv = MAKE_UINT32(CLIP(in[2] * 255 / a),
816
                                 CLIP(in[1] * 255 / a),
821
                             CLIP(in[1] * 255 / a),
817
                                 CLIP(in[0] * 255 / a), a);
822
                             CLIP(in[0] * 255 / a), a);
818
        }
823
        }
824
        memcpy(_out + i * sizeof(iv), &iv, sizeof(iv));
819
        in += 4;
825
        in += 4;
820
    }
826
    }
821
}
827
}
Lines 838-848 static void Link Here
838
unpackRGBAL(UINT8* _out, const UINT8* in, int pixels)
844
unpackRGBAL(UINT8* _out, const UINT8* in, int pixels)
839
{
845
{
840
    int i;
846
    int i;
841
    UINT32* out = (UINT32*) _out;
842
    /* RGBA, line interleaved */
847
    /* RGBA, line interleaved */
843
    for (i = 0; i < pixels; i++) {
848
    for (i = 0; i < pixels; i++) {
844
        out[i] = MAKE_UINT32(in[i], in[i+pixels], in[i+pixels+pixels],
849
        UINT32 iv = MAKE_UINT32(in[i], in[i+pixels], in[i+pixels+pixels],
845
                             in[i+pixels+pixels+pixels]);
850
                                in[i+pixels+pixels+pixels]);
851
        memcpy(_out + i * sizeof(iv), &iv, sizeof(iv));
846
    }
852
    }
847
}
853
}
848
854
Lines 850-859 void Link Here
850
unpackRGBA16L(UINT8* _out, const UINT8* in, int pixels)
856
unpackRGBA16L(UINT8* _out, const UINT8* in, int pixels)
851
{
857
{
852
    int i;
858
    int i;
853
    UINT32* out = (UINT32*) _out;
854
    /* 16-bit RGBA, little-endian order */
859
    /* 16-bit RGBA, little-endian order */
855
    for (i = 0; i < pixels; i++) {
860
    for (i = 0; i < pixels; i++) {
856
        out[i] = MAKE_UINT32(in[1], in[3], in[5], in[7]);
861
        UINT32 iv = MAKE_UINT32(in[1], in[3], in[5], in[7]);
862
        memcpy(_out + i * sizeof(iv), &iv, sizeof(iv));
857
        in += 8;
863
        in += 8;
858
    }
864
    }
859
}
865
}
Lines 862-871 void Link Here
862
unpackRGBA16B(UINT8* _out, const UINT8* in, int pixels)
868
unpackRGBA16B(UINT8* _out, const UINT8* in, int pixels)
863
{
869
{
864
    int i;
870
    int i;
865
    UINT32* out = (UINT32*) _out;
866
    /* 16-bit RGBA, big-endian order */
871
    /* 16-bit RGBA, big-endian order */
867
    for (i = 0; i < pixels; i++) {
872
    for (i = 0; i < pixels; i++) {
868
        out[i] = MAKE_UINT32(in[0], in[2], in[4], in[6]);
873
        UINT32 iv = MAKE_UINT32(in[0], in[2], in[4], in[6]);
874
        memcpy(_out + i * sizeof(iv), &iv, sizeof(iv));
869
        in += 8;
875
        in += 8;
870
    }
876
    }
871
}
877
}
Lines 874-883 static void Link Here
874
unpackARGB(UINT8* _out, const UINT8* in, int pixels)
880
unpackARGB(UINT8* _out, const UINT8* in, int pixels)
875
{
881
{
876
    int i;
882
    int i;
877
    UINT32* out = (UINT32*) _out;
878
    /* RGBA, leading pad */
883
    /* RGBA, leading pad */
879
    for (i = 0; i < pixels; i++) {
884
    for (i = 0; i < pixels; i++) {
880
        out[i] = MAKE_UINT32(in[1], in[2], in[3], in[0]);
885
        UINT32 iv = MAKE_UINT32(in[1], in[2], in[3], in[0]);
886
        memcpy(_out + i * sizeof(iv), &iv, sizeof(iv));
881
        in += 4;
887
        in += 4;
882
    }
888
    }
883
}
889
}
Lines 886-895 static void Link Here
886
unpackABGR(UINT8* _out, const UINT8* in, int pixels)
892
unpackABGR(UINT8* _out, const UINT8* in, int pixels)
887
{
893
{
888
    int i;
894
    int i;
889
    UINT32* out = (UINT32*) _out;
890
    /* RGBA, reversed bytes */
895
    /* RGBA, reversed bytes */
891
    for (i = 0; i < pixels; i++) {
896
    for (i = 0; i < pixels; i++) {
892
        out[i] = MAKE_UINT32(in[3], in[2], in[1], in[0]);
897
        UINT32 iv = MAKE_UINT32(in[3], in[2], in[1], in[0]);
898
        memcpy(_out + i * sizeof(iv), &iv, sizeof(iv));
893
        in += 4;
899
        in += 4;
894
    }
900
    }
895
}
901
}
Lines 898-907 static void Link Here
898
unpackBGRA(UINT8* _out, const UINT8* in, int pixels)
904
unpackBGRA(UINT8* _out, const UINT8* in, int pixels)
899
{
905
{
900
    int i;
906
    int i;
901
    UINT32* out = (UINT32*) _out;
902
    /* RGBA, reversed bytes */
907
    /* RGBA, reversed bytes */
903
    for (i = 0; i < pixels; i++) {
908
    for (i = 0; i < pixels; i++) {
904
        out[i] = MAKE_UINT32(in[2], in[1], in[0], in[3]);
909
        UINT32 iv = MAKE_UINT32(in[2], in[1], in[0], in[3]);
910
        memcpy(_out + i * sizeof(iv), &iv, sizeof(iv));
905
        in += 4;
911
        in += 4;
906
    }
912
    }
907
}
913
}
Lines 913-922 static void Link Here
913
unpackCMYKI(UINT8* _out, const UINT8* in, int pixels)
919
unpackCMYKI(UINT8* _out, const UINT8* in, int pixels)
914
{
920
{
915
    int i;
921
    int i;
916
    UINT32* out = (UINT32*) _out;
917
    /* CMYK, inverted bytes (Photoshop 2.5) */
922
    /* CMYK, inverted bytes (Photoshop 2.5) */
918
    for (i = 0; i < pixels; i++) {
923
    for (i = 0; i < pixels; i++) {
919
        out[i] = ~MAKE_UINT32(in[0], in[1], in[2], in[3]);
924
        UINT32 iv = ~MAKE_UINT32(in[0], in[1], in[2], in[3]);
925
        memcpy(_out + i * sizeof(iv), &iv, sizeof(iv));
920
        in += 4;
926
        in += 4;
921
    }
927
    }
922
}
928
}
Lines 991-1020 unpackI12_I16(UINT8* out, const UINT8* in, int pixels){ Link Here
991
#ifdef WORDS_BIGENDIAN
997
#ifdef WORDS_BIGENDIAN
992
    UINT8* tmp = (UINT8 *)&pixel;
998
    UINT8* tmp = (UINT8 *)&pixel;
993
#endif
999
#endif
994
    UINT16* out16 = (UINT16 *)out;
995
    for (i = 0; i < pixels-1; i+=2) {
1000
    for (i = 0; i < pixels-1; i+=2) {
996
        pixel = (((UINT16) in[0]) << 4 ) + (in[1] >>4);
1001
        pixel = (((UINT16) in[0]) << 4 ) + (in[1] >>4);
997
#ifdef WORDS_BIGENDIAN
1002
#ifdef WORDS_BIGENDIAN
998
        out[0] = tmp[1];  out[1] = tmp[0];
1003
        out[0] = tmp[1];  out[1] = tmp[0];
999
#else
1004
#else
1000
        out16[0] = pixel;
1005
        memcpy(out, &pixel, sizeof(pixel));
1001
#endif
1006
#endif
1002
1007
1003
        pixel = (((UINT16) (in[1] & 0x0F)) << 8) + in[2];
1008
        pixel = (((UINT16) (in[1] & 0x0F)) << 8) + in[2];
1004
#ifdef WORDS_BIGENDIAN
1009
#ifdef WORDS_BIGENDIAN
1005
        out[2] = tmp[1];  out[3] = tmp[0];
1010
        out[2] = tmp[1];  out[3] = tmp[0];
1006
#else
1011
#else
1007
        out16[1] = pixel;
1012
        memcpy(out + sizeof(pixel), &pixel, sizeof(pixel));
1008
#endif
1013
#endif
1009
1014
1010
		in += 3; out16 += 2; out+=4;
1015
		in += 3; out+=4;
1011
    }
1016
    }
1012
    if (i == pixels-1) {
1017
    if (i == pixels-1) {
1013
        pixel = (((UINT16) in[0]) << 4 ) + (in[1] >>4);
1018
        pixel = (((UINT16) in[0]) << 4 ) + (in[1] >>4);
1014
#ifdef WORDS_BIGENDIAN
1019
#ifdef WORDS_BIGENDIAN
1015
        out[0] = tmp[1];  out[1] = tmp[0];
1020
        out[0] = tmp[1];  out[1] = tmp[0];
1016
#else
1021
#else
1017
        out16[0] = pixel;
1022
        memcpy(out, &pixel, sizeof(pixel));
1018
#endif
1023
#endif
1019
    }
1024
    }
1020
}
1025
}
1021
- 

Return to bug 659460