/// gets suitability rating for format and takes preferred format into account
        public int GetFormatRating(GliFormat format, GliFormat preferredFormat)
        {
            var  rating             = GetFormatRating(format);
            var  preferredPixelType = preferredFormat.GetDataType();
            var  pixelType          = format.GetDataType();
            bool isSrgb             = preferredPixelType == PixelDataType.Srgb;
            bool hasRgb             = preferredFormat.HasRgb();

            if (format == preferredFormat)
            {
                rating += 150;
            }

            // keep srgb specifier
            if (isSrgb == (format.GetDataType() == PixelDataType.Srgb))
            {
                rating += 200;
            }
            else
            {
                rating -= 200;
            }

            // small bonus for same datatype
            if (preferredPixelType == pixelType)
            {
                rating += 5;
            }

            // small bonus for rgb match
            if (hasRgb == format.HasRgb())
            {
                rating += 15;
            }

            // small bonus for high precision
            if (!preferredFormat.IsLessThan8Bit() && !format.IsLessThan8Bit())
            {
                rating += 20;
            }

            // small bonus for kept compression
            if (preferredFormat.IsCompressed() && format.IsCompressed())
            {
                rating += 10;
            }

            return(rating);
        }
Exemple #2
0
        private static bool IsIntegerPrecisionFormat(GliFormat format)
        {
            switch (format.GetDataType())
            {
            case PixelDataType.SInt:
            case PixelDataType.UInt:
            case PixelDataType.SScaled:
            case PixelDataType.UScaled:
                return(true);
            }

            return(false);
        }
Exemple #3
0
        // gets a suitability rating for the format based on the statistic values
        public int GetFormatRating(GliFormat format)
        {
            const int alphaMissWeight  = 1000; // penalty if alpha channel is required but missing
            const int alphaMatchWeight = 5;    // bonus for same alpha state
            const int signWeight       = 10;
            const int unormWeight      = 300;

            // determine basic properties of image
            bool hasAlpha  = HasAlpha;
            bool isUnormed = Average.Min >= 0.0f && Average.Max <= 1.0f &&
                             Alpha.Min >= 0.0f && Alpha.Max <= 1.0f;
            bool isSigned = Average.Min < 0.0f;

            int rating = 0;

            // is alpha required?
            if (hasAlpha && !format.HasAlpha())
            {
                rating -= alphaMissWeight; // alpha should be present if image needs alpha
            }
            else if (hasAlpha == format.HasAlpha())
            {
                rating += alphaMatchWeight; // alpha state matching
            }
            // is a signed format required?
            var pixelType = format.GetDataType();

            if (isSigned && !pixelType.IsSigned())
            {
                rating -= signWeight; // signed format is required
            }
            else if (isSigned == pixelType.IsSigned())
            {
                rating += signWeight;
            }

            // range 0 1?
            if (!isUnormed && pixelType == PixelDataType.UNorm) // unorm is not sufficient
            {
                rating -= unormWeight;
            }
            else if (!isUnormed && pixelType == PixelDataType.Srgb) // maybe tonemapping to srgb? better than unorm probably
            {
                rating -= unormWeight / 10;
            }

            //else if (isUnormed == pixelType.IsUnormed())
            //    rating += unormWeight;

            return(rating);
        }
Exemple #4
0
        /// gets suitability rating for format and takes preferred format into account
        public int GetFormatRating(GliFormat format, GliFormat preferredFormat)
        {
            var  rating             = GetFormatRating(format);
            var  preferredPixelType = preferredFormat.GetDataType();
            var  pixelType          = format.GetDataType();
            bool isSrgb             = preferredPixelType == PixelDataType.Srgb;
            bool hasRgb             = preferredFormat.HasRgb();

            if (format == preferredFormat)
            {
                rating += 150;
            }

            // keep srgb specifier
            if (isSrgb == (pixelType == PixelDataType.Srgb))
            {
                rating += 200;
            }
            else
            {
                // prefer srgb formats over unorm etc. when converting from hdr to ldr
                if (!preferredFormat.IsAtMost8bit() && !preferredPixelType.IsUnormed() && pixelType == PixelDataType.Srgb)
                {
                    rating -= 50;
                }
                else
                {
                    rating -= 200;
                }
            }

            // small bonus for same datatype
            if (preferredPixelType == pixelType)
            {
                rating += 5;
            }

            // small bonus for rgb match
            if (hasRgb == format.HasRgb())
            {
                rating += 15;
            }

            // small bonus for high precision
            if (!preferredFormat.IsLessThan8Bit() && !format.IsLessThan8Bit())
            {
                rating += 20;
            }

            // small bonus for kept compression
            if (preferredFormat.IsCompressed() && format.IsCompressed())
            {
                rating += 10;
            }

            // try to keep hdr formats
            if (!preferredFormat.IsAtMost8bit() && !format.IsAtMost8bit())
            {
                // keep unorm property
                if (preferredPixelType.IsUnormed() == pixelType.IsUnormed())
                {
                    rating += 50;
                }
            }



            return(rating);
        }
