示例#1
0
        /// <summary>
        /// Moves the register marks a certain amount up or down the image.
        /// </summary>
        /// <param name="inputImage">Image whose registermarks should be removed.</param>
        /// <param name="dirPaths">Paths of the program.</param>
        /// <param name="regMarkCoord">Coordinates of the register marks.</param>
        /// <returns>An image where the register marks have been removed.</returns>
        private BarebonesImage RemoveRegisterMarks(BarebonesImage inputImage, DirPaths dirPaths, RegisterMarksCoordinates regMarkCoord)
        {
            BarebonesImage blankRegMark = new BarebonesImage();

            string pathAndFile = Path.Combine(dirPaths.regMarks, dirPaths.blankRegMark);

            blankRegMark = blankRegMark.ReadATIFF(pathAndFile);

            //Cover the old register marks with white pixels.
            inputImage.Insert(blankRegMark, regMarkCoord.lead.Item1, regMarkCoord.lead.Item2);
            inputImage.Insert(blankRegMark, regMarkCoord.trail.Item1, regMarkCoord.trail.Item2);

            return(inputImage);
        }
示例#2
0
        /// <summary>
        /// Inserts register marks to their coordinates.
        /// </summary>
        /// <param name="inputImage">Image whose registermarks should be removed.</param>
        /// <param name="dirPaths">Paths of the program.</param>
        /// <param name="regMarkCoord">Coordinates of the register marks.</param>
        /// <returns>An image where the register marks have been inserted into their positions.</returns>
        private BarebonesImage InsertRegisterMarks(BarebonesImage inputImage, DirPaths dirPaths, RegisterMarksCoordinates regMarkCoord)
        {
            BarebonesImage leadRegMark  = new BarebonesImage();
            BarebonesImage trailRegMark = new BarebonesImage();

            string pathAndFile = Path.Combine(dirPaths.regMarks, dirPaths.leadRegMark);

            leadRegMark = leadRegMark.ReadATIFF(pathAndFile);

            pathAndFile  = Path.Combine(dirPaths.regMarks, dirPaths.trailRegMark);
            trailRegMark = trailRegMark.ReadATIFF(pathAndFile);

            //Insert the register mark.
            inputImage.Insert(leadRegMark, regMarkCoord.lead.Item1, regMarkCoord.lead.Item2);
            inputImage.Insert(trailRegMark, regMarkCoord.trail.Item1, regMarkCoord.trail.Item2);

            return(inputImage);
        }
