godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.79k stars 20.13k forks source link

C# - GetData() cannot be natively converted to float[] #95325

Open sixstepsaway opened 1 month ago

sixstepsaway commented 1 month ago

Tested versions

System information

Windows 10, Forward+

Issue description

In GDScript, you can call

image.get_data().to_float32_array()

which gets the data from the image and returns it as a float array.

In C# there's no native way of converting, so the only way I can do this is I have to have a GDScript on a node and call that, but I can't do that off the main thread, so I can't background thread it.

Any chance of a conversion like GDScript has, somehow?

Steps to reproduce

Get an image. Run image.GetData(). Observe the lack of conversion :(

Minimal reproduction project (MRP)

Same as above: Get an image. Run image.GetData(). Observe the lack of conversion :(

AThousandShips commented 1 month ago

This would be something on the C# library side, have you checked if there is a C# equivalent in the standard library there? The equivalent data is just a standard System.Array, try, for example System.BitConverter

sixstepsaway commented 1 month ago

There isn't. It returns byte, you can't choose to have it as a float instead, and converting byte to float in C# is... complex.

On Fri, 9 Aug 2024, 11:52 A Thousand Ships, @.***> wrote:

This would be something on the C# library side, have you checked if there is a C# equivalent in the standard library there? The equivalent data is just a standard System.Array

— Reply to this email directly, view it on GitHub https://github.com/godotengine/godot/issues/95325#issuecomment-2277681014, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOWS7TKBSO3LYIWDXZ5EZDDZQSNNTAVCNFSM6AAAAABMIHI4NGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENZXGY4DCMBRGQ . You are receiving this because you authored the thread.Message ID: @.***>

AThousandShips commented 1 month ago

I mean to convert byte[] to float[], there's no method on Image to get a float[], in GDScript or C#, the difference is that PackedByteArray is a raw array in C#, so the conversion is something that's the responsibility of the C# side, specifically the library

sixstepsaway commented 1 month ago

All right, thank you.

On Fri, 9 Aug 2024 at 11:58, A Thousand Ships @.***> wrote:

I mean to convert byte[] to float[], there's no method on Image to get a float[], in GDScript or C#, the difference is that PackedByteArray is a raw array in C#, so the conversion is something that's the responsibility of the C# side, specifically the library

— Reply to this email directly, view it on GitHub https://github.com/godotengine/godot/issues/95325#issuecomment-2277691652, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOWS7TJHXWIWWV2MZCSN5WLZQSOFZAVCNFSM6AAAAABMIHI4NGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENZXGY4TCNRVGI . You are receiving this because you authored the thread.Message ID: @.***>