aboutsummaryrefslogtreecommitdiff
path: root/core/image
diff options
context:
space:
mode:
authorJeroen van Rijn <Kelimion@users.noreply.github.com>2021-06-20 18:40:46 +0200
committerGitHub <noreply@github.com>2021-06-20 18:40:46 +0200
commit18471f358ea0e096bfdfb9dc04cd3fcbbb3ea50b (patch)
treedcd9e9ba138d33ee8cde9910d8603a473cf27205 /core/image
parentd66fd71d217815a97af12e5e0a1bd035783c3f36 (diff)
parent55d09251d8ec7455609bbbf3d211e9be8948bf0e (diff)
Merge pull request #1025 from Kelimion/png_info
Change PNG's img.sidecar to ^Info, make img.depth an int.
Diffstat (limited to 'core/image')
-rw-r--r--core/image/common.odin2
-rw-r--r--core/image/png/example.odin6
-rw-r--r--core/image/png/png.odin13
3 files changed, 12 insertions, 9 deletions
diff --git a/core/image/common.odin b/core/image/common.odin
index 9d46b81e6..2d1dcf0f8 100644
--- a/core/image/common.odin
+++ b/core/image/common.odin
@@ -7,7 +7,7 @@ Image :: struct {
width: int,
height: int,
channels: int,
- depth: u8,
+ depth: int,
pixels: bytes.Buffer,
/*
Some image loaders/writers can return/take an optional background color.
diff --git a/core/image/png/example.odin b/core/image/png/example.odin
index 30cbf5d21..2b95d724a 100644
--- a/core/image/png/example.odin
+++ b/core/image/png/example.odin
@@ -26,12 +26,12 @@ main :: proc() {
if err != nil {
fmt.printf("Trying to read PNG file %v returned %v\n", file, err);
} else {
- v: png.Info;
+ v: ^png.Info;
ok: bool;
fmt.printf("Image: %vx%vx%v, %v-bit.\n", img.width, img.height, img.channels, img.depth);
- if v, ok = img.sidecar.(png.Info); ok {
+ if v, ok = img.sidecar.(^png.Info); ok {
// Handle ancillary chunks as you wish.
// We provide helper functions for a few types.
for c in v.chunks {
@@ -195,7 +195,7 @@ write_image_as_ppm :: proc(filename: string, image: ^image.Image) -> (success: b
defer close(fd);
write_string(fd,
- fmt.tprintf("P6\n%v %v\n%v\n", width, height, (1 << depth -1)),
+ fmt.tprintf("P6\n%v %v\n%v\n", width, height, (1 << uint(depth) - 1)),
);
if channels == 3 {
diff --git a/core/image/png/png.odin b/core/image/png/png.odin
index 2964348d9..8d26d87d7 100644
--- a/core/image/png/png.odin
+++ b/core/image/png/png.odin
@@ -392,7 +392,10 @@ load_from_stream :: proc(stream: io.Stream, options := Options{}, allocator := c
img = new(Image);
}
- img.sidecar = nil;
+ info: ^Info;
+ if img.sidecar == nil {
+ info = new(Info);
+ }
ctx := &compress.Context{
input = stream,
@@ -413,7 +416,8 @@ load_from_stream :: proc(stream: io.Stream, options := Options{}, allocator := c
e: io.Error;
header: IHDR;
- info: Info;
+
+ img.sidecar = info;
info.chunks.allocator = context.temp_allocator;
// State to ensure correct chunk ordering.
@@ -462,12 +466,12 @@ load_from_stream :: proc(stream: io.Stream, options := Options{}, allocator := c
// Color image without a palette
img.channels = 3;
final_image_channels = 3;
- img.depth = header.bit_depth;
+ img.depth = int(header.bit_depth);
} else {
// Grayscale
img.channels = 1;
final_image_channels = 1;
- img.depth = header.bit_depth;
+ img.depth = int(header.bit_depth);
}
if .Alpha in header.color_type {
@@ -522,7 +526,6 @@ load_from_stream :: proc(stream: io.Stream, options := Options{}, allocator := c
// If we only want image metadata and don't want the pixel data, we can early out.
if .return_metadata not_in options && .do_not_decompress_image in options {
img.channels = final_image_channels;
- img.sidecar = info;
return img, nil;
}
// There must be at least 1 IDAT, contiguous if more.