Commit fc27cfc
authored
Merge pull request #371 from tannerhelland/neuquant
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.30 files changed
Lines changed: 1127 additions & 646 deletions
File tree
- App/PhotoDemon/Languages
- Master
- Classes
- Forms
- Modules
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
2703 | 2703 | | |
2704 | 2704 | | |
2705 | 2705 | | |
2706 | | - | |
| 2706 | + | |
2707 | 2707 | | |
2708 | 2708 | | |
2709 | 2709 | | |
| |||
6252 | 6252 | | |
6253 | 6253 | | |
6254 | 6254 | | |
| 6255 | + | |
| 6256 | + | |
| 6257 | + | |
| 6258 | + | |
| 6259 | + | |
| 6260 | + | |
| 6261 | + | |
| 6262 | + | |
| 6263 | + | |
| 6264 | + | |
| 6265 | + | |
| 6266 | + | |
| 6267 | + | |
| 6268 | + | |
| 6269 | + | |
| 6270 | + | |
| 6271 | + | |
6255 | 6272 | | |
6256 | 6273 | | |
6257 | 6274 | | |
| |||
6262 | 6279 | | |
6263 | 6280 | | |
6264 | 6281 | | |
6265 | | - | |
6266 | | - | |
6267 | | - | |
6268 | | - | |
6269 | | - | |
6270 | 6282 | | |
6271 | 6283 | | |
6272 | 6284 | | |
| |||
6277 | 6289 | | |
6278 | 6290 | | |
6279 | 6291 | | |
6280 | | - | |
| 6292 | + | |
6281 | 6293 | | |
6282 | 6294 | | |
6283 | 6295 | | |
| |||
8943 | 8955 | | |
8944 | 8956 | | |
8945 | 8957 | | |
8946 | | - | |
8947 | | - | |
8948 | | - | |
8949 | | - | |
8950 | | - | |
8951 | | - | |
8952 | | - | |
| 8958 | + | |
| 8959 | + | |
8953 | 8960 | | |
8954 | 8961 | | |
8955 | 8962 | | |
| |||
8982 | 8989 | | |
8983 | 8990 | | |
8984 | 8991 | | |
8985 | | - | |
| 8992 | + | |
8986 | 8993 | | |
8987 | 8994 | | |
8988 | 8995 | | |
| |||
13656 | 13663 | | |
13657 | 13664 | | |
13658 | 13665 | | |
13659 | | - | |
13660 | | - | |
13661 | | - | |
13662 | | - | |
13663 | | - | |
13664 | | - | |
13665 | | - | |
13666 | | - | |
13667 | | - | |
13668 | | - | |
13669 | | - | |
13670 | | - | |
13671 | 13666 | | |
13672 | 13667 | | |
13673 | | - | |
| 13668 | + | |
13674 | 13669 | | |
13675 | 13670 | | |
13676 | | - | |
13677 | | - | |
| 13671 | + | |
| 13672 | + | |
13678 | 13673 | | |
13679 | 13674 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
2702 | 2702 | | |
2703 | 2703 | | |
2704 | 2704 | | |
2705 | | - | |
| 2705 | + | |
2706 | 2706 | | |
2707 | 2707 | | |
2708 | 2708 | | |
| |||
6254 | 6254 | | |
6255 | 6255 | | |
6256 | 6256 | | |
| 6257 | + | |
| 6258 | + | |
| 6259 | + | |
| 6260 | + | |
| 6261 | + | |
| 6262 | + | |
| 6263 | + | |
| 6264 | + | |
| 6265 | + | |
| 6266 | + | |
| 6267 | + | |
| 6268 | + | |
| 6269 | + | |
| 6270 | + | |
| 6271 | + | |
| 6272 | + | |
| 6273 | + | |
6257 | 6274 | | |
6258 | 6275 | | |
6259 | 6276 | | |
| |||
6264 | 6281 | | |
6265 | 6282 | | |
6266 | 6283 | | |
6267 | | - | |
6268 | | - | |
6269 | | - | |
6270 | | - | |
6271 | | - | |
6272 | 6284 | | |
6273 | 6285 | | |
6274 | 6286 | | |
| |||
6279 | 6291 | | |
6280 | 6292 | | |
6281 | 6293 | | |
6282 | | - | |
| 6294 | + | |
6283 | 6295 | | |
6284 | 6296 | | |
6285 | 6297 | | |
| |||
8945 | 8957 | | |
8946 | 8958 | | |
8947 | 8959 | | |
8948 | | - | |
8949 | | - | |
8950 | | - | |
8951 | | - | |
8952 | | - | |
8953 | | - | |
8954 | | - | |
| 8960 | + | |
| 8961 | + | |
8955 | 8962 | | |
8956 | 8963 | | |
8957 | 8964 | | |
| |||
8984 | 8991 | | |
8985 | 8992 | | |
8986 | 8993 | | |
8987 | | - | |
| 8994 | + | |
8988 | 8995 | | |
8989 | 8996 | | |
8990 | 8997 | | |
| |||
13641 | 13648 | | |
13642 | 13649 | | |
13643 | 13650 | | |
13644 | | - | |
13645 | | - | |
13646 | | - | |
13647 | | - | |
13648 | | - | |
13649 | | - | |
13650 | | - | |
13651 | | - | |
13652 | | - | |
13653 | | - | |
13654 | | - | |
13655 | | - | |
13656 | 13651 | | |
13657 | 13652 | | |
13658 | | - | |
| 13653 | + | |
13659 | 13654 | | |
13660 | 13655 | | |
13661 | | - | |
13662 | | - | |
| 13656 | + | |
| 13657 | + | |
13663 | 13658 | | |
13664 | 13659 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
2705 | 2705 | | |
2706 | 2706 | | |
2707 | 2707 | | |
2708 | | - | |
| 2708 | + | |
2709 | 2709 | | |
2710 | 2710 | | |
2711 | 2711 | | |
| |||
6252 | 6252 | | |
6253 | 6253 | | |
6254 | 6254 | | |
| 6255 | + | |
| 6256 | + | |
| 6257 | + | |
| 6258 | + | |
| 6259 | + | |
| 6260 | + | |
| 6261 | + | |
| 6262 | + | |
| 6263 | + | |
| 6264 | + | |
| 6265 | + | |
| 6266 | + | |
| 6267 | + | |
| 6268 | + | |
| 6269 | + | |
| 6270 | + | |
| 6271 | + | |
6255 | 6272 | | |
6256 | 6273 | | |
6257 | 6274 | | |
| |||
6262 | 6279 | | |
6263 | 6280 | | |
6264 | 6281 | | |
6265 | | - | |
6266 | | - | |
6267 | | - | |
6268 | | - | |
6269 | | - | |
6270 | 6282 | | |
6271 | 6283 | | |
6272 | 6284 | | |
| |||
6277 | 6289 | | |
6278 | 6290 | | |
6279 | 6291 | | |
6280 | | - | |
| 6292 | + | |
6281 | 6293 | | |
6282 | 6294 | | |
6283 | 6295 | | |
| |||
8943 | 8955 | | |
8944 | 8956 | | |
8945 | 8957 | | |
8946 | | - | |
8947 | | - | |
8948 | | - | |
8949 | | - | |
8950 | | - | |
8951 | | - | |
8952 | | - | |
| 8958 | + | |
| 8959 | + | |
8953 | 8960 | | |
8954 | 8961 | | |
8955 | 8962 | | |
| |||
8982 | 8989 | | |
8983 | 8990 | | |
8984 | 8991 | | |
8985 | | - | |
| 8992 | + | |
8986 | 8993 | | |
8987 | 8994 | | |
8988 | 8995 | | |
| |||
13641 | 13648 | | |
13642 | 13649 | | |
13643 | 13650 | | |
13644 | | - | |
13645 | | - | |
13646 | | - | |
13647 | | - | |
13648 | | - | |
13649 | | - | |
13650 | | - | |
13651 | | - | |
13652 | | - | |
13653 | | - | |
13654 | | - | |
13655 | | - | |
13656 | 13651 | | |
13657 | 13652 | | |
13658 | | - | |
| 13653 | + | |
13659 | 13654 | | |
13660 | 13655 | | |
13661 | | - | |
13662 | | - | |
| 13656 | + | |
| 13657 | + | |
13663 | 13658 | | |
13664 | 13659 | | |
0 commit comments