Пример #1
0
        public override byte[] ToRaw()
        {
            if (SaveTextureType != PsuTextureType.Raster)
            {
                throw new InvalidOperationException("Can't save DXT textures yet");
            }
            int width  = mips[0].Width;
            int height = mips[0].Height;

            XvrImageParameters parameters = new XvrImageParameters(width, height, SaveTextureType, mips.Length > 1, SavePixelFormat);

            //Let's try just leaving the file start blank? I don't think this actually works...
            byte[] imageData = XvrRasterEncoders.GetEncoder(parameters).EncodeImage(mips, parameters);

            MemoryStream headerStream = new MemoryStream();
            BinaryWriter headerWriter = new BinaryWriter(headerStream);

            headerWriter.Write(Encoding.ASCII.GetBytes(superFormat));
            headerWriter.Write(globalIndex);
            headerWriter.Write(unknown1);
            headerWriter.Write((int)0);
            headerWriter.Write(Encoding.ASCII.GetBytes(subFormat));
            headerWriter.Write((int)imageData.Length + 8);
            headerWriter.Write(parameters.pixelFormat);
            headerWriter.Write(parameters.pixelFlags);
            headerWriter.Write((short)0);
            headerWriter.Write((short)width);
            headerWriter.Write((short)height);
            header = headerStream.ToArray();

            MemoryStream outStream = new MemoryStream();
            BinaryWriter outWriter = new BinaryWriter(outStream);

            outWriter.Write((short)1);
            outWriter.Write((short)0x84);
            outWriter.Write((int)0);
            outWriter.Write((int)0);
            outWriter.Write((short)0x2A); //I don't know what this is!
            short dimensionsMips = 0;

            dimensionsMips |= (short)mips.Length;
            byte widthPower  = logTwo(width);    //Make sure make sure MAKE SURE dimensions are a power of 2!
            byte heightPower = logTwo(height);

            dimensionsMips |= (short)(widthPower << 8);
            dimensionsMips |= (short)(heightPower << 4);
            outWriter.Write(dimensionsMips);
            outWriter.Write((int)0);
            outWriter.Write(1);
            outWriter.Write((int)0);
            outWriter.Write((int)imageData.Length);
            outWriter.Write(imageData);
            return(outStream.ToArray());
        }
Пример #2
0
 public Bitmap getPreviewMip(int mipIndex)
 {
     //this is a hack because DXT textures get converted to argb32 in case of rounding issues
     //it should probably be handled differently?
     if (!(mipDirty[mipIndex] && (mips[mipIndex].PixelFormat == SavePixelFormat.ToPixelFormat() && mips[mipIndex].Width == mips[0].Width >> mipIndex && mips[mipIndex].Height == mips[0].Height >> mipIndex)) && SavePixelFormat == OriginalPixelFormat)
     {
         return(mips[mipIndex]);
     }
     else
     {
         return(XvrRasterEncoders.GetEncoder(SaveTextureType, SavePixelFormat).getTranscodedMip(mips[mipIndex], mips[0].Width >> mipIndex, mips[0].Height >> mipIndex));
     }
 }