Ejemplo n.º 1
0
emit_byte (j_compress_ptr cinfo, int val)
/* Emit a byte */
{
  struct jpeg_destination_mgr * dest = cinfo->dest;

  *(dest->next_output_byte)++ = (JOCTET) val;
  if (--dest->free_in_buffer == 0) {
    if (! (*dest->empty_output_buffer) (cinfo))
      cinfo->ERREXIT(JERR_CANT_SUSPEND);
  }
}
Ejemplo n.º 2
0
jinit_compress_master (j_compress_ptr cinfo)
{
  /* Initialize master control (includes parameter checking/processing) */
  jinit_c_master_control(cinfo, FALSE /* full compression */);

  /* Preprocessing */
  if (! cinfo->raw_data_in) {
    jinit_color_converter(cinfo);
    jinit_downsampler(cinfo);
    jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
  }
  /* Forward DCT */
  jinit_forward_dct(cinfo);
  /* Entropy encoding: either Huffman or arithmetic coding. */
  if (cinfo->arith_code) {
    cinfo->ERREXIT(JERR_ARITH_NOTIMPL);
  } else {
    if (cinfo->progressive_mode) {
#ifdef C_PROGRESSIVE_SUPPORTED
      jinit_phuff_encoder(cinfo);
#else
      ERREXIT(cinfo, JERR_NOT_COMPILED);
#endif
    } else
      jinit_huff_encoder(cinfo);
  }

  /* Need a full-image coefficient buffer in any multi-pass mode. */
  jinit_c_coef_controller(cinfo,
		(boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding));
  jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);

  jinit_marker_writer(cinfo);

	/* We can now tell the memory manager to allocate virtual arrays. */
	cinfo->mem->realize_virt_arrays ();

	/* Write the datastream header (SOI) immediately.
	* Frame and scan headers are postponed till later.
	* This lets application insert special markers after the SOI.
	*/
	(*cinfo->marker->write_file_header) (cinfo);
}
Ejemplo n.º 3
0
// Initialize for a processing pass.
void start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
{
  my_prep_ptr prep = (my_prep_ptr) cinfo->prep;

  if (pass_mode != JBUF_PASS_THRU)
    cinfo->ERREXIT(JERR_BAD_BUFFER_MODE);

  /* Initialize total-height counter for detecting bottom of image */
  prep->rows_to_go = cinfo->image_height;
  /* Mark the conversion buffer empty */
  prep->next_buf_row = 0;
#ifdef CONTEXT_ROWS_SUPPORTED
  /* Preset additional state variables for context mode.
   * These aren't used in non-context mode, so we needn't test which mode.
   */
  prep->this_row_group = 0;
  /* Set next_buf_stop to stop after two row groups have been read in. */
  prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
#endif
}
Ejemplo n.º 4
0
jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
{
  my_prep_ptr prep;
  int ci;
  jpeg_component_info * compptr;

  if (need_full_buffer)		/* safety check */
    cinfo->ERREXIT(JERR_BAD_BUFFER_MODE);

  prep = (my_prep_ptr)
    cinfo->mem->alloc_small(JPOOL_IMAGE, sizeof(my_prep_controller));
  cinfo->prep = (struct jpeg_c_prep_controller *) prep;
  prep->pub.start_pass = start_pass_prep;

  /* Allocate the color conversion buffer.
   * We make the buffer wide enough to allow the downsampler to edge-expand
   * horizontally within the buffer, if it so chooses.
   */
  if (cinfo->downsample->need_context_rows) {
    /* Set up to provide context rows */
#ifdef CONTEXT_ROWS_SUPPORTED
    prep->pub.pre_process_data = pre_process_context;
    create_context_buffer(cinfo);
#else
    ERREXIT(cinfo, JERR_NOT_COMPILED);
#endif
  } else {
    /* No context, just make it tall enough for one row group */
    prep->pub.pre_process_data = pre_process_data;
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
	 ci++, compptr++) {
      prep->color_buf[ci] = cinfo->mem->alloc_sarray
	(JPOOL_IMAGE,
	 (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
			cinfo->max_h_samp_factor) / compptr->h_samp_factor),
	 (JDIMENSION) cinfo->max_v_samp_factor);
    }
  }
}
Ejemplo n.º 5
0
void start_pass_fdctmgr (j_compress_ptr cinfo)
{
    my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
    int ci, qtblno, i;
    jpeg_component_info *compptr;
    JQUANT_TBL * qtbl;
    DCTELEM * dtbl;

    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
            ci++, compptr++)
    {
        qtblno = compptr->quant_tbl_no;
        /* Make sure specified quantization table is present */
        if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
                cinfo->quant_tbl_ptrs[qtblno] == NULL)
            cinfo->ERREXIT1(JERR_NO_QUANT_TABLE, qtblno);
        qtbl = cinfo->quant_tbl_ptrs[qtblno];
        /* Compute divisors for this quant table */
        /* We may do this more than once for same table, but it's not a big deal */
        switch (cinfo->dct_method)
        {
#ifdef DCT_ISLOW_SUPPORTED
        case JDCT_ISLOW:
            /* For LL&M IDCT method, divisors are equal to raw quantization
             * coefficients multiplied by 8 (to counteract scaling).
             */
            if (fdct->divisors[qtblno] == NULL)
            {
                fdct->divisors[qtblno] = (DCTELEM *)
                                         cinfo->mem->alloc_small (JPOOL_IMAGE, DCTSIZE2 * sizeof(DCTELEM));
            }
            dtbl = fdct->divisors[qtblno];
            for (i = 0; i < DCTSIZE2; i++)
            {
                dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3;
            }
            break;
#endif
#ifdef DCT_IFAST_SUPPORTED
        case JDCT_IFAST:
        {
            /* For AA&N IDCT method, divisors are equal to quantization
             * coefficients scaled by scalefactor[row]*scalefactor[col], where
             *   scalefactor[0] = 1
             *   scalefactor[k] = cos(k*PI/16) * sqrt(2)    for k=1..7
             * We apply a further scale factor of 8.
             */
#define CONST_BITS 14
            static const INT16 aanscales[DCTSIZE2] =
            {
                /* precomputed values scaled up by 14 bits */
                16384, 22725, 21407, 19266, 16384, 12873,  8867,  4520,
                22725, 31521, 29692, 26722, 22725, 17855, 12299,  6270,
                21407, 29692, 27969, 25172, 21407, 16819, 11585,  5906,
                19266, 26722, 25172, 22654, 19266, 15137, 10426,  5315,
                16384, 22725, 21407, 19266, 16384, 12873,  8867,  4520,
                12873, 17855, 16819, 15137, 12873, 10114,  6967,  3552,
                8867, 12299, 11585, 10426,  8867,  6967,  4799,  2446,
                4520,  6270,  5906,  5315,  4520,  3552,  2446,  1247
            };
            SHIFT_TEMPS

            if (fdct->divisors[qtblno] == NULL)
            {
                fdct->divisors[qtblno] = (DCTELEM *)
                                         cinfo->mem->alloc_small (JPOOL_IMAGE, DCTSIZE2 * sizeof(DCTELEM));
            }
            dtbl = fdct->divisors[qtblno];
            for (i = 0; i < DCTSIZE2; i++)
            {
                dtbl[i] = (DCTELEM)
                          DESCALE((long) qtbl->quantval[i] * (long) aanscales[i],
                                  CONST_BITS-3);
            }
        }
        break;
#endif
#ifdef DCT_FLOAT_SUPPORTED
        case JDCT_FLOAT:
        {
            /* For float AA&N IDCT method, divisors are equal to quantization
             * coefficients scaled by scalefactor[row]*scalefactor[col], where
             *   scalefactor[0] = 1
             *   scalefactor[k] = cos(k*PI/16) * sqrt(2)    for k=1..7
             * We apply a further scale factor of 8.
             * What's actually stored is 1/divisor so that the inner loop can
             * use a multiplication rather than a division.
             */
            FAST_FLOAT * fdtbl;
            int row, col;
            static const double aanscalefactor[DCTSIZE] =
            {
                1.0, 1.387039845, 1.306562965, 1.175875602,
                1.0, 0.785694958, 0.541196100, 0.275899379
            };

            if (fdct->float_divisors[qtblno] == NULL)
            {
                fdct->float_divisors[qtblno] = (FAST_FLOAT *)
                                               cinfo->mem->alloc_small (JPOOL_IMAGE,
                                                       DCTSIZE2 * sizeof(FAST_FLOAT));
            }
            fdtbl = fdct->float_divisors[qtblno];
            i = 0;
            for (row = 0; row < DCTSIZE; row++)
            {
                for (col = 0; col < DCTSIZE; col++)
                {
                    fdtbl[i] = (FAST_FLOAT)
                               (1.0 / (((double) qtbl->quantval[i] *
                                        aanscalefactor[row] * aanscalefactor[col] * 8.0)));
                    i++;
                }
            }
        }
        break;
#endif
        default:
            cinfo->ERREXIT(JERR_NOT_COMPILED);
            break;
        }
    }
}