Jump to content
  • Advertisement
Sign in to follow this  
fluke

functions to handle multiple pixel bit depths

This topic is 3718 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

the short version: how can i write a function to process both 8-bit and 16-bit images so i don't have to write two versions of that function? the long version: i've been working on a small image processing application which targets huge jpeg/tiff images. it will load both 8-bit and 16-bit images (8-bit and 16-bit per channel of course). up until now, i just used an unsigned short buffer to store my images, and do my processing before saving them back to the disk. naturally, 8-bit images had their final color values type-casted to prevent compiler warnings, though clipping functions kept any out-of-bounds mischief from happening... anyway, now i'm doing some more complicated routines where storing several copies of this buffer into other buffers becomes necessary, or at least convenient - but i'm not crazy about the amount of memory i'm consuming. i only want to consume the appropriate amount of memory for the images being loaded as most of them will more than likely be 8-bit. approaches i've considered: 1) converting the char/short values to double (0.-1.) on entry, processing them, then returning them back. lots of overhead here, though... 2) passing void pointers and a value representing the type: not sure if this is doable, how to do it, or if it is safe.

Share this post


Link to post
Share on other sites
Advertisement
This excellent article shows exactly how you do it. It's called policy based design. Basically you simply write some classes that know how to perform certain operations on pixels, and then template your functions based on this pixel type. There's more to it than that though, you really need to read the article.

I've got my software 3D engine working in 8, 16, 24, and 32 bit effortlessly using this technique, without code duplication.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!