From 201300737a27681583feb188ae06f829ce9d1f46 Mon Sep 17 00:00:00 2001 From: Gwen Lg Date: Wed, 17 Jul 2024 22:54:37 +0200 Subject: [PATCH] refacto(vobsub): remove useless `to_image` from VobSubIndexedImage replaced by implementing `ToImage` trait for `VobSubToImage`. `VobSubToImage` use an `VobSubIndexedImage` and a `Palette` as input. --- src/vobsub/img.rs | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/src/vobsub/img.rs b/src/vobsub/img.rs index 3954722..047ff0e 100644 --- a/src/vobsub/img.rs +++ b/src/vobsub/img.rs @@ -1,7 +1,7 @@ //! Run-length encoded image format for subtitles. use core::fmt::{self, Debug}; -use image::{ImageBuffer, Luma, Pixel, Rgb, Rgba, RgbaImage}; +use image::{ImageBuffer, Luma, Pixel, Rgb, Rgba}; use iter_fixed::IntoIteratorFixed; use log::trace; use nom::{ @@ -13,7 +13,7 @@ use nom::{ }; use thiserror::Error; -use super::{IResultExt, NomError, Palette, VobSubError}; +use super::{IResultExt, NomError, VobSubError}; use crate::{ content::{Area, Size}, image::{ImageArea, ImageSize, ToImage, ToOcrImage, ToOcrImageOpt}, @@ -252,25 +252,6 @@ impl VobSubIndexedImage { pub fn raw_image(&self) -> &[u8] { self.raw_image.as_slice() } - - /// Decompress to subtitle to an RBGA image. - /// WIP: replace by more generic - #[must_use] - pub fn to_image(&self, palette: &Palette) -> RgbaImage { - let width = u32::from(self.area.width()); - let height = u32::from(self.area.height()); - ImageBuffer::from_fn(width, height, |x, y| { - let offset = cast::usize(y * width + x); - // We need to subtract the raw index from 3 to get the same - // results as everybody else. I found this by inspecting the - // Handbrake subtitle decoding routines. - let px = usize::from(3 - self.raw_image[offset]); - let rgb = palette[usize::from(self.palette[px])].0; - let a = self.alpha[px]; - let aa = a << 4 | a; - Rgba([rgb[0], rgb[1], rgb[2], aa]) - }) - } } impl fmt::Debug for VobSubIndexedImage {