public void CreateArrayTest(string file1, string file2)
        {
            var list = new List<TexImage>();
            for (int i = 0; i < 5; ++i)
            {
                var temp = new TexImage();
                fiLib.Execute(temp, new LoadingRequest(file1, false));
                list.Add(temp);

                temp = new TexImage();
                fiLib.Execute(temp, new LoadingRequest(file2, false));
                list.Add(temp);
            }

            var array = new TexImage();
            library.Execute(array, new ArrayCreationRequest(list));

            Assert.IsTrue(array.ArraySize == list.Count);

            //Console.WriteLine("ArrayTexLibrary_CreateArray_" + Path.GetFileName(file1) + "_" + Path.GetFileName(file2) + "." + TestTools.ComputeSHA1(array.Data, array.DataSize));
            Assert.IsTrue(TestTools.ComputeSHA1(array.Data, array.DataSize).Equals(TestTools.GetInstance().Checksum["ArrayTexLibrary_CreateArray_" + Path.GetFileName(file1) + "_" + Path.GetFileName(file2)]));

            array.Dispose();
            foreach (var image in list)
            {
                image.Dispose();
            }
        }
Пример #2
0
        public static void FlipTest(TexImage image, ITexLibrary library, Orientation orientation)
        {
            library.Execute(image, new FlippingRequest(orientation));

            Assert.IsTrue(TestTools.ComputeSHA1(image.Data, image.DataSize).Equals(TestTools.GetInstance().Checksum["FlipTest_" + orientation + "_" + image.Name]));
            //Console.WriteLine("FlipTest_" + orientation + "_" + image.Name + "." + TestTools.ComputeSHA1(image.Data, image.DataSize));
        }
Пример #3
0
        public void StartLibrary(TexImage image)
        {
            if(image.Format.IsCompressed())
            {
                Log.Error("FreeImage can't process compressed texture.");
                throw new TextureToolsException("FreeImage can't process compressed texture.");
            }

            var libraryData = new FreeImageTextureLibraryData();
            image.LibraryData[this] = libraryData;

            libraryData.Bitmaps = new FIBITMAP[image.SubImageArray.Length];

            FREE_IMAGE_TYPE type;
            uint bpp, redMask, greenMask, blueMask;
            if (!FreeImage.GetFormatParameters(image.Format, out type, out bpp, out redMask, out greenMask, out blueMask))
            {
                throw new ArgumentException("The pixel format '{0}' is not supported by FreeImage".ToFormat(image.Format));
            }
            for (int i = 0; i < image.SubImageArray.Length; ++i)
            {
                var data = image.SubImageArray[i].Data;
                var width = image.SubImageArray[i].Width;
                var heigth = image.SubImageArray[i].Height;
                var pitch = image.SubImageArray[i].RowPitch;
                libraryData.Bitmaps[i] = FreeImage.ConvertFromRawBits(data, type, width, heigth, pitch, bpp, redMask, greenMask, blueMask, false);
            }

            if (image.DisposingLibrary != null) image.DisposingLibrary.Dispose(image);

            image.DisposingLibrary = this;

            libraryData.Data = IntPtr.Zero;
        }
Пример #4
0
        public bool CanHandleRequest(TexImage image, IRequest request)
        {
            switch (request.Type)
            {
                case RequestType.Export:
                    {
                        string extension = Path.GetExtension(((ExportRequest)request).FilePath);
                        return extension.Equals(".dds") || extension.Equals(Extension);
                    }

                case RequestType.ExportToXenko:
                    return true;

                case RequestType.Loading: // Xenko can load dds file or his own format or a Xenko <see cref="Image"/> instance.
                    LoadingRequest load = (LoadingRequest)request;
                    if(load.Mode == LoadingRequest.LoadingMode.XkImage) return true;
                    else if(load.Mode == LoadingRequest.LoadingMode.FilePath)
                    {
                        string extension = Path.GetExtension(load.FilePath);
                        return extension.Equals(".dds") || extension.Equals(Extension);
                    } else return false;

            }
            return false;
        }
Пример #5
0
        public void Execute(TexImage image, IRequest request)
        {
            switch (request.Type)
            {
                case RequestType.ArrayCreation:
                    CreateArray(image, (ArrayCreationRequest)request);
                    break;
                case RequestType.ArrayExtraction:
                    Extract(image, (ArrayExtractionRequest)request);
                    break;
                case RequestType.ArrayUpdate:
                    Update(image, (ArrayUpdateRequest)request);
                    break;
                case RequestType.ArrayInsertion:
                    Insert(image, (ArrayInsertionRequest)request);
                    break;
                case RequestType.ArrayElementRemoval:
                    Remove(image, (ArrayElementRemovalRequest)request);
                    break;
                case RequestType.CubeCreation:
                    CreateCube(image, (CubeCreationRequest)request);
                    break;

                default:
                    Log.Error("ArrayTexLib can't handle this request: " + request.Type);
                    throw new TextureToolsException("ArrayTexLib can't handle this request: " + request.Type);
            }
        }
Пример #6
0
        public void Execute(TexImage image, IRequest request)
        {
            if (image.GetType() != typeof(TexAtlas))
            {
                throw new TextureToolsException("The given texture must be an instance of TexAtlas.");
            }

            TexAtlas atlas = (TexAtlas)image;

            switch (request.Type)
            {
                case RequestType.AtlasCreation:
                    Create(atlas, (AtlasCreationRequest)request, 0);
                    break;
                case RequestType.AtlasExtraction:
                    Extract(atlas, (AtlasExtractionRequest)request);
                    break;
                case RequestType.AtlasUpdate:
                    Update(atlas, (AtlasUpdateRequest)request);
                    break;

                default:
                    Log.Error("AtlasTexLibrary can't handle this request: " + request.Type);
                    throw new TextureToolsException("AtlasTexLibrary can't handle this request: " + request.Type);
            }
        }
