Skip to main content

Analysis

Struct Analysis 

Source
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: GifMetadata

Metadata 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>

Source

pub fn frame_count(&self) -> usize

Get the number of frames.

Source

pub fn segment_count(&self) -> usize

Get the number of segments.

Source

pub fn total_duration_ms(&self) -> u64

Get the total duration in milliseconds.

Source

pub fn static_segments(&self) -> Vec<&Segment>

Get segments that are marked as static.

Source

pub fn apply_operations(&self, ops: &SegmentOps) -> Vec<EncodableFrame>

Apply segment operations and get encodable frames.

Operations not in the map default to Keep.

Source

pub fn export<E: GifEncoder>( &self, encoder: &E, ops: &SegmentOps, config: &EncodeConfig, ) -> Result<Vec<u8>>

Apply operations and export using the specified encoder.

Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Source

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.

Source

pub fn as_encodable(&self) -> Vec<EncodableFrame>

Get frames as encodable without any operations applied.

Source

pub fn pauses(&self) -> SegmentSelector<'_>

Select all static segments (pauses/duplicate frames).

Returns a [SegmentSelector] that can be filtered and operated on.

§Example
// Cap all pauses to 300ms
let ops = analysis.pauses().cap(300);

// Collapse only long pauses
let ops = analysis.pauses()
    .longer_than(500)
    .collapse(200);
Source

pub fn motion(&self) -> SegmentSelector<'_>

Select all motion segments (non-static, actually changing content).

§Example
// Speed up all motion by 1.5x
let ops = analysis.motion().speed_up(1.5);
Source

pub fn all(&self) -> SegmentSelector<'_>

Select all segments.

§Example
// Speed up everything by 2x
let ops = analysis.all().speed_up(2.0);
Source

pub fn segment(&self, id: usize) -> SegmentSelector<'_>

Select a single segment by ID.

§Example
// Remove segment 5
let ops = analysis.segment(5).remove();
Source

pub fn segments_by_id(&self, ids: &[usize]) -> SegmentSelector<'_>

Select multiple segments by ID.

§Example
// Collapse specific segments
let ops = analysis.segments_by_id(&[1, 3, 5]).collapse(100);
Source

pub fn frames_range(&self, range: Range<usize>) -> SegmentSelector<'_>

Select segments by frame index range.

Selects any segment that overlaps with the given frame range.

§Example
// Speed up the first 100 frames
let ops = analysis.frames_range(0..100).speed_up(2.0);
Source

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);
Source

pub fn collapse_all_pauses(&self, duration_ms: u32) -> SegmentOps

Collapse all static segments to a fixed duration.

Every static segment becomes a single frame with the specified delay, regardless of its original length.

§Example
// Make all pauses exactly 200ms
let ops = analysis.collapse_all_pauses(200);
Source

pub fn remove_long_pauses(&self, min_ms: u32) -> SegmentOps

Remove all static segments longer than the specified duration.

§Example
// Remove any pause longer than 2 seconds
let ops = analysis.remove_long_pauses(2000);
Source

pub fn speed_up_pauses(&self, factor: f64) -> SegmentOps

Speed up all static segments by a factor.

A factor of 2.0 makes pauses twice as fast (half duration). A factor of 0.5 makes them half as fast (double duration).

§Example
// Make all pauses 3x faster
let ops = analysis.speed_up_pauses(3.0);
Source

pub fn speed_up_all(&self, factor: f64) -> SegmentOps

Speed up the entire GIF by a factor.

Affects all segments, not just static ones.

§Example
// Make everything 1.5x faster
let ops = analysis.speed_up_all(1.5);
Source

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);
}
Source

pub fn merge_ops(op_sets: &[SegmentOps]) -> SegmentOps

Merge multiple operation sets, with later ops overriding earlier ones.

§Example
let base = analysis.cap_pauses(500);
let extra = analysis.speed_up_all(1.2);
let combined = Analysis::<H>::merge_ops(&[base, extra]);

Trait Implementations§

Source§

impl<H: Clone> Clone for Analysis<H>

Source§

fn clone(&self) -> Analysis<H>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<H: Debug> Debug for Analysis<H>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.