When I try to compile this, it gives me the error:
graphics.c: In function 'loadImageJPEG':
graphics.c:533: error: 'for' loop initial declaration used outside C99 mode
graphics.c:543: error: 'for' loop initial declaration used outside C99 mode
make: *** [graphics.o] Error 1
Code: Select all
#include <stdlib.h>
#include <malloc.h>
#include <pspdisplay.h>
#include <psputils.h>
#include <png.h>
#include <pspgu.h>
#include <jpeglib.h>
#include <jerror.h>
#include "graphics.h"
#include "framebuffer.h"
// Other code, none related...
Image* loadImageJPEG(const char* filename)
{
struct jpeg_decompress_struct dinfo;
struct jpeg_error_mgr jerr;
dinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&dinfo);
FILE* inFile = fopen(filename, "rb");
if (!inFile) {
jpeg_destroy_decompress(&dinfo);
return NULL;
}
jpeg_stdio_src(&dinfo, inFile);
jpeg_read_header(&dinfo, TRUE);
int width = dinfo.image_width;
int height = dinfo.image_height;
jpeg_start_decompress(&dinfo);
Image* image = (Image*) malloc(sizeof(Image));
if (!image) {
jpeg_destroy_decompress(&dinfo);
return NULL;
}
image->imageWidth = width;
image->imageHeight = height;
image->textureWidth = getNextPower2(width);
image->textureHeight = getNextPower2(height);
image->data = (Color*) memalign(16, image->textureWidth * image->textureHeight * sizeof(Color));
u8* line = (u8*) malloc(width * 3);
if (!line) {
jpeg_destroy_decompress(&dinfo);
return NULL;
}
if (dinfo.jpeg_color_space == JCS_GRAYSCALE) {
while (dinfo.output_scanline < dinfo.output_height) {
int y = dinfo.output_scanline;
jpeg_read_scanlines(&dinfo, &line, 1);
for (int x = 0; x < width; x++) { // <-- Line 533
Color c = line[x];
image->data[x + image->textureWidth * y] = c | (c << 8) | (c << 16) | 0xff000000;;
}
}
} else {
while (dinfo.output_scanline < dinfo.output_height) {
int y = dinfo.output_scanline;
jpeg_read_scanlines(&dinfo, &line, 1);
u8* linePointer = line;
for (int x = 0; x < width; x++) { // <-- Line 543
Color c = *(linePointer++);
c |= (*(linePointer++)) << 8;
c |= (*(linePointer++)) << 16;
image->data[x + image->textureWidth * y] = c | 0xff000000;
}
}
}
jpeg_finish_decompress(&dinfo);
jpeg_destroy_decompress(&dinfo);
free(line);
return image;
}