Fix exportImageToMemory (#232)

* fix exportImageToMemory

* update make_return_cast
This commit is contained in:
Tommy D. Rossi 2025-03-30 18:00:07 +02:00 committed by GitHub
parent e072ff119b
commit a00552ea79
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 1 deletions

View File

@ -122,6 +122,8 @@ def add_namespace_to_type(t: str) -> str:
def make_return_cast(source_type: str, dest_type: str, inner: str) -> str: def make_return_cast(source_type: str, dest_type: str, inner: str) -> str:
if source_type == dest_type: if source_type == dest_type:
return inner return inner
if "ExportImageToMemory" in inner:
return f"{inner}[0..@as(usize, @intCast(fileSize.*))]"
if source_type in ["[*c]const u8", "[*c]u8"]: if source_type in ["[*c]const u8", "[*c]u8"]:
return f"std.mem.span({inner})" return f"std.mem.span({inner})"

View File

@ -3838,7 +3838,7 @@ pub fn exportImage(image: Image, fileName: [:0]const u8) bool {
/// Export image to memory buffer /// Export image to memory buffer
pub fn exportImageToMemory(image: Image, fileType: [:0]const u8, fileSize: *i32) [:0]u8 { pub fn exportImageToMemory(image: Image, fileType: [:0]const u8, fileSize: *i32) [:0]u8 {
return std.mem.span(cdef.ExportImageToMemory(image, @as([*c]const u8, @ptrCast(fileType)), @as([*c]c_int, @ptrCast(fileSize)))); return cdef.ExportImageToMemory(image, @as([*c]const u8, @ptrCast(fileType)), @as([*c]c_int, @ptrCast(fileSize)))[0..@as(usize, @intCast(fileSize.*))];
} }
/// Export image as code file defining an array of bytes, returns true on success /// Export image as code file defining an array of bytes, returns true on success