Jump to content
  • Advertisement
Sign in to follow this  
DarkCybo1

Where can I find a resource on how to create a custom image format?

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

For instance, I dont know how I would store the data of each pixel. I'm wanting to do this because I plan to create a custom format for an OpenGL application. Also, I'm using the C++ language.

Share this post


Link to post
Share on other sites
Advertisement
THe language doesnt matter....how you want to store the pixels is up to you since its your own format...a raw format does nothing but store the pixel, pixel by pixel. Something like a bitmap though has a header with info and stores RGB (though I think its BGR, plus alpha). Other formats may have encyption and or compress and lots of other goodies.

Share this post


Link to post
Share on other sites
Ummm....what do you mean? RGB... red, green, blue. 0-255, one byte each. So you could make a file format with 3 bytes for each pixel. 4 if you want RGBA

Share this post


Link to post
Share on other sites
Thanks for the info. For a second there, I thought you had to combine the r, g, b into one strange value (I'm thinking of something else though).

Share this post


Link to post
Share on other sites
C++ (it may be microsoft only, not sure) has an RGB() and RGBA() macro that takes 4 values and "converts" them into a long. there are also similar functions that can pull out the specific values from a long.

this doesn't answer your main question, but is a useful way to store / read the values.

Share this post


Link to post
Share on other sites
That's a Microsoft macro, and expands roughly into:


#define RGB(r,g,b) (((b & 0xFF) << 16) & ((g & 0xFF) << 8) & (r & 0xFF))

Share this post


Link to post
Share on other sites
Yeah, you can just save the RGBA values directly to a file, probably with the width and height and format (RGB or RGBA, and color depth) as well. You might also want to preclude everything with a few "ID" bytes, so you can make sure you're loading a valid image. So your format might look like this:

ID String
width height
RGB or RGBA
color depth
pixel data

of course, this will almost certainly be in binary format, so it won't actually look like the above. But you get the idea.

Take a look at fstream in the stl.

Share this post


Link to post
Share on other sites
Just don't do it.

There are lots of existing image file formats already, and one of them is likely to suit your needs just fine.

For example, there's JPEG for photographic lossy compression; PNG for pixel art lossless compression (with transparency) or paletted images; TGA for lossless images typically without compression but with full alpha channel, or paletted images; and DDS which supports pretty much any kind of uncompressed encoding you can think of (although only the DXT series of compression formats). There's TIFF to support storing pretty much any kind of bitmap data. There's PSD for storing multi-layered, tile-accessed complex image documents.

The benefit of using an existing file format is that you can view them in the Windows Explorer window; you can open them in Photoshop and change them around and save them out again; and you can mail them to your friends (or receive them from your friends) without any compatibility worries.

What possible reason could you have to create your own image file format, instead of using an existing format? Perhaps if you described to us what specific features you need of the file format, we could suggest an existing, well-supported file format for you to use instead of re-inventing the wheel.

Share this post


Link to post
Share on other sites
Unless you're developing some wickedly brilliant compression scheme I would have to agree with the above posts, existing formats have most of the major bases covered. In the end you'll either have an index value pointing to a color table for each pixel, or you'll have so many bits dedicated to various color channels per pixel. Even with compression it will stil have to be converted to an array of color values at some point, so I would save my effort for more interesting problems.

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!