Initial commit - from Precise source
[freerdp-ubuntu-pcb-backport.git] / libfreerdp-gdi / 8bpp.c
1 /**
2  * FreeRDP: A Remote Desktop Protocol Client
3  * GDI 8bpp Internal Buffer Routines
4  *
5  * Copyright 2010-2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 #include <stdio.h>
21 #include <string.h>
22 #include <stdlib.h>
23 #include <freerdp/api.h>
24 #include <freerdp/freerdp.h>
25 #include <freerdp/gdi/gdi.h>
26 #include <freerdp/codec/color.h>
27
28 #include <freerdp/gdi/pen.h>
29 #include <freerdp/gdi/bitmap.h>
30 #include <freerdp/gdi/region.h>
31 #include <freerdp/gdi/clipping.h>
32 #include <freerdp/gdi/drawing.h>
33
34 #include <freerdp/gdi/8bpp.h>
35
36 int FillRect_8bpp(HGDI_DC hdc, HGDI_RECT rect, HGDI_BRUSH hbr)
37 {
38         /* TODO: Implement 8bpp FillRect() */
39         return 0;
40 }
41
42 static int BitBlt_BLACKNESS_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight)
43 {
44         int y;
45         uint8* dstp;
46
47         for (y = 0; y < nHeight; y++)
48         {
49                 dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y);
50
51                 if (dstp != 0)
52                         memset(dstp, 0, nWidth * hdcDest->bytesPerPixel);
53         }
54
55         return 0;
56 }
57
58 static int BitBlt_WHITENESS_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight)
59 {
60         int y;
61         uint8* dstp;
62         
63         for (y = 0; y < nHeight; y++)
64         {
65                 dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y);
66
67                 if (dstp != 0)
68                         memset(dstp, 0xFF, nWidth * hdcDest->bytesPerPixel);
69         }
70
71         return 0;
72 }
73
74 static int BitBlt_SRCCOPY_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc)
75 {
76         int y;
77         uint8* srcp;
78         uint8* dstp;
79
80         if ((hdcDest->selectedObject != hdcSrc->selectedObject) ||
81             gdi_CopyOverlap(nXDest, nYDest, nWidth, nHeight, nXSrc, nYSrc) == 0)
82         {
83                 for (y = 0; y < nHeight; y++)
84                 {
85                         srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
86                         dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y);
87
88                         if (srcp != 0 && dstp != 0)
89                                 memcpy(dstp, srcp, nWidth * hdcDest->bytesPerPixel);
90                 }
91
92                 return 0;
93         }
94         
95         if (nYSrc < nYDest)
96         {
97                 /* copy down (bottom to top) */
98                 for (y = nHeight - 1; y >= 0; y--)
99                 {
100                         srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
101                         dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y);
102
103                         if (srcp != 0 && dstp != 0)
104                                 memmove(dstp, srcp, nWidth * hdcDest->bytesPerPixel);
105                 }
106         }
107         else if (nYSrc > nYDest || nXSrc > nXDest)
108         {
109                 /* copy up or left (top top bottom) */
110                 for (y = 0; y < nHeight; y++)
111                 {
112                         srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
113                         dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y);
114
115                         if (srcp != 0 && dstp != 0)
116                                 memmove(dstp, srcp, nWidth * hdcDest->bytesPerPixel);
117                 }
118         }
119         else
120         {
121                 /* copy straight right */
122                 for (y = 0; y < nHeight; y++)
123                 {
124                         srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
125                         dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y);
126
127                         if (srcp != 0 && dstp != 0)
128                                 memmove(dstp, srcp, nWidth * hdcDest->bytesPerPixel);
129                 }
130         }
131         
132         return 0;
133 }
134
135 static int BitBlt_NOTSRCCOPY_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc)
136 {
137         int x, y;
138         uint8* srcp;
139         uint8* dstp;
140         
141         for (y = 0; y < nHeight; y++)
142         {
143                 srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
144                 dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y);
145
146                 if (dstp != 0)
147                 {
148                         for (x = 0; x < nWidth; x++)
149                         {
150                                 *dstp = ~(*srcp);
151                                 srcp++;
152                                 dstp++;
153                         }
154                 }
155         }
156
157         return 0;
158 }
159
160 static int BitBlt_DSTINVERT_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight)
161 {
162         int x, y;
163         uint8* dstp;
164                 
165         for (y = 0; y < nHeight; y++)
166         {
167                 dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y);
168
169                 if (dstp != 0)
170                 {
171                         for (x = 0; x < nWidth; x++)
172                         {
173                                 *dstp = ~(*dstp);
174                                 dstp++;
175                         }
176                 }
177         }
178
179         return 0;
180 }
181
182 static int BitBlt_SRCERASE_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc)
183 {
184         int x, y;
185         uint8* srcp;
186         uint8* dstp;
187                 
188         for (y = 0; y < nHeight; y++)
189         {
190                 srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
191                 dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y);
192
193                 if (dstp != 0)
194                 {
195                         for (x = 0; x < nWidth; x++)
196                         {
197                                 *dstp = *srcp & ~(*dstp);
198                                 srcp++;
199                                 dstp++;
200                         }
201                 }
202         }
203
204         return 0;
205 }
206
207 static int BitBlt_NOTSRCERASE_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc)
208 {
209         int x, y;
210         uint8* srcp;
211         uint8* dstp;
212                 
213         for (y = 0; y < nHeight; y++)
214         {
215                 srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
216                 dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y);
217
218                 if (dstp != 0)
219                 {
220                         for (x = 0; x < nWidth; x++)
221                         {
222                                 *dstp = ~(*srcp) & ~(*dstp);
223                                 srcp++;
224                                 dstp++;
225                         }
226                 }
227         }
228
229         return 0;
230 }
231
232 static int BitBlt_SRCINVERT_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc)
233 {
234         int x, y;
235         uint8* srcp;
236         uint8* dstp;
237                 
238         for (y = 0; y < nHeight; y++)
239         {
240                 srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
241                 dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y);
242
243                 if (dstp != 0)
244                 {
245                         for (x = 0; x < nWidth; x++)
246                         {
247                                 *dstp ^= *srcp;
248                                 srcp++;
249                                 dstp++;
250                         }
251                 }
252         }
253
254         return 0;
255 }
256
257 static int BitBlt_SRCAND_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc)
258 {
259         int x, y;
260         uint8* srcp;
261         uint8* dstp;
262                 
263         for (y = 0; y < nHeight; y++)
264         {
265                 srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
266                 dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y);
267
268                 if (dstp != 0)
269                 {
270                         for (x = 0; x < nWidth; x++)
271                         {
272                                 *dstp &= *srcp;
273                                 srcp++;
274                                 dstp++;
275                         }
276                 }
277         }
278
279         return 0;
280 }
281
282 static int BitBlt_SRCPAINT_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc)
283 {
284         int x, y;
285         uint8* srcp;
286         uint8* dstp;
287                 
288         for (y = 0; y < nHeight; y++)
289         {
290                 srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
291                 dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y);
292
293                 if (dstp != 0)
294                 {
295                         for (x = 0; x < nWidth; x++)
296                         {
297                                 *dstp |= *srcp;
298                                 srcp++;
299                                 dstp++;
300                         }
301                 }
302         }
303
304         return 0;
305 }
306
307 static int BitBlt_DSPDxax_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc)
308 {
309         /* TODO: Implement 8bpp DSPDxax BitBlt */
310         return 0;
311 }
312
313 static int BitBlt_SPna_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc)
314 {
315         int x, y;
316         uint8* srcp;
317         uint8* dstp;
318         uint8* patp;
319         
320         for (y = 0; y < nHeight; y++)
321         {
322                 srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
323                 dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y);             
324
325                 if (dstp != 0)
326                 {
327                         for (x = 0; x < nWidth; x++)
328                         {
329                                 patp = gdi_get_brush_pointer(hdcDest, x, y);
330                                 
331                                 *dstp = *srcp & ~(*patp);
332                                 patp++;
333                                 srcp++;
334                                 dstp++;
335                         }
336                 }
337         }
338         
339         return 0;
340 }
341
342 static int BitBlt_PDxn_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight)
343 {
344         int x, y;
345         uint8* dstp;
346         uint8* patp;
347
348         for (y = 0; y < nHeight; y++)
349         {
350                 dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y);
351
352                 if (dstp != 0)
353                 {
354                         for (x = 0; x < nWidth; x++)
355                         {
356                                 patp = gdi_get_brush_pointer(hdcDest, x, y);
357
358                                 *dstp = *dstp ^ ~(*patp);
359                                 patp++;
360                                 dstp++;
361                         }
362                 }
363         }
364
365         return 0;
366 }
367
368 static int BitBlt_DSna_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc)
369 {
370         int x, y;
371         uint8* srcp;
372         uint8* dstp;
373
374         for (y = 0; y < nHeight; y++)
375         {
376                 srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
377                 dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y);
378
379                 if (dstp != 0)
380                 {
381                         for (x = 0; x < nWidth; x++)
382                         {
383                                 *dstp = ~(*srcp) & (*dstp);
384                                 srcp++;
385                                 dstp++;
386                         }
387                 }
388         }
389
390         return 0;
391 }
392
393 static int BitBlt_MERGECOPY_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc)
394 {
395         int x, y;
396         uint8* srcp;
397         uint8* dstp;
398         uint8* patp;
399         
400         for (y = 0; y < nHeight; y++)
401         {
402                 srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
403                 dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y);
404
405                 if (dstp != 0)
406                 {
407                         for (x = 0; x < nWidth; x++)
408                         {
409                                 patp = gdi_get_brush_pointer(hdcDest, x, y);
410                                 
411                                 *dstp = *srcp & *patp;
412                                 patp++;
413                                 srcp++;
414                                 dstp++;
415                         }
416                 }
417         }
418         
419         return 0;
420 }
421
422 static int BitBlt_MERGEPAINT_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc)
423 {
424         int x, y;
425         uint8* srcp;
426         uint8* dstp;
427         
428         for (y = 0; y < nHeight; y++)
429         {
430                 srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
431                 dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y);
432
433                 if (dstp != 0)
434                 {
435                         for (x = 0; x < nWidth; x++)
436                         {                               
437                                 *dstp = ~(*srcp) | *dstp;
438                                 srcp++;
439                                 dstp++;
440                         }
441                 }
442         }
443         
444         return 0;
445 }
446
447 static int BitBlt_PATCOPY_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight)
448 {
449         int x, y;
450         uint8* dstp;
451         uint8* patp;
452         uint8 palIndex;
453
454         if(hdcDest->brush->style == GDI_BS_SOLID)
455         {
456                 palIndex = ((hdcDest->brush->color >> 16) & 0xFF);
457                 for (y = 0; y < nHeight; y++)
458                 {
459                         dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y);
460                         if (dstp != 0)
461                         {
462                                 for (x = 0; x < nWidth; x++)
463                                 {
464                                         *dstp = palIndex;
465                                         dstp++;
466                                 }
467                         }
468                 }
469         }
470         else
471         {
472                 for (y = 0; y < nHeight; y++)
473                 {
474                         dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y);
475
476                         if (dstp != 0)
477                         {
478                                 for (x = 0; x < nWidth; x++)
479                                 {
480                                         patp = gdi_get_brush_pointer(hdcDest, x, y);
481
482                                         *dstp = *patp;
483                                         patp++;
484                                         dstp++;
485                                 }
486                         }
487                 }
488         }
489
490         return 0;
491 }
492
493 static int BitBlt_PATINVERT_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight)
494 {
495         int x, y;
496         uint8* dstp;
497         uint8* patp;
498         uint8 palIndex;
499
500         if(hdcDest->brush->style == GDI_BS_SOLID)
501         {
502                 palIndex = ((hdcDest->brush->color >> 16) & 0xFF);
503                 for (y = 0; y < nHeight; y++)
504                 {
505                         dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y);
506                         if (dstp != 0)
507                         {
508                                 for (x = 0; x < nWidth; x++)
509                                 {
510                                         *dstp ^= palIndex;
511                                         dstp++;
512                                 }
513                         }
514                 }
515         }
516         else
517         {
518                 for (y = 0; y < nHeight; y++)
519                 {
520                         dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y);
521
522                         if (dstp != 0)
523                         {
524                                 for (x = 0; x < nWidth; x++)
525                                 {
526                                         patp = gdi_get_brush_pointer(hdcDest, x, y);
527
528                                         *dstp = *patp ^ *dstp;
529                                         patp++;
530                                         dstp++;
531                                 }
532                         }
533                 }
534         }
535         
536         return 0;
537 }
538
539 static int BitBlt_PATPAINT_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc)
540 {
541         int x, y;
542         uint8* srcp;
543         uint8* dstp;
544         uint8* patp;
545         
546         for (y = 0; y < nHeight; y++)
547         {
548                 srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
549                 dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y);
550
551                 if (dstp != 0)
552                 {
553                         for (x = 0; x < nWidth; x++)
554                         {
555                                 patp = gdi_get_brush_pointer(hdcDest, x, y);
556                                 
557                                 *dstp = *dstp | (*patp | ~(*srcp));
558                                 patp++;
559                                 srcp++;
560                                 dstp++;
561                         }
562                 }
563         }
564         
565         return 0;
566 }
567
568 int BitBlt_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc, int rop)
569 {
570         if (hdcSrc != NULL)
571         {
572                 if (gdi_ClipCoords(hdcDest, &nXDest, &nYDest, &nWidth, &nHeight, &nXSrc, &nYSrc) == 0)
573                         return 0;
574         }
575         else
576         {
577                 if (gdi_ClipCoords(hdcDest, &nXDest, &nYDest, &nWidth, &nHeight, NULL, NULL) == 0)
578                         return 0;
579         }
580         
581         gdi_InvalidateRegion(hdcDest, nXDest, nYDest, nWidth, nHeight);
582         
583         switch (rop)
584         {
585                 case GDI_BLACKNESS:
586                         return BitBlt_BLACKNESS_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight);
587                         break;
588
589                 case GDI_WHITENESS:
590                         return BitBlt_WHITENESS_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight);
591                         break;
592
593                 case GDI_SRCCOPY:
594                         return BitBlt_SRCCOPY_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc);
595                         break;
596
597                 case GDI_SPna:
598                         return BitBlt_SPna_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc);
599                         break;
600
601                 case GDI_DSna:
602                         return BitBlt_DSna_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc);
603                         break;
604
605                 case GDI_DSPDxax:
606                         return BitBlt_DSPDxax_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc);
607                         break;
608                         
609                 case GDI_NOTSRCCOPY:
610                         return BitBlt_NOTSRCCOPY_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc);
611                         break;
612
613                 case GDI_DSTINVERT:
614                         return BitBlt_DSTINVERT_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight);
615                         break;
616
617                 case GDI_SRCERASE:
618                         return BitBlt_SRCERASE_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc);
619                         break;
620
621                 case GDI_NOTSRCERASE:
622                         return BitBlt_NOTSRCERASE_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc);
623                         break;
624
625                 case GDI_SRCINVERT:
626                         return BitBlt_SRCINVERT_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc);
627                         break;
628
629                 case GDI_SRCAND:
630                         return BitBlt_SRCAND_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc);
631                         break;
632
633                 case GDI_SRCPAINT:
634                         return BitBlt_SRCPAINT_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc);
635                         break;
636
637                 case GDI_MERGECOPY:
638                         return BitBlt_MERGECOPY_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc);
639                         break;
640
641                 case GDI_MERGEPAINT:
642                         return BitBlt_MERGEPAINT_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc);
643                         break;
644
645                 case GDI_PATCOPY:
646                         return BitBlt_PATCOPY_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight);
647                         break;
648
649                 case GDI_PATINVERT:
650                         return BitBlt_PATINVERT_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight);
651                         break;
652
653                 case GDI_PATPAINT:
654                         return BitBlt_PATPAINT_8bpp(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc);
655                         break;
656         }
657         
658         printf("BitBlt: unknown rop: 0x%08X\n", rop);
659         return 1;
660 }
661
662 int PatBlt_8bpp(HGDI_DC hdc, int nXLeft, int nYLeft, int nWidth, int nHeight, int rop)
663 {
664         if (gdi_ClipCoords(hdc, &nXLeft, &nYLeft, &nWidth, &nHeight, NULL, NULL) == 0)
665                 return 0;
666         
667         gdi_InvalidateRegion(hdc, nXLeft, nYLeft, nWidth, nHeight);
668
669         switch (rop)
670         {
671                 case GDI_PATCOPY:
672                         return BitBlt_PATCOPY_8bpp(hdc, nXLeft, nYLeft, nWidth, nHeight);
673                         break;
674
675                 case GDI_PATINVERT:
676                         return BitBlt_PATINVERT_8bpp(hdc, nXLeft, nYLeft, nWidth, nHeight);
677                         break;
678                         
679                 case GDI_DSTINVERT:
680                         return BitBlt_DSTINVERT_8bpp(hdc, nXLeft, nYLeft, nWidth, nHeight);
681                         break;
682
683                 case GDI_BLACKNESS:
684                         return BitBlt_BLACKNESS_8bpp(hdc, nXLeft, nYLeft, nWidth, nHeight);
685                         break;
686
687                 case GDI_WHITENESS:
688                         return BitBlt_WHITENESS_8bpp(hdc, nXLeft, nYLeft, nWidth, nHeight);
689                         break;
690
691                 case GDI_PDxn:
692                         return BitBlt_PDxn_8bpp(hdc, nXLeft, nYLeft, nWidth, nHeight);
693                         break;
694
695                 default:
696                         break;
697         }
698         
699         printf("PatBlt: unknown rop: 0x%08X\n", rop);
700         return 1;
701 }
702
703 INLINE void SetPixel_BLACK_8bpp(uint8* pixel, uint8* pen)
704 {
705         /* D = 0 */
706         *pixel = 0;
707 }
708
709 INLINE void SetPixel_NOTMERGEPEN_8bpp(uint8* pixel, uint8* pen)
710 {
711         /* D = ~(D | P) */
712         *pixel = ~(*pixel | *pen);
713 }
714
715 INLINE void SetPixel_MASKNOTPEN_8bpp(uint8* pixel, uint8* pen)
716 {
717         /* D = D & ~P */
718         *pixel &= ~(*pen);
719 }
720
721 INLINE void SetPixel_NOTCOPYPEN_8bpp(uint8* pixel, uint8* pen)
722 {
723         /* D = ~P */
724         *pixel = ~(*pen);
725 }
726
727 INLINE void SetPixel_MASKPENNOT_8bpp(uint8* pixel, uint8* pen)
728 {
729         /* D = P & ~D */
730         *pixel = *pen & ~*pixel;
731 }
732
733 INLINE void SetPixel_NOT_8bpp(uint8* pixel, uint8* pen)
734 {
735         /* D = ~D */
736         *pixel = ~(*pixel);
737 }
738
739 INLINE void SetPixel_XORPEN_8bpp(uint8* pixel, uint8* pen)
740 {
741         /* D = D ^ P */
742         *pixel = *pixel ^ *pen;
743 }
744
745 INLINE void SetPixel_NOTMASKPEN_8bpp(uint8* pixel, uint8* pen)
746 {
747         /* D = ~(D & P) */
748         *pixel = ~(*pixel & *pen);
749 }
750
751 INLINE void SetPixel_MASKPEN_8bpp(uint8* pixel, uint8* pen)
752 {
753         /* D = D & P */
754         *pixel &= *pen;
755 }
756
757 INLINE void SetPixel_NOTXORPEN_8bpp(uint8* pixel, uint8* pen)
758 {
759         /* D = ~(D ^ P) */
760         *pixel = ~(*pixel ^ *pen);
761 }
762
763 INLINE void SetPixel_NOP_8bpp(uint8* pixel, uint8* pen)
764 {
765         /* D = D */
766 }
767
768 INLINE void SetPixel_MERGENOTPEN_8bpp(uint8* pixel, uint8* pen)
769 {
770         /* D = D | ~P */
771         *pixel |= ~(*pen);
772 }
773
774 INLINE void SetPixel_COPYPEN_8bpp(uint8* pixel, uint8* pen)
775 {
776         /* D = P */
777         *pixel = *pen;
778 }
779
780 INLINE void SetPixel_MERGEPENNOT_8bpp(uint8* pixel, uint8* pen)
781 {
782         /* D = P | ~D */
783         *pixel = *pen | ~(*pixel);
784 }
785
786 INLINE void SetPixel_MERGEPEN_8bpp(uint8* pixel, uint8* pen)
787 {
788         /* D = P | D */
789         *pixel |= *pen;
790 }
791
792 INLINE void SetPixel_WHITE_8bpp(uint8* pixel, uint8* pen)
793 {
794         /* D = 1 */
795         *pixel = 0xFF;
796 }
797
798 #define PIXEL_TYPE              uint8
799 #define GDI_GET_POINTER         gdi_GetPointer_8bpp
800 #define GDI_GET_PEN_COLOR       gdi_GetPenColor_8bpp
801
802 #define LINE_TO                 LineTo_BLACK_8bpp
803 #define SET_PIXEL_ROP2          SetPixel_BLACK_8bpp
804 #include "include/line.c"
805 #undef LINE_TO
806 #undef SET_PIXEL_ROP2
807
808 #define LINE_TO                 LineTo_NOTMERGEPEN_8bpp
809 #define SET_PIXEL_ROP2          SetPixel_NOTMERGEPEN_8bpp
810 #include "include/line.c"
811 #undef LINE_TO
812 #undef SET_PIXEL_ROP2
813
814 #define LINE_TO                 LineTo_MASKNOTPEN_8bpp
815 #define SET_PIXEL_ROP2          SetPixel_MASKNOTPEN_8bpp
816 #include "include/line.c"
817 #undef LINE_TO
818 #undef SET_PIXEL_ROP2
819
820 #define LINE_TO                 LineTo_NOTCOPYPEN_8bpp
821 #define SET_PIXEL_ROP2          SetPixel_NOTCOPYPEN_8bpp
822 #include "include/line.c"
823 #undef LINE_TO
824 #undef SET_PIXEL_ROP2
825
826 #define LINE_TO                 LineTo_MASKPENNOT_8bpp
827 #define SET_PIXEL_ROP2          SetPixel_MASKPENNOT_8bpp
828 #include "include/line.c"
829 #undef LINE_TO
830 #undef SET_PIXEL_ROP2
831
832 #define LINE_TO                 LineTo_NOT_8bpp
833 #define SET_PIXEL_ROP2          SetPixel_NOT_8bpp
834 #include "include/line.c"
835 #undef LINE_TO
836 #undef SET_PIXEL_ROP2
837
838 #define LINE_TO                 LineTo_XORPEN_8bpp
839 #define SET_PIXEL_ROP2          SetPixel_XORPEN_8bpp
840 #include "include/line.c"
841 #undef LINE_TO
842 #undef SET_PIXEL_ROP2
843
844 #define LINE_TO                 LineTo_NOTMASKPEN_8bpp
845 #define SET_PIXEL_ROP2          SetPixel_NOTMASKPEN_8bpp
846 #include "include/line.c"
847 #undef LINE_TO
848 #undef SET_PIXEL_ROP2
849
850 #define LINE_TO                 LineTo_MASKPEN_8bpp
851 #define SET_PIXEL_ROP2          SetPixel_MASKPEN_8bpp
852 #include "include/line.c"
853 #undef LINE_TO
854 #undef SET_PIXEL_ROP2
855
856 #define LINE_TO                 LineTo_NOTXORPEN_8bpp
857 #define SET_PIXEL_ROP2          SetPixel_NOTXORPEN_8bpp
858 #include "include/line.c"
859 #undef LINE_TO
860 #undef SET_PIXEL_ROP2
861
862 #define LINE_TO                 LineTo_NOP_8bpp
863 #define SET_PIXEL_ROP2          SetPixel_NOP_8bpp
864 #include "include/line.c"
865 #undef LINE_TO
866 #undef SET_PIXEL_ROP2
867
868 #define LINE_TO                 LineTo_MERGENOTPEN_8bpp
869 #define SET_PIXEL_ROP2          SetPixel_MERGENOTPEN_8bpp
870 #include "include/line.c"
871 #undef LINE_TO
872 #undef SET_PIXEL_ROP2
873
874 #define LINE_TO                 LineTo_COPYPEN_8bpp
875 #define SET_PIXEL_ROP2          SetPixel_COPYPEN_8bpp
876 #include "include/line.c"
877 #undef LINE_TO
878 #undef SET_PIXEL_ROP2
879
880 #define LINE_TO                 LineTo_MERGEPENNOT_8bpp
881 #define SET_PIXEL_ROP2          SetPixel_MERGEPENNOT_8bpp
882 #include "include/line.c"
883 #undef LINE_TO
884 #undef SET_PIXEL_ROP2
885
886 #define LINE_TO                 LineTo_MERGEPEN_8bpp
887 #define SET_PIXEL_ROP2          SetPixel_MERGEPEN_8bpp
888 #include "include/line.c"
889 #undef LINE_TO
890 #undef SET_PIXEL_ROP2
891
892 #define LINE_TO                 LineTo_WHITE_8bpp
893 #define SET_PIXEL_ROP2          SetPixel_WHITE_8bpp
894 #include "include/line.c"
895 #undef LINE_TO
896 #undef SET_PIXEL_ROP2
897
898 #undef PIXEL_TYPE
899 #undef GDI_GET_POINTER
900 #undef GDI_GET_PEN_COLOR
901
902 pLineTo_8bpp LineTo_ROP2_8bpp[32] =
903 {
904         LineTo_BLACK_8bpp,
905         LineTo_NOTMERGEPEN_8bpp,
906         LineTo_MASKNOTPEN_8bpp,
907         LineTo_NOTCOPYPEN_8bpp,
908         LineTo_MASKPENNOT_8bpp,
909         LineTo_NOT_8bpp,
910         LineTo_XORPEN_8bpp,
911         LineTo_NOTMASKPEN_8bpp,
912         LineTo_MASKPEN_8bpp,
913         LineTo_NOTXORPEN_8bpp,
914         LineTo_NOP_8bpp,
915         LineTo_MERGENOTPEN_8bpp,
916         LineTo_COPYPEN_8bpp,
917         LineTo_MERGEPENNOT_8bpp,
918         LineTo_MERGEPEN_8bpp,
919         LineTo_WHITE_8bpp
920 };
921
922 int LineTo_8bpp(HGDI_DC hdc, int nXEnd, int nYEnd)
923 {
924         pLineTo_8bpp _LineTo;
925         int rop2 = gdi_GetROP2(hdc) - 1;
926
927         _LineTo = LineTo_ROP2_8bpp[rop2];
928
929         if (_LineTo != NULL)
930                 return _LineTo(hdc, nXEnd, nYEnd);
931         else
932                 return 0;
933 }