mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
Replace core:image's sidecar with explicit metadata_ptr and metadata_type.
To unpack, use:
```odin
v: ^png.Info;
if img.metadata_ptr != nil && img.metadata_type == png.Info {
v = (^png.Info)(img.metadata_ptr);
...
}
```
This commit is contained in:
@@ -14,7 +14,7 @@ import "core:os"
|
||||
main :: proc() {
|
||||
file: string;
|
||||
|
||||
options := image.Options{};
|
||||
options := image.Options{.return_metadata};
|
||||
err: compress.Error;
|
||||
img: ^image.Image;
|
||||
|
||||
@@ -27,11 +27,11 @@ main :: proc() {
|
||||
fmt.printf("Trying to read PNG file %v returned %v\n", file, err);
|
||||
} else {
|
||||
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 img.metadata_ptr != nil && img.metadata_type == png.Info {
|
||||
v = (^png.Info)(img.metadata_ptr);
|
||||
// Handle ancillary chunks as you wish.
|
||||
// We provide helper functions for a few types.
|
||||
for c in v.chunks {
|
||||
|
||||
@@ -392,10 +392,7 @@ load_from_stream :: proc(stream: io.Stream, options := Options{}, allocator := c
|
||||
img = new(Image);
|
||||
}
|
||||
|
||||
info: ^Info;
|
||||
if img.sidecar == nil {
|
||||
info = new(Info);
|
||||
}
|
||||
info := new(Info, context.allocator);
|
||||
|
||||
ctx := &compress.Context{
|
||||
input = stream,
|
||||
@@ -417,7 +414,6 @@ load_from_stream :: proc(stream: io.Stream, options := Options{}, allocator := c
|
||||
|
||||
header: IHDR;
|
||||
|
||||
img.sidecar = info;
|
||||
info.chunks.allocator = context.temp_allocator;
|
||||
|
||||
// State to ensure correct chunk ordering.
|
||||
@@ -659,7 +655,8 @@ load_from_stream :: proc(stream: io.Stream, options := Options{}, allocator := c
|
||||
}
|
||||
|
||||
if .return_header in options || .return_metadata in options {
|
||||
img.sidecar = info;
|
||||
img.metadata_ptr = info;
|
||||
img.metadata_type = typeid_of(Info);
|
||||
}
|
||||
if .do_not_decompress_image in options {
|
||||
img.channels = final_image_channels;
|
||||
|
||||
Reference in New Issue
Block a user