this repo has no description
13
fork

Configure Feed

Select the types of activity you want to include in your feed.

image: implement local filesystem transmission

Implement transmission over a local filesystem, by file, temp file, or
shared mem.

+61
+6
src/Image.zig
··· 21 21 png, 22 22 }; 23 23 24 + pub const TransmitMedium = enum { 25 + file, 26 + temp_file, 27 + shared_mem, 28 + }; 29 + 24 30 pub const Placement = struct { 25 31 img_id: u32, 26 32 options: Image.DrawOptions,
+55
src/Vaxis.zig
··· 717 717 return result; 718 718 } 719 719 720 + /// Transmit an image using the local filesystem. Allocates only for base64 encoding 721 + pub fn transmitLocalImagePath( 722 + self: *Vaxis, 723 + allocator: std.mem.Allocator, 724 + tty: AnyWriter, 725 + payload: []const u8, 726 + height: usize, 727 + width: usize, 728 + medium: Image.TransmitMedium, 729 + format: Image.TransmitFormat, 730 + ) !Image { 731 + defer self.next_img_id += 1; 732 + 733 + const id = self.next_img_id; 734 + 735 + const size = base64Encoder.calcSize(payload.len); 736 + if (size >= 4096) return error.PathTooLong; 737 + 738 + const buf = try allocator.alloc(u8, size); 739 + const encoded = base64Encoder.encode(buf, payload); 740 + defer allocator.free(buf); 741 + 742 + const medium_char: u8 = switch (medium) { 743 + .file => 'f', 744 + .temp_file => 't', 745 + .shared_mem => 's', 746 + }; 747 + 748 + switch (format) { 749 + .rgb => { 750 + try tty.print( 751 + "\x1b_Gf=24,s={d},v={d},i={d},t={c};{s}\x1b\\", 752 + .{ width, height, id, medium_char, encoded }, 753 + ); 754 + }, 755 + .rgba => { 756 + try tty.print( 757 + "\x1b_Gf=32,s={d},v={d},i={d},t={c};{s}\x1b\\", 758 + .{ width, height, id, medium_char, encoded }, 759 + ); 760 + }, 761 + .png => { 762 + try tty.print( 763 + "\x1b_Gf=100,i={d},t={c};{s}\x1b\\", 764 + .{ id, medium_char, encoded }, 765 + ); 766 + }, 767 + } 768 + return .{ 769 + .id = id, 770 + .width = width, 771 + .height = height, 772 + }; 773 + } 774 + 720 775 /// Transmit an image which has been pre-base64 encoded 721 776 pub fn transmitPreEncodedImage( 722 777 self: *Vaxis,