#[derive(Clone, Debug)]
pub enum META_BITBLT {
WithBitmap {
record_size: crate::wmf::parser::RecordSize,
record_function: u16,
raster_operation: crate::wmf::parser::TernaryRasterOperation,
y_src: i16,
x_src: i16,
height: i16,
width: i16,
y_dest: i16,
x_dest: i16,
target: crate::wmf::parser::Bitmap16,
},
WithoutBitmap {
record_size: crate::wmf::parser::RecordSize,
record_function: u16,
raster_operation: crate::wmf::parser::TernaryRasterOperation,
y_src: i16,
x_src: i16,
reserved: [u8; 2],
height: i16,
width: i16,
y_dest: i16,
x_dest: i16,
},
}
impl META_BITBLT {
#[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_BITBLT,
)?;
let (
(raster_operation, raster_operation_bytes),
(y_src, y_src_bytes),
(x_src, x_src_bytes),
) = (
crate::wmf::parser::TernaryRasterOperation::parse(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 + y_src_bytes + x_src_bytes);
let bitmap_specified = u32::from(record_size) != u32::from((record_function >> 8) + 3);
let reserved = if bitmap_specified {
[0; 2]
} else {
let (v, c) = crate::wmf::parser::read::<R, 2>(buf)?;
record_size.consume(c);
v
};
let (
(height, height_bytes),
(width, width_bytes),
(y_dest, y_dest_bytes),
(x_dest, x_dest_bytes),
) = (
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(height_bytes + width_bytes + y_dest_bytes + x_dest_bytes);
let record = if bitmap_specified {
let (target, c) = crate::wmf::parser::Bitmap16::parse(buf)?;
record_size.consume(c);
Self::WithBitmap {
record_size,
record_function,
raster_operation,
y_src,
x_src,
height,
width,
y_dest,
x_dest,
target,
}
} else {
Self::WithoutBitmap {
record_size,
record_function,
raster_operation,
y_src,
x_src,
reserved,
height,
width,
y_dest,
x_dest,
}
};
crate::wmf::parser::records::consume_remaining_bytes(buf, record_size)?;
Ok(record)
}
}