⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jdcoefct.c

📁 基于Linux的ffmepg decoder
💻 C
📖 第 1 页 / 共 5 页
字号:
    buffer[ci] = (*cinfo->mem->access_virt_barray)
      ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
       cinfo->input_iMCU_row * compptr->v_samp_factor,
       (JDIMENSION) compptr->v_samp_factor, TRUE);
    // Note: entropy decoder expects buffer to be zeroed,
    // but this is handled automatically by the memory manager
    // because we requested a pre-zeroed array.
    //
  }

  // Loop to process one whole iMCU row
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
       yoffset++) {
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
	 MCU_col_num++) {
      // Construct list of pointers to DCT blocks belonging to this MCU
      blkn = 0;			// index of current DCT block within MCU
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
	compptr = cinfo->cur_comp_info[ci];
	start_col = MCU_col_num * compptr->MCU_width;
	for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
	  buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
	  for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
	    coef->MCU_buffer[blkn++] = buffer_ptr++;
	  }
	}
      }
      // Try to fetch the MCU.
      if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
	// Suspension forced; update state counters and exit
	coef->MCU_vert_offset = yoffset;
	coef->MCU_ctr = MCU_col_num;
	return JPEG_SUSPENDED;
      }
    }
    // Completed an MCU row, but perhaps not an iMCU row
    coef->MCU_ctr = 0;
  }
  // Completed the iMCU row, advance counters for next one
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
    start_iMCU_row(cinfo);
    return JPEG_ROW_COMPLETED;
  }
  // Completed the scan
  (*cinfo->inputctl->finish_input_pass) (cinfo);
  return JPEG_SCAN_COMPLETED;
  */
}


/*
 * Decompress and return some data in the multi-pass case.
 * Always attempts to emit one fully interleaved MCU row ("iMCU" row).
 * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
 *
 * NB: output_buf contains a plane for each component in image.
 */

