0
|
1 /*
|
|
2 * Copyright (c) 2004-2006 Kazunori "jagarl" Ueno
|
|
3 * All rights reserved.
|
|
4 *
|
|
5 * Redistribution and use in source and binary forms, with or without
|
|
6 * modification, are permitted provided that the following conditions
|
|
7 * are met:
|
|
8 * 1. Redistributions of source code must retain the above copyright
|
|
9 * notice, this list of conditions and the following disclaimer.
|
|
10 * 2. Redistributions in binary form must reproduce the above copyright
|
|
11 * notice, this list of conditions and the following disclaimer in the
|
|
12 * documentation and/or other materials provided with the distribution.
|
|
13 * 3. The name of the author may not be used to endorse or promote products
|
|
14 * derived from this software without specific prior written permission.
|
|
15 *
|
|
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
26 */
|
|
27
|
52
|
28 #include "font/font.h"
|
|
29 #include "font/text.h"
|
|
30 #include "rect.h"
|
|
31 #include "SDL.h"
|
|
32 #include "surface.h"
|
|
33 #include <stdio.h>
|
0
|
34
|
|
35 Rect DSurfaceRenderText(TextGlyphStream::iterator start, TextGlyphStream::iterator end, const Rect& srcrect,
|
|
36 Surface* dst, const Rect& dstrect); // 文字描画
|
|
37 void DSurfaceFill(Surface* src, const Rect& rect, int r, int g, int b, int a); // クリア
|
|
38 void DSurfaceFillA(Surface* src, const Rect& rect, int r, int g, int b, int a); // テキストウィンドウ背景の設定
|
|
39 void DSurfaceMove(Surface* src_o, const Rect& srcrect, Surface* dst_o, const Rect& dstrect); // コピー
|
|
40 void DSurfaceBlitAlpha(Surface* src_o, const Rect& srcrect_o, Surface* dst_o, const Rect& dstrect_o, const unsigned char* alpha, const Rect& alpharect);
|
|
41 void DSurfaceBlitSaturate(Surface* src_o, const Rect& srcrect, Surface* dst_o, const Rect& dstrect, unsigned char alpha);
|
|
42 void DSurfaceBlitMultiply(Surface* src_o, const Rect& srcrect_o, Surface* dst_o, const Rect& dstrect_o);
|
|
43
|
|
44 #ifndef ALPHA_MAX
|
|
45 #define ALPHA_MAX 255
|
|
46 #endif
|
|
47
|
|
48 Rect::Rect(const TextGlyph& letter) {
|
|
49 lx = letter.x + letter.glyph->bitmap_left;
|
|
50 rx = lx + letter.glyph->bitmap.width;
|
|
51
|
|
52 ty = letter.y - letter.glyph->bitmap_top;
|
|
53 by = ty + letter.glyph->bitmap.rows;
|
|
54 }
|
|
55
|
|
56 Rect::Rect(const class Surface& so) {
|
|
57 SDL_Surface* s = (SDL_Surface*)(&so);
|
|
58 lx = 0; ty = 0;
|
|
59 rx = s->w; by = s->h;
|
|
60 }
|
52
|
61
|
0
|
62 inline Rect _Rect(const SDL_Rect& r) {
|
|
63 return Rect(r.x, r.y, r.x+r.w, r.y+r.h);
|
52
|
64 }
|
|
65
|
0
|
66 inline SDL_Rect SDLed(const Rect& rect) {
|
|
67 SDL_Rect r;
|
|
68 r.x = rect.lx;
|
|
69 r.y = rect.ty;
|
|
70 r.w = rect.rx-rect.lx;
|
|
71 r.h = rect.by-rect.ty;
|
|
72 return r;
|
|
73 }
|
|
74
|
|
75 Rect DSurfaceRenderText(TextGlyphStream::iterator start, TextGlyphStream::iterator end, const Rect& srcrect,
|
|
76 Surface* dst_o, const Rect& dstrect) {
|
|
77
|
|
78 SDL_Surface* dst = (SDL_Surface*)dst_o;
|
|
79 Rect confine_to(srcrect);
|
|
80 Rect dst_clip(_Rect(dst->clip_rect));
|
|
81 Rect drawn_rect(0,0,0,0);
|
|
82
|
|
83 int dif_x = dstrect.lx - srcrect.lx;
|
|
84 int dif_y = dstrect.ty - srcrect.ty;
|
|
85
|
|
86 dst_clip.rmove(-dif_x, -dif_y);
|
|
87 confine_to.intersect(dst_clip);
|
|
88
|
|
89 TextGlyphStream::iterator it;
|
|
90 SDL_PixelFormat& fmt = *dst->format;
|
|
91 int ashift = fmt.Ashift - fmt.Aloss; int amask = fmt.Amask;
|
|
92 int dbpl = dst->pitch;
|
|
93 int dbpp = fmt.BytesPerPixel;
|
|
94
|
|
95 SDL_LockSurface(dst);
|
|
96 for (it=start; it!=end; it++) {
|
|
97 Rect letter_r(*it);
|
|
98 letter_r.intersect(confine_to);
|
|
99 if (letter_r.empty()) continue;
|
|
100 drawn_rect.join(letter_r);
|
|
101
|
|
102 int w = letter_r.width();
|
|
103 int h = letter_r.height();
|
|
104 int sbpl = it->glyph->bitmap.width;
|
|
105
|
|
106 unsigned char* smem = it->glyph->bitmap.buffer +
|
|
107 (letter_r.ty - (it->y-it->glyph->bitmap_top)) * sbpl +
|
|
108 (letter_r.lx - (it->x+it->glyph->bitmap_left));
|
|
109 char* dmem = (char*)dst->pixels +
|
|
110 (letter_r.ty + dif_y) * dbpl +
|
|
111 (letter_r.lx + dif_x) * dbpp;
|
|
112 Uint32 pixel = ((int(it->r)<<fmt.Rshift)&fmt.Rmask) |((int(it->g)<<fmt.Gshift)&fmt.Gmask) |((int(it->b)<<fmt.Bshift)&fmt.Bmask);
|
|
113 int i,j;
|
|
114 if (!it->is_rev) {
|
|
115 if (dbpp == 4) {
|
|
116 for (i=0; i<h; i++) {
|
|
117 for (j=0; j<w; j++) {
|
|
118 int alpha = smem[j];
|
|
119 ((Uint32*)dmem)[j] = pixel | ((alpha << ashift)&amask);
|
|
120 }
|
|
121 smem += sbpl; dmem += dbpl;
|
|
122 }
|
|
123 } else if (dbpp == 2) {
|
|
124 for (i=0; i<h; i++) {
|
|
125 for (j=0; j<w; j++) {
|
|
126 int alpha = smem[j];
|
|
127 ((Uint16*)dmem)[j] = pixel | ((alpha << ashift)&amask);
|
|
128 }
|
|
129 smem += sbpl; dmem += dbpl;
|
|
130 }
|
|
131 } else abort();
|
|
132 } else { /* reversed */
|
|
133 if (dbpp == 4) {
|
|
134 for (i=0; i<h; i++) {
|
|
135 for (j=0; j<w; j++) {
|
|
136 int alpha = 255 - smem[j];
|
|
137 ((Uint32*)dmem)[j] = pixel | ((alpha << ashift)&amask);
|
|
138 }
|
|
139 smem += sbpl; dmem += dbpl;
|
|
140 }
|
|
141 } else if (dbpp == 2) {
|
|
142 for (i=0; i<h; i++) {
|
|
143 for (j=0; j<w; j++) {
|
|
144 int alpha = 255 - smem[j];
|
|
145 ((Uint16*)dmem)[j] = pixel | ((alpha << ashift)&amask);
|
|
146 }
|
|
147 smem += sbpl; dmem += dbpl;
|
|
148 }
|
|
149 } else abort();
|
|
150 }
|
|
151 }
|
|
152 SDL_UnlockSurface(dst);
|
|
153 drawn_rect.rmove(dif_x, dif_y);
|
|
154 return drawn_rect;
|
|
155 }
|
52
|
156
|
0
|
157 void DSurfaceFill(Surface* src_o, const Rect& rect, int r, int g, int b, int a) {
|
|
158 SDL_Rect sr = SDLed(rect);
|
|
159 SDL_Surface* src = (SDL_Surface*)src_o;
|
|
160 SDL_FillRect( src, &sr, SDL_MapRGBA(src->format, r, g, b, a));
|
|
161 }
|
|
162
|
|
163 static void clip_rect(Rect& srcrect, Rect& dstrect, SDL_Surface* dstsurf) {
|
|
164 Rect confine_to(srcrect);
|
|
165 Rect dst_clip(_Rect(dstsurf->clip_rect));
|
|
166
|
|
167 int dif_x = dstrect.lx - srcrect.lx;
|
|
168 int dif_y = dstrect.ty - srcrect.ty;
|
|
169
|
|
170 dst_clip.rmove(-dif_x, -dif_y);
|
|
171 confine_to.intersect(dst_clip);
|
|
172
|
|
173 srcrect = confine_to;
|
|
174 dstrect = confine_to;
|
|
175 dstrect.rmove(dif_x, dif_y);
|
|
176 }
|
|
177
|
|
178 void DSurfaceMove(Surface* src_o, const Rect& srcrect_o, Surface* dst_o, const Rect& dstrect_o) {
|
|
179
|
|
180 SDL_Surface* dst = (SDL_Surface*)dst_o;
|
|
181 SDL_Surface* src = (SDL_Surface*)src_o;
|
|
182
|
|
183 if (dst->format->BytesPerPixel != src->format->BytesPerPixel) return; // RGB変換はできない
|
|
184
|
|
185 Rect srcrect(srcrect_o), dstrect(dstrect_o);
|
|
186 clip_rect(srcrect, dstrect, dst);
|
|
187
|
|
188 SDL_LockSurface(dst); SDL_LockSurface(src);
|
|
189 int sbpl = src->pitch;
|
|
190 int dbpl = dst->pitch;
|
|
191 int bpp = dst->format->BytesPerPixel;
|
|
192 int width = bpp * srcrect.width();
|
|
193 int height = srcrect.height();
|
|
194 char* smem = src_o->mem(srcrect);
|
|
195 char* dmem = dst_o->mem(dstrect);
|
|
196 char* smem_end = src_o->mem_end(srcrect);
|
|
197 char* dmem_end = dst_o->mem_end(dstrect);
|
|
198
|
|
199 // メモリに重なりがあり、src が上位側の場合、コピー方向を逆転する
|
|
200 if (smem < dmem && dmem < smem_end) {
|
|
201 int i,j;
|
|
202 for (i=0; i<height; i++) {
|
|
203 char* s = smem_end; char* d = dmem_end;
|
|
204 for (j=0; j<width; j++)
|
|
205 *--d = *--s;
|
|
206 dmem_end -= dbpl; smem_end -= sbpl;
|
|
207 }
|
|
208 } else {
|
|
209 int i;
|
|
210 for (i=0; i<height; i++) {
|
|
211 memcpy(dmem, smem, width);
|
|
212 dmem += dbpl; smem += sbpl;
|
|
213 }
|
|
214 }
|
|
215 SDL_UnlockSurface(dst);
|
|
216 SDL_UnlockSurface(src);
|
|
217 }
|
|
218
|
|
219 void DSurfaceFillA(Surface* dsto, const Rect& rect, int r, int g, int b, int a) {
|
|
220 SDL_Surface* dst = (SDL_Surface*)dsto;
|
|
221 SDL_LockSurface( dst);
|
|
222 int dbpl = dst->pitch;
|
|
223 int bpp = dst->format->BytesPerPixel;
|
|
224 int width = rect.width();
|
|
225 int height = rect.height();
|
|
226 int amask = dst->format->Amask;
|
|
227 int ashift = dst->format->Ashift - dst->format->Aloss;
|
|
228
|
|
229 char* dmem = (char*)(dst->pixels) + rect.ty*dbpl + rect.lx*bpp;
|
|
230 unsigned int pixel = SDL_MapRGBA(dst->format, r, g, b, 0);
|
|
231 unsigned int pixela = SDL_MapRGBA(dst->format, r, g, b, a);
|
|
232 a += a>>7; /* 0-256 にする */
|
52
|
233 int i, j;
|
0
|
234 for (i=0; i<height; i++) {
|
|
235 char* d = dmem;
|
|
236 if (bpp == 4) {
|
|
237 for (j=0; j<width; j++) {
|
|
238 int alpha = (*(Uint32*)d)>>ashift;
|
|
239 if (alpha == 0) (*(Uint32*)d) = pixel;
|
|
240 else if (alpha == 255) *((Uint32*)d) = pixela;
|
|
241 else { *((Uint32*)d) = pixel | ((((alpha*a)>>8)<<ashift)&amask); }
|
|
242 d += bpp;
|
|
243 }
|
|
244 } else if (bpp == 2) {
|
|
245 for (j=0; j<width; j++) {
|
|
246 int alpha = (*(Uint16*)d)>>ashift;
|
|
247 if (alpha == 0) *((Uint16*)d) = pixel;
|
|
248 else if (alpha == 255) *((Uint16*)d) = pixela;
|
|
249 else { *((Uint16*)d) = pixel | ((((alpha*a)>>8)<<ashift)&amask); }
|
|
250 d += bpp;
|
|
251 }
|
|
252 }
|
|
253 dmem += dbpl;
|
|
254 }
|
|
255 SDL_UnlockSurface( dst);
|
|
256 }
|
|
257
|
|
258 #define ASHIFT 24
|
|
259 #define CMASK1 0xff00ff
|
|
260 #define CMASK2 0x00ff00
|
|
261
|
|
262 inline void blit_pixel(Uint32* dmem, Uint32* smem, const unsigned char* amem, bool use_srcalpha) {
|
|
263 Uint32 d = *dmem;
|
|
264 Uint32 s = *smem;
|
|
265 Uint32 as = s>>ASHIFT;
|
|
266 if (as == 255 || (!use_srcalpha) ) {
|
|
267 as = *amem;
|
|
268 } else {
|
|
269 as += as>>7; /* 0-0xff -> 0-0x100 */
|
|
270 as *= *amem;
|
|
271 as >>= 8;
|
|
272 }
|
|
273 as += as>>7;
|
|
274 Uint32 s1 = s & CMASK1;
|
|
275 Uint32 d1 = d & CMASK1;
|
|
276 d1 = (d1 + (((s1-d1) * as) >> 8)) & CMASK1;
|
|
277 s &= CMASK2;
|
|
278 d &= CMASK2;
|
|
279 d = (d + (((s-d) * as) >> 8)) & CMASK2;
|
|
280 *dmem = d1 | d | 0xff000000;
|
|
281 }
|
52
|
282
|
0
|
283 static void blit_line(Uint32* dmem, Uint32* smem, const unsigned char* amem,int ax0, int ax1, int awidth, int aj0, int aj1, bool use_srcalpha) {
|
|
284 int j;
|
|
285 int ax = ax0;
|
|
286 const unsigned char* a = amem + ax0;
|
|
287 Uint32* d = dmem;
|
|
288 Uint32* s = smem;
|
|
289 if (awidth == 1) { // わりとよくあるので最適化
|
|
290 for (j=aj0; j < aj1; j++) {
|
|
291 blit_pixel(d++, s++, amem, use_srcalpha);
|
|
292 }
|
|
293 } else {
|
|
294 for (j=aj0; j < aj1; j++) {
|
|
295 for (; ax<awidth; ax++)
|
|
296 blit_pixel(d++, s++, a++, use_srcalpha);
|
|
297 ax = 0;
|
|
298 a = amem;
|
|
299 }
|
|
300 for (; ax < ax1; ax++) blit_pixel(d++, s++, a++, use_srcalpha);
|
|
301 }
|
|
302 }
|
|
303
|
|
304 void DSurfaceBlitAlpha(Surface* src_o, const Rect& srcrect_o, Surface* dst_o, const Rect& dstrect_o, const unsigned char* alpha, const Rect& alpharect) {
|
|
305 SDL_Surface* dst = (SDL_Surface*)dst_o;
|
|
306 SDL_Surface* src = (SDL_Surface*)src_o;
|
|
307 SDL_PixelFormat& fmt = *dst->format;
|
|
308
|
|
309 Rect srcrect(srcrect_o), dstrect(dstrect_o);
|
|
310 clip_rect(srcrect, dstrect, dst);
|
|
311
|
|
312 int awidth = alpharect.width();
|
|
313 int aheight = alpharect.height();
|
|
314 if (awidth == 0 || aheight == 0) return;
|
|
315 int ax0 = srcrect.lx % awidth;
|
|
316 int ay0 = srcrect.ty % aheight;
|
|
317 int aj0 = srcrect.lx / awidth;
|
|
318 int ai0 = srcrect.ty / aheight;
|
|
319 int ax1 = srcrect.rx % awidth;
|
|
320 int ay1 = srcrect.by % aheight;
|
|
321 int aj1 = srcrect.rx / awidth;
|
|
322 int ai1 = srcrect.by / aheight;
|
|
323
|
|
324 SDL_LockSurface(dst);
|
|
325 SDL_LockSurface(src);
|
|
326 int dbpl = dst->pitch;
|
|
327 int sbpl = src->pitch;
|
|
328 int bpp = dst->format->BytesPerPixel;
|
|
329
|
|
330 char* dmem = dst_o->mem(dstrect);
|
|
331 char* smem = src_o->mem(srcrect);
|
|
332
|
|
333 const unsigned char* amem = alpha + ay0 * awidth;
|
|
334 int i;
|
|
335 int ay = ay0;
|
|
336 for (i = ai0; i < ai1; i++) {
|
|
337 for (; ay < aheight; ay++) {
|
|
338 if (src->format->Amask == 0)
|
|
339 blit_line( (Uint32*)dmem, (Uint32*)smem, amem,ax0, ax1, awidth, aj0, aj1, false);
|
|
340 else
|
|
341 blit_line( (Uint32*)dmem, (Uint32*)smem, amem,ax0, ax1, awidth, aj0, aj1, true);
|
|
342 amem += awidth; dmem += dbpl; smem += sbpl;
|
|
343 }
|
|
344 ay = 0; amem = alpha;
|
|
345 }
|
|
346 for (; ay < ay1; ay++) {
|
|
347 if (src->format->Amask == 0)
|
|
348 blit_line( (Uint32*)dmem, (Uint32*)smem, amem,ax0, ax1, awidth, aj0, aj1, false);
|
|
349 else
|
|
350 blit_line( (Uint32*)dmem, (Uint32*)smem, amem,ax0, ax1, awidth, aj0, aj1, true);
|
|
351 amem += awidth; dmem += dbpl; smem += sbpl;
|
|
352 }
|
|
353 SDL_UnlockSurface(src);
|
|
354 SDL_UnlockSurface(dst);
|
|
355 }
|
52
|
356
|
0
|
357 void DSurfaceBlitSaturate(Surface* src_o, const Rect& srcrect_o, Surface* dst_o, const Rect& dstrect_o, unsigned char alpha) {
|
|
358 SDL_Surface* dst = (SDL_Surface*)dst_o;
|
|
359 SDL_Surface* src = (SDL_Surface*)src_o;
|
|
360
|
|
361 if (dst->format->BytesPerPixel != src->format->BytesPerPixel) return; // RGB変換はできない
|
|
362
|
|
363 Rect srcrect(srcrect_o), dstrect(dstrect_o);
|
|
364 clip_rect(srcrect, dstrect, dst);
|
|
365
|
|
366 SDL_LockSurface(dst); SDL_LockSurface(src);
|
|
367 int sbpl = src->pitch;
|
|
368 int dbpl = dst->pitch;
|
|
369 int bpp = dst->format->BytesPerPixel;
|
|
370 int width = srcrect.width();
|
|
371 int height = srcrect.height();
|
|
372 char* smem = src_o->mem(srcrect);
|
|
373 char* dmem = dst_o->mem(dstrect);
|
|
374 char* smem_end = src_o->mem_end(srcrect);
|
|
375 char* dmem_end = dst_o->mem_end(dstrect);
|
|
376
|
|
377 SDL_PixelFormat& fmt = *dst->format;
|
|
378 int rshift = fmt.Rshift - fmt.Rloss; int rmask = fmt.Rmask;
|
|
379 int gshift = fmt.Gshift - fmt.Gloss; int gmask = fmt.Gmask;
|
|
380 int bshift = fmt.Bshift - fmt.Bloss; int bmask = fmt.Bmask;
|
|
381 int allmask = rmask | gmask | bmask;
|
|
382 int i;
|
|
383 for (i=0; i<height; i++) {
|
|
384 char* d = dmem; char* s = smem;
|
|
385 int j; for (j=0; j<width; j++) {
|
|
386 Uint32 sd = *(Uint32*)s;
|
|
387 Uint32 dd = *(Uint32*)d;
|
|
388 if (sd&allmask) {
|
|
389 Uint32 sr = (sd&rmask)>>rshift;
|
|
390 Uint32 sg = (sd&gmask)>>gshift;
|
|
391 Uint32 sb = (sd&bmask)>>bshift;
|
|
392 if (alpha != ALPHA_MAX) {
|
|
393 sr = (sr*alpha)>>8;
|
|
394 sg = (sg*alpha)>>8;
|
|
395 sb = (sb*alpha)>>8;
|
|
396 }
|
|
397 Uint32 dr = sr + ((dd&rmask)>>rshift);
|
|
398 Uint32 dg = sg + ((dd&gmask)>>gshift);
|
|
399 Uint32 db = sb + ((dd&bmask)>>bshift);
|
|
400 if (dr > 255) dr = 255;
|
|
401 if (dg > 255) dg = 255;
|
|
402 if (db > 255) db = 255;
|
|
403 *(Uint32*)d = ((dr<<rshift)&rmask)| ((dg<<gshift)&gmask)| ((db<<bshift)&bmask);
|
|
404 }
|
|
405 s += bpp; d += bpp;
|
|
406 }
|
|
407 dmem += dbpl; smem += sbpl;
|
|
408 }
|
|
409 SDL_UnlockSurface(src);
|
|
410 SDL_UnlockSurface(dst);
|
|
411 }
|
52
|
412
|
0
|
413 void DSurfaceBlitMultiply(Surface* src_o, const Rect& srcrect_o, Surface* dst_o, const Rect& dstrect_o) {
|
|
414 SDL_Surface* dst = (SDL_Surface*)dst_o;
|
|
415 SDL_Surface* src = (SDL_Surface*)src_o;
|
|
416
|
|
417 Rect srcrect(srcrect_o), dstrect(dstrect_o);
|
|
418 clip_rect(srcrect, dstrect, dst);
|
|
419
|
|
420 SDL_LockSurface(dst);
|
|
421 SDL_LockSurface(src);
|
|
422 int dbpl = dst->pitch;
|
|
423 int sbpl = src->pitch;
|
|
424 int bpp = dst->format->BytesPerPixel;
|
|
425 int width = srcrect.width();
|
|
426 int height = srcrect.height();
|
|
427 char* dmem = dst_o->mem(dstrect);
|
|
428 char* smem = src_o->mem(srcrect);
|
|
429
|
|
430 SDL_PixelFormat& fmt = *dst->format;
|
|
431 /* dst の 0-255 を 0-pixel に変換する(積算) */
|
|
432 int i;
|
|
433 int table1[256], table2[256], table3[256];
|
|
434 Uint32 src_pixel = *(Uint32*)smem;
|
|
435 src_pixel |= 0xff000000;
|
|
436 int c1=src_pixel&255, c2=(src_pixel>>8)&255, c3=(src_pixel>>16)&255;
|
|
437 for (i=0; i<256; i++) {
|
|
438 int n = i + (i>>7);
|
|
439 table1[i] = (c1*n)>>8;
|
|
440 table2[i] = (c2*n)&0xff00;
|
|
441 table3[i] = ((c3*n)<<8) & 0xff0000;
|
|
442 }
|
|
443 int err_count = 0;
|
|
444 for (i=0; i<height; i++) {
|
|
445 Uint32* d = (Uint32*)dmem;
|
|
446 Uint32* s = (Uint32*)smem;
|
|
447 int j; for (j=0; j<width; j++) {
|
|
448 Uint32 dd = *d;
|
|
449 Uint32 ss = *s;
|
|
450 if (ss == src_pixel) {
|
|
451 *(Uint32*)d = table1[ dd & 0xff] | table2[ (dd>>8) & 0xff] | table3[ (dd>>16) & 0xff];
|
|
452 } else if ( ((ss^src_pixel) & 0xffffff) == 0) { // r,g,b of ss == src_pixel
|
|
453 Uint32 as = ss>>ASHIFT;
|
|
454 as += as>>7;
|
|
455 ss = table1[ dd & 0xff] | table2[ (dd>>8) & 0xff] | table3[ (dd>>16) & 0xff];
|
|
456 Uint32 s1 = ss&CMASK1;
|
|
457 Uint32 d1 = dd&CMASK1;
|
|
458 d1 = (d1 + (((s1-d1) * as) >> 8)) & CMASK1;
|
|
459 ss &= CMASK2;
|
|
460 dd &= CMASK2;
|
|
461 dd = (dd + (((ss-dd) * as) >> 8)) & CMASK2;
|
|
462 *(Uint32*)d = d1 | dd | 0xff000000;
|
|
463 } else err_count++;
|
|
464 d++; s++;
|
|
465 }
|
|
466 dmem += dbpl; smem += sbpl;
|
|
467 }
|
|
468 if (err_count) {
|
|
469 fprintf(stderr,"multipy_blit : surface does not have unique color(%08x); %d pixels in width %d, height %d\n",
|
|
470 src_pixel, err_count, width, height);
|
|
471 }
|
|
472 SDL_UnlockSurface(dst);
|
|
473 SDL_UnlockSurface(src);
|
|
474 }
|