mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-11-26 13:31:00 +00:00
closedcaption: move some textstyle helpers to shared files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1398>
This commit is contained in:
parent
fb9b511e15
commit
ded4261971
3 changed files with 81 additions and 64 deletions
|
@ -14,7 +14,7 @@ use gst::subclass::prelude::*;
|
||||||
use atomic_refcell::AtomicRefCell;
|
use atomic_refcell::AtomicRefCell;
|
||||||
|
|
||||||
use crate::cea608utils::*;
|
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;
|
use gst::glib::once_cell::sync::Lazy;
|
||||||
|
|
||||||
|
@ -67,65 +67,6 @@ struct Cea708ServiceState {
|
||||||
pen_attributes: SetPenAttributesArgs,
|
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 {
|
fn cea608_mode_visible_rows(mode: Cea608Mode) -> u8 {
|
||||||
match mode {
|
match mode {
|
||||||
Cea608Mode::RollUp2 => 2,
|
Cea608Mode::RollUp2 => 2,
|
||||||
|
@ -213,9 +154,9 @@ impl Cea708ServiceState {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut need_pen_attributes = false;
|
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;
|
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) {
|
if self.pen_attributes.underline != (preamble.underline > 0) {
|
||||||
|
@ -241,9 +182,9 @@ impl Cea708ServiceState {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut need_pen_attributes = false;
|
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;
|
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 {
|
if self.pen_attributes.underline != midrowchange.underline {
|
||||||
|
|
|
@ -45,6 +45,12 @@ pub enum TextStyle {
|
||||||
ItalicWhite,
|
ItalicWhite,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl TextStyle {
|
||||||
|
pub fn is_italics(&self) -> bool {
|
||||||
|
*self == TextStyle::ItalicWhite
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<u32> for TextStyle {
|
impl From<u32> for TextStyle {
|
||||||
fn from(val: u32) -> Self {
|
fn from(val: u32) -> Self {
|
||||||
match val {
|
match val {
|
||||||
|
|
|
@ -8,7 +8,11 @@
|
||||||
|
|
||||||
use cea708_types::{tables::*, Service};
|
use cea708_types::{tables::*, Service};
|
||||||
|
|
||||||
|
use gst::glib;
|
||||||
use gst::glib::once_cell::sync::Lazy;
|
use gst::glib::once_cell::sync::Lazy;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::cea608utils::TextStyle;
|
||||||
|
|
||||||
static CAT: Lazy<gst::DebugCategory> = Lazy::new(|| {
|
static CAT: Lazy<gst::DebugCategory> = Lazy::new(|| {
|
||||||
gst::DebugCategory::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)]
|
#[derive(Debug)]
|
||||||
pub enum WriteError {
|
pub enum WriteError {
|
||||||
// returns the number of characters/bytes written
|
// returns the number of characters/bytes written
|
||||||
|
|
Loading…
Reference in a new issue