source: trunk/src/ddraw/fillfunc.cpp

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

MoveRect fixes (src & dest surfaces the same + overlap); fill fixes + optimizations

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