Пример #7
0
        public void StartLibrary(TexImage image)
        {
            if (image.LibraryData.ContainsKey(this) && ((DxtTextureLibraryData)image.LibraryData[this]).DxtImages[0].pixels.Equals(image.Data)) return;

            DxtTextureLibraryData libraryData = new DxtTextureLibraryData();
            image.LibraryData[this] = libraryData;

            DXGI_FORMAT format = RetrieveNativeFormat(image.Format);

            libraryData.DxtImages = new DxtImage[image.SubImageArray.Length];

            for (int i = 0; i < image.SubImageArray.Length; ++i)
            {
                libraryData.DxtImages[i] = new DxtImage(image.SubImageArray[i].Width, image.SubImageArray[i].Height, format, image.SubImageArray[i].RowPitch, image.SubImageArray[i].SlicePitch, image.SubImageArray[i].Data);
            }

            switch (image.Dimension)
            {
                case TexImage.TextureDimension.Texture1D:
                    libraryData.Metadata = new TexMetadata(image.Width, image.Height, image.Depth, image.ArraySize, image.MipmapCount, 0, 0, format, TEX_DIMENSION.TEX_DIMENSION_TEXTURE1D); break;
                case TexImage.TextureDimension.Texture2D:
                    libraryData.Metadata = new TexMetadata(image.Width, image.Height, image.Depth, image.ArraySize, image.MipmapCount, 0, 0, format, TEX_DIMENSION.TEX_DIMENSION_TEXTURE2D); break;
                case TexImage.TextureDimension.Texture3D:
                    libraryData.Metadata = new TexMetadata(image.Width, image.Height, image.Depth, image.ArraySize, image.MipmapCount, 0, 0, format, TEX_DIMENSION.TEX_DIMENSION_TEXTURE3D); break;
                case TexImage.TextureDimension.TextureCube:
                    libraryData.Metadata = new TexMetadata(image.Width, image.Height, image.Depth, image.ArraySize, image.MipmapCount, TEX_MISC_FLAG.TEX_MISC_TEXTURECUBE, 0, format, TEX_DIMENSION.TEX_DIMENSION_TEXTURE2D); break;
            }

            libraryData.Image = null;

        }
Пример #8
0
 public static TexImage Load(ITexLibrary library, string file)
 {
     var image = new TexImage();
     library.Execute(image, new LoadingRequest(InputTestFolder + file, false));
     image.Name = file;
     image.CurrentLibrary = library;
     return image;
 }
Пример #9
0
 public static void DecompressTest(TexImage image, ITexLibrary library)
 {
     Assert.IsTrue(image.Format.IsCompressed());
     library.Execute(image, new DecompressingRequest(false));
     Assert.IsTrue(image.Format == PixelFormat.R8G8B8A8_UNorm);
     Assert.IsTrue(TestTools.ComputeSHA1(image.Data, image.DataSize).Equals(TestTools.GetInstance().Checksum["DecompressTest_" + image.Name]));
     //Console.WriteLine("DecompressTest_" + image.Name + "." + TestTools.ComputeSHA1(image.Data, image.DataSize));
 }
Пример #10
0
        public static void SwitchChannelsTest(TexImage image, ITexLibrary library)
        {
            var isInRgbaOrder = image.Format.IsRGBAOrder();
            library.Execute(image, new SwitchingBRChannelsRequest());
            Assert.IsTrue(image.Format.IsRGBAOrder() != isInRgbaOrder);

            //Console.WriteLine("SwitchChannelsTest_" + image.Name + "." + TestTools.ComputeSHA1(image.Data, image.DataSize));
            Assert.IsTrue(TestTools.ComputeSHA1(image.Data, image.DataSize).Equals(TestTools.GetInstance().Checksum["SwitchChannelsTest_" + image.Name]));
        }
Пример #11
0
        /// <summary>
        /// The purpose of this test is to show that after calling the StartLibrary method on a TexImage,
        /// this image will contain in its LibraryData list the ITextureLibraryData instance corresponding
        /// to the actual state of the TexImage.
        /// An instance of ITextureLibraryData is creating at the load of the TexImage by the library so we
        /// must delete it first for the sake of this test.
        /// </summary>
        public static void StartLibraryTest(TexImage image, ITexLibrary library)
        {
            image.LibraryData.Remove(library); // deleting the LibraryData instance

            Assert.IsFalse(image.LibraryData.ContainsKey(library));

            library.StartLibrary(image);

            Assert.IsTrue(image.LibraryData.ContainsKey(library));
        }
Пример #12
0
        public void Dispose(TexImage image)
        {
            if (!image.LibraryData.ContainsKey(this)) return;
            PvrTextureLibraryData libraryData = (PvrTextureLibraryData)image.LibraryData[this];

            if (libraryData.Texture != null)
            {
                libraryData.Header = null;
                libraryData.Texture.Dispose();
            }
        }
Пример #13
0
 public void Execute(TexImage image, IRequest request)
 {
     switch (request.Type)
     {
         case RequestType.ColorKey:
             ApplyColorKey(image, (ColorKeyRequest)request);
             break;
         default:
             Log.Error("ColorKeyTexLibrary can't handle this request: " + request.Type);
             throw new TextureToolsException("ColorKeyTexLibrary can't handle this request: " + request.Type);
     }
 }
Пример #14
0
        public void StartLibraryTest(string file)
        {
            TexImage image = new TexImage();

            var dxtLib = new DxtTexLib();
            dxtLib.Execute(image, new LoadingRequest(Module.PathToInputImages + file, false));
            image.CurrentLibrary = dxtLib;
            dxtLib.EndLibrary(image);

            TexLibraryTest.StartLibraryTest(image, library);

            image.Dispose();
        }
Пример #15
0
        public bool CanHandleRequest(TexImage image, IRequest request)
        {
            switch (request.Type)
            {
                case RequestType.Compressing:
                    return SupportFormat(((CompressingRequest)request).Format) && SupportFormat(image.Format);
                case RequestType.Decompressing:
                    return SupportFormat(image.Format);

                default:
                    return false;
            }
        }
Пример #16
0
        public void Dispose(TexImage image)
        {
            DxtTextureLibraryData libraryData = (DxtTextureLibraryData)image.LibraryData[this];

            if (libraryData.Image == null && libraryData.DxtImages != null)
            {
                ScratchImage img = new ScratchImage();
                img.InitializeFromImages(libraryData.DxtImages, libraryData.DxtImages.Length);
                img.Release();
            }
            else
            {
                libraryData.Image.Dispose();
            }
        }
Пример #17
0
        public static void FixedRescaleTest(TexImage image, ITexLibrary library, Filter.Rescaling filter)
        {
            var request = new FixedRescalingRequest(256, 256, filter);
            int width = request.ComputeWidth(image);
            int height = request.ComputeHeight(image);

            library.Execute(image, request);
            Assert.IsTrue(image.Width == width);
            Assert.IsTrue(image.Height == height);
            Assert.IsTrue(image.MipmapCount == 1);

            image.Update();

            Assert.IsTrue(TestTools.ComputeSHA1(image.Data, image.DataSize).Equals(TestTools.GetInstance().Checksum["FixedRescaleTest_" + filter + "_" + image.Name]));
            //Console.WriteLine("FixedRescaleTest_" + filter + "_" + image.Name + "." + TestTools.ComputeSHA1(image.Data, image.DataSize));
        }
Пример #18
0
        public void StartLibrary(TexImage image)
        {
            AtitcTextureLibraryData libraryData = new AtitcTextureLibraryData();
            image.LibraryData[this] = libraryData;

            libraryData.Textures = new Texture[image.SubImageArray.Length];

            var bpp = Paradox.Graphics.PixelFormatExtensions.SizeInBits(image.Format);

            for (int i = 0; i < image.SubImageArray.Length; ++i)
            {
                libraryData.Textures[i] = new Texture(image.SubImageArray[i].Width, image.SubImageArray[i].Height, image.SubImageArray[i].RowPitch, RetrieveNativeFormat(image.Format), image.SubImageArray[i].DataSize, image.SubImageArray[i].Data);
            }

            libraryData.Data = IntPtr.Zero;
        }
