Example #1
0
        /// <summary>
        /// Prepares the encoder part of the codec for a encoding.
        /// </summary>
        /// <param name="plane">The zero-based sample plane index.</param>
        /// <returns>
        /// 	<c>true</c> if this codec successfully prepared its encoder part and ready
        /// to encode data; otherwise, <c>false</c>.
        /// </returns>
        /// <remarks>
        /// 	<b>PreEncode</b> is called after <see cref="SetupEncode"/> and before encoding.
        /// </remarks>
        public override bool PreEncode(short plane)
        {
            m_bit = 8;
            m_data = 0;
            m_encoder = Fax3Encoder.useFax1DEncoder;

            /*
            * This is necessary for Group 4; otherwise it isn't
            * needed because the first scanline of each strip ends
            * up being copied into the refline.
            */
            if (m_refline != null)
                Array.Clear(m_refline, 0, m_refline.Length);

            if (is2DEncoding())
            {
                float res = m_tif.m_dir.td_yresolution;
                /*
                * The CCITT spec says that when doing 2d encoding, you
                * should only do it on K consecutive scanlines, where K
                * depends on the resolution of the image being encoded
                * (2 for <= 200 lpi, 4 for > 200 lpi).  Since the directory
                * code initializes td_yresolution to 0, this code will
                * select a K of 2 unless the YResolution tag is set
                * appropriately.  (Note also that we fudge a little here
                * and use 150 lpi to avoid problems with units conversion.)
                */
                if (m_tif.m_dir.td_resolutionunit == ResolutionUnit.Centimeter)
                {
                    /* convert to inches */
                    res *= 2.54f;
                }

                m_maxk = (res > 150 ? 4 : 2);
                m_k = m_maxk - 1;
            }
            else
            {
                m_maxk = 0;
                m_k = 0;
            }

            m_line = 0;
            return true;
        }
Example #2
0
        /// <summary>
        /// Encode a buffer of pixels.
        /// </summary>
        private bool Fax3Encode(byte[] buffer, int offset, int count)
        {
            m_buffer = buffer;
            m_offset = offset;

            while (count > 0)
            {
                if ((m_mode & FaxMode.NoEOL) == 0)
                    Fax3PutEOL();

                if (is2DEncoding())
                {
                    if (m_encoder == Fax3Encoder.useFax1DEncoder)
                    {
                        if (!Fax3Encode1DRow())
                            return false;

                        m_encoder = Fax3Encoder.useFax2DEncoder;
                    }
                    else
                    {
                        if (!Fax3Encode2DRow())
                            return false;

                        m_k--;
                    }

                    if (m_k == 0)
                    {
                        m_encoder = Fax3Encoder.useFax1DEncoder;
                        m_k = m_maxk - 1;
                    }
                    else
                    {
                        Buffer.BlockCopy(m_buffer, m_offset, m_refline, 0, m_rowbytes);
                    }
                }
                else
                {
                    if (!Fax3Encode1DRow())
                        return false;
                }

                m_offset += m_rowbytes;
                count -= m_rowbytes;
            }

            return true;
        }
Example #3
0
        private void cleanState()
        {
            m_mode = FaxMode.CLASSIC;
            m_groupoptions = Group3Opt.UNKNOWN;
            m_cleanfaxdata = CleanFaxData.CLEAN;
            m_badfaxlines = 0;
            m_badfaxrun = 0;
            m_recvparams = 0;
            m_subaddress = null;
            m_recvtime = 0;
            m_faxdcs = null;

            fill = null;
            m_rw_mode = 0;
            m_rowbytes = 0;
            m_rowpixels = 0;

            m_decoder = 0;
            m_bitmap = null;
            m_data = 0;
            m_bit = 0;
            m_EOLcnt = 0;
            m_runs = null;
            m_refruns = 0;
            m_curruns = 0;

            m_a0 = 0;
            m_RunLength = 0;
            m_thisrun = 0;
            m_pa = 0;
            m_pb = 0;

            m_encoder = 0;
            m_encodingFax4 = false;
            m_refline = null;
            m_k = 0;
            m_maxk = 0;
            m_line = 0;

            m_buffer = null;
            m_offset = 0;
        }