Exemplo n.º 1
0
        public static void PlugOneSideHoles(OptimizedImgParams indices, double allowedHoleHeight, MinXOrMaxXEnum minXOrMaxXEnum)
        {
            //create a new set of points that will be modified using the plug hole logic
            var points            = new List <Point>();
            var xLimitsAtYIndices = indices.XLimitsAtYIndices;

            for (var y = 0; y < xLimitsAtYIndices.Length; y++)
            {
                var xLimits = xLimitsAtYIndices[y];
                if (xLimits.Width <= 0)
                {
                    continue;
                }

                int x;
                switch (minXOrMaxXEnum)
                {
                case MinXOrMaxXEnum.MinX:
                    x = xLimits.Min;
                    break;

                case MinXOrMaxXEnum.MaxX:
                default:
                    x = xLimits.Max;
                    break;
                }
                var point = new Point(x, y);
                points.Add(point);
            }

            PlugHolesRepeatedly(points, allowedHoleHeight, minXOrMaxXEnum);

            ModifyXValuesBasedOnNewPoints(xLimitsAtYIndices, points, minXOrMaxXEnum);
        }
Exemplo n.º 2
0
        /// <summary>
        /// saves modified individual textures to separate files in the provided folder location
        /// helps in debugging
        /// </summary>
        /// <param name="optimizedImgParams"></param>
        /// <param name="img"></param>
        private static void DebugSaveIndicesForImageFile(OptimizedImgParams optimizedImgParams, AddTexImageInfo img)
        {
            if (string.IsNullOrWhiteSpace(DebugFolderLocation))
            {
                return;
            }

            var sourceBitmap = img.ImageBitmap;
            var debugImage   = new Bitmap(sourceBitmap.Width, sourceBitmap.Height);

            for (var y = 0; y < optimizedImgParams.XLimitsAtYIndices.Length; y++)
            {
                for (var x = optimizedImgParams.XLimitsAtYIndices[y].Min; x <= optimizedImgParams.XLimitsAtYIndices[y].Max; x++)
                {
                    var pixelColor = sourceBitmap.GetPixel(x, y);
                    debugImage.SetPixel(x, y, pixelColor);
                }
            }
            debugImage.Save(string.Format(@"{0}\ImgWidthOptimizer_{1}.png", DebugFolderLocation, DateTime.Now.Ticks));
        }
Exemplo n.º 3
0
        /// <summary>
        /// initializes all indices to min max 0
        /// </summary>
        /// <param name="height"></param>
        /// <param name="noOfImages"></param>
        /// <returns></returns>
        private static OptimizedImgParams[] GetInitializedXLimitsAtYIndices(int height, int noOfImages)
        {
            var xLimitsAtYIndices = new OptimizedImgParams[noOfImages];

            for (var imgIndex = 0; imgIndex < noOfImages; imgIndex++)
            {
                xLimitsAtYIndices[imgIndex] = new OptimizedImgParams
                {
                    XLimitsAtYIndices = new MinAndMaxIndices[height]
                };
                //initialize to zero
                for (var y = 0; y < height; y++)
                {
                    xLimitsAtYIndices[imgIndex].XLimitsAtYIndices[y] = new MinAndMaxIndices {
                        Min = 0, Max = 0, InitializedToZeroZero = true
                    }
                }
                ;
            }
            return(xLimitsAtYIndices);
        }
Exemplo n.º 4
0
 public static void PlugSideHoles(OptimizedImgParams indices, double allowedHoleHeight)
 {
     PlugOneSideHoles(indices, allowedHoleHeight, MinXOrMaxXEnum.MinX);
     PlugOneSideHoles(indices, allowedHoleHeight, MinXOrMaxXEnum.MaxX);
 }