惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
H
Help Net Security
腾讯CDC
宝玉的分享
宝玉的分享
H
Hackread – Cybersecurity News, Data Breaches, AI and More
L
LangChain Blog
爱范儿
爱范儿
T
The Blog of Author Tim Ferriss
J
Java Code Geeks
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
MyScale Blog
MyScale Blog
Engineering at Meta
Engineering at Meta
N
Netflix TechBlog - Medium
D
Docker
V
V2EX
Last Week in AI
Last Week in AI
G
Google Developers Blog
IT之家
IT之家
C
Check Point Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
人人都是产品经理
人人都是产品经理
博客园 - 叶小钗
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 聂微东

PBS activity

Make capypdf a submodule (7f9465b6) · Commits · Inkscape / inkscape · GitLab Draft: Make capypdf a submodule to enable it in the PPA (!7987) · Merge requests · Inkscape / inkscape · GitLab a7a272aeb209d29b500adb09d575af1d89645ffe to f9f9d913e36b14250122d9bc43911b5bb84e958c · PBS / Inkscape · GitLab Make capypdf a submodule (12ee5f11) · Commits · Inkscape / inkscape · GitLab Commits · launchpad-staging · Inkscape / inkscape · GitLab Commits · unmeson · PBS / Inkscape · GitLab Objects can't be moved using arrows keys (#6226) · Issues · Inkscape / inkscape · GitLab Down, left, right arrow keys don't work to move objects (#13628) · Issues · Inkscape / Inbox · GitLab Down, left, right arrow keys don't work to move objects (#13628) · Issues · Inkscape / Inbox · GitLab Draft: Expand tests for boolean operations on paths (!7980) · Merge requests · Inkscape / inkscape · GitLab 1.5-dev: cannot create/open documents after closing window on macOS (#5981) · Issues · Inkscape / inkscape · GitLab Use new Modifiers system for the arc tool (!7961) · Merge requests · Inkscape / inkscape · GitLab Remove dependency on deprecated appdirs module (!730) · Merge requests · Inkscape / extensions · GitLab Commits · appdirs · PBS / extensions · GitLab 1.5-dev: Unable to open the Extension Manager (#6202) · Issues · Inkscape / inkscape · GitLab PBS pushed to project branch capypdf-static at PBS / Inkscape PBS pushed to project branch capypdf-static at PBS / Inkscape Make internal capypdf static (!7947) · Merge requests · Inkscape / inkscape · GitLab Shape builder tool does not detect the interior region (#4477) · Issues · Inkscape / inkscape · GitLab Make (most) tests build and run on Windows (!7940) · Merge requests · Inkscape / inkscape · GitLab Generate AppImage with quick-sharun (a465f4ce) · Commits · PBS / Inkscape · GitLab Commits · sharun · PBS / Inkscape · GitLab 1.5-dev: Split mode state is incorrect in the menu when opening a new document (#6135) · Issues · Inkscape / inkscape · GitLab PBS deleted project branch deadlock-win at PBS / Inkscape 1.5-dev: (Windows) Deadlock on quit, process not exiting sometimes (#6003) · Issues · Inkscape / inkscape · GitLab Fix dark mode on gtk 4.20 (!7932) · Merge requests · Inkscape / inkscape · GitLab Fix some resizing issues on Windows by not setting GTK_CSD (!7931) · Merge requests · Inkscape / inkscape · GitLab Draft: Fix AppImage crashing during save on older distros (!7922) · Merge requests · Inkscape / inkscape · GitLab 19086deebf770c8932b403ee536c8f8562a376f9 to 55362ef7d4c363d9613d70ac7194de7e8e323a34 · PBS / Inkscape · GitLab c74f78ca23ff302b7b59175490b870f1a616b778 to 19086deebf770c8932b403ee536c8f8562a376f9 · PBS / Inkscape · GitLab
Add custom color palette support to bitmap tracing with n...
2026-04-14 · via PBS activity

Add custom color palette support to bitmap tracing with novel color quantization algorithm

  • Review changes

  • Download

NOTE: This PR has been co-authored by Claude.ai. I could not find the official policy of Inkscape regarding AI contributions. Please discard this PR if it contravenes Inkscape policies. The code has been checked and tested by myself (in addition to running ninja check).


Allow users to define their own color palette (or modify the auto-generated one) for multi-color tracing (Trace Bitmap > Multicolor > Colors), instead of relying solely on automatic octree color quantization.

This addresses a pain point when vectorizing a bitmap and getting a lot of similar colors, missing important hues present in the image.

When "Colors" mode is selected in the Multicolor tab, a palette editor replaces the scans slider. The palette is automatically populated by analyzing the selected image (sampling 10K pixels out of the image, so that it remains always reponsive). The optimal number of colors and their values are determined without user interaction.

Each color is shown as a row with:

  • A color swatch: hover to see the eyedropper icon, click to pick a color directly from the canvas (reuses the dropper tool's one-time pick mechanism, same as Fill & Stroke)
  • A hex label with disclosure arrow: click to expand an inline color picker with HSL/RGB sliders (reuses ColorPickerPanel, the same widget as Fill & Stroke)
  • A delete button to remove individual colors

The "+" button uses constrained k-means to find the best next color to add (the most distinctive color not yet covered by the palette). The refresh button re-extracts the optimal palette from the image.

The custom palette is then passed through to the tracing engine, which maps each pixel to the nearest palette color instead of running octree quantization. The rest of the tracing pipeline (per-color mask creation, potrace vectorization, stacking) works unchanged.

The attached SVG shows the old vs new color quantization algorithm on a range of different bitmap types: samples_tracing_autopalette.svg

Perceptual color quantization

The previous octree quantization operated in raw RGB space and allocated colors proportionally to pixel count: a large gray background would consume most of the palette while small vivid regions (e.g. colored flowers) were lost.

The new approach uses saliency-weighted k-means in Oklab perceptual color space:

  1. Oklab color space: Euclidean distance in Oklab closely matches perceived color difference, so the algorithm naturally preserves hue diversity rather than clustering around brightness variations.
  2. Local chroma saliency weighting: Before running k-means, each pixel is weighted by how much its chroma differs from its local neighborhood. Pixels at color boundaries and in small distinctive regions get ~20× more influence than uniform background pixels. This steers k-means toward visually important colors without sacrificing clustering quality.
  3. Automatic palette size: The elbow method on k-means inertia determines the optimal number of colors (2–10), biased slightly toward richer palettes.
  4. Pixel-to-palette assignment also uses Oklab distance, so each pixel maps to the color that looks closest, not just the geometrically nearest in RGB.

The old octree quantization is preserved for QUANT_MONO and BRIGHTNESS_MULTI modes where the output is converted to grayscale anyway.

Implementation notes

  • Oklab conversion is implemented directly in quantize.cpp rather than reusing ok_color::linear_srgb_to_oklab() from src/colors/spaces/ok-color.cpp, because those functions are internal to the color picker widget (not declared in the public header), use different types, and operate on linear sRGB without handling the transfer function. A self-contained implementation avoids coupling between unrelated subsystems.
  • Palette swatches use GtkSnapshot (snapshot_vfunc with gtk_snapshot_append_color) instead of Cairo, following the approach established in !7765 (merged).
  • The inline color picker uses a shared ColorPickerPanel instance (with PlateType::None) that is inserted below the active row and bound to its ColorSet, ensuring full UI consistency with Fill & Stroke.
Edited by Séverin Lemaignan