Identation corrected, many fixes and minor improvements, initial DIB support
[reactos.git] / reactos / subsys / win32k / dib / dib24bpp.c
1 #undef WIN32_LEAN_AND_MEAN
2 #include <windows.h>
3 #include <stdlib.h>
4 #include <win32k/bitmaps.h>
5 #include <win32k/debug.h>
6 #include <debug.h>
7 #include <ddk/winddi.h>
8 #include "..\eng\objects.h"
9 #include "dib.h"
10
11 VOID DIB_24BPP_PutPixel(PSURFOBJ SurfObj, LONG x, LONG y, RGBTRIPLE c)
12 {
13 PBYTE byteaddr = SurfObj->pvBits + y * SurfObj->lDelta;
14 PRGBTRIPLE addr = (PRGBTRIPLE)byteaddr + x;
15
16 *addr = c;
17 }
18
19 RGBTRIPLE DIB_24BPP_GetPixel(PSURFOBJ SurfObj, LONG x, LONG y)
20 {
21 PBYTE byteaddr = SurfObj->pvBits + y * SurfObj->lDelta;
22 PRGBTRIPLE addr = (PRGBTRIPLE)byteaddr + x;
23
24 return *addr;
25 }
26
27 VOID DIB_24BPP_HLine(PSURFOBJ SurfObj, LONG x1, LONG x2, LONG y, RGBTRIPLE c)
28 {
29 PBYTE byteaddr = SurfObj->pvBits + y * SurfObj->lDelta;
30 PRGBTRIPLE addr = (PRGBTRIPLE)byteaddr + x1;
31 LONG cx = x1;
32
33 while(cx <= x2) {
34 *addr = c;
35 ++addr;
36 ++cx;
37 }
38 }
39
40 VOID DIB_24BPP_VLine(PSURFOBJ SurfObj, LONG x, LONG y1, LONG y2, RGBTRIPLE c)
41 {
42 PBYTE byteaddr = SurfObj->pvBits + y1 * SurfObj->lDelta;
43 PRGBTRIPLE addr = (PRGBTRIPLE)byteaddr + x;
44 ULONG lDelta = SurfObj->lDelta;
45
46 byteaddr = (PBYTE)addr;
47 while(y1++ <= y2) {
48 *addr = c;
49
50 byteaddr += lDelta;
51 addr = (PRGBTRIPLE)byteaddr;
52 }
53 }
54
55 VOID DIB_24BPP_BltTo_24BPP(PSURFOBJ dstpsd, LONG dstx, LONG dsty, LONG w, LONG h,
56 PSURFOBJ srcpsd, LONG srcx, LONG srcy)
57 {
58 PRGBTRIPLE dst;
59 PRGBTRIPLE src;
60 PBYTE bytedst;
61 PBYTE bytesrc;
62 int i;
63 int dlDelta = dstpsd->lDelta;
64 int slDelta = srcpsd->lDelta;
65
66 bytedst = (char *)dstpsd->pvBits + dsty * dlDelta;
67 bytesrc = (char *)srcpsd->pvBits + srcy * slDelta;
68 dst = (PRGBTRIPLE)bytedst + dstx;
69 src = (PRGBTRIPLE)bytesrc + srcx;
70
71 while(--h >= 0) {
72 PRGBTRIPLE d = dst;
73 PRGBTRIPLE s = src;
74 LONG dx = dstx;
75 LONG sx = srcx;
76 for(i=0; i<w; ++i) {
77 *d = *s;
78 ++d;
79 ++s;
80 }
81 dst += dlDelta;
82 src += slDelta;
83 }
84 }
85
86 BOOLEAN DIB_To_24BPP_Bitblt( SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
87 SURFGDI *DestGDI, SURFGDI *SourceGDI,
88 PRECTL DestRect, POINTL *SourcePoint,
89 ULONG Delta, XLATEOBJ *ColorTranslation)
90 {
91 ULONG i, j, sx, xColor, f1;
92 PBYTE DestBits, SourceBits_24BPP, DestLine, SourceLine_24BPP;
93 PRGBTRIPLE SPDestBits, SPSourceBits_24BPP, SPDestLine, SPSourceLine_24BPP; // specially for 24-to-24 blit
94 PBYTE SourceBits_4BPP, SourceBits_8BPP, SourceLine_4BPP, SourceLine_8BPP;
95 PWORD SourceBits_16BPP, SourceLine_16BPP;
96 PDWORD SourceBits_32BPP, SourceLine_32BPP;
97
98 DestBits = DestSurf->pvBits + (DestRect->top * DestSurf->lDelta) + DestRect->left * 3;
99
100 switch(SourceGDI->BitsPerPixel)
101 {
102 case 4:
103 SourceBits_4BPP = SourceSurf->pvBits + (SourcePoint->y * SourceSurf->lDelta) + SourcePoint->x;
104
105 for (j=DestRect->top; j<DestRect->bottom; j++)
106 {
107 SourceLine_4BPP = SourceBits_4BPP;
108 DestLine = DestBits;
109 sx = SourcePoint->x;
110 f1 = sx & 1;
111
112 for (i=DestRect->left; i<DestRect->right; i++)
113 {
114 xColor = XLATEOBJ_iXlate(ColorTranslation,
115 (*SourceLine_4BPP & altnotmask[sx&1]) >> (4 * (1-(sx & 1))));
116 *DestLine++ = xColor & 0xff;
117 *(PWORD)DestLine = xColor >> 8;
118 DestLine += 2;
119 if(f1 == 1) { SourceLine_4BPP++; f1 = 0; } else { f1 = 1; }
120 sx++;
121 }
122
123 SourceBits_4BPP += SourceSurf->lDelta;
124 DestBits += DestSurf->lDelta;
125 }
126 break;
127
128 default:
129 DbgPrint("DIB_24BPP_Bitblt: Unhandled Source BPP: %u\n", SourceGDI->BitsPerPixel);
130 return FALSE;
131 }
132
133 return TRUE;
134 }