Пример #19
0
        public void StartLibrary(TexImage image)
        {
            AtitcTextureLibraryData libraryData = new AtitcTextureLibraryData();
            image.LibraryData[this] = libraryData;

            libraryData.Textures = new Texture[image.SubImageArray.Length];

            int bpp = (int)image.Format.GetBPP();

            for (int i = 0; i < image.SubImageArray.Length; ++i)
            {
                libraryData.Textures[i] = new Texture(image.SubImageArray[i].Width, image.SubImageArray[i].Height, image.SubImageArray[i].RowPitch, RetrieveNativeFormat(image.Format), image.SubImageArray[i].DataSize, image.SubImageArray[i].Data);
            }

            libraryData.Data = IntPtr.Zero;
        }
Пример #20
0
        public bool CanHandleRequest(TexImage image, IRequest request)
        {
            switch (request.Type)
            {
                case RequestType.ArrayCreation:
                case RequestType.ArrayExtraction:
                case RequestType.ArrayUpdate:
                case RequestType.ArrayInsertion:
                case RequestType.ArrayElementRemoval:
                case RequestType.CubeCreation:
                    return true;

                default:
                    return false;
            }
        }
Пример #21
0
        public void ExportToXenkoTest(string file)
        {
            TexImage image = TestTools.Load(library, file);

            ExportToXenkoRequest request = new ExportToXenkoRequest();

            library.Execute(image, request);

            var xk = request.XkImage;

            Assert.True(xk.TotalSizeInBytes == image.DataSize);
            Assert.True(xk.Description.MipLevels == image.MipmapCount);
            Assert.True(xk.Description.Width == image.Width);
            Assert.True(xk.Description.Height == image.Height);

            image.Dispose();
        }
Пример #22
0
        public void StartLibrary(TexImage image)
        {
            AtitcTextureLibraryData libraryData = new AtitcTextureLibraryData();

            image.LibraryData[this] = libraryData;

            libraryData.Textures = new Texture[image.SubImageArray.Length];

            int bpp = (int)Tools.GetBPP(image.Format);

            for (int i = 0; i < image.SubImageArray.Length; ++i)
            {
                libraryData.Textures[i] = new Texture(image.SubImageArray[i].Width, image.SubImageArray[i].Height, image.SubImageArray[i].RowPitch, RetrieveNativeFormat(image.Format), image.SubImageArray[i].DataSize, image.SubImageArray[i].Data);
            }

            libraryData.Data = IntPtr.Zero;
        }
Пример #23
0
        public ITexImage ReadFrom(
            BinaryReader reader,
            ITexImageContainer container,
            TexFormat texFormat)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            if (!texFormat.IsValid())
            {
                throw new EnumNotValidException <TexFormat>(texFormat);
            }

            var mipmapCount = reader.ReadInt32();

            if (mipmapCount > Constants.MaximumMipmapCount)
            {
                throw new UnsafeTexException(
                          $"Mipmap count exceeds limit: {mipmapCount}/{Constants.MaximumMipmapCount}");
            }

            var readFunction = PickMipmapReader(container.ImageContainerVersion);
            var format       = TexMipmapFormatGetter.GetFormatForTex(container.ImageFormat, texFormat);
            var image        = new TexImage();

            for (var i = 0; i < mipmapCount; i++)
            {
                var mipmap = readFunction(reader);
                mipmap.Format = format;

                if (DecompressMipmapBytes)
                {
                    _texMipmapDecompressor.DecompressMipmap(mipmap);
                }

                image.Mipmaps.Add(mipmap);
            }

            return(image);
        }
        public void UpdateTest(string arrayFile, int indice, string newTexture)
        {
            TexImage array = TestTools.Load(dxtLib, arrayFile);

            dxtLib.EndLibrary(array);

            var updateTexture = TestTools.Load(fiLib, newTexture);

            library.Execute(array, new ArrayUpdateRequest(updateTexture, indice));
            library.EndLibrary(array);

            //Console.WriteLine("ArrayTexLibrary_Update_" + indice + "_" + arrayFile + "." + TestTools.ComputeSHA1(array.Data, array.DataSize));
            Assert.IsTrue(TestTools.ComputeSHA1(array.Data, array.DataSize).Equals(TestTools.GetInstance().Checksum["ArrayTexLibrary_Update_" + indice + "_" + arrayFile]));

            updateTexture.Dispose();
            array.Dispose();
        }
Пример #25
0
        /// <summary>
        /// Creates a texture array.
        /// </summary>
        /// <param name="array">The array.</param>
        /// <param name="request">The request.</param>
        private void Create(TexImage array, ArrayCreationRequest request)
        {
            array.Width            = request.TextureList[0].Width;
            array.Height           = request.TextureList[0].Height;
            array.Depth            = request.TextureList[0].Depth;
            array.RowPitch         = request.TextureList[0].RowPitch;
            array.SlicePitch       = request.TextureList[0].SlicePitch;
            array.Format           = request.TextureList[0].Format;
            array.FaceCount        = request.TextureList[0].FaceCount;
            array.MipmapCount      = request.TextureList[0].MipmapCount;
            array.DisposingLibrary = this;

            array.Name      = request.TextureList[0].Name + "_array";
            array.ArraySize = request.TextureList.Count;

            array.SubImageArray = new TexImage.SubImage[request.TextureList.Count * request.TextureList[0].SubImageArray.Length];

            array.DataSize = 0;
            array.DataSize = request.TextureList[0].DataSize * array.ArraySize;

            array.Data = Marshal.AllocHGlobal(array.DataSize);

            int      offset1, offset2;
            long     arrayData = array.Data.ToInt64();
            long     currentData;
            IntPtr   buffer;
            TexImage current;

            offset1 = 0;
            for (int i = 0; i < request.TextureList.Count; ++i)
            {
                current  = request.TextureList[i];
                buffer   = new IntPtr(arrayData + offset1);
                offset1 += current.DataSize;
                Utilities.CopyMemory(buffer, current.Data, current.DataSize);

                offset2     = 0;
                currentData = buffer.ToInt64();
                for (int j = 0; j < current.SubImageArray.Length; ++j)
                {
                    array.SubImageArray[i * current.SubImageArray.Length + j]      = current.SubImageArray[j];
                    array.SubImageArray[i * current.SubImageArray.Length + j].Data = new IntPtr(currentData + offset2);
                    offset2 += current.SubImageArray[j].DataSize;
                }
            }
        }
