source: trunk/src/ddraw/fillfunc.cpp@ 8816

Last change on this file since 8816 was 8816, checked in by sandervl, 23 years ago

color fill fixes (heap corruption & missing lines)

File size: 14.9 KB
Line 
1/* $Id: fillfunc.cpp,v 1.5 2002-07-01 16:02:05 sandervl Exp $ */
2
3/*
4 * ColorFill functions
5 *
6 * Copyright 1999 Markus Montkowski
7 *
8 * Project Odin Software License can be found in LICENSE.TXT
9 *
10 */
11
12#define INCL_BASE
13#include <os2wrap.h>
14#include <win32type.h>
15#include <memory.h>
16#include <misc.h>
17#include "fillfunc.h"
18
19//
20// Blt Functions
21//
22
23#ifndef USE_ASM
24void __cdecl Fill8( char* pDst,
25 DWORD dwWidth,
26 DWORD dwHeight,
27 DWORD dwPitch,
28 DWORD dwColor)
29{
30 DWORD *pColor;
31 char *pFillPos;
32 int i;
33 dprintf(("DDRAW:Fill8 with %08X\n",dwColor));
34
35 // First Fill First row with the color
36
37 for( i=0,pColor = (DWORD*)pDst;i<(dwWidth/4);i++)
38 pColor[i] = dwColor;
39
40 if(dwWidth % 4)
41 {
42 if(i==0) i = 1; //or else next line will corrupt heap
43 pFillPos = (char*) (&pColor[i-1]);
44 for(i=0;i<dwWidth % 4;i++)
45 pFillPos[i] = (UCHAR) dwColor;
46 }
47
48 dwHeight--;
49
50 if(dwWidth == dwPitch)
51 {
52 // Width = Pitch => fill buffer so no need to take care of lines
53 memcpy(pDst+dwPitch, pDst, dwWidth*dwHeight);
54 }
55 else
56 {
57 pFillPos = pDst+dwPitch;
58 while(dwHeight)
59 {
60 memcpy(pFillPos,pDst,dwWidth);
61 pFillPos += dwPitch;
62 dwHeight--;
63 }
64 }
65}
66void __cdecl Fill16( char* pDst,
67 DWORD dwWidth,
68 DWORD dwHeight,
69 DWORD dwPitch,
70 DWORD dwColor)
71{
72 DWORD *pColor;
73 char *pFillPos;
74 int i;
75 dprintf(("DDRAW:Fill16 with %08X \n",dwColor));
76
77 // First Fill First row with the color
78
79 for( i=0,pColor = (DWORD*)pDst;i<(dwWidth/2);i++)
80 pColor[i] = dwColor;
81
82 if(dwWidth % 2)
83 {
84 if(i==0) i = 1; //or else next line will corrupt heap
85 pFillPos = (char*)(&pColor[i-1]);
86 *((USHORT*)pFillPos) = (USHORT)dwColor;
87 }
88
89 dwWidth *=2;
90 dwHeight--;
91
92 if(dwWidth == dwPitch)
93 {
94 // Width = Pitch => fill buffer so no need to take care of lines
95 memcpy(pDst+dwPitch, pDst, dwWidth*dwHeight);
96 }
97 else
98 {
99 pFillPos = pDst+dwPitch;
100 while(dwHeight)
101 {
102 memcpy(pFillPos,pDst,dwWidth);
103 pFillPos += dwPitch;
104 dwHeight--;
105 }
106 }
107}
108void __cdecl Fill24( char* pDst,
109 DWORD dwWidth,
110 DWORD dwHeight,
111 DWORD dwPitch,
112 DWORD dwColor)
113{
114 DWORD *pColor;
115 char *pFillPos;
116 int i;
117 dprintf(("DDRAW:Fill24 with %08X \n",dwColor));
118
119 // First Fill First row with the color
120
121 for(i=0 ; i<dwWidth ; i++)
122 {
123 pColor = (DWORD*)(pDst+(i*3));
124 *pColor = dwColor;
125 }
126 dwWidth *=3;
127 dwHeight--;
128
129 if(dwWidth == dwPitch)
130 {
131 // Width = Pitch => fill buffer so no need to take care of lines
132 memcpy(pDst+dwPitch, pDst, dwWidth*dwHeight);
133 }
134 else
135 {
136 pFillPos = pDst+dwPitch;
137 while(dwHeight)
138 {
139 memcpy(pFillPos,pDst,dwWidth);
140 pFillPos += dwPitch;
141 dwHeight--;
142 }
143 }
144}
145
146void __cdecl Fill32( char* pDst,
147 DWORD dwWidth,
148 DWORD dwHeight,
149 DWORD dwPitch,
150 DWORD dwColor)
151{
152 DWORD *pColor;
153 char *pFillPos;
154 int i;
155 dprintf(("DDRAW:Fill24 with %08X \n",dwColor));
156
157 // First Fill First row with the color
158
159 for(i=0 ; i<dwWidth ; i++)
160 {
161 pColor[i] = dwColor;
162 }
163 dwWidth *=4;
164 dwHeight--;
165
166 if(dwWidth == dwPitch)
167 {
168 // Width = Pitch => fill buffer so no need to take care of lines
169 memcpy(pDst+dwPitch, pDst, dwWidth*dwHeight);
170 }
171 else
172 {
173 pFillPos = pDst+dwPitch;
174 while(dwHeight)
175 {
176 memcpy(pFillPos,pDst,dwWidth);
177 pFillPos += dwPitch;
178 dwHeight--;
179 }
180 }
181}
182#else
183 #define Fill8 Fill8ASM
184 #define Fill16 Fill16ASM
185 #define Fill24 Fill24ASM
186 #define Fill32 Fill32ASM
187#endif
188
189
190
191// without ColorConversion
192 void __cdecl Fill8on8( char *pDB,
193 char *pFB,
194 DWORD dwTop,
195 DWORD dwLeft,
196 DWORD dwWidth,
197 DWORD dwHeight,
198 DWORD dwPitchDB,
199 DWORD dwPitchFB,
200 DWORD dwColor,
201 VOID *pPalette
202 )
203{
204 dprintf(("Fill8on8\n"));
205 dwColor = (dwColor&0xFF)+(dwColor&0xFF<<8);
206 dwColor += (dwColor<<16);
207
208 Fill8( pDB+(dwTop*dwPitchDB)+dwLeft,
209 dwWidth,
210 dwHeight,
211 dwPitchDB,
212 dwColor);
213}
214 void __cdecl Fill16on16( char *pDB,
215 char *pFB,
216 DWORD dwTop,
217 DWORD dwLeft,
218 DWORD dwWidth,
219 DWORD dwHeight,
220 DWORD dwPitchDB,
221 DWORD dwPitchFB,
222 DWORD dwColor,
223 VOID *pPalette
224 )
225{
226 dprintf(("Fill16on16 %x (%d,%d)(%d,%d) %d %x", pDB+(dwTop*dwPitchDB)+(dwLeft*2), dwLeft, dwTop, dwWidth, dwHeight, dwPitchDB, dwColor));
227 dwColor = (dwColor&0xFFFF)+((dwColor&0xFFFF)<<16);
228
229 Fill16( pDB+(dwTop*dwPitchDB)+(dwLeft*2),
230 dwWidth,
231 dwHeight,
232 dwPitchDB,
233 dwColor);
234}
235 void __cdecl Fill24on24( char *pDB,
236 char *pFB,
237 DWORD dwTop,
238 DWORD dwLeft,
239 DWORD dwWidth,
240 DWORD dwHeight,
241 DWORD dwPitchDB,
242 DWORD dwPitchFB,
243 DWORD dwColor,
244 VOID *pPalette
245 )
246{
247 dprintf(("Fill24on24\n"));
248 dwColor <<= 8;
249
250 Fill24( pDB+(dwTop*dwPitchDB)+(dwLeft*3),
251 dwWidth,
252 dwHeight,
253 dwPitchDB,
254 dwColor);
255
256}
257 void __cdecl Fill32on32( char *pDB,
258 char *pFB,
259 DWORD dwTop,
260 DWORD dwLeft,
261 DWORD dwWidth,
262 DWORD dwHeight,
263 DWORD dwPitchDB,
264 DWORD dwPitchFB,
265 DWORD dwColor,
266 VOID *pPalette
267 )
268{
269 dprintf(("Fill32on32\n"));
270 Fill32( pDB+(dwTop*dwPitchDB)+(dwLeft*4),
271 dwWidth,
272 dwHeight,
273 dwPitchDB,
274 dwColor);
275}
276
277 void __cdecl Fill8on16( char *pDB,
278 char *pFB,
279 DWORD dwTop,
280 DWORD dwLeft,
281 DWORD dwWidth,
282 DWORD dwHeight,
283 DWORD dwPitchDB,
284 DWORD dwPitchFB,
285 DWORD dwColor,
286 VOID *pPalette
287 )
288{
289 DWORD dwCol;
290 dprintf(("Fill8on16\n"));
291 dwCol = (dwColor&0xFF)+(dwColor&0xFF<<8);
292 dwCol += (dwCol<<16);
293
294 Fill8( pFB+(dwTop*dwPitchFB)+dwLeft,
295 dwWidth,
296 dwHeight,
297 dwPitchFB,
298 dwCol);
299
300 dwCol = ((WORD*)pPalette)[dwColor];
301 dwCol += (dwCol<<16);
302 Fill16( pDB+(dwTop*dwPitchDB)+(dwLeft*2),
303 dwWidth,
304 dwHeight,
305 dwPitchDB,
306 dwCol);
307}
308
309 void __cdecl Fill8on24( char *pDB,
310 char *pFB,
311 DWORD dwTop,
312 DWORD dwLeft,
313 DWORD dwWidth,
314 DWORD dwHeight,
315 DWORD dwPitchDB,
316 DWORD dwPitchFB,
317 DWORD dwColor,
318 VOID *pPalette
319 )
320{
321 DWORD dwCol;
322 dprintf(("Fill8on24\n"));
323 dwCol = (dwColor&0xFF)+(dwColor&0xFF<<8);
324 dwCol += (dwCol<<16);
325
326 Fill8( pFB+(dwTop*dwPitchFB)+dwLeft,
327 dwWidth,
328 dwHeight,
329 dwPitchFB,
330 dwCol);
331
332 dwCol = ((DWORD*)pPalette)[dwColor];
333 //dwCol <<= 8;
334 Fill24( pDB+(dwTop*dwPitchDB)+(dwLeft*3),
335 dwWidth,
336 dwHeight,
337 dwPitchDB,
338 dwCol);
339}
340 void __cdecl Fill8on32( char *pDB,
341 char *pFB,
342 DWORD dwTop,
343 DWORD dwLeft,
344 DWORD dwWidth,
345 DWORD dwHeight,
346 DWORD dwPitchDB,
347 DWORD dwPitchFB,
348 DWORD dwColor,
349 VOID *pPalette
350 )
351{
352 DWORD dwCol;
353 dprintf(("Fill8on32\n"));
354 dwCol = (dwColor&0xFF)+(dwColor&0xFF<<8);
355 dwCol += (dwCol<<16);
356
357 Fill8( pFB+(dwTop*dwPitchFB)+dwLeft,
358 dwWidth,
359 dwHeight,
360 dwPitchFB,
361 dwCol);
362
363 dwCol = ((DWORD*)pPalette)[dwColor];
364 Fill32( pDB+(dwTop*dwPitchDB)+(dwLeft*4),
365 dwWidth,
366 dwHeight,
367 dwPitchDB,
368 dwCol);
369}
370 void __cdecl Fill16on8( char *pDB,
371 char *pFB,
372 DWORD dwTop,
373 DWORD dwLeft,
374 DWORD dwWidth,
375 DWORD dwHeight,
376 DWORD dwPitchDB,
377 DWORD dwPitchFB,
378 DWORD dwColor,
379 VOID *pPalette
380 )
381{
382 dprintf(("Fill16on8 NOT Implemented \n"));
383}
384 void __cdecl Fill16on24( char *pDB,
385 char *pFB,
386 DWORD dwTop,
387 DWORD dwLeft,
388 DWORD dwWidth,
389 DWORD dwHeight,
390 DWORD dwPitchDB,
391 DWORD dwPitchFB,
392 DWORD dwColor,
393 VOID *pPalette
394 )
395{
396 DWORD dwCol;
397 dprintf(("Fill16on24\n"));
398 dwCol = dwColor + (dwColor<<16);
399
400 Fill16( pFB+(dwTop*dwPitchFB)+(dwLeft*2),
401 dwWidth,
402 dwHeight,
403 dwPitchFB,
404 dwCol);
405
406 dwCol = ((dwColor & 0xF800)<< 16) +
407 ((dwColor & 0x07E0)<< 13) +
408 ((dwColor & 0x001F)<< 11);
409 Fill24( pDB+(dwTop*dwPitchDB)+(dwLeft*2),
410 dwWidth,
411 dwHeight,
412 dwPitchDB,
413 dwCol);
414}
415 void __cdecl Fill16on32( char *pDB,
416 char *pFB,
417 DWORD dwTop,
418 DWORD dwLeft,
419 DWORD dwWidth,
420 DWORD dwHeight,
421 DWORD dwPitchDB,
422 DWORD dwPitchFB,
423 DWORD dwColor,
424 VOID *pPalette
425 )
426{
427 DWORD dwCol;
428 dprintf(("Fill16on32\n"));
429 dwCol = dwColor + (dwColor<<16);
430
431 Fill16( pFB+(dwTop*dwPitchFB)+(dwLeft*2),
432 dwWidth,
433 dwHeight,
434 dwPitchFB,
435 dwCol);
436
437 dwCol = ((dwColor & 0xF800)<< 16) +
438 ((dwColor & 0x07E0)<< 13) +
439 ((dwColor & 0x001F)<< 11);
440 Fill32( pDB+(dwTop*dwPitchDB)+(dwLeft*4),
441 dwWidth,
442 dwHeight,
443 dwPitchDB,
444 dwCol);
445}
446
447 void __cdecl Fill24on8( char *pDB,
448 char *pFB,
449 DWORD dwTop,
450 DWORD dwLeft,
451 DWORD dwWidth,
452 DWORD dwHeight,
453 DWORD dwPitchDB,
454 DWORD dwPitchFB,
455 DWORD dwColor,
456 VOID *pPalette
457 )
458{
459 dprintf(("Fill24on8 NOT implemented\n"));
460}
461 void __cdecl Fill24on16( char *pDB,
462 char *pFB,
463 DWORD dwTop,
464 DWORD dwLeft,
465 DWORD dwWidth,
466 DWORD dwHeight,
467 DWORD dwPitchDB,
468 DWORD dwPitchFB,
469 DWORD dwColor,
470 VOID *pPalette
471 )
472{
473 DWORD dwCol;
474 dprintf(("Fill24on16\n"));
475 //dwColor <<=8;
476
477 Fill24( pFB+(dwTop*dwPitchFB)+(dwLeft*3),
478 dwWidth,
479 dwHeight,
480 dwPitchFB,
481 dwColor);
482
483 dwCol = ((dwColor & 0xF8000000) >>16) +
484 ((dwColor & 0x00FE0000)>> 13) +
485 ((dwColor & 0x0000F800)>> 11);
486
487 dwCol = dwCol + (dwCol<<16);
488 Fill16( pDB+(dwTop*dwPitchDB)+(dwLeft*2),
489 dwWidth,
490 dwHeight,
491 dwPitchDB,
492 dwCol);
493}
494 void __cdecl Fill24on32( char *pDB,
495 char *pFB,
496 DWORD dwTop,
497 DWORD dwLeft,
498 DWORD dwWidth,
499 DWORD dwHeight,
500 DWORD dwPitchDB,
501 DWORD dwPitchFB,
502 DWORD dwColor,
503 VOID *pPalette
504 )
505{
506 dprintf(("Fill24on32\n"));
507 //dwColor <<=8;
508
509 Fill24( pFB+(dwTop*dwPitchFB)+(dwLeft*3),
510 dwWidth,
511 dwHeight,
512 dwPitchFB,
513 dwColor);
514 Fill32( pDB+(dwTop*dwPitchDB)+(dwLeft*4),
515 dwWidth,
516 dwHeight,
517 dwPitchDB,
518 dwColor);
519}
520 void __cdecl Fill32on8( char *pDB,
521 char *pFB,
522 DWORD dwTop,
523 DWORD dwLeft,
524 DWORD dwWidth,
525 DWORD dwHeight,
526 DWORD dwPitchDB,
527 DWORD dwPitchFB,
528 DWORD dwColor,
529 VOID *pPalette
530 )
531{
532 dprintf(("Fill32on8 NOT implemented\n"));
533}
534 void __cdecl Fill32on16( char *pDB,
535 char *pFB,
536 DWORD dwTop,
537 DWORD dwLeft,
538 DWORD dwWidth,
539 DWORD dwHeight,
540 DWORD dwPitchDB,
541 DWORD dwPitchFB,
542 DWORD dwColor,
543 VOID *pPalette
544 )
545{
546 DWORD dwCol;
547 dprintf(("Fill32on16\n"));
548
549 Fill32( pFB+(dwTop*dwPitchFB)+(dwLeft*4),
550 dwWidth,
551 dwHeight,
552 dwPitchFB,
553 dwColor);
554
555 dwCol = ((dwColor & 0xF8000000) >>16) +
556 ((dwColor & 0x00FE0000)>> 13) +
557 ((dwColor & 0x0000F800)>> 11);
558
559 dwCol = dwCol + (dwCol<<16);
560 Fill16( pDB+(dwTop*dwPitchDB)+(dwLeft*2),
561 dwWidth,
562 dwHeight,
563 dwPitchDB,
564 dwCol);
565}
566 void __cdecl Fill32on24( char *pDB,
567 char *pFB,
568 DWORD dwTop,
569 DWORD dwLeft,
570 DWORD dwWidth,
571 DWORD dwHeight,
572 DWORD dwPitchDB,
573 DWORD dwPitchFB,
574 DWORD dwColor,
575 VOID *pPalette
576 )
577{
578 dprintf(("Fill32on24\n"));
579 Fill32( pFB+(dwTop*dwPitchFB)+(dwLeft*4),
580 dwWidth,
581 dwHeight,
582 dwPitchFB,
583 dwColor);
584
585 Fill24( pDB+(dwTop*dwPitchDB)+(dwLeft*3),
586 dwWidth,
587 dwHeight,
588 dwPitchDB,
589 dwColor);
590}
591
Note: See TracBrowser for help on using the repository browser.