简体   繁体   English

需要在VS2013 x64中工作的jpeglib-turbo示例

[英]Need example of jpeglib-turbo that works in VS2013 x64

I'm trying to learn how to use the jpeg-turbo library. 我正在尝试学习如何使用jpeg-turbo库。 And I'm have a devil of a time getting started. 我有一个开始的恶魔。 The example.c example in the doc folder, and every single example I find on the web, crashes in VS2013 when I try to read a .jpg file. 当我尝试读取.jpg文件时,doc文件夹中的example.c示例以及我在网上找到的每个示例都在VS2013中崩溃。 They compile fine. 他们编译很好。 But when I run them they crash with an access violation error. 但是当我运行它们时,它们因访问冲突错误而崩溃。

What I really need is a tiny working (beginner friendly) example that is known to run properly in VS2013 x64. 我真正需要的是一个很小的工作示例(适合初学者),众所周知该示例可以在VS2013 x64中正常运行。 Including the main(){} code block code. 包括main(){}代码块代码。 And if there's anything special in the VS project properties that I might need to set that could be causing this crashing. 而且,如果我可能需要设置VS项目属性中的任何特殊内容,可能会导致崩溃。

I'm pulling my hair out just trying to get one simple example working. 我只是想弄一个简单的例子而已。

Thanks for the help. 谢谢您的帮助。

*Edit-- Here is a very small example. *编辑-这是一个非常小的示例。 I've also tried to get jpeglib to run with and without using Boost/GIL But it always crashes when loading the image: exception at 0x00000000774AE4B4 (ntdll.dll) 我也尝试过使jpeglib在不使用Boost / GIL的情况下运行,但是在加载图像时它总是崩溃:0x00000000774AE4B4(ntdll.dll)处的异常

#include <stdio.h>
#include <assert.h>
#include <jpeglib.h>

#pragma warning(disable: 4996)

int main(int argc, char* argv[])
{
    struct jpeg_decompress_struct cinfo;
    struct jpeg_error_mgr jerr;
    JSAMPARRAY buffer;
    int row_stride;

    //initialize error handling
    cinfo.err = jpeg_std_error(&jerr);

    FILE* infile;
    infile = fopen("source.jpg", "rb");
    assert(infile != NULL);

    //initialize the decompression
    jpeg_create_decompress(&cinfo);

    //specify the input
    jpeg_stdio_src(&cinfo, infile);

    //read headers
    (void)jpeg_read_header(&cinfo, TRUE);

    jpeg_start_decompress(&cinfo); <----This guy seems to be the culprit

    printf("width: %d, height: %d\n", cinfo.output_width, cinfo.output_height);

    row_stride = cinfo.output_width * cinfo.output_components;

    buffer = (*cinfo.mem->alloc_sarray)
        ((j_common_ptr)&cinfo, JPOOL_IMAGE, row_stride, 1);

    JSAMPLE firstRed, firstGreen, firstBlue; // first pixel of each row, recycled
    while (cinfo.output_scanline < cinfo.output_height)
    {
        (void)jpeg_read_scanlines(&cinfo, buffer, 1);
        firstRed = buffer[0][0];
        firstBlue = buffer[0][1];
        firstGreen = buffer[0][2];
        printf("R: %d, G: %d, B: %d\n", firstRed, firstBlue, firstGreen);
    }

    jpeg_finish_decompress(&cinfo);

    return 0;
}

I found the problem. 我发现了问题。

In my VS project's Linker->Input->Additional Dependencies. 在我的VS项目的Linker-> Input-> Additional Dependencies中。 I changed it to use turbojpeg-static.lib. 我将其更改为使用turbojpeg-static.lib。 Or jpeg-static.lib when I'm using the non turbo enhanced libraries. 当我使用非Turbo增强库时,则为jpeg-static.lib。

The turbojpeg.lib or jpeg.lib crashes for some reason when reading the image. 读取图像时,turbojpeg.lib或jpeg.lib出于某种原因而崩溃。

FYI, I am using the libjpeg-turbo-1.4.2-vc64.exe version with VS2013. 仅供参考,我在VS2013中使用libjpeg-turbo-1.4.2-vc64.exe版本。 And this is how I got it to work. 这就是我让它起作用的方式。

One more very important thing that I learned that I'd like to share. 我想分享的另一件非常重要的事情。 When writing to a new .jpg image. 写入新的.jpg图像时。 If the new image size is different than the source image. 如果新图像大小与源图像不同。 It will typically crash. 通常会崩溃。 Especially if the new size is larger than the source. 特别是如果新大小大于源大小。 I'm guessing this happens because it takes a much longer time to re-sample the color data to a different size. 我猜这是因为要花更长的时间才能将颜色数据重新采样为其他大小。 So this type of action might require it's own thread to prevent crashing. 因此,此类操作可能需要其自己的线程来防止崩溃。

I wasted a lot of time chasing code errors and compiler settings due to this one. 由于这一原因,我浪费了很多时间来追求代码错误和编译器设置。 So watch out for that one. 所以要当心。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM