This is pretty much all elaborating on what konju said before.
can it take in a array of colors instead of a texture for the palette?
I have never tried to directly pass a array to a shader. Regardless you can use multi-texturing remember a texture 2d is basically just a 2d array.
Indexing mathematically a color palette in a 1D array to a Texture2d or vice versa is very simple you basically use the following indexing formulas such that it doesn’t matter if its in a array [ ] or a texture 2d [ , ].
You can use this same method later to instead encode a color index into a u,v look up in the palette
// 1D index to 2D index
// were i is a index to a array in a for loop
y = i / img.Width;
x = i - (int)(y) * img.Width;
// 2D index to 1D index
i = y * img.Width + x;
can textures be encode and decoded as binary data?
Yes of course its all in binary however they are stored as vector4 normalized floats in a texture.
This means you convert values of a color element back and forth like so.
int myblue = 24;
float normalizedblue = myblue / 255;
int blue = normalizedblue * 255;
// a color in the cpu
new Color( , , blue, );
// what the gpu reads off of a texture in a shader
float4 c = Tex2d(coordinateA, pos2d);
// c’s blue element is basically the normalized value.
new Float4 ( , , normalizedBlue, );
however you cant directly do bitwise math on it as its in float8 format not base2 binary notation instead you have to multiply and divide ect.
how would the shader method be achieved specifically for this case?
load your palette colors to a texture2d with set data use a 255,x 255 texture.
(that is 0 to 65,025 colors)
This will be Texture A on the shader.
load your Image data to a array this will probably the hardest part.
I don’t think monogame supports directly loading palette indexed images loading them into a array will be on you. (if your just generating them you have the array already)
Create a texture with the proper Width x Height, same size as the image, well call this texture B.
Transform the arrays index’s values into the r b elements of a color array of the same size this is for the texture.
Previously discussed we do it to encode this time not to index
1D index to 2D index as color positions r,b instead
// 1D encode to 2 color elements r,b in this case
r = i / 255;
b = i - ( (int)( i ) * 255;
Place these found values into a color array.
use set data to send the color array to a texture2d call it B.
Send both textures A and B to the shader.
In the pixel shader.
Get the color at the current texture coordinates of B
Take the colors r and b values and then…
Use those r b values as x y coordinates for getting a color in texture A.
return that color.
the shader will have all the info it needs so nothing will need to be decoded or indexed on its side.