Manipulating pixels, and hardware accelerated blits

Hello 2D guys. :wink:
I’ve got a special case where I in every frame first need direct access to a surface’s pixels and then I need to blit it to the primary surface with hardware acceleration enabled. I used DirectDraw a few years ago and the code would’ve looked something like this:


dds->Lock(...);
for (...)
{
  // Write pixels to the surface's buffer
}
dds->Unlock(...);
ddsPrimary->Blt(...);

As I understand it, I should create a BuffferedImage to get access to the raw pixels. But the BufferedImage will be kept in system memory instead of video memory, so I won’t be able to use hardware accelerated blits with it. :frowning:
Is there a way to use a video memory surface and access the pixels for a limited time only, just like I would with Lock(…)/Unlock(…), so that I can use hardware accelerated blits AND manipulate the raw pixels?

There’s an example program in the original thread that shows what I’m trying to do.

/Martin

The short answer is there’s no way get access to the vram-based surface’ pixels in Java2D in the way
you can do it in DirectDraw (the lock, use, unlock).

However, for some cases using BufferedImage as it was suggested in the other
thread may work ok if the size of the image is not too large.

I hate to do this again (it seems like stick this into every other thread) but here’s a link to a
demo we wrote for an article. Check out the way the background animation is handled:
https://ping.dev.java.net/
The specific file:
https://ping.dev.java.net/source/browse/ping/src/ping/ZoomyBackground.java?rev=1.4&view=auto&content-type=text/vnd.viewcvs-markup

You can try some tricks like not copying the whole image every time, only
the area where you midified the pixels. Also, if you don’t need to modify the image on each
frame, it may make sense to cache an intermediate image in a VolatileImage and
only update it so often.

Hope this helps.

Thanks,
Dmitri

Ok, thanks.
I described my use case in that other thread. Given that, what would you suggest for me to do? Perhaps I should just live with the fact that I won’t be able to use hw acceleration in this case? Oh well, the hw stretch makes the image blurry anyway… :slight_smile:

I replied in your other Thread.