0

I have followed the CImg tutorial and I it works perfectly. However, if I try to load a different image (other than lena.jpg), I get a stack overflow error.

For example, this works:

CImg<float> image;
string filePath = "C:/Users/zzz/Documents/lena.jpg";
image.load(filePath.c_str());

But this gives an error:

CImg<float> image;
string filePath = "C:/Users/zzz/Documents/anotherimage.jpg";
image.load(filePath.c_str());

The error is: Unhandled exception at 0x77bb15de in LoadImageTest.exe: 0xC00000FD: Stack overflow.

I thought the stack overflow was due to "anotherimage.jpg" being too large, so I also tried a really small image (16x16 pixels). This resulted in the same error.

Does anyone have any suggestions as to why this is happening?

Full code:

#include "stdafx.h"
#include <iostream>

#include "CImg.h"

using namespace cimg_library;
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    CImg<float> image;

    // This works...
    string filePath = "C:/Users/zzz/Pictures/lena.jpg";

    // This doesn't work...
    // string filePath = "C:/Users/zzz/Pictures/small.jpg";

    image.load(filePath.c_str());

    CImgDisplay main_disp(image, "The image");

    while (!main_disp.is_closed())
    {
        main_disp.wait();
    }

    return 0;
}
TallClimate
  • 3
  • 1
  • 4

1 Answers1

0

Looks weird. Are you sure this is indeed a file in JPG format ? Does it use some special JPEG formats (B&W, 12 bits ?, ...).

bvalabas
  • 241
  • 1
  • 1
  • Thanks that solved it! Looking at the image properties, lena.jpg was actually a bitmap (weird), whereas the other images were genuine jpegs. I installed ImageMagick and it worked fine. – TallClimate Jan 10 '13 at 18:07