tiny.gif.DecodeStorage
Defined in tiny.gif.
API (22)
Actions
Public operations.
Types and contracts
Public types and contracts.
Fields and members
Public fields and members.
Source
Source: lib/gif/src/decode/storage.zig:27
zig
pub const Storage = struct { phase: alloc_phase.capacity.Phase, capacity: capacity_mod.Capacity, bytes: []align(capacity_mod.storage_alignment) u8, frames: []model.Frame, canvas: []u8, previous_canvas: []u8, indices: []u8, compressed: []u8, retained_rgba8: []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 = plan_mod.Error; pub const claim: alloc_phase.capacity.Declaration = .{ .source = .{ .id = "gif.decode_storage", .kind = .phase_static, .limit_source = .caller, .storage = .{ .covered = &.{ .{ .id = "decoded_frame_descriptors", .lifetime = .steady, .detail = "decoded frame descriptors", }, .{ .id = "current_and_previous_rgba8_canvases", .lifetime = .steady, .detail = "current and previous RGBA8 canvases", }, .{ .id = "frame_index_and_compressed_byte_scratch", .lifetime = .steady, .detail = "frame index and compressed-byte scratch", }, .{ .id = "retained_decoded_rgba8_frames", .lifetime = .steady, .detail = "retained decoded RGBA8 frames", }, }, .excluded = &.{ "caller-owned GIF input bytes", "GIF encoding palettes, indices, and output bytes", }, }, .capacity = .{ .inputs = &.{ alloc_phase.capacity.bindInput(Limits, "bounds_frames", "bounds.frames"), alloc_phase.capacity.bindInput(Limits, "bounds_canvas_pixels", "bounds.canvas_pixels"), alloc_phase.capacity.bindInput(Limits, "bounds_frame_pixels", "bounds.frame_pixels"), alloc_phase.capacity.bindInput(Limits, "bounds_compressed_bytes", "bounds.compressed_bytes"), alloc_phase.capacity.bindInput(Limits, "bounds_retained_rgba8_bytes", "bounds.retained_rgba8_bytes"), }, .type_selectors = &.{ alloc_phase.capacity.bindType(model.Frame, "frame"), }, .nodes = &.{ .{ .input = 0 }, .{ .scale = .{ .node = 0, .coefficient = .{ .size_of_concrete_type = 0 } } }, .{ .alignment = .{ .node = 1, .alignment = .{ .literal = 16 } } }, .{ .input = 1 }, .{ .scale = .{ .node = 3, .coefficient = .{ .literal = 8 } } }, .{ .input = 2 }, .{ .input = 3 }, .{ .input = 4 }, .{ .add = .{ .left = 2, .right = 4 } }, .{ .add = .{ .left = 8, .right = 5 } }, .{ .add = .{ .left = 9, .right = 6 } }, .{ .add = .{ .left = 10, .right = 7 } }, }, .assertions = &.{.{ .scope = .closure_total, .measure = .retained, .relation = .exact, .expression = 11, }}, }, .overload = .{ .kind = .reject_before_mutation, .detail = "structural planning rejects each caller bound before acquisition; input mismatch and concurrent acquisition leave the region reusable", }, .risks = .{ .transitive = .{ .status = .witnessed, .detail = "container parsing, LZW decode, compositing, disposal, and retained frame construction use acquired regions only after activation", }, .foreign = .{ .status = .excluded, .detail = "input ownership and consumer presentation effects remain outside decode storage", }, }, .obligations = &.{ .{ .key = "gif_decode_capacity", .role = .capacity_model }, .{ .key = "gif_decode_acquisition", .role = .custom }, .{ .key = "gif_decode_oom", .role = .custom }, .{ .key = "gif_decode_boundaries", .role = .overload }, .{ .key = "gif_decode_reuse", .role = .overload }, .{ .key = "gif_decode_malformed", .role = .overload }, .{ .key = "gif_decode_sealed", .role = .transitive_risk }, .{ .key = "gif_decode_root", .role = .custom }, .{ .key = "gif_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, .frames = typedSlice(model.Frame, bytes, capacity.frame_offset, capacity.plan.frames), .canvas = bytes[capacity.canvas_offset..][0..capacity.plan.canvas_rgba8_bytes], .previous_canvas = bytes[capacity.previous_canvas_offset..][0..capacity.plan.canvas_rgba8_bytes], .indices = bytes[capacity.indices_offset..][0..capacity.plan.frame_pixels], .compressed = bytes[capacity.compressed_offset..][0..capacity.plan.compressed_bytes], .retained_rgba8 = bytes[capacity.retained_rgba8_offset..][0..capacity.plan.retained_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.exactBounds()); if (!std.meta.eql(actual, self.capacity.plan)) return error.DecodeInputMismatch; @memset(self.canvas, 0); self.in_use = true; return .{ .frames = self.frames, .canvas = self.canvas, .previous_canvas = self.previous_canvas, .indices = self.indices, .compressed = self.compressed, .retained_rgba8 = self.retained_rgba8, }; } pub fn reset(self: *Storage) void { std.debug.assert(self.phase == .steady); std.debug.assert(self.in_use); self.in_use = false; } pub fn status(self: *const Storage) Status { return .{ .phase = self.phase, .in_use = self.in_use, .storage_bytes = self.capacity.storage_bytes, .canvas_pixels = self.capacity.plan.canvas_pixels, .frame_pixels = self.capacity.plan.frame_pixels, .frames = self.capacity.plan.frames, .compressed_bytes = self.capacity.plan.compressed_bytes, .retained_rgba8_bytes = self.capacity.plan.retained_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.frames = &.{}; self.canvas = &.{}; self.previous_canvas = &.{}; self.indices = &.{}; self.compressed = &.{}; self.retained_rgba8 = &.{}; }};Source: lib/gif/src/root.zig:18
zig
pub const DecodeStorage = decode.Storage;Audit
| Definitions | 13 |
|---|---|
| Public names | 13 |
| Members | 10 |
| Version | 26.7.0 |
| Revision | daab053ee433 |