jcparam.c
/*
 * Create a recommended progressive-JPEG script.
 * cinfo->num_components and cinfo->jpeg_color_space must be correct.
 */
Create a recommended progressive-JPEG script.
Create a recommended progressive - JPEG script .
GLOBAL(void)
jpeg_simple_progression (j_compress_ptr cinfo)
{
  int ncomps;
  int nscans;
  jpeg_scan_info *scanptr;
  if (cinfo->master->optimize_scans) {
    if (jpeg_search_progression(cinfo) == TRUE)
      return;
  }
  if (cinfo->global_state != CSTATE_START)
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  ncomps = cinfo->num_components;
  if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
    if (cinfo->master->compress_profile == JCP_MAX_COMPRESSION) {
      if (cinfo->master->dc_scan_opt_mode == 0) {
        nscans = 9;  
      } else if (cinfo->master->dc_scan_opt_mode == 1) {
        nscans = 11; 
      } else {
        nscans = 10; 
      }
    } else {
      nscans = 10;   
    }
  } else {
    if (cinfo->master->compress_profile == JCP_MAX_COMPRESSION) {
    if (ncomps > MAX_COMPS_IN_SCAN)
        nscans = 5 * ncomps;      
      else
        nscans = 1 + 4 * ncomps;  
    } else {
      if (ncomps > MAX_COMPS_IN_SCAN)
      nscans = 6 * ncomps;      
    else
      nscans = 2 + 4 * ncomps;  
  }
  }
  if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) {
    cinfo->script_space_size = MAX(nscans, 10);
    cinfo->script_space = (jpeg_scan_info *)
      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
                        cinfo->script_space_size * sizeof(jpeg_scan_info));
  }
  scanptr = cinfo->script_space;
  cinfo->scan_info = scanptr;
  cinfo->num_scans = nscans;
  if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
    if (cinfo->master->compress_profile == JCP_MAX_COMPRESSION) {
      if (cinfo->master->dc_scan_opt_mode == 0) {
        scanptr = fill_dc_scans(scanptr, ncomps, 0, 0);
      } else if (cinfo->master->dc_scan_opt_mode == 1) {
        scanptr = fill_a_scan(scanptr, 0, 0, 0, 0, 0);
        scanptr = fill_a_scan(scanptr, 1, 0, 0, 0, 0);
        scanptr = fill_a_scan(scanptr, 2, 0, 0, 0, 0);
      } else {
        scanptr = fill_dc_scans(scanptr, 1, 0, 0);
        scanptr = fill_a_scan_pair(scanptr, 1, 0, 0, 0, 0);
      }
      scanptr = fill_a_scan(scanptr, 0, 1, 8, 0, 2);
      scanptr = fill_a_scan(scanptr, 1, 1, 8, 0, 0);
      scanptr = fill_a_scan(scanptr, 2, 1, 8, 0, 0);
      scanptr = fill_a_scan(scanptr, 0, 9, 63, 0, 2);
      scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1);
      scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0);
      scanptr = fill_a_scan(scanptr, 1, 9, 63, 0, 0);
      scanptr = fill_a_scan(scanptr, 2, 9, 63, 0, 0);
    } else {
    scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
    scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2);
    scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 1);
    scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 1);
    scanptr = fill_a_scan(scanptr, 0, 6, 63, 0, 2);
    scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1);
    scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
    scanptr = fill_a_scan(scanptr, 2, 1, 63, 1, 0);
    scanptr = fill_a_scan(scanptr, 1, 1, 63, 1, 0);
    scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0);
    }
  } else {
    if (cinfo->master->compress_profile == JCP_MAX_COMPRESSION) {
      scanptr = fill_dc_scans(scanptr, ncomps, 0, 0);
      scanptr = fill_scans(scanptr, ncomps, 1, 8, 0, 2);
      scanptr = fill_scans(scanptr, ncomps, 9, 63, 0, 2);
      scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1);
      scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0);
    } else {
    scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
    scanptr = fill_scans(scanptr, ncomps, 1, 5, 0, 2);
    scanptr = fill_scans(scanptr, ncomps, 6, 63, 0, 2);
    scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1);
    scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
    scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0);
  }
}
}
GLOBAL ( void ) jpeg_simple_progression ( j_compress_ptr cinfo ) { int ncomps ; int nscans ; jpeg_scan_info * scanptr ; if ( cinfo -> master -> optimize_scans ) { if ( jpeg_search_progression ( cinfo ) == TRUE ) return ; } if ( cinfo -> global_state != CSTATE_START ) ERREXIT1 ( cinfo , JERR_BAD_STATE , cinfo -> global_state ) ; ncomps = cinfo -> num_components ; if ( ncomps == 3 && cinfo -> jpeg_color_space == JCS_YCbCr ) { if ( cinfo -> master -> compress_profile == JCP_MAX_COMPRESSION ) { if ( cinfo -> master -> dc_scan_opt_mode == 0 ) { nscans = 9 ; } else if ( cinfo -> master -> dc_scan_opt_mode == 1 ) { nscans = 11 ; } else { nscans = 10 ; } } else { nscans = 10 ; } } else { if ( cinfo -> master -> compress_profile == JCP_MAX_COMPRESSION ) { if ( ncomps > MAX_COMPS_IN_SCAN ) nscans = 5 * ncomps ; else nscans = 1 + 4 * ncomps ; } else { if ( ncomps > MAX_COMPS_IN_SCAN ) nscans = 6 * ncomps ; else nscans = 2 + 4 * ncomps ; } } if ( cinfo -> script_space == NULL || cinfo -> script_space_size < nscans ) { cinfo -> script_space_size = MAX ( nscans , 10 ) ; cinfo -> script_space = ( jpeg_scan_info * ) ( * cinfo -> mem -> alloc_small ) ( ( j_common_ptr ) cinfo , JPOOL_PERMANENT , cinfo -> script_space_size * sizeof ( jpeg_scan_info ) ) ; } scanptr = cinfo -> script_space ; cinfo -> scan_info = scanptr ; cinfo -> num_scans = nscans ; if ( ncomps == 3 && cinfo -> jpeg_color_space == JCS_YCbCr ) { if ( cinfo -> master -> compress_profile == JCP_MAX_COMPRESSION ) { if ( cinfo -> master -> dc_scan_opt_mode == 0 ) { scanptr = fill_dc_scans ( scanptr , ncomps , 0 , 0 ) ; } else if ( cinfo -> master -> dc_scan_opt_mode == 1 ) { scanptr = fill_a_scan ( scanptr , 0 , 0 , 0 , 0 , 0 ) ; scanptr = fill_a_scan ( scanptr , 1 , 0 , 0 , 0 , 0 ) ; scanptr = fill_a_scan ( scanptr , 2 , 0 , 0 , 0 , 0 ) ; } else { scanptr = fill_dc_scans ( scanptr , 1 , 0 , 0 ) ; scanptr = fill_a_scan_pair ( scanptr , 1 , 0 , 0 , 0 , 0 ) ; } scanptr = fill_a_scan ( scanptr , 0 , 1 , 8 , 0 , 2 ) ; scanptr = fill_a_scan ( scanptr , 1 , 1 , 8 , 0 , 0 ) ; scanptr = fill_a_scan ( scanptr , 2 , 1 , 8 , 0 , 0 ) ; scanptr = fill_a_scan ( scanptr , 0 , 9 , 63 , 0 , 2 ) ; scanptr = fill_a_scan ( scanptr , 0 , 1 , 63 , 2 , 1 ) ; scanptr = fill_a_scan ( scanptr , 0 , 1 , 63 , 1 , 0 ) ; scanptr = fill_a_scan ( scanptr , 1 , 9 , 63 , 0 , 0 ) ; scanptr = fill_a_scan ( scanptr , 2 , 9 , 63 , 0 , 0 ) ; } else { scanptr = fill_dc_scans ( scanptr , ncomps , 0 , 1 ) ; scanptr = fill_a_scan ( scanptr , 0 , 1 , 5 , 0 , 2 ) ; scanptr = fill_a_scan ( scanptr , 2 , 1 , 63 , 0 , 1 ) ; scanptr = fill_a_scan ( scanptr , 1 , 1 , 63 , 0 , 1 ) ; scanptr = fill_a_scan ( scanptr , 0 , 6 , 63 , 0 , 2 ) ; scanptr = fill_a_scan ( scanptr , 0 , 1 , 63 , 2 , 1 ) ; scanptr = fill_dc_scans ( scanptr , ncomps , 1 , 0 ) ; scanptr = fill_a_scan ( scanptr , 2 , 1 , 63 , 1 , 0 ) ; scanptr = fill_a_scan ( scanptr , 1 , 1 , 63 , 1 , 0 ) ; scanptr = fill_a_scan ( scanptr , 0 , 1 , 63 , 1 , 0 ) ; } } else { if ( cinfo -> master -> compress_profile == JCP_MAX_COMPRESSION ) { scanptr = fill_dc_scans ( scanptr , ncomps , 0 , 0 ) ; scanptr = fill_scans ( scanptr , ncomps , 1 , 8 , 0 , 2 ) ; scanptr = fill_scans ( scanptr , ncomps , 9 , 63 , 0 , 2 ) ; scanptr = fill_scans ( scanptr , ncomps , 1 , 63 , 2 , 1 ) ; scanptr = fill_scans ( scanptr , ncomps , 1 , 63 , 1 , 0 ) ; } else { scanptr = fill_dc_scans ( scanptr , ncomps , 0 , 1 ) ; scanptr = fill_scans ( scanptr , ncomps , 1 , 5 , 0 , 2 ) ; scanptr = fill_scans ( scanptr , ncomps , 6 , 63 , 0 , 2 ) ; scanptr = fill_scans ( scanptr , ncomps , 1 , 63 , 2 , 1 ) ; scanptr = fill_dc_scans ( scanptr , ncomps , 1 , 0 ) ; scanptr = fill_scans ( scanptr , ncomps , 1 , 63 , 1 , 0 ) ; } } }
Create a recommended progressive-JPEG script.
Create a recommended progressive - JPEG script .
/* Safety check to ensure start_compress not called yet. */ /* Figure space needed for script.  Calculation must match code below! */ /* Custom script for YCbCr color images. */ /* 1 DC scan for all components */ /* 1 DC scan for each component */ /* 1 DC scan for luminance and 1 DC scan for chroma */ /* 2 DC scans and 8 AC scans */ /* All-purpose script for other color spaces. */ /* 2 DC + 4 AC scans per component */ /* 2 DC scans; 4 AC scans per component */ /* 2 DC + 4 AC scans per component */ /* 2 DC scans; 4 AC scans per component */ /* Allocate space for script.
   * We need to put it in the permanent pool in case the application performs
   * multiple compressions without changing the settings.  To avoid a memory
   * leak if jpeg_simple_progression is called repeatedly for the same JPEG
   * object, we try to re-use previously allocated space, and we allocate
   * enough space to handle YCbCr even if initially asked for grayscale.
   */ /* Custom script for YCbCr color images. */ /* scan defined in jpeg_scan_rgb.txt in jpgcrush */ /* Initial DC scan */ /* 1 DC scan for all components */ /* 1 DC scan for each component */ /* 1 DC scan for luminance and 1 DC scan for chroma */ /* Low frequency AC scans */ /* Complete spectral selection for luma AC */ /* Finish luma AC successive approximation */ /* Complete spectral selection for chroma AC */ /* Initial DC scan */ /* Initial AC scan: get some luma data out in a hurry */ /* Chroma data is too small to be worth expending many scans on */ /* Complete spectral selection for luma AC */ /* Refine next bit of luma AC */ /* Finish DC successive approximation */ /* Finish AC successive approximation */ /* Luma bottom bit comes last since it's usually largest scan */ /* All-purpose script for other color spaces. */ /* scan defined in jpeg_scan_bw.txt in jpgcrush */ /* DC component, no successive approximation */ /* Successive approximation first pass */ /* Successive approximation second pass */ /* Successive approximation final pass */ /* Successive approximation first pass */ /* Successive approximation second pass */ /* Successive approximation final pass */