 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
jason867
Joined: 24 Jul 2005 Posts: 78
|
Posted: Tue Aug 23, 2005 2:44 pm Post subject: Problems with screenshot code. |
|
|
Hi everybody, nice to see you again. I've been trying to get a screenshot function to work and I've been having trouble. I searched through these forums for related threads, and I found a couple. One piece of code developed a .tga screenshot. I managed to get this working, but I didn't like the fact that Quicktime was the only program on my computer that would open this file. So I tried using the .bmp version I found. I've been tinkering around with it but haven't gotten anywhere. Here is my source so far;
M_Header.h
| Code: |
////////////////////////////////////////////////////////////////////////////////////
// My_Header.h Version 1.0
// By Jason J. Owens
// August 21, 2005 9:24 AM
//////////////////////////////////////////////////////////////////////////////////////////
#ifndef __MY_HEADER__
#define __MY_HEADER__
// Function Prototypes
void screenshot();
///////////////////////////////////////////////////////////////////////////////////////
// Function Definitions
void screenshot()
{
unsigned char bmpHeader24[] = { 0x42, 0x4d, 0x38, 0xfa, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0xe0, 0x01, 0x00, 0x00, 0x10, 0x01, 0x00, 0x00, 0x01, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x0b, 0x00, 0x00, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
unsigned char buffer[SCR_WIDTH*3];
unsigned char r,g,b;
int bufferIndex = 0;
unsigned short p;
char savePath="ms0:/PSP/PHOTO/Screenshots/screenshot.bmp";
int file = sceIoOpen(savePath,PSP_O_CREAT | PSP_O_TRUNC | PSP_O_RDWR, 0777); // savePath should hold the path to your file
// write bmp header
sceIoWrite(file,bmpHeader24,54);
// write bmp data
unsigned long vptr0 = VRAM;
int i=0;
for(i=0; i<272; i++)
{
unsigned long vptr=vptr0;
int e=0;
for(e=0; e<480; e++)
{
p = *(unsigned short *)vptr;
r = (p<<3)&0xf8;
g = (p>>2)&0xf8;
b = (p>>7)&0xf8;
buffer[bufferIndex] = b;
bufferIndex++;
buffer[bufferIndex] = g;
bufferIndex++;
buffer[bufferIndex] = r;
bufferIndex++;
vptr+=PIXEL_SIZE*2;
}
// write chunk
sceIoWrite(file,buffer,SCR_WIDTH*3);
bufferIndex=0;
vptr0-=BUF_WIDTH*2;
}
// bmp end
unsigned char end[] = { 0x00, 0x00 };
sceIoWrite(file,end,2);
sceIoClose(file);
}
///////////////////////////////////////////////////////////////////////////////////////
|
Main.c
| Code: |
//////////////////////////////////////////////////////////////////////////////////////////
/* test Version 1.0
* by Jason J. Owens
* August 18, 2005 9:00 AM
*/
//////////////////////////////////////////////////////////////////////////////////////////
// #includes
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <stdlib.h>
#include <stdio.h>
#include <Graphics.h>
#include <My_Header.h>
PSP_MODULE_INFO("test", 0x1000, 1, 1); // Defines module info.
PSP_MAIN_THREAD_ATTR(0); // Defines the main thread's attribute value (optional).
//#define printf pspDebugScreenPrintf // Defines printf, just to make typing easier.
int ExitGame = 0; // Gets set to '1' when getting ready to exit the game.
// Exit callback
int exit_callback(int arg1, int arg2, void *common)
{
ExitGame = 1;
return 0;
}
// Callback thread
int CallbackThread(SceSize args, void *argp)
{
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", 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, THREAD_ATTR_USER, 0);
if(thid >= 0)
{
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
int Random(int high)
{
return (rand() % (high+1));
}
// Here's the Main Function.
int main(void)
{
pspDebugScreenInit(); // Initializes the Debug text output screen.
SetupCallbacks(); // Sets up the callback thread and returns its thread id.
srand(sceKernelLibcTime((void *) 0)); // seeded with time
InitializeGraphics(1);
int x=0,y=0,x1=0,y1=0,radius=0,xsize=0,ysize=0,r=0,g=0,b=0,a=0,c=0,three_d=0,rand3d=0,text=0;
while(!ExitGame)
{
x=Random(480);
r=Random(255);
y=Random(272);
x1=Random(480);
y1=Random(272);
g=Random(255);
xsize=Random(25);
b=Random(255);
ysize=Random(25);
rand3d=Random(25);
radius=Random(150);
text=20;
switch(Random(5))
{
case 0:
PlotPixel(x,y,r,g,b);
case 1:
PlotPixel(x,y,r,g,b);
case 2:
PlotLine(x,y,x1,y1,r,g,b);
case 3:
PlotCircle(x,y,radius,r,g,b);
case 4:
for(a=0;a<xsize;a++)
{
for(c=0;c<ysize;c++)
{
PlotPixel(x+a,y+c,r,g,b);
}
}
case 5:
for(three_d=0;three_d<rand3d;three_d++)
{
for(a=0;a<xsize;a++)
{
for(c=0;c<ysize;c++)
{
PlotPixel(x+a+three_d,y+c+three_d,r+three_d,g+three_d,b+three_d);
}
}
}
}
}
screenshot();
sceKernelExitGame(); // Returns PSP to the Main Menu.
return 0; // Just for good practice.
}
//////////////////////////////////////////////////////////////////////////////////////////
|
Does anyone have a clue as to what I'm doing wrong? _________________ Ask not for whom the bell tolls, it tolls for thee, besides, I'm playing my PSP, tee hee!
------------------------------------------------------
Visit my website for my PSP Homebrew! |
|
| Back to top |
|
 |
0x0001

Joined: 21 Jul 2005 Posts: 11
|
Posted: Tue Aug 23, 2005 3:01 pm Post subject: |
|
|
why is this define commented?
//#define printf pspDebugScreenPrintf // Defines printf, just to make typing easier. |
|
| Back to top |
|
 |
jason867
Joined: 24 Jul 2005 Posts: 78
|
Posted: Tue Aug 23, 2005 4:00 pm Post subject: |
|
|
I wasn't using it in the program, so I comented it out... _________________ Ask not for whom the bell tolls, it tolls for thee, besides, I'm playing my PSP, tee hee!
------------------------------------------------------
Visit my website for my PSP Homebrew! |
|
| Back to top |
|
 |
jason867
Joined: 24 Jul 2005 Posts: 78
|
Posted: Fri Aug 26, 2005 2:18 pm Post subject: |
|
|
I found this bitmap screenshot code on another thread in this forum;
| Code: | unsigned char bmpHeader24[] = { 0x42, 0x4d, 0x38, 0xfa, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0xe0, 0x01, 0x00, 0x00, 0x10, 0x01, 0x00, 0x00, 0x01, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x0b, 0x00, 0x00, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
unsigned char buffer[SCREEN_WIDTH*3];
unsigned char r,g,b;
int bufferIndex = 0;
unsigned short p;
file = sceIoOpen(savePath,O_CREAT | O_TRUNC | O_RDWR, 0777); // savePath should hold the path to your file
// write bmp header
sceIoWrite(file,bmpHeader24,54);
// write bmp data
vptr0 = pgGetVramAddr(0,271); // you can find this function in NEM's sources
for(i=0; i<272; i++)
{
vptr=vptr0;
for(e=0; e<480; e++)
{
p = *(unsigned short *)vptr;
r = (p<<3)&0xf8;
g = (p>>2)&0xf8;
b = (p>>7)&0xf8;
buffer[bufferIndex] = b;
bufferIndex++;
buffer[bufferIndex] = g;
bufferIndex++;
buffer[bufferIndex] = r;
bufferIndex++;
vptr+=PIXELSIZE*2;
}
// write chunk
sceIoWrite(file,buffer,SCREEN_WIDTH*3);
bufferIndex=0;
vptr0-=LINESIZE*2;
}
// bmp end
unsigned char end[] = { 0x00, 0x00 };
sceIoWrite(file,end,2);
sceIoClose(file); |
But I can't find Nem's Sources, as mentioned here;
| Code: | | vptr0 = pgGetVramAddr(0,271); // you can find this function in NEM's sources |
Since it says 'getVramAddr' I figured I could simply replace it with this (440000, I'm not sure if that's right, but I know I had it right in my source) but it would crash as soon as this function was called. I've looked through it and can't find anything that might be the problem except for this one function call. Can anyone point me in the direciton for 'NEM's sources'?
Thanks for your help. _________________ Ask not for whom the bell tolls, it tolls for thee, besides, I'm playing my PSP, tee hee!
------------------------------------------------------
Visit my website for my PSP Homebrew! |
|
| Back to top |
|
 |
rinco
Joined: 21 Jan 2005 Posts: 255 Location: Canberra, Australia
|
Posted: Fri Aug 26, 2005 2:39 pm Post subject: |
|
|
nowadays we get vram address with this:
| Code: | pspsdk/sdk/ge/pspge.h: * Get the address of VRAM.
pspsdk/sdk/ge/pspge.h:void * sceGeEdramGetAddr(void);
|
this is unlikely to change ever again. |
|
| Back to top |
|
 |
jason867
Joined: 24 Jul 2005 Posts: 78
|
Posted: Fri Aug 26, 2005 4:40 pm Post subject: |
|
|
I changed my code accordingly but my PSP still crashed when calling the screenshot function. It did the same thing when I put the vram address in there too (440000, or whatever it actually is). Is there anything wrong with just putting the address in there? And as far as you can tell, is there anything wrong with this code to be making it crash? _________________ Ask not for whom the bell tolls, it tolls for thee, besides, I'm playing my PSP, tee hee!
------------------------------------------------------
Visit my website for my PSP Homebrew! |
|
| Back to top |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Fri Aug 26, 2005 4:57 pm Post subject: |
|
|
| Your code looks terrible, but what about vptr0+=BUF_WIDTH*2? And take a look at saveImage in graphics.c for a more clean code. |
|
| Back to top |
|
 |
Arwin
Joined: 12 Jul 2005 Posts: 426
|
|
| Back to top |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Fri Aug 26, 2005 6:47 pm Post subject: |
|
|
| Arwin wrote: | Somehow 'src' disappeared from your path to graphics.c, and since I think you copied it, that's really weird.
|
This morning (GMT) it was without "src", but Nevyn restructered it a bit :-) |
|
| Back to top |
|
 |
jason867
Joined: 24 Jul 2005 Posts: 78
|
Posted: Sat Aug 27, 2005 4:13 am Post subject: |
|
|
| Shine wrote: | | Your code looks terrible, but what about vptr0+=BUF_WIDTH*2? And take a look at saveImage in graphics.c for a more clean code. |
Well, that's not my code, I got that from elsewhere here at the ps2dev forums. But thanks for the graphics.c link, I'll take a look at it. _________________ Ask not for whom the bell tolls, it tolls for thee, besides, I'm playing my PSP, tee hee!
------------------------------------------------------
Visit my website for my PSP Homebrew! |
|
| Back to top |
|
 |
jason867
Joined: 24 Jul 2005 Posts: 78
|
Posted: Sat Aug 27, 2005 4:22 am Post subject: |
|
|
I looked at the code in graphics.c, and I've already tried that version (or something extremely similiar). I really don't like .tga files, the only program I have to view them with is quicktime media player, lol. Is there a way to save to a different format than .tga? I'll see if that one fix for the .bmp code works. _________________ Ask not for whom the bell tolls, it tolls for thee, besides, I'm playing my PSP, tee hee!
------------------------------------------------------
Visit my website for my PSP Homebrew! |
|
| Back to top |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Sat Aug 27, 2005 6:11 am Post subject: |
|
|
I've changed the code to save PNG images:
| Code: |
void saveImage(const char* filename, Color* data, int width, int height, int lineSize, int saveAlpha)
{
png_structp png_ptr;
png_infop info_ptr;
FILE* fp;
int i, x, y;
u8* line;
if ((fp = fopen(filename, "wb")) == NULL) return;
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr) return;
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
return;
}
png_init_io(png_ptr, fp);
png_set_IHDR(png_ptr, info_ptr, width, height, 8,
saveAlpha ? PNG_COLOR_TYPE_RGBA : PNG_COLOR_TYPE_RGB,
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
png_write_info(png_ptr, info_ptr);
line = (u8*) malloc(width * (saveAlpha ? 4 : 3));
for (y = 0; y < height; y++) {
for (i = 0, x = 0; x < width; x++) {
Color color = data[x + y * lineSize];
int r = (color & 0x1f) << 3;
int g = ((color >> 5) & 0x1f) << 3 ;
int b = ((color >> 10) & 0x1f) << 3 ;
line[i++] = r;
line[i++] = g;
line[i++] = b;
if (saveAlpha) {
int a = color & 0x8000 ? 0xff : 0;
line[i++] = a;
}
}
png_write_row(png_ptr, line);
}
free(line);
png_write_end(png_ptr, info_ptr);
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
fclose(fp);
}
|
You can call it like this for screenshots: saveImage(filename, getVramDisplayBuffer(), SCREEN_WIDTH, SCREEN_HEIGHT, PSP_LINE_SIZE, 0)
In your Makefile you need to add "-lpng -lz" to your "LIBS" and you have to compile zlib and libpng (which is simply a "make" and "make install" in the directories). |
|
| Back to top |
|
 |
jason867
Joined: 24 Jul 2005 Posts: 78
|
Posted: Sat Aug 27, 2005 10:17 am Post subject: |
|
|
Ok, png is just fine with me. Now, compiling zlib and libpng, I'm not sure where those directories are. Are they in the default cygwin installation? Or in the pspsdk installation? Thanks for the code, I haven't tested it yet, but I'm confident it will work for me. _________________ Ask not for whom the bell tolls, it tolls for thee, besides, I'm playing my PSP, tee hee!
------------------------------------------------------
Visit my website for my PSP Homebrew! |
|
| Back to top |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
|
| Back to top |
|
 |
jason867
Joined: 24 Jul 2005 Posts: 78
|
Posted: Sun Aug 28, 2005 2:05 am Post subject: |
|
|
ok, I've installed everything and changed my code and all. But when I compile, it throughs a bunch of errors, which makes me think I need to include some header files or librarys. Would you happen to know which ones these are? _________________ Ask not for whom the bell tolls, it tolls for thee, besides, I'm playing my PSP, tee hee!
------------------------------------------------------
Visit my website for my PSP Homebrew! |
|
| Back to top |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Sun Aug 28, 2005 2:12 am Post subject: |
|
|
| My crystall sphere is out of order. Compiler errors, linker errors? You have written "include <png.h>" in your file and changed the Makefile as I wrote? |
|
| Back to top |
|
 |
jason867
Joined: 24 Jul 2005 Posts: 78
|
Posted: Sun Aug 28, 2005 3:45 am Post subject: |
|
|
Nice wisecrack, I figured out that I needed to include png.h, but it still threw some errors after typing make. I can't think of the exact wording at the moment, but it was to the effect of 'this is the first time so and so function has been declared' You know, the type of errors you get when you forget to include a header file or something. Oh, I remember one specific problem, in the arguments passed to the saveImage function, the second one (***,color* data,***) is giving problems because the datatype of 'color' hasn't been specified, which I presume is because a certain header wasn't included. I can't remember if this problem was fixed when I figured out that I needed to include png.h. But there were other simliar errors. What other files do I need to include besides png.h? zlib.h? _________________ Ask not for whom the bell tolls, it tolls for thee, besides, I'm playing my PSP, tee hee!
------------------------------------------------------
Visit my website for my PSP Homebrew! |
|
| Back to top |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Sun Aug 28, 2005 3:58 am Post subject: |
|
|
The easiest way would be to look at the graphics.c, but perhaps you forgot "#include <stdio.h>" for fopen? If you don't want to write the error messages, I can't help :-)
And you are right, Color is a typedef (see the graphics.h) and you can replace it with u16, if you are using a 16 bit format. |
|
| Back to top |
|
 |
jason867
Joined: 24 Jul 2005 Posts: 78
|
Posted: Sun Aug 28, 2005 4:08 am Post subject: |
|
|
Owner@Pavilion1200 /usr/local/pspdev/psp/sdk/My_Homebrew/test
$ make
psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -c -o main.o mai
n.c
main.c: In function 'main':
main.c:81: warning: implicit declaration of function 'getVramDisplayBuffer'
main.c:81: warning: passing argument 2 of 'screenshot' makes pointer from intege
r without a cast
psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -L-lpng -L-lz -L.
-L/usr/local/pspdev/psp/sdk/lib main.o -lpspdebug -lpspdisplay -lpspge -lpsp
ctrl -lpspsdk -lc -lpspuser -lpspkernel -o test.elf
main.o: In function `screenshot':
main.c:(.text+0x4fc): undefined reference to `png_create_write_struct'
main.c:(.text+0x50c): undefined reference to `png_create_info_struct'
main.c:(.text+0x520): undefined reference to `png_init_io'
main.c:(.text+0x54c): undefined reference to `png_set_IHDR'
main.c:(.text+0x558): undefined reference to `png_write_info'
main.c:(.text+0x61c): undefined reference to `png_write_row'
main.c:(.text+0x638): undefined reference to `png_write_end'
main.c:(.text+0x644): undefined reference to `png_destroy_write_struct'
main.c:(.text+0x690): undefined reference to `png_destroy_write_struct'
main.o: In function `main':
main.c:(.text+0x84c): undefined reference to `getVramDisplayBuffer'
collect2: ld returned 1 exit status
make: *** [test.elf] Error 1
Owner@Pavilion1200 /usr/local/pspdev/psp/sdk/My_Homebrew/test
$
There's what I've gotten so far.
P.S. I changed the name of the function to 'screenshot' for my own purposes. _________________ Ask not for whom the bell tolls, it tolls for thee, besides, I'm playing my PSP, tee hee!
------------------------------------------------------
Visit my website for my PSP Homebrew! |
|
| Back to top |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Sun Aug 28, 2005 4:21 am Post subject: |
|
|
I quote myself:
| Quote: |
In your Makefile you need to add "-lpng -lz" to your "LIBS" and you have to compile zlib and libpng (which is simply a "make" and "make install" in the directories).
|
and you have to provide getVramDisplayBuffer or use a constant. |
|
| Back to top |
|
 |
jason867
Joined: 24 Jul 2005 Posts: 78
|
Posted: Sun Aug 28, 2005 4:46 am Post subject: |
|
|
I did that makefile stuff, and I did the make and make install's in both directories
By using a constant instead do you mean simply putting a pointer to the beginning of the VRAM there?
So, if I'm not double buffering, then I simply put the begginning address of VRAM at that spot, and it'll work? And if I do use double buffering, then I just need figure out how to switch to the other buffer to take screenshot from, right? _________________ Ask not for whom the bell tolls, it tolls for thee, besides, I'm playing my PSP, tee hee!
------------------------------------------------------
Visit my website for my PSP Homebrew! |
|
| Back to top |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Sun Aug 28, 2005 5:13 am Post subject: |
|
|
| jason867 wrote: | I did that makefile stuff, and I did the make and make install's in both directories
|
yes, you are right, it is another problem, because your compiler command line looks right, I didn't see the -lpng and -lz first. Perhaps you have an outdated PSPSDK.
Please check, if the /usr/local/pspdev/psp/lib/libpng.a is available and from today and "psp-gcc --version" says "psp-gcc (GCC) 4.0.1 (PSPDEV 20050729)" and rebuilt your psptoolchain, if it is older than a week. I don't have any more ideas, but in general PNG works, at least for Lua Player.
Sometimes there are problems with the order in your LIBS variable, for example in Lua Player it looks like this:
| Code: |
LIBS= -llua -llualib -lpng -lz -lpspgu -lm -lmikmod -lmmio -lpspaudiolib -lpspaudio -lpspusb -lpspusbstor
|
| jason867 wrote: |
By using a constant instead do you mean simply putting a pointer to the beginning of the VRAM there?
|
Yes, but using sceGeEdramGetAddr() is more clean, see the samples in the PSPSDK.
| jason867 wrote: |
So, if I'm not double buffering, then I simply put the begginning address of VRAM at that spot, and it'll work? And if I do use double buffering, then I just need figure out how to switch to the other buffer to take screenshot from, right? |
Yes. |
|
| Back to top |
|
 |
jason867
Joined: 24 Jul 2005 Posts: 78
|
Posted: Mon Aug 29, 2005 12:16 am Post subject: |
|
|
I figured it out, I made a small mistake in the makefile. But now it works great! Thanks for everyone's help, especially shine's. If I remember right, this isn't the only thing you've helped me out on...
[Edit} I've now got nice clean screenshots of some of my programs for my website, tee hee! _________________ Ask not for whom the bell tolls, it tolls for thee, besides, I'm playing my PSP, tee hee!
------------------------------------------------------
Visit my website for my PSP Homebrew! |
|
| Back to top |
|
 |
OmahaStylee
Joined: 29 Aug 2005 Posts: 14 Location: Los Angeles, CA
|
Posted: Mon Aug 29, 2005 5:01 pm Post subject: Source? |
|
|
Can you post the completed source of your screen shot code? _________________
 |
|
| Back to top |
|
 |
jason867
Joined: 24 Jul 2005 Posts: 78
|
Posted: Tue Aug 30, 2005 4:36 am Post subject: Re: Source? |
|
|
| OmahaStylee wrote: | | Can you post the completed source of your screen shot code? |
Sure, here it is.
| Code: | void screenshot(const char* filename)
{
png_structp png_ptr;
png_infop info_ptr;
FILE* fp;
int i, x, y;
u16* data = VRAM;
int width=SCR_WIDTH;
int height=SCR_HEIGHT;
int linesize=BUF_WIDTH;
int saveAlpha=0;
u8* line;
if ((fp = fopen(filename, "wb")) == NULL) return;
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr) return;
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
return;
}
png_init_io(png_ptr, fp);
png_set_IHDR(png_ptr, info_ptr, width, height, 8,
saveAlpha ? PNG_COLOR_TYPE_RGBA : PNG_COLOR_TYPE_RGB,
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
png_write_info(png_ptr, info_ptr);
line = (u8*) malloc(width * (saveAlpha ? 4 : 3));
for (y = 0; y < height; y++) {
for (i = 0, x = 0; x < width; x++) {
u16 color = data[x + y * linesize];
int r = (color & 0x1f) << 3;
int g = ((color >> 5) & 0x1f) << 3 ;
int b = ((color >> 10) & 0x1f) << 3 ;
line[i++] = r;
line[i++] = g;
line[i++] = b;
if (saveAlpha) {
int a = color & 0x8000 ? 0xff : 0;
line[i++] = a;
}
}
png_write_row(png_ptr, line);
}
free(line);
png_write_end(png_ptr, info_ptr);
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
fclose(fp);
}
|
in your Cygwin Bash Shell (or whatever you use) enter the folowing lines;
svn co svn://svn.ps2dev.org/psp/trunk/zlib -- press [Enter] and wait for the prompt to show back up.
svn co svn://svn.ps2dev.org/psp/trunk/libpng -- press [Enter] and wait for the prompt to show back up.
[Edit] Those two lines up just above this look like links to websites, but they're not, so don't even bother clicking on them.
then you need to change your directory in the bash shell to your psptoolchain/zlib folder, and then type 'make' and then 'make install'
then change the directory over to your psptoolchain/libpng folder and type 'make' and 'make install' again.
You need to include png.h and you need to add the following to your makefile;
and then when you call the screenshot, make sure to type a valid file path, such as;
| Code: | | screenshot("ms0:/filepath.png"); | With filepath being your filepath. You have to have 'ms0:/' at the beginning and '.png' at the end. Once called you'll see your memory stick led flash several times, and then when you hook up your psp to your pc, you'll find your filepath.png screenshot file at the directory of your memory stick that you set it to write to.
Enjoy!
(Sorry if I got a little too in depth and detailed there, I get that ways sometimes) _________________ Ask not for whom the bell tolls, it tolls for thee, besides, I'm playing my PSP, tee hee!
------------------------------------------------------
Visit my website for my PSP Homebrew! |
|
| Back to top |
|
 |
