Ejemplo n.º 1
0
 public CMYKbbImage()
 {
     cyan    = new BarebonesImage();
     magenta = new BarebonesImage();
     yellow  = new BarebonesImage();
     black   = new BarebonesImage();
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Takes two BBImages and merges them into a single BBImage.
        /// </summary>
        /// <param name="Left">The BBImage that will be to the left in the new BBImage.</param>
        /// <param name="Right">The BBImage that will be to the right in the new BBImage.</param>
        /// <returns>True upon completion</returns>
        public bool Merge(BarebonesImage Left, BarebonesImage Right)
        {
            //Width of the merged image is the widths of both the input images.
            Width = Left.Width + Right.Width;

            //Padding for width is recalculated.
            WidthWithPad = Width + CalculatePad(Width);

            //Sets the height of the merged image to the tallest of the input images.
            if (Left.Height > Right.Height)
            {
                Height = Left.Height;
            }
            else if (Left.Height < Right.Height)
            {
                Height = Right.Height;
            }
            else
            {
                Height = Left.Height;
            }

            // The image is offset vertically so it ends up in the middle.
            int verticalOffset = (Height - Left.Height) / 2;

            this.Insert(Left, verticalOffset, 0);

            //Offset recalculated for the right image.
            verticalOffset = (Height - Right.Height) / 2;
            this.Insert(Right, verticalOffset, 0);

            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Inserts an BBImage into this BBImage.
        /// </summary>
        /// <param name="insertImage">The BBImage that will be inserted into this BBImage.</param>
        /// <param name="x">The place where the image will be inserted.</param>
        /// <param name="y">The place where the image will be inserted.</param>
        /// <returns>True upon completion</returns>
        public bool Insert(BarebonesImage insertImage, int x, int y)
        {
            /* Loop through all the pixles in the image to be inserted.
             * Offset it vertically so it ends up in the right position*/

            for (int i = 0; i < insertImage.Width; i++)
            {
                for (int j = 0; j < insertImage.Height; j++)
                {
                    SetPixel(i + x, j + y, insertImage.GetPixel(i, j));
                }
            }

            return(true);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Method is called to read a tiff image
        /// </summary>
        /// <param name="fileToRead">The file that will be read including the path.</param>
        /// <returns>A BarebonesImage.</returns>
        public BarebonesImage ReadATIFF(string fileToRead)
        {
            //Overrides the error handler so that it won't spit out a bunch of warnings.
            BBErrorHandler bbErrorHandler = new BBErrorHandler();

            Tiff.SetErrorHandler(bbErrorHandler);

            Tiff           inputImage = Tiff.Open(fileToRead, "r");
            BarebonesImage bbImage    = new BarebonesImage
            {
                Width  = inputImage.GetField(TiffTag.IMAGEWIDTH)[0].ToInt(),
                Height = inputImage.GetField(TiffTag.IMAGELENGTH)[0].ToInt()
            };

            #region Check that the file is of the correct format. Lots of boring code.
            int samplesPerPixel = inputImage.GetField(TiffTag.SAMPLESPERPIXEL)[0].ToInt();
            if (samplesPerPixel != 1)
            {
                throw new ArgumentException("samplesPerPixel must be 1");
            }

            int bitsPerSample = inputImage.GetField(TiffTag.BITSPERSAMPLE)[0].ToInt();
            if (bitsPerSample != 1)
            {
                throw new ArgumentException("bitsPerSample must be 1");
            }

            string photo = inputImage.GetField(TiffTag.PHOTOMETRIC)[0].ToString();
            if (string.Compare(photo, @"MINISWHITE") != 0)
            {
                throw new ArgumentException("photo must be MINISWHITE");
            }

            //string compression = inputImage.GetField(TiffTag.COMPRESSION)[0].ToString();
            // if (string.Compare(compression, @"CCITT_T6") != 0)
            //      throw new ArgumentException("Compression must be CCITT_T6");

            string plane = inputImage.GetField(TiffTag.PLANARCONFIG)[0].ToString();
            if (string.Compare(plane, @"CONTIG") != 0)
            {
                throw new ArgumentException("plane must be CONTIG");
            }

            string resUnit = inputImage.GetField(TiffTag.RESOLUTIONUNIT)[0].ToString();
            if (string.Compare(resUnit, @"INCH") != 0)
            {
                throw new ArgumentException("resUnit must be INCH");
            }

            #endregion

            //Images are padded with zeros so the images consist of whole bytes as per the TIF specification.
            bbImage.WidthWithPad = bbImage.Width + bbImage.CalculatePad(bbImage.Width);

            byte[] ImageByteStream = new byte[bbImage.WidthWithPad / 8 * bbImage.Height];

            // Read for multiple strips
            int stripSize   = inputImage.StripSize();
            int stripMax    = inputImage.NumberOfStrips();
            int imageOffset = 0;

            //This ImageMatrix is where the data of the image will be stored in the Barebones Image.
            bbImage.ImageMatrix = new List <List <byte> >();

            // Goes through all the strips and put them into a single bytestreame.
            for (int stripCount = 0; stripCount < stripMax; stripCount++)
            {
                int result = inputImage.ReadEncodedStrip(stripCount, ImageByteStream, imageOffset, stripSize);
                if (result == -1)
                {
                    Console.Error.WriteLine("Read error on input strip number {0}", stripCount);
                }

                imageOffset += result;
            }

            //Convert the array to a list, chop it up and insert it into the ImageMatrix of the Barebones Image.
            List <byte> ImageByteList = ImageByteStream.ToList();
            for (int i = 0; i < ImageByteList.Count; i += bbImage.WidthWithPad / 8)
            {
                bbImage.ImageMatrix.Add(ImageByteList.GetRange(i, Math.Min(bbImage.WidthWithPad / 8, ImageByteList.Count - i)));
            }


            inputImage.Close();

            return(bbImage);
        }