From ecfea027a022abd2cabefe074375206ef0233120 Mon Sep 17 00:00:00 2001 From: Despacito696969 <56641258+Despacito696969@users.noreply.github.com> Date: Fri, 26 Aug 2022 23:49:33 +0200 Subject: [PATCH 01/14] Fixed marshal_to_writer not supporting i128 Previously json.marshal(i128(696969)) would print 0 as there was no `u = i128(i)` initialization. --- core/encoding/json/marshal.odin | 1 + 1 file changed, 1 insertion(+) diff --git a/core/encoding/json/marshal.odin b/core/encoding/json/marshal.odin index 8cc814fcf..8f7749aba 100644 --- a/core/encoding/json/marshal.odin +++ b/core/encoding/json/marshal.odin @@ -85,6 +85,7 @@ marshal_to_writer :: proc(w: io.Writer, v: any, opt: ^Marshal_Options) -> (err: case i16: u = u128(i) case i32: u = u128(i) case i64: u = u128(i) + case i128: u = u128(i) case int: u = u128(i) case u8: u = u128(i) case u16: u = u128(i) From 00f2e911a73e99b1283306272ff433984d90486c Mon Sep 17 00:00:00 2001 From: Benoit Jacquier Date: Sat, 27 Aug 2022 16:07:21 +0200 Subject: [PATCH 02/14] Add support for basic TGA loading --- core/image/common.odin | 6 ++ core/image/tga/tga.odin | 146 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 151 insertions(+), 1 deletion(-) diff --git a/core/image/common.odin b/core/image/common.odin index baacd64d9..beb3f93ee 100644 --- a/core/image/common.odin +++ b/core/image/common.odin @@ -61,6 +61,7 @@ Image_Metadata :: union #shared_nil { ^Netpbm_Info, ^PNG_Info, ^QOI_Info, + ^TGA_Info, } @@ -168,6 +169,7 @@ Error :: union #shared_nil { General_Image_Error :: enum { None = 0, + Unsupported_Option, // File I/O Unable_To_Read_File, Unable_To_Write_File, @@ -390,6 +392,10 @@ TGA_Header :: struct #packed { } #assert(size_of(TGA_Header) == 18) +TGA_Info :: struct { + header: TGA_Header, +} + // Function to help with image buffer calculations compute_buffer_size :: proc(width, height, channels, depth: int, extra_row_bytes := int(0)) -> (size: int) { size = ((((channels * width * depth) + 7) >> 3) + extra_row_bytes) * height diff --git a/core/image/tga/tga.odin b/core/image/tga/tga.odin index 67a088eb5..9b56b9db4 100644 --- a/core/image/tga/tga.odin +++ b/core/image/tga/tga.odin @@ -14,6 +14,11 @@ import "core:mem" import "core:image" import "core:bytes" import "core:os" +import "core:compress" + +// TODO: alpha_premultiply support +// TODO: RLE decompression + Error :: image.Error Image :: image.Image @@ -98,4 +103,143 @@ save_to_file :: proc(output: string, img: ^Image, options := Options{}, allocato return nil if write_ok else .Unable_To_Write_File } -save :: proc{save_to_memory, save_to_file} \ No newline at end of file +save :: proc{save_to_memory, save_to_file} + +load_from_context :: proc(ctx: ^$C, options := Options{}, allocator := context.allocator) -> (img: ^Image, err: Error) { + context.allocator = allocator + options := options + + if .alpha_premultiply in options { + return nil, .Unsupported_Option + } + + if .info in options { + options |= {.return_metadata, .do_not_decompress_image} + options -= {.info} + } + + if .return_header in options && .return_metadata in options { + options -= {.return_header} + } + + header := image.read_data(ctx, image.TGA_Header) or_return + + // Header checks + if header.data_type_code != DATATYPE_UNCOMPRESSED_RGB { + return nil, .Unsupported_Format + } + if header.bits_per_pixel!=24 && header.bits_per_pixel!=32 { + return nil, .Unsupported_Format + } + if ( header.image_descriptor & IMAGE_DESCRIPTOR_INTERLEAVING_MASK ) != 0 { + return nil, .Unsupported_Format + } + + if (int(header.dimensions[0])*int(header.dimensions[1])) > image.MAX_DIMENSIONS { + return nil, .Image_Dimensions_Too_Large + } + + if img == nil { + img = new(Image) + } + + if .return_metadata in options { + info := new(image.TGA_Info) + info.header = header + img.metadata = info + } + src_channels := int(header.bits_per_pixel)/8 + img.which = .TGA + img.channels = .alpha_add_if_missing in options ? 4: src_channels + img.channels = .alpha_drop_if_present in options ? 3: img.channels + + img.depth = 8 + img.width = int(header.dimensions[0]) + img.height = int(header.dimensions[1]) + + if .do_not_decompress_image in options { + return img, nil + } + + // skip id + if _, e := compress.read_slice(ctx, int(header.id_length)); e!= .None { + destroy(img) + return nil, .Corrupt + } + + if !resize(&img.pixels.buf, img.channels * img.width * img.height) { + destroy(img) + return nil, .Unable_To_Allocate_Or_Resize + } + + origin_is_topleft := (header.image_descriptor & IMAGE_DESCRIPTOR_TOPLEFT_MASK ) != 0 + for y in 0.. (img: ^Image, err: Error) { + ctx := &compress.Context_Memory_Input{ + input_data = data, + } + + img, err = load_from_context(ctx, options, allocator) + return img, err +} + +load_from_file :: proc(filename: string, options := Options{}, allocator := context.allocator) -> (img: ^Image, err: Error) { + context.allocator = allocator + + data, ok := os.read_entire_file(filename) + defer delete(data) + + if ok { + return load_from_bytes(data, options) + } else { + return nil, .Unable_To_Read_File + } +} + +load :: proc{load_from_file, load_from_bytes, load_from_context} + +destroy :: proc(img: ^Image) { + if img == nil { + return + } + + bytes.buffer_destroy(&img.pixels) + if v, ok := img.metadata.(^image.TGA_Info); ok { + free(v) + } + + free(img) +} + +DATATYPE_UNCOMPRESSED_RGB :: 0x2 +IMAGE_DESCRIPTOR_INTERLEAVING_MASK :: (1<<6) | (1<<7) +IMAGE_DESCRIPTOR_TOPLEFT_MASK :: 1<<5 + +@(init, private) +_register :: proc() { + image.register(.TGA, load_from_bytes, destroy) +} \ No newline at end of file From 934131abf86a03e98aa924fc93720e68729f317e Mon Sep 17 00:00:00 2001 From: Benoit Jacquier Date: Sat, 27 Aug 2022 19:30:15 +0200 Subject: [PATCH 03/14] Add RLE supports for TGA loader --- core/image/common.odin | 7 ++++- core/image/tga/tga.odin | 68 ++++++++++++++++++++++++++++++----------- 2 files changed, 57 insertions(+), 18 deletions(-) diff --git a/core/image/common.odin b/core/image/common.odin index a627fa68b..f0cb491a2 100644 --- a/core/image/common.odin +++ b/core/image/common.odin @@ -378,10 +378,15 @@ QOI_Info :: struct { header: QOI_Header, } +TGA_Data_Type :: enum u8 { + Uncompressed_RGB = 2, + Compressed_RBB = 10 +} + TGA_Header :: struct #packed { id_length: u8, color_map_type: u8, - data_type_code: u8, + data_type_code: TGA_Data_Type, color_map_origin: u16le, color_map_length: u16le, color_map_depth: u8, diff --git a/core/image/tga/tga.odin b/core/image/tga/tga.odin index 9b56b9db4..6fd65b7d9 100644 --- a/core/image/tga/tga.odin +++ b/core/image/tga/tga.odin @@ -4,6 +4,7 @@ List of contributors: Jeroen van Rijn: Initial implementation. + Benoit Jacquier: tga loader */ @@ -17,7 +18,6 @@ import "core:os" import "core:compress" // TODO: alpha_premultiply support -// TODO: RLE decompression Error :: image.Error @@ -62,7 +62,7 @@ save_to_memory :: proc(output: ^bytes.Buffer, img: ^Image, options := Options{} } header := image.TGA_Header{ - data_type_code = 0x02, // Color, uncompressed. + data_type_code = .Uncompressed_RGB, dimensions = {u16le(img.width), u16le(img.height)}, bits_per_pixel = u8(img.depth * img.channels), image_descriptor = 1 << 5, // Origin is top left. @@ -125,8 +125,12 @@ load_from_context :: proc(ctx: ^$C, options := Options{}, allocator := context.a header := image.read_data(ctx, image.TGA_Header) or_return // Header checks - if header.data_type_code != DATATYPE_UNCOMPRESSED_RGB { - return nil, .Unsupported_Format + rle_encoding := false + + switch header.data_type_code { + case .Compressed_RBB: rle_encoding = true + case .Uncompressed_RGB: + case: return nil, .Unsupported_Format } if header.bits_per_pixel!=24 && header.bits_per_pixel!=32 { return nil, .Unsupported_Format @@ -173,26 +177,57 @@ load_from_context :: proc(ctx: ^$C, options := Options{}, allocator := context.a } origin_is_topleft := (header.image_descriptor & IMAGE_DESCRIPTOR_TOPLEFT_MASK ) != 0 + rle_repetition_count := 0 + read_pixel := true + is_packet_rle := false + pixel: [4]u8 for y in 0..>7) != 0 + rle_repetition_count = 1 + int(rle_cmd & 0x7F) + read_pixel = true + } else if is_packet_rle==false { + read_pixel = rle_repetition_count>0 } else { - dst[3] = 255 + read_pixel = false } } + // Read pixel + if read_pixel { + src, err := compress.read_slice(ctx, src_channels) + if err!=.None { + destroy(img) + return nil, .Corrupt + } + pixel[2] = src[0] + pixel[1] = src[1] + pixel[0] = src[2] + pixel[3] = src_channels==4 ? src[3] : 255 + if img.channels==4 { + if src_channels==4 { + dst[3] = src[3] + } else { + dst[3] = 255 + } + } + } + + // Write pixel + mem.copy(dst, mem.raw_data(&pixel), img.channels) dst = mem.ptr_offset(dst, img.channels) + rle_repetition_count -= 1 } } return img, nil @@ -235,7 +270,6 @@ destroy :: proc(img: ^Image) { free(img) } -DATATYPE_UNCOMPRESSED_RGB :: 0x2 IMAGE_DESCRIPTOR_INTERLEAVING_MASK :: (1<<6) | (1<<7) IMAGE_DESCRIPTOR_TOPLEFT_MASK :: 1<<5 From 6363013dd8537a6d8321b4ab9dd4b9f1a3c922b8 Mon Sep 17 00:00:00 2001 From: Benoit Jacquier Date: Sat, 27 Aug 2022 19:45:14 +0200 Subject: [PATCH 04/14] style fix --- core/image/common.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/image/common.odin b/core/image/common.odin index f0cb491a2..7caba4fca 100644 --- a/core/image/common.odin +++ b/core/image/common.odin @@ -380,7 +380,7 @@ QOI_Info :: struct { TGA_Data_Type :: enum u8 { Uncompressed_RGB = 2, - Compressed_RBB = 10 + Compressed_RBB = 10, } TGA_Header :: struct #packed { From d9adb0fd6b89c5ac96a726b2eeafaf5d8d7798bc Mon Sep 17 00:00:00 2001 From: Lucas Perlind Date: Sun, 28 Aug 2022 16:29:50 +1000 Subject: [PATCH 05/14] Add much of Win32's Raw Input API --- core/sys/windows/user32.odin | 151 +++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) diff --git a/core/sys/windows/user32.odin b/core/sys/windows/user32.odin index 4b3d3e68e..d5ad9c378 100644 --- a/core/sys/windows/user32.odin +++ b/core/sys/windows/user32.odin @@ -190,6 +190,14 @@ foreign user32 { SetWindowTextW :: proc(hWnd: HWND, lpString: LPCWSTR) -> BOOL --- CallWindowProcW :: proc(lpPrevWndFunc: WNDPROC, hWnd: HWND, Msg: UINT, wParam: WPARAM, lParam: LPARAM) -> LRESULT --- EnableWindow :: proc(hWnd: HWND, bEnable: BOOL) -> BOOL --- + + DefRawInputProc :: proc(paRawInput: ^PRAWINPUT, nInput: INT, cbSizeHeader: UINT) -> LRESULT --- + GetRawInputBuffer :: proc(pRawInput: PRAWINPUT, pcbSize: PUINT, cbSizeHeader: UINT) -> UINT --- + GetRawInputData :: proc(hRawInput: HRAWINPUT, uiCommand: UINT, pData: LPVOID, pcbSize: PUINT, cbSizeHeader: UINT) -> UINT --- + GetRawInputDeviceInfoW :: proc(hDevice: HANDLE, uiCommand: UINT, pData: LPVOID, pcbSize: PUINT) -> UINT --- + GetRawInputDeviceList :: proc(pRawInputDeviceList: PRAWINPUTDEVICELIST, puiNumDevices: PUINT, cbSize: UINT) -> UINT --- + GetRegisteredRawInputDevices :: proc(pRawInputDevices: PRAWINPUTDEVICE, puiNumDevices: PUINT, cbSize: UINT) -> UINT --- + RegisterRawInputDevices :: proc(pRawInputDevices: PCRAWINPUTDEVICE, uiNumDevices: UINT, cbSize: UINT) -> BOOL --- } CreateWindowW :: #force_inline proc "stdcall" ( @@ -277,3 +285,146 @@ DPI_AWARENESS_CONTEXT_SYSTEM_AWARE :: DPI_AWARENESS_CONTEXT(~uintptr(1)) DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE :: DPI_AWARENESS_CONTEXT(~uintptr(2)) // -3 DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 :: DPI_AWARENESS_CONTEXT(~uintptr(3)) // -4 DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED :: DPI_AWARENESS_CONTEXT(~uintptr(4)) // -5 + +RAWINPUTHEADER :: struct { + dwType: DWORD, + dwSize: DWORD, + hDevice: HANDLE, + wParam: WPARAM, +} + +RAWHID :: struct { + dwSizeHid: DWORD, + dwCount: DWORD, + bRawData: [1]BYTE, +} + +RAWMOUSE :: struct { + usFlags: USHORT, + DUMMYUNIONNAME: struct #raw_union { + ulButtons: ULONG, + DUMMYSTRUCTNAME: struct { + usButtonFlags: USHORT, + usButtonData: USHORT, + }, + }, + ulRawButtons: ULONG, + lLastX: LONG, + lLastY: LONG, + ulExtraInformation: ULONG, +} + +RAWKEYBOARD :: struct { + MakeCode: USHORT, + Flags: USHORT, + Rserved: USHORT, + VKey: USHORT, + Message: UINT, + ExtraInformation: ULONG, +} + +RAWINPUT :: struct { + header: RAWINPUTHEADER, + data: struct #raw_union { + mouse: RAWMOUSE, + keyboard: RAWKEYBOARD, + hid: RAWHID, + }, +} + +PRAWINPUT :: ^RAWINPUT +HRAWINPUT :: distinct LPARAM + +RAWINPUTDEVICE :: struct { + usUsagePage: USHORT, + usUsage: USHORT, + dwFlags: DWORD, + hwndTarget: HWND, +} + +PRAWINPUTDEVICE :: ^RAWINPUTDEVICE +PCRAWINPUTDEVICE :: PRAWINPUTDEVICE + +RAWINPUTDEVICELIST :: struct { + hDevice: HANDLE, + dwType: DWORD, +} + +PRAWINPUTDEVICELIST :: ^RAWINPUTDEVICELIST + +RID_DEVICE_INFO_HID :: struct { + dwVendorId: DWORD, + dwProductId: DWORD, + dwVersionNumber: DWORD, + usUsagePage: USHORT, + usUsage: USHORT, +} + +RID_DEVICE_INFO_KEYBOARD :: struct { + dwType: DWORD, + dwSubType: DWORD, + dwKeyboardMode: DWORD, + dwNumberOfFunctionKeys: DWORD, + dwNumberOfIndicators: DWORD, + dwNumberOfKeysTotal: DWORD, +} + +RID_DEVICE_INFO_MOUSE :: struct { + dwId: DWORD, + dwNumberOfButtons: DWORD, + dwSampleRate: DWORD, + fHasHorizontalWheel: BOOL, +} + +RID_DEVICE_INFO :: struct { + cbSize: DWORD, + dwType: DWORD, + DUMMYUNIONNAME: struct #raw_union { + mouse: RID_DEVICE_INFO_MOUSE, + keyboard: RID_DEVICE_INFO_KEYBOARD, + hid: RID_DEVICE_INFO_HID, + }, +} + +RIDEV_REMOVE :: 0x00000001 +RIDEV_EXCLUDE :: 0x00000010 +RIDEV_PAGEONLY :: 0x00000020 +RIDEV_NOLEGACY :: 0x00000030 +RIDEV_INPUTSINK :: 0x00000100 +RIDEV_CAPTUREMOUSE :: 0x00000200 +RIDEV_NOHOTKEYS :: 0x00000200 +RIDEV_APPKEYS :: 0x00000400 +RIDEV_EXINPUTSINK :: 0x00001000 +RIDEV_DEVNOTIFY :: 0x00002000 + +RID_HEADER :: 0x10000005 +RID_INPUT :: 0x10000003 + +RIM_TYPEMOUSE :: 0 +RIM_TYPEKEYBOARD :: 1 +RIM_TYPEHID :: 2 + +MOUSE_MOVE_RELATIVE :: 0x00 +MOUSE_MOVE_ABSOLUTE :: 0x01 +MOUSE_VIRTUAL_DESKTOP :: 0x02 +MOUSE_ATTRIUBTTES_CHANGED :: 0x04 +MOUSE_MOVE_NOCOALESCE :: 0x08 + +RI_MOUSE_BUTTON_1_DOWN :: 0x0001 +RI_MOUSE_LEFT_BUTTON_DOWNS :: RI_MOUSE_BUTTON_1_DOWN +RI_MOUSE_BUTTON_1_UP :: 0x0002 +RI_MOUSE_LEFT_BUTTON_UP :: RI_MOUSE_BUTTON_1_UP +RI_MOUSE_BUTTON_2_DOWN :: 0x0004 +RI_MOUSE_RIGHT_BUTTON_DOWN :: RI_MOUSE_BUTTON_2_DOWN +RI_MOUSE_BUTTON_2_UP :: 0x0008 +RI_MOUSE_RIGHT_BUTTON_UP :: RI_MOUSE_BUTTON_2_UP +RI_MOUSE_BUTTON_3_DOWN :: 0x0010 +RI_MOUSE_MIDDLE_BUTTON_DOWN :: RI_MOUSE_BUTTON_3_DOWN +RI_MOUSE_BUTTON_3_UP :: 0x0020 +RI_MOUSE_MIDDLE_BUTTON_UP :: RI_MOUSE_BUTTON_3_UP +RI_MOUSE_BUTTON_4_DOWN :: 0x0040 +RI_MOUSE_BUTTON_4_UP :: 0x0080 +RI_MOUSE_BUTTON_5_DOWN :: 0x0100 +RI_MOUSE_BUTTON_5_UP :: 0x0200 +RI_MOUSE_WHEEL :: 0x0400 +RI_MOUSE_HWHEEL :: 0x0800 From f74e281efadbbd3c042f2f3aed13f0552cd881dd Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Sun, 28 Aug 2022 18:25:07 +0200 Subject: [PATCH 06/14] Various changes to TGA reader - Style changes - Change ptr usage to slice indexing - Add TGA Footer Also, add `peek_data` with offset to `compress`. --- core/compress/common.odin | 57 +++++++++++++++- core/image/common.odin | 17 ++++- core/image/tga/tga.odin | 139 ++++++++++++++++++++++++-------------- 3 files changed, 159 insertions(+), 54 deletions(-) diff --git a/core/compress/common.odin b/core/compress/common.odin index f4e378269..b42cbefff 100644 --- a/core/compress/common.odin +++ b/core/compress/common.odin @@ -294,6 +294,24 @@ peek_data_from_memory :: #force_inline proc(z: ^Context_Memory_Input, $T: typeid } } +@(optimization_mode="speed") +peek_data_at_offset_from_memory :: #force_inline proc(z: ^Context_Memory_Input, $T: typeid, #any_int offset: int) -> (res: T, err: io.Error) { + size :: size_of(T) + + #no_bounds_check { + if len(z.input_data) >= size + offset { + buf := z.input_data[offset:][:size] + return (^T)(&buf[0])^, .None + } + } + + if len(z.input_data) == 0 { + return T{}, .EOF + } else { + return T{}, .Short_Buffer + } +} + @(optimization_mode="speed") peek_data_from_stream :: #force_inline proc(z: ^Context_Stream_Input, $T: typeid) -> (res: T, err: io.Error) { size :: size_of(T) @@ -321,7 +339,44 @@ peek_data_from_stream :: #force_inline proc(z: ^Context_Stream_Input, $T: typeid return res, .None } -peek_data :: proc{peek_data_from_memory, peek_data_from_stream} +@(optimization_mode="speed") +peek_data_at_offset_from_stream :: #force_inline proc(z: ^Context_Stream_Input, $T: typeid, #any_int offset: int) -> (res: T, err: io.Error) { + size :: size_of(T) + + // Get current position to return to. + cur_pos, e1 := z.input->impl_seek(0, .Current) + if e1 != .None { + return T{}, e1 + } + + // Seek to offset. + pos, e2 := z.input->impl_seek(offset, .Start) + if e2 != .None { + return T{}, e2 + } + + r, e3 := io.to_reader_at(z.input) + if !e3 { + return T{}, .Empty + } + when size <= 128 { + b: [size]u8 + } else { + b := make([]u8, size, context.temp_allocator) + } + _, e4 := io.read_at(r, b[:], pos) + if e4 != .None { + return T{}, .Empty + } + + // Return read head to original position. + z.input->impl_seek(cur_pos, .Start) + + res = (^T)(&b[0])^ + return res, .None +} + +peek_data :: proc{peek_data_from_memory, peek_data_from_stream, peek_data_at_offset_from_memory, peek_data_at_offset_from_stream} diff --git a/core/image/common.odin b/core/image/common.odin index 7caba4fca..c79344445 100644 --- a/core/image/common.odin +++ b/core/image/common.odin @@ -46,7 +46,7 @@ Image :: struct { height: int, channels: int, depth: int, // Channel depth in bits, typically 8 or 16 - pixels: bytes.Buffer, + pixels: bytes.Buffer `fmt:"-"`, /* Some image loaders/writers can return/take an optional background color. For convenience, we return them as u16 so we don't need to switch on the type @@ -380,7 +380,7 @@ QOI_Info :: struct { TGA_Data_Type :: enum u8 { Uncompressed_RGB = 2, - Compressed_RBB = 10, + Compressed_RBB = 10, } TGA_Header :: struct #packed { @@ -397,8 +397,19 @@ TGA_Header :: struct #packed { } #assert(size_of(TGA_Header) == 18) +New_TGA_Signature :: "TRUEVISION-XFILE.\x00" + +TGA_Footer :: struct #packed { + extension_area_offset: u32le, + developer_directory_offset: u32le, + signature: [18]u8 `fmt:"s"`, // Should match signature if New TGA. +} +#assert(size_of(TGA_Footer) == 26) + TGA_Info :: struct { - header: TGA_Header, + header: TGA_Header, + image_id: string, + footer: Maybe(TGA_Footer), } // Function to help with image buffer calculations diff --git a/core/image/tga/tga.odin b/core/image/tga/tga.odin index 6fd65b7d9..d257d06ff 100644 --- a/core/image/tga/tga.odin +++ b/core/image/tga/tga.odin @@ -16,10 +16,12 @@ import "core:image" import "core:bytes" import "core:os" import "core:compress" +import "core:strings" +import "core:fmt" +_ :: fmt // TODO: alpha_premultiply support - Error :: image.Error Image :: image.Image Options :: image.Options @@ -122,6 +124,21 @@ load_from_context :: proc(ctx: ^$C, options := Options{}, allocator := context.a options -= {.return_header} } + // First check for a footer. + filesize := compress.input_size(ctx) or_return + + footer: image.TGA_Footer + have_valid_footer := false + + if filesize >= size_of(image.TGA_Header) + size_of(image.TGA_Footer) { + if f, f_err := compress.peek_data(ctx, image.TGA_Footer, filesize - i64(size_of(image.TGA_Footer))); f_err == .None { + if string(f.signature[:]) == image.New_TGA_Signature { + have_valid_footer = true + footer = f + } + } + } + header := image.read_data(ctx, image.TGA_Header) or_return // Header checks @@ -132,14 +149,16 @@ load_from_context :: proc(ctx: ^$C, options := Options{}, allocator := context.a case .Uncompressed_RGB: case: return nil, .Unsupported_Format } - if header.bits_per_pixel!=24 && header.bits_per_pixel!=32 { - return nil, .Unsupported_Format - } - if ( header.image_descriptor & IMAGE_DESCRIPTOR_INTERLEAVING_MASK ) != 0 { + + if header.bits_per_pixel != 24 && header.bits_per_pixel != 32 { return nil, .Unsupported_Format } - if (int(header.dimensions[0])*int(header.dimensions[1])) > image.MAX_DIMENSIONS { + if header.image_descriptor & IMAGE_DESCRIPTOR_INTERLEAVING_MASK != 0 { + return nil, .Unsupported_Format + } + + if int(header.dimensions[0]) * int(header.dimensions[1]) > image.MAX_DIMENSIONS { return nil, .Image_Dimensions_Too_Large } @@ -147,88 +166,104 @@ load_from_context :: proc(ctx: ^$C, options := Options{}, allocator := context.a img = new(Image) } + defer if err != nil { + destroy(img) + } + + src_channels := int(header.bits_per_pixel) / 8 + img.which = .TGA + img.channels = 4 if .alpha_add_if_missing in options else src_channels + img.channels = 3 if .alpha_drop_if_present in options else img.channels + + img.depth = 8 + img.width = int(header.dimensions[0]) + img.height = int(header.dimensions[1]) + + // Read Image ID if present + image_id := "" + if _id, e := compress.read_slice(ctx, int(header.id_length)); e != .None { + return nil, .Corrupt + } else { + if .return_metadata in options { + id := strings.trim_right_null(string(_id)) + image_id = strings.clone(id) + } + } + if .return_metadata in options { info := new(image.TGA_Info) - info.header = header + info.header = header + info.image_id = image_id + if have_valid_footer { + info.footer = footer + } img.metadata = info } - src_channels := int(header.bits_per_pixel)/8 - img.which = .TGA - img.channels = .alpha_add_if_missing in options ? 4: src_channels - img.channels = .alpha_drop_if_present in options ? 3: img.channels - - img.depth = 8 - img.width = int(header.dimensions[0]) - img.height = int(header.dimensions[1]) if .do_not_decompress_image in options { return img, nil } - // skip id - if _, e := compress.read_slice(ctx, int(header.id_length)); e!= .None { - destroy(img) - return nil, .Corrupt - } - if !resize(&img.pixels.buf, img.channels * img.width * img.height) { - destroy(img) - return nil, .Unable_To_Allocate_Or_Resize + return img, .Unable_To_Allocate_Or_Resize } - origin_is_topleft := (header.image_descriptor & IMAGE_DESCRIPTOR_TOPLEFT_MASK ) != 0 + origin_is_topleft := header.image_descriptor & IMAGE_DESCRIPTOR_TOPLEFT_MASK != 0 rle_repetition_count := 0 - read_pixel := true - is_packet_rle := false - pixel: [4]u8 - for y in 0..>7) != 0 + is_packet_rle = (rle_cmd >> 7) != 0 rle_repetition_count = 1 + int(rle_cmd & 0x7F) read_pixel = true - } else if is_packet_rle==false { - read_pixel = rle_repetition_count>0 + } else if !is_packet_rle { + read_pixel = rle_repetition_count > 0 } else { read_pixel = false } } // Read pixel if read_pixel { - src, err := compress.read_slice(ctx, src_channels) - if err!=.None { - destroy(img) - return nil, .Corrupt + src, src_err := compress.read_slice(ctx, src_channels) + if src_err != .None { + return img, .Corrupt } + pixel[2] = src[0] pixel[1] = src[1] pixel[0] = src[2] - pixel[3] = src_channels==4 ? src[3] : 255 - if img.channels==4 { - if src_channels==4 { - dst[3] = src[3] + + pixel[3] = src_channels == 4 ? src[3] : 255 + if img.channels == 4 { + if src_channels == 4 { + img.pixels.buf[offset:][3] = src[3] } else { - dst[3] = 255 + img.pixels.buf[offset:][3] = 255 } } } // Write pixel - mem.copy(dst, mem.raw_data(&pixel), img.channels) - dst = mem.ptr_offset(dst, img.channels) + copy(img.pixels.buf[offset:], pixel[:img.channels]) + offset += img.channels rle_repetition_count -= 1 } + line += 1 if origin_is_topleft else -1 } return img, nil } @@ -258,15 +293,19 @@ load_from_file :: proc(filename: string, options := Options{}, allocator := cont load :: proc{load_from_file, load_from_bytes, load_from_context} destroy :: proc(img: ^Image) { - if img == nil { + if img == nil || img.width == 0 || img.height == 0 { return } bytes.buffer_destroy(&img.pixels) if v, ok := img.metadata.(^image.TGA_Info); ok { + delete(v.image_id) free(v) } + // Make destroy idempotent + img.width = 0 + img.height = 0 free(img) } From d0109db23b742ac1a7ed44e0c47be86aad37336b Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Sun, 28 Aug 2022 19:41:42 +0200 Subject: [PATCH 07/14] [TGA] Add support for Top-Right and Bottom-Right origins. --- core/image/common.odin | 9 +++++++-- core/image/tga/tga.odin | 32 ++++++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/core/image/common.odin b/core/image/common.odin index c79344445..7c8df3d57 100644 --- a/core/image/common.odin +++ b/core/image/common.odin @@ -379,8 +379,13 @@ QOI_Info :: struct { } TGA_Data_Type :: enum u8 { - Uncompressed_RGB = 2, - Compressed_RBB = 10, + No_Image_Data = 0, + Uncompressed_Color_Mapped = 1, + Uncompressed_RGB = 2, + Uncompressed_Black_White = 3, + Compressed_Color_Mapped = 9, + Compressed_RGB = 10, + Compressed_Black_White = 11, } TGA_Header :: struct #packed { diff --git a/core/image/tga/tga.odin b/core/image/tga/tga.odin index d257d06ff..af5b07ef5 100644 --- a/core/image/tga/tga.odin +++ b/core/image/tga/tga.odin @@ -145,9 +145,23 @@ load_from_context :: proc(ctx: ^$C, options := Options{}, allocator := context.a rle_encoding := false switch header.data_type_code { - case .Compressed_RBB: rle_encoding = true + // Supported formats: RGB(A), RGB(A) RLE + case .Compressed_RGB: + rle_encoding = true case .Uncompressed_RGB: - case: return nil, .Unsupported_Format + + case .No_Image_Data: + return nil, .Unsupported_Format + case .Uncompressed_Color_Mapped: + return nil, .Unsupported_Format + case .Uncompressed_Black_White: + return nil, .Unsupported_Format + case .Compressed_Color_Mapped: + return nil, .Unsupported_Format + case .Compressed_Black_White: + return nil, .Unsupported_Format + case: + return nil, .Unsupported_Format } if header.bits_per_pixel != 24 && header.bits_per_pixel != 32 { @@ -208,7 +222,8 @@ load_from_context :: proc(ctx: ^$C, options := Options{}, allocator := context.a return img, .Unable_To_Allocate_Or_Resize } - origin_is_topleft := header.image_descriptor & IMAGE_DESCRIPTOR_TOPLEFT_MASK != 0 + origin_is_top := header.image_descriptor & IMAGE_DESCRIPTOR_TOP_MASK != 0 + origin_is_left := header.image_descriptor & IMAGE_DESCRIPTOR_RIGHT_MASK == 0 rle_repetition_count := 0 read_pixel := true is_packet_rle := false @@ -216,10 +231,10 @@ load_from_context :: proc(ctx: ^$C, options := Options{}, allocator := context.a pixel: [4]u8 stride := img.width * img.channels - line := 0 if origin_is_topleft else img.height - 1 + line := 0 if origin_is_top else img.height - 1 for _ in 0.. Date: Sun, 28 Aug 2022 21:48:51 +0200 Subject: [PATCH 08/14] [TGA] Add B5G5R5 15- and 16-bit support. --- core/image/tga/tga.odin | 141 ++++++++++++++++++++++++++++------------ 1 file changed, 99 insertions(+), 42 deletions(-) diff --git a/core/image/tga/tga.odin b/core/image/tga/tga.odin index af5b07ef5..d8b200b67 100644 --- a/core/image/tga/tga.odin +++ b/core/image/tga/tga.odin @@ -17,8 +17,6 @@ import "core:bytes" import "core:os" import "core:compress" import "core:strings" -import "core:fmt" -_ :: fmt // TODO: alpha_premultiply support @@ -142,29 +140,58 @@ load_from_context :: proc(ctx: ^$C, options := Options{}, allocator := context.a header := image.read_data(ctx, image.TGA_Header) or_return // Header checks - rle_encoding := false + rle_encoding := false + color_mapped := false + src_channels := 0 + dest_depth := header.bits_per_pixel + dest_channels := 0 - switch header.data_type_code { - // Supported formats: RGB(A), RGB(A) RLE - case .Compressed_RGB: - rle_encoding = true - case .Uncompressed_RGB: + #partial switch header.data_type_code { + // Supported formats: RGB(A), RGB(A) RLE + case .Compressed_RGB: + rle_encoding = true + case .Uncompressed_RGB: + // Intentionally blank + case .Uncompressed_Color_Mapped: + color_mapped = true - case .No_Image_Data: - return nil, .Unsupported_Format - case .Uncompressed_Color_Mapped: - return nil, .Unsupported_Format - case .Uncompressed_Black_White: - return nil, .Unsupported_Format - case .Compressed_Color_Mapped: - return nil, .Unsupported_Format - case .Compressed_Black_White: - return nil, .Unsupported_Format - case: - return nil, .Unsupported_Format + case: + return nil, .Unsupported_Format } - if header.bits_per_pixel != 24 && header.bits_per_pixel != 32 { + if color_mapped { + if header.color_map_type != 1 { + return nil, .Unsupported_Format + } + dest_depth = header.color_map_depth + + // Expect LUT entry index to be 8 bits + if header.bits_per_pixel != 8 || header.color_map_origin != 0 || header.color_map_length > 256 { + return nil, .Unsupported_Format + } + } + + switch dest_depth { + case 15: // B5G5R5 + src_channels = 2 + dest_channels = 3 + if color_mapped { + return nil, .Unsupported_Format + } + case 16: // B5G5R5A1 + src_channels = 2 + dest_channels = 3 // Alpha bit is dodgy in TGA, so we ignore it. + if color_mapped { + return nil, .Unsupported_Format + } + case 24: // RGB8 + src_channels = 3 if !color_mapped else 1 + dest_channels = 3 + case 32: // RGBA8 + src_channels = 4 if !color_mapped else 1 + dest_channels = 4 + + case: return nil, .Unsupported_Format } @@ -184,9 +211,8 @@ load_from_context :: proc(ctx: ^$C, options := Options{}, allocator := context.a destroy(img) } - src_channels := int(header.bits_per_pixel) / 8 img.which = .TGA - img.channels = 4 if .alpha_add_if_missing in options else src_channels + img.channels = 4 if .alpha_add_if_missing in options else dest_channels img.channels = 3 if .alpha_drop_if_present in options else img.channels img.depth = 8 @@ -196,7 +222,7 @@ load_from_context :: proc(ctx: ^$C, options := Options{}, allocator := context.a // Read Image ID if present image_id := "" if _id, e := compress.read_slice(ctx, int(header.id_length)); e != .None { - return nil, .Corrupt + return img, .Corrupt } else { if .return_metadata in options { id := strings.trim_right_null(string(_id)) @@ -204,6 +230,32 @@ load_from_context :: proc(ctx: ^$C, options := Options{}, allocator := context.a } } + color_map := make([]RGBA_Pixel, header.color_map_length) + defer delete(color_map) + + if color_mapped { + switch header.color_map_depth { + case 24: + for i in 0..> 5) & 31) << 3 + r := u8((v >> 10) & 31) << 3 + pixel = {r, g, b, 255} + case 3: + pixel = {src[2], src[1], src[0], 255} + case 4: + pixel = {src[2], src[1], src[0], src[3]} + case: + return img, .Corrupt } } // Write pixel - copy(img.pixels.buf[offset:], pixel[:img.channels]) - offset += img.channels if origin_is_left else -img.channels + copy(img.pixels.buf[offset:], pixel[:dest_channels]) + offset += dest_channels if origin_is_left else -dest_channels rle_repetition_count -= 1 } line += 1 if origin_is_top else -1 From 3d4698debeac92e86da0f2771207e135ce06b223 Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Mon, 29 Aug 2022 00:29:50 +0200 Subject: [PATCH 09/14] [TGA] Add B&W and RLE color-mapped. --- core/image/common.odin | 39 ++++++++++++++++++++++--- core/image/tga/tga.odin | 65 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 92 insertions(+), 12 deletions(-) diff --git a/core/image/common.odin b/core/image/common.odin index 7c8df3d57..58ff83dd1 100644 --- a/core/image/common.odin +++ b/core/image/common.odin @@ -407,14 +407,45 @@ New_TGA_Signature :: "TRUEVISION-XFILE.\x00" TGA_Footer :: struct #packed { extension_area_offset: u32le, developer_directory_offset: u32le, - signature: [18]u8 `fmt:"s"`, // Should match signature if New TGA. + signature: [18]u8 `fmt:"s,0"`, // Should match signature if New TGA. } #assert(size_of(TGA_Footer) == 26) +TGA_Extension :: struct #packed { + extension_size: u16le, // Size of this struct. If not 495 bytes it means it's an unsupported version. + author_name: [41]u8 `fmt:"s,0"`, // Author name, ASCII. Zero-terminated + author_comments: [324]u8 `fmt:"s,0"`, // Author comments, formatted as 4 lines of 80 character lines, each zero terminated. + datetime: struct {month, day, year, hour, minute, second: u16le}, + job_name: [41]u8 `fmt:"s,0"`, // Author name, ASCII. Zero-terminated + job_time: struct {hour, minute, second: u16le}, + software_id: [41]u8 `fmt:"s,0"`, // Software ID name, ASCII. Zero-terminated + software_version: struct #packed { + number: u16le, // Version number * 100 + letter: u8 `fmt:"r"`, // " " if not used + }, + key_color: [4]u8, // ARGB key color used at time of production + aspect_ratio: [2]u16le, // Numerator / Denominator + gamma: [2]u16le, // Numerator / Denominator, range should be 0.0..10.0 + color_correction_offset: u32le, // 0 if no color correction information + postage_stamp_offset: u32le, // 0 if no thumbnail + scanline_offset: u32le, // 0 if no scanline table + attributes: TGA_Alpha_Kind, +} +#assert(size_of(TGA_Extension) == 495) + +TGA_Alpha_Kind :: enum u8 { + None, + Undefined_Ignore, + Undefined_Retain, + Useful, + Premultiplied, +} + TGA_Info :: struct { - header: TGA_Header, - image_id: string, - footer: Maybe(TGA_Footer), + header: TGA_Header, + image_id: string, + footer: Maybe(TGA_Footer), + extension: Maybe(TGA_Extension), } // Function to help with image buffer calculations diff --git a/core/image/tga/tga.odin b/core/image/tga/tga.odin index d8b200b67..39c46c7c7 100644 --- a/core/image/tga/tga.odin +++ b/core/image/tga/tga.odin @@ -24,6 +24,7 @@ Error :: image.Error Image :: image.Image Options :: image.Options +GA_Pixel :: image.GA_Pixel RGB_Pixel :: image.RGB_Pixel RGBA_Pixel :: image.RGBA_Pixel @@ -128,20 +129,33 @@ load_from_context :: proc(ctx: ^$C, options := Options{}, allocator := context.a footer: image.TGA_Footer have_valid_footer := false + extension: image.TGA_Extension + have_valid_extension := false + if filesize >= size_of(image.TGA_Header) + size_of(image.TGA_Footer) { if f, f_err := compress.peek_data(ctx, image.TGA_Footer, filesize - i64(size_of(image.TGA_Footer))); f_err == .None { if string(f.signature[:]) == image.New_TGA_Signature { have_valid_footer = true footer = f + + if i64(footer.extension_area_offset) + i64(size_of(image.TGA_Extension)) < filesize { + if e, e_err := compress.peek_data(ctx, image.TGA_Extension, footer.extension_area_offset); e_err == .None { + if e.extension_size == size_of(image.TGA_Extension) { + have_valid_extension = true + extension = e + } + } + } } } } header := image.read_data(ctx, image.TGA_Header) or_return - + // Header checks rle_encoding := false color_mapped := false + black_white := false src_channels := 0 dest_depth := header.bits_per_pixel dest_channels := 0 @@ -152,8 +166,18 @@ load_from_context :: proc(ctx: ^$C, options := Options{}, allocator := context.a rle_encoding = true case .Uncompressed_RGB: // Intentionally blank + case .Uncompressed_Black_White: + black_white = true + dest_depth = 24 case .Uncompressed_Color_Mapped: color_mapped = true + case .Compressed_Color_Mapped: + color_mapped = true + rle_encoding = true + case .Compressed_Black_White: + black_white = true + rle_encoding = true + dest_depth = 24 case: return nil, .Unsupported_Format @@ -176,16 +200,16 @@ load_from_context :: proc(ctx: ^$C, options := Options{}, allocator := context.a src_channels = 2 dest_channels = 3 if color_mapped { - return nil, .Unsupported_Format + src_channels = 1 } case 16: // B5G5R5A1 src_channels = 2 dest_channels = 3 // Alpha bit is dodgy in TGA, so we ignore it. if color_mapped { - return nil, .Unsupported_Format + src_channels = 1 } case 24: // RGB8 - src_channels = 3 if !color_mapped else 1 + src_channels = 1 if (color_mapped || black_white) else 3 dest_channels = 3 case 32: // RGBA8 src_channels = 4 if !color_mapped else 1 @@ -235,6 +259,16 @@ load_from_context :: proc(ctx: ^$C, options := Options{}, allocator := context.a if color_mapped { switch header.color_map_depth { + case 16: + for i in 0..> 5) & 31) << 3 + r := u8((v >> 10) & 31) << 3 + pixel = {r, g, b, 255} + } + case 2: - assert(dest_depth == 16) - v := int(src[0]) | int(src[1]) << 8 + v := u16(src[0]) | u16(src[1]) << 8 b := u8( v & 31) << 3 g := u8((v >> 5) & 31) << 3 r := u8((v >> 10) & 31) << 3 pixel = {r, g, b, 255} + case 3: pixel = {src[2], src[1], src[0], 255} case 4: From 6c2e0b09ba04c332f58695db55665fb6f66ddbc3 Mon Sep 17 00:00:00 2001 From: Colin Davidson Date: Mon, 29 Aug 2022 00:43:35 -0700 Subject: [PATCH 10/14] Add more queue helpers --- core/container/queue/queue.odin | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/container/queue/queue.odin b/core/container/queue/queue.odin index ae1ca9f62..a42d0e5a4 100644 --- a/core/container/queue/queue.odin +++ b/core/container/queue/queue.odin @@ -73,11 +73,18 @@ get :: proc(q: ^$Q/Queue($T), #any_int i: int, loc := #caller_location) -> T { front :: proc(q: ^$Q/Queue($T)) -> T { return q.data[q.offset] } +front_ptr :: proc(q: ^$Q/Queue($T)) -> ^T { + return &q.data[q.offset] +} back :: proc(q: ^$Q/Queue($T)) -> T { idx := (q.offset+uint(q.len))%builtin.len(q.data) return q.data[idx] } +back_ptr :: proc(q: ^$Q/Queue($T)) -> ^T { + idx := (q.offset+uint(q.len))%builtin.len(q.data) + return &q.data[idx] +} set :: proc(q: ^$Q/Queue($T), #any_int i: int, val: T, loc := #caller_location) { runtime.bounds_check_error_loc(loc, i, builtin.len(q.data)) From 83c002c197301bffdd2140966e98c89c4529b1b6 Mon Sep 17 00:00:00 2001 From: Colin Davidson Date: Mon, 29 Aug 2022 01:53:40 -0700 Subject: [PATCH 11/14] add peeks --- core/container/queue/queue.odin | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/container/queue/queue.odin b/core/container/queue/queue.odin index a42d0e5a4..9674b40be 100644 --- a/core/container/queue/queue.odin +++ b/core/container/queue/queue.odin @@ -99,6 +99,16 @@ get_ptr :: proc(q: ^$Q/Queue($T), #any_int i: int, loc := #caller_location) -> ^ return &q.data[idx] } +peek_front :: proc(q: ^$Q/Queue($T)) -> ^T { + idx := q.offset%builtin.len(q.data) + return &q.data[idx] +} + +peek_back :: proc(q: ^$Q/Queue($T)) -> ^T { + idx := (uint(q.len - 1)+q.offset)%builtin.len(q.data) + return &q.data[idx] +} + // Push an element to the back of the queue push_back :: proc(q: ^$Q/Queue($T), elem: T) -> bool { if space(q^) == 0 { From 7a6fc3a93bf1be42de21a1af7af6e9e435438832 Mon Sep 17 00:00:00 2001 From: Colin Davidson Date: Mon, 29 Aug 2022 02:03:12 -0700 Subject: [PATCH 12/14] Add bounds check for peeks --- core/container/queue/queue.odin | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/container/queue/queue.odin b/core/container/queue/queue.odin index 9674b40be..b3a8ad43f 100644 --- a/core/container/queue/queue.odin +++ b/core/container/queue/queue.odin @@ -99,12 +99,14 @@ get_ptr :: proc(q: ^$Q/Queue($T), #any_int i: int, loc := #caller_location) -> ^ return &q.data[idx] } -peek_front :: proc(q: ^$Q/Queue($T)) -> ^T { +peek_front :: proc(q: ^$Q/Queue($T), loc := #caller_location) -> ^T { + runtime.bounds_check_error_loc(loc, 0, builtin.len(q.data)) idx := q.offset%builtin.len(q.data) return &q.data[idx] } -peek_back :: proc(q: ^$Q/Queue($T)) -> ^T { +peek_back :: proc(q: ^$Q/Queue($T), loc := #caller_location) -> ^T { + runtime.bounds_check_error_loc(loc, int(q.len - 1), builtin.len(q.data)) idx := (uint(q.len - 1)+q.offset)%builtin.len(q.data) return &q.data[idx] } From 25102d4792501b070f05cab5a6f774a717754a79 Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Mon, 29 Aug 2022 14:47:00 +0200 Subject: [PATCH 13/14] Fix #1985 --- src/llvm_backend.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index 6ee1541d6..29dc13dad 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -1017,8 +1017,11 @@ String lb_filepath_obj_for_module(lbModule *m) { } String ext = {}; - - if (build_context.build_mode == BuildMode_Assembly) { + if (build_context.out_filepath.len > 0) { + if (build_context.build_paths[BuildPath_Output].ext.len > 0) { + ext = concatenate_strings(permanent_allocator(), STR_LIT("."), build_context.build_paths[BuildPath_Output].ext); + } + } else if (build_context.build_mode == BuildMode_Assembly) { ext = STR_LIT(".S"); } else { if (is_arch_wasm()) { @@ -1050,7 +1053,6 @@ String lb_filepath_obj_for_module(lbModule *m) { } } } - return concatenate_strings(permanent_allocator(), path, ext); } From 317db2758ab30370fdebf47486d560fe17d5ddc4 Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Mon, 29 Aug 2022 14:50:18 +0200 Subject: [PATCH 14/14] Revert "Fix #1985" This reverts commit 25102d4792501b070f05cab5a6f774a717754a79. --- src/llvm_backend.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index 29dc13dad..6ee1541d6 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -1017,11 +1017,8 @@ String lb_filepath_obj_for_module(lbModule *m) { } String ext = {}; - if (build_context.out_filepath.len > 0) { - if (build_context.build_paths[BuildPath_Output].ext.len > 0) { - ext = concatenate_strings(permanent_allocator(), STR_LIT("."), build_context.build_paths[BuildPath_Output].ext); - } - } else if (build_context.build_mode == BuildMode_Assembly) { + + if (build_context.build_mode == BuildMode_Assembly) { ext = STR_LIT(".S"); } else { if (is_arch_wasm()) { @@ -1053,6 +1050,7 @@ String lb_filepath_obj_for_module(lbModule *m) { } } } + return concatenate_strings(permanent_allocator(), path, ext); }