METHODDEF(int)
decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
{
#ifdef USE_INTERNAL_CPU
  int retcode;
  unsigned int v,s,bitlen=0;
  unsigned int last_bit;
  unsigned int command;
  //boolean very_first_time=TRUE;
  FTMCP100_CODEC *pCodec=(FTMCP100_CODEC *)cinfo->pCodec;
  
  struct jpeg_decompress_embedded_struct *pdecinfo=(struct jpeg_decompress_embedded_struct *)JPG_DEC_INFO;
  
  //outdata_len=0; // we initialize the global variables here...@##@!#...
  
  command=2; // 2 : to instruct internal CPU to do non-interleaved decoding for the very first time.
  for(;;) 
    {
       unsigned int mcctl_reg;
       //unsigned int start_inter_cpu;
       ftmcp100_set_mcu_dma_noninterleaved_params(cinfo);
       
       // store the parameters used for internal CPU  
       store_embedded_cpu_parameters(cinfo,pdecinfo);
  
       pdecinfo->external_cpu_response=0;
       pdecinfo->internal_cpu_command=command; // to instruct the internal CPU to do non-interleaved decoding for the very first time
       
       #ifdef VPE_OUTPUT
         RTL_DEBUG_OUT(0x90000000 | 0x210) // begin to start the internal CPU
       #endif
       
       // start the internal CPU only for the very first time
       //if(very_first_time) {
         //__asm{		
           SET_INCTL(1<<18)
         //}
       //}

      // to wait for internal CPU's response by querying the 'pdecinfo->external_cpu_response' variable
      POLL_EXTERNAL_CPU_RESPONSE_START        
      #ifdef VPE_OUTPUT
        RTL_DEBUG_OUT(0x90000000 | pdecinfo->internal_cpu_command) // show the pdecinfo->internal_cpu_command
      #endif       
      while(pdecinfo->external_cpu_response!=2) 
        { int i;  for(i=0;i<10000; i++) { }  
          #ifdef VPE_OUTPUT
            RTL_DEBUG_OUT(0x90000000 | 0x211) // still querying the external CPU
          #endif
        }        
      command=3; // 3 : to instruct internal CPU to do next non-interleaved decoding.
      //very_first_time=FALSE;
      POLL_EXTERNAL_CPU_RESPONSE_END
  
      #ifdef VPE_OUTPUT
        RTL_DEBUG_OUT(0x90000000 | 0x2ff) // end of starting the internal CPU
      #endif      
       //retcode=decompress_noninterleaved_data(cinfo,output_buf);
	   //if (retcode == JPEG_REACHED_EOI)
	   //  break;
	   
	   
	   // we make JPEG mode off because sometimes 0xff00 may occur before
	   // any marker (such as 0xffd9 EOI marker), so we need to work around here...
	   // it was caused by the testsuite -- 422_q95_rst7_non-inter -- c071
	   // take a look at the end of EOI marker...
	   READ_MCCTL(mcctl_reg) //__asm {  READ_MCCTL(mcctl_reg) }
	   mcctl_reg=mcctl_reg &0x0fffffdff; // disable JPEG mode
	   SET_MCCTL(mcctl_reg) //__asm {  SET_MCCTL(mcctl_reg) }	   
	     
	   // before absorbing more inputs, we need to sacn to the byte boundary
	   READ_BADR(v) //__asm { READ_BADR(v) }
	   READ_VADR(s) //__asm { READ_VADR(s) }
	   last_bit=(s&0x001f);
	   bitlen=(8-(last_bit%8))%8;
	   SET_BALR(bitlen) //__asm { SET_BALR(bitlen) }	   
	   
	   // absort any unwanted zero before going to absorb marker
	   // because in hardware the priority of reconstruction of zero
	   // is higher than SET_BALR()
	   READ_BADR(v) //__asm { READ_BADR(v) } // for debug usage
	   if(!(v&0x0ff000000)) 	   
  	     SET_BALR(8) //__asm { SET_BALR(8) } // absorb zeros
	   
	   //__asm { READ_BADR(v) } // for debug usage
	   //__asm { SET_BALR(0) } // for debug usage
	   
       // Absorb some more inputs
       (*cinfo->inputctl->finish_input_pass) (cinfo);
       retcode = (*cinfo->inputctl->consume_input) (cinfo);
  
       //if (retcode == JPEG_SUSPENDED)
       //  return FALSE;
       if (retcode == JPEG_REACHED_EOI)
         break;
       //return JPEG_SCAN_COMPLETED;
    }
  
  // 0 : to instruct internal CPU to stop and exit decoding
  pdecinfo->internal_cpu_command=0;
  
  cinfo->output_scanline=cinfo->output_height; // to force the previous caller in djpeg.c to leave the loop
  return FALSE; // to force the caller to leave the loop
  
#else // else of #ifdef USE_INTERNAL_CPU

  int retcode;  
  unsigned int v,s,bitlen=0;
  unsigned int last_bit;  
  FTMCP100_CODEC *pCodec=(FTMCP100_CODEC *)cinfo->pCodec;

  for(;;) 
    {
       unsigned int mcctl_reg;
       ftmcp100_set_mcu_dma_noninterleaved_params(cinfo);
       // we need to flush the D cache or the result will be wrong
       FA526_CleanInvalidateDCacheAll();
       
       retcode=decompress_noninterleaved_data(cinfo,output_buf);
	   if (retcode == JPEG_REACHED_EOI)
	     break;
	   
	   // we make JPEG mode off because sometimes 0xff00 may occur before
	   // any marker (such as 0xffd9 EOI marker), so we need to work around here...
	   // it was caused by the testsuite -- 422_q95_rst7_non-inter -- c071
	   // take a look at the end of EOI marker...
	   READ_MCCTL(mcctl_reg)
	   mcctl_reg=mcctl_reg &0x0fffffdff; // disable JPEG mode
	   SET_MCCTL(mcctl_reg)
	     
	   // before absorbing more inputs, we need to sacn to the byte boundary
	   READ_BADR(v)
	   READ_VADR(s)
	   last_bit=(s&0x001f);
	   bitlen=(8-(last_bit%8))%8;
	   SET_BALR(bitlen)
	   
	   // absort any unwanted zero before going to absorb marker
	   // because in hardware the priority of reconstruction of zero
	   // is higher than SET_BALR()
	   READ_BADR(v)
	   if(!(v&0x0ff000000))
  	     SET_BALR(8) // absorb zeros
	   
	   // READ_BADR(v) // for debug usage
	   // SET_BALR(0) // for debug usage
	   
       // Absorb some more inputs
       (*cinfo->inputctl->finish_input_pass) (cinfo);
       retcode = (*cinfo->inputctl->consume_input) (cinfo);
  
       //if (retcode == JPEG_SUSPENDED)
       //  return FALSE;
       if (retcode == JPEG_REACHED_EOI)
         break;
       //return JPEG_SCAN_COMPLETED;
    }
    

  cinfo->output_scanline=cinfo->output_height; // to force the previous caller in djpeg.c to leave the loop
  return FALSE; // to force the caller to leave the loop
#endif // end of #ifdef USE_INTERNAL_CPU

  /* original code 
  
  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  JDIMENSION block_num;
  int ci, block_row, block_rows;
  JBLOCKARRAY buffer;
  JBLOCKROW buffer_ptr;
  JSAMPARRAY output_ptr;
  JDIMENSION output_col;
  jpeg_component_info *compptr;
  inverse_DCT_method_ptr inverse_DCT;

  // Force some input to be done if we are getting ahead of the input.
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
	 (cinfo->input_scan_number == cinfo->output_scan_number &&
	  cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
    if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
      return JPEG_SUSPENDED;
  }

  // OK, output from the virtual arrays.
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
       ci++, compptr++) {
    // Don't bother to IDCT an uninteresting component.
    if (! compptr->component_needed)
      continue;
    // Align the virtual buffer for this component.
    buffer = (*cinfo->mem->access_virt_barray)
      ((j_common_ptr) cinfo, coef->whole_image[ci],
       cinfo->output_iMCU_row * compptr->v_samp_factor,
       (JDIMENSION) compptr->v_samp_factor, FALSE);
    // Count non-dummy DCT block rows in this iMCU row.
    if (cinfo->output_iMCU_row < last_iMCU_row)
      block_rows = compptr->v_samp_factor;
    else {
      // NB: can't use last_row_height here; it is input-side-dependent!
      block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
    }
    inverse_DCT = cinfo->idct->inverse_DCT[ci];
    output_ptr = output_buf[ci];
    // Loop over all DCT blocks to be processed.
    for (block_row = 0; block_row < block_rows; block_row++) {
      buffer_ptr = buffer[block_row];
      output_col = 0;
      for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) {
	(*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,
			output_ptr, output_col);
	buffer_ptr++;
	output_col += compptr->DCT_scaled_size;
      }
      output_ptr += compptr->DCT_scaled_size;
    }
  }

  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
    return JPEG_ROW_COMPLETED;
  return JPEG_SCAN_COMPLETED;
  
  */
}

