Example #1
0
        /// <summary> Creates a new writer to the specified File object, to write data from
        /// the specified component.
        ///
        /// <p>The three components that will be written as R, G and B must be
        /// specified through the b1, b2 and b3 arguments.</p>
        ///
        /// </summary>
        /// <param name="out">The file where to write the data
        ///
        /// </param>
        /// <param name="imgSrc">The source from where to get the image data to write.
        ///
        /// </param>
        /// <param name="n1">The index of the first component from where to get the data,
        /// that will be written as the red channel.
        ///
        /// </param>
        /// <param name="n2">The index of the second component from where to get the data,
        /// that will be written as the green channel.
        ///
        /// </param>
        /// <param name="n3">The index of the third component from where to get the data,
        /// that will be written as the green channel.
        ///
        /// </param>
        /// <seealso cref="DataBlk">
        ///
        /// </seealso>
        public ImgWriterPPM(IFileInfo out_Renamed, BlkImgDataSrc imgSrc, int n1, int n2, int n3)
        {
            // Check that imgSrc is of the correct type
            // Check that the component index is valid
            if ((n1 < 0) || (n1 >= imgSrc.NumComps) || (n2 < 0) || (n2 >= imgSrc.NumComps) || (n3 < 0) || (n3 >= imgSrc.NumComps) || (imgSrc.getNomRangeBits(n1) > 8) || (imgSrc.getNomRangeBits(n2) > 8) || (imgSrc.getNomRangeBits(n3) > 8))
            {
                throw new System.ArgumentException("Invalid component indexes");
            }
            // Initialize
            w = imgSrc.getCompImgWidth(n1);
            h = imgSrc.getCompImgHeight(n1);
            // Check that all components have same width and height
            if (w != imgSrc.getCompImgWidth(n2) || w != imgSrc.getCompImgWidth(n3) || h != imgSrc.getCompImgHeight(n2) || h != imgSrc.getCompImgHeight(n3))
            {
                throw new System.ArgumentException("All components must have the" + " same dimensions and no" + " subsampling");
            }
            w = imgSrc.ImgWidth;
            h = imgSrc.ImgHeight;

            // Continue initialization
            if (out_Renamed.Exists && !out_Renamed.Delete())
            {
                throw new System.IO.IOException("Could not reset file");
            }
            this.out_Renamed = SupportClass.RandomAccessFileSupport.CreateRandomAccessFile(out_Renamed, "rw");
            src    = imgSrc;
            cps[0] = n1;
            cps[1] = n2;
            cps[2] = n3;
            fb[0]  = imgSrc.getFixedPoint(n1);
            fb[1]  = imgSrc.getFixedPoint(n2);
            fb[2]  = imgSrc.getFixedPoint(n3);

            levShift[0] = 1 << (imgSrc.getNomRangeBits(n1) - 1);
            levShift[1] = 1 << (imgSrc.getNomRangeBits(n2) - 1);
            levShift[2] = 1 << (imgSrc.getNomRangeBits(n3) - 1);

            writeHeaderInfo();
        }
Example #2
0
        /// <summary> Creates a new writer to the specified File object, to write data from
        /// the specified component.
        /// 
        /// <p>The three components that will be written as R, G and B must be
        /// specified through the b1, b2 and b3 arguments.</p>
        /// 
        /// </summary>
        /// <param name="out">The file where to write the data
        /// 
        /// </param>
        /// <param name="imgSrc">The source from where to get the image data to write.
        /// 
        /// </param>
        /// <param name="n1">The index of the first component from where to get the data,
        /// that will be written as the red channel.
        /// 
        /// </param>
        /// <param name="n2">The index of the second component from where to get the data,
        /// that will be written as the green channel.
        /// 
        /// </param>
        /// <param name="n3">The index of the third component from where to get the data,
        /// that will be written as the green channel.
        /// 
        /// </param>
        /// <seealso cref="DataBlk">
        /// 
        /// </seealso>
        public ImgWriterPPM(IFileInfo out_Renamed, BlkImgDataSrc imgSrc, int n1, int n2, int n3)
        {
            // Check that imgSrc is of the correct type
            // Check that the component index is valid
            if ((n1 < 0) || (n1 >= imgSrc.NumComps) || (n2 < 0) || (n2 >= imgSrc.NumComps) || (n3 < 0) || (n3 >= imgSrc.NumComps) || (imgSrc.getNomRangeBits(n1) > 8) || (imgSrc.getNomRangeBits(n2) > 8) || (imgSrc.getNomRangeBits(n3) > 8))
            {
                throw new System.ArgumentException("Invalid component indexes");
            }
            // Initialize
            w = imgSrc.getCompImgWidth(n1);
            h = imgSrc.getCompImgHeight(n1);
            // Check that all components have same width and height
            if (w != imgSrc.getCompImgWidth(n2) || w != imgSrc.getCompImgWidth(n3) || h != imgSrc.getCompImgHeight(n2) || h != imgSrc.getCompImgHeight(n3))
            {
                throw new System.ArgumentException("All components must have the" + " same dimensions and no" + " subsampling");
            }
            w = imgSrc.ImgWidth;
            h = imgSrc.ImgHeight;

            // Continue initialization
            if (out_Renamed.Exists && !out_Renamed.Delete())
            {
                throw new System.IO.IOException("Could not reset file");
            }
            this.out_Renamed = SupportClass.RandomAccessFileSupport.CreateRandomAccessFile(out_Renamed, "rw");
            src = imgSrc;
            cps[0] = n1;
            cps[1] = n2;
            cps[2] = n3;
            fb[0] = imgSrc.getFixedPoint(n1);
            fb[1] = imgSrc.getFixedPoint(n2);
            fb[2] = imgSrc.getFixedPoint(n3);

            levShift[0] = 1 << (imgSrc.getNomRangeBits(n1) - 1);
            levShift[1] = 1 << (imgSrc.getNomRangeBits(n2) - 1);
            levShift[2] = 1 << (imgSrc.getNomRangeBits(n3) - 1);

            writeHeaderInfo();
        }