Пример #1
0
        static Histogram GetHistogramFromParameter(string param)
        {
            var sanitizedParam = param.Replace("\\", "/");
            var idb            = indexes.FirstOrDefault(db => db.ContainsAsset(sanitizedParam));

            if (idb != null)
            {
                var imageData = idb.GetImageDataFromPath(sanitizedParam);
                return(imageData.histogram);
            }

            if (!File.Exists(sanitizedParam))
            {
                return(null);
            }

            var texture = AssetDatabase.LoadMainAssetAtPath(sanitizedParam) as Texture2D;

            if (texture == null)
            {
                return(null);
            }

            Color32[] pixels;
            if (texture.isReadable)
            {
                pixels = texture.GetPixels32();
            }
            else
            {
                var copy = TextureUtils.CopyTextureReadable(texture, texture.width, texture.height);
                pixels = copy.GetPixels32();
            }
            var histogram = new Histogram();

            ImageUtils.ComputeHistogram(pixels, histogram);
            return(histogram);
        }