Пример #26
0
        public void StartLibrary(TexImage image)
        {
            AtitcTextureLibraryData libraryData = new AtitcTextureLibraryData();

            image.LibraryData[this] = libraryData;

            libraryData.Textures = new Texture[image.SubImageArray.Length];

            var bpp = Xenko.Graphics.PixelFormatExtensions.SizeInBits(image.Format);

            for (int i = 0; i < image.SubImageArray.Length; ++i)
            {
                libraryData.Textures[i] = new Texture(image.SubImageArray[i].Width, image.SubImageArray[i].Height, image.SubImageArray[i].RowPitch, RetrieveNativeFormat(image.Format), image.SubImageArray[i].DataSize, image.SubImageArray[i].Data);
            }

            libraryData.Data = IntPtr.Zero;
        }
Пример #27
0
        public void ExportToParadoxTest(string file)
        {
            TexImage image = TestTools.Load(library, file);

            ExportToParadoxRequest request = new ExportToParadoxRequest();

            library.Execute(image, request);

            var pdx = request.PdxImage;

            Assert.IsTrue(pdx.TotalSizeInBytes == image.DataSize);
            Assert.IsTrue(pdx.Description.MipLevels == image.MipmapCount);
            Assert.IsTrue(pdx.Description.Width == image.Width);
            Assert.IsTrue(pdx.Description.Height == image.Height);

            image.Dispose();
        }
Пример #28
0
        private void Start()
        {
            patternImage   = TexImage.Create(patternImageSize, PixelFormat.EFormat.BGR32);
            drawLayerImage = TexImage.Create(patternImageSize, PixelFormat.EFormat.BGR32);

            _patternPatternDetector =
                (patternType == PatternType.Charuco ?
                 (Pattern.Pattern) new Charuco(patternSize, squareLength) :
                 new LineGrid(patternSize, patternRegion)).GetDetector();
            var pattern = (GridPattern)_patternPatternDetector.pattern;

            Debug.Log($"Pattern {patternType} Corners: {pattern.Corners}");
            Debug.Log($"Pattern {patternType} XGrids: {pattern.XGrids}");
            Debug.Log($"Pattern {patternType} YGrids: {pattern.YGrids}");

            _patternPatternDetector.pattern.Draw(patternImage);
            Debug.Log(_patternPatternDetector.Run(patternImage, drawLayerImage, isDebug));
        }
Пример #29
0
        public void RescaleTest(string file)
        {
            TexImage image  = texTool.Load(Module.PathToInputImages + file);
            int      width  = image.Width;
            int      height = image.Height;

            Assert.True(image.MipmapCount > 1);

            texTool.Rescale(image, 0.5f, 0.5f, Filter.Rescaling.Bicubic);
            Assert.True(image.Width == width / 2);
            Assert.True(image.Height == height / 2);
            Assert.True(image.MipmapCount == 1);

            Assert.Equal(TestTools.GetInstance().Checksum["TextureTool_Rescale_" + image.Name], TestTools.ComputeSHA1(image.Data, image.DataSize));
            //Console.WriteLine("TextureTool_Rescale_" + image.Name + "." + TestTools.ComputeSHA1(image.Data, image.DataSize));

            image.Dispose();
        }
Пример #30
0
        public bool CanHandleRequest(TexImage image, IRequest request)
        {
            if (image.GetType() != typeof(TexAtlas))
            {
                return(false);
            }

            switch (request.Type)
            {
            case RequestType.AtlasCreation:
            case RequestType.AtlasExtraction:
            case RequestType.AtlasUpdate:
                return(true);

            default:
                return(false);
            }
        }
Пример #31
0
        public void ExtractTest(string arrayFile, int indice)
        {
            TexImage array = TestTools.Load(dxtLib, arrayFile);

            var request = new ArrayExtractionRequest(indice, 16);

            library.Execute(array, request);
            array.CurrentLibrary = library;

            var extracted = request.Texture;

            //Console.WriteLine("ArrayTexLibrary_Extract_" + arrayFile + "." + TestTools.ComputeSHA1(extracted.Data, extracted.DataSize));
            Assert.IsTrue(TestTools.ComputeSHA1(extracted.Data, extracted.DataSize).Equals(TestTools.GetInstance().Checksum["ArrayTexLibrary_Extract_" + arrayFile]));

            extracted.Dispose();

            array.Dispose();
        }
Пример #32
0
        public void EndLibraryTest(string file)
        {
            TexImage image = LoadInput(file);

            IntPtr buffer;

            buffer = image.SubImageArray[0].Data;
            library.Execute(image, new DecompressingRequest(false));

            Assert.IsTrue(image.Format == Xenko.Graphics.PixelFormat.R8G8B8A8_UNorm); // The images features are updated with the call to Execute
            Assert.IsTrue(image.SubImageArray[0].Data == buffer);                     // The sub images are only updated on the call to EndLibrary

            library.EndLibrary(image);

            Assert.IsTrue(image.SubImageArray[0].Data != buffer);

            image.Dispose();
        }
Пример #33
0
        public void EndLibrary(TexImage image)
        {
            if (!image.LibraryData.ContainsKey(this))
            {
                return;
            }
            AtitcTextureLibraryData libraryData = (AtitcTextureLibraryData)image.LibraryData[this];

            for (int i = 0; i < libraryData.Textures.Length; ++i)
            {
                image.SubImageArray[i].Data       = libraryData.Textures[i].pData;
                image.SubImageArray[i].DataSize   = libraryData.Textures[i].dwDataSize;
                image.SubImageArray[i].Width      = libraryData.Textures[i].dwWidth;
                image.SubImageArray[i].Height     = libraryData.Textures[i].dwHeight;
                image.SubImageArray[i].RowPitch   = libraryData.Textures[i].dwPitch;
                image.SubImageArray[i].SlicePitch = libraryData.Textures[i].dwDataSize;
            }
        }
Пример #34
0
        public void StartLibraryTest(string file)
        {
            TexImage image = TestTools.Load(library, file);

            TexLibraryTest.StartLibraryTest(image, library);

            DxtTextureLibraryData libraryData = (DxtTextureLibraryData)image.LibraryData[library];

            Assert.True(libraryData.DxtImages.Length == image.SubImageArray.Length);
            for (int i = 0; i < libraryData.DxtImages.Length; ++i) // Checking on features
            {
                Assert.True(libraryData.DxtImages[i].RowPitch == image.SubImageArray[i].RowPitch);
            }

            image.CurrentLibrary = null; // If we don't set the CurrentLibrary to null, the Dispose() method of TexImage will try calling the EndMethod, which won't work if no operation has been made on the image since the StartLibrary call. This case can't happen.

            image.Dispose();
        }
Пример #35
0
        public bool CanHandleRequest(TexImage image, IRequest request)
        {
            if (image.GetType() != typeof(TexAtlas))
            {
                return false;
            }

            switch (request.Type)
            {
                case RequestType.AtlasCreation:
                case RequestType.AtlasExtraction:
                case RequestType.AtlasUpdate:
                    return true;

                default:
                    return false;
            }
        }
