aboutsummaryrefslogtreecommitdiff
path: root/core/image
diff options
context:
space:
mode:
authorJeroen van Rijn <Kelimion@users.noreply.github.com>2021-05-03 15:08:34 +0200
committerJeroen van Rijn <Kelimion@users.noreply.github.com>2021-05-03 15:08:34 +0200
commit59b3c472ca1ea4e56728eb81c3c8b595a4b1bcdd (patch)
treece9948ba6b2a1dc888006066a11c65c62bb0ebe0 /core/image
parent357f66fceeb6cbc3b72281300dbe7af4e2b68715 (diff)
Convert `core:compress` and `core:image` error checks to new union comparison.
No more need for `is_kind(err, Error_Value)`, just test err == Error_Value.
Diffstat (limited to 'core/image')
-rw-r--r--core/image/png/example.odin4
-rw-r--r--core/image/png/helpers.odin8
-rw-r--r--core/image/png/png.odin21
3 files changed, 16 insertions, 17 deletions
diff --git a/core/image/png/example.odin b/core/image/png/example.odin
index be6cdd7d7..072f88d6b 100644
--- a/core/image/png/example.odin
+++ b/core/image/png/example.odin
@@ -23,7 +23,7 @@ main :: proc() {
img, err = png.load(file, options);
defer png.destroy(img);
- if !png.is_kind(err, png.E_General.OK) {
+ if err != png.E_General.OK {
fmt.printf("Trying to read PNG file %v returned %v\n", file, err);
} else {
v: png.Info;
@@ -120,7 +120,7 @@ main :: proc() {
}
}
- if is_kind(err, E_General.OK) && .do_not_decompress_image not_in options && .info not_in options {
+ if err == E_General.OK && .do_not_decompress_image not_in options && .info not_in options {
if ok := write_image_as_ppm("out.ppm", img); ok {
fmt.println("Saved decoded image.");
} else {
diff --git a/core/image/png/helpers.odin b/core/image/png/helpers.odin
index 9bd5f55b2..eb0d2f827 100644
--- a/core/image/png/helpers.odin
+++ b/core/image/png/helpers.odin
@@ -107,7 +107,7 @@ text :: proc(c: Chunk) -> (res: Text, ok: bool) {
buf: bytes.Buffer;
zlib_error := zlib.inflate_from_byte_array(fields[2], &buf);
defer bytes.buffer_destroy(&buf);
- if !is_kind(zlib_error, E_General.OK) {
+ if zlib_error != E_General.OK {
ok = false; return;
}
@@ -161,7 +161,7 @@ text :: proc(c: Chunk) -> (res: Text, ok: bool) {
buf: bytes.Buffer;
zlib_error := zlib.inflate_from_byte_array(rest, &buf);
defer bytes.buffer_destroy(&buf);
- if !is_kind(zlib_error, E_General.OK) {
+ if zlib_error != E_General.OK {
ok = false; return;
}
@@ -200,7 +200,7 @@ iccp :: proc(c: Chunk) -> (res: iCCP, ok: bool) {
// Set up ZLIB context and decompress iCCP payload
buf: bytes.Buffer;
zlib_error := zlib.inflate_from_byte_array(fields[2], &buf);
- if !is_kind(zlib_error, E_General.OK) {
+ if zlib_error != E_General.OK {
bytes.buffer_destroy(&buf);
ok = false; return;
}
@@ -498,7 +498,7 @@ when false {
err = zlib.write_zlib_stream_from_memory(&ctx);
b: []u8;
- if is_kind(err, E_General, E_General.OK) {
+ if err == E_General.OK {
b = ctx.out_buf[:];
} else {
return err;
diff --git a/core/image/png/png.odin b/core/image/png/png.odin
index 716185c5f..74f287df8 100644
--- a/core/image/png/png.odin
+++ b/core/image/png/png.odin
@@ -16,7 +16,6 @@ Error :: compress.Error;
E_General :: compress.General_Error;
E_PNG :: image.Error;
E_Deflate :: compress.Deflate_Error;
-is_kind :: compress.is_kind;
Image :: image.Image;
Options :: image.Options;
@@ -274,7 +273,7 @@ read_chunk :: proc(ctx: ^compress.Context) -> (Chunk, Error) {
read_header :: proc(ctx: ^compress.Context) -> (IHDR, Error) {
c, e := read_chunk(ctx);
- if !is_kind(e, E_General.OK) {
+ if e != E_General.OK {
return {}, e;
}
@@ -454,7 +453,7 @@ load_from_stream :: proc(stream: io.Stream, options := Options{}, allocator := c
seen_ihdr = true;
header, err = read_header(&ctx);
- if !is_kind(err, E_General.OK) {
+ if err != E_General.OK {
return img, err;
}
@@ -507,7 +506,7 @@ load_from_stream :: proc(stream: io.Stream, options := Options{}, allocator := c
}
c, err = read_chunk(&ctx);
- if !is_kind(err, E_General.OK) {
+ if err != E_General.OK {
return img, err;
}
@@ -542,7 +541,7 @@ load_from_stream :: proc(stream: io.Stream, options := Options{}, allocator := c
next := ch.type;
for next == .IDAT {
c, err = read_chunk(&ctx);
- if !is_kind(err, E_General.OK) {
+ if err != E_General.OK {
return img, err;
}
@@ -562,7 +561,7 @@ load_from_stream :: proc(stream: io.Stream, options := Options{}, allocator := c
seen_idat = true;
case .IEND:
c, err = read_chunk(&ctx);
- if !is_kind(err, E_General.OK) {
+ if err != E_General.OK {
return img, err;
}
seen_iend = true;
@@ -571,7 +570,7 @@ load_from_stream :: proc(stream: io.Stream, options := Options{}, allocator := c
// TODO: Make sure that 16-bit bKGD + tRNS chunks return u16 instead of u16be
c, err = read_chunk(&ctx);
- if !is_kind(err, E_General.OK) {
+ if err != E_General.OK {
return img, err;
}
seen_bkgd = true;
@@ -606,7 +605,7 @@ load_from_stream :: proc(stream: io.Stream, options := Options{}, allocator := c
}
case .tRNS:
c, err = read_chunk(&ctx);
- if !is_kind(err, E_General.OK) {
+ if err != E_General.OK {
return img, err;
}
@@ -648,7 +647,7 @@ load_from_stream :: proc(stream: io.Stream, options := Options{}, allocator := c
case:
// Unhandled type
c, err = read_chunk(&ctx);
- if !is_kind(err, E_General.OK) {
+ if err != E_General.OK {
return img, err;
}
if .return_metadata in options {
@@ -676,7 +675,7 @@ load_from_stream :: proc(stream: io.Stream, options := Options{}, allocator := c
zlib_error := zlib.inflate(idat, &buf);
defer bytes.buffer_destroy(&buf);
- if !is_kind(zlib_error, E_General.OK) {
+ if zlib_error != E_General.OK {
return {}, zlib_error;
} else {
/*
@@ -713,7 +712,7 @@ load_from_stream :: proc(stream: io.Stream, options := Options{}, allocator := c
as metadata, and set it instead to the raw number of channels.
*/
defilter_error := defilter(img, &buf, &header, options);
- if !is_kind(defilter_error, E_General.OK) {
+ if defilter_error != E_General.OK {
bytes.buffer_destroy(&img.pixels);
return {}, defilter_error;
}