Пример #1
0
        private bool LoadTextureFormatDataFromBuffer()
        {
                        #if NATIVE_PLUGIN_LOAD
            textureData.width          = FastLoad_Texture_GetWidth();
            textureData.heght          = FastLoad_Texture_GetHeight();
            textureData.format         = FastLoad_Texture_GetFormat();
            textureData.flags          = FastLoad_Texture_GetFlags();
            textureData.compressedSize = 0;
            textureData.dataSize       = FastLoad_Texture_GetBodySize();
            textureData.rawData        = FastLoad_Texture_GetRawData();
                        #else
            if (!FastLoaderUtil.CheckHeader(this.bufferData, 0, FastLoaderUtil.FastTextureHeader))
            {
                return(false);
            }
            textureData.width          = FastLoaderUtil.GetIntFromByteArray(this.bufferData, 8);
            textureData.heght          = FastLoaderUtil.GetIntFromByteArray(this.bufferData, 12);
            textureData.format         = FastLoaderUtil.GetIntFromByteArray(this.bufferData, 16);
            textureData.flags          = FastLoaderUtil.GetIntFromByteArray(this.bufferData, 20);
            textureData.compressedSize = FastLoaderUtil.GetIntFromByteArray(this.bufferData, 24);
            textureData.dataSize       = FastLoaderUtil.GetIntFromByteArray(this.bufferData, 28);

            if (textureData.compress)
            {
                Lz4Util.Decode(this.bufferData, 32, textureData.compressedSize, this.uncompressedBuffer, 0, textureData.dataSize);
                textureData.rawData = Marshal.UnsafeAddrOfPinnedArrayElement(this.uncompressedBuffer, 0);
            }
            else
            {
                textureData.rawData = Marshal.UnsafeAddrOfPinnedArrayElement(this.bufferData, 32);
            }
                        #endif
            return(true);
        }
        private void WriteTextureToStream(Stream stream, Texture2D texture, bool isCompress, int blockSize)
        {
            byte[] rawData       = texture.GetRawTextureData();
            byte[] writeData     = null;
            int    writeDataSize = 0;

            if (isCompress)
            {
                writeData     = this.lz4Buffer;
                writeDataSize = Lz4Util.Encode(blockSize, rawData, 0, rawData.Length, writeData, 0, writeData.Length);
                Debug.Log("Write " + rawData.Length + "->" + writeDataSize);
            }
            else
            {
                writeData     = rawData;
                writeDataSize = rawData.Length;
            }
            byte[] fileData = new byte[writeDataSize + 32];

            int flag = TextureLoaderUtil.GetFlagInt(isCompress, (texture.mipmapCount > 1), (texture.filterMode != FilterMode.Point));

            // write header
            System.Array.Copy(FastLoaderUtil.FastTextureHeader, 0, fileData, 0, FastLoaderUtil.FastTextureHeader.Length);
            FastLoaderUtil.GetByteArrayFromInt(texture.width, fileData, 8);
            FastLoaderUtil.GetByteArrayFromInt(texture.height, fileData, 12);
            FastLoaderUtil.GetByteArrayFromInt((int)texture.format, fileData, 16);
            FastLoaderUtil.GetByteArrayFromInt(flag, fileData, 20);
            FastLoaderUtil.GetByteArrayFromInt(writeDataSize, fileData, 24);
            FastLoaderUtil.GetByteArrayFromInt(rawData.Length, fileData, 28);

            System.Array.Copy(writeData, 0, fileData, 32, writeDataSize);
            stream.Write(fileData, 0, fileData.Length);
            // calc crc32
            byte[] crc32 = new byte[4];
            FastLoaderUtil.GetByteArrayFromInt(Crc32.GetValue(fileData, 0, fileData.Length), crc32, 0);
            stream.Write(crc32, 0, crc32.Length);

            Debug.Log("format " + texture.format + "::" + (int)texture.format);
        }