Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Algorithm for seamless tileablization of any bitmap...

This thread is locked; no one can reply to it. rss feed Print
Algorithm for seamless tileablization of any bitmap...
Edward Sanville
Member #820
December 2000

I want to create a utility which will seamlessly tileablize any bitmap it inputs, and output the result to another bitmap file. I have already devised an algorithm to vertically or horizontally seamlessly tilize any bitmap, pseudocode goes like this:
take bottom half of image, superimpose on top half of image, smoothly gradiating the superimposed half's translucency from 0% to 100% (top to bottom). do the same, superimposing top half on bottom half.
This will make the bitmap vertically seamlessly tileable. the same concept can be used for the right and left halves of the image to make it horizontally seamlessly tileable. Unfortunately, I haven't yet figured out how to make an image both vertically AND horizonatally tileable. I know it's possible, because one can do it in any good image editing program, such as GIMP or Photoshop, but unfortunately my pain program doesn't allow this, and besides, I want to do it to bitmaps on mass production scales for my game. Anybody out there know a way to do this?

Matt Smith
Member #783
November 2000

just do both methods, one after the other, it should work.
for mass production - remember that tiles will only be seamless if they have the same edge types. You may need to generate tiles with every combination of edge types - especially if your map is generated from an algorithm.

There may be more sophisticated algorithms you wish to explore, based on frequencies in the image rather than intensities. This may
give a better blend on textures. nice in theory, but your code sounds fine.

Goku
Member #686
September 2000
avatar

Sorry Matt, but if it's what I think it is, it won't work to do one after the other. What you could do is instead of doing a rectangle the way you mentioned, do a triangle from the corners to the center. That might work a little better.
When Paintshop Pro does it, it requires that the source bitmap be at least 4 times the size of the destination (2x as wide, 2x as tall). Obviously it uses some of the outside areas around it but I'm not sure how...
-Goku
SANE Productions Homepage:
http://www.geocities.com/scsuth

Acheron
Member #790
November 2000

You could try merging the top/bottom edges and the left/right edges without actually merging the very corners where overlap occurs. Then merge the corners as a seperate blend.

Daniel

Jason Heim
Member #484
June 2000

well, this may get messy with some bitmaps, but i use this "algorithm" (more like a method) to make a tile when i'm using corel photo-paint or whatever:

1 - take the bitmap and shift it by half the width horizontally and half the height vertically, wrapping at the edges. this essentially moves the borders into a 'crosshairs' formation into the center of your image.

2 - now work from the centerpoint of each side, blurring or translucently merging as you which, growing wider as you reach the center of the image. do this incrementally, taking one step closer to the center from each edge at a time.

3 - repeat 1 and 2 at least once.

however, you should know that what you are attempting is quite ambitious. for instance, the method i describe above would not work for textures with sharp edges such as marble. it would just look terrible.

to do something with sharp edges, i would keep step 1, but step 2 would be much more complex. you would have to discern where the sharp edges were with a edge detection routine. apply segments to the edges, and connect the segments across the borders by shifting the endpoints. then use the morph algorithm on the segments you drew previously. sound messy? i can tell you, it certainly is!

but for blurry textures, the first algorithm i described should be somewhat effective.

good luck!

jase

Edward Sanville
Member #820
December 2000

Thanks guys, for your responses. I've already tried doing my method twice in succession, and as some very smart person suggested, it didn't work. Took me a while to figure out why, though... Apparently this problem if much more complex than I originally anticipated when I began to code my first algorithm. Oh well...
-Ed

Edward Sanville
Member #820
December 2000

Update on the tilizablizer algorithm!
It turns out I was agonizing over this for nothing. It was as easy as doing my method first vertically, then horizonatlly, as was originally suggested by MattSmith. The reason I thought it wouldn't work was that I thought I'd tried it. I hadn't though, foolishly, because what I had done was to perform the algorithm horizontally and vertically, and merge the two images together. This destroyed the ability of the algorithm to make the image both vertically and horizotally tileable. This is a very nice, very compact algorithm which tileablizes any input bitmap, without the use of messy blurring effects, and without the use of messy triangular bitmap pieces.
-Ed

Edward Sanville
Member #820
December 2000

After exploring the tileability issue some more, it occured to me that one can make a whole array of tiles mutually tileable by using the same algorithm I mentioned above, except by crossing two bitmaps together, one of which has already been self-tileablized. This would make the two tiles mutually tileable. This should come in handy for anyone who wants to make a tile-based game of any kind in which the tiles look convincing, (i.e. not like tiles at all).
-Ed

Matt Smith
Member #783
November 2000

The Inescapable conclusion of doing this to too many different inputs would be that they all have blurry grey edges.
ideally you want to match the 4 edges individually and then blend to them. You could define one bitmap as the 'archetype' of each edge.
If you store the edge types in the tile data you can use this to help your map-generating algorithm.

Edward Sanville
Member #820
December 2000

Yes, what I meant was that you would probably keep one tile as an archetype. For instance, you could make an archetype, seamlessly tileable brick tile, and then work a bunch of other brick bitmaps off of the one, making a whole bunch of slightly different, mutually tileable brick bitmaps. It's too beautiful...
-Ed

Go to: