예제 #1
0
        private void HandleResizing(TextureTool texTool, TexImage image)
        {
            if (Width != null && Height != null)
            {
                bool targetInPercent;
                var  width  = ParsePixelSize(Width, out targetInPercent);
                var  height = ParsePixelSize(Height, out targetInPercent);

                if (targetInPercent)
                {
                    texTool.Rescale(image, width / 100f, height / 100f, RescalingFilter);
                }
                else
                {
                    texTool.Resize(image, width, height, RescalingFilter);
                }
            }
            else if (Width != null && Height == null)
            {
                bool targetInPercent;
                var  width = ParsePixelSize(Width, out targetInPercent);

                if (targetInPercent)
                {
                    texTool.Rescale(image, width / 100f, 1, RescalingFilter);
                }
                else
                {
                    texTool.Resize(image, width, image.Height, RescalingFilter);
                }
            }
            else if (Width == null && Height != null)
            {
                bool targetInPercent;
                var  height = ParsePixelSize(Height, out targetInPercent);

                if (targetInPercent)
                {
                    texTool.Rescale(image, 1, height / 100f, RescalingFilter);
                }
                else
                {
                    texTool.Resize(image, image.Width, height, RescalingFilter);
                }
            }
        }
예제 #2
0
파일: TexImage.cs 프로젝트: vvvv/stride
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj))
            {
                return(false);
            }
            if (ReferenceEquals(this, obj))
            {
                return(true);
            }
            if (obj.GetType() != this.GetType())
            {
                return(false);
            }

            TexImage img = (TexImage)obj;

            if (SubImageArray.Length != img.SubImageArray.Length)
            {
                return(false);
            }
            for (int i = 0; i < SubImageArray.Length; ++i)
            {
                if (!(SubImageArray[i].DataSize == img.SubImageArray[i].DataSize &&
                      SubImageArray[i].Width == img.SubImageArray[i].Width &&
                      SubImageArray[i].Height == img.SubImageArray[i].Height &&
                      SubImageArray[i].RowPitch == img.SubImageArray[i].RowPitch &&
                      SubImageArray[i].SlicePitch == img.SubImageArray[i].SlicePitch))
                {
                    return(false);
                }
            }

            return(Width == img.Width &&
                   Height == img.Height &&
                   Depth == img.Depth &&
                   Format == img.Format &&
                   MipmapCount == img.MipmapCount &&
                   ArraySize == img.ArraySize &&
                   FaceCount == img.FaceCount &&
                   Dimension == img.Dimension &&
                   DataSize == img.DataSize &&
                   RowPitch == img.RowPitch &&
                   SlicePitch == img.SlicePitch);
        }
