In re SwatchBooker palette parsing
Closed, ResolvedPublic

Description

As I told to Wolthera, I'd like to add support for SwatchBooker palettes.

Format highlights:

  • It is a ZIP file with extension .sbz and declared unofficial MIME type application/swatchbook
  • Contents:
    • swatchbook.xml is the palette itself
    • <file name>.jpg/png is the palette's thumbnail/icon
    • profiles/*.icc contains all profiles referred to by the palette
  • Metadata: format, type, description, license, rights, title.
  • SwatchBook.xml itself
    • separated into materials (colors) and book (those included in the palette)
    • materials is one or more colors, each one with metadata (id + title, possibly localized with xml:lang) and one or more definitions in a given colorspace

Questions and issues I've found:

  • KoColorSet should be refactored to read the file only once. Currently, it reads the whole contents into a QByteArray, which I cannot use with KoStore or KZip AFAIK.
    • I can use this opportunity to switch to KisMimeDatabase instead for detecting XML and ZIP.
  • How to deal with localized color names? Till KoColorSet supports i18n, which one to assign as name?
  • How to deal with multiple color definitions? The specs say

There can be several values definitions for each color. They'll be treated in order of appearance.

so I guess it should be set to the first one read (again, till KoColorSet supports multiple definitions and/or defines a colorspace priority).

  • How to see and edit metadata?

Details

Differential Revisions
Restricted Differential Revision
lsegovia created this task.Nov 1 2016, 2:11 PM

Checkout the rempt/T4121-improve-palette-format branch(that is, git checkout rempt/T4121-improve-palette-format, git pull). The loadKPL function should show you how to get data from a zip file.

If the spec says to load in sequence then load in sequence.

For localised names, the name would preferably the one without the lang xml. Otherwise the en localisation, otherwise load the first label you come across.

Don't worry about editing/seeing metadata. We'll deal with that when we're going to rewrite the palette docker proper. I'll be happy if Krita can spit out some meta-data in the meantime.

rempt added a comment.Nov 3 2016, 10:29 AM
KoColorSet should be refactored to read the file only once. Currently, it reads the whole contents into a QByteArray, which I cannot use with KoStore or KZip AFAIK.

Yes, that's possible. It's, in fact, how we currently load the new internal file format, which is also xml + stuff in a zipfile. Check the code in rempt/T4121-improve-palette-format. But basically, you open a QBuffer on the byte array, and then a KoStore on the buffer.

can use this opportunity to switch to KisMimeDatabase instead for detecting XML and ZIP.

I'm not sure what you want to do here -- I would initially just add ".sbz" to the list of extensions in KisMimeDatabase. Adding separate entries for all possible palette formats is another possibility, but the scribus .xml extension for their palette files is extremely unfortunate.

How to deal with localized color names? Till KoColorSet supports i18n, which one to assign as name?

If I look at the swatchbooker format, there is always an untranslated name:

<dc:title>Gray levels</dc:title>
<dc:title xml:lang="fr">Niveaux de gris</dc:title>

I'd use the title that isn't tagged with a language by default.

How to deal with multiple color definitions?

I'd be tempted to say, if there's lab, always use that, and otherwise the first one in the list.

How to see and edit metadata?

That will need much more work. You'll need to add fields to KoColorSet's internal datamodel to store the metadata, but editing it and showing it needs work on the palette widget itself. And that work needs to be preceded by design work.

woltherav added a comment.EditedNov 3 2016, 10:33 AM

Either way, do try to see if you can do your work in that branch. It'll be easier to diff that way :)

I'll try to merge impex into this branch so the code is up to date later today.

woltherav added a revision: Restricted Differential Revision.Nov 12 2016, 5:53 PM
woltherav moved this task from Backlog to Needs merge on the Krita: Next Features board.

This is currently in the Palette Branch.

rempt closed this task as Resolved.Mar 21 2017, 1:34 PM