jpeg压缩

	CImageCompresser *pThisObject=(CImageCompresser *)pArgue;
	BYTE *pData=NULL;
	BYTE *pDataJPGIn = new BYTE[10000000];
	int nWidth,nHeight,nBytesPerPix,nIndex,nMirrorImage;
	int nAdjust;
	int i,j;
	long count;
	int nLost = 0;

	while ((pThisObject->m_nCompress==1)||(pData!=NULL))
	{
		pData = pThisObject->BufferOut(&nWidth,&nHeight,&nBytesPerPix,&nIndex);
		if (pData==NULL) 
		{
			Sleep(100);
			continue;
		}

		nAdjust = nWidth*nBytesPerPix%4;
		if (nAdjust>0) nAdjust = 4-nAdjust;

		if (nBytesPerPix==3){
			for (j=0;j<nHeight;j++){
				for (i = 0;i<nWidth;i++)
				{
					pDataJPGIn[j*(nWidth*3+nAdjust)+i*3] = pData[j*(nWidth*3+nAdjust)+i*3+2];
					pDataJPGIn[j*(nWidth*3+nAdjust)+i*3+1] = pData[j*(nWidth*3+nAdjust)+i*3+1];
					pDataJPGIn[j*(nWidth*3+nAdjust)+i*3+2] = pData[j*(nWidth*3+nAdjust)+i*3];
				}
			}
		}else{
			for (j=0;j<nHeight;j++){
				for (i = 0;i<nWidth;i++)
				{
					pDataJPGIn[j*(nWidth+nAdjust)+i] = pData[j*(nWidth+nAdjust)+i];
				}
			}
		}
		delete [] pData;
		pData = NULL;

		FILE *f;
		char strPathName[255];//路径名
		sprintf_s(strPathName, "%s\\", theApp.m_strPicFullPath);
		char strDestFileName[255];//带路径图片名
		sprintf_s(strDestFileName,"%s%s%d.jpg",strPathName,theApp.m_Channel,nIndex);

		fopen_s(&f,strDestFileName,"wb");
		if (f==NULL) 
		{
			delete [] pDataJPGIn;
			return;
		}

		struct jpeg_compress_struct jcs;
		jpeg_create_compress(&jcs);
		struct jpeg_error_mgr jem;
		jcs.err = jpeg_std_error(&jem);
		jpeg_stdio_dest(&jcs, f);

		jcs.image_width = nWidth; 			
		jcs.image_height = nHeight;
		jcs.input_components = nBytesPerPix;			 
		if (nBytesPerPix==1)
			jcs.in_color_space = JCS_GRAYSCALE; 
		else 
			jcs.in_color_space = JCS_RGB;

		jpeg_set_defaults(&jcs);	
		jpeg_set_quality (&jcs, 80, true);
		jpeg_start_compress(&jcs, TRUE);

		JSAMPROW row_pointer[1];			
		int row_stride;			

		row_stride = jcs.image_width*nBytesPerPix;		
		while (jcs.next_scanline < jcs.image_height) {
			row_pointer[0] = & pDataJPGIn[jcs.next_scanline * (row_stride+nAdjust)];
			jpeg_write_scanlines(&jcs, row_pointer, 1);
		}

		jpeg_finish_compress(&jcs);
		jpeg_destroy_compress(&jcs);
		fclose(f);

		theApp.m_iSaveImageCount++;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码猿杂谈

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值