converting a byte array to a struct array?
Steven Schveighoffer
schveiguy at yahoo.com
Tue Dec 29 06:08:53 PST 2009
On Tue, 29 Dec 2009 07:56:04 -0500, Trass3r <mrmocool at gmx.de> wrote:
> I got some RGB palette in a byte array which I'd like to convert or
> "map" to an RGB struct array, isn't this easily possible without using
> dozens of struct constructors?
>
>
> RGB[256] PALETTE = cast(RGB[256]) [
> 0x00, 0x00, 0x00, 0xE3, 0x53, 0x00,
> 0xCF, 0x4B, 0x07, 0xBF, 0x43, 0x0F, ...
>
> doesn't work cause of "non-constant expression"
>
> RGB[256] PALETTE = (cast(RGB[]) [
> 0x00, 0x00, 0x00, 0xE3, 0x53, 0x00,
> 0xCF, 0x4B, 0x07, 0xBF, 0x43, 0x0F, ...
> ]) (0 .. 256);
>
> compiles, but yields empty structs (and doesn't seem right anyway).
What is RGB's structure?
I would expect something like this to work:
RGB[256] PALETTE = [
{0x00, 0x00, 0x00},
{0xE3, 0x53, 0x00},
...
];
Assuming RGB is a struct of 3 ubyte members...
-Steve
More information about the Digitalmars-d-learn
mailing list