Skip to content

Commit

Permalink
Merge pull request #371 from tannerhelland/neuquant
Browse files Browse the repository at this point in the history
This merge adds a new neural-network color quantizer to PhotoDemon.  (A color quantizer builds a palette of [n] colors from an existing image.)  I started with [Neuquant](https://en.wikipedia.org/wiki/Color_quantization#Algorithms), a well-known color quantizer, and reworked the algorithm extensively to better fit PD's unique use-cases and performance requirements.  This included overhauling the algorithm to also work with alpha channels.

The end result is a fast, powerful quantizer than can produce remarkably high-quality 8-bit (<=256 color) images, which is particularly relevant for things like exporting animated GIFs.  I'm currently investigating adding animated WebP support to the project, which is part of what prompted this work on a new, better quantizer.  

One of the unique strengths of Neuquant is how well it can produce palettes for images with subtle gradients, like logos, charts, or 3D-rendered objects/scenes.  This makes it especially useful for optimizing images for the web, because Neuquant can produce 8-bit versions of images that look very close to their 32-bit counterparts, but unlike other mechanisms that rely on dithering to "artificially" make color density look richer, Neuquant simply generates a much better palette.  This lets you get away with undithered 8-bit reduction for most images, which greatly improves compressibility of the final image (compared to the "noise" dithering naturally introduces).

Anyway, the main use-cases of this new feature are hidden, with PD silently leaning on the new color quantizer when relevant (like saving to 8-bit formats a la GIF).  To play with the quantizer as a standalone feature, you can use the Effects > Stylize > Palettize tool, which directly exposes the quantizer for experimentation.
  • Loading branch information
tannerhelland committed Sep 22, 2021
2 parents 4e015a6 + 1512bb5 commit fc27cfc
Show file tree
Hide file tree
Showing 30 changed files with 1,127 additions and 646 deletions.
57 changes: 26 additions & 31 deletions App/PhotoDemon/Languages/French.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<langid>fr-FR</langid>
<langname>Français</langname>
<langversion>6.7.544</langversion>
<langversion>6.7.545</langversion>
<langstatus>Complete</langstatus>

<author>Jean Jacques Piedfort (orig. Frank Donckers)</author>
Expand Down Expand Up @@ -2703,7 +2703,7 @@ Pour activer le support du scanner, veuillez copiez le fichier EZTW32.dll (dispo
<translation>license zLib</translation>
</phrase>

<!-- Plugin_Management.bas contains 22 phrases. 16 were duplicates of existing phrases, so only 6 new phrases were written to file. -->
<!-- Plugin_Management.bas contains 24 phrases. 18 were duplicates of existing phrases, so only 6 new phrases were written to file. -->

<phrase>
<original>Preparing image for printing</original>
Expand Down Expand Up @@ -6252,6 +6252,23 @@ La mise à jour est traitée automatiquement en arrière-plan. Vous recevrez une

<!-- Adjustments_Levels.frm contains 13 phrases. 7 were duplicates of existing phrases, so only 6 new phrases were written to file. -->

<phrase>
<original>foreground</original>
<translation></translation>
</phrase>

<phrase>
<original>gamma</original>
<translation>gamma</translation>
</phrase>

<phrase>
<original>Removing haze from image</original>
<translation></translation>
</phrase>

<!-- Adjustments_Lighting_Dehaze.frm contains 7 phrases. 4 were duplicates of existing phrases, so only 3 new phrases were written to file. -->

<phrase>
<original>exposure compensation (stops)</original>
<translation>compensation d'exposition (arrêts)</translation>
Expand All @@ -6262,11 +6279,6 @@ La mise à jour est traitée automatiquement en arrière-plan. Vous recevrez une
<translation>décalage</translation>
</phrase>

<phrase>
<original>gamma</original>
<translation>gamma</translation>
</phrase>

<phrase>
<original>new exposure curve</original>
<translation>nouvelle courbe d'exposition</translation>
Expand All @@ -6277,7 +6289,7 @@ La mise à jour est traitée automatiquement en arrière-plan. Vous recevrez une
<translation>Réglage de l'exposition de l'image</translation>
</phrase>

<!-- Adjustments_Lighting_Exposure.frm contains 7 phrases. 2 were duplicates of existing phrases, so only 5 new phrases were written to file. -->
<!-- Adjustments_Lighting_Exposure.frm contains 7 phrases. 3 were duplicates of existing phrases, so only 4 new phrases were written to file. -->

<phrase>
<original>keep all colors in sync</original>
Expand Down Expand Up @@ -8943,13 +8955,8 @@ If you want to save it with a different file name, please select 'Cancel', then
</phrase>

<phrase>
<original>Xiaolin Wu</original>
<translation>Xiaolin Wu</translation>
</phrase>

<phrase>
<original>NeuQuant</original>
<translation>NeuQuant</translation>
<original>neural network</original>
<translation></translation>
</phrase>

<phrase>
Expand Down Expand Up @@ -8982,7 +8989,7 @@ If you want to save it with a different file name, please select 'Cancel', then
<translation>ATTENTION ! Fichier de palette invalide.</translation>
</phrase>

<!-- Effects_Stylize_Palettize.frm contains 33 phrases. 15 were duplicates of existing phrases, so only 18 new phrases were written to file. -->
<!-- Effects_Stylize_Palettize.frm contains 31 phrases. 14 were duplicates of existing phrases, so only 17 new phrases were written to file. -->

<phrase>
<original>glow radius</original>
Expand Down Expand Up @@ -13656,24 +13663,12 @@ Si vous choisissez de désactiver les mises à jour, n'oubliez pas de visiter ph

<!-- Tools_ScreenVideoPrefs.frm contains 17 phrases. 7 were duplicates of existing phrases, so only 10 new phrases were written to file. -->

<phrase>
<original>foreground</original>
<translation></translation>
</phrase>

<phrase>
<original>Removing haze from image</original>
<translation></translation>
</phrase>

<!-- Adjustments_Lighting_Dehaze.frm contains 7 phrases. 5 were duplicates of existing phrases, so only 2 new phrases were written to file. -->

<!-- Automatic text extraction complete. -->

<phrasecount>2584</phrasecount>
<phrasecount>2583</phrasecount>

<!-- As of this build, PhotoDemon contains 5324 phrases. -->
<!-- 2740 are duplicates, so only 2584 unique phrases have been written to file. -->
<!-- These 2584 phrases contain approximately 11871 total words. -->
<!-- 2741 are duplicates, so only 2583 unique phrases have been written to file. -->
<!-- These 2583 phrases contain approximately 11870 total words. -->

</pdData>
57 changes: 26 additions & 31 deletions App/PhotoDemon/Languages/German.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<langid>de-DE</langid>
<langname>Deutsch (DE)</langname>
<langversion>9.0.724</langversion>
<langversion>9.0.725</langversion>
<langstatus>Up-to-date</langstatus>

<author>rk (ehem. Frank Donckers, Helmut Kuerbiss)</author>
Expand Down Expand Up @@ -2702,7 +2702,7 @@ Um die Scanner-Unterstützung zu aktivieren, kopieren Sie bitte die Datei EZTW32
<translation>zLib-License</translation>
</phrase>

<!-- Plugin_Management.bas contains 22 phrases. 16 were duplicates of existing phrases, so only 6 new phrases were written to file. -->
<!-- Plugin_Management.bas contains 24 phrases. 18 were duplicates of existing phrases, so only 6 new phrases were written to file. -->

<phrase>
<original>Preparing image for printing</original>
Expand Down Expand Up @@ -6254,6 +6254,23 @@ Das Update wird automatisch im Hintergrund verarbeitet. Sie werden ein neue Bena

<!-- Adjustments_Levels.frm contains 13 phrases. 7 were duplicates of existing phrases, so only 6 new phrases were written to file. -->

<phrase>
<original>foreground</original>
<translation>Vordergrund</translation>
</phrase>

<phrase>
<original>gamma</original>
<translation>Gamma</translation>
</phrase>

<phrase>
<original>Removing haze from image</original>
<translation>Entfernung des Dunstes aus Bild</translation>
</phrase>

<!-- Adjustments_Lighting_Dehaze.frm contains 7 phrases. 4 were duplicates of existing phrases, so only 3 new phrases were written to file. -->

<phrase>
<original>exposure compensation (stops)</original>
<translation>Belichtungskompensation (Stopps)</translation>
Expand All @@ -6264,11 +6281,6 @@ Das Update wird automatisch im Hintergrund verarbeitet. Sie werden ein neue Bena
<translation>Offset</translation>
</phrase>

<phrase>
<original>gamma</original>
<translation>Gamma</translation>
</phrase>

<phrase>
<original>new exposure curve</original>
<translation>Neue Belichtungskurve</translation>
Expand All @@ -6279,7 +6291,7 @@ Das Update wird automatisch im Hintergrund verarbeitet. Sie werden ein neue Bena
<translation>Bildbelichtung wird angepasst</translation>
</phrase>

<!-- Adjustments_Lighting_Exposure.frm contains 7 phrases. 2 were duplicates of existing phrases, so only 5 new phrases were written to file. -->
<!-- Adjustments_Lighting_Exposure.frm contains 7 phrases. 3 were duplicates of existing phrases, so only 4 new phrases were written to file. -->

<phrase>
<original>keep all colors in sync</original>
Expand Down Expand Up @@ -8945,13 +8957,8 @@ If you want to save it with a different file name, please select 'Cancel', then
</phrase>

<phrase>
<original>Xiaolin Wu</original>
<translation>Xiaolin Wu</translation>
</phrase>

<phrase>
<original>NeuQuant</original>
<translation>NeuQuant</translation>
<original>neural network</original>
<translation></translation>
</phrase>

<phrase>
Expand Down Expand Up @@ -8984,7 +8991,7 @@ If you want to save it with a different file name, please select 'Cancel', then
<translation>WARNUNG! Palettendatei ungültig.</translation>
</phrase>

<!-- Effects_Stylize_Palettize.frm contains 33 phrases. 15 were duplicates of existing phrases, so only 18 new phrases were written to file. -->
<!-- Effects_Stylize_Palettize.frm contains 31 phrases. 14 were duplicates of existing phrases, so only 17 new phrases were written to file. -->

<phrase>
<original>glow radius</original>
Expand Down Expand Up @@ -13641,24 +13648,12 @@ Wenn Sie sich dennoch dafür entscheiden, Updates zu deaktivieren, vergessen Sie

<!-- Tools_ScreenVideoPrefs.frm contains 17 phrases. 7 were duplicates of existing phrases, so only 10 new phrases were written to file. -->

<phrase>
<original>foreground</original>
<translation>Vordergrund</translation>
</phrase>

<phrase>
<original>Removing haze from image</original>
<translation>Entfernung des Dunstes aus Bild</translation>
</phrase>

<!-- Adjustments_Lighting_Dehaze.frm contains 7 phrases. 5 were duplicates of existing phrases, so only 2 new phrases were written to file. -->

<!-- Automatic text extraction complete. -->

<phrasecount>2584</phrasecount>
<phrasecount>2583</phrasecount>

<!-- As of this build, PhotoDemon contains 5324 phrases. -->
<!-- 2740 are duplicates, so only 2584 unique phrases have been written to file. -->
<!-- These 2584 phrases contain approximately 11871 total words. -->
<!-- 2741 are duplicates, so only 2583 unique phrases have been written to file. -->
<!-- These 2583 phrases contain approximately 11870 total words. -->

</pdData>
57 changes: 26 additions & 31 deletions App/PhotoDemon/Languages/Indonesian.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<langid>id-ID</langid>
<langname>Indonesian</langname>
<langversion>6.6.502</langversion>
<langversion>6.6.503</langversion>
<langstatus>Complete</langstatus>

<author>Ari Sohandri Putra (7.0 updates by Google Translate)</author>
Expand Down Expand Up @@ -2705,7 +2705,7 @@ Untuk mengaktifkan dukungan scanner, silahkan salin file EZTW32.dll (tersedia un
<translation>lesen zlib</translation>
</phrase>

<!-- Plugin_Management.bas contains 22 phrases. 16 were duplicates of existing phrases, so only 6 new phrases were written to file. -->
<!-- Plugin_Management.bas contains 24 phrases. 18 were duplicates of existing phrases, so only 6 new phrases were written to file. -->

<phrase>
<original>Preparing image for printing</original>
Expand Down Expand Up @@ -6252,6 +6252,23 @@ Pembaruan otomatis pengolahan di latar belakang. Anda akan menerima pemberitahua

<!-- Adjustments_Levels.frm contains 13 phrases. 7 were duplicates of existing phrases, so only 6 new phrases were written to file. -->

<phrase>
<original>foreground</original>
<translation></translation>
</phrase>

<phrase>
<original>gamma</original>
<translation>gamma</translation>
</phrase>

<phrase>
<original>Removing haze from image</original>
<translation></translation>
</phrase>

<!-- Adjustments_Lighting_Dehaze.frm contains 7 phrases. 4 were duplicates of existing phrases, so only 3 new phrases were written to file. -->

<phrase>
<original>exposure compensation (stops)</original>
<translation>pampasan pendedahan (berhenti)</translation>
Expand All @@ -6262,11 +6279,6 @@ Pembaruan otomatis pengolahan di latar belakang. Anda akan menerima pemberitahua
<translation>mengimbangi</translation>
</phrase>

<phrase>
<original>gamma</original>
<translation>gamma</translation>
</phrase>

<phrase>
<original>new exposure curve</original>
<translation>keluk pendedahan baru</translation>
Expand All @@ -6277,7 +6289,7 @@ Pembaruan otomatis pengolahan di latar belakang. Anda akan menerima pemberitahua
<translation>Melaraskan pendedahan imej</translation>
</phrase>

<!-- Adjustments_Lighting_Exposure.frm contains 7 phrases. 2 were duplicates of existing phrases, so only 5 new phrases were written to file. -->
<!-- Adjustments_Lighting_Exposure.frm contains 7 phrases. 3 were duplicates of existing phrases, so only 4 new phrases were written to file. -->

<phrase>
<original>keep all colors in sync</original>
Expand Down Expand Up @@ -8943,13 +8955,8 @@ If anda mahu menyimpannya dengan nama fail yang berbeza, sila pilih 'Batal', kem
</phrase>

<phrase>
<original>Xiaolin Wu</original>
<translation>Xiaolin Wu</translation>
</phrase>

<phrase>
<original>NeuQuant</original>
<translation>NeuQuant</translation>
<original>neural network</original>
<translation></translation>
</phrase>

<phrase>
Expand Down Expand Up @@ -8982,7 +8989,7 @@ If anda mahu menyimpannya dengan nama fail yang berbeza, sila pilih 'Batal', kem
<translation></translation>
</phrase>

<!-- Effects_Stylize_Palettize.frm contains 33 phrases. 15 were duplicates of existing phrases, so only 18 new phrases were written to file. -->
<!-- Effects_Stylize_Palettize.frm contains 31 phrases. 14 were duplicates of existing phrases, so only 17 new phrases were written to file. -->

<phrase>
<original>glow radius</original>
Expand Down Expand Up @@ -13641,24 +13648,12 @@ Jika anda masih memilih untuk melumpuhkan Perbarui, jangan lupa untuk mengunjung

<!-- Tools_ScreenVideoPrefs.frm contains 17 phrases. 7 were duplicates of existing phrases, so only 10 new phrases were written to file. -->

<phrase>
<original>foreground</original>
<translation></translation>
</phrase>

<phrase>
<original>Removing haze from image</original>
<translation></translation>
</phrase>

<!-- Adjustments_Lighting_Dehaze.frm contains 7 phrases. 5 were duplicates of existing phrases, so only 2 new phrases were written to file. -->

<!-- Automatic text extraction complete. -->

<phrasecount>2584</phrasecount>
<phrasecount>2583</phrasecount>

<!-- As of this build, PhotoDemon contains 5324 phrases. -->
<!-- 2740 are duplicates, so only 2584 unique phrases have been written to file. -->
<!-- These 2584 phrases contain approximately 11871 total words. -->
<!-- 2741 are duplicates, so only 2583 unique phrases have been written to file. -->
<!-- These 2583 phrases contain approximately 11870 total words. -->

</pdData>
Loading

0 comments on commit fc27cfc

Please sign in to comment.