1use super::direct::*;
2use super::header::*;
3use super::jpeg::*;
4pub use super::version::BlpVersion;
5
6pub const BLP_MAX_WIDTH: u32 = 65535;
9pub const BLP_MAX_HEIGHT: u32 = 65535;
12
13#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
17pub struct BlpImage {
18 pub header: BlpHeader,
19 pub content: BlpContent,
20}
21
22impl BlpImage {
23 pub fn image_count(&self) -> usize {
25 match &self.content {
26 BlpContent::Dxt1(v) => v.images.len(),
27 BlpContent::Dxt3(v) => v.images.len(),
28 BlpContent::Dxt5(v) => v.images.len(),
29 BlpContent::Raw1(v) => v.images.len(),
30 BlpContent::Raw3(v) => v.images.len(),
31 BlpContent::Jpeg(v) => v.images.len(),
32 }
33 }
34
35 pub fn content_jpeg(&self) -> Option<&BlpJpeg> {
37 self.content.jpeg()
38 }
39
40 pub fn content_raw1(&self) -> Option<&BlpRaw1> {
42 self.content.raw1()
43 }
44
45 pub fn content_raw3(&self) -> Option<&BlpRaw3> {
47 self.content.raw3()
48 }
49
50 pub fn content_dxt1(&self) -> Option<&BlpDxtn> {
52 self.content.dxt1()
53 }
54
55 pub fn ontent_dxt3(&self) -> Option<&BlpDxtn> {
57 self.content.dxt3()
58 }
59
60 pub fn content_dxt5(&self) -> Option<&BlpDxtn> {
62 self.content.dxt5()
63 }
64}
65
66#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
68pub enum BlpContent {
69 Jpeg(BlpJpeg),
70 Raw1(BlpRaw1),
72 Raw3(BlpRaw3),
74 Dxt1(BlpDxtn),
76 Dxt3(BlpDxtn),
78 Dxt5(BlpDxtn),
80}
81
82impl BlpContent {
83 pub fn tag(&self) -> BlpContentTag {
84 match self {
85 BlpContent::Jpeg { .. } => BlpContentTag::Jpeg,
86 BlpContent::Raw1 { .. } => BlpContentTag::Direct,
87 BlpContent::Raw3 { .. } => BlpContentTag::Direct,
88 BlpContent::Dxt1 { .. } => BlpContentTag::Direct,
89 BlpContent::Dxt3 { .. } => BlpContentTag::Direct,
90 BlpContent::Dxt5 { .. } => BlpContentTag::Direct,
91 }
92 }
93
94 pub fn jpeg(&self) -> Option<&BlpJpeg> {
95 match self {
96 BlpContent::Jpeg(v) => Some(v),
97 _ => None,
98 }
99 }
100
101 pub fn raw1(&self) -> Option<&BlpRaw1> {
102 match self {
103 BlpContent::Raw1(v) => Some(v),
104 _ => None,
105 }
106 }
107
108 pub fn raw3(&self) -> Option<&BlpRaw3> {
109 match self {
110 BlpContent::Raw3(v) => Some(v),
111 _ => None,
112 }
113 }
114
115 pub fn dxt1(&self) -> Option<&BlpDxtn> {
116 match self {
117 BlpContent::Dxt1(v) => Some(v),
118 _ => None,
119 }
120 }
121
122 pub fn dxt3(&self) -> Option<&BlpDxtn> {
123 match self {
124 BlpContent::Dxt3(v) => Some(v),
125 _ => None,
126 }
127 }
128
129 pub fn dxt5(&self) -> Option<&BlpDxtn> {
130 match self {
131 BlpContent::Dxt5(v) => Some(v),
132 _ => None,
133 }
134 }
135}