예제 #3
0
        public void Run(string[] args)
        {
            // Print the exe header
            PrintHeader();

            foreach (String s in args)
            {
                Console.WriteLine(s);
            }

            Console.WriteLine("");

            // Parse the command line
            if (!ParseCommandLine(args))
            {
                Environment.Exit(-1);
            }

            // Check if we have a pattern
            InputPatternFile = Path.Combine(Environment.CurrentDirectory, InputPatternFile);

            int  indexOfPattern = InputPatternFile.IndexOf('*');
            bool isPattern      = indexOfPattern >= 0;

            if (!isPattern)
            {
                InputPatternFile = Path.GetFullPath(InputPatternFile);
            }
            OutputFileOrDirectory = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, OutputFileOrDirectory));

            var inputOutputFiles = new List <Tuple <string, string> >();

            if (isPattern)
            {
                if (!Directory.Exists(OutputFileOrDirectory))
                {
                    Directory.CreateDirectory(OutputFileOrDirectory);
                }

                var directory = InputPatternFile.Substring(0, indexOfPattern);
                var pattern   = InputPatternFile.Substring(indexOfPattern, InputPatternFile.Length - indexOfPattern);

                foreach (var file in Directory.EnumerateFiles(directory, pattern, SearchOption.AllDirectories))
                {
                    var outputFile = Path.Combine(OutputFileOrDirectory, file.Substring(directory.Length, file.Length - directory.Length));

                    bool excludeFile = false;
                    foreach (var excludeItem in ExcludeList)
                    {
                        if (file.IndexOf(excludeItem, StringComparison.InvariantCultureIgnoreCase) >= 0)
                        {
                            excludeFile = true;
                            break;
                        }
                    }

                    if (!excludeFile)
                    {
                        inputOutputFiles.Add(new Tuple <string, string>(file, outputFile));
                    }
                }
            }
            else
            {
                inputOutputFiles.Add(new Tuple <string, string>(InputPatternFile, OutputFileOrDirectory));
            }

            var texTool = new TextureTool();

            GlobalLogger.GlobalMessageLogged += new ConsoleLogListener();

            bool hasErrors = false;

            foreach (var inputOutputFile in inputOutputFiles)
            {
                var inputFile  = inputOutputFile.Item1;
                var outputFile = inputOutputFile.Item2;

                TexImage image = null;
                try
                {
                    image = texTool.Load(inputFile, IsSRgb);

                    HandleResizing(texTool, image);

                    if (FlipOrientation.HasValue)
                    {
                        texTool.Flip(image, FlipOrientation.Value);
                    }

                    if (MipMap)
                    {
                        texTool.GenerateMipMaps(image, MipMapFilter);
                    }

                    if (PreMulAlpha)
                    {
                        texTool.PreMultiplyAlpha(image);
                    }

                    if (TextureFormat.HasValue)
                    {
                        texTool.Compress(image, TextureFormat.Value);
                    }

                    texTool.Save(image, outputFile, MipMapSize);
                }
                catch (TextureToolsException)
                {
                    hasErrors = true;
                }
                finally
                {
                    if (image != null)
                    {
                        image.Dispose();
                    }
                }
            }

            texTool.Dispose();

            if (hasErrors)
            {
                //Environment.Exit(-1);
            }
        }
예제 #4
0
파일: TexImage.cs 프로젝트: vvvv/stride
        /// <summary>
        /// Creates a new object that is a copy of the current instance.
        /// </summary>
        /// <param name="CopyMemory">if set to <c>true</c> [copy memory], it is a DEEP copy.</param>
        /// <returns>
        /// A new object that is a copy of this instance.
        /// </returns>
        virtual public Object Clone(bool CopyMemory)
        {
            if (this.CurrentLibrary != null)
            {
                this.CurrentLibrary.EndLibrary(this); this.CurrentLibrary = null;
            }

            TexImage newTex = new TexImage()
            {
                // Basic infos
                Data               = CopyMemory?System.Runtime.InteropServices.Marshal.AllocHGlobal(this.DataSize):this.Data,
                DataSize           = this.DataSize,
                Width              = this.Width,
                Height             = this.Height,
                Depth              = this.Depth,
                RowPitch           = this.RowPitch,
                SlicePitch         = this.SlicePitch,
                Format             = this.Format,
                OriginalAlphaDepth = this.OriginalAlphaDepth,

                // Texture infos
                ArraySize     = this.ArraySize,
                FaceCount     = this.FaceCount,
                MipmapCount   = this.MipmapCount,
                SubImageArray = new SubImage[this.SubImageArray.Length],
                Dimension     = this.Dimension,
                Name          = this.Name,

                // ITexLibrary Data
                DisposingLibrary = this.DisposingLibrary,
                CurrentLibrary   = this.CurrentLibrary,
                LibraryData      = new Dictionary <ITexLibrary, ITextureLibraryData>(),

                // Disposing info
                Disposed = this.Disposed,
            };

            if (CopyMemory)
            {
                Utilities.CopyMemory(newTex.Data, this.Data, this.DataSize);
            }

            int offset = 0;

            for (int i = 0; i < this.SubImageArray.Length; ++i)
            {
                newTex.SubImageArray[i] = this.SubImageArray[i];
                if (CopyMemory)
                {
                    newTex.SubImageArray[i].Data = new IntPtr(newTex.Data.ToInt64() + offset);
                }
                offset += newTex.SubImageArray[i].DataSize;
            }

            if (CopyMemory && this.DisposingLibrary != null)
            {
                this.DisposingLibrary.StartLibrary(newTex);
            }
            else if (!CopyMemory)
            {
                newTex.DisposingLibrary = null;
            }

            return(newTex);
        }