Not logged inGosu Forums
Forum back to Help Search Register Login
Up Topic Gosu / Extending Gosu / My Addon : GlowImage ( C++)
- By jblovloss Date 2009-07-25 19:41 Edited 2009-07-28 01:22
Glow stands for Gosu "Low"(er), as in low-level. I got a bit annoyed when using Gosu because it was a chore to go back and forth between bitmaps and images when i wanted to dynamically create something. And the fact that I couldn't figure out how to go from Image to Bitmap just made things worse. So, I made a library - a class called a GlowImage, which contains both a bitmap and an image. The Image side gets updated when the bitmap changes, but efficiently, and only when you want it to. I also added lines, fills, and rectangles in there to make things easier.

I started on flipping, but decided to back off on that for now. You can still fetch the original bitmap or image, and call all of Gosu's usual functions on it. By all means, feel free to add features to this class if you like it.


Aha i caught a bug right away. Few of em, actually. Also, a resize function was missing... tsk tsk, Joseph.


Forgot to say... i fixed said bugs
Attachment: (0B)
- By banister Date 2009-07-29 14:06 Edited 2009-07-31 08:38
nice.  you should check out Bresenham's line algorithm for further optimization

also, im really scared of recursive floodfill algorithms, you never had a problem with it blowing the stack on a large image?
- By jblovloss Date 2009-07-31 13:03
Actually i have before, but I hadn't used lines. I simply called recursion up, down, left, right, and 400x400 images crashed it.

For this floodfill, I used what I was SUPPOSED to use - lines. You will never have more items on the stack than horizontal lines needed to fill the space. Take a1027 x 768 resolution - that's only a maximum of 768 recursions on the stack at any one time.  One optimization would be to find the middle of the fill space and start there, thus splitting the max stack usage in half. Probably unneeded.

What you have to remember about recursions is that they're okay as long as they pop off the stack often enough. Every time this algorithm finishes moving upward from a particular spot, the stack gets released all the way back to where it started and it proceeds in another area. Pixel-by-pixel recursion crashed because it basically filled like a constantly moving pen searching for uncolored spots, so that almost every single pixel went on the stack! At 400x400, that's around 160,000 for just a rectangle! Compare that to horizontal lines, which at  worst case will use 400.
Up Topic Gosu / Extending Gosu / My Addon : GlowImage ( C++)

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill