~ubuntu-branches/ubuntu/maverick/pygame/maverick

« back to all changes in this revision

Viewing changes to src/surface_fill.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2010-01-14 17:02:11 UTC
  • mfrom: (1.3.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100114170211-21eop2ja7mr9vdcr
Tags: 1.9.1release-0ubuntu1
* New upstream version (lp: #433304)
* debian/control:
  - build-depends on libportmidi-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include "surface.h"
21
21
 
22
22
 
 
23
static int
 
24
surface_fill_blend_add (SDL_Surface *surface, SDL_Rect *rect, Uint32 color)
 
25
{
 
26
    Uint8 *pixels;
 
27
    int width = rect->w;
 
28
    int height = rect->h;
 
29
    int skip;
 
30
    int bpp = surface->format->BytesPerPixel;
 
31
    int n;
 
32
    SDL_PixelFormat *fmt = surface->format;
 
33
    Uint8 sR, sG, sB, sA, cR, cG, cB, cA;
 
34
    Uint32 pixel;
 
35
    Uint32 tmp;
 
36
    int result = -1;
 
37
    int ppa = (surface->flags & SDL_SRCALPHA && fmt->Amask);
 
38
 
 
39
    pixels = (Uint8 *) surface->pixels + surface->offset +
 
40
        (Uint16) rect->y * surface->pitch + (Uint16) rect->x * bpp;
 
41
    skip = surface->pitch - width * bpp;
 
42
 
 
43
    switch (bpp)
 
44
    {
 
45
    case 1:
 
46
    {
 
47
        SDL_GetRGBA (color, fmt, &cR, &cG, &cB, &cA);
 
48
        while (height--)
 
49
        {
 
50
            LOOP_UNROLLED4(
 
51
            {
 
52
                GET_PIXELVALS_1 (sR, sG, sB, sA, pixels, fmt);
 
53
                BLEND_ADD (tmp, cR, cG, cB, cA, sR, sG, sB, sA);
 
54
                *pixels = SDL_MapRGBA (fmt, sR, sG, sB, sA);
 
55
                pixels += bpp;
 
56
            }, n, width);
 
57
            pixels += skip;
 
58
        }
 
59
        result = 0;
 
60
        break;
 
61
    }
 
62
    case 3:
 
63
    {
 
64
        size_t offsetR, offsetG, offsetB;
 
65
        SET_OFFSETS_24 (offsetR, offsetG, offsetB, fmt);
 
66
        GET_PIXELVALS (cR, cG, cB, cA, color, fmt, ppa);
 
67
        while (height--)
 
68
        {
 
69
            LOOP_UNROLLED4(
 
70
            {
 
71
                GET_PIXEL (pixel, bpp, pixels);
 
72
                GET_PIXELVALS (sR, sG, sB, sA, pixel, fmt, ppa);
 
73
                BLEND_ADD (tmp, cR, cG, cB, cA, sR, sG, sB, sA);
 
74
                pixels[offsetR] = sR;
 
75
                pixels[offsetG] = sG;
 
76
                pixels[offsetB] = sB;
 
77
                pixels += bpp;
 
78
            }, n, width);
 
79
            pixels += skip;
 
80
        }
 
81
        result = 0;
 
82
        break;
 
83
    }
 
84
    default:
 
85
    {
 
86
        GET_PIXELVALS (cR, cG, cB, cA, color, fmt, ppa);
 
87
        /*
 
88
        printf ("Color: %d, %d, %d, %d, BPP is: %d\n", cR, cG, cB, cA, bpp);
 
89
        */
 
90
        while (height--)
 
91
        {
 
92
            LOOP_UNROLLED4(
 
93
            {
 
94
                GET_PIXEL (pixel, bpp, pixels);
 
95
                GET_PIXELVALS (sR, sG, sB, sA, pixel, fmt, ppa);
 
96
                BLEND_ADD (tmp, cR, cG, cB, cA, sR, sG, sB, sA);
 
97
                CREATE_PIXEL(pixels, sR, sG, sB, sA, bpp, fmt);
 
98
                pixels += bpp;
 
99
            }, n, width);
 
100
            pixels += skip;
 
101
        }
 
102
        result = 0;
 
103
        break;
 
104
    }
 
105
    }
 
106
    return result;
 
107
}
 
108
 
 
109
static int
 
110
surface_fill_blend_sub (SDL_Surface *surface, SDL_Rect *rect, Uint32 color)
 
111
{
 
112
    Uint8 *pixels;
 
113
    int width = rect->w;
 
114
    int height = rect->h;
 
115
    int skip;
 
116
    int bpp = surface->format->BytesPerPixel;
 
117
    int n;
 
118
    SDL_PixelFormat *fmt = surface->format;
 
119
    Uint8 sR, sG, sB, sA, cR, cG, cB, cA;
 
120
    Uint32 pixel;
 
121
    Sint32 tmp2;
 
122
    int result = -1;
 
123
    int ppa = (surface->flags & SDL_SRCALPHA && fmt->Amask);
 
124
 
 
125
    pixels = (Uint8 *) surface->pixels + surface->offset +
 
126
        (Uint16) rect->y * surface->pitch + (Uint16) rect->x * bpp;
 
127
    skip = surface->pitch - width * bpp;
 
128
 
 
129
    switch (bpp)
 
130
    {
 
131
    case 1:
 
132
    {
 
133
        SDL_GetRGBA (color, fmt, &cR, &cG, &cB, &cA);
 
134
        while (height--)
 
135
        {
 
136
            LOOP_UNROLLED4(
 
137
            {
 
138
                GET_PIXELVALS_1 (sR, sG, sB, sA, pixels, fmt);
 
139
                BLEND_SUB (tmp2, cR, cG, cB, cA, sR, sG, sB, sA);
 
140
                *pixels = SDL_MapRGBA (fmt, sR, sG, sB, sA);
 
141
                pixels += bpp;
 
142
            }, n, width);
 
143
            pixels += skip;
 
144
        }
 
145
        result = 0;
 
146
        break;
 
147
    }
 
148
    case 3:
 
149
    {
 
150
        size_t offsetR, offsetG, offsetB;
 
151
        SET_OFFSETS_24 (offsetR, offsetG, offsetB, fmt);
 
152
        GET_PIXELVALS (cR, cG, cB, cA, color, fmt, ppa);
 
153
        while (height--)
 
154
        {
 
155
            LOOP_UNROLLED4(
 
156
            {
 
157
                GET_PIXEL (pixel, bpp, pixels);
 
158
                GET_PIXELVALS (sR, sG, sB, sA, pixel, fmt, ppa);
 
159
                BLEND_SUB (tmp2, cR, cG, cB, cA, sR, sG, sB, sA);
 
160
                pixels[offsetR] = sR;
 
161
                pixels[offsetG] = sG;
 
162
                pixels[offsetB] = sB;
 
163
                pixels += bpp;
 
164
            }, n, width);
 
165
            pixels += skip;
 
166
        }
 
167
        result = 0;
 
168
        break;
 
169
    }
 
170
    default:
 
171
    {
 
172
        GET_PIXELVALS (cR, cG, cB, cA, color, fmt, ppa);
 
173
        /*
 
174
        printf ("Color: %d, %d, %d, %d, BPP is: %d\n", cR, cG, cB, cA, bpp);
 
175
        */
 
176
        while (height--)
 
177
        {
 
178
            LOOP_UNROLLED4(
 
179
            {
 
180
                GET_PIXEL (pixel, bpp, pixels);
 
181
                GET_PIXELVALS (sR, sG, sB, sA, pixel, fmt, ppa);
 
182
                BLEND_SUB (tmp2, cR, cG, cB, cA, sR, sG, sB, sA);
 
183
                CREATE_PIXEL(pixels, sR, sG, sB, sA, bpp, fmt);
 
184
                pixels += bpp;
 
185
            }, n, width);
 
186
            pixels += skip;
 
187
        }
 
188
        result = 0;
 
189
        break;
 
190
    }
 
191
    }
 
192
    return result;
 
193
}
 
194
 
 
195
static int
 
196
surface_fill_blend_mult (SDL_Surface *surface, SDL_Rect *rect, Uint32 color)
 
197
{
 
198
    Uint8 *pixels;
 
199
    int width = rect->w;
 
200
    int height = rect->h;
 
201
    int skip;
 
202
    int bpp = surface->format->BytesPerPixel;
 
203
    int n;
 
204
    SDL_PixelFormat *fmt = surface->format;
 
205
    Uint8 sR, sG, sB, sA, cR, cG, cB, cA;
 
206
    Uint32 pixel;
 
207
    int result = -1;
 
208
    int ppa = (surface->flags & SDL_SRCALPHA && fmt->Amask);
 
209
 
 
210
    pixels = (Uint8 *) surface->pixels + surface->offset +
 
211
        (Uint16) rect->y * surface->pitch + (Uint16) rect->x * bpp;
 
212
    skip = surface->pitch - width * bpp;
 
213
 
 
214
    switch (bpp)
 
215
    {
 
216
    case 1:
 
217
    {
 
218
        SDL_GetRGBA (color, fmt, &cR, &cG, &cB, &cA);
 
219
        while (height--)
 
220
        {
 
221
            LOOP_UNROLLED4(
 
222
            {
 
223
                GET_PIXELVALS_1 (sR, sG, sB, sA, pixels, fmt);
 
224
                BLEND_MULT (cR, cG, cB, cA, sR, sG, sB, sA);
 
225
                *pixels = SDL_MapRGBA (fmt, sR, sG, sB, sA);
 
226
                pixels += bpp;
 
227
            }, n, width);
 
228
            pixels += skip;
 
229
        }
 
230
        result = 0;
 
231
        break;
 
232
    }
 
233
    case 3:
 
234
    {
 
235
        size_t offsetR, offsetG, offsetB;
 
236
        SET_OFFSETS_24 (offsetR, offsetG, offsetB, fmt);
 
237
        GET_PIXELVALS (cR, cG, cB, cA, color, fmt, ppa);
 
238
        while (height--)
 
239
        {
 
240
            LOOP_UNROLLED4(
 
241
            {
 
242
                GET_PIXEL (pixel, bpp, pixels);
 
243
                GET_PIXELVALS (sR, sG, sB, sA, pixel, fmt, ppa);
 
244
                BLEND_MULT (cR, cG, cB, cA, sR, sG, sB, sA);
 
245
                pixels[offsetR] = sR;
 
246
                pixels[offsetG] = sG;
 
247
                pixels[offsetB] = sB;
 
248
                pixels += bpp;
 
249
            }, n, width);
 
250
            pixels += skip;
 
251
        }
 
252
        result = 0;
 
253
        break;
 
254
    }
 
255
    default:
 
256
    {
 
257
        GET_PIXELVALS (cR, cG, cB, cA, color, fmt, ppa);
 
258
        /*
 
259
        printf ("Color: %d, %d, %d, %d, BPP is: %d\n", cR, cG, cB, cA, bpp);
 
260
        */
 
261
        while (height--)
 
262
        {
 
263
            LOOP_UNROLLED4(
 
264
            {
 
265
                GET_PIXEL (pixel, bpp, pixels);
 
266
                GET_PIXELVALS (sR, sG, sB, sA, pixel, fmt, ppa);
 
267
                BLEND_MULT (cR, cG, cB, cA, sR, sG, sB, sA);
 
268
                CREATE_PIXEL(pixels, sR, sG, sB, sA, bpp, fmt);
 
269
                pixels += bpp;
 
270
            }, n, width);
 
271
            pixels += skip;
 
272
        }
 
273
        result = 0;
 
274
        break;
 
275
    }
 
276
    }
 
277
    return result;
 
278
}
 
279
 
 
280
static int
 
281
surface_fill_blend_min (SDL_Surface *surface, SDL_Rect *rect, Uint32 color)
 
282
{
 
283
    Uint8 *pixels;
 
284
    int width = rect->w;
 
285
    int height = rect->h;
 
286
    int skip;
 
287
    int bpp = surface->format->BytesPerPixel;
 
288
    int n;
 
289
    SDL_PixelFormat *fmt = surface->format;
 
290
    Uint8 sR, sG, sB, sA, cR, cG, cB, cA;
 
291
    Uint32 pixel;
 
292
    int result = -1;
 
293
    int ppa = (surface->flags & SDL_SRCALPHA && fmt->Amask);
 
294
 
 
295
    pixels = (Uint8 *) surface->pixels + surface->offset +
 
296
        (Uint16) rect->y * surface->pitch + (Uint16) rect->x * bpp;
 
297
    skip = surface->pitch - width * bpp;
 
298
 
 
299
    switch (bpp)
 
300
    {
 
301
    case 1:
 
302
    {
 
303
        SDL_GetRGBA (color, fmt, &cR, &cG, &cB, &cA);
 
304
        while (height--)
 
305
        {
 
306
            LOOP_UNROLLED4(
 
307
            {
 
308
                GET_PIXELVALS_1 (sR, sG, sB, sA, pixels, fmt);
 
309
                BLEND_MIN (cR, cG, cB, cA, sR, sG, sB, sA);
 
310
                *pixels = SDL_MapRGBA (fmt, sR, sG, sB, sA);
 
311
                pixels += bpp;
 
312
            }, n, width);
 
313
            pixels += skip;
 
314
        }
 
315
        result = 0;
 
316
        break;
 
317
    }
 
318
    case 3:
 
319
    {
 
320
        size_t offsetR, offsetG, offsetB;
 
321
        SET_OFFSETS_24 (offsetR, offsetG, offsetB, fmt);
 
322
        GET_PIXELVALS (cR, cG, cB, cA, color, fmt, ppa);
 
323
        while (height--)
 
324
        {
 
325
            LOOP_UNROLLED4(
 
326
            {
 
327
                GET_PIXEL (pixel, bpp, pixels);
 
328
                GET_PIXELVALS (sR, sG, sB, sA, pixel, fmt, ppa);
 
329
                BLEND_MIN (cR, cG, cB, cA, sR, sG, sB, sA);
 
330
                pixels[offsetR] = sR;
 
331
                pixels[offsetG] = sG;
 
332
                pixels[offsetB] = sB;
 
333
                pixels += bpp;
 
334
            }, n, width);
 
335
            pixels += skip;
 
336
        }
 
337
        result = 0;
 
338
        break;
 
339
    }
 
340
    default:
 
341
    {
 
342
        GET_PIXELVALS (cR, cG, cB, cA, color, fmt, ppa);
 
343
        /*
 
344
        printf ("Color: %d, %d, %d, %d, BPP is: %d\n", cR, cG, cB, cA, bpp);
 
345
        */
 
346
        while (height--)
 
347
        {
 
348
            LOOP_UNROLLED4(
 
349
            {
 
350
                GET_PIXEL (pixel, bpp, pixels);
 
351
                GET_PIXELVALS (sR, sG, sB, sA, pixel, fmt, ppa);
 
352
                BLEND_MIN (cR, cG, cB, cA, sR, sG, sB, sA);
 
353
                CREATE_PIXEL(pixels, sR, sG, sB, sA, bpp, fmt);
 
354
                pixels += bpp;
 
355
            }, n, width);
 
356
            pixels += skip;
 
357
        }
 
358
        result = 0;
 
359
        break;
 
360
    }
 
361
    }
 
362
    return result;
 
363
}
 
364
 
 
365
static int
 
366
surface_fill_blend_max (SDL_Surface *surface, SDL_Rect *rect, Uint32 color)
 
367
{
 
368
    Uint8 *pixels;
 
369
    int width = rect->w;
 
370
    int height = rect->h;
 
371
    int skip;
 
372
    int bpp = surface->format->BytesPerPixel;
 
373
    int n;
 
374
    SDL_PixelFormat *fmt = surface->format;
 
375
    Uint8 sR, sG, sB, sA, cR, cG, cB, cA;
 
376
    Uint32 pixel;
 
377
    int result = -1;
 
378
    int ppa = (surface->flags & SDL_SRCALPHA && fmt->Amask);
 
379
 
 
380
    pixels = (Uint8 *) surface->pixels + surface->offset +
 
381
        (Uint16) rect->y * surface->pitch + (Uint16) rect->x * bpp;
 
382
    skip = surface->pitch - width * bpp;
 
383
 
 
384
    switch (bpp)
 
385
    {
 
386
    case 1:
 
387
    {
 
388
        SDL_GetRGBA (color, fmt, &cR, &cG, &cB, &cA);
 
389
        while (height--)
 
390
        {
 
391
            LOOP_UNROLLED4(
 
392
            {
 
393
                GET_PIXELVALS_1 (sR, sG, sB, sA, pixels, fmt);
 
394
                BLEND_MAX (cR, cG, cB, cA, sR, sG, sB, sA);
 
395
                *pixels = SDL_MapRGBA (fmt, sR, sG, sB, sA);
 
396
                pixels += bpp;
 
397
            }, n, width);
 
398
            pixels += skip;
 
399
        }
 
400
        result = 0;
 
401
        break;
 
402
    }
 
403
    case 3:
 
404
    {
 
405
        size_t offsetR, offsetG, offsetB;
 
406
        SET_OFFSETS_24 (offsetR, offsetG, offsetB, fmt);
 
407
        GET_PIXELVALS (cR, cG, cB, cA, color, fmt, ppa);
 
408
        while (height--)
 
409
        {
 
410
            LOOP_UNROLLED4(
 
411
            {
 
412
                GET_PIXEL (pixel, bpp, pixels);
 
413
                GET_PIXELVALS (sR, sG, sB, sA, pixel, fmt, ppa);
 
414
                BLEND_MAX (cR, cG, cB, cA, sR, sG, sB, sA);
 
415
                pixels[offsetR] = sR;
 
416
                pixels[offsetG] = sG;
 
417
                pixels[offsetB] = sB;
 
418
                pixels += bpp;
 
419
            }, n, width);
 
420
            pixels += skip;
 
421
        }
 
422
        result = 0;
 
423
        break;
 
424
    }
 
425
    default:
 
426
    {
 
427
        GET_PIXELVALS (cR, cG, cB, cA, color, fmt, ppa);
 
428
        /*
 
429
        printf ("Color: %d, %d, %d, %d, BPP is: %d\n", cR, cG, cB, cA, bpp);
 
430
        */
 
431
        while (height--)
 
432
        {
 
433
            LOOP_UNROLLED4(
 
434
            {
 
435
                GET_PIXEL (pixel, bpp, pixels);
 
436
                GET_PIXELVALS (sR, sG, sB, sA, pixel, fmt, ppa);
 
437
                BLEND_MAX (cR, cG, cB, cA, sR, sG, sB, sA);
 
438
                CREATE_PIXEL(pixels, sR, sG, sB, sA, bpp, fmt);
 
439
                pixels += bpp;
 
440
            }, n, width);
 
441
            pixels += skip;
 
442
        }
 
443
        result = 0;
 
444
        break;
 
445
    }
 
446
    }
 
447
    return result;
 
448
}
 
449
 
 
450
 
 
451
/* ------------------------- */
23
452
 
24
453
static int
25
454
surface_fill_blend_rgba_add (SDL_Surface *surface, SDL_Rect *rect, Uint32 color)
28
457
    int width = rect->w;
29
458
    int height = rect->h;
30
459
    int skip;
31
 
    int bpp;
 
460
    int bpp = surface->format->BytesPerPixel;
32
461
    int n;
33
 
    SDL_PixelFormat *fmt;
 
462
    SDL_PixelFormat *fmt = surface->format;
34
463
    Uint8 sR, sG, sB, sA, cR, cG, cB, cA;
35
464
    Uint32 pixel;
36
465
    Uint32 tmp;
37
466
    int result = -1;
38
 
 
39
 
    bpp = surface->format->BytesPerPixel;
40
 
    fmt = surface->format;
 
467
    int ppa = (surface->flags & SDL_SRCALPHA && fmt->Amask);
 
468
 
 
469
    if (!ppa)
 
470
    {
 
471
        return surface_fill_blend_add (surface, rect, color);
 
472
    }
 
473
 
41
474
    pixels = (Uint8 *) surface->pixels + surface->offset +
42
475
        (Uint16) rect->y * surface->pitch + (Uint16) rect->x * bpp;
43
476
    skip = surface->pitch - width * bpp;
63
496
    }
64
497
    default:
65
498
    {
66
 
        GET_PIXELVALS (cR, cG, cB, cA, color, fmt);
 
499
        GET_PIXELVALS (cR, cG, cB, cA, color, fmt, ppa);
67
500
        /*
68
501
        printf ("Color: %d, %d, %d, %d, BPP is: %d\n", cR, cG, cB, cA, bpp);
69
502
        */
72
505
            LOOP_UNROLLED4(
73
506
            {
74
507
                GET_PIXEL (pixel, bpp, pixels);
75
 
                GET_PIXELVALS (sR, sG, sB, sA, pixel, fmt);
 
508
                GET_PIXELVALS (sR, sG, sB, sA, pixel, fmt, ppa);
76
509
                BLEND_RGBA_ADD (tmp, cR, cG, cB, cA, sR, sG, sB, sA);
77
510
                CREATE_PIXEL(pixels, sR, sG, sB, sA, bpp, fmt);
78
511
                pixels += bpp;
93
526
    int width = rect->w;
94
527
    int height = rect->h;
95
528
    int skip;
96
 
    int bpp;
 
529
    int bpp = surface->format->BytesPerPixel;
97
530
    int n;
98
 
    SDL_PixelFormat *fmt;
 
531
    SDL_PixelFormat *fmt = surface->format;
99
532
    Uint8 sR, sG, sB, sA, cR, cG, cB, cA;
100
533
    Uint32 pixel;
101
 
    Uint32 tmp;
 
534
    Sint32 tmp2;
102
535
    int result = -1;
103
 
 
104
 
    bpp = surface->format->BytesPerPixel;
105
 
    fmt = surface->format;
 
536
    int ppa = (surface->flags & SDL_SRCALPHA && fmt->Amask);
 
537
 
 
538
    if (!ppa)
 
539
    {
 
540
        return surface_fill_blend_sub (surface, rect, color);
 
541
    }
 
542
 
106
543
    pixels = (Uint8 *) surface->pixels + surface->offset +
107
544
        (Uint16) rect->y * surface->pitch + (Uint16) rect->x * bpp;
108
545
    skip = surface->pitch - width * bpp;
117
554
            LOOP_UNROLLED4(
118
555
            {
119
556
                GET_PIXELVALS_1 (sR, sG, sB, sA, pixels, fmt);
120
 
                BLEND_RGBA_SUB (tmp, cR, cG, cB, cA, sR, sG, sB, sA);
 
557
                BLEND_RGBA_SUB (tmp2, cR, cG, cB, cA, sR, sG, sB, sA);
121
558
                *pixels = SDL_MapRGBA (fmt, sR, sG, sB, sA);
122
559
                pixels += bpp;
123
560
            }, n, width);
128
565
    }
129
566
    default:
130
567
    {
131
 
        GET_PIXELVALS (cR, cG, cB, cA, color, fmt);
 
568
        GET_PIXELVALS (cR, cG, cB, cA, color, fmt, ppa);
132
569
        /*
133
570
        printf ("Color: %d, %d, %d, %d, BPP is: %d\n", cR, cG, cB, cA, bpp);
134
571
        */
137
574
            LOOP_UNROLLED4(
138
575
            {
139
576
                GET_PIXEL (pixel, bpp, pixels);
140
 
                GET_PIXELVALS (sR, sG, sB, sA, pixel, fmt);
141
 
                BLEND_RGBA_SUB (tmp, cR, cG, cB, cA, sR, sG, sB, sA);
 
577
                GET_PIXELVALS (sR, sG, sB, sA, pixel, fmt, ppa);
 
578
                BLEND_RGBA_SUB (tmp2, cR, cG, cB, cA, sR, sG, sB, sA);
142
579
                CREATE_PIXEL(pixels, sR, sG, sB, sA, bpp, fmt);
143
580
                pixels += bpp;
144
581
            }, n, width);
158
595
    int width = rect->w;
159
596
    int height = rect->h;
160
597
    int skip;
161
 
    int bpp;
 
598
    int bpp = surface->format->BytesPerPixel;
162
599
    int n;
163
 
    SDL_PixelFormat *fmt;
 
600
    SDL_PixelFormat *fmt = surface->format;
164
601
    Uint8 sR, sG, sB, sA, cR, cG, cB, cA;
165
602
    Uint32 pixel;
166
603
    int result = -1;
167
 
 
168
 
    bpp = surface->format->BytesPerPixel;
169
 
    fmt = surface->format;
 
604
    int ppa = (surface->flags & SDL_SRCALPHA && fmt->Amask);
 
605
 
 
606
    if (!ppa)
 
607
    {
 
608
        return surface_fill_blend_mult (surface, rect, color);
 
609
    }
 
610
 
170
611
    pixels = (Uint8 *) surface->pixels + surface->offset +
171
612
        (Uint16) rect->y * surface->pitch + (Uint16) rect->x * bpp;
172
613
    skip = surface->pitch - width * bpp;
192
633
    }
193
634
    default:
194
635
    {
195
 
        GET_PIXELVALS (cR, cG, cB, cA, color, fmt);
 
636
        GET_PIXELVALS (cR, cG, cB, cA, color, fmt, ppa);
196
637
        /*
197
638
        printf ("Color: %d, %d, %d, %d, BPP is: %d\n", cR, cG, cB, cA, bpp);
198
639
        */
201
642
            LOOP_UNROLLED4(
202
643
            {
203
644
                GET_PIXEL (pixel, bpp, pixels);
204
 
                GET_PIXELVALS (sR, sG, sB, sA, pixel, fmt);
 
645
                GET_PIXELVALS (sR, sG, sB, sA, pixel, fmt, ppa);
205
646
                BLEND_RGBA_MULT (cR, cG, cB, cA, sR, sG, sB, sA);
206
647
                CREATE_PIXEL(pixels, sR, sG, sB, sA, bpp, fmt);
207
648
                pixels += bpp;
222
663
    int width = rect->w;
223
664
    int height = rect->h;
224
665
    int skip;
225
 
    int bpp;
 
666
    int bpp = surface->format->BytesPerPixel;
226
667
    int n;
227
 
    SDL_PixelFormat *fmt;
 
668
    SDL_PixelFormat *fmt = surface->format;
228
669
    Uint8 sR, sG, sB, sA, cR, cG, cB, cA;
229
670
    Uint32 pixel;
230
671
    int result = -1;
231
 
 
232
 
    bpp = surface->format->BytesPerPixel;
233
 
    fmt = surface->format;
 
672
    int ppa = (surface->flags & SDL_SRCALPHA && fmt->Amask);
 
673
 
 
674
    if (!ppa)
 
675
    {
 
676
        return surface_fill_blend_min (surface, rect, color);
 
677
    }
 
678
 
234
679
    pixels = (Uint8 *) surface->pixels + surface->offset +
235
680
        (Uint16) rect->y * surface->pitch + (Uint16) rect->x * bpp;
236
681
    skip = surface->pitch - width * bpp;
256
701
    }
257
702
    default:
258
703
    {
259
 
        GET_PIXELVALS (cR, cG, cB, cA, color, fmt);
 
704
        GET_PIXELVALS (cR, cG, cB, cA, color, fmt, ppa);
260
705
        /*
261
706
        printf ("Color: %d, %d, %d, %d, BPP is: %d\n", cR, cG, cB, cA, bpp);
262
707
        */
265
710
            LOOP_UNROLLED4(
266
711
            {
267
712
                GET_PIXEL (pixel, bpp, pixels);
268
 
                GET_PIXELVALS (sR, sG, sB, sA, pixel, fmt);
 
713
                GET_PIXELVALS (sR, sG, sB, sA, pixel, fmt, ppa);
269
714
                BLEND_RGBA_MIN (cR, cG, cB, cA, sR, sG, sB, sA);
270
715
                CREATE_PIXEL(pixels, sR, sG, sB, sA, bpp, fmt);
271
716
                pixels += bpp;
286
731
    int width = rect->w;
287
732
    int height = rect->h;
288
733
    int skip;
289
 
    int bpp;
290
 
    int n;
291
 
    SDL_PixelFormat *fmt;
292
 
    Uint8 sR, sG, sB, sA, cR, cG, cB, cA;
293
 
    Uint32 pixel;
294
 
    int result = -1;
295
 
 
296
 
    bpp = surface->format->BytesPerPixel;
297
 
    fmt = surface->format;
298
 
    pixels = (Uint8 *) surface->pixels + surface->offset +
299
 
        (Uint16) rect->y * surface->pitch + (Uint16) rect->x * bpp;
300
 
    skip = surface->pitch - width * bpp;
301
 
 
302
 
    switch (bpp)
303
 
    {
304
 
    case 1:
305
 
    {
306
 
        SDL_GetRGBA (color, fmt, &cR, &cG, &cB, &cA);
307
 
        while (height--)
308
 
        {
309
 
            LOOP_UNROLLED4(
310
 
            {
311
 
                GET_PIXELVALS_1 (sR, sG, sB, sA, pixels, fmt);
312
 
                BLEND_RGBA_MAX (cR, cG, cB, cA, sR, sG, sB, sA);
313
 
                *pixels = SDL_MapRGBA (fmt, sR, sG, sB, sA);
314
 
                pixels += bpp;
315
 
            }, n, width);
316
 
            pixels += skip;
317
 
        }
318
 
        result = 0;
319
 
        break;
320
 
    }
321
 
    default:
322
 
    {
323
 
        GET_PIXELVALS (cR, cG, cB, cA, color, fmt);
324
 
        /*
325
 
        printf ("Color: %d, %d, %d, %d, BPP is: %d\n", cR, cG, cB, cA, bpp);
326
 
        */
327
 
        while (height--)
328
 
        {
329
 
            LOOP_UNROLLED4(
330
 
            {
331
 
                GET_PIXEL (pixel, bpp, pixels);
332
 
                GET_PIXELVALS (sR, sG, sB, sA, pixel, fmt);
333
 
                BLEND_RGBA_MAX (cR, cG, cB, cA, sR, sG, sB, sA);
334
 
                CREATE_PIXEL(pixels, sR, sG, sB, sA, bpp, fmt);
335
 
                pixels += bpp;
336
 
            }, n, width);
337
 
            pixels += skip;
338
 
        }
339
 
        result = 0;
340
 
        break;
341
 
    }
342
 
    }
343
 
    return result;
344
 
}
345
 
 
346
 
 
347
 
 
348
 
 
349
 
 
350
 
 
351
 
 
352
 
 
353
 
 
354
 
 
355
 
 
356
 
 
357
 
 
358
 
 
359
 
 
360
 
 
361
 
 
362
 
 
363
 
 
364
 
 
365
 
 
366
 
 
367
 
 
368
 
 
369
 
 
370
 
 
371
 
 
372
 
// -------------------------
373
 
 
374
 
 
375
 
 
376
 
static int
377
 
surface_fill_blend_add (SDL_Surface *surface, SDL_Rect *rect, Uint32 color)
378
 
{
379
 
    Uint8 *pixels;
380
 
    int width = rect->w;
381
 
    int height = rect->h;
382
 
    int skip;
383
 
    int bpp;
384
 
    int n;
385
 
    SDL_PixelFormat *fmt;
386
 
    Uint8 sR, sG, sB, sA, cR, cG, cB, cA;
387
 
    Uint32 pixel;
388
 
    Uint32 tmp;
389
 
    int result = -1;
390
 
 
391
 
    bpp = surface->format->BytesPerPixel;
392
 
    fmt = surface->format;
393
 
    pixels = (Uint8 *) surface->pixels + surface->offset +
394
 
        (Uint16) rect->y * surface->pitch + (Uint16) rect->x * bpp;
395
 
    skip = surface->pitch - width * bpp;
396
 
 
397
 
    switch (bpp)
398
 
    {
399
 
    case 1:
400
 
    {
401
 
        SDL_GetRGBA (color, fmt, &cR, &cG, &cB, &cA);
402
 
        while (height--)
403
 
        {
404
 
            LOOP_UNROLLED4(
405
 
            {
406
 
                GET_PIXELVALS_1 (sR, sG, sB, sA, pixels, fmt);
407
 
                BLEND_ADD (tmp, cR, cG, cB, cA, sR, sG, sB, sA);
408
 
                *pixels = SDL_MapRGBA (fmt, sR, sG, sB, sA);
409
 
                pixels += bpp;
410
 
            }, n, width);
411
 
            pixels += skip;
412
 
        }
413
 
        result = 0;
414
 
        break;
415
 
    }
416
 
    default:
417
 
    {
418
 
        GET_PIXELVALS (cR, cG, cB, cA, color, fmt);
419
 
        /*
420
 
        printf ("Color: %d, %d, %d, %d, BPP is: %d\n", cR, cG, cB, cA, bpp);
421
 
        */
422
 
        while (height--)
423
 
        {
424
 
            LOOP_UNROLLED4(
425
 
            {
426
 
                GET_PIXEL (pixel, bpp, pixels);
427
 
                GET_PIXELVALS (sR, sG, sB, sA, pixel, fmt);
428
 
                BLEND_ADD (tmp, cR, cG, cB, cA, sR, sG, sB, sA);
429
 
                CREATE_PIXEL(pixels, sR, sG, sB, sA, bpp, fmt);
430
 
                pixels += bpp;
431
 
            }, n, width);
432
 
            pixels += skip;
433
 
        }
434
 
        result = 0;
435
 
        break;
436
 
    }
437
 
    }
438
 
    return result;
439
 
}
440
 
 
441
 
static int
442
 
surface_fill_blend_sub (SDL_Surface *surface, SDL_Rect *rect, Uint32 color)
443
 
{
444
 
    Uint8 *pixels;
445
 
    int width = rect->w;
446
 
    int height = rect->h;
447
 
    int skip;
448
 
    int bpp;
449
 
    int n;
450
 
    SDL_PixelFormat *fmt;
451
 
    Uint8 sR, sG, sB, sA, cR, cG, cB, cA;
452
 
    Uint32 pixel;
453
 
    Uint32 tmp;
454
 
    int result = -1;
455
 
 
456
 
    bpp = surface->format->BytesPerPixel;
457
 
    fmt = surface->format;
458
 
    pixels = (Uint8 *) surface->pixels + surface->offset +
459
 
        (Uint16) rect->y * surface->pitch + (Uint16) rect->x * bpp;
460
 
    skip = surface->pitch - width * bpp;
461
 
 
462
 
    switch (bpp)
463
 
    {
464
 
    case 1:
465
 
    {
466
 
        SDL_GetRGBA (color, fmt, &cR, &cG, &cB, &cA);
467
 
        while (height--)
468
 
        {
469
 
            LOOP_UNROLLED4(
470
 
            {
471
 
                GET_PIXELVALS_1 (sR, sG, sB, sA, pixels, fmt);
472
 
                BLEND_SUB (tmp, cR, cG, cB, cA, sR, sG, sB, sA);
473
 
                *pixels = SDL_MapRGBA (fmt, sR, sG, sB, sA);
474
 
                pixels += bpp;
475
 
            }, n, width);
476
 
            pixels += skip;
477
 
        }
478
 
        result = 0;
479
 
        break;
480
 
    }
481
 
    default:
482
 
    {
483
 
        GET_PIXELVALS (cR, cG, cB, cA, color, fmt);
484
 
        /*
485
 
        printf ("Color: %d, %d, %d, %d, BPP is: %d\n", cR, cG, cB, cA, bpp);
486
 
        */
487
 
        while (height--)
488
 
        {
489
 
            LOOP_UNROLLED4(
490
 
            {
491
 
                GET_PIXEL (pixel, bpp, pixels);
492
 
                GET_PIXELVALS (sR, sG, sB, sA, pixel, fmt);
493
 
                BLEND_SUB (tmp, cR, cG, cB, cA, sR, sG, sB, sA);
494
 
                CREATE_PIXEL(pixels, sR, sG, sB, sA, bpp, fmt);
495
 
                pixels += bpp;
496
 
            }, n, width);
497
 
            pixels += skip;
498
 
        }
499
 
        result = 0;
500
 
        break;
501
 
    }
502
 
    }
503
 
    return result;
504
 
}
505
 
 
506
 
static int
507
 
surface_fill_blend_mult (SDL_Surface *surface, SDL_Rect *rect, Uint32 color)
508
 
{
509
 
    Uint8 *pixels;
510
 
    int width = rect->w;
511
 
    int height = rect->h;
512
 
    int skip;
513
 
    int bpp;
514
 
    int n;
515
 
    SDL_PixelFormat *fmt;
516
 
    Uint8 sR, sG, sB, sA, cR, cG, cB, cA;
517
 
    Uint32 pixel;
518
 
    int result = -1;
519
 
 
520
 
    bpp = surface->format->BytesPerPixel;
521
 
    fmt = surface->format;
522
 
    pixels = (Uint8 *) surface->pixels + surface->offset +
523
 
        (Uint16) rect->y * surface->pitch + (Uint16) rect->x * bpp;
524
 
    skip = surface->pitch - width * bpp;
525
 
 
526
 
    switch (bpp)
527
 
    {
528
 
    case 1:
529
 
    {
530
 
        SDL_GetRGBA (color, fmt, &cR, &cG, &cB, &cA);
531
 
        while (height--)
532
 
        {
533
 
            LOOP_UNROLLED4(
534
 
            {
535
 
                GET_PIXELVALS_1 (sR, sG, sB, sA, pixels, fmt);
536
 
                BLEND_MULT (cR, cG, cB, cA, sR, sG, sB, sA);
537
 
                *pixels = SDL_MapRGBA (fmt, sR, sG, sB, sA);
538
 
                pixels += bpp;
539
 
            }, n, width);
540
 
            pixels += skip;
541
 
        }
542
 
        result = 0;
543
 
        break;
544
 
    }
545
 
    default:
546
 
    {
547
 
        GET_PIXELVALS (cR, cG, cB, cA, color, fmt);
548
 
        /*
549
 
        printf ("Color: %d, %d, %d, %d, BPP is: %d\n", cR, cG, cB, cA, bpp);
550
 
        */
551
 
        while (height--)
552
 
        {
553
 
            LOOP_UNROLLED4(
554
 
            {
555
 
                GET_PIXEL (pixel, bpp, pixels);
556
 
                GET_PIXELVALS (sR, sG, sB, sA, pixel, fmt);
557
 
                BLEND_MULT (cR, cG, cB, cA, sR, sG, sB, sA);
558
 
                CREATE_PIXEL(pixels, sR, sG, sB, sA, bpp, fmt);
559
 
                pixels += bpp;
560
 
            }, n, width);
561
 
            pixels += skip;
562
 
        }
563
 
        result = 0;
564
 
        break;
565
 
    }
566
 
    }
567
 
    return result;
568
 
}
569
 
 
570
 
static int
571
 
surface_fill_blend_min (SDL_Surface *surface, SDL_Rect *rect, Uint32 color)
572
 
{
573
 
    Uint8 *pixels;
574
 
    int width = rect->w;
575
 
    int height = rect->h;
576
 
    int skip;
577
 
    int bpp;
578
 
    int n;
579
 
    SDL_PixelFormat *fmt;
580
 
    Uint8 sR, sG, sB, sA, cR, cG, cB, cA;
581
 
    Uint32 pixel;
582
 
    int result = -1;
583
 
 
584
 
    bpp = surface->format->BytesPerPixel;
585
 
    fmt = surface->format;
586
 
    pixels = (Uint8 *) surface->pixels + surface->offset +
587
 
        (Uint16) rect->y * surface->pitch + (Uint16) rect->x * bpp;
588
 
    skip = surface->pitch - width * bpp;
589
 
 
590
 
    switch (bpp)
591
 
    {
592
 
    case 1:
593
 
    {
594
 
        SDL_GetRGBA (color, fmt, &cR, &cG, &cB, &cA);
595
 
        while (height--)
596
 
        {
597
 
            LOOP_UNROLLED4(
598
 
            {
599
 
                GET_PIXELVALS_1 (sR, sG, sB, sA, pixels, fmt);
600
 
                BLEND_MIN (cR, cG, cB, cA, sR, sG, sB, sA);
601
 
                *pixels = SDL_MapRGBA (fmt, sR, sG, sB, sA);
602
 
                pixels += bpp;
603
 
            }, n, width);
604
 
            pixels += skip;
605
 
        }
606
 
        result = 0;
607
 
        break;
608
 
    }
609
 
    default:
610
 
    {
611
 
        GET_PIXELVALS (cR, cG, cB, cA, color, fmt);
612
 
        /*
613
 
        printf ("Color: %d, %d, %d, %d, BPP is: %d\n", cR, cG, cB, cA, bpp);
614
 
        */
615
 
        while (height--)
616
 
        {
617
 
            LOOP_UNROLLED4(
618
 
            {
619
 
                GET_PIXEL (pixel, bpp, pixels);
620
 
                GET_PIXELVALS (sR, sG, sB, sA, pixel, fmt);
621
 
                BLEND_MIN (cR, cG, cB, cA, sR, sG, sB, sA);
622
 
                CREATE_PIXEL(pixels, sR, sG, sB, sA, bpp, fmt);
623
 
                pixels += bpp;
624
 
            }, n, width);
625
 
            pixels += skip;
626
 
        }
627
 
        result = 0;
628
 
        break;
629
 
    }
630
 
    }
631
 
    return result;
632
 
}
633
 
 
634
 
static int
635
 
surface_fill_blend_max (SDL_Surface *surface, SDL_Rect *rect, Uint32 color)
636
 
{
637
 
    Uint8 *pixels;
638
 
    int width = rect->w;
639
 
    int height = rect->h;
640
 
    int skip;
641
 
    int bpp;
642
 
    int n;
643
 
    SDL_PixelFormat *fmt;
644
 
    Uint8 sR, sG, sB, sA, cR, cG, cB, cA;
645
 
    Uint32 pixel;
646
 
    int result = -1;
647
 
 
648
 
    bpp = surface->format->BytesPerPixel;
649
 
    fmt = surface->format;
650
 
    pixels = (Uint8 *) surface->pixels + surface->offset +
651
 
        (Uint16) rect->y * surface->pitch + (Uint16) rect->x * bpp;
652
 
    skip = surface->pitch - width * bpp;
653
 
 
654
 
    switch (bpp)
655
 
    {
656
 
    case 1:
657
 
    {
658
 
        SDL_GetRGBA (color, fmt, &cR, &cG, &cB, &cA);
659
 
        while (height--)
660
 
        {
661
 
            LOOP_UNROLLED4(
662
 
            {
663
 
                GET_PIXELVALS_1 (sR, sG, sB, sA, pixels, fmt);
664
 
                BLEND_MAX (cR, cG, cB, cA, sR, sG, sB, sA);
665
 
                *pixels = SDL_MapRGBA (fmt, sR, sG, sB, sA);
666
 
                pixels += bpp;
667
 
            }, n, width);
668
 
            pixels += skip;
669
 
        }
670
 
        result = 0;
671
 
        break;
672
 
    }
673
 
    default:
674
 
    {
675
 
        GET_PIXELVALS (cR, cG, cB, cA, color, fmt);
676
 
        /*
677
 
        printf ("Color: %d, %d, %d, %d, BPP is: %d\n", cR, cG, cB, cA, bpp);
678
 
        */
679
 
        while (height--)
680
 
        {
681
 
            LOOP_UNROLLED4(
682
 
            {
683
 
                GET_PIXEL (pixel, bpp, pixels);
684
 
                GET_PIXELVALS (sR, sG, sB, sA, pixel, fmt);
685
 
                BLEND_MAX (cR, cG, cB, cA, sR, sG, sB, sA);
686
 
                CREATE_PIXEL(pixels, sR, sG, sB, sA, bpp, fmt);
687
 
                pixels += bpp;
688
 
            }, n, width);
689
 
            pixels += skip;
690
 
        }
691
 
        result = 0;
692
 
        break;
693
 
    }
694
 
    }
695
 
    return result;
696
 
}
 
734
    int bpp = surface->format->BytesPerPixel;
 
735
    int n;
 
736
    SDL_PixelFormat *fmt = surface->format;
 
737
    Uint8 sR, sG, sB, sA, cR, cG, cB, cA;
 
738
    Uint32 pixel;
 
739
    int result = -1;
 
740
    int ppa = (surface->flags & SDL_SRCALPHA && fmt->Amask);
 
741
 
 
742
    if (!ppa)
 
743
    {
 
744
        return surface_fill_blend_max (surface, rect, color);
 
745
    }
 
746
 
 
747
    pixels = (Uint8 *) surface->pixels + surface->offset +
 
748
        (Uint16) rect->y * surface->pitch + (Uint16) rect->x * bpp;
 
749
    skip = surface->pitch - width * bpp;
 
750
 
 
751
    switch (bpp)
 
752
    {
 
753
    case 1:
 
754
    {
 
755
        SDL_GetRGBA (color, fmt, &cR, &cG, &cB, &cA);
 
756
        while (height--)
 
757
        {
 
758
            LOOP_UNROLLED4(
 
759
            {
 
760
                GET_PIXELVALS_1 (sR, sG, sB, sA, pixels, fmt);
 
761
                BLEND_RGBA_MAX (cR, cG, cB, cA, sR, sG, sB, sA);
 
762
                *pixels = SDL_MapRGBA (fmt, sR, sG, sB, sA);
 
763
                pixels += bpp;
 
764
            }, n, width);
 
765
            pixels += skip;
 
766
        }
 
767
        result = 0;
 
768
        break;
 
769
    }
 
770
    default:
 
771
    {
 
772
        GET_PIXELVALS (cR, cG, cB, cA, color, fmt, ppa);
 
773
        /*
 
774
        printf ("Color: %d, %d, %d, %d, BPP is: %d\n", cR, cG, cB, cA, bpp);
 
775
        */
 
776
        while (height--)
 
777
        {
 
778
            LOOP_UNROLLED4(
 
779
            {
 
780
                GET_PIXEL (pixel, bpp, pixels);
 
781
                GET_PIXELVALS (sR, sG, sB, sA, pixel, fmt, ppa);
 
782
                BLEND_RGBA_MAX (cR, cG, cB, cA, sR, sG, sB, sA);
 
783
                CREATE_PIXEL(pixels, sR, sG, sB, sA, bpp, fmt);
 
784
                pixels += bpp;
 
785
            }, n, width);
 
786
            pixels += skip;
 
787
        }
 
788
        result = 0;
 
789
        break;
 
790
    }
 
791
    }
 
792
    return result;
 
793
}
 
794
 
697
795
 
698
796
int
699
797
surface_fill_blend (SDL_Surface *surface, SDL_Rect *rect, Uint32 color,
775
873
        break;
776
874
    }
777
875
    }
 
876
 
 
877
    if (locked)
 
878
    {
 
879
        SDL_UnlockSurface (surface);
 
880
    }
778
881
    return result;
779
882
}