### Install libmypaint Source: https://github.com/mypaint/libmypaint/blob/master/README.md Installs the compiled libmypaint library to the system. Requires root privileges. ```bash # make install ``` -------------------------------- ### Configure Build Options Source: https://github.com/mypaint/libmypaint/blob/master/README.md Configures the build process for libmypaint. Use '--prefix' to specify an installation directory. ```bash ./configure ``` ```bash ./configure --prefix=/tmp/junk/example ``` -------------------------------- ### Install OpenSUSE Dependencies Source: https://github.com/mypaint/libmypaint/blob/master/README.md Installs required build dependencies for libmypaint on OpenSUSE Tumbleweed. Covers standard and git build requirements. ```bash # zypper install gcc13 gobject-introspection-devel libjson-c-devel glib2-devel ``` ```bash # zypper install git python311 autoconf intltool gettext-tools libtool ``` -------------------------------- ### Draw a simple painting with MyPaint Source: https://context7.com/mypaint/libmypaint/llms.txt A complete example demonstrating MyPaint initialization, surface creation, brush configuration, drawing a stroke, and saving the result as a PNG. Requires various MyPaint headers. ```c #include #include "mypaint.h" #include "mypaint-brush.h" #include "mypaint-brush-settings.h" #include "mypaint-fixed-tiled-surface.h" void stroke_to(MyPaintBrush *brush, MyPaintSurface *surf, float x, float y, float pressure) { float viewzoom = 1.0, viewrotation = 0.0, barrel_rotation = 0.0; float ytilt = 0.0, xtilt = 0.0, dtime = 1.0/60.0; gboolean linear = FALSE; mypaint_brush_stroke_to(brush, surf, x, y, pressure, xtilt, ytilt, dtime, viewzoom, viewrotation, barrel_rotation, linear); } int main(int argc, char *argv[]) { // Initialize mypaint_init(); // Create surface int width = 400, height = 300; MyPaintFixedTiledSurface *surface = mypaint_fixed_tiled_surface_new(width, height); MyPaintSurface *surf = mypaint_fixed_tiled_surface_interface(surface); // Create and configure brush MyPaintBrush *brush = mypaint_brush_new(); mypaint_brush_from_defaults(brush); // Blue color mypaint_brush_set_base_value(brush, MYPAINT_BRUSH_SETTING_COLOR_H, 0.6); mypaint_brush_set_base_value(brush, MYPAINT_BRUSH_SETTING_COLOR_S, 0.8); mypaint_brush_set_base_value(brush, MYPAINT_BRUSH_SETTING_COLOR_V, 0.9); // Medium size, soft brush mypaint_brush_set_base_value(brush, MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC, 2.5); mypaint_brush_set_base_value(brush, MYPAINT_BRUSH_SETTING_HARDNESS, 0.4); mypaint_brush_set_base_value(brush, MYPAINT_BRUSH_SETTING_OPAQUE, 0.7); // Draw a curved stroke mypaint_brush_new_stroke(brush); mypaint_surface_begin_atomic(surf); stroke_to(brush, surf, 50, 150, 0.0); // Start position stroke_to(brush, surf, 100, 100, 0.5); stroke_to(brush, surf, 150, 80, 0.8); stroke_to(brush, surf, 200, 100, 0.9); stroke_to(brush, surf, 250, 150, 0.7); stroke_to(brush, surf, 300, 200, 0.5); stroke_to(brush, surf, 350, 180, 0.3); stroke_to(brush, surf, 350, 180, 0.0); // End stroke // Get dirty region MyPaintRectangle roi; MyPaintRectangles rois = { .num_rectangles = 1, .rectangles = &roi }; mypaint_surface_end_atomic(surf, &rois); printf("Drew stroke, dirty region: (%d, %d) - %dx%d\n", roi.x, roi.y, roi.width, roi.height); // Save result mypaint_surface_save_png(surf, "painting.png", 0, 0, width, height); printf("Saved to painting.png\n"); // Cleanup mypaint_brush_unref(brush); mypaint_surface_unref(surf); return 0; } ``` -------------------------------- ### Install Debian Dependencies Source: https://github.com/mypaint/libmypaint/blob/master/README.md Installs essential build dependencies for libmypaint on Debian-based systems. Includes packages for standard configuration and git builds. ```bash # apt install -y build-essential # apt install -y libjson-c-dev libgirepository1.0-dev libglib2.0-dev ``` ```bash # apt install -y python autotools-dev intltool gettext libtool ``` -------------------------------- ### Install Red Hat Dependencies Source: https://github.com/mypaint/libmypaint/blob/master/README.md Installs necessary build dependencies for libmypaint on Red Hat-based systems like CentOS 7. Includes packages for standard and git builds. ```bash # yum install -y gcc gobject-introspection-devel json-c-devel glib2-devel ``` ```bash # yum install -y git python autoconf intltool gettext libtool ``` -------------------------------- ### Check pkg-config Availability Source: https://github.com/mypaint/libmypaint/blob/master/README.md Verifies if pkg-config can detect the installed libmypaint. If not found, the PKG_CONFIG_PATH needs to be updated. ```bash pkg-config --list-all | grep -i mypaint ``` ```bash # sh -c "echo 'PKG_CONFIG_PATH=/usr/local/pkgconfig' >>/etc/environment" ``` -------------------------------- ### Rebuild and Install libmypaint Source: https://github.com/mypaint/libmypaint/blob/master/po/README.md After modifying translations, rebuild and reinstall libmypaint to see the effects in applications that use it. This ensures the updated translations are included. ```bash make make install ``` -------------------------------- ### Draw a single dab on the surface Source: https://context7.com/mypaint/libmypaint/llms.txt Demonstrates the function signature and a practical example of drawing a red dab on a fixed tiled surface. ```c #include // Surface draw_dab function signature int mypaint_surface_draw_dab( MyPaintSurface *self, float x, float y, // Center position float radius, // Dab radius in pixels float color_r, // Red (0.0-1.0) float color_g, // Green (0.0-1.0) float color_b, // Blue (0.0-1.0) float opaque, // Opacity (0.0-1.0) float hardness, // Edge hardness (0.0-1.0) float softness, // Softness (0.0-1.0) float alpha_eraser, // Eraser mode (0.0=paint, 1.0=erase) float aspect_ratio, // Ellipse aspect ratio (>=1.0) float angle, // Ellipse angle (0-180 degrees) float lock_alpha, // Lock alpha channel (0.0-1.0) float colorize, // Colorize mode (0.0-1.0) float posterize, // Posterize strength (0.0-1.0) float posterize_num, // Posterization levels float paint // Spectral paint mode (0.0-1.0) ); // Example: Draw a single red dab MyPaintFixedTiledSurface *fixed_surface = mypaint_fixed_tiled_surface_new(400, 400); MyPaintSurface *surface = mypaint_fixed_tiled_surface_interface(fixed_surface); mypaint_surface_begin_atomic(surface); mypaint_surface_draw_dab(surface, 200.0, 200.0, // x, y 20.0, // radius 1.0, 0.0, 0.0, // RGB (red) 0.8, // opaque 0.7, // hardness 0.0, // softness 0.0, // alpha_eraser (0 = normal paint) 1.0, // aspect_ratio (1 = circle) 0.0, // angle 0.0, // lock_alpha 0.0, // colorize 0.0, // posterize 0.05, // posterize_num 0.0); // paint mode MyPaintRectangle roi; MyPaintRectangles rois = { .num_rectangles = 1, .rectangles = &roi }; mypaint_surface_end_atomic(surface, &rois); mypaint_surface_unref(surface); ``` -------------------------------- ### Uninstall libmypaint Source: https://github.com/mypaint/libmypaint/blob/master/README.md Removes the installed libmypaint library from the system. Requires root privileges. ```bash # make uninstall ``` -------------------------------- ### Set and Get Brush Base Values Source: https://context7.com/mypaint/libmypaint/llms.txt Configures brush appearance by setting base values for various settings like color, radius, opacity, and hardness using `mypaint_brush_set_base_value()`. You can also retrieve these values using `mypaint_brush_get_base_value()`. ```c #include #include MyPaintBrush *brush = mypaint_brush_new(); mypaint_brush_from_defaults(brush); // Set brush color to red (HSV color model) mypaint_brush_set_base_value(brush, MYPAINT_BRUSH_SETTING_COLOR_H, 0.0); // Hue: 0.0 = red mypaint_brush_set_base_value(brush, MYPAINT_BRUSH_SETTING_COLOR_S, 1.0); // Saturation: full mypaint_brush_set_base_value(brush, MYPAINT_BRUSH_SETTING_COLOR_V, 1.0); // Value: full brightness // Set brush radius (logarithmic scale: 2.0 ≈ 7 pixels) mypaint_brush_set_base_value(brush, MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC, 2.0); // Set opacity mypaint_brush_set_base_value(brush, MYPAINT_BRUSH_SETTING_OPAQUE, 0.8); // Set hardness (0.0 = soft, 1.0 = hard) mypaint_brush_set_base_value(brush, MYPAINT_BRUSH_SETTING_HARDNESS, 0.6); // Get current value float radius = mypaint_brush_get_base_value(brush, MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC); printf("Brush radius: %f\n", radius); mypaint_brush_unref(brush); ``` -------------------------------- ### mypaint_brush_set_base_value / mypaint_brush_get_base_value Source: https://context7.com/mypaint/libmypaint/llms.txt Sets or gets the base value for a specific brush setting. ```APIDOC ## mypaint_brush_set_base_value / mypaint_brush_get_base_value ### Description Sets or gets the base value for a brush setting. Base values define the default behavior when no input mappings modify the setting. ### Parameters - **brush** (MyPaintBrush*) - Required - The brush instance. - **setting_id** (int) - Required - The ID of the setting to modify (e.g., MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC). - **value** (float) - Required - The value to set. ``` -------------------------------- ### Update Specific Language Translation Source: https://github.com/mypaint/libmypaint/blob/master/po/README.md Use this command to update the .po file for a specific language, for example, French. This should be done before working on a translation. ```bash ./po/update_translations.sh fr ``` -------------------------------- ### Brush State Management Source: https://context7.com/mypaint/libmypaint/llms.txt Functions to get and set internal brush state values, useful for saving, restoring, or replaying brush strokes. ```APIDOC ## Brush State Management ### Description Gets or sets internal brush state values. Useful for saving/restoring brush state or implementing stroke replay. ### Parameters #### Request Body - **brush** (MyPaintBrush*) - Required - The brush instance. - **state_id** (int) - Required - The specific state identifier (e.g., MYPAINT_BRUSH_STATE_X). - **value** (float) - Required - The value to set (for set operations). ### Response #### Success Response (200) - **value** (float) - The current state value. ``` -------------------------------- ### Manage Stroke State Source: https://context7.com/mypaint/libmypaint/llms.txt Call new_stroke at the start of a stroke to reset state. Use reset to clear all brush state including filters and smudge colors. ```c #include MyPaintBrush *brush = mypaint_brush_new(); mypaint_brush_from_defaults(brush); // Begin a new stroke (resets stroke-related state) mypaint_brush_new_stroke(brush); // ... perform stroke_to calls ... // Get total painting time for the stroke double painting_time = mypaint_brush_get_total_stroke_painting_time(brush); printf("Stroke painting time: %f seconds\n", painting_time); // Fully reset all brush state (including smudge colors, position filters, etc.) mypaint_brush_reset(brush); mypaint_brush_unref(brush); ``` -------------------------------- ### Create and Manage MyPaintBrush Instances Source: https://context7.com/mypaint/libmypaint/llms.txt Demonstrates creating new brush instances, including one with support for multiple smudge colors, and managing their reference counts. Remember to free brushes when no longer needed. ```c #include // Create a new brush MyPaintBrush *brush = mypaint_brush_new(); // For brushes that use multiple smudge colors (offset dabs) MyPaintBrush *brush_with_buckets = mypaint_brush_new_with_buckets(256); // Increase reference count (for shared ownership) mypaint_brush_ref(brush); // Decrease reference count (frees when count reaches 0) mypaint_brush_unref(brush); ``` -------------------------------- ### mypaint_init Source: https://context7.com/mypaint/libmypaint/llms.txt Initializes the libmypaint library. This function must be called before any other libmypaint functions are invoked. ```APIDOC ## mypaint_init ### Description Initializes the libmypaint library. Must be called before using any other libmypaint functions. ### Method void ### Endpoint mypaint_init() ``` -------------------------------- ### Apply MyPaintTransformations to points Source: https://context7.com/mypaint/libmypaint/llms.txt Shows how to create and apply various transformations like translation, rotation, and reflection to points using MyPaintTransform. Requires math.h for M_PI. ```c #include #include // Create identity transform MyPaintTransform t = mypaint_transform_unit(); // Translate t = mypaint_transform_translate(t, 100.0, 50.0); // Rotate clockwise by 45 degrees t = mypaint_transform_rotate_cw(t, M_PI / 4.0); // Rotate counter-clockwise t = mypaint_transform_rotate_ccw(t, M_PI / 6.0); // Reflect across an axis at given angle t = mypaint_transform_reflect(t, 0.0); // reflect across x-axis // Apply transform to a point float x = 10.0, y = 20.0; float x_out, y_out; mypaint_transform_point(&t, x, y, &x_out, &y_out); printf("Transformed: (%f, %f) -> (%f, %f)\n", x, y, x_out, y_out); ``` -------------------------------- ### Initialize libmypaint Source: https://context7.com/mypaint/libmypaint/llms.txt Call `mypaint_init()` before using any other libmypaint functions. This function initializes the library. ```c #include int main() { // Initialize libmypaint mypaint_init(); // Now safe to use libmypaint functions // ... return 0; } ``` -------------------------------- ### Initialize custom tiled surface Source: https://context7.com/mypaint/libmypaint/llms.txt Sets up a custom tiled surface implementation by defining tile request callbacks and initializing the surface structure. ```c #include // Custom tile request callbacks void my_tile_request_start(MyPaintTiledSurface *self, MyPaintTileRequest *request) { // Provide tile buffer for the requested tile coordinates // request->tx, request->ty are tile coordinates // request->buffer should be set to a guint16[MYPAINT_TILE_SIZE * MYPAINT_TILE_SIZE * 4] buffer // request->readonly indicates if the tile will be modified } void my_tile_request_end(MyPaintTiledSurface *self, MyPaintTileRequest *request) { // Called when tile access is complete // Flush or release tile buffer as needed } // Initialize custom tiled surface typedef struct { MyPaintTiledSurface parent; // Custom fields... } MyCustomSurface; MyCustomSurface *create_custom_surface(void) { MyCustomSurface *self = malloc(sizeof(MyCustomSurface)); mypaint_tiled_surface_init(&self->parent, my_tile_request_start, my_tile_request_end); return self; } // Initialize a tile request MyPaintTileRequest request; mypaint_tile_request_init(&request, 0, // mipmap level (0 = full resolution) 5, 3, // tile x, y coordinates FALSE); // readonly (FALSE = writing) ``` -------------------------------- ### Initialize Fixed Tiled Surface with mypaint_fixed_tiled_surface_new Source: https://context7.com/mypaint/libmypaint/llms.txt Creates a fixed-size surface for testing. Use the interface function to obtain a generic surface pointer for brush operations. ```c #include // Create a 800x600 surface MyPaintFixedTiledSurface *fixed_surface = mypaint_fixed_tiled_surface_new(800, 600); // Get dimensions int width = mypaint_fixed_tiled_surface_get_width(fixed_surface); int height = mypaint_fixed_tiled_surface_get_height(fixed_surface); printf("Surface size: %d x %d\n", width, height); // Get the generic surface interface for use with brush MyPaintSurface *surface = mypaint_fixed_tiled_surface_interface(fixed_surface); // Use surface with brush... // mypaint_brush_stroke_to(brush, surface, ...); // Clean up mypaint_surface_unref(surface); ``` -------------------------------- ### Initialize GEGL-backed Surface Source: https://context7.com/mypaint/libmypaint/llms.txt Creates and configures a surface compatible with GEGL buffers for integration into GIMP or similar workflows. ```c #include #include // Initialize GEGL first Gegl_init(NULL, NULL); // Create GEGL-backed surface MyPaintGeglTiledSurface *gegl_surface = mypaint_gegl_tiled_surface_new(); // Get the underlying GEGL buffer GeglBuffer *buffer = mypaint_gegl_tiled_surface_get_buffer(gegl_surface); // Set a custom GEGL buffer GeglBuffer *custom_buffer = gegl_buffer_new( GEGL_RECTANGLE(0, 0, 800, 600), babl_format("R'G'B'A float")); mypaint_gegl_tiled_surface_set_buffer(gegl_surface, custom_buffer); // Get MyPaintSurface interface for use with brush MyPaintSurface *surface = mypaint_gegl_tiled_surface_interface(gegl_surface); // Use with brush MyPaintBrush *brush = mypaint_brush_new(); mypaint_brush_from_defaults(brush); mypaint_brush_new_stroke(brush); mypaint_surface_begin_atomic(surface); mypaint_brush_stroke_to(brush, surface, 100, 100, 0.5, 0, 0, 0.1, 1, 0, 0, FALSE); mypaint_surface_end_atomic(surface, NULL); // Clean up mypaint_brush_unref(brush); mypaint_surface_unref(surface); g_object_unref(buffer); Gegl_exit(); ``` -------------------------------- ### Create and manipulate MyPaintRectangles Source: https://context7.com/mypaint/libmypaint/llms.txt Demonstrates creating, expanding, and copying MyPaintRectangle objects for managing dirty regions. Ensure MyPaintRectangle is defined and included. ```c #include // Create rectangles MyPaintRectangle rect1 = { .x = 10, .y = 20, .width = 100, .height = 50 }; MyPaintRectangle rect2 = { .x = 50, .y = 40, .width = 80, .height = 60 }; // Expand rect1 to include a point mypaint_rectangle_expand_to_include_point(&rect1, 200, 150); printf("After point: x=%d, y=%d, w=%d, h=%d\n", rect1.x, rect1.y, rect1.width, rect1.height); // Expand rect1 to include rect2 mypaint_rectangle_expand_to_include_rect(&rect1, &rect2); printf("After union: x=%d, y=%d, w=%d, h=%d\n", rect1.x, rect1.y, rect1.width, rect1.height); // Copy a rectangle MyPaintRectangle *copy = mypaint_rectangle_copy(&rect1); // ... use copy ... free(copy); // Working with multiple rectangles (for end_atomic) MyPaintRectangle rects[4]; MyPaintRectangles roi = { .num_rectangles = 4, .rectangles = rects }; ``` -------------------------------- ### Build libmypaint Source: https://github.com/mypaint/libmypaint/blob/master/README.md Compiles the libmypaint library after configuration. This command should be run from the root of the source directory. ```bash make ``` -------------------------------- ### Run Test Suite Source: https://github.com/mypaint/libmypaint/blob/master/README.md Executes all unit tests for libmypaint to verify the build integrity. Run this command after compiling. ```bash make check ``` -------------------------------- ### mypaint_tiled_surface_init Source: https://context7.com/mypaint/libmypaint/llms.txt Initializes a custom tiled surface implementation. Used when implementing custom rendering backends. ```APIDOC ## mypaint_tiled_surface_init ### Description Initializes a custom tiled surface implementation. Used when implementing custom rendering backends. ### Parameters - **self** (MyPaintTiledSurface*) - Required - Tiled surface instance - **tile_request_start** (callback) - Required - Callback for tile request start - **tile_request_end** (callback) - Required - Callback for tile request end ``` -------------------------------- ### Configure Brush Dynamic Mappings Source: https://context7.com/mypaint/libmypaint/llms.txt Use these functions to define how input values like pressure affect brush settings. Ensure the brush is initialized before setting mapping points. ```c #include #include MyPaintBrush *brush = mypaint_brush_new(); mypaint_brush_from_defaults(brush); // Set up pressure-sensitive opacity // First, set number of control points for the pressure->opacity mapping mypaint_brush_set_mapping_n(brush, MYPAINT_BRUSH_SETTING_OPAQUE_MULTIPLY, // Setting to modify MYPAINT_BRUSH_INPUT_PRESSURE, // Input that modifies it 2); // Number of control points // Define the mapping curve: (input_value, output_offset) // Point 0: at pressure 0.0, multiply opacity by 0.0 (invisible) mypaint_brush_set_mapping_point(brush, MYPAINT_BRUSH_SETTING_OPAQUE_MULTIPLY, MYPAINT_BRUSH_INPUT_PRESSURE, 0, // Point index 0.0, // Input value (pressure) 0.0); // Output offset // Point 1: at pressure 1.0, multiply opacity by 1.0 (full opacity) mypaint_brush_set_mapping_point(brush, MYPAINT_BRUSH_SETTING_OPAQUE_MULTIPLY, MYPAINT_BRUSH_INPUT_PRESSURE, 1, // Point index 1.0, // Input value (pressure) 1.0); // Output offset // Query mapping configuration int num_points = mypaint_brush_get_mapping_n(brush, MYPAINT_BRUSH_SETTING_OPAQUE_MULTIPLY, MYPAINT_BRUSH_INPUT_PRESSURE); float x, y; mypaint_brush_get_mapping_point(brush, MYPAINT_BRUSH_SETTING_OPAQUE_MULTIPLY, MYPAINT_BRUSH_INPUT_PRESSURE, 0, &x, &y); printf("Point 0: input=%f, offset=%f\n", x, y); // Check if a setting is constant (no dynamic mappings) gboolean is_const = mypaint_brush_is_constant(brush, MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC); mypaint_brush_unref(brush); ``` -------------------------------- ### Load Brush Settings from JSON String Source: https://context7.com/mypaint/libmypaint/llms.txt Loads brush settings from a JSON string, typically from a MyPaint brush file. Returns TRUE on success and FALSE on failure. Ensure the file is read correctly into a string buffer. ```c #include #include MyPaintBrush *brush = mypaint_brush_new(); // Load brush definition from file FILE *fp = fopen("brushes/classic/charcoal.myb", "r"); if (fp) { fseek(fp, 0, SEEK_END); long size = ftell(fp); fseek(fp, 0, SEEK_SET); char *brush_def = malloc(size + 1); fread(brush_def, 1, size, fp); brush_def[size] = '\0'; fclose(fp); // Parse JSON brush definition gboolean success = mypaint_brush_from_string(brush, brush_def); if (success) { printf("Brush loaded successfully\n"); } free(brush_def); } mypaint_brush_unref(brush); ``` -------------------------------- ### Generate and Check Distribution Releases Source: https://github.com/mypaint/libmypaint/blob/master/README.md Commands to create a distribution package and verify its integrity before public release. ```bash $ make dist ``` ```bash $ make distcheck ``` -------------------------------- ### mypaint_gegl_tiled_surface_new Source: https://context7.com/mypaint/libmypaint/llms.txt Creates a GEGL-backed surface for integration with GEGL/GIMP workflows. ```APIDOC ## mypaint_gegl_tiled_surface_new ### Description Creates a GEGL-backed surface for integration with GEGL/GIMP workflows. ### Method C Function ``` -------------------------------- ### Run MyPaint with Original Strings Source: https://github.com/mypaint/libmypaint/blob/master/po/README.md To compare translations, you can run MyPaint with the original strings by setting the LC_MESSAGES environment variable to 'C'. ```bash LC_MESSAGES=C ./mypaint ``` -------------------------------- ### mypaint_brush_from_string Source: https://context7.com/mypaint/libmypaint/llms.txt Loads brush settings from a JSON string (MyPaint brush file format). ```APIDOC ## mypaint_brush_from_string ### Description Loads brush settings from a JSON string (MyPaint brush file format). Returns TRUE on success, FALSE on failure. ### Parameters - **brush** (MyPaintBrush*) - Required - The brush instance to update. - **brush_def** (const char*) - Required - The JSON string containing brush settings. ``` -------------------------------- ### Check ldconfig Availability Source: https://github.com/mypaint/libmypaint/blob/master/README.md Ensures that the dynamic linker cache is aware of libmypaint. If not found, the LD_LIBRARY_PATH or ld.so.conf.d needs to be updated. ```bash # ldconfig -p |grep -i libmypaint ``` ```bash $ export LD_LIBRARY_PATH=/usr/local/lib ``` ```bash # sh -c "echo '/usr/local/lib' > /etc/ld.so.conf.d/usrlocal.conf" # ldconfig ``` -------------------------------- ### Run MyPaint with Specific Translation Source: https://github.com/mypaint/libmypaint/blob/master/po/README.md On Linux, you can test MyPaint with a specific translation by setting the LANG environment variable. Ensure the locale is supported and you are in the mypaint source root directory. ```bash LANG=ll_CC.utf8 ./mypaint ``` -------------------------------- ### Update Translation Template Source: https://github.com/mypaint/libmypaint/blob/master/po/README.md Run this command to update the POT file after changing program strings. This allows WebLate users to create new translations. ```bash ./po/update_translations.sh --only-template ``` -------------------------------- ### Manage Smudge Buckets with mypaint_brush_get_smudge_bucket_state Source: https://context7.com/mypaint/libmypaint/llms.txt Manages color storage for brushes using multiple offset dabs. Requires a brush initialized with smudge buckets. ```c #include // Create brush with smudge buckets MyPaintBrush *brush = mypaint_brush_new_with_buckets(256); mypaint_brush_from_defaults(brush); // Set smudge bucket state // Parameters: bucket_index, r, g, b, a, prev_r, prev_g, prev_b, prev_a, prev_color_recentness mypaint_brush_set_smudge_bucket_state(brush, 0, 1.0, 0.0, 0.0, 1.0, // Current smudge color (red) 0.5, 0.5, 0.5, 1.0, // Previous color 0.5); // Previous color recentness // Get smudge bucket state float r, g, b, a; float prev_r, prev_g, prev_b, prev_a; float prev_recentness; mypaint_brush_get_smudge_bucket_state(brush, 0, &r, &g, &b, &a, &prev_r, &prev_g, &prev_b, &prev_a, &prev_recentness); printf("Bucket 0 smudge color: rgba(%f, %f, %f, %f)\n", r, g, b, a); // Get range of buckets used int min_bucket = mypaint_brush_get_min_smudge_bucket_used(brush); int max_bucket = mypaint_brush_get_max_smudge_bucket_used(brush); printf("Buckets used: %d to %d\n", min_bucket, max_bucket); mypaint_brush_unref(brush); ``` -------------------------------- ### Generate Configure Script Source: https://github.com/mypaint/libmypaint/blob/master/README.md Generates the 'configure' script from 'configure.ac' using autotools. This step is only necessary when building from the git repository. ```bash git clone https://github.com/mypaint/libmypaint.git cd libmypaint ./autogen.sh ``` -------------------------------- ### Fixed Tiled Surface API Source: https://context7.com/mypaint/libmypaint/llms.txt Creates and manages a fixed-size tiled surface for painting operations. ```APIDOC ## mypaint_fixed_tiled_surface_new ### Description Creates a simple fixed-size tiled surface for testing and basic use cases. ### Parameters #### Request Body - **width** (int) - Required - Width of the surface. - **height** (int) - Required - Height of the surface. ### Response #### Success Response (200) - **surface** (MyPaintFixedTiledSurface*) - The newly created surface instance. ``` -------------------------------- ### Brush Management Functions Source: https://context7.com/mypaint/libmypaint/llms.txt Functions for creating, referencing, and resetting brush instances. ```APIDOC ## mypaint_brush_new ### Description Creates a new brush instance with default settings. The brush must be freed with mypaint_brush_unref when no longer needed. ## mypaint_brush_from_defaults ### Description Resets all brush settings to their default values. Useful for creating a basic brush before customizing specific settings. ``` -------------------------------- ### mypaint_brush_setting_info Source: https://context7.com/mypaint/libmypaint/llms.txt Retrieves metadata about a specific brush setting. ```APIDOC ## mypaint_brush_setting_info ### Description Gets metadata about a brush setting, including name, default value, and valid range. ### Method C Function ### Parameters - **setting** (MyPaintBrushSetting) - Required - The brush setting identifier. ``` -------------------------------- ### mypaint_brush_set_mapping_n / mypaint_brush_set_mapping_point Source: https://context7.com/mypaint/libmypaint/llms.txt Configures dynamic mappings for brush settings, allowing properties like opacity and size to be modified by input values such as pressure or speed. ```APIDOC ## mypaint_brush_set_mapping_n / mypaint_brush_set_mapping_point ### Description Configures dynamic mappings that modify brush settings based on input values. This enables pressure-sensitive opacity, speed-dependent size, etc. ### Method C function calls ### Endpoint N/A (Library functions) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```c #include #include MyPaintBrush *brush = mypaint_brush_new(); mypaint_brush_from_defaults(brush); // Set up pressure-sensitive opacity // First, set number of control points for the pressure->opacity mapping mypaint_brush_set_mapping_n(brush, MYPAINT_BRUSH_SETTING_OPAQUE_MULTIPLY, // Setting to modify MYPAINT_BRUSH_INPUT_PRESSURE, // Input that modifies it 2); // Number of control points // Define the mapping curve: (input_value, output_offset) // Point 0: at pressure 0.0, multiply opacity by 0.0 (invisible) mypaint_brush_set_mapping_point(brush, MYPAINT_BRUSH_SETTING_OPAQUE_MULTIPLY, MYPAINT_BRUSH_INPUT_PRESSURE, 0, // Point index 0.0, // Input value (pressure) 0.0); // Output offset // Point 1: at pressure 1.0, multiply opacity by 1.0 (full opacity) mypaint_brush_set_mapping_point(brush, MYPAINT_BRUSH_SETTING_OPAQUE_MULTIPLY, MYPAINT_BRUSH_INPUT_PRESSURE, 1, // Point index 1.0, // Input value (pressure) 1.0); // Output offset // Query mapping configuration int num_points = mypaint_brush_get_mapping_n( brush, MYPAINT_BRUSH_SETTING_OPAQUE_MULTIPLY, MYPAINT_BRUSH_INPUT_PRESSURE); float x, y; mypaint_brush_get_mapping_point( brush, MYPAINT_BRUSH_SETTING_OPAQUE_MULTIPLY, MYPAINT_BRUSH_INPUT_PRESSURE, 0, &x, &y); printf("Point 0: input=%%f, offset=%%f\n", x, y); // Check if a setting is constant (no dynamic mappings) gboolean is_const = mypaint_brush_is_constant(brush, MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC); mypaint_brush_unref(brush); ``` ### Response #### Success Response (200) N/A (This is a configuration function) #### Response Example N/A ``` -------------------------------- ### Update Translation Strings Source: https://github.com/mypaint/libmypaint/blob/master/README.md Updates .po files to reflect changes in localizable strings within the source code. ```bash $ cd po && make update-po ``` -------------------------------- ### Reset Brush Settings to Defaults Source: https://context7.com/mypaint/libmypaint/llms.txt Use `mypaint_brush_from_defaults()` to reset all brush settings to their default values. This is useful before customizing specific settings. ```c #include MyPaintBrush *brush = mypaint_brush_new(); // Reset to defaults mypaint_brush_from_defaults(brush); // Now customize as needed mypaint_brush_set_base_value(brush, MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC, 2.0); mypaint_brush_unref(brush); ``` -------------------------------- ### Manage Brush State with mypaint_brush_get_state and mypaint_brush_set_state Source: https://context7.com/mypaint/libmypaint/llms.txt Use these functions to save or restore internal brush state values, such as position, radius, and pressure. ```c #include #include MyPaintBrush *brush = mypaint_brush_new(); mypaint_brush_from_defaults(brush); // Get current state values float x = mypaint_brush_get_state(brush, MYPAINT_BRUSH_STATE_X); float y = mypaint_brush_get_state(brush, MYPAINT_BRUSH_STATE_Y); float actual_radius = mypaint_brush_get_state(brush, MYPAINT_BRUSH_STATE_ACTUAL_RADIUS); float pressure = mypaint_brush_get_state(brush, MYPAINT_BRUSH_STATE_PRESSURE); printf("Brush state: pos=(%f, %f), radius=%f, pressure=%f\n", x, y, actual_radius, pressure); // Set state values (useful for restoring saved state) mypaint_brush_set_state(brush, MYPAINT_BRUSH_STATE_X, 100.0); mypaint_brush_set_state(brush, MYPAINT_BRUSH_STATE_Y, 100.0); mypaint_brush_unref(brush); ``` -------------------------------- ### Retrieve Brush Input Metadata Source: https://context7.com/mypaint/libmypaint/llms.txt Accesses metadata for brush inputs like pressure or speed, including valid ranges and normal values. ```c #include // Get info about a specific input const MyPaintBrushInputInfo *info = mypaint_brush_input_info( MYPAINT_BRUSH_INPUT_PRESSURE); printf("Input: %s\n", info->cname); printf("Name: %s\n", mypaint_brush_input_info_get_name(info)); printf("Range: [%f, %f] (hard), [%f, %f] (soft)\n", info->hard_min, info->hard_max, info->soft_min, info->soft_max); printf("Normal value: %f\n", info->normal); printf("Tooltip: %s\n", mypaint_brush_input_info_get_tooltip(info)); // Look up input by internal name MyPaintBrushInput input = mypaint_brush_input_from_cname("pressure"); // Returns MYPAINT_BRUSH_INPUT_PRESSURE // Available inputs: // MYPAINT_BRUSH_INPUT_PRESSURE - tablet pressure (0.0-1.0) // MYPAINT_BRUSH_INPUT_SPEED1 - fine speed // MYPAINT_BRUSH_INPUT_SPEED2 - gross speed // MYPAINT_BRUSH_INPUT_RANDOM - random value (0.0-1.0) // MYPAINT_BRUSH_INPUT_STROKE - stroke progress (0.0-1.0) // MYPAINT_BRUSH_INPUT_DIRECTION - stroke direction (0-180 degrees) // MYPAINT_BRUSH_INPUT_TILT_DECLINATION - stylus tilt angle // MYPAINT_BRUSH_INPUT_TILT_ASCENSION - stylus rotation // MYPAINT_BRUSH_INPUT_CUSTOM - user-defined input // MYPAINT_BRUSH_INPUT_VIEWZOOM - canvas zoom level // MYPAINT_BRUSH_INPUT_BARREL_ROTATION - stylus barrel rotation ``` -------------------------------- ### Save surface to PNG Source: https://context7.com/mypaint/libmypaint/llms.txt Exports the current surface contents to a PNG file using specified dimensions and offsets. ```c #include #include MyPaintFixedTiledSurface *fixed_surface = mypaint_fixed_tiled_surface_new(800, 600); MyPaintSurface *surface = mypaint_fixed_tiled_surface_interface(fixed_surface); // ... draw on surface ... // Save to PNG file mypaint_surface_save_png(surface, "output.png", 0, 0, // x, y offset 800, 600); // width, height mypaint_surface_unref(surface); ``` -------------------------------- ### Sample surface color and alpha Source: https://context7.com/mypaint/libmypaint/llms.txt Retrieves color and alpha values from a specific surface position, useful for smudge brush implementations. ```c #include MyPaintFixedTiledSurface *fixed_surface = mypaint_fixed_tiled_surface_new(400, 400); MyPaintSurface *surface = mypaint_fixed_tiled_surface_interface(fixed_surface); // Sample color at position float r, g, b, a; mypaint_surface_get_color(surface, 200.0, 200.0, // x, y position 10.0, // sampling radius &r, &g, &b, &a, // output color 0.0); // paint mode printf("Sampled color: rgba(%f, %f, %f, %f)\n", r, g, b, a); // Get just the alpha value float alpha = mypaint_surface_get_alpha(surface, 200.0, 200.0, 10.0); printf("Alpha at position: %f\n", alpha); mypaint_surface_unref(surface); ``` -------------------------------- ### Render Strokes to Surface Source: https://context7.com/mypaint/libmypaint/llms.txt Use stroke_to to process motion events and render dabs. Wrap calls in surface_begin_atomic and surface_end_atomic to track dirty regions. ```c #include #include #include MyPaintBrush *brush = mypaint_brush_new(); mypaint_brush_from_defaults(brush); // Create a surface to draw on MyPaintFixedTiledSurface *fixed_surface = mypaint_fixed_tiled_surface_new(800, 600); MyPaintSurface *surface = mypaint_fixed_tiled_surface_interface(fixed_surface); // Start a stroke mypaint_brush_new_stroke(brush); // Begin atomic operation (for tracking dirty regions) mypaint_surface_begin_atomic(surface); // Draw stroke points // Parameters: brush, surface, x, y, pressure, xtilt, ytilt, dtime, // viewzoom, viewrotation, barrel_rotation, linear float viewzoom = 1.0; float viewrotation = 0.0; float barrel_rotation = 0.0; gboolean linear = FALSE; // Move to start position mypaint_brush_stroke_to(brush, surface, 100.0, 100.0, // x, y position 0.0, // pressure (0 = pen up) 0.0, 0.0, // xtilt, ytilt 0.1, // dtime (seconds since last event) viewzoom, viewrotation, barrel_rotation, linear); // Draw a curved stroke mypaint_brush_stroke_to(brush, surface, 150.0, 120.0, 0.5, 0.0, 0.0, 0.05, viewzoom, viewrotation, barrel_rotation, linear); mypaint_brush_stroke_to(brush, surface, 200.0, 110.0, 0.8, 0.0, 0.0, 0.05, viewzoom, viewrotation, barrel_rotation, linear); mypaint_brush_stroke_to(brush, surface, 250.0, 130.0, 0.6, 0.0, 0.0, 0.05, viewzoom, viewrotation, barrel_rotation, linear); mypaint_brush_stroke_to(brush, surface, 300.0, 100.0, 0.3, 0.0, 0.0, 0.05, viewzoom, viewrotation, barrel_rotation, linear); // Lift pen mypaint_brush_stroke_to(brush, surface, 300.0, 100.0, 0.0, 0.0, 0.0, 0.05, viewzoom, viewrotation, barrel_rotation, linear); // End atomic operation and get dirty region MyPaintRectangle roi; MyPaintRectangles rois = { .num_rectangles = 1, .rectangles = &roi }; mypaint_surface_end_atomic(surface, &rois); printf("Dirty region: x=%d, y=%d, w=%d, h=%d\n", roi.x, roi.y, roi.width, roi.height); mypaint_brush_unref(brush); mypaint_surface_unref(surface); ``` -------------------------------- ### Calculate dab shape opacity Source: https://github.com/mypaint/libmypaint/wiki/Using-Brushlib Pseudocode for calculating pixel opacity based on dab geometry, including elliptical transformations and hardness. ```pseudocode cs = cos(angle/360*2*pi) sn = sin(angle/360*2*pi) for each pixel: dx = pixel.x - x dy = pixel.y - y dyr = (dy*cs-dx*sn)*aspect_ratio dxr = (dy*sn+dx*cs) dd = (dyr*dyr + dxr*dxr) / (radius*radius) if dd > 1: opa = 0 else if dd < hardness: opa = dd + 1-(dd/hardness) else opa = hardness/(1-hardness)*(1-dd) pixel_opacity = opa * opaque ``` -------------------------------- ### mypaint_brush_input_info Source: https://context7.com/mypaint/libmypaint/llms.txt Retrieves metadata about a specific brush input. ```APIDOC ## mypaint_brush_input_info ### Description Gets metadata about a brush input, including name and valid range. ### Method C Function ### Parameters - **input** (MyPaintBrushInput) - Required - The brush input identifier. ``` -------------------------------- ### Retrieve Brush Setting Metadata Source: https://context7.com/mypaint/libmypaint/llms.txt Accesses information about brush settings, including names, ranges, and default values, or looks up settings by their internal string names. ```c #include // Get info about a specific setting const MyPaintBrushSettingInfo *info = mypaint_brush_setting_info( MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC); printf("Setting: %s\n", info->cname); printf("Name: %s\n", mypaint_brush_setting_info_get_name(info)); printf("Min: %f, Default: %f, Max: %f\n", info->min, info->def, info->max); printf("Constant: %s\n", info->constant ? "yes" : "no"); printf("Tooltip: %s\n", info->brush_setting_info_get_tooltip(info)); // Look up setting by internal name MyPaintBrushSetting setting = mypaint_brush_setting_from_cname("radius_logarithmic"); // Returns MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC ``` -------------------------------- ### mypaint_brush_new_stroke / mypaint_brush_reset Source: https://context7.com/mypaint/libmypaint/llms.txt Manages the state of a drawing stroke. `new_stroke` should be called to begin a new stroke, and `reset` can be used to clear all brush state. ```APIDOC ## mypaint_brush_new_stroke / mypaint_brush_reset ### Description Manages stroke state. Call `new_stroke` at the beginning of each stroke, and optionally `reset` to clear all brush state. ### Method C function calls ### Endpoint N/A (Library functions) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```c #include MyPaintBrush *brush = mypaint_brush_new(); mypaint_brush_from_defaults(brush); // Begin a new stroke (resets stroke-related state) mypaint_brush_new_stroke(brush); // ... perform stroke_to calls ... // Get total painting time for the stroke double painting_time = mypaint_brush_get_total_stroke_painting_time(brush); printf("Stroke painting time: %%f seconds\n", painting_time); // Fully reset all brush state (including smudge colors, position filters, etc.) mypaint_brush_reset(brush); mypaint_brush_unref(brush); ``` ### Response #### Success Response (200) N/A (These are state management functions) #### Response Example N/A ```