summaryrefslogtreecommitdiffstats
path: root/libfreerdp/gdi/brush.c
blob: 28aa59d80e4809809d2ed24634b7c783b787de8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
/**
 * FreeRDP: A Remote Desktop Protocol Implementation
 * GDI Brush Functions
 *
 * Copyright 2010-2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
 * Copyright 2016 Armin Novak <armin.novak@thincast.com>
 * Copyright 2016 Thincast Technologies GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/* GDI Brush Functions: http://msdn.microsoft.com/en-us/library/dd183395/ */

#include <freerdp/config.h>

#include <stdio.h>
#include <stdlib.h>

#include <freerdp/freerdp.h>
#include <freerdp/gdi/gdi.h>
#include <freerdp/gdi/region.h>
#include <freerdp/log.h>

#include "brush.h"
#include "clipping.h"

#define TAG FREERDP_TAG("gdi.brush")

const char* gdi_rop_to_string(UINT32 code)
{
	switch (code)
	{
		case GDI_BLACKNESS:
			return "0";

		case GDI_DPSoon:
			return "DPSoon";

		case GDI_DPSona:
			return "DPSona";

		case GDI_PSon:
			return "PSon";

		case GDI_SDPona:
			return "SDPona";

		case GDI_DPon:
			return "DPon";

		case GDI_PDSxnon:
			return "PDSxnon";

		case GDI_PDSaon:
			return "PDSaon";

		case GDI_SDPnaa:
			return "SDPnaa";

		case GDI_PDSxon:
			return "PDSxon";

		case GDI_DPna:
			return "DPna";

		case GDI_PSDnaon:
			return "PSDnaon";

		case GDI_SPna:
			return "SPna";

		case GDI_PDSnaon:
			return "PDSnaon";

		case GDI_PDSonon:
			return "PDSonon";

		case GDI_Pn:
			return "Pn";

		case GDI_PDSona:
			return "PDSona";

		case GDI_NOTSRCERASE:
			return "DSon";

		case GDI_SDPxnon:
			return "SDPxnon";

		case GDI_SDPaon:
			return "SDPaon";

		case GDI_DPSxnon:
			return "DPSxnon";

		case GDI_DPSaon:
			return "DPSaon";

		case GDI_PSDPSanaxx:
			return "PSDPSanaxx";

		case GDI_SSPxDSxaxn:
			return "SSPxDSxaxn";

		case GDI_SPxPDxa:
			return "SPxPDxa";

		case GDI_SDPSanaxn:
			return "SDPSanaxn";

		case GDI_PDSPaox:
			return "PDSPaox";

		case GDI_SDPSxaxn:
			return "SDPSxaxn";

		case GDI_PSDPaox:
			return "PSDPaox";

		case GDI_DSPDxaxn:
			return "DSPDxaxn";

		case GDI_PDSox:
			return "PDSox";

		case GDI_PDSoan:
			return "PDSoan";

		case GDI_DPSnaa:
			return "DPSnaa";

		case GDI_SDPxon:
			return "SDPxon";

		case GDI_DSna:
			return "DSna";

		case GDI_SPDnaon:
			return "SPDnaon";

		case GDI_SPxDSxa:
			return "SPxDSxa";

		case GDI_PDSPanaxn:
			return "PDSPanaxn";

		case GDI_SDPSaox:
			return "SDPSaox";

		case GDI_SDPSxnox:
			return "SDPSxnox";

		case GDI_DPSxa:
			return "DPSxa";

		case GDI_PSDPSaoxxn:
			return "PSDPSaoxxn";

		case GDI_DPSana:
			return "DPSana";

		case GDI_SSPxPDxaxn:
			return "SSPxPDxaxn";

		case GDI_SPDSoax:
			return "SPDSoax";

		case GDI_PSDnox:
			return "PSDnox";

		case GDI_PSDPxox:
			return "PSDPxox";

		case GDI_PSDnoan:
			return "PSDnoan";

		case GDI_PSna:
			return "PSna";

		case GDI_SDPnaon:
			return "SDPnaon";

		case GDI_SDPSoox:
			return "SDPSoox";

		case GDI_NOTSRCCOPY:
			return "Sn";

		case GDI_SPDSaox:
			return "SPDSaox";

		case GDI_SPDSxnox:
			return "SPDSxnox";

		case GDI_SDPox:
			return "SDPox";

		case GDI_SDPoan:
			return "SDPoan";

		case GDI_PSDPoax:
			return "PSDPoax";

		case GDI_SPDnox:
			return "SPDnox";

		case GDI_SPDSxox:
			return "SPDSxox";

		case GDI_SPDnoan:
			return "SPDnoan";

		case GDI_PSx:
			return "PSx";

		case GDI_SPDSonox:
			return "SPDSonox";

		case GDI_SPDSnaox:
			return "SPDSnaox";

		case GDI_PSan:
			return "PSan";

		case GDI_PSDnaa:
			return "PSDnaa";

		case GDI_DPSxon:
			return "DPSxon";

		case GDI_SDxPDxa:
			return "SDxPDxa";

		case GDI_SPDSanaxn:
			return "SPDSanaxn";

		case GDI_SRCERASE:
			return "SDna";

		case GDI_DPSnaon:
			return "DPSnaon";

		case GDI_DSPDaox:
			return "DSPDaox";

		case GDI_PSDPxaxn:
			return "PSDPxaxn";

		case GDI_SDPxa:
			return "SDPxa";

		case GDI_PDSPDaoxxn:
			return "PDSPDaoxxn";

		case GDI_DPSDoax:
			return "DPSDoax";

		case GDI_PDSnox:
			return "PDSnox";

		case GDI_SDPana:
			return "SDPana";

		case GDI_SSPxDSxoxn:
			return "SSPxDSxoxn";

		case GDI_PDSPxox:
			return "PDSPxox";

		case GDI_PDSnoan:
			return "PDSnoan";

		case GDI_PDna:
			return "PDna";

		case GDI_DSPnaon:
			return "DSPnaon";

		case GDI_DPSDaox:
			return "DPSDaox";

		case GDI_SPDSxaxn:
			return "SPDSxaxn";

		case GDI_DPSonon:
			return "DPSonon";

		case GDI_DSTINVERT:
			return "Dn";

		case GDI_DPSox:
			return "DPSox";

		case GDI_DPSoan:
			return "DPSoan";

		case GDI_PDSPoax:
			return "PDSPoax";

		case GDI_DPSnox:
			return "DPSnox";

		case GDI_PATINVERT:
			return "DPx";

		case GDI_DPSDonox:
			return "DPSDonox";

		case GDI_DPSDxox:
			return "DPSDxox";

		case GDI_DPSnoan:
			return "DPSnoan";

		case GDI_DPSDnaox:
			return "DPSDnaox";

		case GDI_DPan:
			return "DPan";

		case GDI_PDSxa:
			return "PDSxa";

		case GDI_DSPDSaoxxn:
			return "DSPDSaoxxn";

		case GDI_DSPDoax:
			return "DSPDoax";

		case GDI_SDPnox:
			return "SDPnox";

		case GDI_SDPSoax:
			return "SDPSoax";

		case GDI_DSPnox:
			return "DSPnox";

		case GDI_SRCINVERT:
			return "DSx";

		case GDI_SDPSonox:
			return "SDPSonox";

		case GDI_DSPDSonoxxn:
			return "DSPDSonoxxn";

		case GDI_PDSxxn:
			return "PDSxxn";

		case GDI_DPSax:
			return "DPSax";

		case GDI_PSDPSoaxxn:
			return "PSDPSoaxxn";

		case GDI_SDPax:
			return "SDPax";

		case GDI_PDSPDoaxxn:
			return "PDSPDoaxxn";

		case GDI_SDPSnoax:
			return "SDPSnoax";

		case GDI_PDSxnan:
			return "PDSxnan";

		case GDI_PDSana:
			return "PDSana";

		case GDI_SSDxPDxaxn:
			return "SSDxPDxaxn";

		case GDI_SDPSxox:
			return "SDPSxox";

		case GDI_SDPnoan:
			return "SDPnoan";

		case GDI_DSPDxox:
			return "DSPDxox";

		case GDI_DSPnoan:
			return "DSPnoan";

		case GDI_SDPSnaox:
			return "SDPSnaox";

		case GDI_DSan:
			return "DSan";

		case GDI_PDSax:
			return "PDSax";

		case GDI_DSPDSoaxxn:
			return "DSPDSoaxxn";

		case GDI_DPSDnoax:
			return "DPSDnoax";

		case GDI_SDPxnan:
			return "SDPxnan";

		case GDI_SPDSnoax:
			return "SPDSnoax";

		case GDI_DPSxnan:
			return "DPSxnan";

		case GDI_SPxDSxo:
			return "SPxDSxo";

		case GDI_DPSaan:
			return "DPSaan";

		case GDI_DPSaa:
			return "DPSaa";

		case GDI_SPxDSxon:
			return "SPxDSxon";

		case GDI_DPSxna:
			return "DPSxna";

		case GDI_SPDSnoaxn:
			return "SPDSnoaxn";

		case GDI_SDPxna:
			return "SDPxna";

		case GDI_PDSPnoaxn:
			return "PDSPnoaxn";

		case GDI_DSPDSoaxx:
			return "DSPDSoaxx";

		case GDI_PDSaxn:
			return "PDSaxn";

		case GDI_SRCAND:
			return "DSa";

		case GDI_SDPSnaoxn:
			return "SDPSnaoxn";

		case GDI_DSPnoa:
			return "DSPnoa";

		case GDI_DSPDxoxn:
			return "DSPDxoxn";

		case GDI_SDPnoa:
			return "SDPnoa";

		case GDI_SDPSxoxn:
			return "SDPSxoxn";

		case GDI_SSDxPDxax:
			return "SSDxPDxax";

		case GDI_PDSanan:
			return "PDSanan";

		case GDI_PDSxna:
			return "PDSxna";

		case GDI_SDPSnoaxn:
			return "SDPSnoaxn";

		case GDI_DPSDPoaxx:
			return "DPSDPoaxx";

		case GDI_SPDaxn:
			return "SPDaxn";

		case GDI_PSDPSoaxx:
			return "PSDPSoaxx";

		case GDI_DPSaxn:
			return "DPSaxn";

		case GDI_DPSxx:
			return "DPSxx";

		case GDI_PSDPSonoxx:
			return "PSDPSonoxx";

		case GDI_SDPSonoxn:
			return "SDPSonoxn";

		case GDI_DSxn:
			return "DSxn";

		case GDI_DPSnax:
			return "DPSnax";

		case GDI_SDPSoaxn:
			return "SDPSoaxn";

		case GDI_SPDnax:
			return "SPDnax";

		case GDI_DSPDoaxn:
			return "DSPDoaxn";

		case GDI_DSPDSaoxx:
			return "DSPDSaoxx";

		case GDI_PDSxan:
			return "PDSxan";

		case GDI_DPa:
			return "DPa";

		case GDI_PDSPnaoxn:
			return "PDSPnaoxn";

		case GDI_DPSnoa:
			return "DPSnoa";

		case GDI_DPSDxoxn:
			return "DPSDxoxn";

		case GDI_PDSPonoxn:
			return "PDSPonoxn";

		case GDI_PDxn:
			return "PDxn";

		case GDI_DSPnax:
			return "DSPnax";

		case GDI_PDSPoaxn:
			return "PDSPoaxn";

		case GDI_DPSoa:
			return "DPSoa";

		case GDI_DPSoxn:
			return "DPSoxn";

		case GDI_DSTCOPY:
			return "D";

		case GDI_DPSono:
			return "DPSono";

		case GDI_SPDSxax:
			return "SPDSxax";

		case GDI_DPSDaoxn:
			return "DPSDaoxn";

		case GDI_DSPnao:
			return "DSPnao";

		case GDI_DPno:
			return "DPno";

		case GDI_PDSnoa:
			return "PDSnoa";

		case GDI_PDSPxoxn:
			return "PDSPxoxn";

		case GDI_SSPxDSxox:
			return "SSPxDSxox";

		case GDI_SDPanan:
			return "SDPanan";

		case GDI_PSDnax:
			return "PSDnax";

		case GDI_DPSDoaxn:
			return "DPSDoaxn";

		case GDI_DPSDPaoxx:
			return "DPSDPaoxx";

		case GDI_SDPxan:
			return "SDPxan";

		case GDI_PSDPxax:
			return "PSDPxax";

		case GDI_DSPDaoxn:
			return "DSPDaoxn";

		case GDI_DPSnao:
			return "DPSnao";

		case GDI_MERGEPAINT:
			return "DSno";

		case GDI_SPDSanax:
			return "SPDSanax";

		case GDI_SDxPDxan:
			return "SDxPDxan";

		case GDI_DPSxo:
			return "DPSxo";

		case GDI_DPSano:
			return "DPSano";

		case GDI_MERGECOPY:
			return "PSa";

		case GDI_SPDSnaoxn:
			return "SPDSnaoxn";

		case GDI_SPDSonoxn:
			return "SPDSonoxn";

		case GDI_PSxn:
			return "PSxn";

		case GDI_SPDnoa:
			return "SPDnoa";

		case GDI_SPDSxoxn:
			return "SPDSxoxn";

		case GDI_SDPnax:
			return "SDPnax";

		case GDI_PSDPoaxn:
			return "PSDPoaxn";

		case GDI_SDPoa:
			return "SDPoa";

		case GDI_SPDoxn:
			return "SPDoxn";

		case GDI_DPSDxax:
			return "DPSDxax";

		case GDI_SPDSaoxn:
			return "SPDSaoxn";

		case GDI_SRCCOPY:
			return "S";

		case GDI_SDPono:
			return "SDPono";

		case GDI_SDPnao:
			return "SDPnao";

		case GDI_SPno:
			return "SPno";

		case GDI_PSDnoa:
			return "PSDnoa";

		case GDI_PSDPxoxn:
			return "PSDPxoxn";

		case GDI_PDSnax:
			return "PDSnax";

		case GDI_SPDSoaxn:
			return "SPDSoaxn";

		case GDI_SSPxPDxax:
			return "SSPxPDxax";

		case GDI_DPSanan:
			return "DPSanan";

		case GDI_PSDPSaoxx:
			return "PSDPSaoxx";

		case GDI_DPSxan:
			return "DPSxan";

		case GDI_PDSPxax:
			return "PDSPxax";

		case GDI_SDPSaoxn:
			return "SDPSaoxn";

		case GDI_DPSDanax:
			return "DPSDanax";

		case GDI_SPxDSxan:
			return "SPxDSxan";

		case GDI_SPDnao:
			return "SPDnao";

		case GDI_SDno:
			return "SDno";

		case GDI_SDPxo:
			return "SDPxo";

		case GDI_SDPano:
			return "SDPano";

		case GDI_PDSoa:
			return "PDSoa";

		case GDI_PDSoxn:
			return "PDSoxn";

		case GDI_DSPDxax:
			return "DSPDxax";

		case GDI_PSDPaoxn:
			return "PSDPaoxn";

		case GDI_SDPSxax:
			return "SDPSxax";

		case GDI_PDSPaoxn:
			return "PDSPaoxn";

		case GDI_SDPSanax:
			return "SDPSanax";

		case GDI_SPxPDxan:
			return "SPxPDxan";

		case GDI_SSPxDSxax:
			return "SSPxDSxax";

		case GDI_DSPDSanaxxn:
			return "DSPDSanaxxn";

		case GDI_DPSao:
			return "DPSao";

		case GDI_DPSxno:
			return "DPSxno";

		case GDI_SDPao:
			return "SDPao";

		case GDI_SDPxno:
			return "SDPxno";

		case GDI_SRCPAINT:
			return "DSo";

		case GDI_SDPnoo:
			return "SDPnoo";

		case GDI_PATCOPY:
			return "P";

		case GDI_PDSono:
			return "PDSono";

		case GDI_PDSnao:
			return "PDSnao";

		case GDI_PSno:
			return "PSno";

		case GDI_PSDnao:
			return "PSDnao";

		case GDI_PDno:
			return "PDno";

		case GDI_PDSxo:
			return "PDSxo";

		case GDI_PDSano:
			return "PDSano";

		case GDI_PDSao:
			return "PDSao";

		case GDI_PDSxno:
			return "PDSxno";

		case GDI_DPo:
			return "DPo";

		case GDI_PATPAINT:
			return "DPSnoo";

		case GDI_PSo:
			return "PSo";

		case GDI_PSDnoo:
			return "PSDnoo";

		case GDI_DPSoo:
			return "DPSoo";

		case GDI_WHITENESS:
			return "1";

		case GDI_GLYPH_ORDER:
			return "SPaDSnao";

		default:
			return "";
	}
}

