Skip to content

Commit 87c20e0

Browse files
committed
separate tilesources
stops them crashing into each other
1 parent 0218e4a commit 87c20e0

File tree

10 files changed

+92
-65
lines changed

10 files changed

+92
-65
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
## master
22

3+
- revise image repaint
4+
35
## 9.0.3 2025/03/13
46

57
- fix save-as
68
- revise image repaint (again)
9+
- fix a crash in graph export
710

811
## 9.0.2 2025/03/10
912

TODO

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
valgrind!
1+
- we seem to be making a lot of iimageview during demo load?
22

3-
==1537060== Conditional jump or move depends on uninitialised value(s)
4-
==1537060== at 0x1978B5: drawstate_free (plotdisplay.c:183)
5-
==1537060== by 0x198C01: plotdisplay_to_image (plotdisplay.c:573)
6-
==1537060== by 0x14038D: apply_graph_export_image_call (builtin.c:521)
3+
- we are not always refreshing thumbnails after load completes
4+
5+
- shrink as well as expand tiles in tilecache_snapshot
6+
7+
- iimage_update_from_tilesource() needs to make all iimageview refresh
8+
9+
- long formula should truncate with an ellipsis
10+
11+
- are we autosizing the sinkscreen threadpool? we shouldn't
712

813
# menu redesign
914

src/iimage.c

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ iimage_dispose(GObject *gobject)
5353
(SListMapFn) classmodel_iimage_unlink, iimage);
5454
g_assert(!iimage->classmodels);
5555

56-
WEAKREF_SET(iimage->tilesource, NULL);
57-
5856
G_OBJECT_CLASS(iimage_parent_class)->dispose(gobject);
5957
}
6058

@@ -416,44 +414,10 @@ iimage_init(iImage *iimage)
416414
iobject_set(IOBJECT(iimage), CLASS_IMAGE, NULL);
417415
}
418416

419-
static void
420-
iimage_tilesource_tiles_changed(Tilesource *tilesource, iImage *iimage)
417+
void
418+
iimage_update_from_tilesource(iImage *iimage, Tilesource *tilesource)
421419
{
422420
iimage->scale = tilesource->scale;
423421
iimage->offset = tilesource->offset;
424422
iimage->falsecolour = tilesource->falsecolour;
425423
}
426-
427-
/* Return a new reference to the tilesource for this iimage. Make a new
428-
* tilesource if there's none.
429-
*/
430-
Tilesource *
431-
iimage_get_tilesource_ref(iImage *iimage)
432-
{
433-
Imageinfo *ii = iimage->value.ii;
434-
435-
if (iimage->tilesource &&
436-
tilesource_has_imageinfo(iimage->tilesource, ii))
437-
// there's a tilesource, and it's for the image we hold
438-
return g_object_ref(iimage->tilesource);
439-
else if (ii) {
440-
// no tilesource, or it's out of date ... make a new one
441-
Tilesource *tilesource = tilesource_new_from_imageinfo(ii);
442-
443-
g_object_set(tilesource,
444-
"active", TRUE,
445-
"scale", iimage->scale,
446-
"offset", iimage->offset,
447-
"falsecolour", iimage->falsecolour,
448-
NULL);
449-
450-
WEAKREF_SET(iimage->tilesource, tilesource);
451-
452-
g_signal_connect_object(tilesource, "tiles-changed",
453-
G_CALLBACK(iimage_tilesource_tiles_changed), iimage, 0);
454-
455-
return tilesource;
456-
}
457-
else
458-
return NULL;
459-
}

src/iimage.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,6 @@ struct _iImage {
7575
/* Private ... build iobject caption here.
7676
*/
7777
VipsBuf caption_buffer;
78-
79-
// the tilesource for the ImageValue ... a weakref which gets dupped and
80-
// given out to any viewers (iimageview, imageui) by
81-
// iimage_get_tilesource_ref()
82-
Tilesource *tilesource;
8378
};
8479