Exemple #5
0
        public ExportViewModel(ModelsEx models, string extension, GliFormat preferredFormat, string filename, bool is3D, DefaultStatistics stats)
        {
            this.models                = models;
            this.extension             = extension;
            this.filename              = filename;
            this.is3D                  = is3D;
            this.usedFormat            = models.Export.Formats.First(fmt => fmt.Extension == extension);
            models.Display.IsExporting = true;
            Quality = models.Settings.LastQuality;

            // init layers
            for (var i = 0; i < models.Images.NumLayers; ++i)
            {
                AvailableLayers.Add(new ListItemViewModel <int>
                {
                    Cargo = i,
                    Name  = "Layer " + i
                });
            }
            selectedLayer = AvailableLayers[models.Export.Layer];
            Debug.Assert(selectedLayer.Cargo == models.Export.Layer);

            // init mipmaps
            for (var i = 0; i < models.Images.NumMipmaps; ++i)
            {
                AvailableMipmaps.Add(new ListItemViewModel <int>
                {
                    Cargo = i,
                    Name  = "Mipmap " + i
                });
            }
            selectedMipmap = AvailableMipmaps[models.Export.Mipmap];
            Debug.Assert(selectedMipmap.Cargo == models.Export.Mipmap);

            // all layer option for ktx and dds
            if (models.Images.NumLayers > 1 && (extension == "ktx" || extension == "dds"))
            {
                AvailableLayers.Add(new ListItemViewModel <int>
                {
                    Cargo = -1,
                    Name  = "All Layer"
                });
                selectedLayer       = AvailableLayers.Last();
                models.Export.Layer = selectedLayer.Cargo;
            }

            // all mipmaps option for ktx and dds
            if (models.Images.NumMipmaps > 1 && (extension == "ktx" || extension == "dds"))
            {
                AvailableMipmaps.Add(new ListItemViewModel <int>
                {
                    Cargo = -1,
                    Name  = "All Mipmaps"
                });
                selectedMipmap       = AvailableMipmaps.Last();
                models.Export.Mipmap = selectedMipmap.Cargo;
            }

            // init available pixel data types
            var usedPixelTypes = new SortedSet <PixelDataType>();

            foreach (var format in usedFormat.Formats)
            {
                // exclude some formats for 3d export
                if (is3D && format.IsExcludedFrom3DExport())
                {
                    continue;
                }

                allFormats.Add(new ListItemViewModel <GliFormat>
                {
                    Cargo   = format,
                    Name    = format.ToString(),
                    ToolTip = format.GetDescription()
                });
                formatRatings.Add(stats.GetFormatRating(format, preferredFormat));
                usedPixelTypes.Add(format.GetDataType());
            }

            if (usedPixelTypes.Count > 1)
            {
                AvailableDataTypes.Add(new ListItemViewModel <PixelDataType>
                {
                    Cargo = PixelDataType.Undefined,
                    Name  = "All"
                });
            }
            var preferredPixelType = preferredFormat.GetDataType();

            foreach (var usedPixelType in usedPixelTypes)
            {
                AvailableDataTypes.Add(new ListItemViewModel <PixelDataType>
                {
                    Cargo   = usedPixelType,
                    Name    = usedPixelType.ToString(),
                    ToolTip = usedPixelType.GetDescription()
                });
                if (usedPixelType == preferredPixelType)
                {
                    SelectedDataType = AvailableDataTypes.Last();
                }
            }

            if (SelectedDataType == null)
            {
                SelectedDataType = AvailableDataTypes[0];
            }

            // assert that those were were set by SelectedDataType
            Debug.Assert(AvailableFormats != null);
            Debug.Assert(SelectedFormat != null);

            // enable quality
            if (extension == "jpg")
            {
                hasQualityValue       = true;
                nonSrgbExportWarnings = true;
            }
            else if (extension == "bmp")
            {
                nonSrgbExportWarnings = true;
            }
            else
            {
                SetKtxDdsQuality();
            }

            models.Export.PropertyChanged += ExportOnPropertyChanged;

            if (models.Export.CropEndX == 0 && models.Export.CropEndY == 0 && models.Export.CropEndZ == 0)
            {
                // assume cropping was not set
                SetMaxCropping();
            }
        }