BitMiracle.LibJpeg.Classic.Internal.jpeg_marker_writer.write_tables_only C# (CSharp) Method

write_tables_only() public method

Write an abbreviated table-specification datastream. This consists of SOI, DQT and DHT tables, and EOI. Any table that is defined and not marked sent_table = true will be emitted. Note that all tables will be marked sent_table = true at exit.
public write_tables_only ( ) : void
return void
        public void write_tables_only()
        {
            emit_marker(JPEG_MARKER.SOI);

            for (int i = 0; i < JpegConstants.NUM_QUANT_TBLS; i++)
            {
                if (m_cinfo.m_quant_tbl_ptrs[i] != null)
                    emit_dqt(i);
            }

            for (int i = 0; i < JpegConstants.NUM_HUFF_TBLS; i++)
            {
                if (m_cinfo.m_dc_huff_tbl_ptrs[i] != null)
                    emit_dht(i, false);
                if (m_cinfo.m_ac_huff_tbl_ptrs[i] != null)
                    emit_dht(i, true);
            }

            emit_marker(JPEG_MARKER.EOI);
        }

Usage Example

        /// <summary>
        /// Alternate compression function: just write an abbreviated table file.
        /// </summary>
        /// <remarks>Before calling this, all parameters and a data destination must be set up.<br/>
        /// 
        /// To produce a pair of files containing abbreviated tables and abbreviated
        /// image data, one would proceed as follows:<br/>
        /// 
        /// <c>Initialize JPEG object<br/>
        /// Set JPEG parameters<br/>
        /// Set destination to table file<br/>
        /// <see cref="jpeg_compress_struct.jpeg_write_tables">jpeg_write_tables();</see><br/>
        /// Set destination to image file<br/>
        /// <see cref="jpeg_compress_struct.jpeg_start_compress">jpeg_start_compress(false);</see><br/>
        /// Write data...<br/>
        /// <see cref="jpeg_compress_struct.jpeg_finish_compress">jpeg_finish_compress();</see><br/>
        /// </c><br/>
        /// 
        /// jpeg_write_tables has the side effect of marking all tables written
        /// (same as <see cref="jpeg_compress_struct.jpeg_suppress_tables">jpeg_suppress_tables(true)</see>).
        /// Thus a subsequent <see cref="jpeg_compress_struct.jpeg_start_compress">jpeg_start_compress</see> 
        /// will not re-emit the tables unless it is passed <c>write_all_tables=true</c>.
        /// </remarks>
        public void jpeg_write_tables()
        {
            if (m_global_state != JpegState.CSTATE_START)
                ERREXIT(J_MESSAGE_CODE.JERR_BAD_STATE, (int)m_global_state);

            /* (Re)initialize error mgr and destination modules */
            m_err.reset_error_mgr();
            m_dest.init_destination();

            /* Initialize the marker writer ... bit of a crock to do it here. */
            m_marker = new jpeg_marker_writer(this);

            /* Write them tables! */
            m_marker.write_tables_only();

            /* And clean up. */
            m_dest.term_destination();
        }