8580
typedef struct _iImageClass {
@@ -92,4 +87,4 @@ typedef struct _iImageClass {
9287
GType iimage_get_type(void);
9388
gboolean iimage_replace(iImage *iimage, const char *filename);
9489
gboolean iimage_replace_imageinfo(iImage *iimage, Imageinfo *ii);
95-
Tilesource *iimage_get_tilesource_ref(iImage *iimage);
90+
void iimage_update_from_tilesource(iImage *iimage, Tilesource *tilesource);

src/iimageview.c

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,24 +145,34 @@ iimageview_refresh(vObject *vobject)
145145
iimageview_compute_visibility(iimageview);
146146

147147
if (iimageview->enable) {
148-
Tilesource *current_tilesource;
149-
g_object_get(iimageview->imagedisplay,
150-
"tilesource", &current_tilesource,
151-
NULL);
152-
Tilesource *new_tilesource = iimage_get_tilesource_ref(iimage);
153-
154-
if (current_tilesource != new_tilesource) {
148+
if (!iimage->value.ii)
155149
g_object_set(iimageview->imagedisplay,
156-
"bestfit", TRUE,
157-
"tilesource", new_tilesource,
150+
"tilesource", NULL,
151+
NULL);
152+
else {
153+
Tilesource *current_tilesource;
154+
g_object_get(iimageview->imagedisplay,
155+
"tilesource", &current_tilesource,
158156
NULL);
159157

160-
// set the image loading, if necessary
161-
tilesource_background_load(new_tilesource);
162-
}
158+
if (current_tilesource &&
159+
current_tilesource->image != iimage->value.ii->image) {
160+
Tilesource *new_tilesource =
161+
tilesource_new_from_iimage(iimage, -1000);
162+
163+
g_object_set(iimageview->imagedisplay,
164+
"bestfit", TRUE,
165+
"tilesource", new_tilesource,
166+
NULL);
163167

164-
VIPS_UNREF(current_tilesource);
165-
VIPS_UNREF(new_tilesource);
168+
// set the image loading, if necessary
169+
tilesource_background_load(new_tilesource);
170+
171+
VIPS_UNREF(new_tilesource);
172+
}
173+
174+
VIPS_UNREF(current_tilesource);
175+
}
166176
}
167177

168178
if (iimageview->label)

src/iimageview.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
typedef struct _iImageview {
4343
Graphicview parent_object;
4444

45+
// we build this for the imagedisplay from the model
46+
Tilesource *tilesource;
47+
4548
GtkWidget *top;
4649
Imagedisplay *imagedisplay;
4750
GtkWidget *label;

src/imageui.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ static void
189189
imageui_set_iimage(Imageui *imageui, iImage *iimage)
190190
{
191191
if (imageui->iimage) {
192+
// update thumbnail from our sliders
193+
if (imageui->tilesource)
194+
iimage_update_from_tilesource(imageui->iimage, imageui->tilesource);
195+
192196
imageui->iimage->views =
193197
g_slist_remove(imageui->iimage->views, imageui);
194198
imageui->iimage = NULL;

src/imagewindow.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1462,7 +1462,7 @@ imagewindow_iimage_changed(iImage *iimage, Imagewindow *win)
14621462
printf("imagewindow_iimage_changed:\n");
14631463
#endif /*DEBUG*/
14641464

1465-
Tilesource *tilesource = iimage_get_tilesource_ref(iimage);
1465+
Tilesource *tilesource = tilesource_new_from_iimage(iimage, 0);
14661466
imagewindow_set_tilesource(win, tilesource);
14671467
tilesource_background_load(tilesource);
14681468
VIPS_UNREF(tilesource);

src/tilesource.c

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ enum {
5454
PROP_ACTIVE,
5555
PROP_LOADED,
5656
PROP_VISIBLE,
57+
PROP_PRIORITY,
5758

5859
/* Signals.
5960
*/
@@ -452,7 +453,7 @@ tilesource_display_image(Tilesource *tilesource, VipsImage **mask_out)
452453
x = vips_image_new();
453454
mask = vips_image_new();
454455
if (vips_sink_screen(image, x, mask,
455-
TILE_SIZE, TILE_SIZE, MAX_TILES, 0,
456+
TILE_SIZE, TILE_SIZE, MAX_TILES, tilesource->priority,
456457
tilesource_render_notify, update)) {
457458
VIPS_UNREF(x);
458459
VIPS_UNREF(mask);
@@ -779,6 +780,10 @@ tilesource_property_name(guint prop_id)
779780
return "VISIBLE";
780781
break;
781782

783+
case PROP_PRIORITY:
784+
return "PRIORITY";
785+
break;
786+
782787
default:
783788
return "<unknown>";
784789
}
@@ -970,6 +975,12 @@ tilesource_set_property(GObject *object,
970975
tilesource->visible = b;
971976
break;
972977

978+
case PROP_PRIORITY:
979+
i = g_value_get_int(value);
980+
if (tilesource->priority != i)
981+
tilesource->priority = i;
982+
break;
983+
973984
default:
974985
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
975986
break;
@@ -1023,6 +1034,10 @@ tilesource_get_property(GObject *object,
10231034
g_value_set_boolean(value, tilesource->visible);
10241035
break;
10251036

1037+
case PROP_PRIORITY:
1038+
g_value_set_int(value, tilesource->priority);
1039+
break;
1040+
10261041
default:
10271042
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
10281043
break;
@@ -1201,6 +1216,13 @@ tilesource_class_init(TilesourceClass *class)
12011216
FALSE,
12021217
G_PARAM_READWRITE));
12031218

1219+
g_object_class_install_property(gobject_class, PROP_PRIORITY,
1220+
g_param_spec_int("priority",
1221+
_("priority"),
1222+
_("Render priority"),
1223+
-1000, 1000, 0,
1224+
G_PARAM_READWRITE));
1225+
12041226
tilesource_signals[SIG_PREEVAL] = g_signal_new("preeval",
12051227
G_TYPE_FROM_CLASS(class),
12061228
G_SIGNAL_RUN_LAST,
@@ -1416,6 +1438,22 @@ tilesource_new_from_imageinfo(Imageinfo *ii)
14161438
return tilesource_new_from_image(ii->image);
14171439
}
14181440

1441+
Tilesource *
1442+
tilesource_new_from_iimage(iImage *iimage, int priority)
1443+
{
1444+
Tilesource *tilesource = tilesource_new_from_imageinfo(iimage->value.ii);
1445+
1446+
g_object_set(tilesource,
1447+
"active", TRUE,
1448+
"scale", iimage->scale,
1449+
"offset", iimage->offset,
1450+
"falsecolour", iimage->falsecolour,
1451+
"priority", priority,
1452+
NULL);
1453+
1454+
return tilesource;
1455+
}
1456+
14191457
gboolean
14201458
tilesource_has_imageinfo(Tilesource *tilesource, Imageinfo *ii)
14211459
{

src/tilesource.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ typedef struct _Tilesource {
237237
int load_error;
238238
char *load_message;
239239

240+
/* Render priority ... lower for thumbnails.
241+
*/
242+
int priority;
243+
240244
} Tilesource;
241245

242246
typedef struct _TilesourceClass {
@@ -282,6 +286,7 @@ GType tilesource_get_type(void);
282286
Tilesource *tilesource_new_from_file(const char *filename);
283287
Tilesource *tilesource_new_from_image(VipsImage *image);
284288
Tilesource *tilesource_new_from_imageinfo(Imageinfo *ii);
289+
Tilesource *tilesource_new_from_iimage(iImage *iimage, int priority);
285290
gboolean tilesource_has_imageinfo(Tilesource *tilesource, Imageinfo *ii);
286291

287292
void tilesource_background_load(Tilesource *tilesource);

0 commit comments

Comments
 (0)