c++ - jpeg_decompress_struct 结构大小不匹配

标签 c++ c struct decode libjpeg

我正在尝试使用 libJPEG Visual Studio Community 2017 上的版本 9b 用于解码编码图像缓冲区(我从 openCV 获得了这个)。

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

我的函数总是在

处退出
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。

最佳答案

问题解决:

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

感谢@LPs在评论中的建议。

关于c++ - jpeg_decompress_struct 结构大小不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43884727/

相关文章:

c++ - 越界访问数组不会出错,为什么?

c - 数组初始化中的三元运算符

c++ - 从函数中获取参数类型列表

c++ - 一般返回一个可选的<T>/nullopt

c - fgets 在遇到空格时停止

c - strdup 返回地址越界

c++ - 在 C++ 中为结构( union )创建构造函数

swift - 间接枚举和结构

python - U8、U16、U32 在 python 中的表示

c++ - 从不同语言环境中的字符串解析 float