Gimp plugin

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

Moderators: cheriff, TyRaNiD

hitchhikr
Posts: 83
Joined: Sat Feb 04, 2006 3:33 pm

Gimp plugin

Post by hitchhikr »

http://perso.orange.fr/franck.charlet/PSPTex.zip

PSPTex is a save plugin for GIMP 2.2.x allowing to create textures for the PlayStation Portable.

It can save raw RGBA (5650, 5551, 4444 or 8888) & indexed (T4, T8) textures (with 5650, 5551, 4444 or 8888 palette modes support) as well as DXTC (DXT1, DXT3, DXT5) compresssed ones, it supports the PSP textures swizzle mode and can generate mipmaps, it also have a color key feature to handle transparency and can convert grayscale pictures into alpha channel only textures.

(Note: if the plugin doesn't work under windows you'll need to copy the gimp dlls into the system directory).
Last edited by hitchhikr on Fri Sep 15, 2006 3:57 am, edited 6 times in total.
white rabbit
Posts: 60
Joined: Wed Jul 06, 2005 7:03 pm

Post by white rabbit »

Thanks for that - I was thinking of making a texture editor, but was putting it off with all the work required.

I'll give that a go tonight!
hitchhikr
Posts: 83
Joined: Sat Feb 04, 2006 3:33 pm

Post by hitchhikr »

I modified the description as this is not a texture editor but only a plugin allowing you to save pictures as raw datas in formats suitable for the psp.
User avatar
Drakonite
Site Admin
Posts: 990
Joined: Sat Jan 17, 2004 1:30 am
Contact:

Post by Drakonite »

Do you plan on releasing the source some time?
Shoot Pixels Not People!
Makeshift Development
hitchhikr
Posts: 83
Joined: Sat Feb 04, 2006 3:33 pm

Post by hitchhikr »

Prolly in a couple of days, just the time to cleanup the source code.
white rabbit
Posts: 60
Joined: Wed Jul 06, 2005 7:03 pm

Post by white rabbit »

Sorry, that's pretty much what I meant - I can edit the texture data outside of the image without too much hassle, but editing an image in a knocked up app is never fun.
hitchhikr
Posts: 83
Joined: Sat Feb 04, 2006 3:33 pm

Post by hitchhikr »

New version released including source code, same url as mentioned before.
User avatar
Drakonite
Site Admin
Posts: 990
Joined: Sat Jan 17, 2004 1:30 am
Contact:

Post by Drakonite »

I've hacked it up a bit and have gotten it running on the linux version of gimp (developer version 2.3.8)

I've ran into a couple problems though...

The image is upside down (height-(y+1) used instead of y) I know this is often done in windows bmp files, but I don't think this is a good thing for the psp? ... was this intentional or is it a bug?

It seems it's supposed to automatically resize the image to a power of 2 width, however it does not appear to be working... I don't have time to look into why right now unfortunatly.

Also, do you have any intentions of adding support for saving the alpha channel?
Shoot Pixels Not People!
Makeshift Development
hitchhikr
Posts: 83
Joined: Sat Feb 04, 2006 3:33 pm

Post by hitchhikr »

The image is upside down (height-(y+1) used instead of y) I know this is often done in windows bmp files, but I don't think this is a good thing for the psp? ... was this intentional or is it a bug?
I'm copying the texture from top to bottom, maybe your uv coordinates are upside down ? In the worst case, flip it vertically within gimp :D
If it's really a problem, i may add an option to allow reverting the textures for saving them, eventually.
It seems it's supposed to automatically resize the image to a power of 2 width, however it does not appear to be working... I don't have time to look into why right now unfortunatly.
No it's not, there's no reason why it should do that, the pow stuff is only used to generate the xxx_TEXTURE_WIDTH constant which is compliant with the textures sizes passed to the psp, the xxx_TEXTURE_REAL_WIDTH contains the real pixels width (as implied), both are to be passed to sceGuTexImage(). The plugin generates a .h file beside the .psptex as an helper.
Also, do you have any intentions of adding support for saving the alpha channel?
There's full support for alpha channel already (unless i screwed something up somewhere).
User avatar
Drakonite
Site Admin
Posts: 990
Joined: Sat Jan 17, 2004 1:30 am
Contact:

Post by Drakonite »

hitchhikr wrote: I'm copying the texture from top to bottom, maybe your uv coordinates are upside down ? In the worst case, flip it vertically within gimp :D
If it's really a problem, i may add an option to allow reverting the textures for saving them, eventually.
So it's just my imagination that line 275 is the following? ;)

Code: Select all

offset = (((height - (y + 1)) * width) + x);
No it's not, there's no reason why it should do that, the pow stuff is only used to generate the xxx_TEXTURE_WIDTH constant which is compliant with the textures sizes passed to the psp, the xxx_TEXTURE_REAL_WIDTH contains the real pixels width (as implied), both are to be passed to sceGuTexImage(). The plugin generates a .h file beside the .psptex as an helper.
Erm.. don't you need the buffer width to be a factor of 2?
Even if you do, not neccisarily saying it's something it should do for you, just mentioning ;)
There's full support for alpha channel already (unless i screwed something up somewhere).
Doesn't seem to work for me... which could be anything from me screwying up to a change in gimp, to you screwying up ;) ... One way or another I'll look into it more after the compo.
Shoot Pixels Not People!
Makeshift Development
hitchhikr
Posts: 83
Joined: Sat Feb 04, 2006 3:33 pm

