#![allow(dead_code)]
use crate::ascii_array::AsciiArray;
use pack1::*;
pub(super) type FXPT2DOT30 = U32LE;
pub(super) type CIEXYZ = [FXPT2DOT30; 3];
pub(super) type CIEXYZTRIPLE = [CIEXYZ; 3];
pub(super) const BI_RGB: u32 = 0;
pub(super) const BI_RLE8: u32 = 1;
pub(super) const BI_RLE4: u32 = 2;
pub(super) const BI_BITFIELDS: u32 = 3;
pub(super) const BI_ALPHABITFIELDS: u32 = 6;
pub(super) const LCS_GM_ABS_COLORIMETRIC: u32 = 0x00000008;
pub(super) const LCS_GM_BUSINESS: u32 = 0x00000001;
pub(super) const LCS_GM_GRAPHICS: u32 = 0x00000002;
pub(super) const LCS_GM_IMAGES: u32 = 0x00000004;
pub(super) const LCS_CALIBRATED_RGB: u32 = 0x00000000;
pub(super) const LCS_sRGB: u32 = 0x7352_4742;
pub(super) const LCS_WINDOWS_COLOR_SPACE: u32 = 0x5769_6E20;
pub(super) const PROFILE_LINKED: u32 = 0x4C49_4E4B;
pub(super) const PROFILE_EMBEDDED: u32 = 0x4D42_4544;
#[derive(Debug, Clone, Copy, bytemuck::Zeroable, bytemuck::Pod)]
#[repr(C)]
pub(crate) struct BitmapFileHeader {
pub ty: AsciiArray<2>,
pub file_size: U32LE,
pub reserved1: U16LE,
pub reserved2: U16LE,
pub bitmap_offset: U32LE,
}
#[derive(Debug, Clone, Copy, bytemuck::Zeroable, bytemuck::Pod)]
#[repr(C)]
pub(crate) struct BitmapCoreHeader {
pub size: U32LE,
pub width: U16LE,
pub height: U16LE,
pub planes: U16LE,
pub bits_per_pixel: U16LE,
}
#[derive(Debug, Clone, Copy, bytemuck::Zeroable, bytemuck::Pod)]
#[repr(C)]
pub(crate) struct BitmapInfoHeader {
pub size: U32LE,
pub width: I32LE,
pub height: I32LE,
pub planes: U16LE,
pub bits_per_pixel: U16LE,
pub compression: U32LE,
pub image_size: U32LE,
pub pixels_per_meter_x: I32LE,
pub pixels_per_meter_y: I32LE,
pub colors_used: U32LE,
pub important_colors: U32LE,
}
#[derive(Debug, Clone, Copy, bytemuck::Zeroable, bytemuck::Pod)]
#[repr(C)]
pub(crate) struct BitmapV2InfoHeader {
pub size: U32LE,
pub width: I32LE,
pub height: I32LE,
pub planes: U16LE,
pub bits_per_pixel: U16LE,
pub compression: U32LE,
pub image_size: U32LE,
pub pixels_per_meter_x: I32LE,
pub pixels_per_meter_y: I32LE,
pub colors_used: U32LE,
pub important_colors: U32LE,
pub r_mask: U32LE,
pub g_mask: U32LE,
pub b_mask: U32LE,
}
#[derive(Debug, Clone, Copy, bytemuck::Zeroable, bytemuck::Pod)]
#[repr(C)]
pub(crate) struct BitmapV3InfoHeader {
pub size: U32LE,
pub width: I32LE,
pub height: I32LE,
pub planes: U16LE,
pub bits_per_pixel: U16LE,
pub compression: U32LE,
pub image_size: U32LE,
pub pixels_per_meter_x: I32LE,
pub pixels_per_meter_y: I32LE,
pub colors_used: U32LE,
pub important_colors: U32LE,
pub r_mask: U32LE,
pub g_mask: U32LE,
pub b_mask: U32LE,
pub a_mask: U32LE,
}
#[derive(Debug, Clone, Copy, bytemuck::Zeroable, bytemuck::Pod)]
#[repr(C)]
pub(crate) struct BitmapV4Header {
pub size: U32LE,
pub width: I32LE,
pub height: I32LE,
pub planes: U16LE,
pub bits_per_pixel: U16LE,
pub compression: U32LE,
pub image_size: U32LE,
pub pixels_per_meter_x: I32LE,
pub pixels_per_meter_y: I32LE,
pub colors_used: U32LE,
pub important_colors: U32LE,
pub r_mask: U32LE,
pub g_mask: U32LE,
pub b_mask: U32LE,
pub a_mask: U32LE,
pub colorspace_type: U32LE,
pub endpoints: CIEXYZTRIPLE,
pub r_gamma: U32LE,
pub g_gamma: U32LE,
pub b_gamma: U32LE,
}
#[derive(Debug, Clone, Copy, bytemuck::Zeroable, bytemuck::Pod)]
#[repr(C)]
pub(crate) struct BitmapV5Header {
pub size: U32LE,
pub width: I32LE,
pub height: I32LE,
pub planes: U16LE,
pub bits_per_pixel: U16LE,
pub compression: U32LE,
pub image_size: U32LE,
pub pixels_per_meter_x: I32LE,
pub pixels_per_meter_y: I32LE,
pub colors_used: U32LE,
pub important_colors: U32LE,
pub r_mask: U32LE,
pub g_mask: U32LE,
pub b_mask: U32LE,
pub a_mask: U32LE,
pub colorspace_type: U32LE,
pub endpoints: CIEXYZTRIPLE,
pub r_gamma: U32LE,
pub g_gamma: U32LE,
pub b_gamma: U32LE,
pub render_intent: U32LE,
pub color_profile_offset: U32LE,
pub color_profile_size: U32LE,
pub reserved: U32LE,
}
impl From<BitmapCoreHeader> for BitmapV5Header {
fn from(
BitmapCoreHeader { size, width, height, planes, bits_per_pixel }: BitmapCoreHeader,
) -> Self {
Self {
size,
width: i32::from(width.get()).into(),
height: i32::from(height.get()).into(),
planes,
bits_per_pixel,
compression: BI_RGB.into(),
image_size: 0.into(),
pixels_per_meter_x: 0.into(),
pixels_per_meter_y: 0.into(),
colors_used: 0.into(),
important_colors: 0.into(),
r_mask: 0.into(),
g_mask: 0.into(),
b_mask: 0.into(),
a_mask: 0.into(),
colorspace_type: LCS_sRGB.into(),
endpoints: [[0.into(); 3]; 3],
r_gamma: 0.into(),
g_gamma: 0.into(),
b_gamma: 0.into(),
render_intent: LCS_GM_IMAGES.into(),
color_profile_offset: 0.into(),
color_profile_size: 0.into(),
reserved: 0.into(),
}
}
}
impl From<BitmapInfoHeader> for BitmapV5Header {
fn from(
BitmapInfoHeader {
size,
width,
height,
planes,
bits_per_pixel,
compression,
image_size,
pixels_per_meter_x,
pixels_per_meter_y,
colors_used,
important_colors,
}: BitmapInfoHeader,
) -> Self {
Self {
size,
width,
height,
planes,
bits_per_pixel,
compression,
image_size,
pixels_per_meter_x,
pixels_per_meter_y,
colors_used,
important_colors,
r_mask: 0.into(),
g_mask: 0.into(),
b_mask: 0.into(),
a_mask: 0.into(),
colorspace_type: LCS_sRGB.into(),
endpoints: [[0.into(); 3]; 3],
r_gamma: 0.into(),
g_gamma: 0.into(),
b_gamma: 0.into(),
render_intent: LCS_GM_IMAGES.into(),
color_profile_offset: 0.into(),
color_profile_size: 0.into(),
reserved: 0.into(),
}
}
}
impl From<BitmapV2InfoHeader> for BitmapV5Header {
fn from(
BitmapV2InfoHeader {
size,
width,
height,
planes,
bits_per_pixel,
compression,
image_size,
pixels_per_meter_x,
pixels_per_meter_y,
colors_used,
important_colors,
r_mask,
g_mask,
b_mask,
}: BitmapV2InfoHeader,
) -> Self {
Self {
size,
width,
height,
planes,
bits_per_pixel,
compression,
image_size,
pixels_per_meter_x,
pixels_per_meter_y,
colors_used,
important_colors,
r_mask,
g_mask,
b_mask,
a_mask: 0.into(),
colorspace_type: LCS_sRGB.into(),
endpoints: [[0.into(); 3]; 3],
r_gamma: 0.into(),
g_gamma: 0.into(),
b_gamma: 0.into(),
render_intent: LCS_GM_IMAGES.into(),
color_profile_offset: 0.into(),
color_profile_size: 0.into(),
reserved: 0.into(),
}
}
}
impl From<BitmapV3InfoHeader> for BitmapV5Header {
fn from(
BitmapV3InfoHeader {
size,
width,
height,
planes,
bits_per_pixel,
compression,
image_size,
pixels_per_meter_x,
pixels_per_meter_y,
colors_used,
important_colors,
r_mask,
g_mask,
b_mask,
a_mask,
}: BitmapV3InfoHeader,
) -> Self {
Self {
size,
width,
height,
planes,
bits_per_pixel,
compression,
image_size,
pixels_per_meter_x,
pixels_per_meter_y,
colors_used,
important_colors,
r_mask,
g_mask,
b_mask,
a_mask,
colorspace_type: LCS_sRGB.into(),
endpoints: [[0.into(); 3]; 3],
r_gamma: 0.into(),
g_gamma: 0.into(),
b_gamma: 0.into(),
render_intent: LCS_GM_IMAGES.into(),
color_profile_offset: 0.into(),
color_profile_size: 0.into(),
reserved: 0.into(),
}
}
}
impl From<BitmapV4Header> for BitmapV5Header {
fn from(
BitmapV4Header {
size,
width,
height,
planes,
bits_per_pixel,
compression,
image_size,
pixels_per_meter_x,
pixels_per_meter_y,
colors_used,
important_colors,
r_mask,
g_mask,
b_mask,
a_mask,
colorspace_type,
endpoints,
r_gamma,
g_gamma,
b_gamma,
}: BitmapV4Header,
) -> Self {
BitmapV5Header {
size,
width,
height,
planes,
bits_per_pixel,
compression,
image_size,
pixels_per_meter_x,
pixels_per_meter_y,
colors_used,
important_colors,
r_mask,
g_mask,
b_mask,
a_mask,
colorspace_type,
endpoints,
r_gamma,
g_gamma,
b_gamma,
render_intent: LCS_GM_IMAGES.into(),
color_profile_offset: 0.into(),
color_profile_size: 0.into(),
reserved: 0.into(),
}
}
}