示例#3
0
        /// <summary>
        /// Changes a.TIF file differently depending on which group it belongs to
        /// based on a "zoneCylinder" code in its file name(as specified in OARconfig.txt).
        /// </summary>
        /// <param name = "fileToProcess" > The filename of the.TIF file to process, path not included.</param>
        /// <returns>True upon completion.</returns>
        internal bool Process(string fileTo)
        {
            BarebonesImage     processImage       = new BarebonesImage();
            ReadPressConfigXML readPressConfigXML = new ReadPressConfigXML();

            Console.WriteLine(DateTime.Now.ToString("yyyyMMdd HH:mm:ss") + " - Processing " + fileTo);

            #region parsing of the file name to get information of how to process the file
            string tower    = fileTo.Substring(parsingInfo.towerStart, parsingInfo.towerLength);
            string cylinder = fileTo.Substring(parsingInfo.cylinderStart, parsingInfo.cylinderLength);
            char   section  = fileTo.Substring(parsingInfo.sectionStart, parsingInfo.sectionLength)[0];
            string half     = fileTo.Substring(parsingInfo.halfStart, parsingInfo.halfLength);

            Console.WriteLine("Tower: " + tower);
            Console.WriteLine("Cylinder: " + cylinder);
            Console.WriteLine("Section: " + section);
            Console.WriteLine("Half: " + half);

            string rollPosition = readPressConfigXML.GetValue(tower, "rollPosition", dirPaths);

            if (!Int32.TryParse(cylinder, out int cylinderInt))
            {
                Console.WriteLine(cylinder + " is not a valid cylinder. Press any key to exit.");
                Console.ReadKey();
                Environment.Exit(0);
            }

            //Black isn't compensated as it is the reference.
            if (cylinderInt > 6)
            {
                Console.WriteLine(DateTime.Now.ToString("yyyyMMdd HH:mm:ss") + " - Processing of " + fileTo + " complete.");
                return(true);
            }

            //Get how many mm the image should be reduced with.
            string colour = CylinderToColour(cylinderInt);
            string fanOut = readPressConfigXML.GetValue(tower, "fanOut" + colour, dirPaths);

            if (!decimal.TryParse(fanOut, out decimal fanOutDecimal))
            {
                Console.WriteLine(fanOut + " is not a valid amount of milimeters. Format may be wrong(. instead of ,). Press any key to exit.");
                Console.ReadKey();
                Environment.Exit(0);
            }

            //No compensation so the method just returns.
            if (fanOutDecimal == 0)
            {
                Console.WriteLine(DateTime.Now.ToString("yyyyMMdd HH:mm:ss") + " - Processing of " + fileTo + " complete.");
                return(true);
            }
            #endregion

            string pathAndFileTo = Path.Combine(dirPaths.middle, fileTo);

            //Load the image that was moved from the source folder.
            processImage = processImage.ReadATIFF(pathAndFileTo);

            //Remove the register marks before it's resized since that's when you know where they are without having to calculate.
            processImage = RemoveRegisterMarks(processImage, dirPaths, regMarkCoord);

            int originalHeight = processImage.Height;

            //Scale is calculated based on how much fan-out there is to be compensated for.
            int scale = MMtoScale(fanOutDecimal, originalHeight, DPI);

            Console.WriteLine(@"'.--------------------------.'");
            Console.WriteLine("Fanout: " + fanOutDecimal);
            Console.WriteLine("Scale: " + scale);
            Console.WriteLine("Original height:" + originalHeight);

            Console.WriteLine("Original height in mm:" + ((decimal)originalHeight / (1200m * 0.0393701m)));

            //Image is resized.
            processImage.DownsizeHeight(scale);

            Console.WriteLine("Resized height:" + processImage.Height);
            Console.WriteLine("Resized height in mm:" + ((decimal)processImage.Height / (1200m * 0.0393701m)));


            //The image will be padded at different place depending on where in the machine the plate will go.
            string moveThisWay  = ComputeWhichWay(rollPosition, section, cylinderInt);
            int    moveThisMuch = ComputeHowMuch(rollPosition, section, fanOutDecimal, DPI);

            Console.WriteLine("Translation in pixels:" + moveThisMuch);
            Console.WriteLine("Translation in mm:" + ((decimal)moveThisMuch / (1200m * 0.0393701m)));
            Console.WriteLine(@"'.--------------------------.'");

            int sizeDifference = originalHeight - processImage.Height;

            switch (moveThisWay)
            {
            case "up":
                Console.WriteLine(moveThisWay);
                processImage.PadHeight(processImage.ImageMatrix.Count, sizeDifference);
                processImage.MoveImage(moveThisWay, moveThisMuch);
                break;

            case "down":
                Console.WriteLine(moveThisWay);
                processImage.PadHeight(0, sizeDifference);
                processImage.MoveImage(moveThisWay, moveThisMuch);
                break;

            case "middle":
                Console.WriteLine(moveThisWay);
                processImage.PadHeight(0, sizeDifference / 2);
                processImage.PadHeight(processImage.ImageMatrix.Count, sizeDifference / 2);
                break;

            default:
                Console.WriteLine(moveThisWay);
                processImage.PadHeight(0, sizeDifference / 2);
                processImage.PadHeight(processImage.ImageMatrix.Count, sizeDifference / 2);
                break;
            }

            //The register marks are put back at the place where they are supposed to be.
            processImage = InsertRegisterMarks(processImage, dirPaths, regMarkCoord);

            //Text is drawn onto the plate to indicate that it has been compensated.


            //Saves the result of the above processing.
            processImage.SaveAsTIFF(pathAndFileTo);

            Console.WriteLine(DateTime.Now.ToString("yyyyMMdd HH:mm:ss") + " - Processing of " + fileTo + " complete.");

            return(true);
        }