/**
 * @brief Create a new solid brush.
 * msdn{dd183518}
 *
 * @param crColor brush color
 * @return new brush
 */
HGDI_BRUSH gdi_CreateSolidBrush(UINT32 crColor)
{
	HGDI_BRUSH hBrush = (HGDI_BRUSH)calloc(1, sizeof(GDI_BRUSH));

	if (!hBrush)
		return NULL;

	hBrush->objectType = GDIOBJECT_BRUSH;
	hBrush->style = GDI_BS_SOLID;
	hBrush->color = crColor;
	return hBrush;
}
/**
 * @brief Create a new pattern brush.
 * msdn{dd183508}
 *
 * @param hbmp pattern bitmap
 * @return new brush
 */
HGDI_BRUSH gdi_CreatePatternBrush(HGDI_BITMAP hbmp)
{
	HGDI_BRUSH hBrush = (HGDI_BRUSH)calloc(1, sizeof(GDI_BRUSH));

	if (!hBrush)
		return NULL;

	hBrush->objectType = GDIOBJECT_BRUSH;
	hBrush->style = GDI_BS_PATTERN;
	hBrush->pattern = hbmp;
	return hBrush;
}

HGDI_BRUSH gdi_CreateHatchBrush(HGDI_BITMAP hbmp)
{
	HGDI_BRUSH hBrush = (HGDI_BRUSH)calloc(1, sizeof(GDI_BRUSH));

	if (!hBrush)
		return NULL;

	hBrush->objectType = GDIOBJECT_BRUSH;
	hBrush->style = GDI_BS_HATCHED;
	hBrush->pattern = hbmp;
	return hBrush;
}