Change Image Depth

Just starting out? Need help? Post your questions and find answers here.
Thomas II
User
User
Posts: 17
Joined: Tue Oct 16, 2007 3:47 pm
Location: Germany
Contact:

Change Image Depth

Post 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
PurePWNRER
User
User
Posts: 45
Joined: Mon Mar 27, 2006 5:44 am

Post 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.
:/ My kingdom for a snippet!
I might bash, But I provide.
Thomas II
User
User
Posts: 17
Joined: Tue Oct 16, 2007 3:47 pm
Location: Germany
Contact:

Post by Thomas II »

Does someone have a code example for me?
(Well, i don't really understand, how to do this ...) :cry:
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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.
BERESHEIT
Thomas II
User
User
Posts: 17
Joined: Tue Oct 16, 2007 3:47 pm
Location: Germany
Contact:

Post 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.
PurePWNRER
User
User
Posts: 45
Joined: Mon Mar 27, 2006 5:44 am

Post 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.
:/ My kingdom for a snippet!
I might bash, But I provide.
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post 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:
Dare2 cut down to size
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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!
I may look like a mule, but I'm not a complete ass.
citystate
Enthusiast
Enthusiast
Posts: 638
Joined: Sun Feb 12, 2006 10:06 pm

Post by citystate »

I love the smell of guano in the morning!
It smells like... Sparkie... :P
there is no sig, only zuul (and the following disclaimer)

WARNING: may be talking out of his hat
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

Are you saying Sparkie smells like shit? :shock:
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Thomas II
User
User
Posts: 17
Joined: Tue Oct 16, 2007 3:47 pm
Location: Germany
Contact:

Post 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 ...
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

What size of files of you thinking of converting. By size I mean dimensions not filesize. :wink:

What size from and to?
Thomas II
User
User
Posts: 17
Joined: Tue Oct 16, 2007 3:47 pm
Location: Germany
Contact:

Post 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.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post 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?
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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:
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Post Reply