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

📄 cmjpghdrbuild.c

📁 MatLab图像传感器网络仿真平台WiSNAP
💻 C
字号:
/*******************************************************************************
 * Attach a JPEG header to ADCM-1670 JPEG data.                                *
 * Syntax: Jpeg = cmJpgHdrBuild(Buffer, Length, Type, Width, Height)           *
 *                                                                             *
 *    Input Parameters:                                                        *
 *    ================                                                         *
 *                                                                             *
 *       Buffer ------> Buffer containing ADCM-1670 JPEG data (array).         *
 *       Type --------> JPEG image type downsampling (positive integer).       *
 *       Width -------> Image width in pixels (positive integer).              *
 *       Height ------> Image height in pixels (positive integer).             *
 *                                                                             *
 *    Output Parameters:                                                       *
 *    =================                                                        *
 *                                                                             *
 *       Jpeg --------> JPEG image data (array).	                            *
 *                                                                             *
 *    See also N/A.                                                            *
 *                                                                             *
 * Compile: mex -v cmJpgHdrBuild.c cmJpgHdr.c                                  *
 * Version: 01-22-2005                                                         *
 *                                                                             *
 * (C) 2005 Stephan Hengstler, Stanford Wireless Sensor Networks Lab           *
 *******************************************************************************/


#include <stdio.h>
#include <windows.h>
#include "mex.h"
#include "cmApiCom.h"#include "cmJpgHdr.h"

void mexFunction(int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[])
{
	double			*buffer, *result;
	int				height, i, length, size, type, width;
	unsigned char	*imager, *jpeg;

	/* get the value(s) of the input variable(s) */
	buffer		= (double *) mxGetPr(prhs[0]);
	type			= (int) mxGetScalar(prhs[1]);
	width			= (int) mxGetScalar(prhs[2]);
	height		= (int) mxGetScalar(prhs[3]);

	/* determine buffer length */
	length		= mxGetNumberOfElements(prhs[0]);

	/* allocate imager and copy buffer */
	imager 		= (unsigned char *) mxCalloc(length+1, sizeof(unsigned char));
	for (i = 0; i < length; i++)
		imager[i]	= (unsigned char) buffer[i];

	/* determine maximum jpeg size */
	size			= 352*352*3+sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);

	/* allocate jpeg */
	jpeg 			= (unsigned char *) mxCalloc(size+1, sizeof(unsigned char));

	/* call the respective subroutine(s) */
	cmJpgHdrBuild (imager, length, jpeg, &size, type, width, height);

	/* set the value(s) of the output variable(s) */
	plhs[0]		= mxCreateDoubleMatrix(1, size, mxREAL);
	result		= mxGetPr(plhs[0]);
	for (i = 0; i < size; i++)
		result[i]	= (double) jpeg[i];

   /* show debug information */
	if (nrhs == 5)
	{
		printf("Debug Information\n");
		printf("buffer		= ");
		for (i = 0; i < 16; i++)
			printf("%3.0f ", buffer[i]);
		printf("...\n");
		printf("type		= %d\n", type);
		printf("width		= %d\n", width);
		printf("height		= %d\n", height);
		printf("length   	= %d\n", length);
		printf("imager		= ");
		for (i = 0; i < 16; i++)
			printf("%3d ", imager[i]);
		printf("...\n");
		printf("size		= %d\n", size);
		printf("jpeg		= ");
		for (i = 0; i < 16; i++)
			printf("%3d ", jpeg[i]);
		printf("...\n");
	}

	/* clean exit */
	return;
}

⌨️ 快捷键说明

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