Post by hitchhikr »

So it's just my imagination that line 275 is the following? ;)
Code:

Code: Select all

  offset = (((height - (y + 1)) * width) + x);
Damn you're right :D
I must have used this for a test purpose but i can't remember which one now, i'll modify that.
Erm.. don't you need the buffer width to be a factor of 2?
Nope, you can do such stuff:

Code: Select all

TEST_TEXTURE_WIDTH 512
TEST_TEXTURE_HEIGHT 256
TEST_TEXTURE_REAL_WIDTH 480
 sceGuTexImage(0, TEST_TEXTURE_WIDTH, TEST_TEXTURE_HEIGHT, TEST_TEXTURE_REAL_WIDTH, &Bytes);
Only the width & height arguments must be power of 2, the tbw one can be anything provided it's aligned on 4 bits i think, it's handy to avoid vram wasting.
Doesn't seem to work for me... which could be anything from me screwying up to a change in gimp, to you screwying up ;) ... One way or another I'll look into it more after the compo.
I'll be interested to know what picture and what mode you used to test it. Notice that in order for the alpha channel to be active you'll need to use something like that in your code:

Code: Select all

	sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
	sceGuEnable(GU_BLEND);
User avatar
Drakonite
Site Admin
Posts: 990
Joined: Sat Jan 17, 2004 1:30 am
Contact:

Post by Drakonite »

hitchhikr wrote:
So it's just my imagination that line 275 is the following? ;)
Code:

Code: Select all

  offset = (((height - (y + 1)) * width) + x);
Damn you're right :D
I must have used this for a test purpose but i can't remember which one now, i'll modify that.
That line was for indexed images I believe, you have the same line somewhere else for RGB images I think.. so make sure you catch both (I had to recompile earlier as I missed the indexed one yesterday ;) )
I'll be interested to know what picture and what mode you used to test it. Notice that in order for the alpha channel to be active you'll need to use something like that in your code:

Code: Select all

	sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
	sceGuEnable(GU_BLEND);
Hrm... Well I think I was doing things right earlier, but I'll try to play with it more today and see what is going on, as it would be nice to have alpha channels in some of my graphics I'm converting. ;)
Shoot Pixels Not People!
Makeshift Development
hitchhikr
Posts: 83
Joined: Sat Feb 04, 2006 3:33 pm

Post by hitchhikr »

Lines: 275, 284, 326 & 375.

I'll remake some tests but i remember i checked the alpha channel stuff thoroughly and it worked fine in every modes.
hitchhikr
Posts: 83
Joined: Sat Feb 04, 2006 3:33 pm

Post by hitchhikr »

I forgot to mention, make sure you're using this too:

Code: Select all

	sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
The default is GU_TCC_RGB i think.
Last edited by hitchhikr on Mon Jun 19, 2006 2:07 am, edited 1 time in total.
hitchhikr
Posts: 83
Joined: Sat Feb 04, 2006 3:33 pm

Post by hitchhikr »

Oki i inverted the y coordinates (i think it was because i first tested'em on tga pictures or something) and i fixed a bug in the palette mask constant (wasn't 0xff for > 16 colors palettes).

EDIT: Also it creates xxx_TEXTURE_HEIGHT & xxx_TEXTURE_REAL_HEIGHT constants.
User avatar
Drakonite
Site Admin
Posts: 990
Joined: Sat Jan 17, 2004 1:30 am
Contact:

Post by Drakonite »

Okay, more bugs...

In the event of of an alpha channel you are reading gimp's data as ABGR, but it seems to be BGRA... and you are using 0xff - A for alpha...
changing those two things I now how correctly working alpha :)
Shoot Pixels Not People!
Makeshift Development
hitchhikr
Posts: 83
Joined: Sat Feb 04, 2006 3:33 pm

Post by hitchhikr »

Ok, i made a test with this and a texture called test and it worked flawlessly as expected:

Code: Select all

	sceGuClearColor(0xffffffff);
	sceGuColor(0xffffffff);

	sceGuClutMode(TEST_PALETTE_FORMAT, 0, TEST_PALETTE_MASK, 0);
	sceGuClutLoad(TEST_PALETTE_COLORS, &RES_TEXTURE_PALETTE);
			
	sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
	sceGuEnable(GU_BLEND);

	sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
	sceGuTexMode(TEST_TEXTURE_FORMAT, TEST_TEXTURE_MIPMAPS, 0, TEST_TEXTURE_SWIZZLE);
	sceGuTexFilter(GU_NEAREST, GU_NEAREST);

	sceGuTexImage(0, TEST_TEXTURE_WIDTH, TEST_TEXTURE_HEIGHT, TEST_TEXTURE_REAL_WIDTH, &RES_TEXTURE);
	sceGuEnable(GU_TEXTURE_2D);

	vertices[0].tu = 0; vertices[0].tv = 0;
	vertices[0].x = 0; vertices[0].y = 0; vertices[0].z = 0;
	vertices[1].tu = TEST_TEXTURE_REAL_WIDTH; vertices[1].tv = TEST_TEXTURE_REAL_HEIGHT;
	vertices[1].x = TEST_TEXTURE_REAL_WIDTH; vertices[1].y = TEST_TEXTURE_REAL_HEIGHT; vertices[1].z = 0;
	sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF | GU_VERTEX_32BITF | GU_TRANSFORM_2D, 2, 0, vertices);

	sceGuDisable(GU_TEXTURE_2D);
	
	sceGuDisable(GU_BLEND);
