aboutsummaryrefslogtreecommitdiff
path: root/core/image/general_os.odin
blob: 63d7c8d43a4526f0c85ea23f02296e4a5ae66323 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#+build !js
package image

import "core:os"

load :: proc{
	load_from_bytes,
	load_from_file,
}

load_from_file :: proc(filename: string, options := Options{}, allocator := context.allocator) -> (img: ^Image, err: Error) {
	data, data_err := os.read_entire_file(filename, allocator)
	defer delete(data, allocator)
	if data_err == nil {
		return load_from_bytes(data, options, allocator)
	} else {
		return nil, .Unable_To_Read_File
	}
}

which :: proc{
	which_bytes,
	which_file,
}

which_file :: proc(path: string) -> Which_File_Type {
	f, err := os.open(path)
	if err != nil {
		return .Unknown
	}
	header: [128]byte
	os.read(f, header[:])
	file_type := which_bytes(header[:])
	os.close(f)
	return file_type
}