jpeg_decompress_struct结构大小不匹配

时间:2017-05-10 06:07:57

标签: c++ c struct decode libjpeg

我正在尝试在Visual Studio Community 2017上使用libJPEG版本9b来解码编码图像缓冲区(我从openCV获取此内容)。

我已经关注this example并编写了我自己的函数,该函数使用指向jpeg_create_decompress的指针作为参数调用jpeg_decompress_struct

我的功能总是退出

if (structsize != SIZEOF(struct jpeg_decompress_struct))
    ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE, 
         (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);

在jdapimin.c中的jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)方法。

我编写了不同的代码,并尝试了在线提供的不同示例,并遇到了同样的问题。

Mat readFile = imread("ottawa.jpg", IMREAD_COLOR);
cout << "Read Matrix size: " << readFile.size() << endl;

vector<uchar> encodedBuffer;          // output buffer to store compressed image
vector<int> compression_params;

int jpegqual = ENCODE_QUALITY; // Compression Parameter
compression_params.push_back(CV_IMWRITE_JPEG_QUALITY);
compression_params.push_back(jpegqual);

imencode(".jpg", readFile, encodedBuffer, compression_params);       // compress the image

cout << "Encoding with OpenCV complete..." << endl;

int matSize = encodedBuffer.size();

cout << "Size of matrix: " << matSize << endl;

// Variables for the decompressor itself
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;

unsigned long jpg_size = encodedBuffer.size();
unsigned char *jpg_buffer = &encodedBuffer.front();

cinfo.err = jpeg_std_error(&jerr);
cout << endl << "In decode function:" << endl;
cout << "cinfo size: " << sizeof(cinfo) << endl;
cout << "jpeg_decompress_struct size: " << sizeof(struct jpeg_decompress_struct) << endl;
jpeg_create_decompress(&cinfo);

我在调用者(主要)和jpeg_CreateDecompress函数中打印结构的大小。

在jdapimin.c文件中:

printf("\nIn jdapimin.c:\n");
printf("Structsize: %zd\n", structsize);
printf("jpeg_decompress_struct: %zd\n", sizeof(struct jpeg_decompress_struct));

这是输出: Output

这完全是我的问题。我无法理解相同sizeof函数如何返回不同的值!为什么有32的差异?我尝试过铸造size_t,去掉铸件。我甚至不知道这可能会出错。

我很抱歉这篇长篇文章,非常感谢任何线索。谢谢!

编辑:我检查了this post,但我自己编译了库并在Visual Studio中链接了.lib。所以不确定,如何检查是否安装了多个libJPEG。

1 个答案:

答案 0 :(得分:1)

问题解决了:

我在我的两个文件中打开了jpeglib.h并检查了位置。 jpeglib.h和我的计划中包含的jdapimin.c文件位于不同的位置。我的项目目录中有一个我的程序正在使用的副本。我删除了那些.h文件,现在两个文件都使用了我的include目录路径中的文件。这解决了问题,现在所有的值都是632。

感谢@ LPs&#39;评论中的建议。

相关问题