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 {
210210 }
211211 }
212212
213+type Rgba = (u8, u8, u8, u8);
214+
213215 /// `&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> {
215217 let digits: String = value
216218 .trim()
217219 .trim_start_matches(['&', 'H', 'h'])
crates/ec-subs/src/ir.rsmodified+3 -1
@@ -7,6 +7,8 @@
77 //! ASS `\pos` and `\an` — rides beside the runs instead of inside them, because
88 //! it applies to the cue as a whole.
99
10+pub type Rgb = (u8, u8, u8);
11+
1012 /// How a karaoke syllable is highlighted, after libass.
1113 #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
1214 pub enum KaraokeMode {
@@ -38,7 +40,7 @@ pub enum Segment {
3840 /// Children in an explicit colour (`<font color>`, ASS `\c` / `\1c`).
3941 Color {
4042 /// Text colour, one byte per channel.
41- rgb: (u8, u8, u8),
43+ rgb: Rgb,
4244 /// What the colour applies to.
4345 children: Vec<Segment>,
4446 },
crates/ec-subs/src/markup.rsmodified+2 -2
@@ -8,7 +8,7 @@
88 //! with nothing open is dropped, and a `<` that begins no tag at all is the
99 //! character it looks like.
1010
11-use crate::ir::Segment;
11+use crate::ir::{Rgb, Segment};
1212
1313 /// Bytes to text, the way a subtitle file has to be read: a UTF-8 or UTF-16 BOM
1414 /// consumed, invalid sequences replaced rather than refused, and CRLF (or a
@@ -301,7 +301,7 @@ fn attribute(attrs: &str, name: &str) -> Option<String> {
301301 }
302302
303303 /// `#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> {
305305 let value = value.trim();
306306 if let Some(hex) = value.strip_prefix('#') {
307307 let digits: String = hex.chars().take_while(char::is_ascii_hexdigit).collect();