forge
Explore
Log in

Don't you dare go Hollow

S13: Rgb and Rgba type aliases for colour tuples in ec-subs and ec-ass (same types)

Browse files at this commit

3582d7f981b6275df65bccb64b6a3df4d26233deAhmet Kaan GümüşParent: 3155b28
crates/ec-ass/src/lib.rsmodified+3 -1
@@ -210,8 +210,10 @@ fn alignment(code: i32, v4: bool) -> TextAlign {
210 }210 }
211 }211 }
212 212
213+type Rgba = (u8, u8, u8, u8);
214+
213 /// `&HAABBGGRR&`: BGR with a *transparency* byte, so 0 is opaque.215 /// `&HAABBGGRR&`: BGR with a *transparency* byte, so 0 is opaque.
214-fn parse_color(value: &str) -> Option<(u8, u8, u8, u8)> {216+fn parse_color(value: &str) -> Option<Rgba> {
215 let digits: String = value217 let digits: String = value
216 .trim()218 .trim()
217 .trim_start_matches(['&', 'H', 'h'])219 .trim_start_matches(['&', 'H', 'h'])
crates/ec-subs/src/ir.rsmodified+3 -1
@@ -7,6 +7,8 @@
7 //! ASS `\pos` and `\an` — rides beside the runs instead of inside them, because7 //! ASS `\pos` and `\an` — rides beside the runs instead of inside them, because
8 //! it applies to the cue as a whole.8 //! it applies to the cue as a whole.
9 9
10+pub type Rgb = (u8, u8, u8);
11+
10 /// How a karaoke syllable is highlighted, after libass.12 /// How a karaoke syllable is highlighted, after libass.
11 #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]13 #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
12 pub enum KaraokeMode {14 pub enum KaraokeMode {
@@ -38,7 +40,7 @@ pub enum Segment {
38 /// Children in an explicit colour (`<font color>`, ASS `\c` / `\1c`).40 /// Children in an explicit colour (`<font color>`, ASS `\c` / `\1c`).
39 Color {41 Color {
40 /// Text colour, one byte per channel.42 /// Text colour, one byte per channel.
41- rgb: (u8, u8, u8),43+ rgb: Rgb,
42 /// What the colour applies to.44 /// What the colour applies to.
43 children: Vec<Segment>,45 children: Vec<Segment>,
44 },46 },
crates/ec-subs/src/markup.rsmodified+2 -2
@@ -8,7 +8,7 @@
8 //! with nothing open is dropped, and a `<` that begins no tag at all is the8 //! with nothing open is dropped, and a `<` that begins no tag at all is the
9 //! character it looks like.9 //! character it looks like.
10 10
11-use crate::ir::Segment;11+use crate::ir::{Rgb, Segment};
12 12
13 /// Bytes to text, the way a subtitle file has to be read: a UTF-8 or UTF-16 BOM13 /// Bytes to text, the way a subtitle file has to be read: a UTF-8 or UTF-16 BOM
14 /// consumed, invalid sequences replaced rather than refused, and CRLF (or a14 /// consumed, invalid sequences replaced rather than refused, and CRLF (or a
@@ -301,7 +301,7 @@ fn attribute(attrs: &str, name: &str) -> Option<String> {
301 }301 }
302 302
303 /// `#rrggbb`, `#rgb`, or one of the sixteen names HTML has always had.303 /// `#rrggbb`, `#rgb`, or one of the sixteen names HTML has always had.
304-fn parse_color(value: &str) -> Option<(u8, u8, u8)> {304+fn parse_color(value: &str) -> Option<Rgb> {
305 let value = value.trim();305 let value = value.trim();
306 if let Some(hex) = value.strip_prefix('#') {306 if let Some(hex) = value.strip_prefix('#') {
307 let digits: String = hex.chars().take_while(char::is_ascii_hexdigit).collect();307 let digits: String = hex.chars().take_while(char::is_ascii_hexdigit).collect();