I almost have a parse for reading a PCX file working, but right now when it applies the texture it is just a jumbled mess of pixels of seemingly random colors. As far as I know it is reading the bytes of the image properly, as I am able to get accurate data on the max x and y for the image. It’s just so far every method I have tried to accurate create the image has been frustrated. The pcx is 8 bits per pixel, with a plane count of 1 and a 256 color with palette. My understanding from what I read is each byte after 127 is an R, G and then B color code for the image. My other thought was maybe each byte itself is a single full color code, since it never goes higher than 255 and this is a 256 color palette. If so, is there a way to convert a single byte value to a full RGB color? I have tried doing some << offsetting but so far no luck.
I am not necessarily asking for the the full answer, but rather some direction on where to take this, especially if I am not thinking about it the correct way.
Here is my code at present.
string pcxPath = Application.dataPath + "texture.pcx";
byte[] reader = File.ReadAllBytes(pcxPath);
bitsInFrame = reader[3];
minX = reader[4];
minY = reader[6];
maxX = reader[8];
maxY = reader[10];
horzDPI = reader[12];
vertDPI = reader[14];
numColorPlanes = reader[65];
horzSourceScreen = reader[70];
vertSourceScreen = reader[72];
startingPoint = 128;
Color[] colorArray = new Color[reader.Length / 3];
Texture2D imgTexture = new Texture2D(maxX / 3, maxY / 3);
string byteString = "";
for (int i = startingPoint; i < reader.Length - 2; i += 3)
{
byteString += reader *+ " ";*
Color newColor = new Color(reader / 255f, reader[i + 1] / 255f, reader[i +2] / 255f);
colorArray[(i - startingPoint) / 3] = newColor;
}
imgTexture.SetPixels(colorArray);
Debug.Log(byteString);
imgTexture.Apply();
mat.materials[0].mainTexture = imgTexture;