2020-11-15 13:50:12 +00:00
|
|
|
// Copyright (C) 2020 Natanael Mojica <neithanmo@gmail.com>
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
2022-01-15 19:18:47 +00:00
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: MIT/Apache-2.0
|
2020-11-15 13:50:12 +00:00
|
|
|
|
2021-06-03 18:20:54 +00:00
|
|
|
use gst::glib;
|
|
|
|
use gst::prelude::*;
|
2020-11-15 13:50:12 +00:00
|
|
|
|
|
|
|
mod imp;
|
|
|
|
|
2021-11-22 09:04:26 +00:00
|
|
|
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy, glib::Enum)]
|
2020-11-15 13:50:12 +00:00
|
|
|
#[repr(u32)]
|
2021-11-22 09:04:26 +00:00
|
|
|
#[enum_type(name = "GstRsPngCompressionLevel")]
|
2020-11-15 13:50:12 +00:00
|
|
|
pub(crate) enum CompressionLevel {
|
2021-11-22 09:04:26 +00:00
|
|
|
#[enum_value(name = "Default: Use the default compression level.", nick = "default")]
|
2020-11-15 13:50:12 +00:00
|
|
|
Default,
|
2021-11-22 09:04:26 +00:00
|
|
|
#[enum_value(name = "Fast: A fast compression algorithm.", nick = "fast")]
|
2020-11-15 13:50:12 +00:00
|
|
|
Fast,
|
2021-11-22 09:04:26 +00:00
|
|
|
#[enum_value(
|
2020-11-15 13:50:12 +00:00
|
|
|
name = "Best: Uses the algorithm with the best results.",
|
|
|
|
nick = "best"
|
|
|
|
)]
|
|
|
|
Best,
|
2021-11-22 09:04:26 +00:00
|
|
|
#[enum_value(name = "Huffman: Huffman compression.", nick = "huffman")]
|
2020-11-15 13:50:12 +00:00
|
|
|
Huffman,
|
2021-11-22 09:04:26 +00:00
|
|
|
#[enum_value(name = "Rle: Rle compression.", nick = "rle")]
|
2020-11-15 13:50:12 +00:00
|
|
|
Rle,
|
|
|
|
}
|
|
|
|
|
2021-11-22 09:04:26 +00:00
|
|
|
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy, glib::Enum)]
|
2020-11-15 13:50:12 +00:00
|
|
|
#[repr(u32)]
|
2021-11-22 09:04:26 +00:00
|
|
|
#[enum_type(name = "GstRsPngFilterType")]
|
2020-11-15 13:50:12 +00:00
|
|
|
pub(crate) enum FilterType {
|
2021-11-22 09:04:26 +00:00
|
|
|
#[enum_value(
|
2020-11-15 13:50:12 +00:00
|
|
|
name = "NoFilter: No filtering applied to the output.",
|
|
|
|
nick = "nofilter"
|
|
|
|
)]
|
|
|
|
NoFilter,
|
2021-11-22 09:04:26 +00:00
|
|
|
#[enum_value(name = "Sub: filter applied to each pixel.", nick = "sub")]
|
2020-11-15 13:50:12 +00:00
|
|
|
Sub,
|
2021-11-22 09:04:26 +00:00
|
|
|
#[enum_value(name = "Up: Up filter similar to Sub.", nick = "up")]
|
2020-11-15 13:50:12 +00:00
|
|
|
Up,
|
2021-11-22 09:04:26 +00:00
|
|
|
#[enum_value(
|
2020-11-15 13:50:12 +00:00
|
|
|
name = "Avg: The Average filter uses the average of the two neighboring pixels.",
|
|
|
|
nick = "avg"
|
|
|
|
)]
|
|
|
|
Avg,
|
2021-11-22 09:04:26 +00:00
|
|
|
#[enum_value(
|
2020-11-15 13:50:12 +00:00
|
|
|
name = "Paeth: The Paeth filter computes a simple linear function of the three neighboring pixels.",
|
|
|
|
nick = "paeth"
|
|
|
|
)]
|
|
|
|
Paeth,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<CompressionLevel> for png::Compression {
|
|
|
|
fn from(value: CompressionLevel) -> Self {
|
|
|
|
match value {
|
|
|
|
CompressionLevel::Default => png::Compression::Default,
|
|
|
|
CompressionLevel::Fast => png::Compression::Fast,
|
|
|
|
CompressionLevel::Best => png::Compression::Best,
|
|
|
|
CompressionLevel::Huffman => png::Compression::Huffman,
|
|
|
|
CompressionLevel::Rle => png::Compression::Rle,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<FilterType> for png::FilterType {
|
|
|
|
fn from(value: FilterType) -> Self {
|
|
|
|
match value {
|
|
|
|
FilterType::NoFilter => png::FilterType::NoFilter,
|
|
|
|
FilterType::Sub => png::FilterType::Sub,
|
|
|
|
FilterType::Up => png::FilterType::Up,
|
|
|
|
FilterType::Avg => png::FilterType::Avg,
|
|
|
|
FilterType::Paeth => png::FilterType::Paeth,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-17 22:44:49 +00:00
|
|
|
glib::wrapper! {
|
2020-11-15 13:50:12 +00:00
|
|
|
pub struct PngEncoder(ObjectSubclass<imp::PngEncoder>) @extends gst_video::VideoEncoder, gst::Element, gst::Object;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
|
|
|
|
gst::Element::register(
|
|
|
|
Some(plugin),
|
|
|
|
"rspngenc",
|
|
|
|
gst::Rank::Primary,
|
|
|
|
PngEncoder::static_type(),
|
|
|
|
)
|
|
|
|
}
|