Using Direct3D to resize GDI+ Bitmaps

Using Direct3D to resize GDI+ Bitmaps

Post by Scott Smit » Thu, 02 Dec 2004 21:28:44


I am looking for the fastest method for resizing Bitmap objects.

So far, Intel's IPP library holds the record. With it, I can resize a
1400x1200 Bitmap to 500x500 128 times a second. I suspect Direct 3D would
be faster, but the bottleneck seems to be loading a creating a surface from
a Bitmap object. I am NOT reading Bitmaps from files. I am taking screen
captures.

I suspect Direct3D would be faster, but I am having trouble with the
algorithm. I am a Direct3D novice. I got it working once but a coworker
accidentally undid my checkout from source control and I lost it. The code
I have working had the problem that it took 2.8 seconds to create a surface
from a Bitmap.

The method I am trying to implement needs to look like this:

Bitmap ResizeBitmap(Bitmap srcBitmap, Size newSize);

I am trying to use device.StretchRectangle to actually do the resize. My
algorithm does this:

* Create a surface from a Bitmap (takes 2.8 seconds - won't do me any good
if I can't reduce this to a few ms)
* use StretchRectangle to resize the surface (to the backbuffer)
* copy the resulting surface (backbuffer) to a new Bitmap object

Are there any Direct3D implementation of this out there?

Thanks,

Scott Smith
www.scott-smith.com
 
 
 

Using Direct3D to resize GDI+ Bitmaps

Post by Scott Smit » Fri, 03 Dec 2004 02:43:48

I got the code working again. And
device.StretchRectangle seems insanely fast. I seem to
be getting a rate of 500,000 resizes a second. I don't
quite believe that number.

But putting a bitmap into a surface is taking 2 seconds
and getting the bitmap out of the surface is taking 3
seconds. So it doesn't matter how fast the resize is.

So does anyone have a have algorthm for getting a bitmap
into and out of a Direct3D surface within a few
milliseconds?

Thanks,

Scott Smith
www.scott-smith.com

 
 
 

Using Direct3D to resize GDI+ Bitmaps

Post by Phil Taylo » Fri, 03 Dec 2004 05:11:42

is the perf cost on the D3D or GDI+ side for the "into'?

as far as reading back, eg the 'out of", if the bits went into video memory
that can be slow. 3 s sounds too slow but depending on the side readbacks
from AGP are 5-10x slower than writes. recent drivers get 200Mb/s readbacks
max. theoretical is 1024Mb/s.

then there is managed overhead. mem copying may incur more than method
invocation depending.

might be worth a try using the unmanaged API to see if its better here.
 
 
 

Using Direct3D to resize GDI+ Bitmaps

Post by Scott Smit » Fri, 03 Dec 2004 11:13:33

I think the performance cost is in moving from system memory to video
memory, because individually, Direct3D is FAST and GDI+ is fast. It just
seems to be moving data between the two that's slow.

I am moving 53760000 bits to video memory (Bitmap -> Surface) (1400x1200x32
bits).

I am moving 8000000 bits from video memory (Surface -> Bitmap) (500x500x32
bits).

I can't believe it's that slow. I mean when you BitBlt something to or from
the screen it just takes a small fraction of a second. But it's still
moving pixel data from video to system memory, right?

Scott Smith
www.scott-smith.com
 
 
 

Using Direct3D to resize GDI+ Bitmaps

Post by Phil Taylo » Sat, 04 Dec 2004 03:12:42

Blter hw can do tricks.

memory accesses cant be tricked.

did you try flipping the loop, or operating on 2 bytes or 4bytes or 8bytes
at a time? sometimes memory is organized differently or an aligned access
allows the hw to generate a better access pattern.