// Initialize the input controller module. // This is called only once, when the decompression object is created. public static void jinit_input_controller(jpeg_decompress cinfo) { my_input_controller inputctl = null; // Create subobject in pool try { inputctl = new my_input_controller(); } catch { ERREXIT1(cinfo, J_MESSAGE_CODE.JERR_OUT_OF_MEMORY, 4); } cinfo.inputctl = inputctl; // Initialize method pointers inputctl.consume_input = consume_markers_d_input; inputctl.reset_input_controller = reset_input_controller_d_input; inputctl.start_input_pass = start_input_pass_d_input; inputctl.finish_input_pass = finish_input_pass_d_input; // Initialize state: can't use reset_input_controller since we don't // want to try to reset other modules yet. inputctl.has_multiple_scans = false; // "unknown" would be better inputctl.eoi_reached = false; inputctl.inheaders = 1; }
// Reset state to begin a fresh datastream. static void reset_input_controller_d_input(jpeg_decompress cinfo) { my_input_controller inputctl = (my_input_controller)cinfo.inputctl; inputctl.consume_input = consume_markers_d_input; inputctl.has_multiple_scans = false; // "unknown" would be better inputctl.eoi_reached = false; inputctl.inheaders = 1; // Reset other modules cinfo.err.reset_error_mgr(cinfo); cinfo.marker.reset_marker_reader(cinfo); // Reset progression state -- would be cleaner if entropy decoder did this cinfo.coef_bits = null; }
// Read JPEG markers before, between, or after compressed-data scans. // Change state as necessary when a new scan is reached. // Return value is JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI. // // The consume_input method pointer points either here or to the // coefficient controller's consume_data routine, depending on whether // we are reading a compressed data segment or inter-segment markers. // // Note: This function should NOT return a pseudo SOS marker (with zero // component number) to the caller. A pseudo marker received by // read_markers is processed and then skipped for other markers. static CONSUME_INPUT consume_markers_d_input(jpeg_decompress cinfo) { my_input_controller inputctl = (my_input_controller)cinfo.inputctl; if (inputctl.eoi_reached) { return(CONSUME_INPUT.JPEG_REACHED_EOI); // After hitting EOI, read no further } CONSUME_INPUT val = cinfo.marker.read_markers(cinfo); for (; ;) // Loop to pass pseudo SOS marker { switch (val) { case CONSUME_INPUT.JPEG_REACHED_SOS: // Found SOS if (inputctl.inheaders != 0) { // 1st SOS if (inputctl.inheaders == 1) { initial_setup_d_input(cinfo); // Initialize the decompression codec. We need to do this here so that // any codec-specific fields and function pointers are available to // the rest of the library. jinit_d_codec(cinfo); } if (cinfo.comps_in_scan == 0) // pseudo SOS marker { inputctl.inheaders = 2; break; } inputctl.inheaders = 0; // Note: start_input_pass must be called by jdmaster.cs // before any more input can be consumed. jdapimin.cs is // responsible for enforcing this sequencing. } else { // 2nd or later SOS marker if (!inputctl.has_multiple_scans) { ERREXIT(cinfo, J_MESSAGE_CODE.JERR_EOI_EXPECTED); // Oops, I wasn't expecting this! } if (cinfo.comps_in_scan == 0) // unexpected pseudo SOS marker { break; } start_input_pass_d_input(cinfo); } return(val); case CONSUME_INPUT.JPEG_REACHED_EOI: // Found EOI inputctl.eoi_reached = true; if (inputctl.inheaders != 0) { // Tables-only datastream, apparently if (cinfo.marker.saw_SOF) { ERREXIT(cinfo, J_MESSAGE_CODE.JERR_SOF_NO_SOS); } } else { // Prevent infinite loop in coef ctlr's decompress_data routine // if user set output_scan_number larger than number of scans. if (cinfo.output_scan_number > cinfo.input_scan_number) { cinfo.output_scan_number = cinfo.input_scan_number; } } return(val); case CONSUME_INPUT.JPEG_SUSPENDED: return(val); } } }
// Initialize the input controller module. // This is called only once, when the decompression object is created. public static void jinit_input_controller(jpeg_decompress cinfo) { my_input_controller inputctl=null; // Create subobject in pool try { inputctl=new my_input_controller(); } catch { ERREXIT1(cinfo, J_MESSAGE_CODE.JERR_OUT_OF_MEMORY, 4); } cinfo.inputctl=inputctl; // Initialize method pointers inputctl.consume_input=consume_markers_d_input; inputctl.reset_input_controller=reset_input_controller_d_input; inputctl.start_input_pass=start_input_pass_d_input; inputctl.finish_input_pass=finish_input_pass_d_input; // Initialize state: can't use reset_input_controller since we don't // want to try to reset other modules yet. inputctl.has_multiple_scans=false; // "unknown" would be better inputctl.eoi_reached=false; inputctl.inheaders=1; }