Anyone using PSPTexTool for Textures?

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
ayatollah
Posts: 15
Joined: Sun Sep 04, 2005 10:49 am

Anyone using PSPTexTool for Textures?

Post by ayatollah »

I was wondering if anybody out there is using PSPTexTool 0.00001 by Henrik Rydgård to convert textures?

I am not really good in IO stuff and have troubles loading the textures and applying them.. The DOC in the ZIP describes an own format and not GU which is not that hard but it says in his textureheader struct:

Code: Select all

typedef struct 
{	
	u32 ID; // == 'PSPT'
	u16 bufWidth; //&#40;NOTE! if bufwidth < xsize then so be it! Obey bufwidth always!&#41;
	u16 bufHeight; //&#40;OBEY bufHeight too, with these we can achieve nonpow2 textures if we set texcoords appropriately&#41;
	u16 flags; //&#123;1=Swizzle&#125;
	u8 xsize; //&#40;1<<xsize = texture size in pixels&#41;
	u8 ysize;
	u8 format;
	u8 numMips;
	u8 numCluts;
	u8 clutSize; // or reserved
	//OK we here have 16 bytes. Everything &#40;textures, palettes&#41; needs to be 16-byte aligned
	//Here comes a variable number of pointers to fix up
	//Then comes the texture data for each level
	//All of the texture data are 16-byte aligned
&#125; TextureHeader;
Right at the end
Here comes a variable Number of pointers to fix up
then comes the texture data for each level..

What I successfully can do until now is to load the Texture HEADER (16 bytes) and display this...

But how do I move on and load the actual palette and texture data??

My Load Routine is:

Code: Select all

void *loadTexture&#40;char *filename, TextureHeader *hdr, *texture&#41; 
&#123;
	SceUID myFile;

	myFile = sceIoOpen&#40;filename, PSP_O_RDONLY, 0777&#41;;
	if&#40;!myFile&#41;
	&#123;
			pspDebugScreenPrintf&#40;"Error loading file %s", filename&#41;;
			return NULL;
	&#125;

	sceIoLseek&#40;myFile, 0x00, SEEK_SET&#41;;
	sceIoRead&#40;myFile, hdr, sizeof&#40;TextureHeader&#41;&#41;;


	sceIoClose&#40;myFile&#41;;

	return &#40;void *&#41;0xDEADBEEF; // ignore
&#125;
Maybe somebody has a snip of their own code that shows how I proceed after loading the HEADER?

Your help is greatly appreciated!
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Post by Raphael »

Well, if you take a look at the code, you see that this guy, after the header, places a list of offsets to the mipmaps and cluts. So just do this (in pseudo code):

for (i=0;i<numMips+numClut;i++)
seek(file, 16+i*4, SEEK_SET);
read(file, &offset, 4);

now you can just read the mipmap N by doing this:

seek(file, offset[N], SEEK_SET);
read(file, &tex, (bufwidth >> N)*(bufheight >> N)*bpp );

where bpp is the bytes per pixel with the given tformat (lower 4bit of formats). with RGBA1555 it would be 2 for example.

Now if you have a CLUT texture format, you'd also have to read the appropriate CLUT, which is done by doing this:

seek(file, offset[numMips+N], SEEK_SET);
read(file, &clut, clutSize*entrySize);

where clutSize is either 16 for CLUT4 or 256 for CLUT8 and entrySize is the bytes per pixel with given palformat (upper 4 bit of formats). See above for example.

Then you have the data you need to process to the GU directly in tex and clut, you'd just have to provide if swizzling was applied when uploading texture and clut. Don't forget that tex and clut have to be alligned to 16byte though.

Hope this helps.
ayatollah
Posts: 15
Joined: Sun Sep 04, 2005 10:49 am

Post by ayatollah »

Ok.. I know where you are coming from... however I still have a problem here .. I am sure it's because of my weak general C Knowledge but I will give it another try to get help :)

I tried reading the values from the Textures myself and simply read it (without using variables since I get confused with the pointers and want to get it to load like you wrote once I know it's really working!)

I have this:

Code: Select all

	
sceIoLseek&#40;myFile, 0x00, SEEK_SET&#41;;
sceIoRead&#40;myFile, hdr, sizeof&#40;TextureHeader&#41;&#41;;
This loads the first 16 Bytes (my texture Header is still like this:

Code: Select all

typedef struct 
&#123;	
	u32 ID; // == 'PSPT'
	u16 bufWidth; //&#40;NOTE! if bufwidth < xsize then so be it! Obey bufwidth always!&#41;
	u16 bufHeight; //&#40;OBEY bufHeight too, with these we can achieve nonpow2 textures if we set texcoords appropriately&#41;
	u16 flags; //&#123;1=Swizzle&#125;
	u8 xsize; //&#40;1<<xsize = texture size in pixels&#41;
	u8 ysize;
	u8 format;
	u8 numMips;
	u8 numCluts;
	u8 clutSize; // or reserved
	//OK we here have 16 bytes. Everything &#40;textures, palettes&#41; needs to be 16-byte aligned
	//Here comes a variable number of pointers to fix up
	//Then comes the texture data for each level
	//All of the texture data are 16-byte aligned
&#125; TextureHeader;
since the offset to the MipMaps and CLUTs (I am using a CLUT8 Texture with 8888 Palette (since the converter does only this!) should be included in the struct, how can i specify them?? they are 32bit but according to the number of MIPMAPS they have either 4 or 1 set of 32bit chunks.. same for the CLUTs..

I tried to save the texture without MIP MAPs and the file
shows:

0x00 - 0x0f => Texture Header
0x10 - 0x13 => Offset to Texture (in this case 0x20 0x00 0x00 0x00)
0x14 - 0x17 => Offset to Palette (in this case 0x20 0x00 0x01 0x00)

I am declaring the following for Texture Data and Palette at the beginning of my main.c:

Code: Select all

unsigned char __attribute__&#40;&#40;aligned&#40;16&#41;&#41;&#41; dragontex&#91;256*256&#93;;
unsigned int __attribute__&#40;&#40;aligned&#40;16&#41;&#41;&#41; dragonpal&#91;256&#93;;
So without reading the Offsets from the File, I simply try to load like this:

Code: Select all

/* Load actual Texture */
	sceIoLseek&#40;myFile, 0x20, SEEK_SET&#41;;
	sceIoRead&#40;myFile, &dragontex, &#40;hdr->bufWidth&#41;*&#40;hdr->bufHeight&#41;&#41;;

/* Load actual first CLUT */
	sceIoLseek&#40;myFile, 0x00010020, SEEK_SET&#41;;
	sceIoRead&#40;myFile, &dragonpal, 256*4&#41;;
The Texture is 256x256 Pixel and since it's a CLUT8, 0x10000 is the length of it.. on the CLUT itself I am reading 256*4 since each color needs 4 Bytes..

I get some result on my cube that reflects the colors but the texture itself is completely messed up.

If i try to load the texture as raw and link it with bin2o in the Makefile it works just fine.. I just want to be more flexible and actually use that cool Converter for further projects..

I know this is completly n00b question but I still hope somebody out there can help me with this!!
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Post by Raphael »

Just had a short look over what you wrote, and one thing I notice is, that you declare unsigned int __attribute__((aligned(16))) dragonpal[256]; for your CLUT, but since its a CLUT8 it has 32bit and thus should be unsigned long.
ayatollah
Posts: 15
Joined: Sun Sep 04, 2005 10:49 am

Post by ayatollah »

The strangest thing is, that the load routine works fine with RAW files.. The same texure when loaded and byteflipped from RGB to ABGR works like a charm! ? !
ayatollah
Posts: 15
Joined: Sun Sep 04, 2005 10:49 am

Post by ayatollah »

Thanx for that hints.. I finally managed to do it..
Insert_witty_name
Posts: 376
Joined: Wed May 10, 2006 11:31 pm

Post by Insert_witty_name »

Sorry to bump such an old topic, but I'd like any info there is on loading the textures from this tool. Thanks.
Post Reply