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 

SDL Image viewer... another problems! :(

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



Joined: 15 Jun 2008
Posts: 121

PostPosted: Sat Jul 19, 2008 11:35 pm    Post subject: SDL Image viewer... another problems! :( Reply with quote

Excuse me for the many post, but I've ever strange problem!! :(
I've writed a Image viewer using SDL, but it crash when I try to resize the image!!!!
Here is the code:
Code:

int Image_viewer(char* target, char* est)
{
    SDL_Surface* screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_ASYNCBLIT);
   
    SDL_ShowCursor(0);
   
    SDL_Surface* back = NULL;
   
    SDL_RWops *rwfile = NULL;
   
    SDL_Surface* background = NULL;
   
    FILE *fp = NULL;
   
    Uint32 black;

    black = SDL_MapRGB(screen->format, 0, 0, 0);
   
    SDL_Rect offset;
   
    SceCtrlLatch pad1;
    SceCtrlData pad2;
   
    sceCtrlSetSamplingCycle(0);
    sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
   
    fp = fopen(target, "rb");
           
    rwfile = SDL_RWFromFP(fp, 1);

    if(rwfile==NULL)
    {
        Init();
        printf("\nErrore nella lettura del file!\n%s", SDL_GetError());
        sleep(3000000);
        SDL_FreeSurface(screen);
        SDL_FreeRW(rwfile);
        SDL_Quit();
        return 1;
    }

    //Load the image

    if(strcmp(est, "BMP")==0) back = SDL_LoadBMP_RW(rwfile, 1);

    if((strcmp(est, "PNM")==0)
            || (strcmp(est, "PPM")==0)
            || (strcmp(est, "PGM")==0)
            || (strcmp(est, "PBM")==0)) back = IMG_LoadPNM_RW(rwfile);

    if(strcmp(est, "XPM")==0) back = IMG_LoadXPM_RW(rwfile);

    if(strcmp(est, "XCF")==0) back = IMG_LoadXCF_RW(rwfile);

    if(strcmp(est, "PCX")==0) back = IMG_LoadPCX_RW(rwfile);

    if(strcmp(est, "GIF")==0) back = IMG_LoadGIF_RW(rwfile);

    if((strcmp(est, "JPG")==0) || (strcmp(est, "JPEG")==0)
            || (strcmp(est, "JPE")==0)) back = IMG_LoadJPG_RW(rwfile);

    if((strcmp(est, "TIF")==0) || (strcmp(est, "TIFF")==0)) back = IMG_LoadTIF_RW(rwfile);

    if(strcmp(est, "PNG")==0) back = IMG_LoadPNG_RW(rwfile);

    if(strcmp(est, "TGA")==0) back = IMG_LoadTGA_RW(rwfile);

    if(strcmp(est, "LBM")==0) back = IMG_LoadLBM_RW(rwfile);

    if(back == NULL )
    {
        Init();
        printf("\nErrore durante il caricamento dell'immagine\n o formato non supportato\n\n%s", SDL_GetError());
        sleep(3000000);
        SDL_FreeSurface(back);
        SDL_FreeSurface(screen);
        SDL_RWclose(rwfile);
        SDL_FreeRW(rwfile);
        SDL_Quit();
        return 1;
    }
    SDL_RWclose(rwfile);
    SDL_FreeRW(rwfile);
   
    int off_x=0;
   
    int off_y=0;
   
/*
    char* new_target = (char*)malloc(256);
   
    char* new_est = (char*)malloc(8);
   
    strcpy(new_target, target);
    strcpy(new_est, est);
   
    int immagine = 0;
*/
   
    double angle=0.000000;
   
    double scale_x=1.000000;
   
    double scale_y=1.000000;
   
    int custom_param=0;
   
    int custom_pos_x=0;
   
    int custom_pos_y=0;
   
    int custom_angle=0;
   
    int rotate_param=0;
   
    int start_scale_x=0;
   
    int start_scale_y=0;
   
    int first_boot=1;
   
    int moving=0;
   
    int allow_custom_pos_x=0;
   
    int allow_custom_pos_y=0;

    int refresh=1;
   
    // int newimage=1;
   
    while(running())
    {
        #include "Image_viewer/pressione_tasto.c"
       
        SDL_FillRect(screen, NULL, black);

        if(!moving)
        {
            if(custom_param!=1)
            {
                if(rotate_param==0)
                {
                    scale_x=(272/scale_y);
                    scale_y=(272/scale_y);
                }
                else
                {
                    scale_x=(272/scale_x);
                    scale_y=(272/scale_x);
                }
            }

            if(first_boot)
            {
                start_scale_x = scale_x;
                start_scale_y = scale_y;
            }

            if(custom_angle!=1)
            {
                angle = 0.000000;
            }
           
            background = rotozoomSurfaceXY(back, angle, scale_x, scale_y, 0); // <---- Here the programm crash!!!!!!!!!!!!!
           
            if(custom_pos_x==0)
            {
                off_x = ( screen->w - background->w ) / 2;
            }
            if(custom_pos_y==0)
            {
                off_y = ( screen->h - background->h ) / 2;
            }
        }
        if(background->w > screen->w)
        {
            allow_custom_pos_x=1;
        }
        else
        {
            allow_custom_pos_x=0;
        }
       
        if(background->h > screen->h)
        {
            allow_custom_pos_y=1;
        }
        else
        {
            allow_custom_pos_y=0;
        }
       
        offset.x = off_x;
        offset.y = off_y;
       
        //Blit the surface
        SDL_BlitSurface( background, NULL, screen, &offset );

        SDL_Flip(screen);
       
        SDL_FreeSurface(background);

        first_boot=0;
    }
    SDL_FreeSurface(screen);
    SDL_FreeSurface(back);
   
    //free(new_target);
    //free(new_est);
   
    SDL_Quit();
    return 0;
}


And here is the code included ( pressione_tasto.c )
Code:

sceCtrlReadLatch(&pad1);
        sceCtrlReadBufferPositive(&pad2, 1);
       
        if(pad1.uiMake==PSP_CTRL_CIRCLE)
        {
            SDL_FreeSurface(background);
            printf("sdkofjhdskfh");
            break;
        }
        if(pad1.uiMake==PSP_CTRL_CROSS)
        {
            moving=0;
            custom_param=0;
            custom_pos_x=0;
            custom_pos_y=0;
            refresh=1;
        }
        if(pad1.uiMake==PSP_CTRL_UP)
        {
            custom_angle=1;
            if(rotate_param==0) rotate_param=1;
            else rotate_param=0;
            angle+=90;
            refresh=1;
            moving=0;
        }
        if(pad1.uiMake==PSP_CTRL_DOWN)
        {
            custom_angle=1;
            if(rotate_param==0) rotate_param=1;
            else rotate_param=0;
            angle-=90;
            refresh=1;
            moving=0;
        }
        if(pad1.uiMake==PSP_CTRL_LTRIGGER)
        {
            if(scale_x>=0.2)
            {
                custom_param=1;
                scale_x-=0.2;
                scale_y-=0.2;
                refresh=1;
                moving=0;
            }
        }
        if(pad1.uiMake==PSP_CTRL_RTRIGGER)
        {
            if(scale_x<start_scale_x+1.500000)
            {
                custom_param=1;
                scale_x+=0.2;
                scale_y+=0.2;
                refresh=1;
                moving=0;
            }
        }
       
        if(pad2.Lx > 128 + 80)
        {
            if(allow_custom_pos_x==1)
            {
                custom_pos_x=1;
                if(off_x>(background->w - screen->w)-((background->w - screen->w)*2)) off_x-=10;
                refresh=1;
                moving=1;
            }
        }
        else if(pad2.Ly > 128 + 80)
        {
            if(allow_custom_pos_y==1)
            {
                custom_pos_y=1;
                if(off_y>(background->h - screen->h)-((background->h - screen->h)*2)) off_y-=10;
                refresh=1;
                moving=1;
            }
        }
        else if(pad2.Lx < 128 - 80)
        {
            if(allow_custom_pos_x==1)
            {
                custom_pos_x=1;
                if(off_x<0) off_x+=10;
                refresh=1;
                moving=1;
            }
        }
        else if(pad2.Ly < 128 - 80)
        {
            if(allow_custom_pos_y==1)
            {
                custom_pos_y=1;
                if(off_y<0) off_y+=10;
                refresh=1;
                moving=1;
            }
        }
        else moving = 0;

I've haven't found a error!
I've to call this function everytime that I want to use it!
( yesterday this code works great, but now it crash!!! Maybe I've modified somethings... I don't remember! and I don't know why now I get a error! )
Please help... :(

Thanks
Back to top
View user's profile Send private message
darkness



Joined: 15 Jun 2008
Posts: 121

PostPosted: Sat Jul 19, 2008 11:42 pm    Post subject: Reply with quote

The problem is the rotozoomSurfaceXY funct! The PSP crash in this funct!
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Sun Jul 20, 2008 5:06 am    Post subject: Reply with quote

I'd say the scale factor is borked. A quick look at the code shows the scale is probably not calculated right. I'd print the arguments, wait a few seconds, then do the rotowhatzits so you can see what is being passed to it when it explodes.
Back to top
View user's profile Send private message AIM Address
darkness



Joined: 15 Jun 2008
Posts: 121

PostPosted: Mon Jul 21, 2008 4:01 am    Post subject: Reply with quote

I've try to scale the image with a fixed value, but it still crash!!
Code:

int Image_viewer(char* target, char* est)
{
    SDL_Surface* screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_ASYNCBLIT);
   
    SDL_ShowCursor(0);
   
    SDL_Surface* back = NULL;
   
    SDL_RWops *rwfile = NULL;
   
    SDL_Surface* background = NULL;
   
    FILE *fp = NULL;
   
    Uint32 black;

    black = SDL_MapRGB(screen->format, 0, 0, 0);
   
    SDL_Rect offset;
   
    SceCtrlLatch pad1;
    SceCtrlData pad2;
   
    sceCtrlSetSamplingCycle(0);
    sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
   
    fp = fopen(target, "rb");
           
    rwfile = SDL_RWFromFP(fp, 1);

    if(rwfile==NULL)
    {
        Init();
        printf("\nErrore nella lettura del file!\n%s", SDL_GetError());
        sleep(3000000);
        SDL_FreeSurface(screen);
        SDL_FreeRW(rwfile);
        SDL_Quit();
        return 1;
    }

    //Load the image

    if(strcmp(est, "BMP")==0) back = SDL_LoadBMP_RW(rwfile, 1);

    if((strcmp(est, "PNM")==0)
            || (strcmp(est, "PPM")==0)
            || (strcmp(est, "PGM")==0)
            || (strcmp(est, "PBM")==0)) back = IMG_LoadPNM_RW(rwfile);

    if(strcmp(est, "XPM")==0) back = IMG_LoadXPM_RW(rwfile);

    if(strcmp(est, "XCF")==0) back = IMG_LoadXCF_RW(rwfile);

    if(strcmp(est, "PCX")==0) back = IMG_LoadPCX_RW(rwfile);

    if(strcmp(est, "GIF")==0) back = IMG_LoadGIF_RW(rwfile);

    if((strcmp(est, "JPG")==0) || (strcmp(est, "JPEG")==0)
            || (strcmp(est, "JPE")==0)) back = IMG_LoadJPG_RW(rwfile);

    if((strcmp(est, "TIF")==0) || (strcmp(est, "TIFF")==0)) back = IMG_LoadTIF_RW(rwfile);

    if(strcmp(est, "PNG")==0) back = IMG_LoadPNG_RW(rwfile);

    if(strcmp(est, "TGA")==0) back = IMG_LoadTGA_RW(rwfile);

    if(strcmp(est, "LBM")==0) back = IMG_LoadLBM_RW(rwfile);

    if(back == NULL )
    {
        Init();
        printf("\nErrore durante il caricamento dell'immagine\n o formato non supportato\n\n%s", SDL_GetError());
        sleep(3000000);
        SDL_FreeSurface(back);
        SDL_FreeSurface(screen);
        SDL_RWclose(rwfile);
        SDL_FreeRW(rwfile);
        SDL_Quit();
        return 1;
    }
    SDL_RWclose(rwfile);
    SDL_FreeRW(rwfile);
   
    int off_x=0;
   
    int off_y=0;
   
/*
    char* new_target = (char*)malloc(256);
   
    char* new_est = (char*)malloc(8);
   
    strcpy(new_target, target);
    strcpy(new_est, est);
   
    int immagine = 0;
*/
   
    double angle=0.000000;
   
    double scale_x=1.000000;
   
    double scale_y=1.000000;
   
    int custom_param=0;
   
    int custom_pos_x=0;
   
    int custom_pos_y=0;
   
    int custom_angle=0;
   
    int rotate_param=0;
   
    int start_scale_x=0;
   
    int start_scale_y=0;
   
    int first_boot=1;
   
    int moving=0;
   
    int allow_custom_pos_x=0;
   
    int allow_custom_pos_y=0;

    int refresh=1;
   
    // int newimage=1;
   
    while(running())
    {
        #include "Image_viewer/pressione_tasto.c"
       
        SDL_FillRect(screen, NULL, black);

        if(!moving)
        {
            if(custom_param!=1)
            {
                if(rotate_param==0)
                {
                    scale_x=(272/scale_y);
                    scale_y=(272/scale_y);
                }
                else
                {
                    scale_x=(272/scale_x);
                    scale_y=(272/scale_x);
                }
            }

            if(first_boot)
            {
                start_scale_x = scale_x;
                start_scale_y = scale_y;
            }

            if(custom_angle!=1)
            {
                angle = 0.000000;
            }
            Init();
            printf("Before scale");
           
            background = rotozoomSurfaceXY(back, 0, 1.00, 1.00, 1); // <---- Here the programm crash!!!!!!!!!!!!!
           
            printf("After scale");
            sleep(1000000);
           
            if(custom_pos_x==0)
            {
                off_x = ( screen->w - background->w ) / 2;
            }
            if(custom_pos_y==0)
            {
                off_y = ( screen->h - background->h ) / 2;
            }
        }
        if(background->w > screen->w)
        {
            allow_custom_pos_x=1;
        }
        else
        {
            allow_custom_pos_x=0;
        }
       
        if(background->h > screen->h)
        {
            allow_custom_pos_y=1;
        }
        else
        {
            allow_custom_pos_y=0;
        }
       
        offset.x = off_x;
        offset.y = off_y;
       
        //Blit the surface
        SDL_BlitSurface( background, NULL, screen, &offset );

        SDL_Flip(screen);
       
        SDL_FreeSurface(background);

        first_boot=0;
    }
    SDL_FreeSurface(screen);
    SDL_FreeSurface(back);
   
    //free(new_target);
    //free(new_est);
   
    SDL_Quit();
    return 0;
}
Back to top
View user's profile Send private message
Jim



Joined: 02 Jul 2005
Posts: 487
Location: Sydney

PostPosted: Mon Jul 21, 2008 11:39 pm    Post subject: Reply with quote

And
http://forums.ps2dev.org/viewtopic.php?t=10658
_________________
http://www.dbfinteractive.com
Back to top
View user's profile Send private message Visit poster's website
darkness



Joined: 15 Jun 2008
Posts: 121

PostPosted: Tue Jul 22, 2008 2:37 am    Post subject: Reply with quote

?? I haven't found a solution! And I'm not use a freemem funct! It crash the first time that the function is called!
Back to top
View user's profile Send private message
Jim



Joined: 02 Jul 2005
Posts: 487
Location: Sydney

PostPosted: Tue Jul 22, 2008 8:07 am    Post subject: Reply with quote

I'm trying to point out you're both using the same scale function and both having the same bug. Looks a bit like the library itself needs fixing. I think J.F alluded to that too. It's worth grabbing the code from svn and seeing what's wrong.

Jim
_________________
http://www.dbfinteractive.com
Back to top
View user's profile Send private message Visit poster's website
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