tiny.png.DecodeStorage
Defined in tiny.png.
API (21)
Actions
Public operations.
Types and contracts
Public types and contracts.
Fields and members
Public fields and members.
Source
Source: lib/png/src/decode/storage.zig:26
zig
pub const Storage = struct { phase: alloc_phase.capacity.Phase, capacity: capacity_mod.Capacity, bytes: []align(capacity_mod.storage_alignment) u8, window: []u8, prior: []u8, current: []u8, output: []u8, in_use: bool = false, pub const Limits: type = capacity_mod.Limits; pub const Capacity: type = capacity_mod.Capacity; pub const Exhaustion: type = model.Exhaustion; pub const InitError = std.mem.Allocator.Error || capacity_mod.DeriveError; pub const AcquireError: type = plan_mod.Error; pub const claim: alloc_phase.capacity.Declaration = .{ .source = .{ .id = "png.decode_storage", .kind = .phase_static, .limit_source = .caller, .storage = .{ .covered = &.{ .{ .id = "deflate_history_window", .lifetime = .steady, .detail = "DEFLATE history window", }, .{ .id = "prior_and_current_filtered_source_rows", .lifetime = .steady, .detail = "prior and current filtered source rows", }, .{ .id = "decoded_rgba8_output", .lifetime = .steady, .detail = "decoded RGBA8 output", }, }, .excluded = &.{ "caller-owned PNG input bytes", "filesystem and presentation storage", }, }, .capacity = .{ .inputs = &.{ alloc_phase.capacity.bindInput(Limits, "bounds_source_row_bytes", "bounds.source_row_bytes"), alloc_phase.capacity.bindInput(Limits, "bounds_image_pixels", "bounds.image_pixels"), }, .type_selectors = &.{}, .nodes = &.{ .{ .constant = 65536 }, .{ .input = 0 }, .{ .scale = .{ .node = 1, .coefficient = .{ .literal = 2 } } }, .{ .input = 1 }, .{ .scale = .{ .node = 3, .coefficient = .{ .literal = 4 } } }, .{ .add = .{ .left = 0, .right = 2 } }, .{ .add = .{ .left = 5, .right = 4 } }, }, .assertions = &.{.{ .scope = .closure_total, .measure = .retained, .relation = .exact, .expression = 6, }}, }, .overload = .{ .kind = .reject_before_mutation, .detail = "Bounds, input mismatch, and concurrent use reject before output mutation.", }, .risks = .{ .transitive = .{ .status = .witnessed, .detail = "One region covers IDAT streaming, DEFLATE, row filters, and output.", }, .foreign = .{ .status = .excluded, .detail = "input ownership and output consumption remain caller effects", }, }, .obligations = &.{ .{ .key = "png_decode_capacity", .role = .capacity_model }, .{ .key = "png_decode_acquisition", .role = .custom }, .{ .key = "png_decode_oom", .role = .custom }, .{ .key = "png_decode_boundaries", .role = .overload }, .{ .key = "png_decode_reuse", .role = .overload }, .{ .key = "png_decode_sealed", .role = .transitive_risk }, .{ .key = "png_decode_root", .role = .custom }, .{ .key = "png_decode_consumer", .role = .foreign_risk }, }, }, .bindings = .{ .owner = @This(), .seal = .{ .family = alloc_phase.capacity.selector(@This().activate), .premise = .{ .class = .checked_semantic_fact, .authority = .checker, }, }, .teardown = .{ .family = alloc_phase.capacity.selector(@This().deinit), .premise = .{ .class = .checked_semantic_fact, .authority = .checker, }, }, }, }; pub fn init(allocator: std.mem.Allocator, limits: Limits) InitError!Storage { const capacity = try Capacity.derive(limits); const bytes = try allocator.alignedAlloc( u8, .fromByteUnits(capacity_mod.storage_alignment), capacity.storage_bytes, ); return .{ .phase = .initialization, .capacity = capacity, .bytes = bytes, .window = bytes[0..flate.max_window_len], .prior = bytes[capacity.prior_offset..][0..capacity.plan.source_row_bytes], .current = bytes[capacity.current_offset..][0..capacity.plan.source_row_bytes], .output = bytes[capacity.output_offset..][0..capacity.plan.rgba8_bytes], }; } pub fn activate(self: *Storage) void { std.debug.assert(self.phase == .initialization); std.debug.assert(self.bytes.len == self.capacity.storage_bytes); self.phase = .steady; } pub fn acquire(self: *Storage, bytes: []const u8) AcquireError!Regions { std.debug.assert(self.phase == .steady); if (self.in_use) return error.DecodeStorageInUse; const actual = try plan_mod.Plan.inspect(bytes, self.capacity.plan.bounds); if (!std.meta.eql(actual, self.capacity.plan)) return error.DecodeInputMismatch; self.in_use = true; return .{ .window = self.window, .prior = self.prior, .current = self.current, .output = self.output, }; } pub fn reset(self: *Storage) void { std.debug.assert(self.phase == .steady); std.debug.assert(self.in_use); self.in_use = false; } pub fn plan(self: *const Storage) plan_mod.Plan { return self.capacity.plan; } pub fn status(self: *const Storage) Status { return .{ .phase = self.phase, .in_use = self.in_use, .storage_bytes = self.capacity.storage_bytes, .input_bytes = self.capacity.plan.input_bytes, .image_pixels = self.capacity.plan.image_pixels, .source_row_bytes = self.capacity.plan.source_row_bytes, .idat_bytes = self.capacity.plan.idat_bytes, .rgba8_bytes = self.capacity.plan.rgba8_bytes, }; } pub fn deinit(self: *Storage, allocator: std.mem.Allocator) void { std.debug.assert(self.phase != .teardown); std.debug.assert(!self.in_use); std.debug.assert(self.bytes.len == self.capacity.storage_bytes); self.phase = .teardown; allocator.free(self.bytes); self.bytes = &.{}; self.window = &.{}; self.prior = &.{}; self.current = &.{}; self.output = &.{}; }};Source: lib/png/src/root.zig:29
zig
pub const DecodeStorage = decode.Storage;Also reachable as
Audit
| Definitions | 14 |
|---|---|
| Public names | 28 |
| Members | 8 |
| Version | 26.7.0 |
| Revision | daab053ee433 |