pub trait Producer:
Send
+ Sync
+ Debug {
// Required methods
fn name(&self) -> &'static str;
fn descriptor(&self) -> ImageDescriptor;
fn produce(&self, region: Region, output: &mut TileMut<'_>) -> Result<()>;
// Provided methods
fn capability(&self) -> DecodeCapability { ... }
fn reduced_descriptor(&self, target: (u32, u32)) -> Option<ImageDescriptor> { ... }
fn reduce_to(&self, descriptor: ImageDescriptor) -> Result<()> { ... }
}Expand description
A source of pixels at the root of a graph.
Producers sit where decoders meet the graph. produce takes &self because
graph nodes are shared across threads; a producer wrapping a single-pass
streaming decoder therefore owns whatever interior mutability it needs (see
DecodedSource).
Required Methods§
Sourcefn descriptor(&self) -> ImageDescriptor
fn descriptor(&self) -> ImageDescriptor
The shape of the image this producer yields.
Known from the header alone; answering this must not decode pixels.
Sourcefn produce(&self, region: Region, output: &mut TileMut<'_>) -> Result<()>
fn produce(&self, region: Region, output: &mut TileMut<'_>) -> Result<()>
Fill output with the pixels of region.
region is always within descriptor().region().
§Errors
Returns PixelsError::Malformed on invalid input bytes,
PixelsError::Io on source failure, or
PixelsError::InvalidArgument if output does not cover region.
Provided Methods§
Sourcefn capability(&self) -> DecodeCapability
fn capability(&self) -> DecodeCapability
Whether this producer can serve arbitrary regions, or only forward ones.
This is the upstream half of ADR-0009’s seam analysis: a producer that can only go forward forces the scheduler to materialize whenever demand is not forward-monotonic, while one serving arbitrary regions lets the same pipeline stream.
Defaults to DecodeCapability::Sequential, the conservative answer —
over-declaring it costs a buffer, under-declaring it is a correctness
bug.
Sourcefn reduced_descriptor(&self, target: (u32, u32)) -> Option<ImageDescriptor>
fn reduced_descriptor(&self, target: (u32, u32)) -> Option<ImageDescriptor>
What this producer would emit if asked for target or larger, when it
can reach that size more cheaply than by producing full resolution.
Pure: nothing is committed, and calling this must not change what
the producer subsequently emits. The planner asks first, checks the
whole graph still holds, and only then calls Producer::reduce_to —
so a producer that reduced itself here would corrupt pipelines the
planner went on to reject.
The returned descriptor is never smaller than target in either axis:
decoding below the requested size and enlarging afterwards would
discard detail and then invent it back.
None — the default — means this producer has only one resolution.
Sourcefn reduce_to(&self, descriptor: ImageDescriptor) -> Result<()>
fn reduce_to(&self, descriptor: ImageDescriptor) -> Result<()>
Commit to emitting descriptor, which Producer::reduced_descriptor
must have returned.
§Errors
Returns PixelsError::Unsupported if this producer cannot reduce, or
PixelsError::InvalidArgument if pixels have already been produced —
the resolution is fixed from the first Producer::produce onward,
because rows already emitted cannot be retracted.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".