aboutsummaryrefslogtreecommitdiff
path: root/core/image
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2022-05-14 15:11:23 +0100
committergingerBill <bill@gingerbill.org>2022-05-14 15:11:23 +0100
commitc516fb947f7aafd00363dfcdaefa79f96e4f4ee5 (patch)
treefbe537bbf6372991af8e5997c2de8c40ce16384d /core/image
parent3aa0a733f3b59388ae320f07cfabb1f4e7f0cec2 (diff)
Add `image.destroy`
Diffstat (limited to 'core/image')
-rw-r--r--core/image/common.odin1
-rw-r--r--core/image/general_loader.odin13
-rw-r--r--core/image/netpbm/netpbm.odin7
-rw-r--r--core/image/png/png.odin1
-rw-r--r--core/image/qoi/qoi.odin1
-rw-r--r--core/image/which.odin22
6 files changed, 29 insertions, 16 deletions
diff --git a/core/image/common.odin b/core/image/common.odin
index 75a649e52..28129a6e1 100644
--- a/core/image/common.odin
+++ b/core/image/common.odin
@@ -54,6 +54,7 @@ Image :: struct {
*/
background: Maybe(RGB_Pixel_16),
metadata: Image_Metadata,
+ which: Which_File_Type,
}
Image_Metadata :: union {
diff --git a/core/image/general_loader.odin b/core/image/general_loader.odin
index 3acffb452..79f5fb737 100644
--- a/core/image/general_loader.odin
+++ b/core/image/general_loader.odin
@@ -43,3 +43,16 @@ load_from_file :: proc(filename: string, options := Options{}, allocator := cont
return nil, .Unable_To_Read_File
}
}
+
+destroy :: proc(img: ^Image, allocator := context.allocator) -> bool {
+ if img == nil {
+ return true
+ }
+ context.allocator = allocator
+ destroyer := _internal_destroyers[img.which]
+ if destroyer != nil {
+ destroyer(img)
+ }
+ free(img)
+ return true
+} \ No newline at end of file
diff --git a/core/image/netpbm/netpbm.odin b/core/image/netpbm/netpbm.odin
index 778ec2c5e..5a504cd7c 100644
--- a/core/image/netpbm/netpbm.odin
+++ b/core/image/netpbm/netpbm.odin
@@ -47,6 +47,7 @@ load_from_bytes :: proc(data: []byte, allocator := context.allocator) -> (img: ^
context.allocator = allocator
img = new(Image)
+ img.which = .NetPBM
header: Header; defer header_destroy(&header)
header_size: int
@@ -758,9 +759,5 @@ _register :: proc() {
destroyer :: proc(img: ^Image) {
_ = destroy(img)
}
- image.register(.PBM, loader, destroyer)
- image.register(.PGM, loader, destroyer)
- image.register(.PPM, loader, destroyer)
- image.register(.PAM, loader, destroyer)
- image.register(.PFM, loader, destroyer)
+ image.register(.NetPBM, loader, destroyer)
} \ No newline at end of file
diff --git a/core/image/png/png.odin b/core/image/png/png.odin
index ea888d0ad..35fdb58d8 100644
--- a/core/image/png/png.odin
+++ b/core/image/png/png.odin
@@ -372,6 +372,7 @@ load_from_context :: proc(ctx: ^$C, options := Options{}, allocator := context.a
if img == nil {
img = new(Image)
}
+ img.which = .PNG
info := new(image.PNG_Info)
img.metadata = info
diff --git a/core/image/qoi/qoi.odin b/core/image/qoi/qoi.odin
index f10f2ff56..29a17d4f4 100644
--- a/core/image/qoi/qoi.odin
+++ b/core/image/qoi/qoi.odin
@@ -224,6 +224,7 @@ load_from_context :: proc(ctx: ^$C, options := Options{}, allocator := context.a
if img == nil {
img = new(Image)
}
+ img.which = .QOI
if .return_metadata in options {
info := new(image.QOI_Info)
diff --git a/core/image/which.odin b/core/image/which.odin
index 30cb78405..82cb03ce6 100644
--- a/core/image/which.odin
+++ b/core/image/which.odin
@@ -14,7 +14,7 @@ Which_File_Type :: enum {
JPEG,
JPEG_2000,
JPEG_XL,
- PBM, PGM, PPM, PAM, PFM, // NetPBM family
+ NetPBM, // NetPBM family
PIC, // Softimage PIC
PNG, // Portable Network Graphics
PSD, // Photoshop PSD
@@ -111,16 +111,16 @@ which_bytes :: proc(data: []byte) -> Which_File_Type {
switch s[2] {
case '\t', '\n', '\r':
switch s[1] {
- case '1', '4':
- return .PBM
- case '2', '5':
- return .PGM
- case '3', '6':
- return .PPM
- case '7':
- return .PAM
- case 'F', 'f':
- return .PFM
+ case '1', '4': // PBM
+ return .NetPBM
+ case '2', '5': // PGM
+ return .NetPBM
+ case '3', '6': // PPM
+ return .NetPBM
+ case '7': // PAM
+ return .NetPBM
+ case 'F', 'f': // PFM
+ return .NetPBM
}
}
case s[:8] == "\x89PNG\r\n\x1a\n":