Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP -- add vips_palette #3122

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

WIP -- add vips_palette #3122

wants to merge 7 commits into from

Conversation

jcupitt
Copy link
Member

@jcupitt jcupitt commented Oct 28, 2022

See #3010 and #2841

So far this is just a simple wrapper around the quantiser.

$ vips palette
compute image palette
usage:
   palette in out [--option-name option-value ...]
where:
   in           - Input image, input VipsImage
   out          - Output image, output VipsImage
optional arguments:
   bitdepth     - Compute an N bit palette, input gint
			default: 8
			min: 0, max: 16
   effort       - Quantisation effort, input gint
			default: 7
			min: 1, max: 10
operation flags: sequential 
$ vips palette k2.jpg x.v
$ vipsheader x.v
x.v: 256x1 uchar, 4 bands, srgb

To do

  • expose the dither code as well
  • make pngload attach the load palette? tiff could too
  • deprecate gif-palette and get that to set plain palette as well
  • pngsave needs an option that means "reuse any attached palette rather than regenerating"

@jcupitt
Copy link
Member Author

jcupitt commented Oct 31, 2022

It looks like I've hit a blocker: putting a palette into VipsQuantiseResult using vips__quantise_image_quantize_fixed() seems to renumber the palette.

I think we need a supported way to set the palette that we want vips__quantise_write_remapped_image() to use.

@jcupitt
Copy link
Member Author

jcupitt commented Oct 31, 2022

To show the problem, try this:

  1. Generate the palette with vips palette astronauts.png palette.v
  2. Use the palette to create an index image with vips dither astronauts.png x.png palette.v
  3. Apply the palette to recover RGB with vips maplut x.png x.jpg palette.v

To make:

x

You can see the index has become scrambled. Index 0 of the palette is:

$ vips getpoint palette.v 0 0
0 91 146 255 

But that RGBA appears in the palette built by vips__quantise_image_quantize_fixed() as:

$ vips dither astronauts.png x.png palette.v | grep 91 | grep 146
53) r = 0, g = 91, b = 146, a = 255

Index 53.

@jcupitt jcupitt added snoozing Kept for reference, no action expected. blocked-upstream labels Nov 22, 2022
@jfcalvo
Copy link

jfcalvo commented Feb 6, 2023

@jcupitt is this totally discarded? This feature would be awesome to extract most used/dominant colors.

@jcupitt
Copy link
Member Author

jcupitt commented Feb 7, 2023

It's not discarded, just snoozing :) Maybe I'll find time to work on it again later this year. Or someone else could pick it up, of course.

@jfcalvo
Copy link

jfcalvo commented Feb 17, 2023

@jcupitt could it be possible to add a parameter to specify the number of colors for the palette?

@infacto
Copy link

infacto commented Jul 10, 2023

Just for my understanding... Can this handle automatic color indexing with external palette like the following?

input output compare
input output compare

Palette from another file (no color intern reduction):
palette
(Steps: 0, 51, 102, 153, 204, 255)

Source Input:
src-input

  • Would that work?
  • How is the color palette defined (file format)?
  • Optional with dithering (Floyd–Steinberg)?

@jcupitt
Copy link
Member Author

jcupitt commented Jul 10, 2023

@infacto yes, though it's blocked on the remapper not supporting a generated palette, unfortunately. This needs a small change to an upstream project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked-upstream snoozing Kept for reference, no action expected.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants