public jpeg_write_scanlines ( byte scanlines, int num_lines ) : int | ||
scanlines | byte | The array of scanlines. |
num_lines | int | The number of scanlines for writing. |
return | int |
public int jpeg_write_scanlines(byte[][] scanlines, int num_lines)
{
if (m_global_state != JpegState.CSTATE_SCANNING)
ERREXIT(J_MESSAGE_CODE.JERR_BAD_STATE, (int)m_global_state);
if (m_next_scanline >= m_image_height)
WARNMS(J_MESSAGE_CODE.JWRN_TOO_MUCH_DATA);
/* Call progress monitor hook if present */
if (m_progress != null)
{
m_progress.Pass_counter = m_next_scanline;
m_progress.Pass_limit = m_image_height;
m_progress.Updated();
}
/* Give master control module another chance if this is first call to
* jpeg_write_scanlines. This lets output of the frame/scan headers be
* delayed so that application can write COM, etc, markers between
* jpeg_start_compress and jpeg_write_scanlines.
*/
if (m_master.MustCallPassStartup())
m_master.pass_startup();
/* Ignore any extra scanlines at bottom of image. */
int rows_left = m_image_height - m_next_scanline;
if (num_lines > rows_left)
num_lines = rows_left;
int row_ctr = 0;
m_main.process_data(scanlines, ref row_ctr, num_lines);
m_next_scanline += row_ctr;
return row_ctr;
}
private static void compress(Stream input, CompressOptions options, Stream output) { Debug.Assert(input != null); Debug.Assert(options != null); Debug.Assert(output != null); jpeg_compress_struct cinfo = new jpeg_compress_struct(new cd_jpeg_error_mgr()); /* Initialize JPEG parameters. * Much of this may be overridden later. * In particular, we don't yet know the input file's color space, * but we need to provide some value for jpeg_set_defaults() to work. */ cinfo.In_color_space = J_COLOR_SPACE.JCS_RGB; /* arbitrary guess */ cinfo.jpeg_set_defaults(); /* Figure out the input file format, and set up to read it. */ cjpeg_source_struct src_mgr = new bmp_source_struct(cinfo); src_mgr.input_file = input; /* Read the input file header to obtain file size & colorspace. */ src_mgr.start_input(); /* Now that we know input colorspace, fix colorspace-dependent defaults */ cinfo.jpeg_default_colorspace(); /* Adjust default compression parameters */ if (!applyOptions(cinfo, options)) return; /* Specify data destination for compression */ cinfo.jpeg_stdio_dest(output); /* Start compressor */ cinfo.jpeg_start_compress(true); /* Process data */ while (cinfo.Next_scanline < cinfo.Image_height) { int num_scanlines = src_mgr.get_pixel_rows(); cinfo.jpeg_write_scanlines(src_mgr.buffer, num_scanlines); } /* Finish compression and release memory */ src_mgr.finish_input(); cinfo.jpeg_finish_compress(); /* All done. */ if (cinfo.Err.Num_warnings != 0) Console.WriteLine("Corrupt-data warning count is not zero"); }