/// <summary> /// Initialization of JPEG compression objects. /// The error manager must already be set up (in case memory manager fails). /// </summary> private void initialize() { /* Zero out pointers to permanent structures. */ m_progress = null; m_src = null; for (int i = 0; i < JpegConstants.NUM_QUANT_TBLS; i++) m_quant_tbl_ptrs[i] = null; for (int i = 0; i < JpegConstants.NUM_HUFF_TBLS; i++) { m_dc_huff_tbl_ptrs[i] = null; m_ac_huff_tbl_ptrs[i] = null; } /* Initialize marker processor so application can override methods * for COM, APPn markers before calling jpeg_read_header. */ m_marker_list = new List<jpeg_marker_struct>(); m_marker = new jpeg_marker_reader(this); /* And initialize the overall input controller. */ m_inputctl = new jpeg_input_controller(this); /* OK, I'm ready */ m_global_state = JpegState.DSTATE_START; }
private void cleanState() { m_jpeg_interchange_format = 0; m_jpeg_interchange_format_length = 0; m_jpeg_proc = 0; m_subsamplingcorrect_done = false; m_subsampling_tag = false; m_subsampling_hor = 0; m_subsampling_ver = 0; m_qtable_offset_count = 0; m_dctable_offset_count = 0; m_actable_offset_count = 0; m_qtable_offset = new uint[3]; m_dctable_offset = new uint[3]; m_actable_offset = new uint[3]; m_restart_interval = 0; m_libjpeg_jpeg_decompress_struct = null; m_file_size = 0; m_image_width = 0; m_image_length = 0; m_strile_width = 0; m_strile_length = 0; m_strile_length_total = 0; m_samples_per_pixel = 0; m_plane_sample_offset = 0; m_samples_per_pixel_per_plane = 0; m_subsamplingcorrect = false; m_subsampling_force_desubsampling_inside_decompression = false; m_qtable = new byte[4][]; m_dctable = new byte[4][]; m_actable = new byte[4][]; m_restart_index = 0; m_sof_log = false; m_sof_marker_id = 0; m_sof_x = 0; m_sof_y = 0; m_sof_c = new byte[3]; m_sof_hv = new byte[3]; m_sof_tq = new byte[3]; m_sos_cs = new byte[3]; m_sos_tda = new byte[3]; m_sos_end = new SosEnd[3]; m_readheader_done = false; m_writeheader_done = false; m_write_cursample = 0; m_write_curstrile = 0; m_libjpeg_session_active = false; m_libjpeg_jpeg_query_style = 0; m_libjpeg_jpeg_error_mgr = null; m_libjpeg_jpeg_source_mgr = null; m_subsampling_convert_log = false; m_subsampling_convert_ylinelen = 0; m_subsampling_convert_ylines = 0; m_subsampling_convert_clinelen = 0; m_subsampling_convert_clines = 0; m_subsampling_convert_ybuf = null; m_subsampling_convert_cbbuf = null; m_subsampling_convert_crbuf = null; m_subsampling_convert_ycbcrimage = null; m_subsampling_convert_clinelenout = 0; m_subsampling_convert_state = 0; m_bytes_per_line = 0; m_lines_per_strile = 0; m_in_buffer_source = OJPEGStateInBufferSource.osibsNotSetYet; m_in_buffer_next_strile = 0; m_in_buffer_strile_count = 0; m_in_buffer_file_pos = 0; m_in_buffer_file_pos_log = false; m_in_buffer_file_togo = 0; m_in_buffer_togo = 0; m_in_buffer_cur = 0; // index into m_in_buffer m_in_buffer = new byte[OJPEG_BUFFER]; m_out_state = 0; m_out_buffer = new byte[OJPEG_BUFFER]; m_skip_buffer = null; m_forceProcessedRgbOutput = false; }
/// <summary> /// Sets input stream. /// </summary> /// <param name="infile">The input stream.</param> /// <remarks> /// The caller must have already opened the stream, and is responsible /// for closing it after finishing decompression. /// </remarks> /// <seealso href="9d052723-a7f9-42de-8747-0bd9896f8157.htm" target="_self">Decompression details</seealso> public void jpeg_stdio_src(Stream infile) { /* The source object and input buffer are made permanent so that a series * of JPEG images can be read from the same file by calling jpeg_stdio_src * only before the first one. (If we discarded the buffer at the end of * one image, we'd likely lose the start of the next one.) * This makes it unsafe to use this manager and a different source * manager serially with the same JPEG object. Caveat programmer. */ if (m_src == null) { /* first time for this JPEG object? */ m_src = new my_source_mgr(this); } my_source_mgr m = m_src as my_source_mgr; if (m != null) m.Attach(infile); }
private bool OJPEGWriteHeaderInfo() { Debug.Assert(!m_libjpeg_session_active); m_out_state = OJPEGStateOutState.ososSoi; m_restart_index = 0; m_libjpeg_jpeg_error_mgr = new OJpegErrorManager(this); if (!jpeg_create_decompress_encap()) return false; m_libjpeg_session_active = true; m_libjpeg_jpeg_source_mgr = new OJpegSrcManager(this); m_libjpeg_jpeg_decompress_struct.Src = m_libjpeg_jpeg_source_mgr; if (jpeg_read_header_encap(true) == ReadResult.JPEG_SUSPENDED) return false; if (!m_subsampling_force_desubsampling_inside_decompression && (m_samples_per_pixel_per_plane > 1)) { m_libjpeg_jpeg_decompress_struct.Raw_data_out = true; m_libjpeg_jpeg_decompress_struct.Do_fancy_upsampling = false; //#if JPEG_LIB_VERSION >= 70 // libjpeg_jpeg_decompress_struct.do_fancy_upsampling=FALSE; //#endif m_libjpeg_jpeg_query_style = 0; if (!m_subsampling_convert_log) { Debug.Assert(m_subsampling_convert_ybuf == null); Debug.Assert(m_subsampling_convert_cbbuf == null); Debug.Assert(m_subsampling_convert_crbuf == null); Debug.Assert(m_subsampling_convert_ycbcrimage == null); m_subsampling_convert_ylinelen = (uint)((m_strile_width + m_subsampling_hor * 8 - 1) / (m_subsampling_hor * 8) * m_subsampling_hor * 8); m_subsampling_convert_ylines = (uint)(m_subsampling_ver * 8); m_subsampling_convert_clinelen = m_subsampling_convert_ylinelen / m_subsampling_hor; m_subsampling_convert_clines = 8; m_subsampling_convert_ybuf = new byte[m_subsampling_convert_ylines][]; for (int i = 0; i < m_subsampling_convert_ylines; i++) m_subsampling_convert_ybuf[i] = new byte[m_subsampling_convert_ylinelen]; m_subsampling_convert_cbbuf = new byte[m_subsampling_convert_clines][]; m_subsampling_convert_crbuf = new byte[m_subsampling_convert_clines][]; for (int i = 0; i < m_subsampling_convert_clines; i++) { m_subsampling_convert_cbbuf[i] = new byte[m_subsampling_convert_clinelen]; m_subsampling_convert_crbuf[i] = new byte[m_subsampling_convert_clinelen]; } m_subsampling_convert_ycbcrimage = new byte[3][][]; m_subsampling_convert_ycbcrimage[0] = new byte[m_subsampling_convert_ylines][]; for (uint n = 0; n < m_subsampling_convert_ylines; n++) m_subsampling_convert_ycbcrimage[0][n] = m_subsampling_convert_ybuf[n]; m_subsampling_convert_ycbcrimage[1] = new byte[m_subsampling_convert_clines][]; for (uint n = 0; n < m_subsampling_convert_clines; n++) m_subsampling_convert_ycbcrimage[1][n] = m_subsampling_convert_cbbuf[n]; m_subsampling_convert_ycbcrimage[2] = new byte[m_subsampling_convert_clines][]; for (uint n = 0; n < m_subsampling_convert_clines; n++) m_subsampling_convert_ycbcrimage[2][n] = m_subsampling_convert_crbuf[n]; m_subsampling_convert_clinelenout = ((m_strile_width + m_subsampling_hor - 1) / m_subsampling_hor); m_subsampling_convert_state = 0; m_bytes_per_line = (uint)(m_subsampling_convert_clinelenout * (m_subsampling_ver * m_subsampling_hor + 2)); m_lines_per_strile = ((m_strile_length + m_subsampling_ver - 1) / m_subsampling_ver); m_subsampling_convert_log = true; } } else { if (m_forceProcessedRgbOutput) { m_libjpeg_jpeg_decompress_struct.Do_fancy_upsampling = false; m_libjpeg_jpeg_decompress_struct.Jpeg_color_space = J_COLOR_SPACE.JCS_YCbCr; m_libjpeg_jpeg_decompress_struct.Out_color_space = J_COLOR_SPACE.JCS_RGB; } else { m_libjpeg_jpeg_decompress_struct.Jpeg_color_space = J_COLOR_SPACE.JCS_UNKNOWN; m_libjpeg_jpeg_decompress_struct.Out_color_space = J_COLOR_SPACE.JCS_UNKNOWN; } m_libjpeg_jpeg_query_style = 1; m_bytes_per_line = m_samples_per_pixel_per_plane * m_strile_width; m_lines_per_strile = m_strile_length; } if (!jpeg_start_decompress_encap()) return false; m_writeheader_done = true; return true; }