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

📄 jdmainct.c

📁 MCB2300_ucgui_LCD320240.rar LPC2368的uc/gui的移植
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Change the pointer lists to duplicate the last sample row at the bottom
 * of the image.  whichptr indicates which xbuffer holds the final iMCU row.
 * Also sets rowgroups_avail to indicate number of nondummy row groups in row.
 */
{
	my_main_ptr pMain = (my_main_ptr) cinfo->main;
	int ci, i, rgroup, iMCUheight, rows_left;
	jpeg_component_info *compptr;
	JSAMPARRAY xbuf;

	for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; ci++, compptr++)
	{
		/* Count sample rows in one iMCU row and in one row group */
		iMCUheight = compptr->v_samp_factor * compptr->DCT_scaled_size;
		rgroup = iMCUheight / cinfo->min_DCT_scaled_size;
		/* Count nondummy sample rows remaining for this component */
		rows_left = (int) (compptr->downsampled_height % (JDIMENSION) iMCUheight);
		if (rows_left == 0)
		{
			rows_left = iMCUheight;
		}
		/* Count nondummy row groups.  Should get same answer for each component,
		 * so we need only do it once.
		 */
		if (ci == 0)
		{
			pMain->rowgroups_avail = (JDIMENSION) ((rows_left - 1) / rgroup + 1);
		}
		/* Duplicate the last real sample row rgroup*2 times; this pads out the
		 * last partial rowgroup and ensures at least one full rowgroup of context.
		 */
		xbuf = pMain->xbuffer[pMain->whichptr][ci];
		for (i = 0; i < rgroup * 2; i++)
		{
			xbuf[rows_left + i] = xbuf[rows_left - 1];
		}
	}
}


/*
 * Initialize for a processing pass.
 */

