pub struct Analysis<H> {
pub metadata: GifMetadata,
pub frames: Vec<AnalyzedFrame<H>>,
pub segments: Vec<Segment>,
}Expand description
Result of GIF analysis containing frames and segments.
Fields§
§metadata: GifMetadataMetadata about the original GIF.
frames: Vec<AnalyzedFrame<H>>Analyzed frames with hashes and segment assignments.
segments: Vec<Segment>Detected segments.
Implementations§
Source§impl<H: Clone + Sync + Send> Analysis<H>
impl<H: Clone + Sync + Send> Analysis<H>
Sourcepub fn frame_count(&self) -> usize
pub fn frame_count(&self) -> usize
Get the number of frames.
Sourcepub fn segment_count(&self) -> usize
pub fn segment_count(&self) -> usize
Get the number of segments.
Sourcepub fn total_duration_ms(&self) -> u64
pub fn total_duration_ms(&self) -> u64
Get the total duration in milliseconds.
Sourcepub fn static_segments(&self) -> Vec<&Segment>
pub fn static_segments(&self) -> Vec<&Segment>
Get segments that are marked as static.
Sourcepub fn apply_operations(&self, ops: &SegmentOps) -> Vec<EncodableFrame>
pub fn apply_operations(&self, ops: &SegmentOps) -> Vec<EncodableFrame>
Apply segment operations and get encodable frames.
Operations not in the map default to Keep.
Sourcepub fn export<E: GifEncoder>(
&self,
encoder: &E,
ops: &SegmentOps,
config: &EncodeConfig,
) -> Result<Vec<u8>>
pub fn export<E: GifEncoder>( &self, encoder: &E, ops: &SegmentOps, config: &EncodeConfig, ) -> Result<Vec<u8>>
Apply operations and export using the specified encoder.
Sourcepub fn export_to_file<E: GifEncoder>(
&self,
encoder: &E,
ops: &SegmentOps,
path: impl AsRef<Path>,
config: &EncodeConfig,
) -> Result<()>
pub fn export_to_file<E: GifEncoder>( &self, encoder: &E, ops: &SegmentOps, path: impl AsRef<Path>, config: &EncodeConfig, ) -> Result<()>
Apply operations and export to a file.
Sourcepub fn apply_all_operations(
&self,
segment_ops: &SegmentOps,
frame_ops: &FrameOps,
) -> Vec<EncodableFrame>
pub fn apply_all_operations( &self, segment_ops: &SegmentOps, frame_ops: &FrameOps, ) -> Vec<EncodableFrame>
Apply both segment and frame operations and get encodable frames.
This is the enhanced version that handles frame-level operations like individual frame removal and segment splitting.
Operations not in the maps default to Keep.
Sourcepub fn calculate_impact(
&self,
segment_ops: &SegmentOps,
frame_ops: &FrameOps,
) -> (usize, u64)
pub fn calculate_impact( &self, segment_ops: &SegmentOps, frame_ops: &FrameOps, ) -> (usize, u64)
Calculate the resulting frame count and duration without cloning images.
Returns (total_frames, total_duration_ms).
Sourcepub fn export_with_frame_ops<E: GifEncoder>(
&self,
encoder: &E,
segment_ops: &SegmentOps,
frame_ops: &FrameOps,
config: &EncodeConfig,
) -> Result<Vec<u8>>
pub fn export_with_frame_ops<E: GifEncoder>( &self, encoder: &E, segment_ops: &SegmentOps, frame_ops: &FrameOps, config: &EncodeConfig, ) -> Result<Vec<u8>>
Apply both segment and frame operations and export using the specified encoder.
Sourcepub fn export_to_file_with_frame_ops<E: GifEncoder>(
&self,
encoder: &E,
segment_ops: &SegmentOps,
frame_ops: &FrameOps,
path: impl AsRef<Path>,
config: &EncodeConfig,
) -> Result<()>
pub fn export_to_file_with_frame_ops<E: GifEncoder>( &self, encoder: &E, segment_ops: &SegmentOps, frame_ops: &FrameOps, path: impl AsRef<Path>, config: &EncodeConfig, ) -> Result<()>
Apply both segment and frame operations and export to a file.
Sourcepub fn split_segments(&self, frame_ops: &FrameOps) -> Analysis<H>
pub fn split_segments(&self, frame_ops: &FrameOps) -> Analysis<H>
Logically split segments at frames marked with FrameOp::SplitAfter.
This returns a new Analysis where segments have been partitioned
based on the split points. This allows applying different segment-level
operations to the newly created parts.
Sourcepub fn as_encodable(&self) -> Vec<EncodableFrame>
pub fn as_encodable(&self) -> Vec<EncodableFrame>
Get frames as encodable without any operations applied.
Sourcepub fn pauses(&self) -> SegmentSelector<'_>
pub fn pauses(&self) -> SegmentSelector<'_>
Sourcepub fn motion(&self) -> SegmentSelector<'_>
pub fn motion(&self) -> SegmentSelector<'_>
Sourcepub fn all(&self) -> SegmentSelector<'_>
pub fn all(&self) -> SegmentSelector<'_>
Sourcepub fn segment(&self, id: usize) -> SegmentSelector<'_>
pub fn segment(&self, id: usize) -> SegmentSelector<'_>
Sourcepub fn segments_by_id(&self, ids: &[usize]) -> SegmentSelector<'_>
pub fn segments_by_id(&self, ids: &[usize]) -> SegmentSelector<'_>
Sourcepub fn frames_range(&self, range: Range<usize>) -> SegmentSelector<'_>
pub fn frames_range(&self, range: Range<usize>) -> SegmentSelector<'_>
Sourcepub fn cap_pauses(&self, max_ms: u32) -> SegmentOps
pub fn cap_pauses(&self, max_ms: u32) -> SegmentOps
Cap all static segments (pause points) to a maximum duration.
Static segments longer than max_ms will be collapsed to a single
frame with that duration. Shorter segments are unchanged.
§Example
// Make all pauses last at most 300ms
let ops = analysis.cap_pauses(300);
let frames = analysis.apply_operations(&ops);Sourcepub fn collapse_all_pauses(&self, duration_ms: u32) -> SegmentOps
pub fn collapse_all_pauses(&self, duration_ms: u32) -> SegmentOps
Sourcepub fn remove_long_pauses(&self, min_ms: u32) -> SegmentOps
pub fn remove_long_pauses(&self, min_ms: u32) -> SegmentOps
Sourcepub fn speed_up_pauses(&self, factor: f64) -> SegmentOps
pub fn speed_up_pauses(&self, factor: f64) -> SegmentOps
Sourcepub fn speed_up_all(&self, factor: f64) -> SegmentOps
pub fn speed_up_all(&self, factor: f64) -> SegmentOps
Sourcepub fn target_duration(&self, target_ms: u64) -> Option<SegmentOps>
pub fn target_duration(&self, target_ms: u64) -> Option<SegmentOps>
Create operations that optimize the GIF for a target duration.
This will collapse/remove static segments as needed to try to reach the target duration. Non-static segments are preserved.
Returns None if the target is not achievable (non-static content
already exceeds the target).
§Example
// Try to get the GIF under 30 seconds
if let Some(ops) = analysis.target_duration(30_000) {
let frames = analysis.apply_operations(&ops);
}Sourcepub fn merge_ops(op_sets: &[SegmentOps]) -> SegmentOps
pub fn merge_ops(op_sets: &[SegmentOps]) -> SegmentOps
Trait Implementations§
Auto Trait Implementations§
impl<H> Freeze for Analysis<H>
impl<H> RefUnwindSafe for Analysis<H>where
H: RefUnwindSafe,
impl<H> Send for Analysis<H>where
H: Send,
impl<H> Sync for Analysis<H>where
H: Sync,
impl<H> Unpin for Analysis<H>where
H: Unpin,
impl<H> UnsafeUnpin for Analysis<H>
impl<H> UnwindSafe for Analysis<H>where
H: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more