Exemplo n.º 1
0
        private static byte[] DecodeDetex(byte[] data, int width, int height, TextureFormat format)
        {
            byte[] dest;

            if (format == TextureFormat.DXT1)
            {
                dest = DXTDecoders.ReadDXT1(data, width, height);
            }
            else if (format == TextureFormat.DXT5)
            {
                dest = DXTDecoders.ReadDXT5(data, width, height);
            }
            else //if (format == TextureFormat.BC7)
            {
                dest = BC7Decoder.ReadBC7(data, width, height);
            }

            for (int i = 0; i < dest.Length; i += 4)
            {
                byte temp = dest[i];
                dest[i]     = dest[i + 2];
                dest[i + 2] = temp;
            }
            return(dest);
        }
Exemplo n.º 2
0
        public static byte[] GetTextureDataFromBytes(byte[] data, TextureFormat texFmt, int width, int height)
        {
            switch (texFmt)
            {
            case TextureFormat.R8:
                return(RGBADecoders.ReadR8(data, width, height));

            case TextureFormat.R16:
                return(RGBADecoders.ReadR16(data, width, height));

            case TextureFormat.RG16:
                return(RGBADecoders.ReadRG16(data, width, height));

            case TextureFormat.RGB24:
                return(RGBADecoders.ReadRGB24(data, width, height));

            case TextureFormat.RGBA32:
                return(RGBADecoders.ReadRGBA32(data, width, height));

            case TextureFormat.ARGB32:
                return(RGBADecoders.ReadARGB32(data, width, height));

            case TextureFormat.RGBA4444:
                return(RGBADecoders.ReadRGBA4444(data, width, height));

            case TextureFormat.ARGB4444:
                return(RGBADecoders.ReadARGB4444(data, width, height));

            case TextureFormat.Alpha8:
                return(RGBADecoders.ReadAlpha8(data, width, height));

            case TextureFormat.DXT1:
                return(DXTDecoders.ReadDXT1(data, width, height));

            case TextureFormat.DXT5:
                return(DXTDecoders.ReadDXT5(data, width, height));

            case TextureFormat.BC7:
                return(BC7Decoder.ReadBC7(data, width, height));

            case TextureFormat.ETC_RGB4:
                return(ETCDecoders.ReadETC(data, width, height));

            case TextureFormat.ETC2_RGB4:
                return(ETCDecoders.ReadETC(data, width, height, true));

            default:
                return(null);
            }
        }