Пример #36
0
        public void DecompressFailTest(string file)
        {
            TexImage image = TestTools.Load(library, file);

            Assert.True(image.Format == Stride.Graphics.PixelFormat.B8G8R8A8_UNorm);

            try
            {
                library.Execute(image, new DecompressingRequest(false));
                Assert.True(false);
            }
            catch (TextureToolsException)
            {
                Assert.True(true);
            }

            image.Dispose();
        }
Пример #37
0
        public void ResizeTest(string file)
        {
            TexImage image  = texTool.Load(TestTools.InputTestFolder + file);
            int      width  = image.Width;
            int      height = image.Height;

            Assert.IsTrue(image.MipmapCount > 1);

            texTool.Resize(image, width / 2, height / 2, Filter.Rescaling.Bicubic);
            Assert.IsTrue(image.Width == width / 2);
            Assert.IsTrue(image.Height == height / 2);
            Assert.IsTrue(image.MipmapCount == 1);

            Assert.IsTrue(TestTools.ComputeSHA1(image.Data, image.DataSize).Equals(TestTools.GetInstance().Checksum["TextureTool_Rescale_" + image.Name]));
            //Console.WriteLine("TextureTool_Rescale_" + image.Name + "." + TestTools.ComputeSHA1(image.Data, image.DataSize));

            image.Dispose();
        }
Пример #38
0
        public void ExtractAllTest(string file1, string file2)
        {
            var list = new List <TexImage>();

            for (int i = 0; i < 5; ++i)
            {
                var temp = new TexImage();
                fiLib.Execute(temp, new LoadingRequest(Module.PathToInputImages + file1, false));
                temp.Name = Path.GetFileName(file1);
                list.Add(temp);
                //Console.WriteLine("ExtractAll_" + Path.GetFileName(file1) + "." + TestTools.ComputeSHA1(temp.Data, temp.DataSize));

                temp = new TexImage();
                fiLib.Execute(temp, new LoadingRequest(Module.PathToInputImages + file2, false));
                temp.Name = Path.GetFileName(file2);
                list.Add(temp);
                //Console.WriteLine("ExtractAll_" + Path.GetFileName(file2) + "." + TestTools.ComputeSHA1(temp.Data, temp.DataSize));
            }

            var array = new TexImage();

            library.Execute(array, new ArrayCreationRequest(list));

            var request = new ArrayExtractionRequest(0);

            library.Execute(array, request);
            library.EndLibrary(array);

            Assert.IsTrue(list.Count == request.Textures.Count);

            for (int i = 0; i < array.ArraySize; ++i)
            {
                var temp = request.Textures[i];
                Assert.IsTrue(TestTools.ComputeSHA1(temp.Data, temp.DataSize).Equals(TestTools.GetInstance().Checksum["ExtractAll_" + list[i].Name]));
                temp.Dispose();
            }

            array.Dispose();

            foreach (var image in list)
            {
                image.Dispose();
            }
        }
Пример #39
0
        /// <summary>
        /// Loads the specified image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="request">The request.</param>
        private void Load(TexImage image, LoadingRequest request)
        {
            Log.Info("Loading " + request.FilePath + " ...");

            PvrTextureLibraryData libraryData = new PvrTextureLibraryData();

            image.LibraryData[this] = libraryData;

            libraryData.Texture = new PVRTexture(request.FilePath);
            libraryData.Header  = libraryData.Texture.GetHeader();

            image.Width  = (int)libraryData.Header.GetWidth();
            image.Height = (int)libraryData.Header.GetHeight();
            image.Depth  = (int)libraryData.Header.GetDepth();
            image.Format = RetrieveFormatFromNativeData(libraryData.Header);

            int pitch, slice;

            Tools.ComputePitch(image.Format, (int)image.Width, (int)image.Height, out pitch, out slice);
            image.RowPitch   = pitch;
            image.SlicePitch = slice;

            image.DisposingLibrary = this;

            UpdateImage(image, libraryData);

            if (image.FaceCount > 1 && image.FaceCount % 6 == 0)
            {
                image.Dimension = TexImage.TextureDimension.TextureCube;
            }
            else if (image.Depth > 1)
            {
                image.Dimension = TexImage.TextureDimension.Texture3D;
            }
            else if (image.Height > 0)
            {
                image.Dimension = TexImage.TextureDimension.Texture2D;
            }
            else
            {
                image.Dimension = TexImage.TextureDimension.Texture1D;
            }
        }
Пример #40
0
        public void Execute(TexImage image, IRequest request)
        {
            FreeImageTextureLibraryData libraryData = image.LibraryData.ContainsKey(this) ? (FreeImageTextureLibraryData)image.LibraryData[this] : null;

            switch (request.Type)
            {
            case RequestType.Loading:
                Load(image, libraryData, (LoadingRequest)request);
                break;

            case RequestType.Rescaling:
                Rescale(image, libraryData, (RescalingRequest)request);
                break;

            case RequestType.SwitchingChannels:
                SwitchChannels(image, libraryData, (SwitchingBRChannelsRequest)request);
                break;

            case RequestType.Flipping:
                Flip(image, libraryData, (FlippingRequest)request);
                break;

            case RequestType.FlippingSub:
                FlipSub(image, libraryData, (FlippingSubRequest)request);
                break;

            case RequestType.Swapping:
                Swap(image, libraryData, (SwappingRequest)request);
                break;

            case RequestType.Export:
                Export(image, libraryData, (ExportRequest)request);
                break;

            case RequestType.GammaCorrection:
                CorrectGamma(image, libraryData, (GammaCorrectionRequest)request);
                break;

            default:
                Log.Error("FITexLib (FreeImage) can't handle this request: " + request.Type);
                throw new TextureToolsException("FITexLib (FreeImage) can't handle this request: " + request.Type);
            }
        }
Пример #41
0
        public void Execute(TexImage image, IRequest request)
        {
            AtitcTextureLibraryData libraryData = (AtitcTextureLibraryData)image.LibraryData[this];

            switch (request.Type)
            {
            case RequestType.Compressing:
                Compress(image, libraryData, (CompressingRequest)request);
                break;

            case RequestType.Decompressing:
                Decompress(image, libraryData, (DecompressingRequest)request);
                break;

            default:
                Log.Error("DxtTexLib (DirectXTex) can't handle this request: " + request.Type);
                throw new TextureToolsException("DxtTexLib (DirectXTex) can't handle this request: " + request.Type);
            }
        }
