Add saving of 24 and 32-bit images to BMP format.

This commit is contained in:
Jeroen van Rijn
2024-06-06 23:53:15 +02:00
parent 08612423b9
commit 566119ff83
2 changed files with 110 additions and 1 deletions
+15
View File
@@ -2,6 +2,7 @@
package core_image_bmp
import "core:os"
import "core:bytes"
load :: proc{load_from_file, load_from_bytes, load_from_context}
@@ -16,4 +17,18 @@ load_from_file :: proc(filename: string, options := Options{}, allocator := cont
} else {
return nil, .Unable_To_Read_File
}
}
save :: proc{save_to_buffer, save_to_file}
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_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
}