Own Image Format

Not really opengl specific but i think i am right here.

i want to develop my own texture/image format. i want to compress the image data. My data is stored as unsigned bytes ( in RGB). my first idea was to write a special char if the current pixel is the same as the previous. my second was to write only one single char if the color of the pixel is a full black or full white. What would you do? do you have any suggestions or experiences in this stuff?

thank you

Well that’s good for compressing your images, but since OpenGL has a strict set of formats, you ought to decompress your data and have it packed in one of those formats before uploading it to the GFX.

i know. my system would be:
write a tool which converts tga or other formats to my format, write the new image. (maybe more than one image -> animated textures)
in the opengl programm i will load my own format, decompress it and bind it in my texturearray

The big question is: why use your own format?
The dds format (DirectDrawSurface) is great, as it copes with mipmaps and cubemaps, and you can extend it yourself.
This would eliminate the need for an intermediate tool to convert from blah-to-blah, allowing you to use images saved directly out of photoshop or whatever, and would also mean you’d be adhering to…god forgive me for saying it…a standard.
The world doesn’t need another bloody image file format.

@knackerd: the world doesn’t need a new one. but the world will never have to use my format. i only want to use it in my application. the main idea is to store many textures in one file (animated textured) and i want to LEARN developing a own format or decompressing jpeg or such stuff.

You’ll need to learn about compression algorithms if you want to do good stuff. This is not an easy task. You’ll have to decide if your format will loose quality or not.

The ideas you stippled are a start for compressing data.
You can look for Huffman coding, or best LZ77.
Those last don’t loose data if I’m not wrong.

Hope that helps.

yes. thank you.

Originally posted by H.Stony:
@knackerd: the world doesn’t need a new one. but the world will never have to use my format. i only want to use it in my application. the main idea is to store many textures in one file (animated textured) and i want to LEARN developing a own format or decompressing jpeg or such stuff.
Oh, sorry, I naturally thought you were interested in the best way of storing and retrieving images in your opengl application, not that you just want to experiment with compression.
Well, this begs the next question: why are you asking this question in this forum?
If you need help using google, or don’t know how to find appropriate newsgroups, then maybe someone here has the time and energy to educate you. I haven’t.

@knackered: i asked this here to get some essential keywords like the useful one “huffman” because here are people with much experience. so what is your problem?
it doesn’t matter. i found the answer in jides post.

Huffman trees completely rule :smiley:

You can’t achieve high compression rate with only huffman encoding. If you want lossless image compression, the best algorithm you can find is JPEG-LS which use gradient predictor combined with huffman encoding or RLE encoding. If you want lossy image compression, you can see JPEG2000 which uses wavelet transform and arithmetic encoding. The JPEG use DCT and Huffman.
By the way, why do you want to create your own format. There are a lot of free SDKs of the formats listed above. Creating your own compressed image format is a big project.

By the way, these formats have high compression rate, but for graphics programming, I recommend you using S3TC compression for best loading time. You can compress it yourself or leave it to the OpenGL driver if you want. (GL_ARB_texture_compression/GL_EXT_texture_compression_s3tc)

Creating your own compressed format can be straightforward, it depends on your strategy.

I created an efficient one using band separation some reversible arithmetic manipulation with overflow/underflow and then a quick once through zlib. It was pretty darned good for minimal effort. However I only did this because of specific features I couldn’t find an image format out there that supported.

It can be fun and you’ll probably learn a bit, but once you’re done learning, unless you have a new & interesting capability then don’t inflict another format on the world. It will only obfuscate your project for others or worse, get into the wild.

I’d strongly suggest you just go with PNGs or some other existing format. People are asking you “why?” for a reason, listen to them.

thanks. experimenting with this things is interresting. but i after all the answers i will forget about it an use a existing file format