gpt4 book ai didi

c++ - 如何使用 C++ 从 RGB 缓冲区调整图像大小

转载 作者:太空宇宙 更新时间:2023-11-04 03:49:02 25 4
gpt4 key购买 nike

我有一个 (char*)RGB 缓冲区,其中包含实际图像的数据。假设实际图像分辨率为 720x576。现在我想将其大小调整为分辨率,例如 120x90。我怎样才能使用 https://code.google.com/p/jpeg-compressor/ 来做到这一点或者 libjpeg ?

注意:可以使用任何其他库,但应该在 Linux 中工作。

编辑:视频解码器以 YUV 格式解码帧,然后将其转换为 RGB。所有这些都发生在缓冲区中。我需要调整 RGB 缓冲区的大小,以制作可变大小的缩略图。

感谢您提前提供帮助

最佳答案

为了实现我的目标,我做了以下工作:

#define TN_WIDTH 240
#define TN_HEIGHT 180

#include "jpegcompressor/jpge.h"
#include "jpegcompressor/jpgd.h"
#include <ippi.h>

bool createThumnailJpeg(const uint8* pSrc, int srcwidth, int srcheight)
{
int req_comps = 3;
jpge::params params;
params.m_quality = 50;
params.m_subsampling = jpge::H2V2;
params.m_two_pass_flag = false;


FILE *fpJPEGTN = fopen("Resource\\jpegcompressor.jpeg","wb");

int dstWidth = TN_WIDTH;
int dstHeight = TN_HEIGHT;
int uiDstBufferSize = dstWidth * dstHeight * 3;
uint8 *pDstRGBBuffer = new uint8[uiDstBufferSize];
uint8 *pJPEGTNBuffer = new uint8[uiDstBufferSize];

int uiSrcBufferSize = srcwidth * srcheight * 3;

IppiSize srcSize = {srcwidth , srcheight};
IppiRect srcROI = {0, 0, srcwidth, srcheight};
IppiSize dstROISize = {dstWidth, dstHeight};
double xfactor = (double) dstWidth / srcwidth;
double yfactor = (double) dstHeight / srcheight;
IppStatus status = ippiResize_8u_C3R(pSrc, srcSize, srcwidth*3, srcROI,
pDstRGBBuffer, dstWidth*3, dstROISize, xfactor, yfactor, 1);

if (!jpge::compress_image_to_jpeg_file_in_memory(pJPEGTNBuffer, uiDstBufferSize, dstWidth, dstHeight, req_comps, pDstRGBBuffer, params))
{
cout << "failed!";
delete[] pDstRGBBuffer;
delete [] pJPEGTNBuffer;
return false;
}
if (fpJPEGTN)
{
fwrite(pJPEGTNBuffer, uiDstBufferSize, 1, fpJPEGTN);
fclose(fpJPEGTN);
}
delete [] pDstRGBBuffer;
delete [] pJPEGTNBuffer;

return true;
}

关于c++ - 如何使用 C++ 从 RGB 缓冲区调整图像大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27017083/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com