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 

How can I put images in display?

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



Joined: 04 Jul 2005
Posts: 17

PostPosted: Mon Aug 08, 2005 1:31 am    Post subject: How can I put images in display? Reply with quote

Hi!

I'm learning to develop to PSP (and also learning C) and I want to push one button, and see one image in the display.

I have the image in C, and I've tried to make a function for do it, but I haven't get it.

Can anybody help me with a very simple function?

Thanks.
Bye.
Back to top
View user's profile Send private message
Shine



Joined: 03 Dec 2004
Posts: 728
Location: Germany

PostPosted: Mon Aug 08, 2005 2:03 am    Post subject: Re: How can I put images in display? Reply with quote

kecC wrote:
Hi!

I have the image in C, and I've tried to make a function for do it, but I haven't get it.


What do you mean with "in C"? Do you have an array of u32 values of your image? Then you could do this:

Code:

#include <pspkernel.h>
#include <pspdisplay.h>
#include <pspctrl.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

/* Define the module info section */
PSP_MODULE_INFO("PAINTIMAGE", 0, 1, 1);

/* Define the main thread's attribute value (optional) */
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);

/* Exit callback */
int exit_callback(int arg1, int arg2, void *common)
{
   sceKernelExitGame();

   return 0;
}

/* Callback thread */
int CallbackThread(SceSize args, void *argp)
{
   int cbid;

   cbid = sceKernelCreateCallback("Exit Callback", (void *) exit_callback, NULL);
   sceKernelRegisterExitCallback(cbid);

   sceKernelSleepThreadCB();

   return 0;
}

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void)
{
   int thid = 0;

   thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
   if(thid >= 0)
   {
      sceKernelStartThread(thid, 0, 0);
   }

   return thid;
}

#define PSP_SCREEN_WIDTH 480
#define PSP_SCREEN_HEIGHT 272
#define PSP_LINE_SIZE 512
#define PSP_PIXEL_FORMAT 3

int main(void)
{
   int i, x, y, oldButtons;
   SceCtrlData pad;
   u32* image;
   u32* vram = (u32*) (0x40000000 | 0x04000000);

   SetupCallbacks();

   // some demo image
   image = malloc(480*272*4);
   for (y = 0; y < 272; y++) {
      for (x = 0; x < 480; x++) {
         image[x + y*480] = x * y;
      }
   }
   
   // init graphics
   sceDisplaySetMode(0, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT);
   sceDisplaySetFrameBuf((void *) vram, 512, 3, 1);
   
   // clear screen
   for (i = 0; i < 512 * 480; i++) vram[i] = 0;

   // wait for key
   sceCtrlSetSamplingCycle(0);
   sceCtrlSetSamplingMode(PSP_CTRL_MODE_DIGITAL);
   sceCtrlReadBufferPositive(&pad, 1);
   oldButtons = pad.Buttons;
   while (1) {
      sceDisplayWaitVblankStart();
      sceCtrlReadBufferPositive(&pad, 1);
      if (oldButtons != pad.Buttons) break;
   }
   
   // draw image
   for (y = 0; y < 272; y++) {
      for (x = 0; x < 480; x++) {
         vram[x + y * 512] = image[x + y*480];
      }
   }

   sceKernelSleepThread();

   return 0;
}


Instead of creating the demo image, you can use your image array.

BTW: with my Lua Player the full source code for the same, but loading a PNG image from memory stick included, looks like this:

Code:

image = loadImage("background.png")
oldButtons = ctrlRead()
while true do
   waitVblankStart()
   buttons = ctrlRead()
   if buttons ~= oldButtons then
      break
   end
end
blitImage(0, 0, image)
flipScreen()
Back to top
View user's profile Send private message
kecC



Joined: 04 Jul 2005
Posts: 17

PostPosted: Mon Aug 08, 2005 8:36 am    Post subject: Reply with quote

Thanks a lot!

But I want to show a image like this type:

Code:

const unsigned short image[] = {
0x735a,0x6f39,0x6b39,0x6f39,0x6b39,0x6f39,...
}


How can I do it?

Thanks again!
Back to top
View user's profile Send private message
nevyn



Joined: 31 Jul 2005
Posts: 136
Location: Sweden

PostPosted: Mon Aug 08, 2005 9:36 am    Post subject: Reply with quote

kecC wrote:
Thanks a lot!

But I want to show a image like this type:

Code:

const unsigned short image[] = {
0x735a,0x6f39,0x6b39,0x6f39,0x6b39,0x6f39,...
}


How can I do it?

Thanks again!


Dude, that's what the code he gave you does.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
hexperience



Joined: 05 Jul 2005
Posts: 19

PostPosted: Mon Aug 08, 2005 1:31 pm    Post subject: Reply with quote

Thanks for the samples guys. It worked, but the colors are messed up.

My orginal pic was 24 bit color. Is there something I need to change in the init of the screen buffer?

Thanks.
Hex.

ps.
You know when you used to play Doom too long when you were a kid... and your head felt rather football shaped and there was pain somewhere about a half inch behind your eyes? I have that from reading C primers and PSP samples... but I'm getting there! 8)
Back to top
View user's profile Send private message
hexperience



Joined: 05 Jul 2005
Posts: 19

PostPosted: Mon Aug 08, 2005 2:59 pm    Post subject: Reply with quote

I figured it out, but I don't know why it worked. Still reading up on my C.

I changed the define for vram from u32 to u16.
And I changed the PixelMode from 3 to 1 which means that the tool that converted my picture created a 16bit array in the .c file rather than a 32bit array which the sample code above was expecting. (I'm guessing).

This thread was what got me going in the right direction if you are still looking for help with this...

http://forums.ps2dev.org/viewtopic.php?t=2899

Cheers
Back to top
View user's profile Send private message
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