mirror of
https://github.com/IllusionMan1212/avif-odin.git
synced 2026-10-24 10:12:28 +00:00
34 lines
812 B
Odin
34 lines
812 B
Odin
//+build !js
|
|||
|
|
package avif
|
||
|
|
|
||
|
|
import "core:os"
|
||
|
|
import "core:bytes"
|
||
|
|
|
||
|
|
save :: proc{save_to_file, save_to_buffer}
|
||
|
|
|
||
|
|
save_to_file :: proc(output: string, img: ^Image, options := Options{}, allocator := context.allocator) -> (err: Error) {
|
||
|
|
out := &bytes.Buffer{}
|
||
|
|
defer bytes.buffer_destroy(out)
|
||
|
|
|
||
|
|
save_to_buffer(out, img, options) or_return
|
||
|
|
write_ok := os.write_entire_file(output, out.buf[:])
|
||
|
|
|
||
|
|
return nil if write_ok else .Unable_To_Write_File
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
load :: proc{load_from_file, load_from_bytes}
|
||
|
|
|
||
|
|
load_from_file :: proc(filename: string, options := Options{}, allocator := context.allocator) -> (img: ^Image, err: Error) {
|
||
|
|
context.allocator = allocator
|
||
|
|
|
||
|
|
data, ok := os.read_entire_file(filename)
|
||
|
|
defer delete(data)
|
||
|
|
|
||
|
|
if ok {
|
||
|
|
return load_from_bytes(data, options)
|
||
|
|
} else {
|
||
|
|
return nil, .Unable_To_Read_File
|
||
|
|
}
|
||
|
|
}
|