• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Switching ColorModels In Realtime

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've been delving into a bit of game-related development lately, and I have thread which constantly renders an offscreen buffer to a panel. I'm emulating 80x25 text-mode, so 16-colors are available (4-bit IndexColorModel). I had quite the time figuring out how to get fades to work smoothly, both in speed and quality, but now I've got most everything working how I'd like.
My only gripe is, whenever performing fades, I must recreate the offscreen image (a BufferedImage) with the altered ColorModel each step along the way. This eats up a couple megs worth during each fade. That wouldn't even particularly bother me, except that it causes the garbage colletion to trigger every so often, and my fades will ungracefully pause.
If I call System.gc() before each fade, I get the wait up front and then the fades are always fine, but I'd really rather just figure out how to switch the color model without having to reallocate memory, ie. a more elegant solution. I do realize that I might not always be able to avoid these kind of pauses in my Java apps, but I can at least take some preventive measures. :-)
A ColorModel is just a rule for color conversion after all, right? It seems rather silly that there wouldn't be some simple mechanism available for swapping out different ones. Perhaps right under my nose? Wouldn't that be swell...
So far I've been unable to find anything that does what I want, and I've been picking through the API for I don't know how long (okay, a couple weeks in my spare time). I've also surfed around quite a bit, in search of some example code doing anything similar, but the only example I did find was something to do with fractals and palette rotation -- but it also regenerates the image every frame.
Any help/hints anyone can offer would be much appreciated!
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to the Swing / AWT forum.
 
I'm not dead! I feel happy! I'd like to go for a walk! I'll even read a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic