Exemplo n.º 1
0
decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
{   
  j_lossy_d_ptr lossyd = (j_lossy_d_ptr) cinfo->codec;
  phuff_entropy_ptr entropy = (phuff_entropy_ptr) lossyd->entropy_private;
  int Al = cinfo->Al;
  register int s, r;
  int blkn, ci;
  JBLOCKROW block;
  BITREAD_STATE_VARS;
  savable_state state;
  d_derived_tbl * tbl;
  jpeg_component_info * compptr;

  /* Process restart marker if needed; may have to suspend */
  if (cinfo->restart_interval) {
    if (entropy->restarts_to_go == 0)
      if (! process_restart(cinfo))
    return FALSE;
  }

  /* If we've run out of data, just leave the MCU set to zeroes.
   * This way, we return uniform gray for the remainder of the segment.
   */
  if (! entropy->insufficient_data) {

    /* Load up working state */
    BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
    ASSIGN_STATE(state, entropy->saved);

    /* Outer loop handles each block in the MCU */

    for (blkn = 0; blkn < cinfo->data_units_in_MCU; blkn++) {
      block = MCU_data[blkn];
      ci = cinfo->MCU_membership[blkn];
      compptr = cinfo->cur_comp_info[ci];
      tbl = entropy->derived_tbls[compptr->dc_tbl_no];

      /* Decode a single block's worth of coefficients */

      /* Section F.2.2.1: decode the DC coefficient difference */
      HUFF_DECODE(s, br_state, tbl, return FALSE, label1);
      if (s) {
    CHECK_BIT_BUFFER(br_state, s, return FALSE);
    r = GET_BITS(s);
    s = HUFF_EXTEND(r, s);
      }

      /* Convert DC difference to actual value, update last_dc_val */
      s += state.last_dc_val[ci];
      state.last_dc_val[ci] = s;
      /* Scale and output the coefficient (assumes jpeg_natural_order[0]=0) */
      (*block)[0] = (JCOEF) (s << Al);
    }

    /* Completed MCU, so update state */
    BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
    ASSIGN_STATE(entropy->saved, state);
  }
Exemplo n.º 2
0
METHODDEF       boolean decode_mcu_AC_first(j_decompress_ptr cinfo, JBLOCKROW * MCU_data)
{
	phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
	int             Se = cinfo->Se;
	int             Al = cinfo->Al;
	register int    s, k, r;
	unsigned int    EOBRUN;
	JBLOCKROW       block;

	BITREAD_STATE_VARS;
	d_derived_tbl  *tbl;

	/* Process restart marker if needed; may have to suspend */
	if(cinfo->restart_interval)
	{
		if(entropy->restarts_to_go == 0)
			if(!process_restart(cinfo))
				return FALSE;
	}

	/* Load up working state.
	 * We can avoid loading/saving bitread state if in an EOB run.
	 */
	EOBRUN = entropy->saved.EOBRUN;	/* only part of saved state we care about */

	/* There is always only one block per MCU */

	if(EOBRUN > 0)				/* if it's a band of zeroes... */
		EOBRUN--;				/* ...process it now (we do nothing) */
	else
	{
		BITREAD_LOAD_STATE(cinfo, entropy->bitstate);
		block = MCU_data[0];
		tbl = entropy->ac_derived_tbl;

		for(k = cinfo->Ss; k <= Se; k++)
		{
			HUFF_DECODE(s, br_state, tbl, return FALSE, label2);
			r = s >> 4;
			s &= 15;
			if(s)
			{
				k += r;
				CHECK_BIT_BUFFER(br_state, s, return FALSE);
				r = GET_BITS(s);
				s = HUFF_EXTEND(r, s);
				/* Scale and output coefficient in natural (dezigzagged) order */
				(*block)[jpeg_natural_order[k]] = (JCOEF) (s << Al);
			}
			else
			{
				if(r == 15)
				{				/* ZRL */
					k += 15;	/* skip 15 zeroes in band */
				}
				else
				{				/* EOBr, run length is 2^r + appended bits */
					EOBRUN = 1 << r;
					if(r)
					{			/* EOBr, r > 0 */
						CHECK_BIT_BUFFER(br_state, r, return FALSE);
						r = GET_BITS(r);
						EOBRUN += r;
					}
					EOBRUN--;	/* this band is processed at this moment */
					break;		/* force end-of-band */
				}
			}
		}

		BITREAD_SAVE_STATE(cinfo, entropy->bitstate);
	}
Exemplo n.º 3
0
boolean decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
{
    phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
    int Se = cinfo->Se;
    int Al = cinfo->Al;
    register int s, k, r;
    unsigned int EOBRUN;
    JBLOCKROW block;
    BITREAD_STATE_VARS;
    d_derived_tbl * tbl;

    /* Process restart marker if needed; may have to suspend */
    if (cinfo->restart_interval)
    {
        if (entropy->restarts_to_go == 0)
            if (! process_restart(cinfo))
                return FALSE;
    }

    /* If we've run out of data, just leave the MCU set to zeroes.
     * This way, we return uniform gray for the remainder of the segment.
     */
    if (! entropy->pub.insufficient_data)
    {

        /* Load up working state.
         * We can avoid loading/saving bitread state if in an EOB run.
         */
        EOBRUN = entropy->saved.EOBRUN;	/* only part of saved state we need */

        /* There is always only one block per MCU */

        if (EOBRUN > 0)		/* if it's a band of zeroes... */
            EOBRUN--;			/* ...process it now (we do nothing) */
        else
        {
            BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
            block = MCU_data[0];
            tbl = entropy->ac_derived_tbl;

            for (k = cinfo->Ss; k <= Se; k++)
            {
                if ( ! br_state.HUFF_DECODE(s, bits_left, get_buffer, tbl) )
                    return FALSE;

                r = s >> 4;
                s &= 15;
                if (s)
                {
                    k += r;
                    if ( ! br_state.CHECK_BIT_BUFFER(s, bits_left, get_buffer) )
                        return FALSE;

                    r = GET_BITS(s);
                    s = HUFF_EXTEND(r, s);
                    /* Scale and output coefficient in natural (dezigzagged) order */
                    (*block)[jpeg_natural_order[k]] = (JCOEF) (s << Al);
                }
                else
                {
                    if (r == 15)  	/* ZRL */
                    {
                        k += 15;		/* skip 15 zeroes in band */
                    }
                    else  		/* EOBr, run length is 2^r + appended bits */
                    {
                        EOBRUN = 1 << r;
                        if (r)  		/* EOBr, r > 0 */
                        {
                            if ( ! br_state.CHECK_BIT_BUFFER(r, bits_left, get_buffer) )
                                return FALSE;
                            r = GET_BITS(r);
                            EOBRUN += r;
                        }
                        EOBRUN--;		/* this band is processed at this moment */
                        break;		/* force end-of-band */
                    }
                }
            }

            BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
        }

        /* Completed MCU, so update state */
        entropy->saved.EOBRUN = EOBRUN;	/* only part of saved state we need */
    }
Exemplo n.º 4
0
decode_mcus (j_decompress_ptr cinfo, JDIFFIMAGE diff_buf,
         JDIMENSION MCU_row_num, JDIMENSION MCU_col_num, JDIMENSION nMCU)
{
  j_lossless_d_ptr losslsd = (j_lossless_d_ptr) cinfo->codec;
  lhuff_entropy_ptr entropy = (lhuff_entropy_ptr) losslsd->entropy_private;
  unsigned int mcu_num;
  int sampn, ci, yoffset, MCU_width, ptrn;
  BITREAD_STATE_VARS;

  /* Set output pointer locations based on MCU_col_num */
  for (ptrn = 0; ptrn < entropy->num_output_ptrs; ptrn++) {
    ci = entropy->output_ptr_info[ptrn].ci;
    yoffset = entropy->output_ptr_info[ptrn].yoffset;
    MCU_width = entropy->output_ptr_info[ptrn].MCU_width;
    entropy->output_ptr[ptrn] =
      diff_buf[ci][MCU_row_num + (JDIMENSION)yoffset] + MCU_col_num * (JDIMENSION)MCU_width;
  }

  /*
   * If we've run out of data, zero out the buffers and return.
   * By resetting the undifferencer, the output samples will be CENTERJSAMPLE.
   *
   * NB: We should find a way to do this without interacting with the
   * undifferencer module directly.
   */
  if (entropy->insufficient_data) {
    for (ptrn = 0; ptrn < entropy->num_output_ptrs; ptrn++)
      jzero_far((void FAR *) entropy->output_ptr[ptrn],
        nMCU * (size_t)entropy->output_ptr_info[ptrn].MCU_width * SIZEOF(JDIFF));

    (*losslsd->predict_process_restart) (cinfo);
  }

  else {

    /* Load up working state */
    BITREAD_LOAD_STATE(cinfo,entropy->bitstate);

    /* Outer loop handles the number of MCU requested */

    for (mcu_num = 0; mcu_num < nMCU; mcu_num++) {

      /* Inner loop handles the samples in the MCU */
      for (sampn = 0; sampn < cinfo->data_units_in_MCU; sampn++) {
    d_derived_tbl * dctbl = entropy->cur_tbls[sampn];
    register int s, r;

    /* Section H.2.2: decode the sample difference */
    HUFF_DECODE(s, br_state, dctbl, return mcu_num, label1);
    if (s) {
      if (s == 16)  /* special case: always output 32768 */
        s = 32768;
      else {    /* normal case: fetch subsequent bits */
        CHECK_BIT_BUFFER(br_state, s, return mcu_num);
        r = GET_BITS(s);
        s = HUFF_EXTEND(r, s);
      }
    }

    /* Output the sample difference */
    *entropy->output_ptr[entropy->output_ptr_index[sampn]]++ = (JDIFF) s;
      }

      /* Completed MCU, so update state */
      BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
    }
  }

 return nMCU;
}
Exemplo n.º 5
0
decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
{   
  phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
__boundcheck_metadata_store((void *)(&entropy),(void *)((size_t)(&entropy)+sizeof(entropy)*8-1));

  int Al = cinfo->Al;
__boundcheck_metadata_store((void *)(&Al),(void *)((size_t)(&Al)+sizeof(Al)*8-1));

  register int s, r;
  int blkn;
__boundcheck_metadata_store((void *)(&blkn),(void *)((size_t)(&blkn)+sizeof(blkn)*8-1));
int  ci;
__boundcheck_metadata_store((void *)(&ci),(void *)((size_t)(&ci)+sizeof(ci)*8-1));

  JBLOCKROW block;
__boundcheck_metadata_store((void *)(&block),(void *)((size_t)(&block)+sizeof(block)*8-1));

  BITREAD_STATE_VARS;
__boundcheck_metadata_store((void *)(&br_state),(void *)((size_t)(&br_state)+sizeof(br_state)*8-1));

  savable_state state;
__boundcheck_metadata_store((void *)(&state),(void *)((size_t)(&state)+sizeof(state)*8-1));

  d_derived_tbl * tbl;
__boundcheck_metadata_store((void *)(&tbl),(void *)((size_t)(&tbl)+sizeof(tbl)*8-1));

  jpeg_component_info * compptr;
__boundcheck_metadata_store((void *)(&compptr),(void *)((size_t)(&compptr)+sizeof(compptr)*8-1));


  /* Process restart marker if needed; may have to suspend */
  if (cinfo->restart_interval) {
    if (entropy->restarts_to_go == 0)
      if (! process_restart(cinfo))
	return FALSE;
  }

  /* Load up working state */
  BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  ASSIGN_STATE(state, entropy->saved);

  /* Outer loop handles each block in the MCU */

  for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
    block = (*(JBLOCKROW *)(__boundcheck_ptr_reference(307,13,"decode_mcu_DC_first",(void *)(&MCU_data[0]),(void *)(&MCU_data[blkn]))));
    ci = cinfo->MCU_membership[_RV_insert_check(0,10,308,10,"decode_mcu_DC_first",blkn)];
    compptr = cinfo->cur_comp_info[_RV_insert_check(0,4,309,15,"decode_mcu_DC_first",ci)];
    tbl = entropy->derived_tbls[_RV_insert_check(0,4,310,11,"decode_mcu_DC_first",compptr->dc_tbl_no)];

    /* Decode a single block's worth of coefficients */

    /* Section F.2.2.1: decode the DC coefficient difference */
    HUFF_DECODE(s, br_state, tbl, return FALSE, label1);
    if (s) {
      CHECK_BIT_BUFFER(br_state, s, return FALSE);
      r = GET_BITS(s);
      s = HUFF_EXTEND(r, s);
    }

    /* Convert DC difference to actual value, update last_dc_val */
    s += state.last_dc_val[_RV_insert_check(0,4,323,10,"decode_mcu_DC_first",ci)];
    state.last_dc_val[_RV_insert_check(0,4,324,5,"decode_mcu_DC_first",ci)] = s;
    /* Scale and output the DC coefficient (assumes jpeg_natural_order[0]=0) */
    (*(JBLOCKROW)(__boundcheck_ptr_reference(326,7,"decode_mcu_DC_first",(void *)(block),(void *)(block))))[0] = (JCOEF) (s << Al);
  }

  /* Completed MCU, so update state */
  BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  ASSIGN_STATE(entropy->saved, state);

  /* Account for restart interval (no-op if not using restarts) */
  entropy->restarts_to_go--;

  return TRUE;
}