|
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
View previous topic :: View next topic |
Author |
Message |
ardatan
Joined: 12 Jan 2008 Posts: 44
|
Posted: Wed Apr 29, 2009 4:40 am Post subject: [PSP] sceJpeg Sample |
|
|
I have prepared a sample for usage of sceJpeg instead of Jpeglib.
Thanks to J.K. for his help....
And thanks to DXLibraryPortable Creators for their useful library...
If you add this to PSPSDK, it may help someone for his/her new app. :)
main.c
Code: | /*
* PSP Software Development Kit - http://www.pspdev.org
* -----------------------------------------------------------------------
* Licensed under the BSD license, see LICENSE in PSPSDK root for details.
*
* main.c - sceJpeg Sample
*
* Copyright (c) 2009 Ardatan
*
*/
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspsdk.h>
#include <stdlib.h>
#include <pspdisplay.h>
#include <pspjpeg.h>
#include <kubridge.h>
PSP_MODULE_INFO("JpegSample", PSP_MODULE_USER, 1, 1);
PSP_HEAP_SIZE_MAX();
#define BUF_WIDTH (512)
#define SCR_WIDTH (480)
#define SCR_HEIGHT (272)
#define PIXEL_SIZE (4)
#define FRAME_SIZE (BUF_WIDTH * SCR_HEIGHT * PIXEL_SIZE)
#define ZBUF_SIZE (BUF_WIDTH SCR_HEIGHT * 2)
#define printf pspDebugScreenPrintf
#define PTR2HND(PTR) ((PTR) - 1)
#define HND2PTR(HND) (HND + 1)
u32 *vram = (u32 *)0x04000000;
/* 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;
}
int FileRead_open(const char* FileName)
{
return PTR2HND(sceIoOpen(FileName,PSP_O_RDWR,0777));
}
int FileRead_close(int FileHandle)
{
if(FileHandle == -1)return -1;
sceIoClose(HND2PTR(FileHandle));
return 0;
}
int FileRead_size(const char *FileName)
{
SceIoStat stat;
if(sceIoGetstat(FileName,&stat) < 0) return -1;
if(stat.st_size > 0x00000000ffffffff)return 0xffffffff;
return stat.st_size;
}
int FileRead_read(void * Buffer,int Size,int FileHandle)
{
if(FileHandle == -1)return -1;
return sceIoRead(HND2PTR(FileHandle),Buffer,Size);
}
u8* convertjpeg(const char *FileName)
{
printf("Convert Starts\n");
int size = FileRead_size(FileName);
static u32 rgbabuf[480*272] __attribute__((aligned(64)));
u8* databuf = (u8*)malloc(size);
if(databuf == NULL || rgbabuf == NULL)
{
printf("Malloc Error!\n");
free(databuf);
free(rgbabuf);
sceJpegDeleteMJpeg();
sceJpegFinishMJpeg();
return NULL;
}
int fh = FileRead_open(FileName);
if(fh == -1)
{
printf("File couldn't open!\n");
free(databuf);
free(rgbabuf);
sceJpegDeleteMJpeg();
sceJpegFinishMJpeg();
return NULL;
}
FileRead_read(databuf,size,fh);
FileRead_close(fh);
int res = sceJpegDecodeMJpeg(databuf,size,rgbabuf,0);
free(databuf);
sceJpegDeleteMJpeg();
sceJpegFinishMJpeg();
if(res < 0)
{
printf("Decode Error!\n");
free(rgbabuf);
return NULL;
}
printf("Convert is completed!\n");
sceDisplaySetMode(0, 480, 272);
sceDisplaySetFrameBuf((void *)0x04000000, 512, PSP_DISPLAY_PIXEL_FORMAT_8888, PSP_DISPLAY_SETBUF_NEXTFRAME);
int i, j, m, n;
for (i = 0; i < 272; i++)
{
m = i*480;
n = i*512;
for (j = 0; j < 480; j++)
{
vram[n+j] = rgbabuf[m+j];
}
}
return 0;
}
int LoadStartModule(char *path)
{
u32 loadResult;
u32 startResult;
int status;
loadResult = kuKernelLoadModule(path, 0, NULL);
if (loadResult & 0x80000000) {
return -1;
}
else {
startResult = sceKernelStartModule(loadResult, 0, NULL, &status, NULL);
}
if (loadResult != startResult) {
return -2;
}
return 0;
}
int StartJpegPsp()
{
printf("Loading 'flash0:/kd/avcodec.prx'...");
if (LoadStartModule("flash0:/kd/avcodec.prx") == 0) {
printf("ok\n");
}
else {
printf("failed\n");
return -1;
}
printf("init Jpeg decompression...");
if (sceJpegInitMJpeg() == 0) {
if (sceJpegCreateMJpeg(480, 272) == 0) {
printf("ok\n");
return 0;
}
}
printf("failed\n");
return -1;
}
int main(void)
{
SetupCallbacks();
pspDebugScreenInit();
StartJpegPsp();
convertjpeg("background.jpg");
sceKernelSleepThread();
return 0;
}
|
Makefile
Code: | TARGET = jpegsample
OBJS = main.o
LIBS = -lpspkubridge -lpspjpeg
INCDIR =
CFLAGS = -O0 -G0 -Wall -g
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
BUILD_PRX = 1
PSP_LARGE_MEMORY = 1
LIBDIR =
PSPBIN = $(PSPSDK)/../bin
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = JPEG
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak |
_________________ I'm sorry for my bad English. |
|
Back to top |
|
|
jimparis
Joined: 10 Jun 2005 Posts: 1179 Location: Boston
|
Posted: Tue Jun 23, 2009 7:41 am Post subject: |
|
|
kubridge isn't in the sdk, so this can't be added as-is.
Can you repost as a full patch (with Makefile.am changes, etc) with that fixed up? |
|
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
|