Ejemplo n.º 1
0
        // Read next input byte; we do not support suspension in this module.
        static int get_byte_arith(jpeg_decompress cinfo)
        {
            jpeg_source_mgr src = cinfo.src;

            if (src.bytes_in_buffer == 0)
            {
                if (!src.fill_input_buffer(cinfo))
                {
                    ERREXIT(cinfo, J_MESSAGE_CODE.JERR_CANT_SUSPEND);
                }
            }
            src.bytes_in_buffer--;
            return(src.input_bytes[src.next_input_byte++]);
        }
Ejemplo n.º 2
0
        // Convert a stream into a source manager.
        public static void StreamToSourceManager
            (ref jpeg_decompress_struct cinfo, Stream stream,
            byte[] prime, int primeLen)
        {
            // Allocate a state structure and store it in "cinfo".
            IntPtr      buf   = Marshal.AllocHGlobal(4096);
            StreamState state = new StreamState();

            state.buf         = buf;
            state.buffer      = new byte [4096];
            state.stream      = stream;
            cinfo.client_data = (IntPtr)(GCHandle.Alloc(state));

            // We prime the input buffer with the JPEG magic number
            // if some higher-level process has already read it.
            int len;

            if (prime != null)
            {
                len = primeLen;
                Marshal.Copy(prime, 0, buf, len);
            }
            else
            {
                len = 0;
            }

            // Create the managed version of "jpeg_source_mgr".
            jpeg_source_mgr mgr = new jpeg_source_mgr();

            mgr.next_input_byte   = buf;
            mgr.bytes_in_buffer   = (size_t)len;
            mgr.init_source       = new init_source_type(init_source);
            mgr.fill_input_buffer =
                new fill_input_buffer_type(fill_input_buffer);
            mgr.skip_input_data =
                new skip_input_data_type(skip_input_data);
            mgr.resync_to_restart =
                new resync_to_restart_type(jpeg_resync_to_restart);
            mgr.term_source =
                new term_source_type(term_source);

            // Convert it into the unmanaged version and store it.
#if __CSCC__
            IntPtr umgr = Marshal.AllocHGlobal(sizeof(jpeg_source_mgr));
            Marshal.StructureToPtr(mgr, umgr, false);
            cinfo.src = (jpeg_source_mgr *)umgr;
#endif
        }
Ejemplo n.º 3
0
	// Convert a stream into a source manager.
	public static void StreamToSourceManager
				(ref jpeg_decompress_struct cinfo, Stream stream,
				 byte[] prime, int primeLen)
			{
				// Allocate a state structure and store it in "cinfo".
				IntPtr buf = Marshal.AllocHGlobal(4096);
				StreamState state = new StreamState();
				state.buf = buf;
				state.buffer = new byte [4096];
				state.stream = stream;
				cinfo.client_data = (IntPtr)(GCHandle.Alloc(state));

				// We prime the input buffer with the JPEG magic number
				// if some higher-level process has already read it.
				int len;
				if(prime != null)
				{
					len = primeLen;
					Marshal.Copy(prime, 0, buf, len);
				}
				else
				{
					len = 0;
				}

				// Create the managed version of "jpeg_source_mgr".
				jpeg_source_mgr mgr = new jpeg_source_mgr();
				mgr.next_input_byte = buf;
				mgr.bytes_in_buffer = (size_t)len;
				mgr.init_source = new init_source_type(init_source);
				mgr.fill_input_buffer =
					new fill_input_buffer_type(fill_input_buffer);
				mgr.skip_input_data =
					new skip_input_data_type(skip_input_data);
				mgr.resync_to_restart =
					new resync_to_restart_type(jpeg_resync_to_restart);
				mgr.term_source =
					new term_source_type(term_source);

				// Convert it into the unmanaged version and store it.
#if __CSCC__
				IntPtr umgr = Marshal.AllocHGlobal(sizeof(jpeg_source_mgr));
				Marshal.StructureToPtr(mgr, umgr, false);
				cinfo.src = (jpeg_source_mgr *)umgr;
#endif
			}