Page 2 of 4

Re: Quantize 1.02 (True Color to 8 bit) - Windows

Posted: Mon Oct 26, 2009 11:29 pm
by luis
netmaestro wrote:I've plugged your NeuQuant.pb code into my 256Colors.dll for converting/saving images as .GIF and the results really are stunning.
If you just used the neuquant.pb please remember there is still the limitation about the image size you mentioned, it is fixed but only through the main include !

Have fun :)

Re: Quantize 1.02 (True Color to 8 bit) - Windows

Posted: Tue Oct 27, 2009 3:09 am
by netmaestro
I chose a different solution for the size. I was afraid of warping the colortable by introducing all those black border pixels, so I make a copy of the image, resize it raw to large enough while keeping the same aspect ratio, and feed that to the NeuQuant procedure. That way, the same colors in the same proportions are being analyzed by NeuQuant. Pixels from the original input image are used for the set-and-dither.

Re: Quantize 1.02 (True Color to 8 bit) - Windows

Posted: Tue Oct 27, 2009 11:09 am
by luis
Yes, it's a better (probably) solution.

I initially thought to use for the border the most used color inside the original image, but then I saw it was really immaterial so I simply went for the black (edit: I should have used rgb(128,128,128) on a second thought because it's in the middle of the 3d color cube).

But your idea is very good.

Re: Quantize 1.02 (True Color to 8 bit) - Windows

Posted: Wed Oct 28, 2009 1:07 am
by luis
1.03 for download if someone interested.

Just to have peace of mind :o I modified the border-thing.

Now the pixels-buffer's color around the image is the most used color in the source image.

I added this proc

Code: Select all

; Find the n most used colors in the passed image
; The desired n number of colors is specified through the sizing of array iaMostused()
; The returned value is the number of colors copied in the array
; If the returned value is less than n, than the number of colors of the image was less than n
; and the remaining items of the array are filled with zeros
; The colors are sorted in descending order, from the most used (first item) to the less used (last item)
Declare.i	Find32BitImageMostUsedColors (hImage, Array iaMostUsed(1))
I use it to find the most (one, single) used color but can be useful to find the n most used too.

Ah, fixed a couple of "256" that should have been "255". Mixing Dims and actual sizes is always a pain in the... back.

See first post for dl.

Bye!

Re: Quantize 1.03 (True Color to 8 bit) - Windows

Posted: Wed Oct 28, 2009 9:09 am
by THCM
Great Work Luis!

Is it possible to reduce a true color image to less than 256 different colors (16, 32 etc.)? Also a nice function for game developers would be, if your converter would support loadable user defined color tables. For example colors 0-15 will be predefined by the user and colors 16-255 can be freely chosen by your quantizer and of course all 256 colors should then be used for the conversion. It would be useful to mix for example a gui and changing background pictures etc..

Re: Quantize 1.03 (True Color to 8 bit) - Windows

Posted: Wed Oct 28, 2009 11:23 am
by luis
The original algorithm was specifically thought to reduce 24 bit images (or 15-16 bit too for that matter) to 256 colors. The target was 256 colors. It will not work well, even if modified, for less than 256 colors. It's possible force it but it's not the right algorithm for that.

So the short answer is no! To quantize for less than 256 color is better to use something different.

About the reserved, loadable palette, etc. I see what you mean but it's all beyond the purpose of this code and I believe it would be better to write something quite different for youR needs. Some code in here can be certainly useful for write that, but that's all.

Re: Quantize 1.03 (True Color to 8 bit) - Windows

Posted: Wed Oct 28, 2009 1:24 pm
by Dreamland Fantasy
@THCM

I have some code that remaps an image to an 8 colour pre-defined palette. It shouldn't be too hard to adapt that to other quantities of colours.

If you are interested then I will dig it out.

Kind regards,

Francis

Re: Quantize 1.03 (True Color to 8 bit) - Windows

Posted: Tue Mar 23, 2010 5:23 pm
by c4s
I realized I didn't thank you although I really like your code - it's fantastic and works very well!

So thank you. :wink:

Re: Quantize 1.03 (True Color to 8 bit) - Windows

Posted: Tue Mar 23, 2010 5:32 pm
by luis
c4s wrote:I realized I didn't thank you although I really like your code - it's fantastic and works very well!
Well, thank you so much for letting me know !
It's always nice to hear something is appreciated and maybe useful.

Hey, now this PB port is officialy linked from the original author of the algorithm !

See "Are people using NeuQuant?"
http://members.ozemail.com.au/~dekker/NEUQUANT.HTML

So my thanks to Mr. Dekker !

(it's another way to make people know about the great PB :wink: )

Re: Quantize 1.03 (True Color to 8 bit) - Windows

Posted: Sun Aug 01, 2010 4:38 pm
by Mistrel
Does not work on Windows XP 64-bit.

I tried both this and netmaestro's method in PureBasic 4.31 and 4.40.

For your code the output is a black bitmap with a small white square towards the bottom right.

Re: Quantize 1.03 (True Color to 8 bit) - Windows

Posted: Sun Aug 01, 2010 5:13 pm
by luis
It works under 64 bit (I mean compiled as 64 bit code) so the the problem is probably due to some quirk of XP64.

Maybe an API not supported by that OS or working differently ?

Sorry but I never had a 64 bit version of XP so I don't know how to check, you are probably in a better position to see where it fails :-)

If you can point me in the right direction I will be happy to update the code to make it work there also.

Re: Quantize 1.03 (True Color to 8 bit) - Windows

Posted: Mon Aug 02, 2010 7:22 am
by Mistrel
I tested it with the 4.40 x64 compiler and it works fine. It just doesn't work compiled with the x86 compiler on Windows XP 64-bit. I'm guessing that this might be the case on any x64 platform (Vista/Win7).

Re: Quantize 1.03 (True Color to 8 bit) - Windows

Posted: Mon Aug 02, 2010 12:57 pm
by luis
Ah! So you previously tried the 32 bit executable under xp64 ?

AFAIK xp64 didn't have the same level of support for 32 bit programs as vista or windows 7, so a compatibility problem is possible. Good to know it works as expected with the 64 bit executable.

FYI the 32 bit executable compiled under win7/32 works fine under win7/64 bits too.

Re: Quantize 1.03 (True Color to 8 bit) - Windows

Posted: Mon Aug 02, 2010 1:38 pm
by Dreamland Fantasy
The 32 bit executable also worked fine under Vista 64 bits.

Kind regards,

Francis

Re: Quantize 1.03 (True Color to 8 bit) - Windows

Posted: Mon Aug 02, 2010 3:09 pm
by Fred
PureBasic v4.50+ uses the very same algo to dither the pictures when using saveimage() with 8 bit paramter.