资料介绍
[分享]JPEG压缩代码
[pic]楼主
[pic] [pic][pic][pic][pic][pic]
[pic]
[pic]
[分享]JPEG压缩代码
simplejpegenc.h
/*
这是一个简单的jpeg编码程序,支持1:1:1采样的baseline彩色jpeg,输入只能是24
bit的BMP文件
代码结构只求能说明各步骤过程,并不做特别的优化,效率较为一般。
*/
#ifndef __JENC__
#define __JENC__
#include
#include
#include
#include
#include
#include "jpeg.h"
#include "jpegformat.h"
using namespace std;
class JEnc
{
public:
// bmFile:输入文件
// jpgFile:输出文件
// Q:质量
void Invoke(string bmFile, string jpgFile, long Q)
{
FILE* pFile; // 输入文件句柄
if ((pFile = fopen(bmFile.c_str(),"rb")) == NULL) // 打开文件
{
throw("open bmp file error.");
}
//
获取jpeg编码需要的bmp数据结构,jpeg要求数据缓冲区的高和宽为8或16的倍数(视采样
方式而定)
BMBUFINFO bmBuffInfo = GetBMBuffSize(pFile);
imgWidth = bmBuffInfo.imgWidth; // 图像宽
imgHeight = bmBuffInfo.imgHeight;