From 47a008be97313aba2136bd2191214553135d63aa Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Mon, 16 Jul 2018 01:42:19 +0200 Subject: [PATCH] Issue #1805 - Sample Points keep resetting themselves to "Pixel" Rename XCF property PROP_SAMPLE_POINT to PROP_OLD_SAMPLE_POINT and add new PROP_SAMPLE_POINT. The new property saves the sample point's pick mode plus some padding for whatever else we might want to add. Always save the old property too so nothing changes for older GIMP versions, and avoid loading the old property if the new one was loaded before. --- app/xcf/xcf-load.c | 41 ++++++++++++++++++++++++++++++++++++++++- app/xcf/xcf-private.h | 5 +++-- app/xcf/xcf-save.c | 39 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 80 insertions(+), 5 deletions(-) diff --git a/app/xcf/xcf-load.c b/app/xcf/xcf-load.c index 3b8a4adbab..f0883a325e 100644 --- a/app/xcf/xcf-load.c +++ b/app/xcf/xcf-load.c @@ -801,17 +801,56 @@ xcf_load_image_props (XcfInfo *info, break; case PROP_SAMPLE_POINTS: + { + gint n_sample_points, i; + + n_sample_points = prop_size / (5 * 4); + for (i = 0; i < n_sample_points; i++) + { + GimpSamplePoint *sample_point; + gint32 x, y; + GimpColorPickMode pick_mode; + guint32 padding[2] = { 0, }; + + xcf_read_int32 (info, (guint32 *) &x, 1); + xcf_read_int32 (info, (guint32 *) &y, 1); + xcf_read_int32 (info, (guint32 *) &pick_mode, 1); + xcf_read_int32 (info, (guint32 *) padding, 2); + + GIMP_LOG (XCF, "prop sample point x=%d y=%d mode=%d", + x, y, pick_mode); + + sample_point = gimp_image_add_sample_point_at_pos (image, + x, y, FALSE); + gimp_image_set_sample_point_pick_mode (image, sample_point, + pick_mode, FALSE); + } + } + break; + + case PROP_OLD_SAMPLE_POINTS: { gint32 x, y; gint i, n_sample_points; + /* if there are already sample points, we loaded the new + * prop before + */ + if (gimp_image_get_sample_points (image)) + { + if (! xcf_skip_unknown_prop (info, prop_size)) + return FALSE; + + break; + } + n_sample_points = prop_size / (4 + 4); for (i = 0; i < n_sample_points; i++) { xcf_read_int32 (info, (guint32 *) &x, 1); xcf_read_int32 (info, (guint32 *) &y, 1); - GIMP_LOG (XCF, "prop sample point x=%d y=%d", x, y); + GIMP_LOG (XCF, "prop old sample point x=%d y=%d", x, y); gimp_image_add_sample_point_at_pos (image, x, y, FALSE); } diff --git a/app/xcf/xcf-private.h b/app/xcf/xcf-private.h index a2048d9aca..b7490d8e9c 100644 --- a/app/xcf/xcf-private.h +++ b/app/xcf/xcf-private.h @@ -52,7 +52,7 @@ typedef enum PROP_USER_UNIT = 24, PROP_VECTORS = 25, PROP_TEXT_LAYER_FLAGS = 26, - PROP_SAMPLE_POINTS = 27, + PROP_OLD_SAMPLE_POINTS = 27, PROP_LOCK_CONTENT = 28, PROP_GROUP_ITEM = 29, PROP_ITEM_PATH = 30, @@ -63,7 +63,8 @@ typedef enum PROP_COMPOSITE_MODE = 35, PROP_COMPOSITE_SPACE = 36, PROP_BLEND_SPACE = 37, - PROP_FLOAT_COLOR = 38 + PROP_FLOAT_COLOR = 38, + PROP_SAMPLE_POINTS = 39, } PropType; typedef enum diff --git a/app/xcf/xcf-save.c b/app/xcf/xcf-save.c index 795c6eeae9..fdebcd7447 100644 --- a/app/xcf/xcf-save.c +++ b/app/xcf/xcf-save.c @@ -383,8 +383,15 @@ xcf_save_image_props (XcfInfo *info, gimp_image_get_guides (image))); if (gimp_image_get_sample_points (image)) - xcf_check_error (xcf_save_prop (info, image, PROP_SAMPLE_POINTS, error, - gimp_image_get_sample_points (image))); + { + /* save the new property before the old one, so loading can skip + * the latter + */ + xcf_check_error (xcf_save_prop (info, image, PROP_SAMPLE_POINTS, error, + gimp_image_get_sample_points (image))); + xcf_check_error (xcf_save_prop (info, image, PROP_OLD_SAMPLE_POINTS, error, + gimp_image_get_sample_points (image))); + } xcf_check_error (xcf_save_prop (info, image, PROP_RESOLUTION, error, xres, yres)); @@ -1074,6 +1081,34 @@ xcf_save_prop (XcfInfo *info, break; case PROP_SAMPLE_POINTS: + { + GList *sample_points = va_arg (args, GList *); + gint n_sample_points = g_list_length (sample_points); + + size = n_sample_points * (5 * 4); + + xcf_write_prop_type_check_error (info, prop_type); + xcf_write_int32_check_error (info, &size, 1); + + for (; sample_points; sample_points = g_list_next (sample_points)) + { + GimpSamplePoint *sample_point = sample_points->data; + gint32 x, y; + GimpColorPickMode pick_mode; + guint32 padding[2] = { 0, }; + + gimp_sample_point_get_position (sample_point, &x, &y); + pick_mode = gimp_sample_point_get_pick_mode (sample_point); + + xcf_write_int32_check_error (info, (guint32 *) &x, 1); + xcf_write_int32_check_error (info, (guint32 *) &y, 1); + xcf_write_int32_check_error (info, (guint32 *) &pick_mode, 1); + xcf_write_int32_check_error (info, (guint32 *) padding, 2); + } + } + break; + + case PROP_OLD_SAMPLE_POINTS: { GList *sample_points = va_arg (args, GList *); gint n_sample_points = g_list_length (sample_points);