Re: [Mypaint-discuss] RFC: JSON format for MyPaint brushes, handling load/save in libmypaint

2012-06-04 Thread Jon Nordby
On 2 June 2012 17:21, Martin Renold martin...@gmx.ch wrote:
 hi Jon

 Nice progress with brushlib!
 No objection to convert MyPaint's .myb to json as planned.

Thanks!
I have pushed a branch json to the mainline repository now. This has
the code for supporting the new format in MyPaint, migrates the stock
brushes to this format and implements loading in libmypaint.

 About dict vs list: IMO if we have a high-level structure like json, only a
 dict makes sense.  The index is only required internally, for fast C array
 access.

I agree. I will make this change in above mentioned branch shortly.

 About base64-encoded PNGs: I think the current two-files approach works very
 well: power-users immediately know how to edit the preview in an external
 application, the textual .myb files are easy to handle.  Brushes are never
 shared individually anyway, but only as a whole collection (ZIP).

Yes, the current approach works OK I think. I don't really propose we
change that now. Though we should document it so that other
applications will work the same way.

 Collected notes about extensible settings:

 There are some settings ('restore_color' and 'lock_alpha') that are not
 handled by brushlib at all.  How will the application access them?

By reading/setting the attributes on the JSON strings passed to/from
the brush, or by using the mypaint_brush_{get,set}_base_value and
similar.

But if the brushlib does not use these, perhaps we should move them
out of the settings key and into the toplevel?

 The experimental blend_modes4-style brush modes also requires a brush
 setting with higher-level application support: it needs the ability to fetch
 the composited image, not just the current layer.  This is something that
 most applications probably don't want to implement.
This could be added to the vfuncs of MyPaintTiledSurface. So that
similar to get_tile/update_tile (which operates only on the layer)
there is a get_image_tile/update_image tile.

Usage of blender will
 probably require additional blender-specific settings, too.  (#mypaint Jun
 22 21:52:52 LetterRip so we would need to have additional fields that
 mypaint and other brushlib users wouldn't recognize).

 So in the long-term, I think what would be required is the ability to add
 opaque brush settings at run-time.  Those could depend on all the inputs.
 Brushlib would calculate the mapping and just pass the resulting value(s) on
 to the dabbing code.

You mean similar to the current custom brush setting? That one would
be able to add such settings at runtime?
That should not be a problem.

 As you know, MyPaint keeps an observable brush settings object around, which
 acts as a master, and the brushlib brush acts as a slave storage of the
 currently active brush settings.  With the proposed change, either MyPaint
 will have to fetch the loaded brush settings back from brushlib, or it will
 have to parse the json itself and use the current API to update the slave.
 (The current API or something very similar is still required to exist
 anyway, since you hardly want to generate and parse a whole json for every
 motion event, when a slider or curve point is dragged with live preview.)

The current API is still there, and I don't plan to make any changes there.
Interactive applications will likely wrap the MyPaintBrush interface
in something that allows them to track changes in the different
settings. I don't see that as a big problem since the API is so small.
And I don't see a convenient way to implement such functionality in
libmypaint (at least not without using glib/gobject).

 I would also suggest that we stop saving settings that are at their default.
 I have introduced the code to save everything at some point because I wanted
 to change the default of one setting and was annoyed that it changed all the
 old brushes - but I think it was a bad idea and really just clutters the
 .myb files and makes them harder to edit/grep by hand.

I think we should continuing to store them, as I don't think it is
acceptable to change the brushes the user has already created by
changing the defaults in the library/application.
And being able to change the default in the lib/app can be handy.

 About saving: I think applications that allow to save .myb files will have a
 similar observer model like MyPaint.  I'm still not a big fan of parsing
 brushsettings in C (but I have no strong objection, neither), so I wonder if
 it really makes brushlib users happy to use the brushlib API when dealing
 with json files.  Could you store a json list via the brushlib API, for
 example?

There is no generic JSON functionality exposed by the brushlib API. If
the application wishes to add additional attributes, that should be
done using whatever library the application prefers for manipulating
JSON documents.

The reponsibility of the brushlib is just to correctly
serialize/deserialize its own settings. And to not meddle with the
applications settings.

 About saving unknown 

[Mypaint-discuss] RFC: JSON format for MyPaint brushes, handling load/save in libmypaint

2012-06-01 Thread Jon Nordby
Hi all,

as has been discussed on and off a bit, it would be nice to move to
JSON for storing the MyPaint brushes. This should make easier for
alternative brush engine implementations (like the Javascript + HTML5
one) to reuse the brushes.

In addition I propose to move load/save into libmypaint (currently
called brushlib). This is so that anyone using libmypaint are
guaranteed to be able to correctly load and save MyPaint brushes
correctly.

== Data format ==
The data format is based on JSON, as defined in RFC4627
(http://tools.ietf.org/html/rfc4627).
Files saved to disk shall have the extension .myb, like before. The
file contents shall be stored UTF-8 encoded.

See the attached example for exact format (pretty printed).

An open question is whether to change the individual setting format to
be a dict with base_value and inputs instead of the current list.
That would be a bit more explicit/readable?

== Extensibility ==
New top-level key, value pairs may be added by applications.
Application specific attributes must have the prefix x_$appname_.
Standardized attributes, as defined by libmypaint/MyPaint must not use
an x_ prefix.

The currently standardized attributes are version, comment,
settings and parent_brush_name.
An open question is whether parent_brush_name is considered MyPaint specific?

Metadata that may be interesting to add in the future includes:
- Brush preview/icon (as base64 encoded PNG for instance)
- Name/email of creator
- Description
- Creation and modification date

== Compatibility ==
- Brushes with old format will work in MyPaint, and be automatically
migrated (backwards compatible)
- Older MyPaint versions will not be able to open this new format (not
forward compatible)
- libmypaint will only be able to open this new format, not older.

== libmypaint API ==

The proposed API for libmypaint is:

void mypaint_brush_from_string(const char *);
const char * mypaint_brush_to_string();

A roundtrip between these is guaranteed to preserve any non-recognized
top-level attributes (application defined). This allows applications
making use of libmypaint that wish to add or modify the additional
metadata to do this by interpreting the JSON string before passing it
on.
Storing the brushes to disk is the responsibility of the application
using libmypaint.

== Implementation plan ==
1. Add code to migrate to new format to MyPaint.
2. Migrate all the brushes shipped with MyPaint to new format.
3. Add code to libmypaint to load/save the setting brushes in new format
4. Document the format, as part of libmypaint
5. Use the libmypaint load/save code in MyPaint


Any comments welcomed! Unless there are major objections I hope to
complete this the next week or so.


slow_ink.myb
Description: Binary data
___
Mypaint-discuss mailing list
Mypaint-discuss@gna.org
https://mail.gna.org/listinfo/mypaint-discuss