User avatar
Drakonite
Site Admin
Posts: 990
Joined: Sat Jan 17, 2004 1:30 am
Contact:

Post by Drakonite »

Do you mean before or after the change I mentioned?
Shoot Pixels Not People!
Makeshift Development
hitchhikr
Posts: 83
Joined: Sat Feb 04, 2006 3:33 pm

Post by hitchhikr »

Before your penultimate post.
User avatar
Drakonite
Site Admin
Posts: 990
Joined: Sat Jan 17, 2004 1:30 am
Contact:

Post by Drakonite »

Hm... k.

FYI I've been using 8888 textures during these test, not paletted textures; that may make a difference...

I've been doing essentially the same as what you've said (though I've done a bunch of other stuff too...) and the original code does not work, while changing the two things I mentioned fixes the issues.

If yours works for you, and mine works for me, I think gimp may have changed how it does things a bit.. As I mentioned I'm using 2.3.8, which is the second to newest dev release... (I don't think they make windows builds of development versions) They changed a lot, so perhaps some of the problems may be caused by changes they've made.
Shoot Pixels Not People!
Makeshift Development
hitchhikr
Posts: 83
Joined: Sat Feb 04, 2006 3:33 pm

Post by hitchhikr »

If yours works for you, and mine works for me, I think gimp may have changed how it does things a bit.. As I mentioned I'm using 2.3.8, which is the second to newest dev release... (I don't think they make windows builds of development versions) They changed a lot, so perhaps some of the problems may be caused by changes they've made.
That's what i was suspecting.
And it wouldn't surprise me as they always screw everything up from one release to another. Actually there's a 2.3.8 release for windows but even the plugins provided with the distrib don't work. I'll stick to the lastest stable release myself.

EDIT: I tested again with a 8888 texture and it still works perfectly.
hitchhikr
Posts: 83
Joined: Sat Feb 04, 2006 3:33 pm

Post by hitchhikr »

Actually, you could tell me what code you did modify so maybe i can update the plugin to operate differently under 2.3 & 2.2 ?
hitchhikr
Posts: 83
Joined: Sat Feb 04, 2006 3:33 pm

Post by hitchhikr »

v1.0 released:

http://perso.orange.fr/franck.charlet/PSPTex.zip

- Fixed GIMP_RGBA_IMAGE, GIMP_GRAYA_IMAGE & GIMP_INDEXEDA_IMAGE inputs.
- Should now compile correctly under linux & co.
Oobles
Site Admin
Posts: 347
Joined: Sat Jan 17, 2004 9:49 am
Location: Melbourne, Australia
Contact:

Post by Oobles »

Just to let you know, I've put a mirror up at:

http://ps2dev.org/psp/Tools/PSPTex

I'll post info to news too.

Oobles.
hitchhikr
Posts: 83
Joined: Sat Feb 04, 2006 3:33 pm

Post by hitchhikr »

I released a 1.01 version (http://registry.gimp.org/plugin?id=7855).

Also i think you should link it to http://perso.orange.fr/franck.charlet/PSPTex.zip instead of mirroring it.
Oobles
Site Admin
Posts: 347
Joined: Sat Jan 17, 2004 9:49 am
Location: Melbourne, Australia
Contact:

Post by Oobles »

No problem. Will modify the page to link instead of mirroring.

Oobles.
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

this is a great plugin under linux thanx alot :)
10011011 00101010 11010111 10001001 10111010
Findeton
Posts: 2
Joined: Thu Aug 31, 2006 10:23 pm

Post by Findeton »

Drakonite wrote:I've hacked it up a bit and have gotten it running on the linux version of gimp (developer version 2.3.8)

I've ran into a couple problems though...

The image is upside down (height-(y+1) used instead of y) I know this is often done in windows bmp files, but I don't think this is a good thing for the psp? ... was this intentional or is it a bug?

It seems it's supposed to automatically resize the image to a power of 2 width, however it does not appear to be working... I don't have time to look into why right now unfortunatly.

Also, do you have any intentions of adding support for saving the alpha channel?
I'm also under linux, how can i get it running on the linux version of the gimp?
hitchhikr
Posts: 83
Joined: Sat Feb 04, 2006 3:33 pm

Post by hitchhikr »

You have to compile it and for this you need the gimp devel package or something.
hitchhikr
Posts: 83
Joined: Sat Feb 04, 2006 3:33 pm

Post by hitchhikr »

Fixed some issues when compiling under linux.
Post Reply