diff --git a/core/image/bmp/bmp.odin b/core/image/bmp/bmp.odin index 057c2ffa047..affeab2a99d 100644 --- a/core/image/bmp/bmp.odin +++ b/core/image/bmp/bmp.odin @@ -242,17 +242,9 @@ load_from_context :: proc(ctx: ^$C, options := Options{}, allocator := context.a case: return img, .Unsupported_Compression } - // Flipped vertically - if info.height < 0 { - pixels := mem.slice_data_cast([]RGB_Pixel, img.pixels.buf[:]) - for y in 0.. (ok: bo return true } +vertical_flip :: proc(img: ^Image) { + pixels := img.pixels.buf[:] + bpp := img.depth/8 * img.channels + bytes_per_line := img.width * bpp + for y in 0.. (img: ^Image, err: Error) { +load_from_bytes :: proc(data: []byte, options := Options{}, allocator := context.allocator) -> (img: ^Image, err: Error) { context.allocator = allocator img = new(Image) @@ -47,6 +48,9 @@ load_from_bytes :: proc(data: []byte, allocator := context.allocator) -> (img: ^ } img.metadata = info + if .vertical_flip in options { + image.vertical_flip(img) + } return img, nil } @@ -722,7 +726,7 @@ autoselect_pbm_format_from_image :: proc(img: ^Image, prefer_binary := true, for @(init, private) _register :: proc() { loader :: proc(data: []byte, options: image.Options, allocator: mem.Allocator) -> (img: ^Image, err: Error) { - return load_from_bytes(data, allocator) + return load_from_bytes(data, options, allocator) } destroyer :: proc(img: ^Image) { _ = destroy(img) diff --git a/core/image/png/png.odin b/core/image/png/png.odin index 2d3665e9482..4bcb1583856 100644 --- a/core/image/png/png.odin +++ b/core/image/png/png.odin @@ -1182,6 +1182,9 @@ load_from_context :: proc(ctx: ^$C, options := Options{}, allocator := context.a panic("We should never see bit depths other than 8, 16 and 'Paletted' here.") } + if .vertical_flip in options { + image.vertical_flip(img) + } return img, nil } diff --git a/core/image/qoi/qoi.odin b/core/image/qoi/qoi.odin index 6b6149e60ae..490b08004e9 100644 --- a/core/image/qoi/qoi.odin +++ b/core/image/qoi/qoi.odin @@ -323,6 +323,10 @@ load_from_context :: proc(ctx: ^$C, options := Options{}, allocator := context.a return img, .Post_Processing_Error } + if .vertical_flip in options { + image.vertical_flip(img) + } + return } diff --git a/core/image/tga/tga.odin b/core/image/tga/tga.odin index 46e37a0cfce..0fdb3f3d138 100644 --- a/core/image/tga/tga.odin +++ b/core/image/tga/tga.odin @@ -371,6 +371,9 @@ load_from_context :: proc(ctx: ^$C, options := Options{}, allocator := context.a } line += 1 if origin_is_top else -1 } + if .vertical_flip in options { + image.vertical_flip(img) + } return img, nil }