0

I have an (char*)RGB buffer that has the data of actual image. Let's say that the actual image resolution is 720x576. Now I want to resize it to a resolution , say 120x90. How can I do this using https://code.google.com/p/jpeg-compressor/ or libjpeg ?

Note: can use any other library, but should work in linux.

Edited: Video decoder decodes a frame in YUV, which I convert it into RGB. All these happen in a buffer. I need to resize the RGB buffer to make a thumbnail out of it with variable size.

Thanks for the help in advance

user2914066
  • 181
  • 4
  • 14
  • 2
    Have you seen this? http://stackoverflow.com/questions/7488048/libjpeg-output-scaling – Rook Nov 19 '14 at 12:43
  • 1
    The links from the unaccepted answer are also relevant. What you've asked isn't strictly a duplicate of that question, but unless you give us a little more to go on you may find this closed as duplicate or too broad! – Rook Nov 19 '14 at 12:44
  • Actually I need to generate thumbnails of variable size from a buffer which contains RGB data of an image. I can use "compress_image_to_jpeg_file_in_memory" api from jpeg-compressor to dump the image, but I am unable to resize the image. – user2914066 Nov 20 '14 at 04:51
  • Sooooo... that question I just linked you which talks about resizing images using libjpeg was helpful, then? – Rook Nov 20 '14 at 07:44
  • thanks for the link..It somehow directed me to my answer. I used intel ippi functions to resize my buffer rather than using libjpeg. Moreover, jpeg compression + Intel ipp was more light than using libjpeg. Thank for the help! – user2914066 Nov 21 '14 at 13:18
  • Glad to hear it. If your solution is relatively compact, it would be nice if you could add it as an answer to this question, otherwise I could close this question as a duplicate. – Rook Nov 21 '14 at 15:42

1 Answers1

0

I did the following to achieve my goal:

#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;
}
user2914066
  • 181
  • 4
  • 14
  • Didn't you say C++? Note for others coming here: Please use smart pointers, std::fstreams (or better: `compress_image_to_jpeg_file`) and check return codes (`status`) to make this safe C++ code. – Flamefire Apr 15 '19 at 08:52