Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / Game Design & Programming / scaling in memory bitmap using hardware Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
speedwell

March 17, 2005, 04:29 PM

i'm working on part of an app the creates non-power-of-2 images for me - i want to display them on textures so i need to scale them up to power-of-2.

i'm not able to do it the sensible way and use opengl to scale UVs.

i've looked at some bilinear scaling algorithms but haven't found anything quite right - too slow or not good enough quality.

any suggestions on how i might do this with hardware - i.e. write a method that is pass in an arbitrary sized buffer and it gets scaled to a new, high quality power-of-2 one quickly..

thanks in advance.

 
bananaboy

March 17, 2005, 07:35 PM

What API are you using? If you can use GDI you can use the StretchBlt function although that doesn't do any filtering. GDI+ has some fancy high quality filtering options but I don't think current GDI+ drivers use hardware. Otherwise, what about Direct3D or DirectDraw? I guess if you can't use OpenGL then those two are out of the question..

cheers
sam.

 
speedwell

March 17, 2005, 10:33 PM

thanks sam but there is no common API except opengl - it's a cross platform (win32, mac osx & linux) application.

 
Corre

March 18, 2005, 03:46 AM

How about generating the images onto a power-of-two texture that is larger than the actual image (so that if you have a 100x147 image you generate it onto a 128x256 texture, leaving parts of it blank).

Then you can either use that texture directly, ignoring the wasted space(and memory) or use hardware to draw a quad using the used part of that texture onto another texture that is power-of-two, thus using the built in filtering of the 3D hardware.

 
Rui Martins

March 18, 2005, 03:46 AM

You don't need to stretch the the images!
just define a power of 2 texture width and height big enought to fit the image. Then copy the image to the texture, and place it at UV origin (0,0), then just use the currect texture coords, to map only the image, without using the extra texture area that is left out.

In a more specialized case, if your images are small and many, just create a big texture, and try to fill it (as optimally as you can with images, then use this texture, but adjust the texture coords, according to where the image you want is located in the texture.

 
Rui Martins

March 18, 2005, 04:45 AM

Not fair 8) same time, nearly same content, and your post gets here first !
Touché.

 
speedwell

March 18, 2005, 11:28 AM

Rui Martins wrote: You don't need to stretch the the images! just define a power of 2 texture width and height big enought to fit the image. Then copy the image to the texture, and place it at UV origin (0,0), then just use the currect texture coords, to map only the image, without using the extra texture area that is left out. In a more specialized case, if your images are small and many, just create a big texture, and try to fill it (as optimally as you can with images, then use this texture, but adjust the texture coords, according to where the image you want is located in the texture.


thanks Rui and Corre but that's exactly what I'm doing now but there is no way in the rendering pipeline for me to tell if a poly needs its' UVs scaled so i am unable to adjust them on the fly - plus there is a requirement for repeating textures so the size of the image and the size of the texture needs to match.

 
tussukka

March 18, 2005, 12:41 PM

I wrote a bicubic image resize routine some time ago, here's a few screenshots how it works out in practise:
http://www.liimatta.org/fusion/filter/filter.html

API example (C++):

surface* x = surface::create("test.png");
x->resize(666,42);
// ...

 
tussukka

March 18, 2005, 12:45 PM

p.s. I didn't run sharpening filter on the bicubic (scaled up) image, if wondering why it is slightly blurry. It really depends when you want to so the code doesn't do that automatically..

 
speedwell

March 18, 2005, 05:19 PM

that looks very interesting - thank you - i'll take a look at the library.

 
This thread contains 10 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.