OmahaStylee
Joined: 29 Aug 2005 Posts: 14 Location: Los Angeles, CA
|
Posted: Tue Aug 30, 2005 6:05 am Post subject: Arg |
|
|
So its not working....
Here is the error its giving me..
| Code: | HP_Owner@Kenya ~/projects/helloworld
$ make kxploit
psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -c -o main.o mai
n.c
main.c: In function 'screenshot':
main.c:55: error: 'VRAM' undeclared (first use in this function)
main.c:55: error: (Each undeclared identifier is reported only once
main.c:55: error: for each function it appears in.)
main.c:56: error: 'SCR_WIDTH' undeclared (first use in this function)
main.c:57: error: 'SCR_HEIGHT' undeclared (first use in this function)
main.c:58: error: 'BUF_WIDTH' undeclared (first use in this function)
main.c:75: warning: implicit declaration of function 'malloc'
main.c:75: warning: incompatible implicit declaration of built-in function 'mall
oc'
main.c:92: warning: implicit declaration of function 'free'
make: *** [main.o] Error 1 |
Here is my Makefile
| Code: | TARGET = hello
OBJS = main.o
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Hello World
LIBS = -lpng -lz
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak |
And here is my source code...
| Code: | // Hello World - My First App for the PSP
/*
This program was created by OmahaStylee on 8-4-05
It is a simple "Hello World" Application.
*/
//Nescisary files with
#include <pspkernel.h>
#include <pspdebug.h>
#include <png.h>
#include <stdio.h>
PSP_MODULE_INFO("Hello World", 0, 1, 2);
// Rename to printf to make it easier
#define printf pspDebugScreenPrintf
// Nescisary files for exiting
/* 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", 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;
}
void screenshot(const char* filename)
{
png_structp png_ptr;
png_infop info_ptr;
FILE* fp;
int i, x, y;
u16* data = VRAM;
int width=SCR_WIDTH;
int height=SCR_HEIGHT;
int linesize=BUF_WIDTH;
int saveAlpha=0;
u8* line;
if ((fp = fopen(filename, "wb")) == NULL) return;
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr) return;
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
return;
}
png_init_io(png_ptr, fp);
png_set_IHDR(png_ptr, info_ptr, width, height, 8,
saveAlpha ? PNG_COLOR_TYPE_RGBA : PNG_COLOR_TYPE_RGB,
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
png_write_info(png_ptr, info_ptr);
line = (u8*) malloc(width * (saveAlpha ? 4 : 3));
for (y = 0; y < height; y++) {
for (i = 0, x = 0; x < width; x++) {
u16 color = data[x + y * linesize];
int r = (color & 0x1f) << 3;
int g = ((color >> 5) & 0x1f) << 3 ;
int b = ((color >> 10) & 0x1f) << 3 ;
line[i++] = r;
line[i++] = g;
line[i++] = b;
if (saveAlpha) {
int a = color & 0x8000 ? 0xff : 0;
line[i++] = a;
}
}
png_write_row(png_ptr, line);
}
free(line);
png_write_end(png_ptr, info_ptr);
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
fclose(fp);
}
// Main function
int main() {
// Start the debug screen
pspDebugScreenInit();
SetupCallbacks();
// Print "Hello, world!"
printf("Hello World, Lets take a screen shot\n\n\n\n\n\n\n\n\n\n THIS IS A SCREEN SHOT");
// Take screenshot
screenshot("ms0:/screenshot.png");
// Pause program until the home button is pressed
sceKernelSleepThread();
return 0;
}
|
Thanks for any and all help... Noobs have to start somewhere, lol. _________________
 |
|
| Back to top |
|
 |
jason867
Joined: 24 Jul 2005 Posts: 78
|
Posted: Tue Aug 30, 2005 9:30 am Post subject: |
|
|
Ok, I don't have much time to elaborate right now, but I'll offer some quick advice. I'll be back on again later tonight.
'VRAM, SCR_WIDTH, SCR_HEIGHT, BUF_WIDTH' are all constants that I used in a graphics.h file that I made for my purposes. But I can tell you what they equal anyways.
"Just type this somewhere before it is used (such as near the beginning of your main.c file).
u16 *VRAM=(void *)(0x44000000);
This is where the screen buffer begins, so that the screenshot function knows where to look.
Put these very close by (above or below the VRAM part)
#define BUF_WIDTH (512)
#define SCR_WIDTH (480)
#define SCR_HEIGHT (272)
Instead of using the three #defines above, you could also just substitute their values in wherever they're needed. But, if you do that it'll be harder to change them to what they need to be if you ever change to a different video mode. (different video modes change the size of the screen in pixels)
As for the other errors, try including stdlib.h
#include <stdlib.h>
I think that might solve the errors. Let me know if it works or not. _________________ Ask not for whom the bell tolls, it tolls for thee, besides, I'm playing my PSP, tee hee!
------------------------------------------------------
Visit my website for my PSP Homebrew! |
|
| Back to top |
|
 |
OmahaStylee
Joined: 29 Aug 2005 Posts: 14 Location: Los Angeles, CA
|
|
| Back to top |
|
 |
jason867
Joined: 24 Jul 2005 Posts: 78
|
Posted: Tue Aug 30, 2005 10:15 am Post subject: |
|
|
Try including this file.
#include <pspdisplay.h>
And then put this line somewhere at the beginning of main.c.
sceDisplaySetMode(1,SCR_WIDTH,SCR_HEIGHT);
Then do your thing and take the picture. I bet that fixes it. _________________ Ask not for whom the bell tolls, it tolls for thee, besides, I'm playing my PSP, tee hee!
------------------------------------------------------
Visit my website for my PSP Homebrew! |
|
| Back to top |
|
 |
OmahaStylee
Joined: 29 Aug 2005 Posts: 14 Location: Los Angeles, CA
|
Posted: Tue Aug 30, 2005 10:56 am Post subject: |
|
|
HP_Owner@Kenya ~/projects/toolkit
$ make kxploit
psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -c -o main.o mai
n.c
main.c:23: error: syntax error before numeric constant
main.c:23: warning: type defaults to 'int' in declaration of 'sceDisplaySetMode'
any ideas? _________________
 |
|
| Back to top |
|
 |
|
|
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
|