forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Loading JPEG code not working [fixed]

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
JoshDB



Joined: 05 Oct 2005
Posts: 87

PostPosted: Mon Jan 02, 2006 2:07 am    Post subject: Loading JPEG code not working [fixed] Reply with quote

Hey guys, I've installed the JPEG lib from the svn and also pulled down a sample bit of code that loads JPEGs. Can you tell me what's wrong with this picture?

When I try to compile this, it gives me the error:

Quote:
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:
#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;
}


Last edited by JoshDB on Mon Jan 02, 2006 6:52 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail AIM Address
AnonymousTipster



Joined: 01 Jul 2005
Posts: 197

PostPosted: Mon Jan 02, 2006 2:20 am    Post subject: Reply with quote

Where you have
for(int x =0; ....)
Change it to
int x=0;
for(x=0;......

You can't declare a variable inside a for() clause with GCC.
Back to top
View user's profile Send private message
JoshDB



Joined: 05 Oct 2005
Posts: 87

PostPosted: Mon Jan 02, 2006 2:31 am    Post subject: Reply with quote

Wow, thanks, it worked. Really fast response, just went to go search for 'loading JPEGs' and you responded ( :

However, although that error is gone, now I get a few others:



I'm guessing these errors have something to do with the included files from the JPEG library?

Edit: Actually, could it be something in the Makefile? Perhaps not referencing the lib?
Back to top
View user's profile Send private message Send e-mail AIM Address
JoshDB



Joined: 05 Oct 2005
Posts: 87

PostPosted: Mon Jan 02, 2006 2:46 am    Post subject: Reply with quote

Woot!

Alright, I added

Quote:
LIBS = -lpspgu -lpng -lz -lm -ljpeg


To the Makefile, and it works.
Back to top
View user's profile Send private message Send e-mail AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group