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
use super::*;
use winapi::um::wingdi::{
GetDeviceCaps, StretchDIBits, BITMAPINFO, BLACKNESS, CAPTUREBLT, DIB_PAL_COLORS,
DIB_RGB_COLORS, DSTINVERT, MERGECOPY, MERGEPAINT, NOMIRRORBITMAP, NOTSRCCOPY,
NOTSRCERASE, PATCOPY, PATINVERT, PATPAINT, SRCAND, SRCCOPY, SRCERASE, SRCINVERT,
SRCPAINT, WHITENESS,
};
#[inline]
pub unsafe fn get_device_caps(hdc: HDC, index: i32) -> i32 {
GetDeviceCaps(hdc, index)
}
#[repr(u32)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DibColors {
Pal = DIB_PAL_COLORS,
RGB = DIB_RGB_COLORS,
}
#[repr(u32)]
#[derive(Debug, Clone, Copy)]
pub enum RasterOp {
Blackness = BLACKNESS,
CaptureBlt = CAPTUREBLT,
DstInvert = DSTINVERT,
MergeCopy = MERGECOPY,
MergePaint = MERGEPAINT,
NoMirrorBitmap = NOMIRRORBITMAP,
NotSrcCopy = NOTSRCCOPY,
NotSrcErase = NOTSRCERASE,
PatCopy = PATCOPY,
PatInvert = PATINVERT,
PatPaint = PATPAINT,
SrcAnd = SRCAND,
SrcCopy = SRCCOPY,
SrcErase = SRCERASE,
SrcInvert = SRCINVERT,
SrcPaint = SRCPAINT,
Whiteness = WHITENESS,
}
impl Default for RasterOp {
fn default() -> Self {
RasterOp::SrcCopy
}
}
#[derive(Debug, Clone, Copy)]
pub struct StretchDIBitsArgs {
pub hdc: HDC,
pub dest: PointSizeRect,
pub src: PointSizeRect,
pub bits: *const c_void,
pub bitmap_info: *const BITMAPINFO,
pub usage: DibColors,
pub raster_op: RasterOp,
}
#[inline]
pub unsafe fn stretch_di_bits(args: StretchDIBitsArgs) -> Option<i32> {
let result = StretchDIBits(
args.hdc,
args.dest.x,
args.dest.y,
args.dest.width,
args.dest.height,
args.src.x,
args.src.y,
args.src.width,
args.src.height,
args.bits as *const _,
args.bitmap_info,
args.usage as u32,
args.raster_op as u32,
);
if result >= 0 {
Some(result)
} else {
None
}
}