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: Select all
/*
* 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;
}
Code: Select all
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