Jump to content
  • Advertisement
Sign in to follow this  
MarkovChain

Cropping extraneous data from a texture

This topic is 3674 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

A simple(ish) problem I've run into Assume you have a large block of 2d Image data, stored in an RGBA8 format. Most of this image is transparent, but there is a section that has an opaque character on it. I've been trying to come up with a way of cropping out all the unnecessary information, and just saving the new texture that is the with and height required to hold all of the opaque data, and saving the position(top-left corner) of it's placement in the original texture. I could easily brute-force it and just check every pixel iteratively, but I'd prefer to use a more elegant solution. I'd love to just have the artists make the images to the correct canvas size to begin with, but theres no winning that fight. This is going to be done on a grouping of full screen animations, the artists just draw the characters on a transparent layer over the background to handle positioning, but rendering all of those frames in real time is terribly unproductive. Any ideas are welcome. Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Are there any assumptions you can make on these images? As in, will the opaque parts be continuous? Is there a certain minimum size to them? Also, what are your exact goals: do you always want one big block or do you want to create multiple blocks if that will minimize the total surface?

Share this post


Link to post
Share on other sites
Thanks for the quick reply:

I can assume that the image is continuous, as in no floating opaque data.

There is no minimum size to the images, and the frames themselves can vary in size on a scale of 2 or 3. One rectangular section is the preferred route.

I hope that clears it up a bit more. I'm going to use the iterative path as a exhaustive solution, as this will be used on our current art as well as in the future, so I can't guarantee that the images will always be continuous.

Share this post


Link to post
Share on other sites
Quote:
Original post by MarkovChain
There is no minimum size to the images, and the frames themselves can vary in size on a scale of 2 or 3. One rectangular section is the preferred route.

If you stick to one rectangle, then here's a possible optimization: keep track of the furthest opaque pixels you've found so far and for each collumn or row, only check as far as those pixels, from both sides. It's essentially keeping track of the minimum bounding box as you go. This does require you to check along the other axis too, because the first pass only tells you the size of the bounding box along one axis, but that pass only needs to be done for one side, because the initial pass already told you the first row or collumn that contained an opaque pixel, just not the last one.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!