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
/// The META_STRETCHDIB Record specifies the transfer of color data from a block
/// of pixels in device-independent format according to a raster operation, with
/// possible expansion or contraction.
///
/// The source of the color data is a DIB, and the destination of the transfer
/// is the current output region in the playback device context.
#[derive(Clone, Debug)]
pub struct META_STRETCHDIB {
/// RecordSize (4 bytes): A 32-bit unsigned integer that defines the number
/// of WORD structures, defined in [MS-DTYP] section 2.2.61, in the record.
pub record_size: crate::wmf::parser::RecordSize,
/// RecordFunction (2 bytes): A 16-bit unsigned integer that defines this
/// WMF record type. The lower byte MUST match the lower byte of the
/// RecordType Enumeration table value META_STRETCHDIB.
pub record_function: u16,
/// RasterOperation (4 bytes): A 32-bit unsigned integer that defines how
/// the source pixels, the current brush in the playback device context,
/// and the destination pixels are to be combined to form the new image.
/// This code MUST be one of the values in the Ternary Raster Operation
/// Enumeration.
pub raster_operation: crate::wmf::parser::TernaryRasterOperation,
/// ColorUsage (2 bytes): A 16-bit unsigned integer that defines whether
/// the Colors field of the DIB contains explicit RGB values or indexes
/// into a palette. This value MUST be in the ColorUsage Enumeration.
pub color_usage: crate::wmf::parser::ColorUsage,
/// SrcHeight (2 bytes): A 16-bit signed integer that defines the height,
/// in logical units, of the source rectangle.
pub src_height: i16,
/// SrcWidth (2 bytes): A 16-bit signed integer that defines the width, in
/// logical units, of the source rectangle.
pub src_width: i16,
/// YSrc (2 bytes): A 16-bit signed integer that defines the y-coordinate,
/// in logical units, of the source rectangle.
pub y_src: i16,
/// XSrc (2 bytes): A 16-bit signed integer that defines the x-coordinate,
/// in logical units, of the source rectangle.
pub x_src: i16,
/// DestHeight (2 bytes): A 16-bit signed integer that defines the height,
/// in logical units, of the destination rectangle.
pub dest_height: i16,
/// DestWidth (2 bytes): A 16-bit signed integer that defines the width, in
/// logical units, of the destination rectangle.
pub dest_width: i16,
/// yDst (2 bytes): A 16-bit signed integer that defines the y-coordinate,
/// in logical units, of the upper-left corner of the destination
/// rectangle.
pub y_dst: i16,
/// xDst (2 bytes): A 16-bit signed integer that defines the x-coordinate,
/// in logical units, of the upper-left corner of the destination
/// rectangle.
pub x_dst: i16,
/// DIB (variable): A variable-sized DeviceIndependentBitmap Object that is
/// the source of the color data.
///
/// If the image format is JPEG or PNG, the ColorUsage field in this record
/// MUST be set to DIB_RGB_COLORS, and the RasterOperation field MUST be
/// set to SRCCOPY.
pub dib: crate::wmf::parser::DeviceIndependentBitmap,
}
impl META_STRETCHDIB {
#[cfg_attr(feature = "tracing", tracing::instrument(
level = tracing::Level::TRACE,
skip_all,
fields(
%record_size,
record_function = %format!("{record_function:#06X}"),
),
err(level = tracing::Level::ERROR, Display),
))]
pub fn parse<R: crate::wmf::Read>(
buf: &mut R,
mut record_size: crate::wmf::parser::RecordSize,
record_function: u16,
) -> Result<Self, crate::wmf::parser::ParseError> {
crate::wmf::parser::records::check_lower_byte_matches(
record_function,
crate::wmf::parser::RecordType::META_STRETCHDIB,
)?;
let (
(raster_operation, raster_operation_bytes),
(color_usage, color_usage_bytes),
(src_height, src_height_bytes),
(src_width, src_width_bytes),
(y_src, y_src_bytes),
(x_src, x_src_bytes),
(dest_height, dest_height_bytes),
(dest_width, dest_width_bytes),
(y_dst, y_dst_bytes),
(x_dst, x_dst_bytes),
) = (
crate::wmf::parser::TernaryRasterOperation::parse(buf)?,
crate::wmf::parser::ColorUsage::parse(buf)?,
crate::wmf::parser::read_i16_from_le_bytes(buf)?,
crate::wmf::parser::read_i16_from_le_bytes(buf)?,
crate::wmf::parser::read_i16_from_le_bytes(buf)?,
crate::wmf::parser::read_i16_from_le_bytes(buf)?,
crate::wmf::parser::read_i16_from_le_bytes(buf)?,
crate::wmf::parser::read_i16_from_le_bytes(buf)?,
crate::wmf::parser::read_i16_from_le_bytes(buf)?,
crate::wmf::parser::read_i16_from_le_bytes(buf)?,
);
record_size.consume(
raster_operation_bytes
+ color_usage_bytes
+ src_height_bytes
+ src_width_bytes
+ y_src_bytes
+ x_src_bytes
+ dest_height_bytes
+ dest_width_bytes
+ y_dst_bytes
+ x_dst_bytes,
);
let (dib, c) =
crate::wmf::parser::DeviceIndependentBitmap::parse_with_color_usage(buf, color_usage)?;
record_size.consume(c);
crate::wmf::parser::records::consume_remaining_bytes(buf, record_size)?;
Ok(Self {
record_size,
record_function,
raster_operation,
color_usage,
src_height,
src_width,
y_src,
x_src,
dest_height,
dest_width,
y_dst,
x_dst,
dib,
})
}
}