Commit Graph

18 Commits

Author SHA1 Message Date
Jeroen van Rijn
ae0b8fce44 Move bytes utils back to EXR code for the time being.
Also, allow PNG example to be run directly from `core:image/png` directory.
2021-06-22 16:39:00 +02:00
Jeroen van Rijn
352494cbb4 ZLIB: Start optimization. 2021-06-21 21:05:52 +02:00
Jeroen van Rijn
8a4b9ddaa3 Fix comment. 2021-06-18 15:42:04 +02:00
Jeroen van Rijn
54a2b6f00e Add bytes.buffer_create_of_type and bytes.buffer_convert_to_type.
Convenience functions to reinterpret or cast one buffer to another type, or create a buffer of a specific type.

	Example:
```odin
	fmt.println("Convert []f16le (x2) to []f32 (x2).");
	b := []u8{0, 60, 0, 60}; // == []f16{1.0, 1.0}

	res, backing, had_to_allocate, err := bytes.buffer_convert_to_type(2, f32, f16le, b);
	fmt.printf("res      : %v\n", res);              // [1.000, 1.000]
	fmt.printf("backing  : %v\n", backing);          // &Buffer{buf = [0, 0, 128, 63, 0, 0, 128, 63], off = 0, last_read = Invalid}
	fmt.printf("allocated: %v\n", had_to_allocate);  // true
	fmt.printf("err      : %v\n", err);              // false

	if had_to_allocate { defer bytes.buffer_destroy(backing); }

	fmt.println("\nConvert []f16le (x2) to []u16 (x2).");

	res2: []u16;
	res2, backing, had_to_allocate, err = bytes.buffer_convert_to_type(2, u16, f16le, b);
	fmt.printf("res      : %v\n", res2);             // [15360, 15360]
	fmt.printf("backing  : %v\n", backing);          // Buffer.buf points to `b` because it could be converted in-place.
	fmt.printf("allocated: %v\n", had_to_allocate);  // false
	fmt.printf("err      : %v\n", err);              // false

	if had_to_allocate { defer bytes.buffer_destroy(backing); }

	fmt.println("\nConvert []f16le (x2) to []u16 (x2), force_convert=true.");

	res2, backing, had_to_allocate, err = bytes.buffer_convert_to_type(2, u16, f16le, b, true);
	fmt.printf("res      : %v\n", res2);             // [1, 1]
	fmt.printf("backing  : %v\n", backing);          // Buffer.buf points to `b` because it could be converted in-place.
	fmt.printf("allocated: %v\n", had_to_allocate);  // false
	fmt.printf("err      : %v\n", err);              // false

	if had_to_allocate { defer bytes.buffer_destroy(backing); }
```
2021-06-18 15:25:36 +02:00
gingerBill
86649e6b44 Core library clean up: Make range expressions more consistent and replace uses of .. with ..= 2021-06-14 11:15:25 +01:00
gingerBill
e82f8214e8 Add bytes.remove, bytes.remove_all, strings.remove, strings.remove_all 2021-05-23 11:46:43 +01:00
gingerBill
d33350e3a5 Add truncate_to_byte and truncate_to_rune for packages strings and bytes 2021-04-22 15:49:10 +01:00
gingerBill
cd2476e084 Add buffer_read_at buffer_write_at 2021-04-14 20:13:26 +01:00
gingerBill
3337412228 split*_iterator procedures for package bytes and strings 2021-03-18 13:26:33 +00:00
gingerBill
aa93305015 Replace usage of inline proc with #force_inline proc in the core library 2021-02-23 16:14:47 +00:00
gingerBill
e6dfc22b8a Add bytes.buffer_write_to and bytes.buffer_read_from 2020-12-17 00:47:05 +00:00
gingerBill
1470cab842 Make bytes.odin consistent with strings.odin in functionality 2020-12-17 00:36:25 +00:00
gingerBill
a31b992d2b Rename bytes/strings.odin to bytes/bytes.odin 2020-12-17 00:25:05 +00:00
gingerBill
a82c902f99 Minor correction to bytes.Buffer's vtable 2020-12-05 15:36:02 +00:00
gingerBill
0ed1300bd6 Make bytes.Reader and strings.Reader have the same interface 2020-12-04 21:25:13 +00:00
gingerBill
dd63665b58 Update bytes.Reader 2020-12-04 20:33:14 +00:00
gingerBill
9b22583397 Add bytes.Buffer 2020-12-04 20:18:41 +00:00
gingerBill
63f2480951 Begin work on package bytes ([]byte equivalent of package strings) 2020-12-04 19:16:40 +00:00