Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/video
diff options
context:
space:
mode:
authorMatthew Waters <matthew@centricular.com>2023-11-06 11:46:56 +0300
committerMatthew Waters <matthew@centricular.com>2023-11-21 15:33:09 +0300
commitded42619718e3ea838f53b0216d6215278b5d426 (patch)
tree3f7f2c6a6844005bf71ff5c2eeadad4a87013cb0 /video
parentfb9b511e1508e8289b7018f8526bcba665930f79 (diff)
closedcaption: move some textstyle helpers to shared files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1398>
Diffstat (limited to 'video')
-rw-r--r--video/closedcaption/src/cea608tocea708/imp.rs69
-rw-r--r--video/closedcaption/src/cea608utils.rs6
-rw-r--r--video/closedcaption/src/cea708utils.rs70
3 files changed, 81 insertions, 64 deletions
diff --git a/video/closedcaption/src/cea608tocea708/imp.rs b/video/closedcaption/src/cea608tocea708/imp.rs
index 414ea5cdb..0461a635a 100644
--- a/video/closedcaption/src/cea608tocea708/imp.rs
+++ b/video/closedcaption/src/cea608tocea708/imp.rs
@@ -14,7 +14,7 @@ use gst::subclass::prelude::*;
use atomic_refcell::AtomicRefCell;
use crate::cea608utils::*;
-use crate::cea708utils::Cea708ServiceWriter;
+use crate::cea708utils::{Cea708ServiceWriter, textstyle_foreground_color, textstyle_to_pen_color, Cea708ServiceWriter};
use gst::glib::once_cell::sync::Lazy;
@@ -67,65 +67,6 @@ struct Cea708ServiceState {
pen_attributes: SetPenAttributesArgs,
}
-fn textstyle_foreground_color(style: TextStyle) -> Color {
- match style {
- TextStyle::Red => Color {
- r: ColorValue::Full,
- g: ColorValue::None,
- b: ColorValue::None,
- },
- TextStyle::Green => Color {
- r: ColorValue::None,
- g: ColorValue::Full,
- b: ColorValue::None,
- },
- TextStyle::Blue => Color {
- r: ColorValue::None,
- g: ColorValue::None,
- b: ColorValue::Full,
- },
- TextStyle::Cyan => Color {
- r: ColorValue::None,
- g: ColorValue::Full,
- b: ColorValue::Full,
- },
- TextStyle::Yellow => Color {
- r: ColorValue::Full,
- g: ColorValue::Full,
- b: ColorValue::None,
- },
- TextStyle::Magenta => Color {
- r: ColorValue::Full,
- g: ColorValue::None,
- b: ColorValue::Full,
- },
- TextStyle::White | TextStyle::ItalicWhite => Color {
- r: ColorValue::Full,
- g: ColorValue::Full,
- b: ColorValue::Full,
- },
- }
-}
-
-fn textstyle_to_pen_color(style: TextStyle) -> SetPenColorArgs {
- let black = Color {
- r: ColorValue::None,
- g: ColorValue::None,
- b: ColorValue::None,
- };
- SetPenColorArgs {
- foreground_color: textstyle_foreground_color(style),
- foreground_opacity: Opacity::Solid,
- background_color: black,
- background_opacity: Opacity::Solid,
- edge_color: black,
- }
-}
-
-fn textstyle_is_italics(style: TextStyle) -> bool {
- style == TextStyle::ItalicWhite
-}
-
fn cea608_mode_visible_rows(mode: Cea608Mode) -> u8 {
match mode {
Cea608Mode::RollUp2 => 2,
@@ -213,9 +154,9 @@ impl Cea708ServiceState {
}
let mut need_pen_attributes = false;
- if self.pen_attributes.italics != textstyle_is_italics(preamble.style) {
+ if self.pen_attributes.italics != preamble.style.is_italics() {
need_pen_attributes = true;
- self.pen_attributes.italics = textstyle_is_italics(preamble.style);
+ self.pen_attributes.italics = preamble.style.is_italics();
}
if self.pen_attributes.underline != (preamble.underline > 0) {
@@ -241,9 +182,9 @@ impl Cea708ServiceState {
}
let mut need_pen_attributes = false;
- if self.pen_attributes.italics != textstyle_is_italics(midrowchange.style) {
+ if self.pen_attributes.italics != midrowchange.style.is_italics() {
need_pen_attributes = true;
- self.pen_attributes.italics = textstyle_is_italics(midrowchange.style);
+ self.pen_attributes.italics = midrowchange.style.is_italics();
}
if self.pen_attributes.underline != midrowchange.underline {
diff --git a/video/closedcaption/src/cea608utils.rs b/video/closedcaption/src/cea608utils.rs
index c422f4a9f..51fc4a6a0 100644
--- a/video/closedcaption/src/cea608utils.rs
+++ b/video/closedcaption/src/cea608utils.rs
@@ -45,6 +45,12 @@ pub enum TextStyle {
ItalicWhite,
}
+impl TextStyle {
+ pub fn is_italics(&self) -> bool {
+ *self == TextStyle::ItalicWhite
+ }
+}
+
impl From<u32> for TextStyle {
fn from(val: u32) -> Self {
match val {
diff --git a/video/closedcaption/src/cea708utils.rs b/video/closedcaption/src/cea708utils.rs
index a6071798c..577d2a01b 100644
--- a/video/closedcaption/src/cea708utils.rs
+++ b/video/closedcaption/src/cea708utils.rs
@@ -8,7 +8,11 @@
use cea708_types::{tables::*, Service};
+use gst::glib;
use gst::glib::once_cell::sync::Lazy;
+use serde::{Deserialize, Serialize};
+
+use crate::cea608utils::TextStyle;
static CAT: Lazy<gst::DebugCategory> = Lazy::new(|| {
gst::DebugCategory::new(
@@ -18,6 +22,72 @@ static CAT: Lazy<gst::DebugCategory> = Lazy::new(|| {
)
});
+#[derive(
+ Serialize, Deserialize, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy, glib::Enum,
+)]
+#[repr(u32)]
+#[enum_type(name = "GstTtToCea708Mode")]
+pub enum Cea708Mode {
+ PopOn,
+ PaintOn,
+ RollUp,
+}
+
+pub fn textstyle_foreground_color(style: TextStyle) -> Color {
+ match style {
+ TextStyle::Red => Color {
+ r: ColorValue::Full,
+ g: ColorValue::None,
+ b: ColorValue::None,
+ },
+ TextStyle::Green => Color {
+ r: ColorValue::None,
+ g: ColorValue::Full,
+ b: ColorValue::None,
+ },
+ TextStyle::Blue => Color {
+ r: ColorValue::None,
+ g: ColorValue::None,
+ b: ColorValue::Full,
+ },
+ TextStyle::Cyan => Color {
+ r: ColorValue::None,
+ g: ColorValue::Full,
+ b: ColorValue::Full,
+ },
+ TextStyle::Yellow => Color {
+ r: ColorValue::Full,
+ g: ColorValue::Full,
+ b: ColorValue::None,
+ },
+ TextStyle::Magenta => Color {
+ r: ColorValue::Full,
+ g: ColorValue::None,
+ b: ColorValue::Full,
+ },
+ TextStyle::White | TextStyle::ItalicWhite => Color {
+ r: ColorValue::Full,
+ g: ColorValue::Full,
+ b: ColorValue::Full,
+ },
+ }
+}
+
+pub fn textstyle_to_pen_color(style: TextStyle) -> SetPenColorArgs {
+ let black = Color {
+ r: ColorValue::None,
+ g: ColorValue::None,
+ b: ColorValue::None,
+ };
+ SetPenColorArgs {
+ foreground_color: textstyle_foreground_color(style),
+ foreground_opacity: Opacity::Solid,
+ background_color: black,
+ background_opacity: Opacity::Solid,
+ edge_color: black,
+ }
+}
+
#[derive(Debug)]
pub enum WriteError {
// returns the number of characters/bytes written