Page 1 of 2

Change Image Depth

Posted: Mon Dec 03, 2007 9:41 pm
by Thomas II
Hello,

I want to convert the depth of a image from 24bit to 8bit ...
Important!: It doesn't matter what colors that are (that needn't be the 256 standart colors); its only important that the image then only have 256 colors.

I tried to do it like this code:
http://www.purearea.net/pb/CodeArchiv/G ... Creator.pb
but the results wasn't good.

How converts Gimp the images?

Here's a Image ... on the left side you can see the main-image. In the middle there's the image, I have done with the above code. The right image I have done with Gimp.
Image

Posted: Tue Dec 04, 2007 4:01 am
by PurePWNRER
GIMP and many other programs create color-tables out of the original image, to later on suit the needs of the limited 8bit image.

For instance, you would go through all the pixels of the original image creating an array that contains the most used pixels in that image, so you can later on map your new 8bit data to those pixels.

So yes, you _should_ care about what colors it outputs.

Theres a lot of techniques regarding dithering, one you could begin with is Floyd Steinberg's.

If you don't care to collect the important data from the original image, then all you'll get is a lousy output.

Posted: Tue Dec 04, 2007 2:06 pm
by Thomas II
Does someone have a code example for me?
(Well, i don't really understand, how to do this ...) :cry:

Posted: Tue Dec 04, 2007 3:36 pm
by netmaestro
May I ask why you want to do this? Because if you're looking for a smaller filesize for the image, at 32*32 you're not gaining much by going to indexed colors. Maybe 20-25% at best if you want to keep much quality. It's at the larger image sizes you start to realize big filesize improvements.

Posted: Tue Dec 04, 2007 6:59 pm
by Thomas II
netmaestro wrote:May I ask why you want to do this? Because if you're looking for a smaller filesize for the image, at 32*32 you're not gaining much by going to indexed colors. Maybe 20-25% at best if you want to keep much quality. It's at the larger image sizes you start to realize big filesize improvements.
Well, I'm writing an Icon-Creator. This one should can create icons with different image depths.

Posted: Wed Dec 05, 2007 5:26 am
by PurePWNRER
You are writing an icon creator, yet; you don't understand how dithering works. May I ask why are you even writing this uber icon creator if you don't know what you're doing?.

Reading through color dithering WILL allow you to later on write dithering functions for your application, meaning; at the end if something goes wrong you'll know why, because you didn't copy&paste code from different places, put it together and claimed it your creation.

If you find it difficult to understand English papers regarding different types of dithering, I'm sure someone either translated or wrote them to your native language.

Just so you don't tag me as an asshole, heres a link to a CS project with source, in this project you'll find more than enough dithering implementations to work with: http://www.codeproject.com/KB/GDI-plus/ ... g_Lab.aspx

Programming is not about copy&pasting, it's about learning and creating. So I would also suggest that you read a paper on dithering, or at least fully read and understand what you are coding / porting. If you don't understand the code, don't bother to use it - that's my general rule and it works at the end (because if something goes wrong you'll know what to do in order to solve the problem).

You may agree or not it's just my point of view on the matter.
If you run into problems while porting the code, feel free to post your current code and someone will help you out.

Posted: Wed Dec 05, 2007 5:45 am
by Dare
PurePWNRER wrote:May I ask why are you even writing this uber icon creator if you don't know what you're doing?.
I would suggest that regardless of how much programming experience we have, every time we start something new we don't know what we are doing initially.

Following your logic, nobody writes anything at all? :)



BTW, have you seen netmaestro's nifty transpetris? The maestro says in his post that at the time of writing he didn't know what he was doing. It was a learning curve.

Pretty nifty Uber Tetris. Glad Nettie bothered.


PurePWNRER wrote:Just so you don't tag me as an asshole
It is tempting to so tag, but I bow to your request. :lol:

Posted: Wed Dec 05, 2007 11:54 am
by srod
I don't know what I'm doing at any time, but it doesn't stop me having a go! :wink:

Actually, I find rummaging through sparkie's refuse a good way of learning. He discards all kinds of useful code snippets. You have to wade through all the bat droppings first though!

Aye, a messy job!

Posted: Wed Dec 05, 2007 11:53 pm
by citystate
I love the smell of guano in the morning!
It smells like... Sparkie... :P

Posted: Thu Dec 06, 2007 11:01 am
by Fluid Byte
Are you saying Sparkie smells like shit? :shock:

Posted: Thu Dec 06, 2007 3:42 pm
by Thomas II
PurePWNRER wrote:Programming is not about copy&pasting, it's about learning and creating. So I would also suggest that you read a paper on dithering, or at least fully read and understand what you are coding / porting. If you don't understand the code, don't bother to use it - that's my general rule and it works at the end (because if something goes wrong you'll know what to do in order to solve the problem).
Do you want to say that I can't program, and only copy&paste?
My Icon-Creator is almost completed, it lacks only a bit of code to convert the image depth.
At the moment, I only have no idea how I can start progamming it ...

Posted: Thu Dec 06, 2007 5:20 pm
by Derek
What size of files of you thinking of converting. By size I mean dimensions not filesize. :wink:

What size from and to?

Posted: Thu Dec 06, 2007 6:14 pm
by Thomas II
Derek wrote:What size of files of you thinking of converting. By size I mean dimensions not filesize. :wink:

What size from and to?
Well, the biggest ones have 128x128 pixels.

Posted: Thu Dec 06, 2007 7:25 pm
by Derek
I'm guessing that is the size of the icon.

Are you trying to convert a photo for instance into an icon, so the file could be millions of pixels in size to start with?

Posted: Fri Dec 07, 2007 5:14 am
by Sparkie
Fluid Byte wrote:Are you saying Sparkie smells like shit?
I do have my moments...just ask my wife. ;)

@srod and citystate: Both of you had better be sleeping with one eye open......you never know when I'll be doing a flyby. :shock: :twisted: