-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd2d.hpp
1746 lines (1743 loc) · 164 KB
/
d2d.hpp
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
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//Copyright (C) 2014-2020 I
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#pragma once
#include"com.hpp"
#include"_2dim.hpp"
#include"_resource_property.hpp"
#include"dwrite.hpp"
#include"dxgi.hpp"
#include<wincodec.h>
#include<d2d1_1.h>
#pragma comment(lib, "d2d1.lib")
#pragma comment(lib, "dxguid.lib")
#include<functional>
#include<utility>
namespace will{
class d2d : public detail::resource<ID2D1Factory1>{
using resource::resource;
template<typename I>
struct d2d_resource : detail::resource<I>{
using detail::resource<I>::resource;
d2d get_factory()const{ID2D1Factory1* ptr;(*this)->GetFactory(reinterpret_cast<ID2D1Factory**>(&ptr));return d2d{std::move(ptr)};}
};
public:
struct creation_property : detail::property<D2D1_CREATION_PROPERTIES>{
creation_property(D2D1_THREADING_MODE th):property(){prop.threadingMode = th;}
#define PROPERTYDECL(name, type, membername) creation_property& name(type t){prop.membername = t;return *this;}
PROPERTYDECL(threading_mode, D2D1_THREADING_MODE, threadingMode)
PROPERTYDECL(debug_level, D2D1_DEBUG_LEVEL, debugLevel)
PROPERTYDECL(option, D2D1_DEVICE_CONTEXT_OPTIONS, options)
#undef PROPERTYDECL
};
struct fill_t{}static constexpr fill = {};
static UINT32 rgb(std::uint8_t r, std::uint8_t g, std::uint8_t b){return static_cast<UINT32>(r)<<16 | static_cast<UINT32>(g)<<8 | b;}
struct alpha_mode{
alpha_mode() = delete;
struct{
constexpr operator D2D1_ALPHA_MODE()const noexcept{return D2D1_ALPHA_MODE_UNKNOWN;}
constexpr operator DXGI_ALPHA_MODE()const noexcept{return DXGI_ALPHA_MODE_UNSPECIFIED;}
}static constexpr unknown = {}, unspecified = {};
struct{
constexpr operator D2D1_ALPHA_MODE()const noexcept{return D2D1_ALPHA_MODE_PREMULTIPLIED;}
constexpr operator D2D1_COLORMANAGEMENT_ALPHA_MODE()const noexcept{return D2D1_COLORMANAGEMENT_ALPHA_MODE_PREMULTIPLIED;}
constexpr operator D2D1_COLORMATRIX_ALPHA_MODE()const noexcept{return D2D1_COLORMATRIX_ALPHA_MODE_PREMULTIPLIED;}
constexpr operator D2D1_BITMAPSOURCE_ALPHA_MODE()const noexcept{return D2D1_BITMAPSOURCE_ALPHA_MODE_PREMULTIPLIED;}
constexpr operator DXGI_ALPHA_MODE()const noexcept{return DXGI_ALPHA_MODE_PREMULTIPLIED;}
}static constexpr premultiplied = {};
struct{
constexpr operator D2D1_ALPHA_MODE()const noexcept{return D2D1_ALPHA_MODE_STRAIGHT;}
constexpr operator D2D1_COLORMANAGEMENT_ALPHA_MODE()const noexcept{return D2D1_COLORMANAGEMENT_ALPHA_MODE_STRAIGHT;}
constexpr operator D2D1_COLORMATRIX_ALPHA_MODE()const noexcept{return D2D1_COLORMATRIX_ALPHA_MODE_STRAIGHT;}
constexpr operator D2D1_BITMAPSOURCE_ALPHA_MODE()const noexcept{return D2D1_BITMAPSOURCE_ALPHA_MODE_STRAIGHT;}
constexpr operator DXGI_ALPHA_MODE()const noexcept{return DXGI_ALPHA_MODE_STRAIGHT;}
}static constexpr straight = {};
struct{
constexpr operator D2D1_ALPHA_MODE()const noexcept{return D2D1_ALPHA_MODE_IGNORE;}
constexpr operator DXGI_ALPHA_MODE()const noexcept{return DXGI_ALPHA_MODE_IGNORE;}
}static constexpr ignore = {};
};
struct interpolation_mode{
interpolation_mode() = delete;
struct{
constexpr operator D2D1_INTERPOLATION_MODE()const noexcept{return D2D1_INTERPOLATION_MODE_NEAREST_NEIGHBOR;}
constexpr operator D2D1_BITMAP_INTERPOLATION_MODE()const noexcept{return D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR;}
constexpr operator D2D1_DPICOMPENSATION_INTERPOLATION_MODE()const noexcept{return D2D1_DPICOMPENSATION_INTERPOLATION_MODE_NEAREST_NEIGHBOR;}
constexpr operator D2D1_BITMAPSOURCE_INTERPOLATION_MODE()const noexcept{return D2D1_BITMAPSOURCE_INTERPOLATION_MODE_NEAREST_NEIGHBOR;}
constexpr operator D2D1_2DAFFINETRANSFORM_INTERPOLATION_MODE()const noexcept{return D2D1_2DAFFINETRANSFORM_INTERPOLATION_MODE_NEAREST_NEIGHBOR;}
constexpr operator D2D1_3DTRANSFORM_INTERPOLATION_MODE()const noexcept{return D2D1_3DTRANSFORM_INTERPOLATION_MODE_NEAREST_NEIGHBOR;}
constexpr operator D2D1_3DPERSPECTIVETRANSFORM_INTERPOLATION_MODE()const noexcept{return D2D1_3DPERSPECTIVETRANSFORM_INTERPOLATION_MODE_NEAREST_NEIGHBOR;}
constexpr operator D2D1_SCALE_INTERPOLATION_MODE()const noexcept{return D2D1_SCALE_INTERPOLATION_MODE_NEAREST_NEIGHBOR;}
}static constexpr nearest_neighbor = {};
struct{
constexpr operator D2D1_INTERPOLATION_MODE()const noexcept{return D2D1_INTERPOLATION_MODE_LINEAR;}
constexpr operator D2D1_BITMAP_INTERPOLATION_MODE()const noexcept{return D2D1_BITMAP_INTERPOLATION_MODE_LINEAR;}
constexpr operator D2D1_DPICOMPENSATION_INTERPOLATION_MODE()const noexcept{return D2D1_DPICOMPENSATION_INTERPOLATION_MODE_LINEAR;}
constexpr operator D2D1_BITMAPSOURCE_INTERPOLATION_MODE()const noexcept{return D2D1_BITMAPSOURCE_INTERPOLATION_MODE_LINEAR;}
constexpr operator D2D1_2DAFFINETRANSFORM_INTERPOLATION_MODE()const noexcept{return D2D1_2DAFFINETRANSFORM_INTERPOLATION_MODE_LINEAR;}
constexpr operator D2D1_3DTRANSFORM_INTERPOLATION_MODE()const noexcept{return D2D1_3DTRANSFORM_INTERPOLATION_MODE_LINEAR;}
constexpr operator D2D1_3DPERSPECTIVETRANSFORM_INTERPOLATION_MODE()const noexcept{return D2D1_3DPERSPECTIVETRANSFORM_INTERPOLATION_MODE_LINEAR;}
constexpr operator D2D1_SCALE_INTERPOLATION_MODE()const noexcept{return D2D1_SCALE_INTERPOLATION_MODE_LINEAR;}
}static constexpr linear = {};
struct{
constexpr operator D2D1_INTERPOLATION_MODE()const noexcept{return D2D1_INTERPOLATION_MODE_CUBIC;}
constexpr operator D2D1_DPICOMPENSATION_INTERPOLATION_MODE()const noexcept{return D2D1_DPICOMPENSATION_INTERPOLATION_MODE_CUBIC;}
constexpr operator D2D1_BITMAPSOURCE_INTERPOLATION_MODE()const noexcept{return D2D1_BITMAPSOURCE_INTERPOLATION_MODE_CUBIC;}
constexpr operator D2D1_2DAFFINETRANSFORM_INTERPOLATION_MODE()const noexcept{return D2D1_2DAFFINETRANSFORM_INTERPOLATION_MODE_CUBIC;}
constexpr operator D2D1_3DTRANSFORM_INTERPOLATION_MODE()const noexcept{return D2D1_3DTRANSFORM_INTERPOLATION_MODE_CUBIC;}
constexpr operator D2D1_3DPERSPECTIVETRANSFORM_INTERPOLATION_MODE()const noexcept{return D2D1_3DPERSPECTIVETRANSFORM_INTERPOLATION_MODE_CUBIC;}
constexpr operator D2D1_SCALE_INTERPOLATION_MODE()const noexcept{return D2D1_SCALE_INTERPOLATION_MODE_CUBIC;}
}static constexpr cubic = {};
struct{
constexpr operator D2D1_INTERPOLATION_MODE()const noexcept{return D2D1_INTERPOLATION_MODE_MULTI_SAMPLE_LINEAR;}
constexpr operator D2D1_DPICOMPENSATION_INTERPOLATION_MODE()const noexcept{return D2D1_DPICOMPENSATION_INTERPOLATION_MODE_MULTI_SAMPLE_LINEAR;}
constexpr operator D2D1_2DAFFINETRANSFORM_INTERPOLATION_MODE()const noexcept{return D2D1_2DAFFINETRANSFORM_INTERPOLATION_MODE_MULTI_SAMPLE_LINEAR;}
constexpr operator D2D1_3DTRANSFORM_INTERPOLATION_MODE()const noexcept{return D2D1_3DTRANSFORM_INTERPOLATION_MODE_MULTI_SAMPLE_LINEAR;}
constexpr operator D2D1_3DPERSPECTIVETRANSFORM_INTERPOLATION_MODE()const noexcept{return D2D1_3DPERSPECTIVETRANSFORM_INTERPOLATION_MODE_MULTI_SAMPLE_LINEAR;}
constexpr operator D2D1_SCALE_INTERPOLATION_MODE()const noexcept{return D2D1_SCALE_INTERPOLATION_MODE_MULTI_SAMPLE_LINEAR;}
}static constexpr multi_sample_linear = {};
struct{
constexpr operator D2D1_INTERPOLATION_MODE()const noexcept{return D2D1_INTERPOLATION_MODE_ANISOTROPIC;}
constexpr operator D2D1_DPICOMPENSATION_INTERPOLATION_MODE()const noexcept{return D2D1_DPICOMPENSATION_INTERPOLATION_MODE_ANISOTROPIC;}
constexpr operator D2D1_2DAFFINETRANSFORM_INTERPOLATION_MODE()const noexcept{return D2D1_2DAFFINETRANSFORM_INTERPOLATION_MODE_ANISOTROPIC;}
constexpr operator D2D1_3DTRANSFORM_INTERPOLATION_MODE()const noexcept{return D2D1_3DTRANSFORM_INTERPOLATION_MODE_ANISOTROPIC;}
constexpr operator D2D1_3DPERSPECTIVETRANSFORM_INTERPOLATION_MODE()const noexcept{return D2D1_3DPERSPECTIVETRANSFORM_INTERPOLATION_MODE_ANISOTROPIC;}
constexpr operator D2D1_SCALE_INTERPOLATION_MODE()const noexcept{return D2D1_SCALE_INTERPOLATION_MODE_ANISOTROPIC;}
}static constexpr anisotropic = {};
struct{
constexpr operator D2D1_INTERPOLATION_MODE()const noexcept{return D2D1_INTERPOLATION_MODE_HIGH_QUALITY_CUBIC;}
constexpr operator D2D1_DPICOMPENSATION_INTERPOLATION_MODE()const noexcept{return D2D1_DPICOMPENSATION_INTERPOLATION_MODE_HIGH_QUALITY_CUBIC;}
constexpr operator D2D1_2DAFFINETRANSFORM_INTERPOLATION_MODE()const noexcept{return D2D1_2DAFFINETRANSFORM_INTERPOLATION_MODE_HIGH_QUALITY_CUBIC;}
constexpr operator D2D1_SCALE_INTERPOLATION_MODE()const noexcept{return D2D1_SCALE_INTERPOLATION_MODE_HIGH_QUALITY_CUBIC;}
}static constexpr high_quality_cubic = {};
static constexpr D2D1_BITMAPSOURCE_INTERPOLATION_MODE fant = D2D1_BITMAPSOURCE_INTERPOLATION_MODE_FANT;
static constexpr D2D1_BITMAPSOURCE_INTERPOLATION_MODE mipmap_linear = D2D1_BITMAPSOURCE_INTERPOLATION_MODE_MIPMAP_LINEAR;
};
struct scale_mode{
scale_mode() = delete;
struct{
constexpr operator D2D1_CONVOLVEMATRIX_SCALE_MODE()const noexcept{return D2D1_CONVOLVEMATRIX_SCALE_MODE_NEAREST_NEIGHBOR;}
constexpr operator D2D1_DISTANTDIFFUSE_SCALE_MODE()const noexcept{return D2D1_DISTANTDIFFUSE_SCALE_MODE_NEAREST_NEIGHBOR;}
constexpr operator D2D1_DISTANTSPECULAR_SCALE_MODE()const noexcept{return D2D1_DISTANTSPECULAR_SCALE_MODE_NEAREST_NEIGHBOR;}
constexpr operator D2D1_POINTDIFFUSE_SCALE_MODE()const noexcept{return D2D1_POINTDIFFUSE_SCALE_MODE_NEAREST_NEIGHBOR;}
constexpr operator D2D1_POINTSPECULAR_SCALE_MODE()const noexcept{return D2D1_POINTSPECULAR_SCALE_MODE_NEAREST_NEIGHBOR;}
constexpr operator D2D1_SPOTDIFFUSE_SCALE_MODE()const noexcept{return D2D1_SPOTDIFFUSE_SCALE_MODE_NEAREST_NEIGHBOR;}
constexpr operator D2D1_SPOTSPECULAR_SCALE_MODE()const noexcept{return D2D1_SPOTSPECULAR_SCALE_MODE_NEAREST_NEIGHBOR;}
}static constexpr nearest_neighbor = {};
struct{
constexpr operator D2D1_CONVOLVEMATRIX_SCALE_MODE()const noexcept{return D2D1_CONVOLVEMATRIX_SCALE_MODE_LINEAR;}
constexpr operator D2D1_DISTANTDIFFUSE_SCALE_MODE()const noexcept{return D2D1_DISTANTDIFFUSE_SCALE_MODE_LINEAR;}
constexpr operator D2D1_DISTANTSPECULAR_SCALE_MODE()const noexcept{return D2D1_DISTANTSPECULAR_SCALE_MODE_LINEAR;}
constexpr operator D2D1_POINTDIFFUSE_SCALE_MODE()const noexcept{return D2D1_POINTDIFFUSE_SCALE_MODE_LINEAR;}
constexpr operator D2D1_POINTSPECULAR_SCALE_MODE()const noexcept{return D2D1_POINTSPECULAR_SCALE_MODE_LINEAR;}
constexpr operator D2D1_SPOTDIFFUSE_SCALE_MODE()const noexcept{return D2D1_SPOTDIFFUSE_SCALE_MODE_LINEAR;}
constexpr operator D2D1_SPOTSPECULAR_SCALE_MODE()const noexcept{return D2D1_SPOTSPECULAR_SCALE_MODE_LINEAR;}
}static constexpr linear = {};
struct{
constexpr operator D2D1_CONVOLVEMATRIX_SCALE_MODE()const noexcept{return D2D1_CONVOLVEMATRIX_SCALE_MODE_CUBIC;}
constexpr operator D2D1_DISTANTDIFFUSE_SCALE_MODE()const noexcept{return D2D1_DISTANTDIFFUSE_SCALE_MODE_CUBIC;}
constexpr operator D2D1_DISTANTSPECULAR_SCALE_MODE()const noexcept{return D2D1_DISTANTSPECULAR_SCALE_MODE_CUBIC;}
constexpr operator D2D1_POINTDIFFUSE_SCALE_MODE()const noexcept{return D2D1_POINTDIFFUSE_SCALE_MODE_CUBIC;}
constexpr operator D2D1_POINTSPECULAR_SCALE_MODE()const noexcept{return D2D1_POINTSPECULAR_SCALE_MODE_CUBIC;}
constexpr operator D2D1_SPOTDIFFUSE_SCALE_MODE()const noexcept{return D2D1_SPOTDIFFUSE_SCALE_MODE_CUBIC;}
constexpr operator D2D1_SPOTSPECULAR_SCALE_MODE()const noexcept{return D2D1_SPOTSPECULAR_SCALE_MODE_CUBIC;}
}static constexpr cubic = {};
struct{
constexpr operator D2D1_CONVOLVEMATRIX_SCALE_MODE()const noexcept{return D2D1_CONVOLVEMATRIX_SCALE_MODE_MULTI_SAMPLE_LINEAR;}
constexpr operator D2D1_DISTANTDIFFUSE_SCALE_MODE()const noexcept{return D2D1_DISTANTDIFFUSE_SCALE_MODE_MULTI_SAMPLE_LINEAR;}
constexpr operator D2D1_DISTANTSPECULAR_SCALE_MODE()const noexcept{return D2D1_DISTANTSPECULAR_SCALE_MODE_MULTI_SAMPLE_LINEAR;}
constexpr operator D2D1_POINTDIFFUSE_SCALE_MODE()const noexcept{return D2D1_POINTDIFFUSE_SCALE_MODE_MULTI_SAMPLE_LINEAR;}
constexpr operator D2D1_POINTSPECULAR_SCALE_MODE()const noexcept{return D2D1_POINTSPECULAR_SCALE_MODE_MULTI_SAMPLE_LINEAR;}
constexpr operator D2D1_SPOTDIFFUSE_SCALE_MODE()const noexcept{return D2D1_SPOTDIFFUSE_SCALE_MODE_MULTI_SAMPLE_LINEAR;}
constexpr operator D2D1_SPOTSPECULAR_SCALE_MODE()const noexcept{return D2D1_SPOTSPECULAR_SCALE_MODE_MULTI_SAMPLE_LINEAR;}
}static constexpr multi_sample_linear = {};
struct{
constexpr operator D2D1_CONVOLVEMATRIX_SCALE_MODE()const noexcept{return D2D1_CONVOLVEMATRIX_SCALE_MODE_ANISOTROPIC;}
constexpr operator D2D1_DISTANTDIFFUSE_SCALE_MODE()const noexcept{return D2D1_DISTANTDIFFUSE_SCALE_MODE_ANISOTROPIC;}
constexpr operator D2D1_DISTANTSPECULAR_SCALE_MODE()const noexcept{return D2D1_DISTANTSPECULAR_SCALE_MODE_ANISOTROPIC;}
constexpr operator D2D1_POINTDIFFUSE_SCALE_MODE()const noexcept{return D2D1_POINTDIFFUSE_SCALE_MODE_ANISOTROPIC;}
constexpr operator D2D1_POINTSPECULAR_SCALE_MODE()const noexcept{return D2D1_POINTSPECULAR_SCALE_MODE_ANISOTROPIC;}
constexpr operator D2D1_SPOTDIFFUSE_SCALE_MODE()const noexcept{return D2D1_SPOTDIFFUSE_SCALE_MODE_ANISOTROPIC;}
constexpr operator D2D1_SPOTSPECULAR_SCALE_MODE()const noexcept{return D2D1_SPOTSPECULAR_SCALE_MODE_ANISOTROPIC;}
}static constexpr anisotropic = {};
struct{
constexpr operator D2D1_CONVOLVEMATRIX_SCALE_MODE()const noexcept{return D2D1_CONVOLVEMATRIX_SCALE_MODE_HIGH_QUALITY_CUBIC;}
constexpr operator D2D1_DISTANTDIFFUSE_SCALE_MODE()const noexcept{return D2D1_DISTANTDIFFUSE_SCALE_MODE_HIGH_QUALITY_CUBIC;}
constexpr operator D2D1_DISTANTSPECULAR_SCALE_MODE()const noexcept{return D2D1_DISTANTSPECULAR_SCALE_MODE_HIGH_QUALITY_CUBIC;}
constexpr operator D2D1_POINTDIFFUSE_SCALE_MODE()const noexcept{return D2D1_POINTDIFFUSE_SCALE_MODE_HIGH_QUALITY_CUBIC;}
constexpr operator D2D1_POINTSPECULAR_SCALE_MODE()const noexcept{return D2D1_POINTSPECULAR_SCALE_MODE_HIGH_QUALITY_CUBIC;}
constexpr operator D2D1_SPOTDIFFUSE_SCALE_MODE()const noexcept{return D2D1_SPOTDIFFUSE_SCALE_MODE_HIGH_QUALITY_CUBIC;}
constexpr operator D2D1_SPOTSPECULAR_SCALE_MODE()const noexcept{return D2D1_SPOTSPECULAR_SCALE_MODE_HIGH_QUALITY_CUBIC;}
}static constexpr high_quality_cubic = {};
};
struct optimization{
optimization() = delete;
struct{
constexpr operator D2D1_DIRECTIONALBLUR_OPTIMIZATION()const noexcept{return D2D1_DIRECTIONALBLUR_OPTIMIZATION_SPEED;}
constexpr operator D2D1_GAUSSIANBLUR_OPTIMIZATION()const noexcept{return D2D1_GAUSSIANBLUR_OPTIMIZATION_SPEED;}
constexpr operator D2D1_SHADOW_OPTIMIZATION()const noexcept{return D2D1_SHADOW_OPTIMIZATION_SPEED;}
}static constexpr speed = {};
struct{
constexpr operator D2D1_DIRECTIONALBLUR_OPTIMIZATION()const noexcept{return D2D1_DIRECTIONALBLUR_OPTIMIZATION_BALANCED;}
constexpr operator D2D1_GAUSSIANBLUR_OPTIMIZATION()const noexcept{return D2D1_GAUSSIANBLUR_OPTIMIZATION_BALANCED;}
constexpr operator D2D1_SHADOW_OPTIMIZATION()const noexcept{return D2D1_SHADOW_OPTIMIZATION_BALANCED;}
}static constexpr balanced = {};
struct{
constexpr operator D2D1_DIRECTIONALBLUR_OPTIMIZATION()const noexcept{return D2D1_DIRECTIONALBLUR_OPTIMIZATION_QUALITY;}
constexpr operator D2D1_GAUSSIANBLUR_OPTIMIZATION()const noexcept{return D2D1_GAUSSIANBLUR_OPTIMIZATION_QUALITY;}
constexpr operator D2D1_SHADOW_OPTIMIZATION()const noexcept{return D2D1_SHADOW_OPTIMIZATION_QUALITY;}
}static constexpr quality = {};
};
explicit d2d(D2D1_FACTORY_TYPE t = D2D1_FACTORY_TYPE_MULTI_THREADED, D2D1_DEBUG_LEVEL dlv =
#ifdef _DEBUG
D2D1_DEBUG_LEVEL_WARNING
#else
D2D1_DEBUG_LEVEL_NONE
#endif
):d2d{+create_factory(t, dlv)}{}
struct stroke_style : d2d_resource<ID2D1StrokeStyle1>{
using d2d_resource::d2d_resource;
struct property : detail::property<D2D1_STROKE_STYLE_PROPERTIES1>{
using detail::property<D2D1_STROKE_STYLE_PROPERTIES1>::property;
#define PROPERTYDECL(name, type, membername) property& name(type t){prop.membername = t;return *this;}
PROPERTYDECL(start_cap, D2D1_CAP_STYLE, startCap)
PROPERTYDECL(end_cap, D2D1_CAP_STYLE, endCap)
PROPERTYDECL(dash_cap, D2D1_CAP_STYLE, dashCap)
property& cap(D2D1_CAP_STYLE s){prop.startCap = prop.endCap = prop.dashCap = s; return *this;}
PROPERTYDECL(line_join, D2D1_LINE_JOIN, lineJoin)
PROPERTYDECL(miter_limit, FLOAT, miterLimit)
PROPERTYDECL(dash_style, D2D1_DASH_STYLE, dashStyle)
PROPERTYDECL(dash_offset, FLOAT, dashOffset)
PROPERTYDECL(transform_type, D2D1_STROKE_TRANSFORM_TYPE, transformType)
#undef PROPERTYDECL
};
D2D1_CAP_STYLE dash_cap()const{return (*this)->GetDashCap();}
UINT32 dashes_count()const{return (*this)->GetDashesCount();}
std::vector<FLOAT> dashes()const{const auto n = dashes_count();std::vector<FLOAT> data(n);(*this)->GetDashes(data.data(), n);return std::move(data);}
FLOAT dash_offset()const{return (*this)->GetDashOffset();}
D2D1_DASH_STYLE dash_style()const{return (*this)->GetDashStyle();}
D2D1_CAP_STYLE end_cap()const{return (*this)->GetEndCap();}
D2D1_LINE_JOIN line_join()const{return (*this)->GetLineJoin();}
FLOAT miter_limit()const{return (*this)->GetMiterLimit();}
D2D1_CAP_STYLE start_cap()const{return (*this)->GetStartCap();}
D2D1_STROKE_TRANSFORM_TYPE transform_type()const{return (*this)->GetStrokeTransformType();}
};
struct drawing_state_block : d2d_resource<ID2D1DrawingStateBlock>{
using d2d_resource::d2d_resource;
struct description : detail::property<D2D1_DRAWING_STATE_DESCRIPTION>{
using property::property;
#define PROPERTYDECL(name, type, membername) description& name(type t){prop.membername = t;return *this;}
PROPERTYDECL(antialias_mode, D2D1_ANTIALIAS_MODE, antialiasMode)
PROPERTYDECL(text_antialias_mode, D2D1_TEXT_ANTIALIAS_MODE, textAntialiasMode)
PROPERTYDECL(tag1, D2D1_TAG, tag1)
PROPERTYDECL(tag2, D2D1_TAG, tag2)
description& tags(const std::pair<D2D1_TAG, D2D1_TAG>& t){prop.tag1 = t.first;prop.tag2 = t.second;return *this;}
PROPERTYDECL(transform, D2D1_MATRIX_3X2_F, transform)
#undef PROPERTYDECL
};
D2D1_DRAWING_STATE_DESCRIPTION get_description(){D2D1_DRAWING_STATE_DESCRIPTION d;(*this)->GetDescription(&d);return d;}
void set_description(const D2D1_DRAWING_STATE_DESCRIPTION& d){(*this)->SetDescription(d);}
__declspec(property(get=get_description, put=set_description)) D2D1_DRAWING_STATE_DESCRIPTION drawing_state_description;
dwrite::rendering_params get_text_rendering_params()const{IDWriteRenderingParams1* ptr;(*this)->GetTextRenderingParams(reinterpret_cast<IDWriteRenderingParams**>(&ptr));return dwrite::rendering_params{std::move(ptr)};}
void set_text_rendering_params(IDWriteRenderingParams1* params = nullptr){(*this)->SetTextRenderingParams(params);}
template<typename DWriteRenderingParams>
void set_text_rendering_params(DWriteRenderingParams&& params){set_text_rendering_params(std::forward<DWriteRenderingParams>(params).get());}
__declspec(property(get=get_text_rendering_params, put=set_text_rendering_parms)) dwrite::rendering_params text_rendering_params;
};
class device : public d2d_resource<ID2D1Device>{
template<typename I>
struct brush : d2d_resource<I>{
using d2d_resource<I>::d2d_resource;
FLOAT get_opacity()const{return (*this)->GetOpacity();}
void set_opcaity(FLOAT opac){(*this)->SetOpacity(opac);}
__declspec(property(get=get_opacity, put=set_opcaity)) FLOAT opacity;
D2D1_MATRIX_3X2_F get_transform()const{D2D1_MATRIX_3X2_F mat;(*this)->GetTransform(&mat);return *this;}
void set_transform(const D2D1_MATRIX_3X2_F& mat){(*this)->SetTransform(mat);}
__declspec(property(get=get_transform, put=set_transform)) D2D1_MATRIX_3X2_F transform;
};
template<typename I>
struct render_target;
public:
class context;
struct solid_color_brush : brush<ID2D1SolidColorBrush>{
using brush::brush;
D2D1_COLOR_F get_color()const{return (*this)->GetColor();}
solid_color_brush& set_color(const D2D1_COLOR_F& c){(*this)->SetColor(c);return *this;}
solid_color_brush& set_color(const D2D1::ColorF::Enum& c){(*this)->SetColor(D2D1::ColorF(c));return *this;}
solid_color_brush& set_color(UINT32 c){(*this)->SetColor(D2D1::ColorF(c));return *this;}
__declspec(property(get=get_color, put=set_color)) D2D1_COLOR_F color;
};
struct gradient_stop_collection : detail::resource<ID2D1GradientStopCollection1>{
using resource::resource;
class property{
std::vector<D2D1_GRADIENT_STOP> grads;
D2D1_COLOR_SPACE preerps = D2D1_COLOR_SPACE_SRGB;
D2D1_COLOR_SPACE posterps = D2D1_COLOR_SPACE_SCRGB;
D2D1_BUFFER_PRECISION bufpre = D2D1_BUFFER_PRECISION_8BPC_UNORM_SRGB;
D2D1_EXTEND_MODE extm = D2D1_EXTEND_MODE_CLAMP;
D2D1_COLOR_INTERPOLATION_MODE colerpm = D2D1_COLOR_INTERPOLATION_MODE_STRAIGHT;
public:
explicit property() = default;
#define PROPERTYDECL(name, type, membername) property& name(type t){membername = t;return *this;}
PROPERTYDECL(preinterpolation_space, D2D1_COLOR_SPACE, preerps)
PROPERTYDECL(postinterpolation_space, D2D1_COLOR_SPACE, posterps)
PROPERTYDECL(buffer_precision, D2D1_BUFFER_PRECISION, bufpre)
PROPERTYDECL(extend_mode, D2D1_EXTEND_MODE, extm)
PROPERTYDECL(color_interpolation_mode, D2D1_COLOR_INTERPOLATION_MODE, colerpm)
PROPERTYDECL(gradient_stops, const std::vector<D2D1_GRADIENT_STOP>&, grads)
property& gradient_stops(std::vector<D2D1_GRADIENT_STOP>&& t){grads = std::move(t);return *this;}
property& gradient_stops(std::initializer_list<D2D1_GRADIENT_STOP> il){grads = il;return *this;}
#undef PROPERTYDECL
friend context;
};
D2D1_GAMMA color_interpolation_gamma()const{return (*this)->GetColorInterpolationGamma();}
D2D1_EXTEND_MODE extend_mode()const{return (*this)->GetExtendMode();}
UINT32 gradient_stop_count()const{return (*this)->GetGradientStopCount();}
std::vector<D2D1_GRADIENT_STOP> gradient_stops()const{const auto n = gradient_stop_count();std::vector<D2D1_GRADIENT_STOP> data(n);(*this)->GetGradientStops1(data.data(), n);return std::move(data);}
D2D1_BUFFER_PRECISION buffer_precision()const{return (*this)->GetBufferPrecision();}
D2D1_COLOR_INTERPOLATION_MODE color_interpolation_mode()const{return (*this)->GetColorInterpolationMode();}
D2D1_COLOR_SPACE post_interpolation_mode()const{return (*this)->GetPostInterpolationSpace();}
D2D1_COLOR_SPACE pre_interpolation_mode()const{return (*this)->GetPreInterpolationSpace();}
};
struct linear_gradient_brush : brush<ID2D1LinearGradientBrush>{
using brush::brush;
D2D1_POINT_2F get_start_point()const{return (*this)->GetStartPoint();}
void set_start_point(const D2D1_POINT_2F& sp){(*this)->SetStartPoint(sp);}
template<typename T>
void set_start_point(T&& t){(*this)->SetStartPoint(two_dim::attribute<D2D1_POINT_2F>(std::forward<T>(t)));}
__declspec(property(get=get_start_point, put=set_start_point)) D2D1_POINT_2F start_point;
D2D1_POINT_2F get_end_point()const{return (*this)->GetEndPoint();}
void set_end_point(const D2D1_POINT_2F& ep){(*this)->SetEndPoint(ep);}
template<typename T>
void set_end_point(T&& t){(*this)->SetEndPoint(two_dim::attribute<D2D1_POINT_2F>(std::forward<T>(t)));}
__declspec(property(get=get_end_point, put=set_end_point)) D2D1_POINT_2F end_point;
gradient_stop_collection get_gradient_stop_collection()const{ID2D1GradientStopCollection1* ptr;(*this)->GetGradientStopCollection(reinterpret_cast<ID2D1GradientStopCollection**>(&ptr));return gradient_stop_collection{std::move(ptr)};}
};
class radial_gradient_brush : public brush<ID2D1RadialGradientBrush>{
class radius_impl{
ID2D1RadialGradientBrush* self;
radius_impl(ID2D1RadialGradientBrush* p):self{p}{}
friend radial_gradient_brush;
public:
operator will::two_dim::xy<FLOAT>()const{return {get_x(), get_y()};}
operator D2D1_POINT_2F()const{return {get_x(), get_y()};}
template<typename T>
T attribute()const{return will::two_dim::attribute<T>(static_cast<will::two_dim::xy<FLOAT>>(*this));}
FLOAT get_x()const{return self->GetRadiusX();}
void set_x(FLOAT t){self->SetRadiusX(t);}
__declspec(property(get=get_x, put=set_x)) FLOAT x;
FLOAT get_y()const{return self->GetRadiusY();}
void set_y(FLOAT t){self->SetRadiusY(t);}
__declspec(property(get=get_y, put=set_y)) FLOAT y;
};
public:
using brush::brush;
D2D1_POINT_2F get_center()const{return (*this)->GetCenter();}
void set_center(const D2D1_POINT_2F& c){(*this)->SetCenter(c);}
template<typename T>
void set_center(T&& t){(*this)->SetCenter(two_dim::attribute<D2D1_POINT_2F>(std::forward<T>(t)));}
__declspec(property(get=get_center, put=set_center)) D2D1_POINT_2F center;
radius_impl get_radius()const{return radius_impl{get()};}
void set_radius(const two_dim::xy<FLOAT>& r){(*this)->SetRadiusX(r.x);(*this)->SetRadiusY(r.y);}
__declspec(property(get=get_radius, put=set_radius)) radius_impl radius;
D2D1_POINT_2F get_gradient_origin_offset()const{return (*this)->GetGradientOriginOffset();}
void set_gradient_origin_offset(const D2D1_POINT_2F& goo){(*this)->SetGradientOriginOffset(goo);}
template<typename T>
void set_gradient_origin_offset(T&& t){(*this)->SetGradientOriginOffset(two_dim::attribute<D2D1_POINT_2F>(std::forward<T>(t)));}
__declspec(property(get=get_gradient_origin_offset, put=set_gradient_origin_offset)) D2D1_POINT_2F gradient_origin_offset;
gradient_stop_collection get_gradient_stop_collection()const{ID2D1GradientStopCollection1* ptr;(*this)->GetGradientStopCollection(reinterpret_cast<ID2D1GradientStopCollection**>(&ptr));return gradient_stop_collection{std::move(ptr)};}
};
class bitmap : public d2d_resource<ID2D1Bitmap1>{
expected<void, hresult_error> copy_from_bitmap(const ::D2D1_POINT_2U* dest_point, ID2D1Bitmap1* bmp, const ::D2D1_RECT_U* src_rect){
const auto hr = (*this)->CopyFromBitmap(dest_point, bmp, src_rect);
if(FAILED(hr))
return make_unexpected<hresult_error>(_T("__FUNCTION__"), hr);
return {};
}
expected<void, hresult_error> copy_from_render_target(const ::D2D1_POINT_2U* dest_point, ::ID2D1RenderTarget* rt, const ::D2D1_RECT_U* src_rect){
const auto hr = (*this)->CopyFromRenderTarget(dest_point, rt, src_rect);
if(FAILED(hr))
return make_unexpected<hresult_error>(_T(__FUNCTION__), hr);
return {};
}
expected<void, hresult_error> copy_from_memory(const ::D2D1_RECT_U* dest_rect, const void* src_data, ::UINT32 pitch){
const auto hr = (*this)->CopyFromMemory(dest_rect, src_data, pitch);
if(FAILED(hr))
return make_unexpected<hresult_error>(_T(__FUNCTION__), hr);
return {};
}
public:
using d2d_resource::d2d_resource;
class property : public detail::property<D2D1_BITMAP_PROPERTIES1>{
class dpi_property{
property* prop;
public:
dpi_property(property* p):prop(p){}
dpi_property(const dpi_property&) = delete;
dpi_property(dpi_property&&) = delete;
dpi_property& operator=(const dpi_property&) = delete;
dpi_property& operator=(dpi_property&&) = delete;
property& operator()(FLOAT x, FLOAT y)const{prop->prop.dpiX = x; prop->prop.dpiY = y; return *prop;}
property& operator()(const two_dim::xy<FLOAT>& xy)const{return (*this)(xy.x, xy.y);}
property& x(FLOAT x)const{prop->prop.dpiX = x; return *prop;}
property& y(FLOAT y)const{prop->prop.dpiY = y; return *prop;}
};
friend class dpi_property;
public:
explicit property(){prop.pixelFormat = {DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED};}
#define PROPERTYDECL(name, type, membername) property& name(type t){prop.membername = t;return *this;}
PROPERTYDECL(format, DXGI_FORMAT, pixelFormat.format)
PROPERTYDECL(alpha_mode, D2D1_ALPHA_MODE, pixelFormat.alphaMode)
const dpi_property dpi = this;
PROPERTYDECL(option, D2D1_BITMAP_OPTIONS, bitmapOptions)
PROPERTYDECL(color_context, ID2D1ColorContext*, colorContext)
#undef PROPERTYDECL
};
struct memory_data{
UINT32 pitch;
const void* data;
};
struct region{
const bitmap& bm;
D2D1_RECT_U rect;
};
class lazy_manipulator{
D2D1::Matrix4x4F mat;
const bitmap& bm;
template<typename>friend struct render_target;
public:
friend bitmap;
friend class renderer;
lazy_manipulator(const bitmap& b):bm{b}{}
lazy_manipulator& perspective_transform(const D2D1::Matrix4x4F& m = {}){mat = mat * m;return *this;}
lazy_manipulator& scale_x(float x = 1.f){return perspective_transform(D2D1::Matrix4x4F::Scale(x, 1.f, 1.f));}
lazy_manipulator& scale_y(float y = 1.f){return perspective_transform(D2D1::Matrix4x4F::Scale(1.f, y, 1.f));}
lazy_manipulator& scale_z(float z = 1.f){return perspective_transform(D2D1::Matrix4x4F::Scale(1.f, 1.f, z));}
lazy_manipulator& scale(float t = 1.f){return perspective_transform(D2D1::Matrix4x4F::Scale(t, t, t));}
lazy_manipulator& scale(float x, float y, float z = 1.f){return perspective_transform(D2D1::Matrix4x4F::Scale(x, y, z));}
lazy_manipulator& skew_x(float x = 1.f){return perspective_transform(D2D1::Matrix4x4F::SkewX(x));}
lazy_manipulator& skew_y(float y = 1.f){return perspective_transform(D2D1::Matrix4x4F::SkewY(y));}
lazy_manipulator& translate_x(float x = 0.f){return perspective_transform(D2D1::Matrix4x4F::Translation(x, 0.f, 0.f));}
lazy_manipulator& translate_y(float y = 0.f){return perspective_transform(D2D1::Matrix4x4F::Translation(0.f, y, 0.f));}
lazy_manipulator& translate_z(float z = 0.f){return perspective_transform(D2D1::Matrix4x4F::Translation(0.f, 0.f, z));}
lazy_manipulator& translate(float x = 0.f, float y = 0.f, float z = 0.f){return perspective_transform(D2D1::Matrix4x4F::Translation(x, y, z));}
lazy_manipulator& rotate_x(float x = 0.f){return perspective_transform(D2D1::Matrix4x4F::RotationX(x));}
lazy_manipulator& rotate_y(float y = 0.f){return perspective_transform(D2D1::Matrix4x4F::RotationY(y));}
lazy_manipulator& rotate_z(float z = 0.f){return perspective_transform(D2D1::Matrix4x4F::RotationZ(z));}
lazy_manipulator& perspective_project(float d){return perspective_transform(D2D1::Matrix4x4F::PerspectiveProjection(d));}
lazy_manipulator& rotate_arbitary_axis(float x, float y, float z, float degrees){return perspective_transform(D2D1::Matrix4x4F::RotationArbitraryAxis(x, y, z, degrees));}
expected<bitmap, hresult_error> freeze(const context& c)const{return c.prerender([&](auto&& r){r.bitmap(bm, 1.f, D2D1_INTERPOLATION_MODE_LINEAR, mat);});}
};
class scoped_readonly_mapped_rect : public ::D2D1_MAPPED_RECT{
const bitmap& bm;
scoped_readonly_mapped_rect(::D2D1_MAPPED_RECT&& mr, const bitmap& bitm)noexcept: ::D2D1_MAPPED_RECT{std::move(mr)}, bm{bitm}{}
public:
scoped_readonly_mapped_rect(const bitmap& bitm): ::D2D1_MAPPED_RECT(+bitm.map_read()), bm{bitm}{}
scoped_readonly_mapped_rect(scoped_readonly_mapped_rect&& t)noexcept: ::D2D1_MAPPED_RECT{std::move(static_cast<::D2D1_MAPPED_RECT&>(t))}, bm{t.bm}{t.bits = nullptr;}
~scoped_readonly_mapped_rect()noexcept{if(bits)auto _ = bm.unmap();}
operator const memory_data&()const{return *reinterpret_cast<const memory_data*>(this);}
friend bitmap;
};
class scoped_mapped_rect : public ::D2D1_MAPPED_RECT{
bitmap& bm;
scoped_mapped_rect(::D2D1_MAPPED_RECT&& s, bitmap& bitm)noexcept: ::D2D1_MAPPED_RECT{std::move(s)}, bm{bitm}{}
public:
scoped_mapped_rect(bitmap& bitm, std::underlying_type_t<::D2D1_MAP_OPTIONS> option): ::D2D1_MAPPED_RECT(+bitm.map(option)), bm{bitm}{}
scoped_mapped_rect(scoped_mapped_rect&& t)noexcept: ::D2D1_MAPPED_RECT{std::move(static_cast<::D2D1_MAPPED_RECT&>(t))}, bm{t.bm}{t.bits = nullptr;}
~scoped_mapped_rect()noexcept{if(bits)auto _ = bm.unmap();}
operator const memory_data&()const{return *reinterpret_cast<const memory_data*>(this);}
friend bitmap;
};
bitmap(bitmap&&) = default;
expected<bitmap, hresult_error> clone(const context& devcont)const{const auto dpi = get_dpi();return devcont.create_bitmap(get_pixel_size(), D2D1::BitmapProperties1(get_bitmap_options(), get_pixel_format(), dpi.x, dpi.y, get_color_context())).bind([&](will::d2d::bitmap&& bm){return bm.copy_from(*this).map([&](){return std::move(bm);});});}
lazy_manipulator perspective_transform(const D2D1::Matrix4x4F& m = {}){return lazy_manipulator{*this}.perspective_transform(m);}
lazy_manipulator scale_x(float x = 1.f)const{return lazy_manipulator{*this}.scale_x(x);}
lazy_manipulator scale_y(float y = 1.f)const{return lazy_manipulator{*this}.scale_y(y);}
lazy_manipulator scale_z(float z = 1.f)const{return lazy_manipulator{*this}.scale_z(z);}
lazy_manipulator scale(float x = 1.f, float y = 1.f, float z = 1.f)const{return lazy_manipulator{*this}.scale(x, y, z);}
lazy_manipulator skew_x(float x = 1.f)const{return lazy_manipulator{*this}.skew_x(x);}
lazy_manipulator skew_y(float y = 1.f)const{return lazy_manipulator{*this}.skew_y(y);}
lazy_manipulator translate_x(float x = 0.f)const{return lazy_manipulator{*this}.translate_x(x);}
lazy_manipulator translate_y(float y = 0.f)const{return lazy_manipulator{*this}.translate_y(y);}
lazy_manipulator translate_z(float z = 0.f)const{return lazy_manipulator{*this}.translate_z(z);}
lazy_manipulator translate(float x = 0.f, float y = 0.f, float z = 0.f)const{return lazy_manipulator{*this}.translate(x, y, z);}
lazy_manipulator rotate_x(float x = 0.f)const{return lazy_manipulator{*this}.rotate_x(x);}
lazy_manipulator rotate_y(float y = 0.f)const{return lazy_manipulator{*this}.rotate_y(y);}
lazy_manipulator rotate_z(float z = 0.f)const{return lazy_manipulator{*this}.rotate_z(z);}
lazy_manipulator perspective_project(float d){return lazy_manipulator{*this}.perspective_project(d);}
lazy_manipulator rotate_arbitary_axis(float x, float y, float z, float degrees){return lazy_manipulator{*this}.rotate_arbitary_axis(x, y, z, degrees);}
region get_region(const D2D1_RECT_U& r)const{return region{*this, r};}
will::two_dim::xy<FLOAT> get_dpi()const{will::two_dim::xy<FLOAT> dpi;(*this)->GetDpi(&dpi.x, &dpi.y);return dpi;}
D2D1_SIZE_U get_pixel_size()const{return (*this)->GetPixelSize();}
D2D1_SIZE_F get_dip_size()const{return (*this)->GetSize();}
D2D1_PIXEL_FORMAT get_pixel_format()const{return (*this)->GetPixelFormat();}
D2D1_BITMAP_OPTIONS get_bitmap_options()const{return (*this)->GetOptions();}
ID2D1ColorContext* get_color_context()const{ID2D1ColorContext* ptr;(*this)->GetColorContext(&ptr);return ptr;}
expected<will::dxgi::surface, hresult_error> get_surface()const{return com_create_resource<IDXGISurface>([&](IDXGISurface** ptr){return (*this)->GetSurface(ptr);}).emap([](HRESULT hr){return make_unexpected<hresult_error>(_T("will::d2d::bitmap::get_surface"), hr);}).bind([](IDXGISurface* ptr){return com_ptr<IDXGISurface>{std::move(ptr)}.as<IDXGISurface2>();}).map([](com_ptr<IDXGISurface2>&& ptr){return will::dxgi::surface{std::move(ptr)};});}
expected<::D2D1_MAPPED_RECT, hresult_error> map(std::underlying_type_t<::D2D1_MAP_OPTIONS> option){::D2D1_MAPPED_RECT rect;const auto hr = (*this)->Map(static_cast<::D2D1_MAP_OPTIONS>(option), &rect);if(FAILED(hr))return make_unexpected<hresult_error>(_T(__FUNCTION__), hr);return rect;}
expected<::D2D1_MAPPED_RECT, hresult_error> map_read()const{::D2D1_MAPPED_RECT rect;const auto hr = (*this)->Map(::D2D1_MAP_OPTIONS_READ, &rect);if(FAILED(hr))return make_unexpected<hresult_error>(_T(__FUNCTION__), hr);return rect;}
expected<void, hresult_error> unmap()const{const auto hr = (*this)->Unmap();if(FAILED(hr))return make_unexpected<hresult_error>(_T(__FUNCTION__), hr);return {};}
expected<scoped_readonly_mapped_rect, hresult_error> scoped_map()const{return map_read().map([&](::D2D1_MAPPED_RECT&& m){return scoped_readonly_mapped_rect{std::move(m), *this};});}
expected<scoped_mapped_rect, hresult_error> scoped_map(std::underlying_type_t<::D2D1_MAP_OPTIONS> option){return map(option).map([&](::D2D1_MAPPED_RECT&& m){return scoped_mapped_rect{std::move(m), *this};});}
expected<void, hresult_error> copy_from(ID2D1Bitmap1* bmp){return copy_from_bitmap(nullptr, bmp, nullptr);}
expected<void, hresult_error> copy_from(ID2D1Bitmap1* bmp, const ::D2D1_RECT_U& src_rect){return copy_from_bitmap(nullptr, bmp, &src_rect);}
expected<void, hresult_error> copy_from(const ::D2D1_POINT_2U& dest_point, ID2D1Bitmap1* bmp){return copy_from_bitmap(&dest_point, bmp, nullptr);}
expected<void, hresult_error> copy_from(const ::D2D1_POINT_2U& dest_point, ID2D1Bitmap1* bmp, const ::D2D1_RECT_U& src_rect){return copy_from_bitmap(&dest_point, bmp, &src_rect);}
expected<void, hresult_error> copy_from(const bitmap& bmp){return copy_from(bmp.get());}
expected<void, hresult_error> copy_from(const bitmap& bmp, const ::D2D1_RECT_U& src_rect){return copy_from(bmp.get(), src_rect);}
expected<void, hresult_error> copy_from(const ::D2D1_POINT_2U& dest_point, const bitmap& bmp){return copy_from(dest_point, bmp.get());}
expected<void, hresult_error> copy_from(const ::D2D1_POINT_2U& dest_point, const bitmap& bmp, const ::D2D1_RECT_U& src_rect){return copy_from(dest_point, bmp.get(), src_rect);}
expected<void, hresult_error> copy_from(ID2D1RenderTarget* rt){return copy_from_render_target(nullptr, rt, nullptr);}
expected<void, hresult_error> copy_from(ID2D1RenderTarget* rt, const ::D2D1_RECT_U& src_rect){return copy_from_render_target(nullptr, rt, &src_rect);}
expected<void, hresult_error> copy_from(const ::D2D1_POINT_2U& dest_point, ID2D1RenderTarget* rt){return copy_from_render_target(&dest_point, rt, nullptr);}
expected<void, hresult_error> copy_from(const ::D2D1_POINT_2U& dest_point, ID2D1RenderTarget* rt, const ::D2D1_RECT_U& src_rect){return copy_from_render_target(&dest_point, rt, &src_rect);}
template<typename I>expected<void, hresult_error> copy_from(const render_target<I>& rt){return copy_from(rt.get());}
template<typename I>expected<void, hresult_error> copy_from(const render_target<I>& rt, const ::D2D1_RECT_U& src_rect){return copy_from(rt.get(), src_rect);}
template<typename I>expected<void, hresult_error> copy_from(const ::D2D1_POINT_2U& dest_point, const render_target<I>& rt){return copy_from(dest_point, rt.get());}
template<typename I>expected<void, hresult_error> copy_from(const ::D2D1_POINT_2U& dest_point, const render_target<I>& rt, const ::D2D1_RECT_U& src_rect){return copy_from(dest_point, rt.get(), src_rect);}
expected<void, hresult_error> copy_from(const void* src_data, UINT32 pitch){return copy_from_memory(nullptr, src_data, pitch);}
expected<void, hresult_error> copy_from(const ::D2D1_RECT_U& dest_rect, const void* src_data, UINT32 pitch){return copy_from_memory(&dest_rect, src_data, pitch);}
expected<void, hresult_error> copy_from(const region& r){return copy_from(r.bm, r.rect);}
expected<void, hresult_error> copy_from(const ::D2D1_POINT_2U& dest_point, const region& r){return copy_from(dest_point, r.bm, r.rect);}
template<typename I>expected<void, hresult_error> copy_from(const typename render_target<I>::region& r){return copy_from(r.rt, r.rect);}
template<typename I>expected<void, hresult_error> copy_from(const ::D2D1_POINT_2U& dest_point, const typename render_target<I>::region& r){return copy_from(dest_point, r.rt, r.rect);}
expected<void, hresult_error> copy_from(const memory_data& data){return copy_from(data.data, data.pitch);}
expected<void, hresult_error> copy_from(const ::D2D1_RECT_U& dest_rect, const memory_data& data){return copy_from(dest_rect, data.data, data.pitch);}
bitmap& operator=(bitmap&&) = default;
template<typename T, std::enable_if_t<!std::is_base_of<ID2D1RenderTarget, std::remove_pointer_t<std::decay_t<T>>>::value>* = nullptr>
bitmap& operator=(const T& t){return *this = t.get();}
bitmap& operator=(ID2D1Bitmap1* bm){+copy_from(bm);return *this;}
bitmap& operator=(ID2D1RenderTarget* rt){+copy_from(rt);return *this;}
bitmap& operator=(const region& r){+copy_from(r);return *this;}
template<typename I>
bitmap& operator=(const typename render_target<I>::region& r){+copy_from(r);return *this;}
bitmap& operator=(const memory_data& data){+copy_from(data);return *this;}
};
class bitmap_brush : public brush<ID2D1BitmapBrush1>{
class extend_mode_impl{
ID2D1BitmapBrush1* self;
extend_mode_impl(ID2D1BitmapBrush1* p):self{p}{}
friend bitmap_brush;
public:
operator will::two_dim::xy<D2D1_EXTEND_MODE>()const{return {get_x(), get_y()};}
D2D1_EXTEND_MODE get_x()const{return self->GetExtendModeX();}
void set_x(D2D1_EXTEND_MODE t){self->SetExtendModeX(t);}
__declspec(property(get=get_x, put=set_x)) D2D1_EXTEND_MODE x;
D2D1_EXTEND_MODE get_y()const{return self->GetExtendModeY();}
void set_y(D2D1_EXTEND_MODE t){self->SetExtendModeY(t);}
__declspec(property(get=get_y, put=set_y)) D2D1_EXTEND_MODE y;
};
public:
using brush::brush;
bitmap get_bitmap()const{using bmp = class bitmap;ID2D1Bitmap1* ptr;(*this)->GetBitmap(reinterpret_cast<ID2D1Bitmap**>(&ptr));return bmp{std::move(ptr)};}
void set_bitmap(ID2D1Bitmap1* bmp){(*this)->SetBitmap(bmp);}
template<typename Bitmap>
void set_bitmap(Bitmap&& b){set_bitmap(std::forward<Bitmap>(b).get());}
__declspec(property(get=get_bitmap, put=set_bitmap)) bitmap bitmap;
extend_mode_impl get_extend_mode()const{return extend_mode_impl{get()};}
void set_extend_mode(const two_dim::xy<D2D1_EXTEND_MODE>& r){(*this)->SetExtendModeX(r.x);(*this)->SetExtendModeY(r.y);}
__declspec(property(get=get_extend_mode, put=set_extend_mode)) extend_mode_impl radius;
D2D1_INTERPOLATION_MODE get_interpolation_mode()const{return (*this)->GetInterpolationMode1();}
void set_interpolation_mode(D2D1_INTERPOLATION_MODE im){(*this)->SetInterpolationMode1(im);}
__declspec(property(get=get_interpolation_mode, put=set_interpolation_mode)) D2D1_INTERPOLATION_MODE interpolation_mode;
};
class effect : public d2d_resource<ID2D1Effect>{
class io_impl{
UINT32 index;
effect& eff;
ID2D1Image* get()const{ID2D1Image* ptr;eff->GetInput(index, &ptr);return ptr;}
public:
io_impl(UINT32 i, effect& eff):index(i), eff(eff){}
io_impl& operator|=(ID2D1Bitmap1* input){eff->SetInput(index, input); return *this;}
io_impl& operator|=(ID2D1Effect* input){eff->SetInputEffect(index, input); return *this;}
template<typename Input>
io_impl& operator|=(Input&& input){return *this |= std::forward<Input>(input).get();}
};
template<typename Prop>
class sv_l_impl{
Prop p;
effect& eff;
public:
sv_l_impl(Prop p, effect& eff):p(p), eff(eff){}
template<typename Value>
effect& operator=(Value&& v){return +eff.set(p, std::forward<Value>(v));}
};
template<typename Prop>
class sv_r_impl{
Prop p;
effect& eff;
public:
sv_r_impl(Prop p, effect& eff):p(p), eff(eff){}
template<typename Value>
effect&& operator=(Value&& v){return std::move(+eff.set(p, std::forward<Value>(v)));}
};
public:
using d2d_resource::d2d_resource;
effect& operator|=(ID2D1Bitmap1* input){(*this)->SetInput(0, input); return *this;}
effect& operator|=(ID2D1Effect* input){(*this)->SetInputEffect(0, input); return *this;}
template<typename Input>
effect& operator|=(Input&& input){return *this |= std::forward<Input>(input).get();}
io_impl operator[](UINT32 i){return io_impl{i, *this};}
template<typename Prop>
sv_l_impl<Prop> operator()(Prop p)& {return sv_l_impl<Prop>(p, *this);}
template<typename Prop>
sv_r_impl<Prop> operator()(Prop p)&&{return sv_r_impl<Prop>(p, *this);}
template<typename Prop, typename Value>
expected<effect&, hresult_error> set(Prop p, Value&& v)& {const auto hr = (*this)->SetValue(p, std::forward<Value>(v));if(SUCCEEDED(hr))return *this ;return make_unexpected<hresult_error>(_T(__FUNCTION__), hr);}
template<typename Prop, typename Value>
expected<effect , hresult_error> set(Prop p, Value&& v)&&{const auto hr = (*this)->SetValue(p, std::forward<Value>(v));if(SUCCEEDED(hr))return std::move(*this);return make_unexpected<hresult_error>(_T(__FUNCTION__), hr);}
};
class builtin_effects{
template<typename T, const CLSID& ClassId>
class impl : effect{friend class context;protected:using self = T;using effect::set;using effect::operator|=;using effect::operator[];public:using effect::effect;using effect::get_factory;using effect::get;using effect::operator->;using effect::operator bool;using effect::operator=;using effect::swap;static const CLSID& clsid(){return ClassId;}};
public:
builtin_effects() = delete;
#define PROPERTYDECL(name, prop, type, default_value, precond, set_expression) \
expected<self&, hresult_error> set_##name(type v = default_value)& {precond;const auto result = this->set(prop, set_expression);if(result)return *this ;return make_unexpected(std::move(result.error()));}\
expected<self , hresult_error> set_##name(type v = default_value)&&{precond;const auto result = this->set(prop, set_expression);if(result)return std::move(*this);return make_unexpected(std::move(result.error()));}\
__declspec(property(put=set_##name)) std::decay_t<type> name;
struct color{
color() = delete;
//(Win10)CLSID_D2D1LookupTable3D
struct color_management : impl<color_management, CLSID_D2D1ColorManagement>{
using impl::impl;
using impl::operator|=;
PROPERTYDECL(source_context, D2D1_COLORMANAGEMENT_PROP_SOURCE_COLOR_CONTEXT, ID2D1ColorContext*, nullptr, , v)
template<typename ColorContext>
expected<self&, hresult_error> set_source_context(ColorContext&& v)& {return set_source_context(std::forward<ColorContext>(v).get());}
template<typename ColorContext>
expected<self , hresult_error> set_source_context(ColorContext&& v)&&{return set_source_context(std::forward<ColorContext>(v).get());}
PROPERTYDECL(source_intent, D2D1_COLORMANAGEMENT_PROP_SOURCE_RENDERING_INTENT, D2D1_COLORMANAGEMENT_RENDERING_INTENT, D2D1_COLORMANAGEMENT_RENDERING_INTENT_PERCEPTUAL, , v)
PROPERTYDECL(destination_context, D2D1_COLORMANAGEMENT_PROP_DESTINATION_COLOR_CONTEXT, ID2D1ColorContext*, nullptr, , v)
template<typename ColorContext>
expected<self&, hresult_error> set_destination_context(ColorContext&& v)& {return set_destination_context(std::forward<ColorContext>(v).get());}
template<typename ColorContext>
expected<self , hresult_error> set_destination_context(ColorContext&& v)&&{return set_destination_context(std::forward<ColorContext>(v).get());}
PROPERTYDECL(destination_intent, D2D1_COLORMANAGEMENT_PROP_DESTINATION_RENDERING_INTENT, D2D1_COLORMANAGEMENT_RENDERING_INTENT, D2D1_COLORMANAGEMENT_RENDERING_INTENT_PERCEPTUAL, , v)
PROPERTYDECL(alpha_mode, D2D1_COLORMANAGEMENT_PROP_ALPHA_MODE, D2D1_COLORMANAGEMENT_ALPHA_MODE, D2D1_COLORMANAGEMENT_ALPHA_MODE_PREMULTIPLIED, , v)
PROPERTYDECL(quality, D2D1_COLORMANAGEMENT_PROP_QUALITY, D2D1_COLORMANAGEMENT_QUALITY, D2D1_COLORMANAGEMENT_QUALITY_NORMAL, , v)
};
private:
struct _color_matrix_effect : impl<_color_matrix_effect, CLSID_D2D1ColorMatrix>{
using impl::impl;
using impl::operator|=;
PROPERTYDECL(color_matrix, D2D1_COLORMATRIX_PROP_COLOR_MATRIX, const D2D1_MATRIX_5X4_F&, D2D1::Matrix5x4F(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0), , v )
PROPERTYDECL(alpha_mode, D2D1_COLORMATRIX_PROP_ALPHA_MODE, D2D1_COLORMATRIX_ALPHA_MODE, D2D1_COLORMATRIX_ALPHA_MODE_PREMULTIPLIED, , v )
PROPERTYDECL(clamp_output, D2D1_COLORMATRIX_PROP_CLAMP_OUTPUT, bool, false, , v ? TRUE : FALSE)
};
public:
using color_matrix = _color_matrix_effect;
struct discrete_transfer : impl<discrete_transfer, CLSID_D2D1DiscreteTransfer>{
using impl::impl;
using impl::operator|=;
expected<self&, hresult_error> set_red (const std::vector<float>& v = {0.f, 1.f})& {if(v.empty()){const auto result = this->set(D2D1_DISCRETETRANSFER_PROP_RED_DISABLE, TRUE);if(result)return *this ;return make_unexpected(std::move(result.error()));}for(auto&& x : v)if(x < 0.f || 1.f < x)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG);const auto result = (*this)->SetValue(D2D1_DISCRETETRANSFER_PROP_RED_TABLE, reinterpret_cast<const BYTE*>(v.data()), static_cast<UINT32>(v.size() * sizeof(float)));if(SUCCEEDED(result))return *this ;return make_unexpected<hresult_error>(_T(__FUNCTION__), result);}
expected<self , hresult_error> set_red (const std::vector<float>& v = {0.f, 1.f})&&{if(v.empty()){const auto result = this->set(D2D1_DISCRETETRANSFER_PROP_RED_DISABLE, TRUE);if(result)return std::move(*this);return make_unexpected(std::move(result.error()));}for(auto&& x : v)if(x < 0.f || 1.f < x)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG);const auto result = (*this)->SetValue(D2D1_DISCRETETRANSFER_PROP_RED_TABLE, reinterpret_cast<const BYTE*>(v.data()), static_cast<UINT32>(v.size() * sizeof(float)));if(SUCCEEDED(result))return std::move(*this);return make_unexpected<hresult_error>(_T(__FUNCTION__), result);}
__declspec(property(put=set_red)) std::vector<float> red;
expected<self&, hresult_error> set_green(const std::vector<float>& v = {0.f, 1.f})& {if(v.empty()){const auto result = this->set(D2D1_DISCRETETRANSFER_PROP_GREEN_DISABLE, TRUE);if(result)return *this ;return make_unexpected(std::move(result.error()));}for(auto&& x : v)if(x < 0.f || 1.f < x)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG);const auto result = (*this)->SetValue(D2D1_DISCRETETRANSFER_PROP_GREEN_TABLE, reinterpret_cast<const BYTE*>(v.data()), static_cast<UINT32>(v.size() * sizeof(float)));if(SUCCEEDED(result))return *this ;return make_unexpected<hresult_error>(_T(__FUNCTION__), result);}
expected<self , hresult_error> set_green(const std::vector<float>& v = {0.f, 1.f})&&{if(v.empty()){const auto result = this->set(D2D1_DISCRETETRANSFER_PROP_GREEN_DISABLE, TRUE);if(result)return std::move(*this);return make_unexpected(std::move(result.error()));}for(auto&& x : v)if(x < 0.f || 1.f < x)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG);const auto result = (*this)->SetValue(D2D1_DISCRETETRANSFER_PROP_GREEN_TABLE, reinterpret_cast<const BYTE*>(v.data()), static_cast<UINT32>(v.size() * sizeof(float)));if(SUCCEEDED(result))return std::move(*this);return make_unexpected<hresult_error>(_T(__FUNCTION__), result);}
__declspec(property(put=set_green)) std::vector<float> green;
expected<self&, hresult_error> set_blue (const std::vector<float>& v = {0.f, 1.f})& {if(v.empty()){const auto result = this->set(D2D1_DISCRETETRANSFER_PROP_BLUE_DISABLE, TRUE);if(result)return *this ;return make_unexpected(std::move(result.error()));}for(auto&& x : v)if(x < 0.f || 1.f < x)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG);const auto result = (*this)->SetValue(D2D1_DISCRETETRANSFER_PROP_BLUE_TABLE, reinterpret_cast<const BYTE*>(v.data()), static_cast<UINT32>(v.size() * sizeof(float)));if(SUCCEEDED(result))return *this ;return make_unexpected<hresult_error>(_T(__FUNCTION__), result);}
expected<self , hresult_error> set_blue (const std::vector<float>& v = {0.f, 1.f})&&{if(v.empty()){const auto result = this->set(D2D1_DISCRETETRANSFER_PROP_BLUE_DISABLE, TRUE);if(result)return std::move(*this);return make_unexpected(std::move(result.error()));}for(auto&& x : v)if(x < 0.f || 1.f < x)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG);const auto result = (*this)->SetValue(D2D1_DISCRETETRANSFER_PROP_BLUE_TABLE, reinterpret_cast<const BYTE*>(v.data()), static_cast<UINT32>(v.size() * sizeof(float)));if(SUCCEEDED(result))return std::move(*this);return make_unexpected<hresult_error>(_T(__FUNCTION__), result);}
__declspec(property(put=set_blue)) std::vector<float> blue;
PROPERTYDECL(clamp_output, D2D1_DISCRETETRANSFER_PROP_CLAMP_OUTPUT, bool, false, , v ? TRUE : FALSE)
};
struct dpi_compensation : impl<dpi_compensation, CLSID_D2D1DpiCompensation>{
using impl::impl;
using impl::operator|=;
PROPERTYDECL(interpolation_mode, D2D1_DPICOMPENSATION_PROP_INTERPOLATION_MODE, D2D1_DPICOMPENSATION_INTERPOLATION_MODE, D2D1_DPICOMPENSATION_INTERPOLATION_MODE_LINEAR, , v)
PROPERTYDECL(border_mode, D2D1_DPICOMPENSATION_PROP_BORDER_MODE, D2D1_BORDER_MODE, D2D1_BORDER_MODE_SOFT, , v)
PROPERTYDECL(input_dpi, D2D1_DPICOMPENSATION_PROP_INPUT_DPI, float, 96.f, , v)
};
struct gamma_transfer : impl<gamma_transfer, CLSID_D2D1GammaTransfer>{
using impl::impl;
using impl::operator|=;
PROPERTYDECL( red_amplitude, D2D1_GAMMATRANSFER_PROP_RED_AMPLITUDE, float, 1.f, , v )
PROPERTYDECL( red_exponent, D2D1_GAMMATRANSFER_PROP_RED_EXPONENT, float, 1.f, , v )
PROPERTYDECL( red_offset, D2D1_GAMMATRANSFER_PROP_RED_OFFSET, float, 0.f, , v )
PROPERTYDECL( red_enable, D2D1_GAMMATRANSFER_PROP_RED_DISABLE, bool, true, , v ? FALSE : TRUE)
PROPERTYDECL(green_amplitude, D2D1_GAMMATRANSFER_PROP_GREEN_AMPLITUDE, float, 1.f, , v )
PROPERTYDECL(green_exponent, D2D1_GAMMATRANSFER_PROP_GREEN_EXPONENT, float, 1.f, , v )
PROPERTYDECL(green_offset, D2D1_GAMMATRANSFER_PROP_GREEN_OFFSET, float, 0.f, , v )
PROPERTYDECL(green_enable, D2D1_GAMMATRANSFER_PROP_GREEN_DISABLE, bool, true, , v ? FALSE : TRUE)
PROPERTYDECL( blue_amplitude, D2D1_GAMMATRANSFER_PROP_BLUE_AMPLITUDE, float, 1.f, , v )
PROPERTYDECL( blue_exponent, D2D1_GAMMATRANSFER_PROP_BLUE_EXPONENT, float, 1.f, , v )
PROPERTYDECL( blue_offset, D2D1_GAMMATRANSFER_PROP_BLUE_OFFSET, float, 0.f, , v )
PROPERTYDECL( blue_enable, D2D1_GAMMATRANSFER_PROP_BLUE_DISABLE, bool, true, , v ? FALSE : TRUE)
PROPERTYDECL(alpha_amplitude, D2D1_GAMMATRANSFER_PROP_ALPHA_AMPLITUDE, float, 1.f, , v )
PROPERTYDECL(alpha_exponent, D2D1_GAMMATRANSFER_PROP_ALPHA_EXPONENT, float, 1.f, , v )
PROPERTYDECL(alpha_offset, D2D1_GAMMATRANSFER_PROP_ALPHA_OFFSET, float, 0.f, , v )
PROPERTYDECL(alpha_enable, D2D1_GAMMATRANSFER_PROP_ALPHA_DISABLE, bool, true, , v ? FALSE : TRUE)
PROPERTYDECL(clamp_output, D2D1_GAMMATRANSFER_PROP_CLAMP_OUTPUT, bool, false, , v ? TRUE : FALSE)
};
//(Win10)CLSID_D2D1HueToRgb
struct hue_rotation : impl<hue_rotation, CLSID_D2D1HueRotation>{
using impl::impl;
using impl::operator|=;
PROPERTYDECL(angle, D2D1_HUEROTATION_PROP_ANGLE, float, 0.f, , v)
};
struct linear_transfer : impl<linear_transfer, CLSID_D2D1LinearTransfer>{
using impl::impl;
using impl::operator|=;
PROPERTYDECL( red_y_intercept, D2D1_LINEARTRANSFER_PROP_RED_Y_INTERCEPT, float, 0.f, , v )
PROPERTYDECL( red_slope, D2D1_LINEARTRANSFER_PROP_RED_SLOPE, float, 1.f, , v )
PROPERTYDECL( red_enable, D2D1_LINEARTRANSFER_PROP_RED_DISABLE, bool, true, , v ? FALSE : TRUE)
PROPERTYDECL(green_y_intercept, D2D1_LINEARTRANSFER_PROP_GREEN_Y_INTERCEPT, float, 0.f, , v )
PROPERTYDECL(green_slope, D2D1_LINEARTRANSFER_PROP_GREEN_SLOPE, float, 1.f, , v )
PROPERTYDECL(green_enable, D2D1_LINEARTRANSFER_PROP_GREEN_DISABLE, bool, true, , v ? FALSE : TRUE)
PROPERTYDECL( blue_y_intercept, D2D1_LINEARTRANSFER_PROP_BLUE_Y_INTERCEPT, float, 0.f, , v )
PROPERTYDECL( blue_slope, D2D1_LINEARTRANSFER_PROP_BLUE_SLOPE, float, 1.f, , v )
PROPERTYDECL( blue_enable, D2D1_LINEARTRANSFER_PROP_BLUE_DISABLE, bool, true, , v ? FALSE : TRUE)
PROPERTYDECL(alpha_y_intercept, D2D1_LINEARTRANSFER_PROP_ALPHA_Y_INTERCEPT, float, 0.f, , v )
PROPERTYDECL(alpha_slope, D2D1_LINEARTRANSFER_PROP_ALPHA_SLOPE, float, 0.f, , v )
PROPERTYDECL(alpha_enable, D2D1_LINEARTRANSFER_PROP_ALPHA_DISABLE, bool, true, , v ? FALSE : TRUE)
PROPERTYDECL(clamp_output, D2D1_LINEARTRANSFER_PROP_CLAMP_OUTPUT, bool, false, , v ? TRUE : FALSE)
};
struct opacity_metadata : impl<opacity_metadata, CLSID_D2D1OpacityMetadata>{
using impl::impl;
using impl::operator|=;
PROPERTYDECL(output_rect, D2D1_OPACITYMETADATA_PROP_INPUT_OPAQUE_RECT, const D2D1_VECTOR_4F&, D2D1::Vector4F(-FLT_MAX, -FLT_MAX, FLT_MAX, FLT_MAX), , v)
};
struct premultiply : impl<premultiply, CLSID_D2D1Premultiply>{
using impl::impl;
using impl::operator|=;
};
//(Win10)CLSID_D2D1RgbToHue
private:
struct _saturation_effect : impl<_saturation_effect, CLSID_D2D1Saturation>{
using impl::impl;
using impl::operator|=;
PROPERTYDECL(saturation, D2D1_SATURATION_PROP_SATURATION, float, .5f, if(v < 0.f || 1.f < v)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG), v)
};
public:
using saturation = _saturation_effect;
struct table_transfer : impl<table_transfer, CLSID_D2D1TableTransfer>{
using impl::impl;
using impl::operator|=;
expected<self&, hresult_error> set_red (const std::vector<float>& v = {0.f, 1.f})& {if(v.empty()){const auto result = this->set(D2D1_TABLETRANSFER_PROP_RED_DISABLE, TRUE);if(result)return *this ;return make_unexpected(std::move(result.error()));}for(auto&& x : v)if(x < 0.f || 1.f < x)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG);const auto result = (*this)->SetValue(D2D1_TABLETRANSFER_PROP_RED_TABLE, reinterpret_cast<const BYTE*>(v.data()), static_cast<UINT32>(v.size() * sizeof(float)));if(SUCCEEDED(result))return *this ;return make_unexpected<hresult_error>(_T(__FUNCTION__), result);}
expected<self , hresult_error> set_red (const std::vector<float>& v = {0.f, 1.f})&&{if(v.empty()){const auto result = this->set(D2D1_TABLETRANSFER_PROP_RED_DISABLE, TRUE);if(result)return std::move(*this);return make_unexpected(std::move(result.error()));}for(auto&& x : v)if(x < 0.f || 1.f < x)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG);const auto result = (*this)->SetValue(D2D1_TABLETRANSFER_PROP_RED_TABLE, reinterpret_cast<const BYTE*>(v.data()), static_cast<UINT32>(v.size() * sizeof(float)));if(SUCCEEDED(result))return std::move(*this);return make_unexpected<hresult_error>(_T(__FUNCTION__), result);}
__declspec(property(put=set_red)) std::vector<float> red;
expected<self&, hresult_error> set_green(const std::vector<float>& v = {0.f, 1.f})& {if(v.empty()){const auto result = this->set(D2D1_TABLETRANSFER_PROP_GREEN_DISABLE, TRUE);if(result)return *this ;return make_unexpected(std::move(result.error()));}for(auto&& x : v)if(x < 0.f || 1.f < x)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG);const auto result = (*this)->SetValue(D2D1_TABLETRANSFER_PROP_GREEN_TABLE, reinterpret_cast<const BYTE*>(v.data()), static_cast<UINT32>(v.size() * sizeof(float)));if(SUCCEEDED(result))return *this ;return make_unexpected<hresult_error>(_T(__FUNCTION__), result);}
expected<self , hresult_error> set_green(const std::vector<float>& v = {0.f, 1.f})&&{if(v.empty()){const auto result = this->set(D2D1_TABLETRANSFER_PROP_GREEN_DISABLE, TRUE);if(result)return std::move(*this);return make_unexpected(std::move(result.error()));}for(auto&& x : v)if(x < 0.f || 1.f < x)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG);const auto result = (*this)->SetValue(D2D1_TABLETRANSFER_PROP_GREEN_TABLE, reinterpret_cast<const BYTE*>(v.data()), static_cast<UINT32>(v.size() * sizeof(float)));if(SUCCEEDED(result))return std::move(*this);return make_unexpected<hresult_error>(_T(__FUNCTION__), result);}
__declspec(property(put=set_green)) std::vector<float> green;
expected<self&, hresult_error> set_blue (const std::vector<float>& v = {0.f, 1.f})& {if(v.empty()){const auto result = this->set(D2D1_TABLETRANSFER_PROP_BLUE_DISABLE, TRUE);if(result)return *this ;return make_unexpected(std::move(result.error()));}for(auto&& x : v)if(x < 0.f || 1.f < x)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG);const auto result = (*this)->SetValue(D2D1_TABLETRANSFER_PROP_BLUE_TABLE, reinterpret_cast<const BYTE*>(v.data()), static_cast<UINT32>(v.size() * sizeof(float)));if(SUCCEEDED(result))return *this ;return make_unexpected<hresult_error>(_T(__FUNCTION__), result);}
expected<self , hresult_error> set_blue (const std::vector<float>& v = {0.f, 1.f})&&{if(v.empty()){const auto result = this->set(D2D1_TABLETRANSFER_PROP_BLUE_DISABLE, TRUE);if(result)return std::move(*this);return make_unexpected(std::move(result.error()));}for(auto&& x : v)if(x < 0.f || 1.f < x)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG);const auto result = (*this)->SetValue(D2D1_TABLETRANSFER_PROP_BLUE_TABLE, reinterpret_cast<const BYTE*>(v.data()), static_cast<UINT32>(v.size() * sizeof(float)));if(SUCCEEDED(result))return std::move(*this);return make_unexpected<hresult_error>(_T(__FUNCTION__), result);}
__declspec(property(put=set_blue)) std::vector<float> blue;
expected<self&, hresult_error> set_alpha(const std::vector<float>& v = {0.f, 1.f})& {if(v.empty()){const auto result = this->set(D2D1_TABLETRANSFER_PROP_ALPHA_DISABLE, TRUE);if(result)return *this ;return make_unexpected(std::move(result.error()));}for(auto&& x : v)if(x < 0.f || 1.f < x)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG);const auto result = (*this)->SetValue(D2D1_TABLETRANSFER_PROP_ALPHA_TABLE, reinterpret_cast<const BYTE*>(v.data()), static_cast<UINT32>(v.size() * sizeof(float)));if(SUCCEEDED(result))return *this ;return make_unexpected<hresult_error>(_T(__FUNCTION__), result);}
expected<self , hresult_error> set_alpha(const std::vector<float>& v = {0.f, 1.f})&&{if(v.empty()){const auto result = this->set(D2D1_TABLETRANSFER_PROP_ALPHA_DISABLE, TRUE);if(result)return std::move(*this);return make_unexpected(std::move(result.error()));}for(auto&& x : v)if(x < 0.f || 1.f < x)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG);const auto result = (*this)->SetValue(D2D1_TABLETRANSFER_PROP_ALPHA_TABLE, reinterpret_cast<const BYTE*>(v.data()), static_cast<UINT32>(v.size() * sizeof(float)));if(SUCCEEDED(result))return std::move(*this);return make_unexpected<hresult_error>(_T(__FUNCTION__), result);}
__declspec(property(put=set_alpha)) std::vector<float> alpha;
PROPERTYDECL(clamp_output, D2D1_TABLETRANSFER_PROP_CLAMP_OUTPUT, bool, false, , v ? TRUE : FALSE)
};
//(Win10)CLSID_D2D1Tint
struct unpremultiply : impl<unpremultiply, CLSID_D2D1UnPremultiply>{
using impl::impl;
using impl::operator|=;
};
//(Win10)CLSID_D2D1YCbCr
};
using color_management = color::color_management;
using color_matrix = color::color_matrix;
using discrete_transfer = color::discrete_transfer;
using dpi_compensation = color::dpi_compensation;
using gamma_transfer = color::gamma_transfer;
using hue_rotation = color::hue_rotation;
using linear_transfer = color::linear_transfer;
using opacity_metadata = color::opacity_metadata;
using premultiply = color::premultiply;
using saturation = color::saturation;
using table_transfer = color::table_transfer;
using unpremultiply = color::unpremultiply;
struct composition{
composition() = delete;
//(Win10)CLSID_D2D1AlphaMask
struct arithmetic_composite : impl<arithmetic_composite, CLSID_D2D1ArithmeticComposite>{
using impl::impl;
auto operator[](_In_range_(0, 1) UINT32 i){if(i > 1U)throw std::invalid_argument(__FUNCTION__);return impl::operator[](i);}
PROPERTYDECL(coefficients, D2D1_ARITHMETICCOMPOSITE_PROP_COEFFICIENTS, const D2D1_VECTOR_4F&, D2D1::Vector4F(1.f, 0.f, 0.f, 0.f), , v )
PROPERTYDECL(clamp_output, D2D1_ARITHMETICCOMPOSITE_PROP_CLAMP_OUTPUT, bool, false, , v ? TRUE : FALSE)
};
struct blend : impl<blend, CLSID_D2D1Blend>{
using impl::impl;
auto operator[](_In_range_(0, 1) UINT32 i){if(i > 1U)throw std::invalid_argument(__FUNCTION__);return impl::operator[](i);}
PROPERTYDECL(mode, D2D1_BLEND_PROP_MODE, D2D1_BLEND_MODE, D2D1_BLEND_MODE_MULTIPLY, , v)
};
struct composite : impl<composite, CLSID_D2D1Composite>{
using impl::impl;
using impl::operator[];
PROPERTYDECL(mode, D2D1_COMPOSITE_PROP_MODE, D2D1_COMPOSITE_MODE, D2D1_COMPOSITE_MODE_SOURCE_OVER, , v)
};
//(Win10)CLSID_D2D1CrossFade
};
using arithmetic_composite = composition::arithmetic_composite;
using blend = composition::blend;
using composite = composition::composite;
struct filter{
filter() = delete;
class convolve_matrix : public impl<convolve_matrix, CLSID_D2D1ConvolveMatrix>{
class _kernel_size{
convolve_matrix& cm;
public:
explicit _kernel_size(convolve_matrix& cm_):cm{cm_}{}
expected<convolve_matrix&, hresult_error> set_x(UINT32 v = 3u)& {const auto result = cm.set(D2D1_CONVOLVEMATRIX_PROP_KERNEL_SIZE_X, v);if(result)return cm ;return make_unexpected(std::move(result.error()));}
expected<convolve_matrix , hresult_error> set_x(UINT32 v = 3u)&&{const auto result = cm.set(D2D1_CONVOLVEMATRIX_PROP_KERNEL_SIZE_X, v);if(result)return std::move(cm);return make_unexpected(std::move(result.error()));}
__declspec(property(put=set_x)) UINT32 x;
expected<convolve_matrix&, hresult_error> set_y(UINT32 v = 3u)& {const auto result = cm.set(D2D1_CONVOLVEMATRIX_PROP_KERNEL_SIZE_Y, v);if(result)return cm ;return make_unexpected(std::move(result.error()));}
expected<convolve_matrix , hresult_error> set_y(UINT32 v = 3u)&&{const auto result = cm.set(D2D1_CONVOLVEMATRIX_PROP_KERNEL_SIZE_Y, v);if(result)return std::move(cm);return make_unexpected(std::move(result.error()));}
__declspec(property(put=set_y)) UINT32 y;
};
friend _kernel_size;
public:
using impl::impl;
using impl::operator|=;
PROPERTYDECL(kernel_unit_length, D2D1_CONVOLVEMATRIX_PROP_KERNEL_UNIT_LENGTH, float, 1.f, , v )
PROPERTYDECL(scale_mode, D2D1_CONVOLVEMATRIX_PROP_SCALE_MODE, D2D1_CONVOLVEMATRIX_SCALE_MODE, D2D1_CONVOLVEMATRIX_SCALE_MODE_LINEAR, , v )
expected<self&, hresult_error> set_kernel_size_x(UINT32 v = 3u)& {const auto result = this->set(D2D1_CONVOLVEMATRIX_PROP_KERNEL_SIZE_X, v);if(result)return *this ;return make_unexpected(std::move(result.error()));}
expected<self , hresult_error> set_kernel_size_x(UINT32 v = 3u)&&{const auto result = this->set(D2D1_CONVOLVEMATRIX_PROP_KERNEL_SIZE_X, v);if(result)return std::move(*this);return make_unexpected(std::move(result.error()));}
expected<self&, hresult_error> set_kernel_size_y(UINT32 v = 3u)& {const auto result = this->set(D2D1_CONVOLVEMATRIX_PROP_KERNEL_SIZE_Y, v);if(result)return *this ;return make_unexpected(std::move(result.error()));}
expected<self , hresult_error> set_kernel_size_y(UINT32 v = 3u)&&{const auto result = this->set(D2D1_CONVOLVEMATRIX_PROP_KERNEL_SIZE_Y, v);if(result)return std::move(*this);return make_unexpected(std::move(result.error()));}
_kernel_size get_kernel_size()noexcept{return _kernel_size{*this};}
expected<self&, hresult_error> set_kernel_size(const two_dim::wh<UINT32>& v = {3, 3})& {return set_kernel_size_x(v.w).bind([&v](self& s){return s .set_kernel_size_y(v.h);});}
expected<self , hresult_error> set_kernel_size(const two_dim::wh<UINT32>& v = {3, 3})&&{return std::move(*this).set_kernel_size_x(v.w).bind([&v](self&& s){return std::move(s).set_kernel_size_y(v.h);});}
__declspec(property(get=get_kernel_size, put=set_kernel_size)) _kernel_size kernel_size;
expected<self&, hresult_error> set_kernel_matrix(const std::vector<float>& v = {0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f})& {const auto result = (*this)->SetValue(D2D1_CONVOLVEMATRIX_PROP_KERNEL_MATRIX, reinterpret_cast<const BYTE*>(v.data()), static_cast<UINT32>(v.size() * sizeof(float)));if(SUCCEEDED(result))return *this ;return make_unexpected<hresult_error>(_T(__FUNCTION__), result);}
expected<self , hresult_error> set_kernel_matrix(const std::vector<float>& v = {0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f})&&{const auto result = (*this)->SetValue(D2D1_CONVOLVEMATRIX_PROP_KERNEL_MATRIX, reinterpret_cast<const BYTE*>(v.data()), static_cast<UINT32>(v.size() * sizeof(float)));if(SUCCEEDED(result))return std::move(*this);return make_unexpected<hresult_error>(_T(__FUNCTION__), result);}
__declspec(property(put=set_kernel_matrix)) std::vector<float> kernel_matrix;
PROPERTYDECL(divisor, D2D1_CONVOLVEMATRIX_PROP_DIVISOR, float, 1.f, , v )
PROPERTYDECL(bias, D2D1_CONVOLVEMATRIX_PROP_BIAS, float, 0.f, , v )
PROPERTYDECL(kernel_offset, D2D1_CONVOLVEMATRIX_PROP_KERNEL_OFFSET, const D2D1_VECTOR_2F&, D2D1::Vector2F(0.f, 0.f), , v )
PROPERTYDECL(preserve_alpha, D2D1_CONVOLVEMATRIX_PROP_PRESERVE_ALPHA, bool, false, , v ? TRUE : FALSE)
PROPERTYDECL(border_mode, D2D1_CONVOLVEMATRIX_PROP_BORDER_MODE, D2D1_BORDER_MODE, D2D1_BORDER_MODE_SOFT, , v )
PROPERTYDECL(clamp_output, D2D1_CONVOLVEMATRIX_PROP_CLAMP_OUTPUT, bool, false, , v ? TRUE : FALSE)
};
struct directional_blur : impl<directional_blur, CLSID_D2D1DirectionalBlur>{
using impl::impl;
using impl::operator|=;
PROPERTYDECL(standard_deviation, D2D1_DIRECTIONALBLUR_PROP_STANDARD_DEVIATION, float, 3.f, , v)
PROPERTYDECL(angle, D2D1_DIRECTIONALBLUR_PROP_ANGLE, float, 0.f, , v)
PROPERTYDECL(optimization, D2D1_DIRECTIONALBLUR_PROP_OPTIMIZATION, D2D1_DIRECTIONALBLUR_OPTIMIZATION, D2D1_DIRECTIONALBLUR_OPTIMIZATION_BALANCED, , v)
PROPERTYDECL(border_mode, D2D1_DIRECTIONALBLUR_PROP_BORDER_MODE, D2D1_BORDER_MODE, D2D1_BORDER_MODE_SOFT, , v)
};
//(Win10)CLSID_D2D1EdgeDetection
struct gaussian_blur : impl<gaussian_blur, CLSID_D2D1GaussianBlur>{
using impl::impl;
using impl::operator|=;
PROPERTYDECL(standard_deviation, D2D1_GAUSSIANBLUR_PROP_STANDARD_DEVIATION, FLOAT, 3.f, , v)
PROPERTYDECL(optimization, D2D1_GAUSSIANBLUR_PROP_OPTIMIZATION, D2D1_GAUSSIANBLUR_OPTIMIZATION, D2D1_GAUSSIANBLUR_OPTIMIZATION_BALANCED, , v)
PROPERTYDECL(border_mode, D2D1_GAUSSIANBLUR_PROP_BORDER_MODE, D2D1_BORDER_MODE, D2D1_BORDER_MODE_SOFT, , v)
};
struct morphology : impl<morphology, CLSID_D2D1Morphology>{
using impl::impl;
using impl::operator|=;
PROPERTYDECL(mode, D2D1_MORPHOLOGY_PROP_MODE, D2D1_MORPHOLOGY_MODE, D2D1_MORPHOLOGY_MODE_ERODE, , v)
PROPERTYDECL(width, D2D1_MORPHOLOGY_PROP_WIDTH, UINT, 1, if(v < 1 || 100 < v)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG), v)
PROPERTYDECL(height, D2D1_MORPHOLOGY_PROP_HEIGHT, UINT, 1, if(v < 1 || 100 < v)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG), v)
expected<self&, hresult_error> set_kernel_size(const two_dim::wh<UINT>& v = {1, 1})& {return set_width(v.w).bind([&v](self& s){return s .set_height(v.h);});}
expected<self , hresult_error> set_kernel_size(const two_dim::wh<UINT>& v = {1, 1})&&{return std::move(*this).set_width(v.w).bind([&v](self&& s){return std::move(s).set_height(v.h);});}
__declspec(property(put=set_kernel_size)) two_dim::wh<UINT> kernel_size;
};
};
using convolve_matrix = filter::convolve_matrix;
using directional_blur = filter::directional_blur;
using gaussian_blur = filter::gaussian_blur;
using morphology = filter::morphology;
struct lighting_and_stylizing{
lighting_and_stylizing() = delete;
struct displacement_map : impl<displacement_map, CLSID_D2D1DisplacementMap>{
using impl::impl;
auto operator[](_In_range_(0, 1) UINT32 i){if(i > 1U)throw std::invalid_argument(__FUNCTION__);return impl::operator[](i);}
PROPERTYDECL(scale, D2D1_DISPLACEMENTMAP_PROP_SCALE, float, 0.f, , v)
PROPERTYDECL(x_channnel_select, D2D1_DISPLACEMENTMAP_PROP_X_CHANNEL_SELECT, D2D1_CHANNEL_SELECTOR, D2D1_CHANNEL_SELECTOR_A, , v)
PROPERTYDECL(y_channnel_select, D2D1_DISPLACEMENTMAP_PROP_Y_CHANNEL_SELECT, D2D1_CHANNEL_SELECTOR, D2D1_CHANNEL_SELECTOR_A, , v)
};
struct distant_diffuse : impl<distant_diffuse, CLSID_D2D1DistantDiffuse>{
using impl::impl;
using impl::operator|=;
PROPERTYDECL(azimuth, D2D1_DISTANTDIFFUSE_PROP_AZIMUTH, float, 0.f, if(v < 0.f || 360.f < v)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG), v)
PROPERTYDECL(elevation, D2D1_DISTANTDIFFUSE_PROP_ELEVATION, float, 0.f, if(v < 0.f || 360.f < v)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG), v)
PROPERTYDECL(diffuse_constant, D2D1_DISTANTDIFFUSE_PROP_DIFFUSE_CONSTANT, float, 1.f, if(v < 0.f || 10000.f < v)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG), v)
PROPERTYDECL(surface_scale, D2D1_DISTANTDIFFUSE_PROP_SURFACE_SCALE, float, 1.f, if(v < 0.f || 10000.f < v)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG), v)
PROPERTYDECL(color, D2D1_DISTANTDIFFUSE_PROP_COLOR, const D2D1_VECTOR_3F&, D2D1::Vector3F(1.f, 1.f, 1.f), , v)
expected<self&, hresult_error> set_color(const D2D1_COLOR_F& v = {1.f, 1.f, 1.f, 1.f})& {return set_color(D2D1::Vector3F(v.r * v.a, v.g * v.a, v.b * v.a));}
expected<self , hresult_error> set_color(const D2D1_COLOR_F& v = {1.f, 1.f, 1.f, 1.f})&&{return std::move(*this).set_color(D2D1::Vector3F(v.r * v.a, v.g * v.a, v.b * v.a));}
expected<self&, hresult_error> set_color(const D2D1::ColorF::Enum& v = D2D1::ColorF::White)& {return set_color(D2D1::ColorF(v));}
expected<self , hresult_error> set_color(const D2D1::ColorF::Enum& v = D2D1::ColorF::White)&&{return std::move(*this).set_color(D2D1::ColorF(v));}
PROPERTYDECL(kernel_unit_length, D2D1_DISTANTDIFFUSE_PROP_KERNEL_UNIT_LENGTH, const D2D1_VECTOR_2F&, D2D1::Vector2F(1.f, 1.f), , v)
PROPERTYDECL(scale_mode, D2D1_DISTANTDIFFUSE_PROP_SCALE_MODE, D2D1_DISTANTDIFFUSE_SCALE_MODE, D2D1_DISTANTDIFFUSE_SCALE_MODE_LINEAR, , v)
};
struct distant_specular : impl<distant_specular, CLSID_D2D1DistantSpecular>{
using impl::impl;
using impl::operator|=;
PROPERTYDECL(azimuth, D2D1_DISTANTSPECULAR_PROP_AZIMUTH, float, 0.f, if(v < 0.f || 360.f < v)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG), v)
PROPERTYDECL(elevation, D2D1_DISTANTSPECULAR_PROP_ELEVATION, float, 0.f, if(v < 0.f || 360.f < v)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG), v)
PROPERTYDECL(specular_exponent, D2D1_DISTANTSPECULAR_PROP_SPECULAR_EXPONENT, float, 1.f, if(v < 1.f || 128.f < v)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG), v)
PROPERTYDECL(specular_constant, D2D1_DISTANTSPECULAR_PROP_SPECULAR_CONSTANT, float, 1.f, if(v < 0.f || 10000.f < v)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG), v)
PROPERTYDECL(surface_scale, D2D1_DISTANTSPECULAR_PROP_SURFACE_SCALE, float, 1.f, if(v < 0.f || 10000.f < v)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG), v)
PROPERTYDECL(color, D2D1_DISTANTSPECULAR_PROP_COLOR, const D2D1_VECTOR_3F&, D2D1::Vector3F(1.f, 1.f, 1.f), , v)
expected<self&, hresult_error> set_color(const D2D1_COLOR_F& v = {1.f, 1.f, 1.f, 1.f})& {return set_color(D2D1::Vector3F(v.r * v.a, v.g * v.a, v.b * v.a));}
expected<self , hresult_error> set_color(const D2D1_COLOR_F& v = {1.f, 1.f, 1.f, 1.f})&&{return std::move(*this).set_color(D2D1::Vector3F(v.r * v.a, v.g * v.a, v.b * v.a));}
expected<self&, hresult_error> set_color(const D2D1::ColorF::Enum& v = D2D1::ColorF::White)& {return set_color(D2D1::ColorF(v));}
expected<self , hresult_error> set_color(const D2D1::ColorF::Enum& v = D2D1::ColorF::White)&&{return std::move(*this).set_color(D2D1::ColorF(v));}
PROPERTYDECL(kernel_unit_length, D2D1_DISTANTSPECULAR_PROP_KERNEL_UNIT_LENGTH, const D2D1_VECTOR_2F&, D2D1::Vector2F(1.f, 1.f), , v)
PROPERTYDECL(scale_mode, D2D1_DISTANTSPECULAR_PROP_SCALE_MODE, D2D1_DISTANTSPECULAR_SCALE_MODE, D2D1_DISTANTSPECULAR_SCALE_MODE_LINEAR, , v)
};
//(Win10)CLSID_D2D1Emboss
struct point_diffuse : impl<point_diffuse, CLSID_D2D1PointDiffuse>{
using impl::impl;
using impl::operator|=;
PROPERTYDECL(light_position, D2D1_POINTDIFFUSE_PROP_LIGHT_POSITION, const D2D1_VECTOR_3F&, D2D1::Vector3F(0.f, 0.f, 0.f), , v)
PROPERTYDECL(diffuse_constant, D2D1_POINTDIFFUSE_PROP_DIFFUSE_CONSTANT, float, 1.f, if(v < 0.f || 10000.f < v)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG), v)
PROPERTYDECL(surface_scale, D2D1_POINTDIFFUSE_PROP_SURFACE_SCALE, float, 1.f, if(v < 0.f || 10000.f < v)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG), v)
PROPERTYDECL(color, D2D1_POINTDIFFUSE_PROP_COLOR, const D2D1_VECTOR_3F&, D2D1::Vector3F(1.f, 1.f, 1.f), , v)
expected<self&, hresult_error> set_color(const D2D1_COLOR_F& v = {1.f, 1.f, 1.f, 1.f})& {return set_color(D2D1::Vector3F(v.r * v.a, v.g * v.a, v.b * v.a));}
expected<self , hresult_error> set_color(const D2D1_COLOR_F& v = {1.f, 1.f, 1.f, 1.f})&&{return std::move(*this).set_color(D2D1::Vector3F(v.r * v.a, v.g * v.a, v.b * v.a));}
expected<self&, hresult_error> set_color(const D2D1::ColorF::Enum& v = D2D1::ColorF::White)& {return set_color(D2D1::ColorF(v));}
expected<self , hresult_error> set_color(const D2D1::ColorF::Enum& v = D2D1::ColorF::White)&&{return std::move(*this).set_color(D2D1::ColorF(v));}
PROPERTYDECL(kernel_unit_length, D2D1_POINTDIFFUSE_PROP_KERNEL_UNIT_LENGTH, const D2D1_VECTOR_2F&, D2D1::Vector2F(1.f, 1.f), , v)
PROPERTYDECL(scale_mode, D2D1_POINTDIFFUSE_PROP_SCALE_MODE, D2D1_POINTDIFFUSE_SCALE_MODE, D2D1_POINTDIFFUSE_SCALE_MODE_LINEAR, , v)
};
struct point_specular : impl<point_specular, CLSID_D2D1PointSpecular>{
using impl::impl;
using impl::operator|=;
PROPERTYDECL(light_position, D2D1_POINTSPECULAR_PROP_LIGHT_POSITION, const D2D1_VECTOR_3F&, D2D1::Vector3F(0.f, 0.f, 0.f), , v)
PROPERTYDECL(specular_exponent, D2D1_POINTSPECULAR_PROP_SPECULAR_EXPONENT, float, 1.f, if(v < 1.f || 128.f < v)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG), v)
PROPERTYDECL(specular_constant, D2D1_POINTSPECULAR_PROP_SPECULAR_CONSTANT, float, 1.f, if(v < 0.f || 10000.f < v)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG), v)
PROPERTYDECL(surface_scale, D2D1_POINTSPECULAR_PROP_SURFACE_SCALE, float, 1.f, if(v < 0.f || 10000.f < v)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG), v)
PROPERTYDECL(color, D2D1_POINTSPECULAR_PROP_COLOR, const D2D1_VECTOR_3F&, D2D1::Vector3F(1.f, 1.f, 1.f), , v)
expected<self&, hresult_error> set_color(const D2D1_COLOR_F& v = {1.f, 1.f, 1.f, 1.f})& {return set_color(D2D1::Vector3F(v.r * v.a, v.g * v.a, v.b * v.a));}
expected<self , hresult_error> set_color(const D2D1_COLOR_F& v = {1.f, 1.f, 1.f, 1.f})&&{return std::move(*this).set_color(D2D1::Vector3F(v.r * v.a, v.g * v.a, v.b * v.a));}
expected<self&, hresult_error> set_color(const D2D1::ColorF::Enum& v = D2D1::ColorF::White)& {return set_color(D2D1::ColorF(v));}
expected<self , hresult_error> set_color(const D2D1::ColorF::Enum& v = D2D1::ColorF::White)&&{return std::move(*this).set_color(D2D1::ColorF(v));}
PROPERTYDECL(kernel_unit_length, D2D1_POINTSPECULAR_PROP_KERNEL_UNIT_LENGTH, const D2D1_VECTOR_2F&, D2D1::Vector2F(1.f, 1.f), , v)
PROPERTYDECL(scale_mode, D2D1_POINTSPECULAR_PROP_SCALE_MODE, D2D1_POINTSPECULAR_SCALE_MODE, D2D1_POINTSPECULAR_SCALE_MODE_LINEAR, , v)
};
//(Win10)CLSID_D2D1Posterize
struct shadow : impl<shadow, CLSID_D2D1Shadow>{
using impl::impl;
using impl::operator|=;
PROPERTYDECL(blur_standard_deviation, D2D1_SHADOW_PROP_BLUR_STANDARD_DEVIATION, float, 3.f, , v)
PROPERTYDECL(color, D2D1_SHADOW_PROP_COLOR , const D2D1_VECTOR_4F&, D2D1::Vector4F(0.f, 0.f, 0.f, 1.f), , v)
expected<self&, hresult_error> set_color(const D2D1_COLOR_F& v = {0.f, 0.f, 0.f, 1.f})& {return set_color(D2D1::Vector4F(v.r, v.g, v.b, v.a));}
expected<self , hresult_error> set_color(const D2D1_COLOR_F& v = {0.f, 0.f, 0.f, 1.f})&&{return std::move(*this).set_color(D2D1::Vector4F(v.r, v.g, v.b, v.a));}
expected<self&, hresult_error> set_color(const D2D1::ColorF::Enum& v = D2D1::ColorF::Black)& {return set_color(D2D1::ColorF(v));}
expected<self , hresult_error> set_color(const D2D1::ColorF::Enum& v = D2D1::ColorF::Black)&&{return std::move(*this).set_color(D2D1::ColorF(v));}
PROPERTYDECL(optimization, D2D1_SHADOW_PROP_OPTIMIZATION , D2D1_SHADOW_OPTIMIZATION, D2D1_SHADOW_OPTIMIZATION_BALANCED, , v)
};
struct spot_diffuse : impl<spot_diffuse, CLSID_D2D1SpotDiffuse>{
using impl::impl;
using impl::operator|=;
PROPERTYDECL(light_position, D2D1_SPOTDIFFUSE_PROP_LIGHT_POSITION, const D2D1_VECTOR_3F&, D2D1::Vector3F(0.f, 0.f, 0.f), , v)
PROPERTYDECL(points_at, D2D1_SPOTDIFFUSE_PROP_POINTS_AT, const D2D1_VECTOR_3F&, D2D1::Vector3F(0.f, 0.f, 0.f), , v)
PROPERTYDECL(focus, D2D1_SPOTDIFFUSE_PROP_FOCUS, float, 1.f, if(v < 0.f || 200.f < v)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG), v)
PROPERTYDECL(limiting_cone_angle, D2D1_SPOTDIFFUSE_PROP_LIMITING_CONE_ANGLE, float, 90.f, if(v < 0.f || 90.f < v)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG), v)
PROPERTYDECL(diffuse_constant, D2D1_SPOTDIFFUSE_PROP_DIFFUSE_CONSTANT, float, 1.f, if(v < 0.f || 10000.f < v)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG), v)
PROPERTYDECL(surface_scale, D2D1_SPOTDIFFUSE_PROP_SURFACE_SCALE, float, 1.f, if(v < 0.f || 10000.f < v)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG), v)
PROPERTYDECL(color, D2D1_SPOTDIFFUSE_PROP_COLOR, const D2D1_VECTOR_3F&, D2D1::Vector3F(1.f, 1.f, 1.f), , v)
expected<self&, hresult_error> set_color(const D2D1_COLOR_F& v = {1.f, 1.f, 1.f, 1.f})& {return set_color(D2D1::Vector3F(v.r * v.a, v.g * v.a, v.b * v.a));}
expected<self , hresult_error> set_color(const D2D1_COLOR_F& v = {1.f, 1.f, 1.f, 1.f})&&{return std::move(*this).set_color(D2D1::Vector3F(v.r * v.a, v.g * v.a, v.b * v.a));}
expected<self&, hresult_error> set_color(const D2D1::ColorF::Enum& v = D2D1::ColorF::White)& {return set_color(D2D1::ColorF(v));}
expected<self , hresult_error> set_color(const D2D1::ColorF::Enum& v = D2D1::ColorF::White)&&{return std::move(*this).set_color(D2D1::ColorF(v));}
PROPERTYDECL(kernel_unit_length, D2D1_SPOTDIFFUSE_PROP_KERNEL_UNIT_LENGTH, const D2D1_VECTOR_2F&, D2D1::Vector2F(1.f, 1.f), , v)
PROPERTYDECL(scale_mode, D2D1_SPOTDIFFUSE_PROP_SCALE_MODE, D2D1_SPOTDIFFUSE_SCALE_MODE, D2D1_SPOTDIFFUSE_SCALE_MODE_LINEAR, , v)
};
struct spot_specular : impl<spot_specular, CLSID_D2D1SpotSpecular>{
using impl::impl;
using impl::operator|=;
PROPERTYDECL(light_position, D2D1_SPOTSPECULAR_PROP_LIGHT_POSITION, const D2D1_VECTOR_3F&, D2D1::Vector3F(0.f, 0.f, 0.f), , v)
PROPERTYDECL(points_at, D2D1_SPOTSPECULAR_PROP_POINTS_AT, const D2D1_VECTOR_3F&, D2D1::Vector3F(0.f, 0.f, 0.f), , v)
PROPERTYDECL(focus, D2D1_SPOTSPECULAR_PROP_FOCUS, float, 1.f, if(v < 0.f || 200.f < v)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG), v)
PROPERTYDECL(limiting_cone_angle, D2D1_SPOTSPECULAR_PROP_LIMITING_CONE_ANGLE, float, 90.f, if(v < 0.f || 90.f < v)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG), v)
PROPERTYDECL(specular_exponent, D2D1_SPOTSPECULAR_PROP_SPECULAR_EXPONENT, float, 1.f, if(v < 1.f || 128.f < v)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG), v)
PROPERTYDECL(specular_constant, D2D1_SPOTSPECULAR_PROP_SPECULAR_CONSTANT, float, 1.f, if(v < 0.f || 10000.f < v)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG), v)
PROPERTYDECL(surface_scale, D2D1_SPOTSPECULAR_PROP_SURFACE_SCALE, float, 1.f, if(v < 0.f || 10000.f < v)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG), v)
PROPERTYDECL(color, D2D1_SPOTSPECULAR_PROP_COLOR, const D2D1_VECTOR_3F&, D2D1::Vector3F(1.f, 1.f, 1.f), , v)
expected<self&, hresult_error> set_color(const D2D1_COLOR_F& v = {1.f, 1.f, 1.f, 1.f})& {return set_color(D2D1::Vector3F(v.r * v.a, v.g * v.a, v.b * v.a));}
expected<self , hresult_error> set_color(const D2D1_COLOR_F& v = {1.f, 1.f, 1.f, 1.f})&&{return std::move(*this).set_color(D2D1::Vector3F(v.r * v.a, v.g * v.a, v.b * v.a));}
expected<self&, hresult_error> set_color(const D2D1::ColorF::Enum& v = D2D1::ColorF::White)& {return set_color(D2D1::ColorF(v));}
expected<self , hresult_error> set_color(const D2D1::ColorF::Enum& v = D2D1::ColorF::White)&&{return std::move(*this).set_color(D2D1::ColorF(v));}
PROPERTYDECL(kernel_unit_length, D2D1_SPOTSPECULAR_PROP_KERNEL_UNIT_LENGTH, const D2D1_VECTOR_2F&, D2D1::Vector2F(1.f, 1.f), , v)
PROPERTYDECL(scale_mode, D2D1_SPOTSPECULAR_PROP_SCALE_MODE, D2D1_SPOTSPECULAR_SCALE_MODE, D2D1_SPOTSPECULAR_SCALE_MODE_LINEAR, , v)
};
};
using displacement_map = lighting_and_stylizing::displacement_map;
using distant_diffuse = lighting_and_stylizing::distant_diffuse;
using distant_specular = lighting_and_stylizing::distant_specular;
using point_diffuse = lighting_and_stylizing::point_diffuse;
using point_specular = lighting_and_stylizing::point_specular;
using shadow = lighting_and_stylizing::shadow;
using spot_diffuse = lighting_and_stylizing::spot_diffuse;
using spot_specular = lighting_and_stylizing::spot_specular;
struct photo{
photo() = delete;
struct brightness : impl<brightness, CLSID_D2D1Brightness>{
using impl::impl;
using impl::operator|=;
PROPERTYDECL(white_point, D2D1_BRIGHTNESS_PROP_WHITE_POINT, const D2D1_VECTOR_2F&, D2D1::Vector2F(1.f, 1.f), if(v.x < 0.f || 1.f < v.x || v.y < 0.f || 1.f < v.y)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG), v)
PROPERTYDECL(black_point, D2D1_BRIGHTNESS_PROP_BLACK_POINT, const D2D1_VECTOR_2F&, D2D1::Vector2F(0.f, 0.f), if(v.x < 0.f || 1.f < v.x || v.y < 0.f || 1.f < v.y)return make_unexpected<hresult_error>(_T(__FUNCTION__), E_INVALIDARG), v)
};
//(Win10)CLSID_D2D1Contrast
//(Win10)CLSID_D2D1Exposure
//(Win10)CLSID_D2D1Glayscale
//(Win10)CLSID_D2D1HilightsShadows
struct histogram : impl<histogram, CLSID_D2D1Histogram>{
using impl::impl;
using impl::operator|=;
PROPERTYDECL(num_bins, D2D1_HISTOGRAM_PROP_NUM_BINS, UINT32, 256, , v)
PROPERTYDECL(channel_select, D2D1_HISTOGRAM_PROP_CHANNEL_SELECT, D2D1_CHANNEL_SELECTOR, D2D1_CHANNEL_SELECTOR_R, , v)
expected<std::vector<float>, hresult_error> output()const{
UINT32 c;
{
const auto hr = (*this)->GetValue(D2D1_HISTOGRAM_PROP_NUM_BINS, &c);
if(FAILED(hr))
return make_unexpected<hresult_error>(_T(__FUNCTION__), hr);
}
std::vector<float> vec;
vec.resize(c);
const auto hr = (*this)->GetValue(D2D1_HISTOGRAM_PROP_HISTOGRAM_OUTPUT, reinterpret_cast<BYTE*>(vec.data()), c * sizeof(float));
if(FAILED(hr))
return make_unexpected<hresult_error>(_T(__FUNCTION__), hr);
return vec;
}