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

📄 imgcompress.cpp

📁 《医学图象的远程传输系统》
💻 CPP
字号:
#include <windows.h>
#include <stdio.h>

#include "ImgCompress.h"
#include "..\Defines.h"

char g_ErrorMsg[4][200]={"","","",""};

BOOL APIENTRY DllMain(HANDLE hModule,DWORD dwReason,LPVOID lpReserved)
{
	return TRUE;
}

BOOL ICInit(const int Channel,JPEG_CORE_PROPERTIES* pjcprops)
{
	if (ijlInit(pjcprops)!=IJL_OK){
		sprintf(g_ErrorMsg[Channel],"ImgCompress: Init IJL library failed on channel %d !",Channel);
		return FALSE;
	}
	pjcprops->DIBChannels=3;
	pjcprops->DIBColor=IJL_BGR;
	pjcprops->JPGChannels=3;
	pjcprops->JPGColor=IJL_YCBCR;
	pjcprops->JPGSubsampling=IJL_411;
	pjcprops->JPGFile=NULL;
	return TRUE;
}

BOOL ICRelease(const int Channel,JPEG_CORE_PROPERTIES* pjcprops)
{
	if (ijlFree(pjcprops)!=IJL_OK){
		sprintf(g_ErrorMsg[Channel],"ImgCompress: Free IJL library failed on channel %d !",Channel);
		return FALSE;
	}
	return TRUE;
}

BOOL ICCompress(const int Channel,JPEG_CORE_PROPERTIES* pjcprops,BYTE* pBmp,BYTE** pJpg,int* JpegSize,BYTE Quality)
{
	if (Channel<0 || Channel>=4){
		sprintf(g_ErrorMsg[Channel],"ImgCompress: channel %d not exists!",Channel);
		return FALSE;
	}
	if (pBmp==NULL || *pJpg==NULL){
		sprintf(g_ErrorMsg[Channel],"ImgCompress: Memory myght not allocated on channel %d !",Channel);
		return FALSE;
	}
    if (Quality<0 || Quality>100){
        sprintf(g_ErrorMsg[Channel],"ImgCompress: Jpeg quality must in the range of 0-100!",Channel);
        return FALSE;
    }
	BITMAPFILEHEADER* bmfh=(BITMAPFILEHEADER*)pBmp;
	BITMAPINFOHEADER* bmih=(BITMAPINFOHEADER*)(pBmp+sizeof(BITMAPFILEHEADER));
	pjcprops->DIBWidth=bmih->biWidth;
	pjcprops->DIBHeight=-bmih->biHeight;
	pjcprops->DIBBytes=pBmp+sizeof(BITMAPINFOHEADER)+sizeof(BITMAPFILEHEADER);
	pjcprops->DIBPadBytes=IJL_DIB_PAD_BYTES(pjcprops->DIBWidth,pjcprops->DIBChannels);
	pjcprops->JPGWidth=bmih->biWidth;
	pjcprops->JPGHeight=bmih->biHeight;
	pjcprops->jquality=Quality; 
	pjcprops->JPGBytes=*pJpg;
	pjcprops->JPGSizeBytes=MAX_JPEG_SIZE;
	if (ijlWrite(pjcprops,IJL_JBUFF_WRITEWHOLEIMAGE)!=IJL_OK){
		sprintf(g_ErrorMsg[Channel],"ImgCompress: Error to compress image on channel %d !",Channel);
		return FALSE;
	}
	*JpegSize=pjcprops->JPGSizeBytes;//return the size of jpeg image
    return TRUE;
}

LPCTSTR ICGetLastError(const int Channel)
{
	if (Channel>=0 && Channel<4)
		return g_ErrorMsg[Channel];
	else
		return NULL;
}

⌨️ 快捷键说明

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