gpt4 book ai didi

c - 使用 LibJpeg 将 YUV 转换为 jpeg 时出现段错误

转载 作者:行者123 更新时间:2023-11-30 17:50:52 27 4
gpt4 key购买 nike

我需要使用 LibJpeg 将 yuv 422 图像中的 Y 仅压缩为 jpeg 图像

Y只是灰度图像

这是我的代码:

y = (char*) malloc(640*480);
for (i = 0, j = 0; j < n; i++, j += 2)
y[i] = raw[j];
Image *dst;

dst = CreateImage(sz, 8, 1);
dst->imageData = y;

//frame is the dst image
bool ipl2jpeg(Image *frame, unsigned char **outbuffer, long unsigned int *outlen) {
unsigned char *outdata = (uchar *) frame->imageData;
struct jpeg_compress_struct cinfo ;
struct jpeg_error_mgr jerr;
JSAMPROW row_ptr[1];
int row_stride;

*outbuffer = NULL;
*outlen = 0;

cinfo.err = jpeg_std_error(&jerr);
jpeg_create_compress(&cinfo);
jpeg_mem_dest(&cinfo, outbuffer, outlen);

cinfo.image_width = frame->width;
cinfo.image_height = frame->height;
cinfo.input_components = frame->nChannels;

cinfo.in_color_space = JCS_GRAYSCALE;

jpeg_set_defaults(&cinfo);
jpeg_set_quality (&cinfo, 50, true);
jpeg_start_compress(&cinfo, TRUE);
row_stride = frame->width * frame->nChannels;

while (cinfo.next_scanline < cinfo.image_height) {
row_ptr[0] = &outdata[cinfo.next_scanline * row_stride];
jpeg_write_scanlines(&cinfo, row_ptr, 1); // Iam getting segm. fault here
}

jpeg_finish_compress(&cinfo);
jpeg_destroy_compress(&cinfo);

return true;
}

我在 jpeg_write_scanlines 中遇到段错误,我不确定我做得是否正确。这是将灰度图像转换为 jpeg 的正确方法吗??

最佳答案

您没有发布可编译的源代码;很难猜测 ipl2jpeg() 实际上是如何调用的

frame->nChannels 应为 1

row_ptr[0]应该指向输入帧数据

关于c - 使用 LibJpeg 将 YUV 转换为 jpeg 时出现段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17002846/

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