Dark Bit Factory & Gravity
PROGRAMMING => C / C++ /C# => Topic started by: va!n on February 26, 2011
-
I think its must be possible, but i am not really sure how to use/write it in C#. What i need is an array where i can read/write RGBA values and just direct access to RED, GREEN, BLUE, ALPHA.
// Init
public struct ARGB // RGBA or ARGB ^^
{
public byte A;
public byte R;
public byte G;
public byte B;
}
public uint[] arTexture;
// Methode
public void TestStructArray()
{
arTexture = new uint[64 * 64];
}
Later something like following should be possible:
// Set (byte) value for any color channel
arTexture[ position ].A = 255
arTexture[ position ].R = 255
arTexture[ position ].G = 255
arTexture[ position ].B = 255
// Set (uint) value for ARGB pixel value
arTexture[ position ].ARGB = 0xFF224466
// Get (byte) value of any color channel
valueA = arTexture[ position ].A
valueR = arTexture[ position ].R
valueG = arTexture[ position ].G
valueB = arTexture[ position ].B
ValueARGB = arTexture[ position ].RGBA
Any idea how this can be done (array with struct)? And yes, i know this can be done by using C#'s COLOR... But i want to use my own for some reasons ;)
[Edited - Added:]
Atm i am using an uint[] where i read/write the full pixelcolor as ARGB and using SHL/SHR operators to get/set the value of the wanted color channel! This works but i want to have a cleaner code and being more flexible.
-
This technique can't work in C#. You are not allowed to know how a struct is represented, and you can't overlay two data structures upon each other. You can get the semantics you want, like Color, but then you can never turn that into an array efficiently.
Your best bet is to work directly with your array of uints. And it will be interesting to see how efficient it is to get them on a bitmapped display. I've tried pixel stuff in C# and have some tips, but my results were 15fps-ish for 640x480.
Jim
-
Hmmm... so its not possible in C#? I have to think about... Using uint for my array and shifting around to set/get a channel color works well..
Yes drawing in C# using GDI/GDI+ is really slow. However i tried from the first second to do all stuff in a big array and bringing the result very fast to a bitmap/on screen! I found a way to draw the array result very fast - a lot faster as C# drawings! From performance issue i have no problem yet. Just only thought how to have cleaner code and....
thanks for your info...
[Edited - Added:]
In one of my very firsts tests i tried to draw and generate 5 different simple textures (each 256x256)... Needed time: ~ 20 ms (i think this is great)