本文整理汇总了C#中Palette.GetBytes方法的典型用法代码示例。如果您正苦于以下问题:C# Palette.GetBytes方法的具体用法?C# Palette.GetBytes怎么用?C# Palette.GetBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Palette
的用法示例。
在下文中一共展示了Palette.GetBytes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DecodeC8
private static byte[] DecodeC8(EndianBinaryReader stream, uint width, uint height, Palette imagePalette, PaletteFormats paletteFormat)
{
//4 bpp, 8 block width/4 block height, block size 32 bytes, possible palettes (IA8, RGB565, RGB5A3)
uint numBlocksW = width / 8;
uint numBlocksH = height / 4;
byte[] decodedData = new byte[width * height * 8];
//Read the indexes from the file
for (int yBlock = 0; yBlock < numBlocksH; yBlock++)
{
for (int xBlock = 0; xBlock < numBlocksW; xBlock++)
{
//Inner Loop for pixels
for (int pY = 0; pY < 4; pY++)
{
for (int pX = 0; pX < 8; pX++)
{
//Ensure we're not reading past the end of the image.
if ((xBlock * 8 + pX >= width) || (yBlock * 4 + pY >= height))
continue;
byte data = stream.ReadByte();
decodedData[width * ((yBlock * 4) + pY) + (xBlock * 8) + pX] = data;
}
}
}
}
//Now look them up in the palette and turn them into actual colors.
byte[] finalDest = new byte[decodedData.Length / 2];
int pixelSize = paletteFormat == PaletteFormats.IA8 ? 2 : 4;
int destOffset = 0;
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
UnpackPixelFromPalette(decodedData[y * width + x], ref finalDest, destOffset, imagePalette.GetBytes(), paletteFormat);
destOffset += pixelSize;
}
}
return finalDest;
}
示例2: DecodeC4
private static byte[] DecodeC4(byte[] fileData, uint dataOffset, uint width, uint height, Palette imagePalette, PaletteFormat paletteFormat)
{
//4 bpp, 8 block width/height, block size 32 bytes, possible palettes (IA8, RGB565, RGB5A3)
uint numBlocksW = width / 8;
uint numBlocksH = height / 8;
byte[] decodedData = new byte[width * height * 8];
//Read the indexes from the file
for (int yBlock = 0; yBlock < numBlocksH; yBlock++)
{
for (int xBlock = 0; xBlock < numBlocksW; xBlock++)
{
//Inner Loop for pixels
for (int pY = 0; pY < 8; pY++)
{
for (int pX = 0; pX < 8; pX += 2)
{
//Ensure we're not reading past the end of the image.
if ((xBlock * 8 + pX >= width) || (yBlock * 8 + pY >= height))
continue;
byte t = (byte)(fileData[dataOffset] & 0xF0);
byte t2 = (byte)(fileData[dataOffset] & 0x0F);
decodedData[width * ((yBlock * 8) + pY) + (xBlock * 8) + pX + 0] = (byte)(t >> 4);
decodedData[width * ((yBlock * 8) + pY) + (xBlock * 8) + pX + 1] = t2;
dataOffset += 1;
}
}
}
}
//Now look them up in the palette and turn them into actual colors.
byte[] finalDest = new byte[decodedData.Length / 2];
int pixelSize = paletteFormat == PaletteFormat.IA8 ? 2 : 4;
int destOffset = 0;
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
UnpackPixelFromPalette(decodedData[y * width + x], ref finalDest, destOffset, imagePalette.GetBytes(), paletteFormat);
destOffset += pixelSize;
}
}
return finalDest;
}