tiny.gif.EncodeStorage
Defined in tiny.gif.
API (20)
Actions
Public operations.
Types and contracts
Public types and contracts.
Fields and members
Public fields and members.
Source
Source: lib/gif/src/encode/storage.zig:25
zig
pub const Storage = struct { phase: alloc_phase.capacity.Phase, capacity: capacity_mod.Capacity, bytes: []align(capacity_mod.storage_alignment) u8, keys: []u32, codes: []u16, compressed: []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 = "gif.encode_storage", .kind = .phase_static, .limit_source = .caller, .storage = .{ .covered = &.{ .{ .id = "global_palette_and_exact_encoding_plan", .lifetime = .steady, .detail = "global palette and exact encoding plan", }, .{ .id = "lzw_dictionary_and_compressed_frame_scratch", .lifetime = .steady, .detail = "LZW dictionary and compressed-frame scratch", }, .{ .id = "encoded_gif_output_bytes", .lifetime = .steady, .detail = "encoded GIF output bytes", }, }, .excluded = &.{ "caller-owned animation frame bytes and frame views", "filesystem and downstream decoder storage", }, }, .capacity = .{ .inputs = &.{ alloc_phase.capacity.bindInput(Limits, "animation_frames", "animation.frames"), alloc_phase.capacity.bindInput(Limits, "bounds_canvas_pixels", "bounds.canvas_pixels"), alloc_phase.capacity.bindInput(Limits, "bounds_frames", "bounds.frames"), }, .type_selectors = &.{}, .nodes = &.{ .{ .constant = 49152 }, .{ .input = 1 }, .{ .input = 2 }, .{ .add = .{ .left = 0, .right = 1 } }, .{ .add = .{ .left = 3, .right = 2 } }, }, .assertions = &.{.{ .scope = .closure_total, .measure = .retained, .relation = .upper_bound, .expression = 4, }}, }, .overload = .{ .kind = .reject_before_mutation, .detail = "Bounds, input mismatch, and concurrent use reject before output mutation.", }, .risks = .{ .transitive = .{ .status = .witnessed, .detail = "Palette lookup, LZW coding, GIF framing, and output writing use fixed regions.", }, .foreign = .{ .status = .excluded, .detail = "input ownership and output consumption remain caller effects", }, }, .obligations = &.{ .{ .key = "gif_encode_capacity", .role = .capacity_model }, .{ .key = "gif_encode_acquisition", .role = .custom }, .{ .key = "gif_encode_oom", .role = .custom }, .{ .key = "gif_encode_boundaries", .role = .overload }, .{ .key = "gif_encode_reuse", .role = .overload }, .{ .key = "gif_encode_sealed", .role = .transitive_risk }, .{ .key = "gif_encode_root", .role = .custom }, .{ .key = "gif_encode_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, ); const compressed_bytes = capacity.plan.max_compressed_bytes; const compressed = bytes[capacity.compressed_offset..][0..compressed_bytes]; return .{ .phase = .initialization, .capacity = capacity, .bytes = bytes, .keys = typedSlice(u32, bytes, capacity.key_offset, lzw.dictionary_slots), .codes = typedSlice(u16, bytes, capacity.code_offset, lzw.dictionary_slots), .compressed = compressed, .output = bytes[capacity.output_offset..][0..capacity.plan.output_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, animation: model.AnimationView) AcquireError!Regions { std.debug.assert(self.phase == .steady); if (self.in_use) return error.EncodeStorageInUse; const dictionary = lzw.Dictionary.init(self.keys, self.codes); const actual = try plan_mod.Plan.inspectDictionary( animation, self.capacity.plan.bounds, dictionary, ); if (!std.meta.eql(actual, self.capacity.plan)) return error.EncodeInputMismatch; self.in_use = true; return .{ .dictionary = dictionary, .compressed = self.compressed, .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 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, .frames = self.capacity.plan.frames, .palette_entries = self.capacity.plan.palette_entries, .compressed_bytes = self.capacity.plan.max_compressed_bytes, .output_bytes = self.capacity.plan.output_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.keys = &.{}; self.codes = &.{}; self.compressed = &.{}; self.output = &.{}; }};Source: lib/gif/src/root.zig:32
zig
pub const EncodeStorage = encode.Storage;Audit
| Definitions | 13 |
|---|---|
| Public names | 13 |
| Members | 8 |
| Version | 26.7.0 |
| Revision | daab053ee433 |