S13: Rgb and Rgba type aliases for colour tuples in ec-subs and ec-ass (same types)
Browse files at this commit3582d7f981b6275df65bccb64b6a3df4d26233deParent: 3155b283 changed files +8 -4
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 | 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 | 217 | let digits: String = value |
| 216 | 218 | .trim() |
| 217 | 219 | .trim_start_matches(['&', 'H', 'h']) |
crates/ec-subs/src/ir.rsmodified+3 -1
| @@ -7,6 +7,8 @@ | ||
| 7 | 7 | //! ASS `\pos` and `\an` — rides beside the runs instead of inside them, because |
| 8 | 8 | //! it applies to the cue as a whole. |
| 9 | 9 | |
| 10 | +pub type Rgb = (u8, u8, u8); | |
| 11 | + | |
| 10 | 12 | /// How a karaoke syllable is highlighted, after libass. |
| 11 | 13 | #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] |
| 12 | 14 | pub enum KaraokeMode { |
| @@ -38,7 +40,7 @@ pub enum Segment { | ||
| 38 | 40 | /// Children in an explicit colour (`<font color>`, ASS `\c` / `\1c`). |
| 39 | 41 | Color { |
| 40 | 42 | /// Text colour, one byte per channel. |
| 41 | - rgb: (u8, u8, u8), | |
| 43 | + rgb: Rgb, | |
| 42 | 44 | /// What the colour applies to. |
| 43 | 45 | children: Vec<Segment>, |
| 44 | 46 | }, |
crates/ec-subs/src/markup.rsmodified+2 -2
| @@ -8,7 +8,7 @@ | ||
| 8 | 8 | //! with nothing open is dropped, and a `<` that begins no tag at all is the |
| 9 | 9 | //! character it looks like. |
| 10 | 10 | |
| 11 | -use crate::ir::Segment; | |
| 11 | +use crate::ir::{Rgb, Segment}; | |
| 12 | 12 | |
| 13 | 13 | /// Bytes to text, the way a subtitle file has to be read: a UTF-8 or UTF-16 BOM |
| 14 | 14 | /// 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 | 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 | 305 | let value = value.trim(); |
| 306 | 306 | if let Some(hex) = value.strip_prefix('#') { |
| 307 | 307 | let digits: String = hex.chars().take_while(char::is_ascii_hexdigit).collect(); |