|
@@ -15,7 +15,6 @@ package qoi
|
|
|
import "core:image"
|
|
|
import "core:compress"
|
|
|
import "core:bytes"
|
|
|
-import "core:os"
|
|
|
|
|
|
Error :: image.Error
|
|
|
Image :: image.Image
|
|
@@ -166,20 +165,6 @@ save_to_memory :: proc(output: ^bytes.Buffer, img: ^Image, options := Options{}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-save_to_file :: proc(output: string, img: ^Image, options := Options{}, allocator := context.allocator) -> (err: Error) {
|
|
|
- context.allocator = allocator
|
|
|
-
|
|
|
- out := &bytes.Buffer{}
|
|
|
- defer bytes.buffer_destroy(out)
|
|
|
-
|
|
|
- save_to_memory(out, img, options) or_return
|
|
|
- write_ok := os.write_entire_file(output, out.buf[:])
|
|
|
-
|
|
|
- return nil if write_ok else .Unable_To_Write_File
|
|
|
-}
|
|
|
-
|
|
|
-save :: proc{save_to_memory, save_to_file}
|
|
|
-
|
|
|
load_from_bytes :: proc(data: []byte, options := Options{}, allocator := context.allocator) -> (img: ^Image, err: Error) {
|
|
|
ctx := &compress.Context_Memory_Input{
|
|
|
input_data = data,
|
|
@@ -189,19 +174,6 @@ load_from_bytes :: proc(data: []byte, options := Options{}, allocator := context
|
|
|
return img, err
|
|
|
}
|
|
|
|
|
|
-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
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
@(optimization_mode="speed")
|
|
|
load_from_context :: proc(ctx: ^$C, options := Options{}, allocator := context.allocator) -> (img: ^Image, err: Error) {
|
|
|
context.allocator = allocator
|
|
@@ -359,8 +331,6 @@ load_from_context :: proc(ctx: ^$C, options := Options{}, allocator := context.a
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-load :: proc{load_from_file, load_from_bytes, load_from_context}
|
|
|
-
|
|
|
/*
|
|
|
Cleanup of image-specific data.
|
|
|
*/
|