METHODDEF(void)
start_pass_main(j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
{
	my_main_ptr pMain = (my_main_ptr) cinfo->main;

	switch (pass_mode)
	{
		case JBUF_PASS_THRU:
			if (cinfo->upsample->need_context_rows)
			{
				pMain->pub.process_data = process_data_context_main;
				make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
				pMain->whichptr = 0;	/* Read first iMCU row into xbuffer[0] */
				pMain->context_state = CTX_PREPARE_FOR_IMCU;
				pMain->iMCU_row_ctr = 0;
			}
			else
			{
				/* Simple case with no context needed */
				pMain->pub.process_data = process_data_simple_main;
			}
			pMain->buffer_full = FALSE;	/* Mark buffer empty */
			pMain->rowgroup_ctr = 0;
			break;
#ifdef QUANT_2PASS_SUPPORTED
		case JBUF_CRANK_DEST:
			/* For last pass of 2-pass quantization, just crank the postprocessor */
			pMain->pub.process_data = process_data_crank_post;
			break;
#endif
		default:
			ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
			break;
	}
}


/*
 * Process some data.
 * This handles the simple case where no context is required.
 */

METHODDEF(void)
process_data_simple_main(j_decompress_ptr cinfo, JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
{
	my_main_ptr pMain = (my_main_ptr) cinfo->main;
	JDIMENSION rowgroups_avail;

	/* Read input data if we haven't filled the main buffer yet */
	if (!pMain->buffer_full)
	{
		if (!(*cinfo->coef->decompress_data) (cinfo, pMain->buffer))
		{
			return;
		}			/* suspension forced, can do nothing more */
		pMain->buffer_full = TRUE;	/* OK, we have an iMCU row to work with */
	}

	/* There are always min_DCT_scaled_size row groups in an iMCU row. */
	rowgroups_avail = (JDIMENSION) cinfo->min_DCT_scaled_size;
	/* Note: at the bottom of the image, we may pass extra garbage row groups
	 * to the postprocessor.  The postprocessor has to check for bottom
	 * of image anyway (at row resolution), so no point in us doing it too.
	 */

	/* Feed the postprocessor */
	(*cinfo->post->post_process_data) (cinfo, pMain->buffer, & pMain->rowgroup_ctr, rowgroups_avail, output_buf, out_row_ctr, out_rows_avail);

	/* Has postprocessor consumed all the data yet? If so, mark buffer empty */
	if (pMain->rowgroup_ctr >= rowgroups_avail)
	{
		pMain->buffer_full = FALSE;
		pMain->rowgroup_ctr = 0;
	}
}


/*
 * Process some data.
 * This handles the case where context rows must be provided.
 */

METHODDEF(void)
process_data_context_main(j_decompress_ptr cinfo, JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
{
	my_main_ptr pMain = (my_main_ptr) cinfo->main;

	/* Read input data if we haven't filled the main buffer yet */
	if (!pMain->buffer_full)
	{
		if (!(*cinfo->coef->decompress_data) (cinfo, pMain->xbuffer[pMain->whichptr]))
		{
			return;
		}			/* suspension forced, can do nothing more */
		pMain->buffer_full = TRUE;	/* OK, we have an iMCU row to work with */
		pMain->iMCU_row_ctr++;	/* count rows received */
	}

	/* Postprocessor typically will not swallow all the input data it is handed
	 * in one call (due to filling the output buffer first).  Must be prepared
	 * to exit and restart.  This switch lets us keep track of how far we got.
	 * Note that each case falls through to the next on successful completion.
	 */
	switch (pMain->context_state)
	{
		case CTX_POSTPONED_ROW:
			/* Call postprocessor using previously set pointers for postponed row */
			(*cinfo->post->post_process_data) (cinfo, pMain->xbuffer[pMain->whichptr], & pMain->rowgroup_ctr, pMain->rowgroups_avail, output_buf, out_row_ctr, out_rows_avail);
			if (pMain->rowgroup_ctr < pMain->rowgroups_avail)
			{
				return;
			}			/* Need to suspend */
			pMain->context_state = CTX_PREPARE_FOR_IMCU;
			if (*out_row_ctr >= out_rows_avail)
			{
				return;
			}			/* Postprocessor exactly filled output buf */
			/*FALLTHROUGH*/
		case CTX_PREPARE_FOR_IMCU:
			/* Prepare to process first M-1 row groups of this iMCU row */
			pMain->rowgroup_ctr = 0;
			pMain->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size - 1);
			/* Check for bottom of image: if so, tweak pointers to "duplicate"
			 * the last sample row, and adjust rowgroups_avail to ignore padding rows.
			 */
			if (pMain->iMCU_row_ctr == cinfo->total_iMCU_rows)
			{
				set_bottom_pointers(cinfo);
			}
			pMain->context_state = CTX_PROCESS_IMCU;
			/*FALLTHROUGH*/
		case CTX_PROCESS_IMCU:
			/* Call postprocessor using previously set pointers */
			(*cinfo->post->post_process_data) (cinfo, pMain->xbuffer[pMain->whichptr], & pMain->rowgroup_ctr, pMain->rowgroups_avail, output_buf, out_row_ctr, out_rows_avail);
			if (pMain->rowgroup_ctr < pMain->rowgroups_avail)
			{
				return;
			}			/* Need to suspend */
			/* After the first iMCU, change wraparound pointers to normal state */
			if (pMain->iMCU_row_ctr == 1)
			{
				set_wraparound_pointers(cinfo);
			}
			/* Prepare to load new iMCU row using other xbuffer list */
			pMain->whichptr ^= 1;	/* 0=>1 or 1=>0 */
			pMain->buffer_full = FALSE;
			/* Still need to process last row group of this iMCU row, */
			/* which is saved at index M+1 of the other xbuffer */
			pMain->rowgroup_ctr = (JDIMENSION) (cinfo->min_DCT_scaled_size + 1);
			pMain->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size + 2);
			pMain->context_state = CTX_POSTPONED_ROW;
	}
}


/*
 * Process some data.
 * Final pass of two-pass quantization: just call the postprocessor.
 * Source data will be the postprocessor controller's internal buffer.
 */

#ifdef QUANT_2PASS_SUPPORTED

METHODDEF(void)
process_data_crank_post(j_decompress_ptr cinfo, JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
{
	(*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL, (JDIMENSION *) NULL, (JDIMENSION) 0, output_buf, out_row_ctr, out_rows_avail);
}

#endif /* QUANT_2PASS_SUPPORTED */


/*
 * Initialize main buffer controller.
 */

GLOBAL(void)
jinit_d_main_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
{
	my_main_ptr pMain;
	int ci, rgroup, ngroups;
	jpeg_component_info *compptr;

	pMain = (my_main_ptr) (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(my_main_controller));
	cinfo->main = (struct jpeg_d_main_controller *) pMain;
	pMain->pub.start_pass = start_pass_main;

	if (need_full_buffer)		/* shouldn't happen */
	{
		ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
	}

	/* Allocate the workspace.
	 * ngroups is the number of row groups we need.
	 */
	if (cinfo->upsample->need_context_rows)
	{
		if (cinfo->min_DCT_scaled_size < 2) /* unsupported, see comments above */
		{
			ERREXIT(cinfo, JERR_NOTIMPL);
		}
		alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
		ngroups = cinfo->min_DCT_scaled_size + 2;
	}
	else
	{
		ngroups = cinfo->min_DCT_scaled_size;
	}

	for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; ci++, compptr++)
	{
		rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) / cinfo->min_DCT_scaled_size; /* height of a row group of component */
		pMain->buffer[ci] = (*cinfo->mem->alloc_sarray) ((j_common_ptr) cinfo, JPOOL_IMAGE, compptr->width_in_blocks * compptr->DCT_scaled_size, (JDIMENSION) (rgroup * ngroups));
	}
}

⌨️ 快捷键说明

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