Datatype Color Quantizing

miker1264 · 4338

miker1264

  • Legendary Member
  • *****
    • Posts: 1827
    • Karma: +84/-6
on: December 05, 2021, 05:49:32 PM
For the past few days I have been writing a small application called DT2GIF (Datatype to GIF).

As input it will accept any image file supported by picture datatypes and it will quantize and output an 8bit GIF.

For Color Quantizing (Color Reduction) it used the Neuquant Algorithm. The results using the algorithm are excellent.

There's an Amiga OS3 binary of PNGNQ that uses the same Neuquant Code to quantize 32bit RGBA to 8bit PNG. So I used it to convert the two 32bit icon images.

One the left of the screenshot is the original image and on the right of each is the 8bit quantized image with "_nq8.png" appended to the filename. How is the quality?

My DT2GIF uses the same Neuquant Code so I know the code works. But the difficulty is getting the NQ Colormap and Indexes into what our Datatypes can deal with.

This is the closest I've been to Real Color Quantizing in the last 6 months! I believe I will get it to work after several more long hours of experimenting with it.  ;)

« Last Edit: December 05, 2021, 08:27:29 PM by miker1264 »



miker1264

  • Legendary Member
  • *****
    • Posts: 1827
    • Karma: +84/-6
Reply #1 on: December 05, 2021, 06:30:38 PM
Wow! The Neuquant Algorithm is almost working.

As you can see in the top left corner the index values are correct. But the colormap is a little off.

After some more fine tuning it should work hopefully.  :D



miker1264

  • Legendary Member
  • *****
    • Posts: 1827
    • Karma: +84/-6
Reply #2 on: December 05, 2021, 07:29:42 PM
Yes. Neuquant Algorithm for Color Quantization is working! My Colormap values were reversed. So I swapped 'BGR' to 'RGB'

I converted it to 8bit PNG instead of 8bit GIF for comparison. But my resulting PNG file is missing a 'tRNS' chunk. Though our PNG Datatype doesn't read it correctly.

Now I will attempt to Quantize a 32bit image to 8bit...Yes. It's working! I quantized the 32bit Water_Tiger PNG into an 8bit PNG with Colormap and Indexes. Oh yeah!!

BTW That's MultiView 1.8.  8)
« Last Edit: December 05, 2021, 09:06:55 PM by miker1264 »



Samurai_Crow

  • Junior Member
  • **
    • Posts: 88
    • Karma: +32/-0
  • Hobby coder
Reply #3 on: December 05, 2021, 10:38:55 PM
Looks great!



OlafS3

  • Legendary Member
  • *****
    • Posts: 544
    • Karma: +50/-8
Reply #4 on: December 06, 2021, 01:59:15 AM
Wow! The Neuquant Algorithm is almost working.

As you can see in the top left corner the index values are correct. But the colormap is a little off.

After some more fine tuning it should work hopefully.  :D

Great  :D

that is something still needed



miker1264

  • Legendary Member
  • *****
    • Posts: 1827
    • Karma: +84/-6
Reply #5 on: December 06, 2021, 03:40:39 AM
Using Neuquant the output image quality is excellent.

Color Quantizing for AROS offers HUGE advantages!

I can thing of two instances to use Neuquant Algorithm.
First is ILBM2ICON. Second is Lunapaint.  :)
« Last Edit: December 06, 2021, 06:18:01 AM by miker1264 »



Amiwell

  • Legendary Member
  • *****
    • Posts: 2616
    • Karma: +35/-4
  • Peace
Reply #6 on: December 06, 2021, 05:15:54 AM
Great Miker :)



miker1264

  • Legendary Member
  • *****
    • Posts: 1827
    • Karma: +84/-6
Reply #7 on: December 06, 2021, 04:30:12 PM
This is the source code for DT2GIF including the Neuquant Algorithm for Color Quantizing.

You can compile it in IcarosDesktop at the commandline using GCC for x86. It's less than 1,000 lines of code.

You can convert 8bit, 24bit or 32bit to GIF. Syntax: dt2gif InputFile.bmp OutputFile.gif (dt2gif SRCE DEST).

I will post the 68k and x86_64 binaries later today. Have fun!  :P
« Last Edit: December 06, 2021, 04:37:44 PM by miker1264 »



AMIGASYSTEM

  • Global Moderator
  • Legendary Member
  • *****
    • Posts: 3740
    • Karma: +69/-2
  • AROS One
    • AROS One
Reply #8 on: December 06, 2021, 05:55:22 PM
I've compiled with GCC on AROS One x86 and I get an error, see screenshot


miker1264

  • Legendary Member
  • *****
    • Posts: 1827
    • Karma: +84/-6
Reply #9 on: December 06, 2021, 06:07:18 PM
I've compiled with GCC on AROS One x86 and I get an error, see screenshot

Sorry. Comment out with // or just delete:  include "debug.h".

You don't have that file. It was for debugging only.  :(

Also it's not "GifDatatype" but rather "Datatype2Gif".

This isn't the GIF Datatype but rather an app to convert to GIF.



AMIGASYSTEM

  • Global Moderator
  • Legendary Member
  • *****
    • Posts: 3740
    • Karma: +69/-2
  • AROS One
    • AROS One
Reply #10 on: December 06, 2021, 06:28:25 PM
With GCC still an error and does not compile the source, see screenshot

I tried with Murks, which instead compiled the source without the need to correct it, but when I run from shell it gives me a guru, see screenshot !


miker1264

  • Legendary Member
  • *****
    • Posts: 1827
    • Karma: +84/-6
Reply #11 on: December 06, 2021, 07:43:34 PM
Try this x86 binary. I included the source as well.

On the commandline: gcc dt2gif.c -o DT2GIF

It compiled on Icaros 2.2.8 with no errors.



miker1264

  • Legendary Member
  • *****
    • Posts: 1827
    • Karma: +84/-6
Reply #12 on: December 06, 2021, 07:45:05 PM
Here's the file.

The fact that it transforms 24bit and 32bit images to 8bit GIF is simply amazing. I've been trying to do this for six months now.
« Last Edit: December 06, 2021, 07:54:52 PM by miker1264 »



miker1264

  • Legendary Member
  • *****
    • Posts: 1827
    • Karma: +84/-6
Reply #13 on: December 07, 2021, 12:26:22 AM
This is the x86_64 64bit version of DT2GIF.

This commandline app converts picture files (8,24,32bit) to 8bit GIF files with Neuquant Algorithm.



AMIGASYSTEM

  • Global Moderator
  • Legendary Member
  • *****
    • Posts: 3740
    • Karma: +69/-2
  • AROS One
    • AROS One
Reply #14 on: December 07, 2021, 02:22:35 AM
Try this x86 binary. I included the source as well.

On the commandline: gcc dt2gif.c -o DT2GIF

It compiled on Icaros 2.2.8 with no errors.

Done some Tests with AROS One x86, even the version compiled with Murks works fine even from Dopus4, but if you try to run from DT2GIF a Shell "several times" and "without parameters" you get the error shown above, this also happens with icarOS and the Nightly Build of deadwood, see screenshot.