コード例 #1
0
ファイル: PaletteArchive.cs プロジェクト: layshua/Alexandria
 internal PaletteArchive(AssetLoader loader)
     : base(loader)
 {
     for (int index = 0; index < 8; index++)
     {
         PaletteAsset asset = PaletteAsset.ReadRgb(Manager, "Palette " + index, loader.Reader, 256, 63);
         AddChild(asset);
     }
 }
コード例 #2
0
        /// <summary>Load the PCX image file.</summary>
        /// <param name="loader"></param>
        /// <returns></returns>
        public override Asset Load(AssetLoader loader)
        {
            BinaryReader reader = loader.Reader;
            PcxHeader    header = new PcxHeader(reader);

            int pitch = (header.BitsPerPixel * header.ColorPlaneCount + 7) / 8 * header.SizeX;

            int[] data = new int[pitch * header.SizeY + 1];

            for (int row = 0; row < header.SizeY; row++)
            {
                switch (header.Compression)
                {
                case PcxCompression.None:
                    for (int index = 0; index < pitch; index++)
                    {
                        data[pitch * row + index] = reader.ReadByte();
                    }
                    break;

                case PcxCompression.RLE:
                    for (int offset = pitch * row, end = offset + header.BytesPerScanLine; offset < end;)
                    {
                        byte value = reader.ReadByte();

                        if (value < 0xC0)
                        {
                            data[offset++] = value;
                        }
                        else
                        {
                            int  runEnd = offset + value - 0xC0;
                            byte code   = reader.ReadByte();

                            while (offset < runEnd)
                            {
                                data[offset++] = code;
                            }
                        }
                    }
                    break;

                default:
                    throw new NotImplementedException();
                }
            }

            PaletteAsset palette = null;

            if (header.ColorPlaneCount == 1)
            {
                if (reader.BaseStream.ReadByte() == PaletteMagic)
                {
                    palette = PaletteAsset.ReadRgb(Manager, loader.Name + " Palette", reader, 1 << header.BitsPerPixel, 255);
                }
            }

            if (palette != null)
            {
                return(new IndexedTextureAsset(loader, palette, header.SizeX, header.SizeY, data, pitch));
            }
            else
            {
                throw new NotImplementedException();
            }
        }