Tuesday, April 5, 2011

Array traversal

So last night I worked on my script to split a giant targa image into an matrix of smaller targa images, and I got awfully close to completion. Two things hindered me.

One, I had the image height and width being read from the file as just int instead of short int. D'oh! That screws it up royally when reading as binary (as opposed to ascii). After I finally noticed that (an hour later... ugh), I spent some time trying to figure out how the indices of the small tga image data arrays should translate to the huge tga image data arrays. I didn't finish that part before I decided that sleep was a fortuitous venture.

But in my spare time here at work I think I've figured it out. If the original file has a pixel width of w0 and I want to split it up into a matrix of images with pixel width w1 (where w1 is a multiple of w0), and I use variables i and j to represent the i and j coordinates of the small matrix and idx and jdx to represent the i and j coordinates of the small tile image within the huge image, then I'm preeeeetty certain it can be achieved like this (remember the image data is a 1-dimensional array):
I've tried it out in a spreadsheet (the extent of programming resources here at work) and it seems to work. Suffice to say I'm eager to get home and test it. If successful, my 2048x2048 huge heightmap will yield 1,024 128x128 tiled heightmaps.

From there, I can begin working on the level-of-detail feature I described in yesterday's post.

Hooray!

No comments:

Post a Comment