#endif /* D_MULTISCAN_FILES_SUPPORTED */


// added by Leo
#ifndef USE_INTERNAL_CPU
GLOBAL(int) decompress_noninterleaved_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
{
  FTMCP100_CODEC *pCodec=(FTMCP100_CODEC *)cinfo->pCodec;
  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  JDIMENSION MCU_col_num;	// index of current MCU within row
  JDIMENSION MCU_row_num;	// index of current MCU within row
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  //JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  //int blkn, xindex, yindex,ci;
  int yoffset;
  //JDIMENSION start_col;
  //JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  //JBLOCKROW buffer_ptr;
  //jpeg_component_info *compptr;
  
  boolean stage_active[3]= { FALSE,FALSE,FALSE }; // VLD-DZ , DQ-MC , DMA stages
  JDIMENSION m[3]={ 0, 0, 0 };  // the MCU_col_num stack 
  
  // we made it static since we usually need to reserve descriptor status because of restart marker
  //static int buf_descriptor1=0; // used to select ping pong buffer for VLD output
  //static int buf_descriptor2=0; // used to select buffer between DQ-MC stage and DMA stage (indicated by MCIADDR for DQ-MC engine output)
  
  unsigned int cpsts_reg,vldsts_reg,vldctl_reg;
  unsigned int dzar_qar;
  unsigned int *mciaddr_ptr;
  volatile MDMA *pmdma = MDMA1; // used to access the DMA register

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -