mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Change General_Error.OK to nil
This commit is contained in:
@@ -17,7 +17,6 @@ Error :: union {
|
|||||||
}
|
}
|
||||||
|
|
||||||
General_Error :: enum {
|
General_Error :: enum {
|
||||||
OK = 0,
|
|
||||||
File_Not_Found,
|
File_Not_Found,
|
||||||
Cannot_Open_File,
|
Cannot_Open_File,
|
||||||
File_Too_Short,
|
File_Too_Short,
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ main :: proc() {
|
|||||||
if len(args) < 2 {
|
if len(args) < 2 {
|
||||||
stderr("No input file specified.\n");
|
stderr("No input file specified.\n");
|
||||||
err := gzip.load(TEST, &buf);
|
err := gzip.load(TEST, &buf);
|
||||||
if err != E_General.OK {
|
if err != nil {
|
||||||
stdout("Displaying test vector: ");
|
stdout("Displaying test vector: ");
|
||||||
stdout(bytes.buffer_to_string(&buf));
|
stdout(bytes.buffer_to_string(&buf));
|
||||||
stdout("\n");
|
stdout("\n");
|
||||||
@@ -54,7 +54,7 @@ main :: proc() {
|
|||||||
} else {
|
} else {
|
||||||
err = gzip.load(file, &buf);
|
err = gzip.load(file, &buf);
|
||||||
}
|
}
|
||||||
if err != gzip.E_General.OK {
|
if err != nil {
|
||||||
if err != E_General.File_Not_Found {
|
if err != E_General.File_Not_Found {
|
||||||
stderr("File not found: ");
|
stderr("File not found: ");
|
||||||
stderr(file);
|
stderr(file);
|
||||||
|
|||||||
@@ -277,7 +277,7 @@ load_from_stream :: proc(stream: io.Stream, buf: ^bytes.Buffer, allocator := con
|
|||||||
|
|
||||||
// fmt.printf("ZLIB returned: %v\n", zlib_error);
|
// fmt.printf("ZLIB returned: %v\n", zlib_error);
|
||||||
|
|
||||||
if zlib_error != E_General.OK || zlib_error == nil {
|
if zlib_error != nil {
|
||||||
return zlib_error;
|
return zlib_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -307,7 +307,7 @@ load_from_stream :: proc(stream: io.Stream, buf: ^bytes.Buffer, allocator := con
|
|||||||
if len(payload) != payload_len {
|
if len(payload) != payload_len {
|
||||||
return E_GZIP.Payload_Length_Invalid;
|
return E_GZIP.Payload_Length_Invalid;
|
||||||
}
|
}
|
||||||
return E_General.OK;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
load :: proc{load_from_file, load_from_slice, load_from_stream};
|
load :: proc{load_from_file, load_from_slice, load_from_stream};
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ main :: proc() {
|
|||||||
err := zlib.inflate(ODIN_DEMO, &buf);
|
err := zlib.inflate(ODIN_DEMO, &buf);
|
||||||
defer bytes.buffer_destroy(&buf);
|
defer bytes.buffer_destroy(&buf);
|
||||||
|
|
||||||
if err != zlib.E_General.OK {
|
if err != nil {
|
||||||
fmt.printf("\nError: %v\n", err);
|
fmt.printf("\nError: %v\n", err);
|
||||||
}
|
}
|
||||||
s := bytes.buffer_to_string(&buf);
|
s := bytes.buffer_to_string(&buf);
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ write_byte :: #force_inline proc(z: ^Context, c: u8) -> (err: io.Error) #no_boun
|
|||||||
allocate_huffman_table :: proc(allocator := context.allocator) -> (z: ^Huffman_Table, err: Error) {
|
allocate_huffman_table :: proc(allocator := context.allocator) -> (z: ^Huffman_Table, err: Error) {
|
||||||
|
|
||||||
z = new(Huffman_Table, allocator);
|
z = new(Huffman_Table, allocator);
|
||||||
return z, E_General.OK;
|
return z, nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
build_huffman :: proc(z: ^Huffman_Table, code_lengths: []u8) -> (err: Error) {
|
build_huffman :: proc(z: ^Huffman_Table, code_lengths: []u8) -> (err: Error) {
|
||||||
@@ -193,13 +193,13 @@ build_huffman :: proc(z: ^Huffman_Table, code_lengths: []u8) -> (err: Error) {
|
|||||||
next_code[v] += 1;
|
next_code[v] += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return E_General.OK;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
decode_huffman_slowpath :: proc(z: ^Context, t: ^Huffman_Table) -> (r: u16, err: Error) #no_bounds_check {
|
decode_huffman_slowpath :: proc(z: ^Context, t: ^Huffman_Table) -> (r: u16, err: Error) #no_bounds_check {
|
||||||
|
|
||||||
r = 0;
|
r = 0;
|
||||||
err = E_General.OK;
|
err = nil;
|
||||||
|
|
||||||
k: int;
|
k: int;
|
||||||
s: u8;
|
s: u8;
|
||||||
@@ -229,7 +229,7 @@ decode_huffman_slowpath :: proc(z: ^Context, t: ^Huffman_Table) -> (r: u16, err:
|
|||||||
compress.consume_bits_lsb(z, s);
|
compress.consume_bits_lsb(z, s);
|
||||||
|
|
||||||
r = t.value[b];
|
r = t.value[b];
|
||||||
return r, E_General.OK;
|
return r, nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
decode_huffman :: proc(z: ^Context, t: ^Huffman_Table) -> (r: u16, err: Error) #no_bounds_check {
|
decode_huffman :: proc(z: ^Context, t: ^Huffman_Table) -> (r: u16, err: Error) #no_bounds_check {
|
||||||
@@ -247,7 +247,7 @@ decode_huffman :: proc(z: ^Context, t: ^Huffman_Table) -> (r: u16, err: Error) #
|
|||||||
if b != 0 {
|
if b != 0 {
|
||||||
s := u8(b >> ZFAST_BITS);
|
s := u8(b >> ZFAST_BITS);
|
||||||
compress.consume_bits_lsb(z, s);
|
compress.consume_bits_lsb(z, s);
|
||||||
return b & 511, E_General.OK;
|
return b & 511, nil;
|
||||||
}
|
}
|
||||||
return decode_huffman_slowpath(z, t);
|
return decode_huffman_slowpath(z, t);
|
||||||
}
|
}
|
||||||
@@ -255,7 +255,7 @@ decode_huffman :: proc(z: ^Context, t: ^Huffman_Table) -> (r: u16, err: Error) #
|
|||||||
parse_huffman_block :: proc(z: ^Context, z_repeat, z_offset: ^Huffman_Table) -> (err: Error) #no_bounds_check {
|
parse_huffman_block :: proc(z: ^Context, z_repeat, z_offset: ^Huffman_Table) -> (err: Error) #no_bounds_check {
|
||||||
#no_bounds_check for {
|
#no_bounds_check for {
|
||||||
value, e := decode_huffman(z, z_repeat);
|
value, e := decode_huffman(z, z_repeat);
|
||||||
if e != E_General.OK {
|
if e != nil {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
if value < 256 {
|
if value < 256 {
|
||||||
@@ -266,7 +266,7 @@ parse_huffman_block :: proc(z: ^Context, z_repeat, z_offset: ^Huffman_Table) ->
|
|||||||
} else {
|
} else {
|
||||||
if value == 256 {
|
if value == 256 {
|
||||||
// End of block
|
// End of block
|
||||||
return E_General.OK;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
value -= 257;
|
value -= 257;
|
||||||
@@ -276,7 +276,7 @@ parse_huffman_block :: proc(z: ^Context, z_repeat, z_offset: ^Huffman_Table) ->
|
|||||||
}
|
}
|
||||||
|
|
||||||
value, e = decode_huffman(z, z_offset);
|
value, e = decode_huffman(z, z_offset);
|
||||||
if e != E_General.OK {
|
if e != nil {
|
||||||
return E_Deflate.Bad_Huffman_Code;
|
return E_Deflate.Bad_Huffman_Code;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -389,7 +389,7 @@ inflate_from_stream :: proc(using ctx: ^Context, raw := false, allocator := cont
|
|||||||
|
|
||||||
// Parse ZLIB stream without header.
|
// Parse ZLIB stream without header.
|
||||||
err = inflate_raw(ctx);
|
err = inflate_raw(ctx);
|
||||||
if err != E_General.OK {
|
if err != nil {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -401,7 +401,7 @@ inflate_from_stream :: proc(using ctx: ^Context, raw := false, allocator := cont
|
|||||||
return E_General.Checksum_Failed;
|
return E_General.Checksum_Failed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return E_General.OK;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @(optimization_mode="speed")
|
// @(optimization_mode="speed")
|
||||||
@@ -417,15 +417,15 @@ inflate_from_stream_raw :: proc(z: ^Context, allocator := context.allocator) ->
|
|||||||
codelength_ht: ^Huffman_Table;
|
codelength_ht: ^Huffman_Table;
|
||||||
|
|
||||||
z_repeat, err = allocate_huffman_table(allocator=context.allocator);
|
z_repeat, err = allocate_huffman_table(allocator=context.allocator);
|
||||||
if err != E_General.OK {
|
if err != nil {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
z_offset, err = allocate_huffman_table(allocator=context.allocator);
|
z_offset, err = allocate_huffman_table(allocator=context.allocator);
|
||||||
if err != E_General.OK {
|
if err != nil {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
codelength_ht, err = allocate_huffman_table(allocator=context.allocator);
|
codelength_ht, err = allocate_huffman_table(allocator=context.allocator);
|
||||||
if err != E_General.OK {
|
if err != nil {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
defer free(z_repeat);
|
defer free(z_repeat);
|
||||||
@@ -481,11 +481,11 @@ inflate_from_stream_raw :: proc(z: ^Context, allocator := context.allocator) ->
|
|||||||
if type == 1 {
|
if type == 1 {
|
||||||
// Use fixed code lengths.
|
// Use fixed code lengths.
|
||||||
err = build_huffman(z_repeat, Z_FIXED_LENGTH[:]);
|
err = build_huffman(z_repeat, Z_FIXED_LENGTH[:]);
|
||||||
if err != E_General.OK {
|
if err != nil {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
err = build_huffman(z_offset, Z_FIXED_DIST[:]);
|
err = build_huffman(z_offset, Z_FIXED_DIST[:]);
|
||||||
if err != E_General.OK {
|
if err != nil {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -506,7 +506,7 @@ inflate_from_stream_raw :: proc(z: ^Context, allocator := context.allocator) ->
|
|||||||
codelength_sizes[Z_LENGTH_DEZIGZAG[i]] = u8(s);
|
codelength_sizes[Z_LENGTH_DEZIGZAG[i]] = u8(s);
|
||||||
}
|
}
|
||||||
err = build_huffman(codelength_ht, codelength_sizes[:]);
|
err = build_huffman(codelength_ht, codelength_sizes[:]);
|
||||||
if err != E_General.OK {
|
if err != nil {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -515,7 +515,7 @@ inflate_from_stream_raw :: proc(z: ^Context, allocator := context.allocator) ->
|
|||||||
|
|
||||||
for n < ntot {
|
for n < ntot {
|
||||||
c, err = decode_huffman(z, codelength_ht);
|
c, err = decode_huffman(z, codelength_ht);
|
||||||
if err != E_General.OK {
|
if err != nil {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -559,18 +559,18 @@ inflate_from_stream_raw :: proc(z: ^Context, allocator := context.allocator) ->
|
|||||||
}
|
}
|
||||||
|
|
||||||
err = build_huffman(z_repeat, lencodes[:hlit]);
|
err = build_huffman(z_repeat, lencodes[:hlit]);
|
||||||
if err != E_General.OK {
|
if err != nil {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = build_huffman(z_offset, lencodes[hlit:ntot]);
|
err = build_huffman(z_offset, lencodes[hlit:ntot]);
|
||||||
if err != E_General.OK {
|
if err != nil {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = parse_huffman_block(z, z_repeat, z_offset);
|
err = parse_huffman_block(z, z_repeat, z_offset);
|
||||||
// log.debugf("Err: %v | Final: %v | Type: %v\n", err, final, type);
|
// log.debugf("Err: %v | Final: %v | Type: %v\n", err, final, type);
|
||||||
if err != E_General.OK {
|
if err != nil {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -578,7 +578,7 @@ inflate_from_stream_raw :: proc(z: ^Context, allocator := context.allocator) ->
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return E_General.OK;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
inflate_from_byte_array :: proc(input: []u8, buf: ^bytes.Buffer, raw := false) -> (err: Error) {
|
inflate_from_byte_array :: proc(input: []u8, buf: ^bytes.Buffer, raw := false) -> (err: Error) {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ main :: proc() {
|
|||||||
img, err = png.load(file, options);
|
img, err = png.load(file, options);
|
||||||
defer png.destroy(img);
|
defer png.destroy(img);
|
||||||
|
|
||||||
if err != png.E_General.OK {
|
if err != nil {
|
||||||
fmt.printf("Trying to read PNG file %v returned %v\n", file, err);
|
fmt.printf("Trying to read PNG file %v returned %v\n", file, err);
|
||||||
} else {
|
} else {
|
||||||
v: png.Info;
|
v: png.Info;
|
||||||
@@ -120,7 +120,7 @@ main :: proc() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err == E_General.OK && .do_not_decompress_image not_in options && .info not_in options {
|
if err == nil && .do_not_decompress_image not_in options && .info not_in options {
|
||||||
if ok := write_image_as_ppm("out.ppm", img); ok {
|
if ok := write_image_as_ppm("out.ppm", img); ok {
|
||||||
fmt.println("Saved decoded image.");
|
fmt.println("Saved decoded image.");
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ text :: proc(c: Chunk) -> (res: Text, ok: bool) {
|
|||||||
buf: bytes.Buffer;
|
buf: bytes.Buffer;
|
||||||
zlib_error := zlib.inflate_from_byte_array(fields[2], &buf);
|
zlib_error := zlib.inflate_from_byte_array(fields[2], &buf);
|
||||||
defer bytes.buffer_destroy(&buf);
|
defer bytes.buffer_destroy(&buf);
|
||||||
if zlib_error != E_General.OK {
|
if zlib_error != nil {
|
||||||
ok = false; return;
|
ok = false; return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,7 +161,7 @@ text :: proc(c: Chunk) -> (res: Text, ok: bool) {
|
|||||||
buf: bytes.Buffer;
|
buf: bytes.Buffer;
|
||||||
zlib_error := zlib.inflate_from_byte_array(rest, &buf);
|
zlib_error := zlib.inflate_from_byte_array(rest, &buf);
|
||||||
defer bytes.buffer_destroy(&buf);
|
defer bytes.buffer_destroy(&buf);
|
||||||
if zlib_error != E_General.OK {
|
if zlib_error != nil {
|
||||||
|
|
||||||
ok = false; return;
|
ok = false; return;
|
||||||
}
|
}
|
||||||
@@ -200,7 +200,7 @@ iccp :: proc(c: Chunk) -> (res: iCCP, ok: bool) {
|
|||||||
// Set up ZLIB context and decompress iCCP payload
|
// Set up ZLIB context and decompress iCCP payload
|
||||||
buf: bytes.Buffer;
|
buf: bytes.Buffer;
|
||||||
zlib_error := zlib.inflate_from_byte_array(fields[2], &buf);
|
zlib_error := zlib.inflate_from_byte_array(fields[2], &buf);
|
||||||
if zlib_error != E_General.OK {
|
if zlib_error != nil {
|
||||||
bytes.buffer_destroy(&buf);
|
bytes.buffer_destroy(&buf);
|
||||||
ok = false; return;
|
ok = false; return;
|
||||||
}
|
}
|
||||||
@@ -498,7 +498,7 @@ when false {
|
|||||||
err = zlib.write_zlib_stream_from_memory(&ctx);
|
err = zlib.write_zlib_stream_from_memory(&ctx);
|
||||||
|
|
||||||
b: []u8;
|
b: []u8;
|
||||||
if err == E_General.OK {
|
if err == nil {
|
||||||
b = ctx.out_buf[:];
|
b = ctx.out_buf[:];
|
||||||
} else {
|
} else {
|
||||||
return err;
|
return err;
|
||||||
@@ -511,6 +511,6 @@ when false {
|
|||||||
iend := make_chunk([]u8{}, .IEND);
|
iend := make_chunk([]u8{}, .IEND);
|
||||||
write_chunk(fd, iend);
|
write_chunk(fd, iend);
|
||||||
|
|
||||||
return E_General.OK;
|
return nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-20
@@ -267,13 +267,13 @@ read_chunk :: proc(ctx: ^compress.Context) -> (Chunk, Error) {
|
|||||||
if chunk.crc != u32be(computed_crc) {
|
if chunk.crc != u32be(computed_crc) {
|
||||||
return {}, E_General.Checksum_Failed;
|
return {}, E_General.Checksum_Failed;
|
||||||
}
|
}
|
||||||
return chunk, E_General.OK;
|
return chunk, nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
read_header :: proc(ctx: ^compress.Context) -> (IHDR, Error) {
|
read_header :: proc(ctx: ^compress.Context) -> (IHDR, Error) {
|
||||||
|
|
||||||
c, e := read_chunk(ctx);
|
c, e := read_chunk(ctx);
|
||||||
if e != E_General.OK {
|
if e != nil {
|
||||||
return {}, e;
|
return {}, e;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -341,7 +341,7 @@ read_header :: proc(ctx: ^compress.Context) -> (IHDR, Error) {
|
|||||||
return {}, E_PNG.Unknown_Color_Type;
|
return {}, E_PNG.Unknown_Color_Type;
|
||||||
}
|
}
|
||||||
|
|
||||||
return header, E_General.OK;
|
return header, nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
chunk_type_to_name :: proc(type: ^Chunk_Type) -> string {
|
chunk_type_to_name :: proc(type: ^Chunk_Type) -> string {
|
||||||
@@ -453,7 +453,7 @@ load_from_stream :: proc(stream: io.Stream, options := Options{}, allocator := c
|
|||||||
seen_ihdr = true;
|
seen_ihdr = true;
|
||||||
|
|
||||||
header, err = read_header(&ctx);
|
header, err = read_header(&ctx);
|
||||||
if err != E_General.OK {
|
if err != nil {
|
||||||
return img, err;
|
return img, err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -506,7 +506,7 @@ load_from_stream :: proc(stream: io.Stream, options := Options{}, allocator := c
|
|||||||
}
|
}
|
||||||
|
|
||||||
c, err = read_chunk(&ctx);
|
c, err = read_chunk(&ctx);
|
||||||
if err != E_General.OK {
|
if err != nil {
|
||||||
return img, err;
|
return img, err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -527,7 +527,7 @@ load_from_stream :: proc(stream: io.Stream, options := Options{}, allocator := c
|
|||||||
if .return_metadata not_in options && .do_not_decompress_image in options {
|
if .return_metadata not_in options && .do_not_decompress_image in options {
|
||||||
img.channels = final_image_channels;
|
img.channels = final_image_channels;
|
||||||
img.sidecar = info;
|
img.sidecar = info;
|
||||||
return img, E_General.OK;
|
return img, nil;
|
||||||
}
|
}
|
||||||
// There must be at least 1 IDAT, contiguous if more.
|
// There must be at least 1 IDAT, contiguous if more.
|
||||||
if seen_idat {
|
if seen_idat {
|
||||||
@@ -541,7 +541,7 @@ load_from_stream :: proc(stream: io.Stream, options := Options{}, allocator := c
|
|||||||
next := ch.type;
|
next := ch.type;
|
||||||
for next == .IDAT {
|
for next == .IDAT {
|
||||||
c, err = read_chunk(&ctx);
|
c, err = read_chunk(&ctx);
|
||||||
if err != E_General.OK {
|
if err != nil {
|
||||||
return img, err;
|
return img, err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -561,7 +561,7 @@ load_from_stream :: proc(stream: io.Stream, options := Options{}, allocator := c
|
|||||||
seen_idat = true;
|
seen_idat = true;
|
||||||
case .IEND:
|
case .IEND:
|
||||||
c, err = read_chunk(&ctx);
|
c, err = read_chunk(&ctx);
|
||||||
if err != E_General.OK {
|
if err != nil {
|
||||||
return img, err;
|
return img, err;
|
||||||
}
|
}
|
||||||
seen_iend = true;
|
seen_iend = true;
|
||||||
@@ -570,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
|
// TODO: Make sure that 16-bit bKGD + tRNS chunks return u16 instead of u16be
|
||||||
|
|
||||||
c, err = read_chunk(&ctx);
|
c, err = read_chunk(&ctx);
|
||||||
if err != E_General.OK {
|
if err != nil {
|
||||||
return img, err;
|
return img, err;
|
||||||
}
|
}
|
||||||
seen_bkgd = true;
|
seen_bkgd = true;
|
||||||
@@ -605,7 +605,7 @@ load_from_stream :: proc(stream: io.Stream, options := Options{}, allocator := c
|
|||||||
}
|
}
|
||||||
case .tRNS:
|
case .tRNS:
|
||||||
c, err = read_chunk(&ctx);
|
c, err = read_chunk(&ctx);
|
||||||
if err != E_General.OK {
|
if err != nil {
|
||||||
return img, err;
|
return img, err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -647,7 +647,7 @@ load_from_stream :: proc(stream: io.Stream, options := Options{}, allocator := c
|
|||||||
case:
|
case:
|
||||||
// Unhandled type
|
// Unhandled type
|
||||||
c, err = read_chunk(&ctx);
|
c, err = read_chunk(&ctx);
|
||||||
if err != E_General.OK {
|
if err != nil {
|
||||||
return img, err;
|
return img, err;
|
||||||
}
|
}
|
||||||
if .return_metadata in options {
|
if .return_metadata in options {
|
||||||
@@ -664,7 +664,7 @@ load_from_stream :: proc(stream: io.Stream, options := Options{}, allocator := c
|
|||||||
}
|
}
|
||||||
if .do_not_decompress_image in options {
|
if .do_not_decompress_image in options {
|
||||||
img.channels = final_image_channels;
|
img.channels = final_image_channels;
|
||||||
return img, E_General.OK;
|
return img, nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !seen_idat {
|
if !seen_idat {
|
||||||
@@ -675,7 +675,7 @@ load_from_stream :: proc(stream: io.Stream, options := Options{}, allocator := c
|
|||||||
zlib_error := zlib.inflate(idat, &buf);
|
zlib_error := zlib.inflate(idat, &buf);
|
||||||
defer bytes.buffer_destroy(&buf);
|
defer bytes.buffer_destroy(&buf);
|
||||||
|
|
||||||
if zlib_error != E_General.OK {
|
if zlib_error != nil {
|
||||||
return {}, zlib_error;
|
return {}, zlib_error;
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
@@ -712,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.
|
as metadata, and set it instead to the raw number of channels.
|
||||||
*/
|
*/
|
||||||
defilter_error := defilter(img, &buf, &header, options);
|
defilter_error := defilter(img, &buf, &header, options);
|
||||||
if defilter_error != E_General.OK {
|
if defilter_error != nil {
|
||||||
bytes.buffer_destroy(&img.pixels);
|
bytes.buffer_destroy(&img.pixels);
|
||||||
return {}, defilter_error;
|
return {}, defilter_error;
|
||||||
}
|
}
|
||||||
@@ -727,10 +727,10 @@ load_from_stream :: proc(stream: io.Stream, options := Options{}, allocator := c
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
if .Paletted in header.color_type && .do_not_expand_indexed in options {
|
if .Paletted in header.color_type && .do_not_expand_indexed in options {
|
||||||
return img, E_General.OK;
|
return img, nil;
|
||||||
}
|
}
|
||||||
if .Color not_in header.color_type && .do_not_expand_grayscale in options {
|
if .Color not_in header.color_type && .do_not_expand_grayscale in options {
|
||||||
return img, E_General.OK;
|
return img, nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -839,7 +839,7 @@ load_from_stream :: proc(stream: io.Stream, options := Options{}, allocator := c
|
|||||||
// If we have 3 in and 3 out, or 4 in and 4 out without premultiplication...
|
// If we have 3 in and 3 out, or 4 in and 4 out without premultiplication...
|
||||||
if raw_image_channels == 4 && .alpha_premultiply not_in options && !seen_bkgd {
|
if raw_image_channels == 4 && .alpha_premultiply not_in options && !seen_bkgd {
|
||||||
// Then we're done.
|
// Then we're done.
|
||||||
return img, E_General.OK;
|
return img, nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1036,7 +1036,7 @@ load_from_stream :: proc(stream: io.Stream, options := Options{}, allocator := c
|
|||||||
// If we have 3 in and 3 out, or 4 in and 4 out without premultiplication...
|
// If we have 3 in and 3 out, or 4 in and 4 out without premultiplication...
|
||||||
if !premultiply {
|
if !premultiply {
|
||||||
// Then we're done.
|
// Then we're done.
|
||||||
return img, E_General.OK;
|
return img, nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1229,7 +1229,7 @@ load_from_stream :: proc(stream: io.Stream, options := Options{}, allocator := c
|
|||||||
unreachable("We should never see bit depths other than 8, 16 and 'Paletted' here.");
|
unreachable("We should never see bit depths other than 8, 16 and 'Paletted' here.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return img, E_General.OK;
|
return img, nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1651,7 +1651,7 @@ defilter :: proc(img: ^Image, filter_bytes: ^bytes.Buffer, header: ^IHDR, option
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return E_General.OK;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
load :: proc{load_from_file, load_from_slice, load_from_stream};
|
load :: proc{load_from_file, load_from_slice, load_from_stream};
|
||||||
|
|||||||
Reference in New Issue
Block a user