打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
libjpeg学习4:libjpeg
int tjpeg2yuv(unsigned char* jpeg_buffer, int jpeg_size, unsigned char** yuv_buffer, int* yuv_size, int* yuv_type)
{
tjhandle handle = NULL;
int width, height, subsample, colorspace;
int flags = 0;
int padding = 1; // 1或4均可,但不能是0
int ret = 0;

handle = tjInitDecompress();
tjDecompressHeader3(handle, jpeg_buffer, jpeg_size, &width, &height, &subsample, &colorspace);

printf("w: %d h: %d subsample: %d color: %d\n", width, height, subsample, colorspace);

flags |= 0;

*yuv_type = subsample;
// 注:经测试,指定的yuv采样格式只对YUV缓冲区大小有影响,实际上还是按JPEG本身的YUV格式来转换的
*yuv_size = tjBufSizeYUV2(width, padding, height, subsample);
*yuv_buffer =(unsigned char *)malloc(*yuv_size);
if (*yuv_buffer == NULL)
{
printf("malloc buffer for rgb failed.\n");
return -1;
}

ret = tjDecompressToYUV2(handle, jpeg_buffer, jpeg_size, *yuv_buffer, width,
padding, height, flags);
if (ret < 0)
{
printf("compress to jpeg failed: %s\n", tjGetErrorStr());
}
tjDestroy(handle);

return ret;
}

int tyuv2jpeg(unsigned char* yuv_buffer, int yuv_size, int width, int height, int subsample, unsigned char** jpeg_buffer, unsigned long* jpeg_size, int quality)
{
tjhandle handle = NULL;
int flags = 0;
int padding = 1; // 1或4均可,但不能是0
int need_size = 0;
int ret = 0;

handle = tjInitCompress();

flags |= 0;

need_size = tjBufSizeYUV2(width, padding, height, subsample);
if (need_size != yuv_size)
{
printf("we detect yuv size: %d, but you give: %d, check again.\n", need_size, yuv_size);
return 0;
}

ret = tjCompressFromYUV(handle, yuv_buffer, width, padding, height, subsample, jpeg_buffer, jpeg_size, quality, flags);
if (ret < 0)
{
printf("compress to jpeg failed: %s\n", tjGetErrorStr());
}

tjDestroy(handle);

return ret;
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
framebuffer显示JPEG图片
用libjpeg库生成jpeg文件(灰度)
如何使用jpeglib库压缩yuv422?
Android拍摄视频流的格式转换(YUV --- RGB) - - JavaEye技术网...
FFMpeg压缩Android摄像头数据写成H264格式文件
一哥技术馆 关于android视频采集的问题,急求解
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服