Datatype Color Quantizing

miker1264 · 1515

miker1264

  • Legendary Member
  • *****
    • Posts: 1224
    • Karma: +80/-2
on: December 06, 2021, 12:49:32 AM
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 06, 2021, 03:27:29 AM by miker1264 »



miker1264

  • Legendary Member
  • *****
    • Posts: 1224
    • Karma: +80/-2
Reply #1 on: December 06, 2021, 01:30:38 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



miker1264

  • Legendary Member
  • *****
    • Posts: 1224
    • Karma: +80/-2
Reply #2 on: December 06, 2021, 02:29:42 AM
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 06, 2021, 04:06:55 AM by miker1264 »



Samurai_Crow

  • Junior Member
  • **
    • Posts: 85
    • Karma: +30/-0
  • Hobby coder
Reply #3 on: December 06, 2021, 05:38:55 AM
Looks great!



OlafS3

  • Senior Member
  • ****
    • Posts: 317
    • Karma: +45/-0
Reply #4 on: December 06, 2021, 08: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: 1224
    • Karma: +80/-2
Reply #5 on: December 06, 2021, 10: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, 01:18:01 PM by miker1264 »



salvo

  • Legendary Member
  • *****
    • Posts: 1575
    • Karma: +20/-4
  • Peace an Love
    • TinyAros
Reply #6 on: December 06, 2021, 12:15:54 PM
Great Miker :)

TinyAros and shop  http://tinyaros.flazio.com
HP Z400 Workstation, Intel Xeon W3565 3.20 Ghz, 8 Gb Ram, SSD 120 Gb, HD 500 Gb, Quadro nvs 295 256 Mb Gallium Ready


miker1264

  • Legendary Member
  • *****
    • Posts: 1224
    • Karma: +80/-2
Reply #7 on: December 06, 2021, 11: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, 11:37:44 PM by miker1264 »



AMIGASYSTEM

  • Legendary Member
  • *****
    • Posts: 1504
    • Karma: +45/-1
  • AROS One
    • AROS One
Reply #8 on: December 07, 2021, 12:55:22 AM
I've compiled with GCC on AROS One x86 and I get an error, see screenshot


miker1264

  • Legendary Member
  • *****
    • Posts: 1224
    • Karma: +80/-2
Reply #9 on: December 07, 2021, 01:07:18 AM
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

  • Legendary Member
  • *****
    • Posts: 1504
    • Karma: +45/-1
  • AROS One
    • AROS One
Reply #10 on: December 07, 2021, 01:28:25 AM
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: 1224
    • Karma: +80/-2
Reply #11 on: December 07, 2021, 02:43:34 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.



miker1264

  • Legendary Member
  • *****
    • Posts: 1224
    • Karma: +80/-2
Reply #12 on: December 07, 2021, 02:45:05 AM
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 07, 2021, 02:54:52 AM by miker1264 »



miker1264

  • Legendary Member
  • *****
    • Posts: 1224
    • Karma: +80/-2
Reply #13 on: December 07, 2021, 07: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

  • Legendary Member
  • *****
    • Posts: 1504
    • Karma: +45/-1
  • AROS One
    • AROS One
Reply #14 on: December 07, 2021, 09: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.