コード例 #1
0
        public void ModifyD3DTX(DDS_Master dds)                                                //ISSUE HERE WITH DXT5 AND MIP MAPS WITH UPSCALED TEXTURES
        {
            mWidth         = dds.header.dwWidth;                                               //this is correct
            mHeight        = dds.header.dwHeight;                                              //this is correct
            mSurfaceFormat = DDS_Functions.Get_T3Format_FromFourCC(dds.header.ddspf.dwFourCC); //this is correct
            mDepth         = dds.header.dwDepth;
            mNumMipLevels  = dds.header.dwMipMapCount;

            List <byte[]> ddsData = dds.textureData;

            ddsData.Reverse();

            mPixelData.Clear();   //this is correct
            mPixelData = ddsData; //this is correct


            StreamHeader newStreamHeader = new StreamHeader()
            {
                mRegionCount   = (int)dds.header.dwMipMapCount,                         //this is correct
                mAuxDataCount  = mStreamHeader.mAuxDataCount,                           //this is correct
                mTotalDataSize = (int)ByteFunctions.Get2DByteArrayTotalSize(mPixelData) //this is correct
            };

            mStreamHeader = newStreamHeader;                                                //this is correct

            List <RegionStreamHeader> regionStreamHeader = new List <RegionStreamHeader>(); //this is correct

            uint[,] mipMapResolutions = DDS_Functions.DDS_CalculateMipResolutions(mNumMipLevels, mWidth, mHeight);
            bool blockSizeDouble = DDS_Functions.DDS_CompressionBool(dds.header);

            for (int i = 0; i < mStreamHeader.mRegionCount; i++)
            {
                RegionStreamHeader region = new RegionStreamHeader()
                {
                    mDataSize   = (uint)mPixelData[i].Length,
                    mFaceIndex  = 0,                                                                                                          //NOTE: for cubemap textures this will need to change
                    mMipCount   = 1,                                                                                                          //NOTE: for cubemap textures this will need to change
                    mMipIndex   = (mStreamHeader.mRegionCount - 1) - i,
                    mPitch      = DDS_Functions.DDS_ComputePitchValue(mipMapResolutions[mStreamHeader.mRegionCount - i, 0], blockSizeDouble), //this is correct
                    mSlicePitch = mPixelData[i].Length,                                                                                       //this is correct
                };

                regionStreamHeader.Add(region);
            }

            regionStreamHeader.Reverse();
            mRegionHeaders = regionStreamHeader.ToArray();

            UpdateArrayCapacities();
            PrintConsole();
        }
コード例 #2
0
        public void ModifyD3DTX(DDS_Master dds)
        {
            mWidth         = dds.header.dwWidth;
            mHeight        = dds.header.dwHeight;
            mSurfaceFormat = DDS_Functions.Get_T3Format_FromFourCC(dds.header.ddspf.dwFourCC);
            mDepth         = dds.header.dwDepth;
            mNumMipLevels  = dds.header.dwMipMapCount;

            List <byte[]> ddsData = new List <byte[]>(dds.textureData); //this is correct

            ddsData.Reverse();                                          //this is correct

            mPixelData.Clear();                                         //this is correct
            mPixelData = ddsData;                                       //this is correct

            StreamHeader newStreamHeader = new StreamHeader()
            {
                mRegionCount   = (int)dds.header.dwMipMapCount,
                mAuxDataCount  = mStreamHeader.mAuxDataCount,
                mTotalDataSize = (int)ByteFunctions.Get2DByteArrayTotalSize(mPixelData) //this is correct
            };

            mStreamHeader = newStreamHeader;

            RegionStreamHeader[] regionStreamHeader = new RegionStreamHeader[mStreamHeader.mRegionCount];
            uint[,] mipMapResolutions = DDS_Functions.DDS_CalculateMipResolutions(mNumMipLevels, mWidth, mHeight);
            bool blockSizeDouble = DDS_Functions.DDS_CompressionBool(dds.header);

            for (int i = 0; i < regionStreamHeader.Length; i++)
            {
                regionStreamHeader[i] = new RegionStreamHeader()
                {
                    mDataSize   = (uint)mPixelData[i].Length,
                    mFaceIndex  = 0,                                                                                                         //NOTE: for cubemap textures this will need to change
                    mMipCount   = 1,                                                                                                         //NOTE: for cubemap textures this will need to change
                    mMipIndex   = (regionStreamHeader.Length - 1) - i,                                                                       //mMipIndex = (regionStreamHeader.Length - 1) - i,
                    mPitch      = DDS_Functions.DDS_ComputePitchValue(mipMapResolutions[regionStreamHeader.Length - i, 0], blockSizeDouble), //this is correct
                    mSlicePitch = mPixelData[i].Length,                                                                                      //this is correct
                };
            }

            mRegionHeaders = regionStreamHeader;

            UpdateArrayCapacities();
            //PrintConsole();
        }