Пример #42
0
        public void Execute(TexImage image, IRequest request)
        {
            DxtTextureLibraryData libraryData = image.LibraryData.ContainsKey(this) ? (DxtTextureLibraryData)image.LibraryData[this] : null;

            switch (request.Type)
            {
            case RequestType.Loading:
                Load(image, libraryData, (LoadingRequest)request);
                break;

            case RequestType.Compressing:
                Compress(image, libraryData, (CompressingRequest)request);
                break;

            case RequestType.Export:
                Export(image, libraryData, (ExportRequest)request);
                break;

            case RequestType.Decompressing:
                Decompress(image, libraryData);
                break;

            case RequestType.MipMapsGeneration:
                GenerateMipMaps(image, libraryData, (MipMapsGenerationRequest)request);
                break;

            case RequestType.Rescaling:
                Rescale(image, libraryData, (RescalingRequest)request);
                break;

            case RequestType.NormalMapGeneration:
                GenerateNormalMap(image, libraryData, (NormalMapGenerationRequest)request);
                break;

            case RequestType.PreMultiplyAlpha:
                PreMultiplyAlpha(image, libraryData);
                break;

            default:
                Log.Error("DxtTexLib (DirectXTex) can't handle this request: " + request.Type);
                throw new TextureToolsException("DxtTexLib (DirectXTex) can't handle this request: " + request.Type);
            }
        }
Пример #43
0
        public void RemoveTest(string arrayFile, int indice)
        {
            TexImage array = TestTools.Load(dxtLib, arrayFile);

            int arraySize = array.ArraySize;

            dxtLib.EndLibrary(array);
            library.StartLibrary(array); // for fun cause it's empty
            library.Execute(array, new ArrayElementRemovalRequest(indice));
            array.CurrentLibrary = library;
            array.Update();

            Assert.IsTrue(arraySize == array.ArraySize + 1);

            //Console.WriteLine("ArrayTexLibrary_Remove_" + indice + "_" + arrayFile + "." + TestTools.ComputeSHA1(array.Data, array.DataSize));
            Assert.IsTrue(TestTools.ComputeSHA1(array.Data, array.DataSize).Equals(TestTools.GetInstance().Checksum["ArrayTexLibrary_Remove_" + indice + "_" + arrayFile]));

            array.Dispose();
        }
Пример #44
0
        public void Execute(TexImage image, IRequest request)
        {
            ParadoxTextureLibraryData libraryData = image.LibraryData.ContainsKey(this) ? (ParadoxTextureLibraryData)image.LibraryData[this] : null;

            switch (request.Type)
            {
            case RequestType.Export:
                Export(image, libraryData, (ExportRequest)request);
                break;

            case RequestType.ExportToParadox:
                ExportToParadox(image, libraryData, (ExportToParadoxRequest)request);
                break;

            case RequestType.Loading:
                Load(image, (LoadingRequest)request);
                break;
            }
        }
Пример #45
0
        public void DecompressFailTest(string file)
        {
            TexImage image = TestTools.Load(library, file);

            Assert.IsTrue(image.Format == SiliconStudio.Paradox.Graphics.PixelFormat.B8G8R8A8_UNorm);
            int dataSize = image.DataSize;

            try
            {
                library.Execute(image, new DecompressingRequest());
                Assert.IsTrue(false);
            }
            catch (TextureToolsException)
            {
                Assert.IsTrue(true);
            }

            image.Dispose();
        }
Пример #46
0
        /// <summary>
        /// Loads the specified image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="libraryData">The library data.</param>
        /// <param name="loader">The loader.</param>
        /// <exception cref="TexLibraryException">Loading dds file failed</exception>
        private void Load(TexImage image, DxtTextureLibraryData libraryData, LoadingRequest loader)
        {
            Log.Info("Loading " + loader.FilePath + " ...");

            libraryData             = new DxtTextureLibraryData();
            image.LibraryData[this] = libraryData;

            libraryData.Image    = new ScratchImage();
            libraryData.Metadata = new TexMetadata();
            HRESULT hr = Utilities.LoadDDSFile(loader.FilePath, DDS_FLAGS.DDS_FLAGS_NONE, out libraryData.Metadata, libraryData.Image);

            if (hr != HRESULT.S_OK)
            {
                Log.Error("Loading dds file " + loader.FilePath + " failed: " + hr);
                throw new TextureToolsException("Loading dds file " + loader.FilePath + " failed: " + hr);
            }

            libraryData.DxtImages = libraryData.Image.GetImages();

            image.DisposingLibrary = this;

            if (libraryData.Metadata.miscFlags == TEX_MISC_FLAG.TEX_MISC_TEXTURECUBE)
            {
                image.Dimension = TexImage.TextureDimension.TextureCube;
            }
            else
            {
                switch (libraryData.Metadata.dimension)
                {
                case TEX_DIMENSION.TEX_DIMENSION_TEXTURE1D:
                    image.Dimension = TexImage.TextureDimension.Texture1D; break;

                case TEX_DIMENSION.TEX_DIMENSION_TEXTURE2D:
                    image.Dimension = TexImage.TextureDimension.Texture2D; break;

                case TEX_DIMENSION.TEX_DIMENSION_TEXTURE3D:
                    image.Dimension = TexImage.TextureDimension.Texture3D; break;
                }
            }

            UpdateImage(image, libraryData);
        }
Пример #47
0
        public void Start()
        {
            _image = TexImage.Create(new Vector2Int(800, 600), PixelFormat.EFormat.BGR32);
            var painter = new Painter(_image);

            painter.Fill(new Color32(255, 255, 255, 100));
            painter.Line(new Vector2(10, 10), new Vector2(100, 10), Color.red);
            painter.Line(new Vector2(10, 10), new Vector2(10, 100), Color.green, 2);
            painter.Triangle(new Vector2(100, 10), 5, 0.0f, Color.red, -1);
            painter.Triangle(new Vector2(10, 100), 5, 90.0f, Color.green, -1);
            painter.Text("X", new Vector2Int(110, 20), Painter.Font.HERSHEY_PLAIN, 2.0f,
                         Color.red, 1);
            painter.Text("Y", new Vector2Int(5, 130), Painter.Font.HERSHEY_PLAIN, 2.0f,
                         Color.green, 1);
            painter.Rectangle(new Rect(150, 150, 100, 200), Color.black, -1);
            painter.Rectangle(new Rect(150, 150, 100, 200), Color.magenta, 3);
            painter.Marker(new Vector2(200, 250), Painter.MarkerType.STAR, 30,
                           new Color32(255, 126, 0, 255), 2);
            var markerPositions = new[] {
                new Vector2(Random.Range(300, 750), Random.Range(50, 550)),
                new Vector2(Random.Range(300, 750), Random.Range(50, 550)),
                new Vector2(Random.Range(300, 750), Random.Range(50, 550)),
                new Vector2(Random.Range(300, 750), Random.Range(50, 550)),
                new Vector2(Random.Range(300, 750), Random.Range(50, 550)),
                new Vector2(Random.Range(300, 750), Random.Range(50, 550))
            };

            painter.Markers(markerPositions, Painter.MarkerType.DIAMOND, 10, Color.yellow);
            var polylines = new[] {
                new[] { new Vector2(350, 100), new Vector2(425, 200), new Vector2(360, 300) },
                new[] {
                    new Vector2(521, 322), new Vector2(618, 294), new Vector2(425, 309),
                    new Vector2(512, 323)
                }
            };

            foreach (var polyline in polylines)
            {
                painter.Polyline(polyline, new Color32(0, 88, 255, 255), 2);
                painter.Polyline(polyline, new Color32(94, 200, 255, 255), -1, false);
            }
        }
