Image scaling

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

Moderators: cheriff, TyRaNiD

Post Reply
Gary13579
Posts: 93
Joined: Mon Aug 15, 2005 7:43 am

Image scaling

Post by Gary13579 »

I've looked all over FileAssistant++ looking for how it scales images, but the source for that is huge and I can't figure out where it is.
I've also searched the forums many many times, and have only found a few Lua functions.

I need a function to scale images.. I've looked at sceGuTexScale in pspgu.h, but there is no documentation on it :(
I would also prefer if it did not loop through the image pixel by pixel changing the size, I want something fast, if possible.
Ryu
Posts: 19
Joined: Mon Oct 17, 2005 8:36 pm

Post by Ryu »

is it to just display them? if yes then just use GL-like functions with proper vertex coordinates and u,v mapping;

example in 16bit:
sceGuDrawArray(GU_SPRITES,GU_TEXTURE_16BIT|GU_COLOR_5551|GU_VERTEX_16BIT|GU_TRANSFORM_2D,2,0,vertices);

and if you use
sceGuTexFilter(GU_LINEAR,GU_LINEAR);

then you'll have a bilinear resize even!
Ryu
Posts: 19
Joined: Mon Oct 17, 2005 8:36 pm

Post by Ryu »

oh yeah with sceGuTexScale(float scaleu,float scalev) you can scale the UV coordinates, actually if you're able to render a sprite on the screen that way (with a texture), then just play a bit with that function and you'll see the textures stretching, so you can use it to scale an image on the screen at least.

u coordinates are multiplied by scaleu
v ... scalev
Gary13579
Posts: 93
Joined: Mon Aug 15, 2005 7:43 am

Post by Gary13579 »

I didn't understand much of that first post, I am pretty new to C :(

So what is scaleu/scalev? Would that just be the amount to scale it by?
If I am understanding correctly, then this

Code: Select all

sceGuTexScale(1.0f, 1.0f);
Would keep the image at original size?
Ryu
Posts: 19
Joined: Mon Oct 17, 2005 8:36 pm

Post by Ryu »

you should look at the examples of the pspsdk, namely the blit.c example.

basically you can draw a quad, let's say you give 4 coordinates
x,y (z=0)
-----------
A 0,0
B 480,0
C 480,272
D 0,272

you can draw that polygon using the sceGu library (similar to opengl), and you can use a texture, so you need to give the u,v mapping coordinates, ranging from 0 to 1 (left and right of the texture), the texture width must be a power of 2.

now imagine you want to zoom x2 on the image, you can just use u,v coordinates with half their values, it'll still draw it on the 480x272 quad...

sorry if it's not clear, and also the sceGuTexScale function is used to scale those u,v coordinates so the values that you give are not from 0 to 1 anymore, use sceGuTexScale(1.0/512,1.0/512) for example if you have a 512x512 texture, then use u,v coordinates corresponding to pixels that you want to draw, so if you want to draw the rectangle 20,10,100,50 on the 480x272 quad, just use u=20 for A and D, u=100 for B and C, v=10 for A and B, v=50 for C and D...

(might have to reverse a value or two if the image is flipped)
chp
Posts: 313
Joined: Wed Jun 23, 2004 7:16 am

Post by chp »

Note that sceGuTexScale() and sceGuTexOffset(), and everything else involving transforms of the ST-coordinates (normalized) into UV-space has no effect when GU_TRANSFORM_2D is specified, what you feed the pipe is raw coordinates. This was incorrectly assumed in early versions of the blit-sample (since it was written back in july), the current one does not use those functions any more.

If you need to be able to transform your texture-coordinates using sceGuTexOffset/Scale(), setup a 2D ortho projection and go with GU_TRANSFORM_3D.
GE Dominator
Post Reply