Exemplo n.º 3
0
 public static byte[] Decode(byte[] data, TextureFormat format, int width, int height)
 {
     return(format switch
     {
         TextureFormat.R8 => RGBADecoders.ReadR8(data, width, height),
         TextureFormat.R16 => RGBADecoders.ReadR16(data, width, height),
         TextureFormat.RG16 => RGBADecoders.ReadRG16(data, width, height),
         TextureFormat.RGB24 => RGBADecoders.ReadRGB24(data, width, height),
         TextureFormat.RGB565 => RGBADecoders.ReadRGB565(data, width, height),
         TextureFormat.RGBA32 => RGBADecoders.ReadRGBA32(data, width, height),
         TextureFormat.ARGB32 => RGBADecoders.ReadARGB32(data, width, height),
         TextureFormat.RGBA4444 => RGBADecoders.ReadRGBA4444(data, width, height),
         TextureFormat.ARGB4444 => RGBADecoders.ReadARGB4444(data, width, height),
         TextureFormat.Alpha8 => RGBADecoders.ReadAlpha8(data, width, height),
         TextureFormat.RHalf => RGBADecoders.ReadRHalf(data, width, height),
         TextureFormat.RGHalf => RGBADecoders.ReadRGHalf(data, width, height),
         TextureFormat.RGBAHalf => RGBADecoders.ReadRGBAHalf(data, width, height),
         TextureFormat.DXT1 => DXTDecoders.ReadDXT1(data, width, height),
         TextureFormat.DXT5 => DXTDecoders.ReadDXT5(data, width, height),
         TextureFormat.BC7 => BC7Decoder.ReadBC7(data, width, height),
         TextureFormat.ETC_RGB4 => ETCDecoders.ReadETC(data, width, height),
         TextureFormat.ETC2_RGB4 => ETCDecoders.ReadETC(data, width, height, true),
         _ => null
     });
Exemplo n.º 4
0
        public static byte[] DecodeTexture(byte[] data, int width, int height, TextureFormat format)
        {
            switch (format)
            {
            case TextureFormat.RGB9e5Float:     //pls don't use (what is this?)
            case TextureFormat.DXT1Crunched:
            case TextureFormat.DXT5Crunched:
            case TextureFormat.ETC_RGB4Crunched:
            case TextureFormat.ETC2_RGBA8Crunched:
                return(null);    // todo

            case TextureFormat.ARGB32:
            case TextureFormat.BGRA32New:
            case TextureFormat.RGBA32:
            case TextureFormat.RGB24:
            case TextureFormat.ARGB4444:
            case TextureFormat.RGBA4444:
            case TextureFormat.RGB565:
            case TextureFormat.Alpha8:
            case TextureFormat.R8:
            case TextureFormat.R16:
            case TextureFormat.RG16:
            case TextureFormat.RHalf:
            case TextureFormat.RGHalf:
            case TextureFormat.RGBAHalf:
            case TextureFormat.RFloat:
            case TextureFormat.RGFloat:
            case TextureFormat.RGBAFloat:
            case TextureFormat.YUV2:
            case TextureFormat.EAC_R:
            case TextureFormat.EAC_R_SIGNED:
            case TextureFormat.EAC_RG:
            case TextureFormat.EAC_RG_SIGNED:
            case TextureFormat.ETC_RGB4:
            case TextureFormat.ETC_RGB4_3DS:
            case TextureFormat.ETC_RGBA8_3DS:
            case TextureFormat.ETC2_RGB4:
            case TextureFormat.ETC2_RGBA1:
            case TextureFormat.ETC2_RGBA8:
            case TextureFormat.PVRTC_RGB2:
            case TextureFormat.PVRTC_RGBA2:
            case TextureFormat.PVRTC_RGB4:
            case TextureFormat.PVRTC_RGBA4:
            case TextureFormat.ASTC_RGB_4x4:
            case TextureFormat.ASTC_RGB_5x5:
            case TextureFormat.ASTC_RGB_6x6:
            case TextureFormat.ASTC_RGB_8x8:
            case TextureFormat.ASTC_RGB_10x10:
            case TextureFormat.ASTC_RGB_12x12:
            case TextureFormat.ASTC_RGBA_4x4:
            case TextureFormat.ASTC_RGBA_5x5:
            case TextureFormat.ASTC_RGBA_8x8:
            case TextureFormat.ASTC_RGBA_10x10:
            case TextureFormat.ASTC_RGBA_12x12:
            {
                var dest = TextureWrapper.DecodeByPVRTexLib(data, (int)format, width, height);
                return(dest);
            }

            case TextureFormat.DXT1:
                var dxt1 = DXTDecoders.ReadDXT1(data, width, height);
                for (var i = 0; i < dxt1.Length; i += 4)
                {
                    var temp = dxt1[i];
                    dxt1[i]     = dxt1[i + 2];
                    dxt1[i + 2] = temp;
                }
                return(dxt1);

            case TextureFormat.DXT5:
                var dxt5 = DXTDecoders.ReadDXT5(data, width, height);
                for (var i = 0; i < dxt5.Length; i += 4)
                {
                    var temp = dxt5[i];
                    dxt5[i]     = dxt5[i + 2];
                    dxt5[i + 2] = temp;
                }
                return(dxt5);

            case TextureFormat.BC7:
                var bc7 = BC7Decoder.ReadBC7(data, width, height);
                for (var i = 0; i < bc7.Length; i += 4)
                {
                    var temp = bc7[i];
                    bc7[i]     = bc7[i + 2];
                    bc7[i + 2] = temp;
                }
                return(bc7);

            case TextureFormat.BC6H:
            case TextureFormat.BC4:
            case TextureFormat.BC5:
                return(null);    // todo

            default:
                return(null);
            }
        }
Exemplo n.º 5
0
        public static byte[] Decode(byte[] data, int width, int height, TextureFormat format)
        {
            switch (format)
            {
            case TextureFormat.RGB9e5Float:     //pls don't use (what is this?)
                return(null);

            //crunch-unity
            //case TextureFormat.DXT1Crunched:
            //case TextureFormat.DXT5Crunched:
            //case TextureFormat.ETC_RGB4Crunched:
            //case TextureFormat.ETC2_RGBA8Crunched:
            //{
            //    byte[] dest = new byte[data.Length]; //just to be safe, buf is same size as original
            //    uint size = 0;
            //    unsafe
            //    {
            //        fixed (byte* dataPtr = data)
            //        fixed (byte* destPtr = dest)
            //        {
            //            IntPtr dataIntPtr = (IntPtr)dataPtr;
            //            IntPtr destIntPtr = (IntPtr)destPtr;
            //            size = PInvoke.DecodeByCrunch(dataIntPtr, destIntPtr, (int)format, (uint)width, (uint)height);
            //        }
            //    }
            //    if (size > 0)
            //    {
            //        byte[] resizedDest = new byte[size];
            //        Buffer.BlockCopy(dest, 0, resizedDest, 0, (int)size);
            //        dest = null;
            //        return resizedDest;
            //    }
            //    else
            //    {
            //        dest = null;
            //        return null;
            //    }
            //}
            //pvrtexlib
            case TextureFormat.ARGB32:
            case TextureFormat.BGRA32New:
            case TextureFormat.RGBA32:
            case TextureFormat.RGB24:
            case TextureFormat.ARGB4444:
            case TextureFormat.RGBA4444:
            case TextureFormat.RGB565:
            case TextureFormat.Alpha8:
            case TextureFormat.R8:
            case TextureFormat.R16:
            case TextureFormat.RG16:
            case TextureFormat.RHalf:
            case TextureFormat.RGHalf:
            case TextureFormat.RGBAHalf:
            case TextureFormat.RFloat:
            case TextureFormat.RGFloat:
            case TextureFormat.RGBAFloat:
            /////////////////////////////////
            case TextureFormat.YUV2:
            case TextureFormat.EAC_R:
            case TextureFormat.EAC_R_SIGNED:
            case TextureFormat.EAC_RG:
            case TextureFormat.EAC_RG_SIGNED:
            case TextureFormat.ETC_RGB4_3DS:
            case TextureFormat.ETC_RGBA8_3DS:
            case TextureFormat.ETC2_RGB4:
            case TextureFormat.ETC2_RGBA1:
            case TextureFormat.ETC2_RGBA8:
            case TextureFormat.PVRTC_RGB2:
            case TextureFormat.PVRTC_RGBA2:
            case TextureFormat.PVRTC_RGB4:
            case TextureFormat.PVRTC_RGBA4:
            case TextureFormat.ASTC_RGB_4x4:
            case TextureFormat.ASTC_RGB_5x5:
            case TextureFormat.ASTC_RGB_6x6:
            case TextureFormat.ASTC_RGB_8x8:
            case TextureFormat.ASTC_RGB_10x10:
            case TextureFormat.ASTC_RGB_12x12:
            case TextureFormat.ASTC_RGBA_4x4:
            case TextureFormat.ASTC_RGBA_5x5:
            case TextureFormat.ASTC_RGBA_8x8:
            case TextureFormat.ASTC_RGBA_10x10:
            case TextureFormat.ASTC_RGBA_12x12:
            {
                byte[] dest = new byte[data.Length * 16];   //just to be safe, buf is 16 times size of original (obv this is prob too big)
                uint   size = 0;
                unsafe
                {
                    fixed(byte *dataPtr = data)
                    fixed(byte *destPtr = dest)
                    {
                        IntPtr dataIntPtr = (IntPtr)dataPtr;
                        IntPtr destIntPtr = (IntPtr)destPtr;

                        size = PInvoke.DecodeByPVRTexLib(dataIntPtr, destIntPtr, (int)format, (uint)width, (uint)height);
                    }
                }
                if (size > 0)
                {
                    byte[] resizedDest = new byte[size];
                    Buffer.BlockCopy(dest, 0, resizedDest, 0, (int)size);
                    dest = null;
                    return(resizedDest);
                }
                else
                {
                    dest = null;
                    return(null);
                }
            }

            //bcnencoder does not decode imagine that
            //detex
            case TextureFormat.DXT1:
                byte[] dxt1 = DXTDecoders.ReadDXT1(data, width, height);
                for (int i = 0; i < dxt1.Length; i += 4)
                {
                    byte temp = dxt1[i];
                    dxt1[i]     = dxt1[i + 2];
                    dxt1[i + 2] = temp;
                }
                return(dxt1);

            case TextureFormat.DXT5:
                byte[] dxt5 = DXTDecoders.ReadDXT5(data, width, height);
                for (int i = 0; i < dxt5.Length; i += 4)
                {
                    byte temp = dxt5[i];
                    dxt5[i]     = dxt5[i + 2];
                    dxt5[i + 2] = temp;
                }
                return(dxt5);

            case TextureFormat.BC7:
                byte[] bc7 = BC7Decoder.ReadBC7(data, width, height);
                for (int i = 0; i < bc7.Length; i += 4)
                {
                    byte temp = bc7[i];
                    bc7[i]     = bc7[i + 2];
                    bc7[i + 2] = temp;
                }
                return(bc7);

            case TextureFormat.BC6H:     //pls don't use
            case TextureFormat.BC4:
            case TextureFormat.BC5:
                return(null);

            default:
                return(null);
            }
        }