Пример #48
0
        /// <summary>
        /// Decompresses the specified image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="libraryData">The library data.</param>
        /// <exception cref="TexLibraryException">Decompression failed!</exception>
        public void Decompress(TexImage image, PvrTextureLibraryData libraryData)
        {
            Log.Info("Decompressing texture ...");

            if (!Utilities.Transcode(libraryData.Texture, PixelType.Standard8PixelType, libraryData.Header.GetChannelType(), libraryData.Header.GetColourSpace(), ECompressorQuality.ePVRTCNormal, true))
            {
                Log.Error("Decompression failed!");
                throw new TextureToolsException("Decompression failed!");
            }

            image.Format = SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UNorm;

            int pitch, slice;

            Tools.ComputePitch(image.Format, image.Width, image.Height, out pitch, out slice);
            image.RowPitch   = pitch;
            image.SlicePitch = slice;

            UpdateImage(image, libraryData);
        }
Пример #49
0
        /// <summary>
        /// Flips the specified image horizontally or vertically.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="libraryData">The library data.</param>
        /// <param name="flip">The flip request.</param>
        private void Flip(TexImage image, FreeImageTextureLibraryData libraryData, FlippingRequest flip)
        {
            Log.Info("Flipping image : " + flip.Flip + " ...");

            for (int i = 0; i < libraryData.Bitmaps.Length; ++i)
            {
                switch (flip.Flip)
                {
                case Orientation.Vertical:
                    FreeImage.FlipVertical(libraryData.Bitmaps[i]);
                    break;

                case Orientation.Horizontal:
                    FreeImage.FlipHorizontal(libraryData.Bitmaps[i]);
                    break;
                }
            }

            image.Flip(flip.Flip);
        }
Пример #50
0
        /// <summary>
        /// Decompresses the specified image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="libraryData">The library data.</param>
        /// <param name="request">The decompression request</param>
        /// <exception cref="TextureToolsException">Decompression failed!</exception>
        public void Decompress(TexImage image, PvrTextureLibraryData libraryData, DecompressingRequest request)
        {
            Log.Verbose("Decompressing texture ...");

            if (!Utilities.Transcode(libraryData.Texture, PixelType.Standard8PixelType, libraryData.Header.GetChannelType(), libraryData.Header.GetColourSpace(), ECompressorQuality.ePVRTCNormal, true))
            {
                Log.Error("Decompression failed!");
                throw new TextureToolsException("Decompression failed!");
            }

            image.Format = request.DecompressedFormat;

            int pitch, slice;

            Tools.ComputePitch(image.Format, image.Width, image.Height, out pitch, out slice);
            image.RowPitch   = pitch;
            image.SlicePitch = slice;

            UpdateImage(image, libraryData);
        }
Пример #51
0
        /// <summary>
        /// Switches the channels R and B.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="libraryData">The library data.</param>
        /// <param name="request">The request.</param>
        /// <exception cref="TexLibraryException">Unsuported format for channel switching.</exception>
        private void SwitchChannels(TexImage image, PvrTextureLibraryData libraryData, SwitchingBRChannelsRequest request)
        {
            Log.Info("Switching channels B and R ...");

            switch (image.Format)
            {
            case SiliconStudio.Paradox.Graphics.PixelFormat.B8G8R8A8_UNorm:
                image.Format = SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UNorm; break;

            case SiliconStudio.Paradox.Graphics.PixelFormat.B8G8R8A8_Typeless:
                image.Format = SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_Typeless; break;

            case SiliconStudio.Paradox.Graphics.PixelFormat.B8G8R8A8_UNorm_SRgb:
                image.Format = SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UNorm_SRgb; break;

            case SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_Typeless:
                image.Format = SiliconStudio.Paradox.Graphics.PixelFormat.B8G8R8A8_Typeless; break;

            case SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UNorm:
                image.Format = SiliconStudio.Paradox.Graphics.PixelFormat.B8G8R8A8_UNorm; break;

            case SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UNorm_SRgb:
                image.Format = SiliconStudio.Paradox.Graphics.PixelFormat.B8G8R8A8_UNorm_SRgb; break;

            default:
                Log.Error("Unsuported format for channel switching.");
                throw new TextureToolsException("Unsuported format for channel switching.");
            }

            PVRTexture textureTemp = new PVRTexture(libraryData.Header, libraryData.Texture.GetDataPtr());

            EChannelName e1 = EChannelName.eBlue;
            EChannelName e2 = EChannelName.eRed;

            Utilities.CopyChannels(libraryData.Texture, textureTemp, 1, out e1, out e2);
            Utilities.CopyChannels(libraryData.Texture, textureTemp, 1, out e2, out e1);

            textureTemp.Dispose();

            UpdateImage(image, libraryData);
        }
Пример #52
0
        public unsafe void ApplyColorKey(TexImage image, ColorKeyRequest request)
        {
            Log.Info("Apply color key [{0}]", request.ColorKey);

            var colorKey = request.ColorKey;
            var rowPtr = image.Data;
            if (image.Format == PixelFormat.R8G8B8A8_UNorm)
            {
                for (int i = 0; i < image.Height; i++)
                {
                    var colors = (Core.Mathematics.Color*)rowPtr;
                    for (int x = 0; x < image.Width; x++)
                    {
                        if (colors[x] == colorKey)
                        {
                            colors[x] = Core.Mathematics.Color.Transparent;
                        }
                    }
                    rowPtr = IntPtr.Add(rowPtr, image.RowPitch);
                }
            }
            else if (image.Format == PixelFormat.B8G8R8A8_UNorm)
            {
                var rgbaColorKey = colorKey.ToRgba();
                for (int i = 0; i < image.Height; i++)
                {
                    var colors = (Core.Mathematics.ColorBGRA*)rowPtr;
                    for (int x = 0; x < image.Width; x++)
                    {
                        if (colors[x].ToRgba() == rgbaColorKey)
                        {
                            colors[x] = Core.Mathematics.Color.Transparent;
                        }
                    }
                    rowPtr = IntPtr.Add(rowPtr, image.RowPitch);
                }
            }
        }
