Utilize union #shared_nil to core:image Error

This commit is contained in:
gingerBill
2022-03-24 12:06:18 +00:00
parent b6b3377786
commit 17e36bd5e1
4 changed files with 39 additions and 33 deletions
+2 -1
View File
@@ -118,7 +118,7 @@ Option :: enum {
}
Options :: distinct bit_set[Option]
Error :: union {
Error :: union #shared_nil {
General_Image_Error,
PNG_Error,
@@ -137,6 +137,7 @@ General_Image_Error :: enum {
}
PNG_Error :: enum {
None = 0,
Invalid_PNG_Signature,
IHDR_Not_First_Chunk,
IHDR_Corrupt,
+3 -3
View File
@@ -439,7 +439,7 @@ when false {
flags: int = O_WRONLY|O_CREATE|O_TRUNC
if len(image.pixels) == 0 || len(image.pixels) < image.width * image.height * int(image.channels) {
return E_PNG.Invalid_Image_Dimensions
return .Invalid_Image_Dimensions
}
mode: int = 0
@@ -450,7 +450,7 @@ when false {
fd, fderr := open(filename, flags, mode)
if fderr != 0 {
return E_General.Cannot_Open_File
return .Cannot_Open_File
}
defer close(fd)
@@ -473,7 +473,7 @@ when false {
case 3: ihdr.color_type = Color_Type{.Color}
case 4: ihdr.color_type = Color_Type{.Color, .Alpha}
case:// Unhandled
return E_PNG.Unknown_Color_Type
return .Unknown_Color_Type
}
h := make_chunk(ihdr, .IHDR)
write_chunk(fd, h)