#include <npp.h>
#include <cuda_runtime.h>
#include <Exceptions.h>
#include "Endianess.h"
#include <math.h>
#include <cmath>
#include <string.h>
#include <fstream>
#include <iostream>
#include <helper_string.h>
#include <helper_cuda.h>
#include "gh_jpegnpp.h"
//量化表数据
typedef struct
{
unsigned char nPrecisionAndIdentifier;
unsigned char aTable[64];
} QuantizationTable;
//图片信息
typedef struct
{
unsigned char nSamplePrecision;
unsigned short nHeight;
unsigned short nWidth;
unsigned char nComponents;
unsigned char aComponentIdentifier[3];
unsigned char aSamplingFactors[3];
unsigned char aQuantizationTableSelector[3];
} FrameHeader;
//扫描头
typedef struct
{
unsigned char nComponents;
unsigned char aComponentSelector[3];
unsigned char aHuffmanTablesSelector[3];
unsigned char nSs;
unsigned char nSe;
unsigned char nA;
} ScanHeader;
//霍夫曼编码表数据,一般是固定的
typedef struct
{
unsigned char nClassAndIdentifier;
unsigned char aCodes[16];
unsigned char aTable[256];
} HuffmanTable;
class CudaJpegEncode
{
public:
CudaJpegEncode();
~CudaJpegEncode();
public:
void Init(int quality, const RectSize* pImageSize);
void SetQuality(unsigned char* pTable, const unsigned char* pTable50, int quality);
void Release();
public:
int EncodeJpeg(const IMAGE_DEST dest, char* pDest);
void SetData(const DataBuffer* pImageBuffer, int yuv_fmt, const RectSize* pImageSize);
public:
NppiDCTState* pDCTState;
FrameHeader oFrameHeader;
QuantizationTable aQuantizationTables[4];
Npp8u* pdQuantizationTables;
HuffmanTable aHuffmanTables[4];
//HuffmanTable* pHuffmanDCTables = aHuffmanTables;
//HuffmanTable* pHuffmanACTables = &aHuffmanTables[2];
HuffmanTable* pHuffmanDCTables;
HuffmanTable* pHuffmanACTables;
ScanHeader oScanHeader;
NppiSize aSrcSize[3];
Npp16s *apdDCT[3];
Npp32s aDCTStep[3];
Npp8u *apSrcImage[3];
Npp32s aSrcImageStep[3];
size_t aSrcPitch[3];
NppiEncodeHuffmanSpec *apHuffmanDCTable[3];
NppiEncodeHuffmanSpec *apHuffmanACTable[3];
int nMCUBlocksH;
int nMCUBlocksV;
Npp8u *pdScan;
Npp32s nScanSize;
Npp8u *pJpegEncoderTemp;
size_t nTempSize;
unsigned char *pDstJpeg;
public:
uint8_t* mY;
uint8_t* mU;
uint8_t* mV;
int mWidth;
int mHeight;
};
#define MEMORY_ALGN_DEVICE 511
#define HD_MEMORY_ALGN_DEVICE 511
#define YUV_FMT_NV12 1
#define YUV_FMT_NV21 2
#define YUV_FMT_YUV420 3
#ifndef max
#define max(X, Y) ((X) > (Y) ?(X):(Y))
#endif
//霍夫曼编码表
unsigned char STD_DC_Y_NRCODES[16] = { 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
unsigned char STD_DC_Y_VALUES[12] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
unsigned char STD_DC_UV_NRCODES[16] = { 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
unsigned char STD_DC_UV_VALUES[12] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
unsigned char STD_AC_Y_NRCODES[16] = { 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0X7D };
unsigned char STD_AC_Y_VALUES[162] =
{
0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
0xf9, 0xfa
};
unsigned char STD_AC_UV_NRCODES[16] = { 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0X77 };
unsigned char STD_AC_UV_VALUES[162] =
{
0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
0xf9, 0xfa
};
#define DCTSIZE2 64
#if 0
//量化表,可以根据图像质量要求更改,这里图像是90%
static const unsigned char std_Y_QT[DCTSIZE2] =
{
3, 2, 2, 3, 2, 2, 3, 3,
3, 3, 4, 3, 3, 4, 5, 8,
5, 5, 4, 4, 5, 10, 7, 7,
6, 8, 12, 10, 12, 12, 11, 10,
11, 11, 13, 14, 18, 16, 13, 14,
17, 14, 11, 11, 16, 22, 16, 17,
19, 20, 21, 21, 21, 12, 15, 23,
24, 22, 20, 24, 18, 20, 21, 20
};
static const unsigned char std_UV_QT[DCTSIZE2] =
{
3, 4, 4, 5, 4, 5, 9, 5,
5, 9, 20, 13, 11, 13, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20
};
#else
/* These are the sample quantization tables given in JPEG spec section K.1.
* The spec says that the values given produce "good" quality, and
* when divided by 2, "very good" quality.
*/
static const unsigned char std_Y_QT[DCTSIZE2] = {
16, 11, 10, 16, 24, 40, 51, 61,
12, 12, 14, 19, 26, 58, 60, 55,
14, 13, 16, 24, 40, 57, 69, 56,
14, 17, 22, 29, 51, 87, 80, 62,
18, 22, 37, 56, 68, 109, 103, 77,
24, 35, 55, 64, 81, 104, 113, 92,
49, 64, 78, 87, 103, 121, 120, 101,
72, 92, 95, 98, 112, 100, 103, 99
};
static const unsigned char std_UV_QT[DCTSIZE2] = {
17, 18, 24, 47, 99, 99, 99, 99,
18, 21, 26, 66, 99, 99, 99, 99,
24, 26, 56, 99, 99, 99, 99, 99,
47, 66, 99, 99, 99, 99, 99, 99,
99, 99, 99, 99, 99, 99, 99, 99,
99, 99, 99, 99, 99, 99, 99, 99,
99, 99, 99, 99, 99, 99, 99, 99,
99, 99, 99, 99, 99, 99, 99, 99
};
#endif
int DivUp(int x, int d)
{
return (x + d - 1) / d;
}
void writeMarker(unsigned char nMarker, unsigned char *&pData)
{
*pData++ = 0x0ff;
*pData++ = nMarker;
}
template<typename T>
void writeAndAdvance(unsigned char *&pData, T nElement)
{
writeBigEndian<T>(pData, nElement);
pData += sizeof(T);
}
void writeJFIFTag(unsigned char *&pData)
{
const char JFIF_TAG[] =
{
0x4a, 0x46, 0x49, 0x46, 0x00,
0x01, 0x02,
0x00,
0x00, 0x01, 0x00, 0x01,
0x00, 0x00
};
writeMarker(0x0e0, pData);
writeAndAdvance<unsigned short>(pData, sizeof(JFIF_TAG) + sizeof(unsigned short));
memcpy(pData, JFIF_TAG, sizeof(JFIF_TAG));
pData += sizeof(JFIF_TAG);
}
void
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论











格式:x-rar 资源大小:12.7MB

格式:zip 资源大小:29.8MB

















收起资源包目录







共 5 条
- 1
资源评论

- 普通网友2024-07-29这篇文章写得太好了!作者的观点深刻,论据充分,读起来让人深思。
- qq_235896832021-04-23为什么保存下来的jpg文件没有宽高等信息呢?柳鲲鹏2021-06-02那能显示吗?
- tsmaomaoyu2019-12-08请问一下有没有NPP_CHECK_NPP和NPP_CHECK_CUDA的定义,一直报错柳鲲鹏2019-12-10是某个头文件的,可以删除。祝顺利。
- david-yue2019-10-17不错,很有参考价值~柳鲲鹏2019-10-17也是向别人学习的结果。祝工作顺利
- 放牛娃不吃草2019-10-11谢谢分享,可以参考柳鲲鹏2019-10-17能给阁下带来便利,也是高兴

柳鲲鹏
- 粉丝: 6709
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 复旦大学计算机科学技术学院计算机视觉课程的作业
- 复旦大学计算机科学技术学院计算机视觉课程作业
- Python技术在企业财务分析及决策中的应用研究-以青木股份为例.pdf
- Linux系统资源分配与利用功能测试工具的设计与实现.pdf
- 基于MATLAB-GUI的多目标情景下的切削参数推荐系统.caj
- 通过CPU路由功能访问MM440变频器(MPI-DP)
- 通过CPU路由功能访问MM440变频器(PN-DP)
- 基于计算机视觉的颈椎姿态实时检测系统助力用户预防颈椎问题
- 图书管理基于Spring Boot与Vue的全栈图书管理系统设计:毕业设计项目源码详解与实现
- 基于python爬虫和NLP的聊天系统设计与实现.pdf
- 本仓库内为2022年春季学期中山大学计算机视觉课程的期末大作业
- 建模的3D和爆炸图,图纸
- 电驱系统电机定子绕组分布与集中技术解析:绕组形式对反电动势及NVH特性的影响
- 计算机视觉课程作业:DPN 代码复现实现
- UITARS-UNITY.rar
- 软件测试基于ADB的mumu模拟器自动化测试脚本优化:解决连接与操作指令失效问题
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