コード例 #3
0
        /// <summary>
        /// Parses the data from a DDS byte array. (Can also read just the header only)
        /// </summary>
        /// <param name="fileData"></param>
        /// <param name="headerOnly"></param>
        private void GetData(byte[] fileData, bool headerOnly)
        {
            ConsoleFunctions.SetConsoleColor(ConsoleColor.Black, ConsoleColor.White);
            Console.WriteLine("Total Source Texture Byte Size = {0}", fileData.Length);

            //which byte offset we are on for the source texture (will be changed as we go through the file)
            byte[] headerBytes = ByteFunctions.AllocateBytes(124, fileData, 4); //skip past the 'DDS '

            //this will automatically read all of the byte data in the header
            header = DDS_Functions.GetHeaderFromBytes(headerBytes);

            ConsoleFunctions.SetConsoleColor(ConsoleColor.Black, ConsoleColor.White);
            Console.WriteLine("DDS Height = {0}", header.dwHeight);
            Console.WriteLine("DDS Width = {0}", header.dwWidth);
            Console.WriteLine("DDS Mip Map Count = {0}", header.dwMipMapCount);
            Console.WriteLine("DDS Compression = {0}", header.ddspf.dwFourCC);

            if (headerOnly)
            {
                return;
            }

            //--------------------------EXTRACT DDS TEXTURE DATA--------------------------
            //calculate dds header length (we add 4 because we skipped the 4 bytes which contain the ddsPrefix, it isn't necessary to parse this data)
            uint ddsHeaderLength = 4 + header.dwSize;

            //calculate the length of just the dds texture data
            uint ddsTextureDataLength = (uint)sourceFileData.Length - ddsHeaderLength;

            //allocate a byte array of dds texture length
            byte[] ddsTextureData = new byte[ddsTextureDataLength];

            //copy the data from the source byte array past the header (so we are only getting texture data)
            Array.Copy(sourceFileData, ddsHeaderLength, ddsTextureData, 0, ddsTextureData.Length);

            //if there are no mip maps
            if (header.dwMipMapCount <= 1)
            {
                textureData = new();
                textureData.Add(ddsTextureData);
                Console.WriteLine("DDS Texture Byte Size = {0}", textureData[0].Length);
            }
            else //if there are mip maps
            {
                //get mip resolutions
                //calculated mip resolutions [Pixel Value, Width or Height (0 or 1)]
                mipMapResolutions = DDS_Functions.DDS_CalculateMipResolutions(header.dwMipMapCount, header.dwWidth, header.dwHeight);

                //get byte sizes
                uint[] byteSizes = DDS_Functions.DDS_GetImageByteSizes(mipMapResolutions, DDS_Functions.DDS_CompressionBool(header));

                textureData = new();
                int test   = ddsTextureData.Length;
                int offset = 0;

                for (int i = 0; i < byteSizes.Length; i++)
                {
                    byte[] temp = new byte[byteSizes[i]];

                    //issue length
                    Array.Copy(ddsTextureData, offset, temp, 0, temp.Length);

                    offset += temp.Length - 1;

                    textureData.Add(temp);

                    test -= (int)byteSizes[i];
                }
            }
        }