libjpg sample source?

Discuss the development of software, tools, libraries and anything else that helps make ps2dev happen.

Moderators: cheriff, Herben

Post Reply
LBGSHI
Posts: 136
Joined: Mon Aug 07, 2006 5:56 am
Contact:

libjpg sample source?

Post by LBGSHI »

I've compiled myPS2's libjpg (as the current libjpg in svn.ps2dev.org/ps2/trunk/libjpg doesn't compile), and copied libjpg.a and libjpg.h to the appropriate directories (thanks to ragnarok2040 for mentioning this idea in a thread), but I have no way of testing libjpg...

Might anyone have some source that requires libjpg, so I can do some testing?
I may be lazy, but I can...zzzZZZzzzZZZzzz...
ragnarok2040
Posts: 202
Joined: Wed Aug 09, 2006 1:00 am

Post by ragnarok2040 »

I don't have a full source, but I think I can post enough of an example on how to convert a jpg into a texture gsKit can use. It's based off what I saw in uLaunchelf. If you haven't patched libjpg with uLaunchelf's modified files, you should replace JPG_FIXED_WIDTH with JPG_NORMAL.

Code: Select all

#include <stdio.h>
#include <libjpg.h>
#include <gsKit.h>

GSTEXTURE BG_TEX;

void loadJpg&#40;void&#41;
&#123;
    jpgData *Jpg;
    u8 *ImgData;


    FILE *File = fopen&#40;jpgPath, "r"&#41;;
    if&#40;File != NULL&#41; &#123;

        Jpg = jpgOpenFILE&#40; File, JPG_WIDTH_FIX&#41;;
        ImgData = malloc &#40; Jpg->width * Jpg->height * &#40;Jpg->bpp / 8&#41; &#41;;
        jpgReadImage&#40; Jpg, ImgData  &#41;;
        BG_TEX.PSM = GS_PSM_CT24;
        BG_TEX.Clut = NULL;
        BG_TEX.VramClut = 0;
        BG_TEX.Width = Jpg->width;
        BG_TEX.Height = Jpg->height;
        BG_TEX.Filter = GS_FILTER_LINEAR;
        BG_TEX.Mem = &#40;void*&#41;ImgData;
        BG_TEX.Vram = gsKit_vram_alloc&#40;gsGlobal, gsKit_texture_size&#40;BG_TEX.Width, BG_TEX.Height, BG_TEX.PSM&#41;, GSKIT_ALLOC_USERBUFFER&#41;;

        gsKit_texture_upload&#40;gsGlobal, &BG_TEX&#41;;

    &#125;
&#125;
Since it's in the same vein :D, I was having trouble with the ps2sdk-ports version of libpng, so I found a way to compile it with the myPS2 version instead.

If you want to compile gsKit with ntba2's libpng:
get ps2sdk-ports/zlib
make && make install
get ntba2's libpng from the myPS2 project off SVN
get ps2sdk-ports/libpng
copy ntba2's libpng.a to ps2sdk/ports/lib
copy ps2sdk-ports/libpng/png.h to ps2sdk/ports/include
copy ps2sdk-ports/libpng/pngconf.h to ps2sdk/ports/include
modify gsKit's Makefile.global and change:
EE_LIBS += -lz -lpng
to
EE_LIBS += -lm -lz -lpng
Then define LIBPNG=$PS2SDK/ports and define ZLIB as the same.

Then you can use gsKit_texture_png(gsGlobal, &BG_TEX, pngPath); to load png images instead of using his libpng.h header.
LBGSHI
Posts: 136
Joined: Mon Aug 07, 2006 5:56 am
Contact:

Post by LBGSHI »

That's awesome; thanks a lot for your help. I'll start toying with all of this after I finish fixing another issue.

Thanks again.
I may be lazy, but I can...zzzZZZzzzZZZzzz...
Post Reply