Пример #1
0
        private void Read(BinaryReaderEx input, bool isPac = false)
        {
            var magic = input.ReadUInt16();
            var type  = MagicNumberToType(magic);

            if (type == PAAType.UNDEFINED)
            {
                type            = (!isPac) ? PAAType.RGBA_4444 : PAAType.P8;
                input.Position -= 2;
            }
            Type = type;

            Palette = new Palette(type);
            Palette.Read(input, mipmapOffsets);

            mipmaps = new List <Mipmap>(16);
            int i = 0;

            while (input.ReadUInt32() != 0)
            {
                input.Position -= 4;

                Debug.Assert(input.Position == mipmapOffsets[i]);
                var mipmap = new Mipmap(input, mipmapOffsets[i++]);
                mipmaps.Add(mipmap);
            }
            if (input.ReadUInt16() != 0)
            {
                throw new FormatException("Expected two more zero's at end of file.");
            }
        }
Пример #2
0
        public static byte[] GetARGB32PixelData(PAA paa, Stream paaStream, Mipmap mipmap)
        {
            var input   = new BinaryReaderEx(paaStream);
            var rawData = mipmap.GetRawPixelData(input, paa.Type);

            byte[] argbPixels;
            switch (paa.Type)
            {
            case PAAType.RGBA_8888:
            case PAAType.P8:
                return(PixelFormatConversion.P8ToARGB32(rawData, paa.Palette));    //never uses swizzling

            case PAAType.DXT1:
            case PAAType.DXT2:
            case PAAType.DXT3:
            case PAAType.DXT4:
            case PAAType.DXT5:
                argbPixels = PixelFormatConversion.DXTToARGB32(rawData, mipmap.Width, mipmap.Height, (int)paa.Type); break;

            case PAAType.RGBA_4444:
                argbPixels = PixelFormatConversion.ARGB16ToARGB32(rawData); break;

            case PAAType.RGBA_5551:
                argbPixels = PixelFormatConversion.ARGB1555ToARGB32(rawData); break;

            case PAAType.AI88:
                argbPixels = PixelFormatConversion.AI88ToARGB32(rawData); break;

            default:
                throw new Exception($"Cannot retrieve pixel data from this PaaType: {paa.Type}");
            }

            ChannelSwizzling.Apply(argbPixels, paa.Palette.ChannelSwizzle);
            return(argbPixels);
        }
Пример #3
0
        public static byte[] GetARGB32PixelData(PAA paa, Stream paaStream, int mipmapIndex = 0)
        {
            var input = new BinaryReaderEx(paaStream);

            Mipmap mipmap  = paa[mipmapIndex];
            var    rawData = mipmap.GetRawPixelData(input, paa.Type);

            switch (paa.Type)
            {
            case PAAType.RGBA_8888:
            case PAAType.P8:
                return(PixelFormatConversion.P8ToARGB32(rawData, paa.Palette));

            case PAAType.DXT1:
            case PAAType.DXT2:
            case PAAType.DXT3:
            case PAAType.DXT4:
            case PAAType.DXT5:
                return(PixelFormatConversion.DXTToARGB32(rawData, mipmap.Width, mipmap.Height, (int)paa.Type));

            case PAAType.RGBA_4444:
                return(PixelFormatConversion.ARGB16ToARGB32(rawData));

            case PAAType.RGBA_5551:
                return(PixelFormatConversion.ARGB1555ToARGB32(rawData));

            case PAAType.AI88:
                return(PixelFormatConversion.AI88ToARGB32(rawData));

            default:
                throw new Exception($"Cannot retrieve pixel data from this PaaType: {paa.Type}");
            }
        }
Пример #4
0
        public static byte[] GetARGB32PixelData(PAA paa, Stream paaStream, int mipmapIndex = 0)
        {
            Mipmap mipmap = paa[mipmapIndex];

            return(GetARGB32PixelData(paa, paaStream, mipmap));
        }