Пример #53
0
        public bool CanHandleRequest(TexImage image, IRequest request)
        {
            switch (request.Type)
            {
                    // Loading only file with a .pvr extension
                case RequestType.Loading:
                    LoadingRequest loader = (LoadingRequest)request;
                    return loader.Mode == LoadingRequest.LoadingMode.FilePath && (Path.GetExtension(loader.FilePath).Equals(".pvr") || Path.GetExtension(loader.FilePath).Equals(".ktx"));

                case RequestType.Compressing:
                    CompressingRequest compress = (CompressingRequest)request;
                    return SupportFormat(compress.Format) && SupportFormat(image.Format);

                case RequestType.Export:
                    ExportRequest export = (ExportRequest)request;
                    return SupportFormat(image.Format) && (Path.GetExtension(export.FilePath).Equals(".pvr") || Path.GetExtension(export.FilePath).Equals(".ktx"));

                case RequestType.Decompressing:
                    return SupportFormat(image.Format);

                case RequestType.MipMapsGeneration:
                    return ((MipMapsGenerationRequest)request).Filter != Filter.MipMapGeneration.Box;

                case RequestType.Rescaling:
                    Filter.Rescaling filter = ((RescalingRequest)request).Filter;
                    return filter == Filter.Rescaling.Bicubic || filter == Filter.Rescaling.Bilinear || filter == Filter.Rescaling.Nearest; 

                case RequestType.PreMultiplyAlpha:
                case RequestType.SwitchingChannels:
                case RequestType.Flipping:
                case RequestType.NormalMapGeneration:
                    return true;

                default:
                    return false;
            }
        }
Пример #54
0
 private TexImage Load(ITexLibrary library, string filePath)
 {
     var image = new TexImage();
     library.Execute(image, new LoadingRequest(filePath, false));
     image.Name = Path.GetFileName(filePath);
     image.CurrentLibrary = library;
     return image;
 }
Пример #55
0
 void PurgeBMP()
 {
     if (TexImage != null) TexImage.Dispose();
     TexImage = null;
 }
Пример #56
0
            public void PopulateBMP()
            {
                PurgeBMP();
                TexImage = new TexImage();
                TexImage.Load(PathManager.FullyQualify(Path));

                //TODO - try to autodetect a format (corona may need to manage palette size a little better)
                SetFormat(TextureFormat.Format4_I8);
            }
Пример #57
0
 public void Dispose()
 {
     if (TexImage != null) TexImage.Dispose();
     TexImage = null;
 }
Пример #58
0
        /// <summary>
        /// Updates the <see cref="TexImage"/> image with the native library data.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="libraryData">The library data.</param>
        private void UpdateImage(TexImage image, DxtTextureLibraryData libraryData)
        {
            int dataSize = 0;

            image.SubImageArray = new TexImage.SubImage[libraryData.DxtImages.Length];
            for (int i = 0; i < libraryData.DxtImages.Length; ++i)
            {
                image.SubImageArray[i] = new TexImage.SubImage();
                image.SubImageArray[i].Data = libraryData.DxtImages[i].pixels;
                image.SubImageArray[i].DataSize = libraryData.DxtImages[i].SlicePitch;
                image.SubImageArray[i].Width = libraryData.DxtImages[i].Width;
                image.SubImageArray[i].Height = libraryData.DxtImages[i].Height;
                image.SubImageArray[i].RowPitch = libraryData.DxtImages[i].RowPitch;
                image.SubImageArray[i].SlicePitch = libraryData.DxtImages[i].SlicePitch;
                dataSize += image.SubImageArray[i].SlicePitch;
            }

            image.Data = libraryData.DxtImages[0].pixels;
            image.DataSize = dataSize;
            image.Width = libraryData.Metadata.Width;
            image.Height = libraryData.Metadata.Height;
            image.Depth = libraryData.Metadata.Depth;
            image.RowPitch = libraryData.DxtImages[0].RowPitch;
            image.Format = (PixelFormat) libraryData.Metadata.format;
            image.MipmapCount = libraryData.Metadata.MipLevels;
            image.ArraySize = libraryData.Metadata.ArraySize;
            image.SlicePitch = libraryData.DxtImages[0].SlicePitch;
            image.OriginalAlphaDepth = Math.Min(image.OriginalAlphaDepth, image.Format.AlphaSizeInBits());
        }
Пример #59
0
        /// <summary>
        /// Premultiplies the alpha.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="libraryData">The library data.</param>
        public void PreMultiplyAlpha(TexImage image, DxtTextureLibraryData libraryData)
        {
            Log.Info("Premultiplying alpha ... ");

            ScratchImage scratchImage = new ScratchImage();

            HRESULT hr = Utilities.PremultiplyAlpha(libraryData.DxtImages, libraryData.DxtImages.Length, ref libraryData.Metadata, TEX_PREMULTIPLY_ALPHA_FLAGS.TEX_PMALPHA_DEFAULT, scratchImage);

            if (hr != HRESULT.S_OK)
            {
                Log.Error("Failed to premultiply the alpha : " + hr);
                throw new TextureToolsException("Failed to premultiply the alpha : " + hr);
            }

            // Freeing Memory
            if (image.DisposingLibrary != null) image.DisposingLibrary.Dispose(image);

            libraryData.Image = scratchImage;
            libraryData.Metadata = libraryData.Image.metadata;
            libraryData.DxtImages = libraryData.Image.GetImages();
            image.DisposingLibrary = this;

            UpdateImage(image, libraryData);
        }
Пример #60
0
        /// <summary>
        /// Generates the normal map.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="libraryData">The library data.</param>
        /// <param name="request">The request.</param>
        /// <exception cref="TexLibraryException">Failed to generate the normal map</exception>
        public void GenerateNormalMap(TexImage image, DxtTextureLibraryData libraryData, NormalMapGenerationRequest request)
        {
            Log.Info("Generating Normal Map ... ");

            ScratchImage scratchImage = new ScratchImage();

            HRESULT hr = Utilities.ComputeNormalMap(libraryData.DxtImages, libraryData.DxtImages.Length, ref libraryData.Metadata, CNMAP_FLAGS.CNMAP_CHANNEL_RED, request.Amplitude, DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM, scratchImage);

            if (hr != HRESULT.S_OK)
            {
                Log.Error("Failed to generate the normal map : " + hr);
                throw new TextureToolsException("Failed to generate the normal map : " + hr);
            }

            // Creating new TexImage with the normal map data.
            request.NormalMap = new TexImage();
            DxtTextureLibraryData normalMapLibraryData = new DxtTextureLibraryData();
            request.NormalMap.LibraryData[this] = normalMapLibraryData;
            normalMapLibraryData.DxtImages = scratchImage.GetImages();
            normalMapLibraryData.Metadata = scratchImage.metadata;
            normalMapLibraryData.Image = scratchImage;

            UpdateImage(request.NormalMap, normalMapLibraryData);
            request.NormalMap.DisposingLibrary = this;
        }