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

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

fill, SurfGetDC, SurfReleaseDC fixes & changes (see ChangeLog for details)

File size: 14.9 KB
Line 
1/* $Id: fillfunc.cpp,v 1.6 2002-07-01 19:15:26 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
228 dwColor = MAKE_RGB565(dwColor);
229 dwColor = (dwColor&0xFFFF)+((dwColor&0xFFFF)<<16);
230
231 Fill16( pDB+(dwTop*dwPitchDB)+(dwLeft*2),
232 dwWidth,
233 dwHeight,
234 dwPitchDB,
235 dwColor);
236}
237 void __cdecl Fill24on24( char *pDB,
238 char *pFB,
239 DWORD dwTop,
240 DWORD dwLeft,
241 DWORD dwWidth,
242 DWORD dwHeight,
243 DWORD dwPitchDB,
244 DWORD dwPitchFB,
245 DWORD dwColor,
246 VOID *pPalette
247 )
248{
249 dprintf(("Fill24on24\n"));
250 dwColor <<= 8;
251
252 Fill24( pDB+(dwTop*dwPitchDB)+(dwLeft*3),
253 dwWidth,
254 dwHeight,
255 dwPitchDB,
256 dwColor);
257
258}
259 void __cdecl Fill32on32( char *pDB,
260 char *pFB,
261 DWORD dwTop,
262 DWORD dwLeft,
263 DWORD dwWidth,
264 DWORD dwHeight,
265 DWORD dwPitchDB,
266 DWORD dwPitchFB,
267 DWORD dwColor,
268 VOID *pPalette
269 )
270{
271 dprintf(("Fill32on32\n"));
272 Fill32( pDB+(dwTop*dwPitchDB)+(dwLeft*4),
273 dwWidth,
274 dwHeight,
275 dwPitchDB,
276 dwColor);
277}
278
279 void __cdecl Fill8on16( char *pDB,
280 char *pFB,
281 DWORD dwTop,
282 DWORD dwLeft,
283 DWORD dwWidth,
284 DWORD dwHeight,
285 DWORD dwPitchDB,
286 DWORD dwPitchFB,
287 DWORD dwColor,
288 VOID *pPalette
289 )
290{
291 DWORD dwCol;
292 dprintf(("Fill8on16\n"));
293 dwCol = (dwColor&0xFF)+(dwColor&0xFF<<8);
294 dwCol += (dwCol<<16);
295
296 Fill8( pFB+(dwTop*dwPitchFB)+dwLeft,
297 dwWidth,
298 dwHeight,
299 dwPitchFB,
300 dwCol);
301
302 dwCol = ((WORD*)pPalette)[dwColor];
303 dwCol += (dwCol<<16);
304 Fill16( pDB+(dwTop*dwPitchDB)+(dwLeft*2),
305 dwWidth,
306 dwHeight,
307 dwPitchDB,
308 dwCol);
309}
310
311 void __cdecl Fill8on24( char *pDB,
312 char *pFB,
313 DWORD dwTop,
314 DWORD dwLeft,
315 DWORD dwWidth,
316 DWORD dwHeight,
317 DWORD dwPitchDB,
318 DWORD dwPitchFB,
319 DWORD dwColor,
320 VOID *pPalette
321 )
322{
323 DWORD dwCol;
324 dprintf(("Fill8on24\n"));
325 dwCol = (dwColor&0xFF)+(dwColor&0xFF<<8);
326 dwCol += (dwCol<<16);
327
328 Fill8( pFB+(dwTop*dwPitchFB)+dwLeft,
329 dwWidth,
330 dwHeight,
331 dwPitchFB,
332 dwCol);
333
334 dwCol = ((DWORD*)pPalette)[dwColor];
335 //dwCol <<= 8;
336 Fill24( pDB+(dwTop*dwPitchDB)+(dwLeft*3),
337 dwWidth,
338 dwHeight,
339 dwPitchDB,
340 dwCol);
341}
342 void __cdecl Fill8on32( char *pDB,
343 char *pFB,
344 DWORD dwTop,
345 DWORD dwLeft,
346 DWORD dwWidth,
347 DWORD dwHeight,
348 DWORD dwPitchDB,
349 DWORD dwPitchFB,
350 DWORD dwColor,
351 VOID *pPalette
352 )
353{
354 DWORD dwCol;
355 dprintf(("Fill8on32\n"));
356 dwCol = (dwColor&0xFF)+(dwColor&0xFF<<8);
357 dwCol += (dwCol<<16);
358
359 Fill8( pFB+(dwTop*dwPitchFB)+dwLeft,
360 dwWidth,
361 dwHeight,
362 dwPitchFB,
363 dwCol);
364
365 dwCol = ((DWORD*)pPalette)[dwColor];
366 Fill32( pDB+(dwTop*dwPitchDB)+(dwLeft*4),
367 dwWidth,
368 dwHeight,
369 dwPitchDB,
370 dwCol);
371}
372 void __cdecl Fill16on8( char *pDB,
373 char *pFB,
374 DWORD dwTop,
375 DWORD dwLeft,
376 DWORD dwWidth,
377 DWORD dwHeight,
378 DWORD dwPitchDB,
379 DWORD dwPitchFB,
380 DWORD dwColor,
381 VOID *pPalette
382 )
383{
384 dprintf(("Fill16on8 NOT Implemented \n"));
385}
386 void __cdecl Fill16on24( char *pDB,
387 char *pFB,
388 DWORD dwTop,
389 DWORD dwLeft,
390 DWORD dwWidth,
391 DWORD dwHeight,
392 DWORD dwPitchDB,
393 DWORD dwPitchFB,
394 DWORD dwColor,
395 VOID *pPalette
396 )
397{
398 DWORD dwCol;
399 dprintf(("Fill16on24\n"));
400 dwCol = dwColor + (dwColor<<16);
401
402 Fill16( pFB+(dwTop*dwPitchFB)+(dwLeft*2),
403 dwWidth,
404 dwHeight,
405 dwPitchFB,
406 dwCol);
407
408 dwCol = ((dwColor & 0xF800)<< 16) +
409 ((dwColor & 0x07E0)<< 13) +
410 ((dwColor & 0x001F)<< 11);
411 Fill24( pDB+(dwTop*dwPitchDB)+(dwLeft*2),
412 dwWidth,
413 dwHeight,
414 dwPitchDB,
415 dwCol);
416}
417 void __cdecl Fill16on32( char *pDB,
418 char *pFB,
419 DWORD dwTop,
420 DWORD dwLeft,
421 DWORD dwWidth,
422 DWORD dwHeight,
423 DWORD dwPitchDB,
424 DWORD dwPitchFB,
425 DWORD dwColor,
426 VOID *pPalette
427 )
428{
429 DWORD dwCol;
430 dprintf(("Fill16on32\n"));
431 dwCol = dwColor + (dwColor<<16);
432
433 Fill16( pFB+(dwTop*dwPitchFB)+(dwLeft*2),
434 dwWidth,
435 dwHeight,
436 dwPitchFB,
437 dwCol);
438
439 dwCol = ((dwColor & 0xF800)<< 16) +
440 ((dwColor & 0x07E0)<< 13) +
441 ((dwColor & 0x001F)<< 11);
442 Fill32( pDB+(dwTop*dwPitchDB)+(dwLeft*4),
443 dwWidth,
444 dwHeight,
445 dwPitchDB,
446 dwCol);
447}
448
449 void __cdecl Fill24on8( char *pDB,
450 char *pFB,
451 DWORD dwTop,
452 DWORD dwLeft,
453 DWORD dwWidth,
454 DWORD dwHeight,
455 DWORD dwPitchDB,
456 DWORD dwPitchFB,
457 DWORD dwColor,
458 VOID *pPalette
459 )
460{
461 dprintf(("Fill24on8 NOT implemented\n"));
462}
463 void __cdecl Fill24on16( char *pDB,
464 char *pFB,
465 DWORD dwTop,
466 DWORD dwLeft,
467 DWORD dwWidth,
468 DWORD dwHeight,
469 DWORD dwPitchDB,
470 DWORD dwPitchFB,
471 DWORD dwColor,
472 VOID *pPalette
473 )
474{
475 DWORD dwCol;
476 dprintf(("Fill24on16\n"));
477 //dwColor <<=8;
478
479 Fill24( pFB+(dwTop*dwPitchFB)+(dwLeft*3),
480 dwWidth,
481 dwHeight,
482 dwPitchFB,
483 dwColor);
484
485 dwCol = ((dwColor & 0xF8000000) >>16) +
486 ((dwColor & 0x00FE0000)>> 13) +
487 ((dwColor & 0x0000F800)>> 11);
488
489 dwCol = dwCol + (dwCol<<16);
490 Fill16( pDB+(dwTop*dwPitchDB)+(dwLeft*2),
491 dwWidth,
492 dwHeight,
493 dwPitchDB,
494 dwCol);
495}
496 void __cdecl Fill24on32( char *pDB,
497 char *pFB,
498 DWORD dwTop,
499 DWORD dwLeft,
500 DWORD dwWidth,
501 DWORD dwHeight,
502 DWORD dwPitchDB,
503 DWORD dwPitchFB,
504 DWORD dwColor,
505 VOID *pPalette
506 )
507{
508 dprintf(("Fill24on32\n"));
509 //dwColor <<=8;
510
511 Fill24( pFB+(dwTop*dwPitchFB)+(dwLeft*3),
512 dwWidth,
513 dwHeight,
514 dwPitchFB,
515 dwColor);
516 Fill32( pDB+(dwTop*dwPitchDB)+(dwLeft*4),
517 dwWidth,
518 dwHeight,
519 dwPitchDB,
520 dwColor);
521}
522 void __cdecl Fill32on8( char *pDB,
523 char *pFB,
524 DWORD dwTop,
525 DWORD dwLeft,
526 DWORD dwWidth,
527 DWORD dwHeight,
528 DWORD dwPitchDB,
529 DWORD dwPitchFB,
530 DWORD dwColor,
531 VOID *pPalette
532 )
533{
534 dprintf(("Fill32on8 NOT implemented\n"));
535}
536 void __cdecl Fill32on16( char *pDB,
537 char *pFB,
538 DWORD dwTop,
539 DWORD dwLeft,
540 DWORD dwWidth,
541 DWORD dwHeight,
542 DWORD dwPitchDB,
543 DWORD dwPitchFB,
544 DWORD dwColor,
545 VOID *pPalette
546 )
547{
548 DWORD dwCol;
549 dprintf(("Fill32on16\n"));
550
551 Fill32( pFB+(dwTop*dwPitchFB)+(dwLeft*4),
552 dwWidth,
553 dwHeight,
554 dwPitchFB,
555 dwColor);
556
557 dwCol = ((dwColor & 0xF8000000) >>16) +
558 ((dwColor & 0x00FE0000)>> 13) +
559 ((dwColor & 0x0000F800)>> 11);
560
561 dwCol = dwCol + (dwCol<<16);
562 Fill16( pDB+(dwTop*dwPitchDB)+(dwLeft*2),
563 dwWidth,
564 dwHeight,
565 dwPitchDB,
566 dwCol);
567}
568 void __cdecl Fill32on24( char *pDB,
569 char *pFB,
570 DWORD dwTop,
571 DWORD dwLeft,
572 DWORD dwWidth,
573 DWORD dwHeight,
574 DWORD dwPitchDB,
575 DWORD dwPitchFB,
576 DWORD dwColor,
577 VOID *pPalette
578 )
579{
580 dprintf(("Fill32on24\n"));
581 Fill32( pFB+(dwTop*dwPitchFB)+(dwLeft*4),
582 dwWidth,
583 dwHeight,
584 dwPitchFB,
585 dwColor);
586
587 Fill24( pDB+(dwTop*dwPitchDB)+(dwLeft*3),
588 dwWidth,
589 dwHeight,
590 dwPitchDB,
591 dwColor);
592}
593
Note: See TracBrowser for help on using the repository browser.