Beispiel #1
0
jpeg_simple_progression (j_compress_ptr cinfo)
{
  int ncomps = cinfo->num_components;
  int nscans;
  jpeg_scan_info * scanptr;

  /* Safety check to ensure start_compress not called yet. */
  if (cinfo->global_state != CSTATE_START)
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);

  /* Figure space needed for script.  Calculation must match code below! */
  if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
    /* Custom script for YCbCr color images. */
    nscans = 10;
  } else {
    /* All-purpose script for other color spaces. */
    if (ncomps > MAX_COMPS_IN_SCAN)
      nscans = 6 * ncomps;	/* 2 DC + 4 AC scans per component */
    else
      nscans = 2 + 4 * ncomps;	/* 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.
   */
  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) {
    /* Custom script for YCbCr color images. */
    /* Initial DC scan */
    scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
    /* Initial AC scan: get some luma data out in a hurry */
    scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2);
    /* Chroma data is too small to be worth expending many scans on */
    scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 1);
    scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 1);
    /* Complete spectral selection for luma AC */
    scanptr = fill_a_scan(scanptr, 0, 6, 63, 0, 2);
    /* Refine next bit of luma AC */
    scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1);
    /* Finish DC successive approximation */
    scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
    /* Finish AC successive approximation */
    scanptr = fill_a_scan(scanptr, 2, 1, 63, 1, 0);
    scanptr = fill_a_scan(scanptr, 1, 1, 63, 1, 0);
    /* Luma bottom bit comes last since it's usually largest scan */
    scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0);
  } else {
    /* All-purpose script for other color spaces. */
    /* Successive approximation first pass */
    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);
    /* Successive approximation second pass */
    scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1);
    /* Successive approximation final pass */
    scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
    scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0);
  }
}
Beispiel #2
0
jpeg_search_progression (j_compress_ptr cinfo)
{
  int ncomps = cinfo->num_components;
  int nscans;
  jpeg_scan_info * scanptr;
  int Al;
  int frequency_split[] = { 2, 8, 5, 12, 18 };
  int i;
  
  /* Safety check to ensure start_compress not called yet. */
  if (cinfo->global_state != CSTATE_START)
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  
  /* Figure space needed for script.  Calculation must match code below! */
  if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
    /* Custom script for YCbCr color images. */
    nscans = 64;
  } else if (ncomps == 1) {
    nscans = 23;
  } else {
    cinfo->num_scans_luma = 0;
    return FALSE;
  }
  
  /* 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.
   */
  if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) {
    cinfo->script_space_size = MAX(nscans, 64);
    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;
  
  cinfo->Al_max_luma = 3;
  cinfo->num_scans_luma_dc = 1;
  cinfo->num_frequency_splits = 5;
  cinfo->num_scans_luma = cinfo->num_scans_luma_dc + (3 * cinfo->Al_max_luma + 2) + (2 * cinfo->num_frequency_splits + 1);
  
  /* 23 scans for luma */
  /* 1 scan for DC */
  /* 11 scans to determine successive approximation */
  /* 11 scans to determine frequency approximation */
  /* after 12 scans need to update following 11 */
  /* after 23 scans need to determine which to keep */
  /* last 4 done conditionally */
  
  /* luma DC by itself */
  if (cinfo->one_dc_scan)
    scanptr = fill_dc_scans(scanptr, ncomps, 0, 0);
  else
    scanptr = fill_dc_scans(scanptr, 1, 0, 0);
  
  scanptr = fill_a_scan(scanptr, 0, 1, 8, 0, 0);
  scanptr = fill_a_scan(scanptr, 0, 9, 63, 0, 0);
  
  for (Al = 0; Al < cinfo->Al_max_luma; Al++) {
    scanptr = fill_a_scan(scanptr, 0, 1, 63, Al+1, Al);
    scanptr = fill_a_scan(scanptr, 0, 1, 8, 0, Al+1);
    scanptr = fill_a_scan(scanptr, 0, 9, 63, 0, Al+1);
  }
  
  scanptr = fill_a_scan(scanptr, 0, 1, 63, 0, 0);
  
  for (i = 0; i < cinfo->num_frequency_splits; i++) {
    scanptr = fill_a_scan(scanptr, 0, 1, frequency_split[i], 0, 0);
    scanptr = fill_a_scan(scanptr, 0, frequency_split[i]+1, 63, 0, 0);
  }
  
  if (ncomps == 1) {
    cinfo->Al_max_chroma = 0;
    cinfo->num_scans_chroma_dc = 0;
  } else {
    cinfo->Al_max_chroma = 2;
    cinfo->num_scans_chroma_dc = 3;
    /* 41 scans for chroma */
    
    /* chroma DC combined */
    scanptr = fill_a_scan_pair(scanptr, 1, 0, 0, 0, 0);
    /* chroma DC separate */
    scanptr = fill_a_scan(scanptr, 1, 0, 0, 0, 0);
    scanptr = fill_a_scan(scanptr, 2, 0, 0, 0, 0);
    
    scanptr = fill_a_scan(scanptr, 1, 1, 8, 0, 0);
    scanptr = fill_a_scan(scanptr, 1, 9, 63, 0, 0);
    scanptr = fill_a_scan(scanptr, 2, 1, 8, 0, 0);
    scanptr = fill_a_scan(scanptr, 2, 9, 63, 0, 0);

    for (Al = 0; Al < cinfo->Al_max_chroma; Al++) {
      scanptr = fill_a_scan(scanptr, 1, 1, 63, Al+1, Al);
      scanptr = fill_a_scan(scanptr, 2, 1, 63, Al+1, Al);
      scanptr = fill_a_scan(scanptr, 1, 1, 8, 0, Al+1);
      scanptr = fill_a_scan(scanptr, 1, 9, 63, 0, Al+1);
      scanptr = fill_a_scan(scanptr, 2, 1, 8, 0, Al+1);
      scanptr = fill_a_scan(scanptr, 2, 9, 63, 0, Al+1);
    }
    
    scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 0);
    scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 0);

    for (i = 0; i < cinfo->num_frequency_splits; i++) {
      scanptr = fill_a_scan(scanptr, 1, 1, frequency_split[i], 0, 0);
      scanptr = fill_a_scan(scanptr, 1, frequency_split[i]+1, 63, 0, 0);
      scanptr = fill_a_scan(scanptr, 2, 1, frequency_split[i], 0, 0);
      scanptr = fill_a_scan(scanptr, 2, frequency_split[i]+1, 63, 0, 0);
    }
  }
  
  return TRUE;
}
Beispiel #3
0
jpeg_simple_progression (j_compress_ptr cinfo)
{
  int ncomps = cinfo->num_components;
  int nscans;
  jpeg_scan_info * scanptr;

  /* Safety check to ensure start_compress not called yet. */
  if (cinfo->global_state != CSTATE_START)
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);

  /* Figure space needed for script.  Calculation must match code below! */
  if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
    /* Custom script for YCbCr color images. */
    nscans = 10;
  } else {
    /* All-purpose script for other color spaces. */
    if (ncomps > MAX_COMPS_IN_SCAN)
      nscans = 6 * ncomps;	/* 2 DC + 4 AC scans per component */
    else
      nscans = 2 + 4 * ncomps;	/* 2 DC scans; 4 AC scans per component */
  }

  /* Allocate space for script. */
  /* We use permanent pool just in case application re-uses script. */
  scanptr = (jpeg_scan_info *)
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
				nscans * SIZEOF(jpeg_scan_info));
  cinfo->scan_info = scanptr;
  cinfo->num_scans = nscans;

  if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
    /* Custom script for YCbCr color images. */
    /* Initial DC scan */
    scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
    /* Initial AC scan: get some luma data out in a hurry */
    scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2);
    /* Chroma data is too small to be worth expending many scans on */
    scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 1);
    scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 1);
    /* Complete spectral selection for luma AC */
    scanptr = fill_a_scan(scanptr, 0, 6, 63, 0, 2);
    /* Refine next bit of luma AC */
    scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1);
    /* Finish DC successive approximation */
    scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
    /* Finish AC successive approximation */
    scanptr = fill_a_scan(scanptr, 2, 1, 63, 1, 0);
    scanptr = fill_a_scan(scanptr, 1, 1, 63, 1, 0);
    /* Luma bottom bit comes last since it's usually largest scan */
    scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0);
  } else {
    /* All-purpose script for other color spaces. */
    /* Successive approximation first pass */
    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);
    /* Successive approximation second pass */
    scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1);
    /* Successive approximation final pass */
    scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
    scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0);
  }
}
Beispiel #4
0
jpeg_simple_progression (j_compress_ptr cinfo)
{
  int ncomps = cinfo->num_components;
  int nscans;
  jpeg_scan_info * scanptr;

  
  if (cinfo->global_state != CSTATE_START)
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);

  
  if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
    
    nscans = 10;
  } 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) {
    
    
    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 {
    
    
    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);
  }
}