I am trying to write a simple image file to disk using stb_image_write. I use the simplest test case : a 128 by 128 pixels RGB image.
I found this example online, and the guy seems to say that it works fine, plus it looks exactly like what I have been writing for 2 hours :
void save_image(int w, int h, int channels_num)
{
int data[w * h * channels_num];
int index = 0;
for (int j = h - 1; j >= 0; --j)
{
for (int i = 0; i < w; ++i)
{
float r = (float)i / (float)w;
float g = (float)j / (float)h;
float b = 0.2f;
int ir = int(255.0 * r);
int ig = int(255.0 * g);
int ib = int(255.0 * b);
data[index++] = ir;
data[index++] = ig;
data[index++] = ib;
}
}
stbi_write_jpg("jpg_test_.jpg", w, h, channels_num, data, 100);
}
save_image(128, 128, 3);
The result should be a nice color gradient, but all I can get is a valid file with some vertical red, green, blue and black lines. Dimensions of the image are ok though. I really don't find the solution here. I am on linux Jessie. Could there be 'endianess' issue or something like that?