Skip to content

Commit b546407

Browse files
committed
fix infobar for histogram images
1 parent 94f190f commit b546407

File tree

3 files changed

+25
-32
lines changed

3 files changed

+25
-32
lines changed

TODO

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
- try:
2-
3-
Hist > New > Identity
4-
Image A1.value
5-
6-
infobar shows (x, y), not just x, and value does not display
7-
81

92
- get judder with rotate and images smaller than the window
103

src/infobar.c

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -227,20 +227,15 @@ infobar_get_pixel(void *a, void *b)
227227
PixelUpdate *update = (PixelUpdate *) a;
228228
VipsImage *image = update->image;
229229

230-
/* Block outside the image.
230+
/* Clip (x, y) to the image dimensions. It might be a histogram, for
231+
* example.
231232
*/
232-
if (update->image_x >= 0 &&
233-
update->image_y >= 0 &&
234-
update->image_x < image->Xsize &&
235-
update->image_y < image->Ysize)
236-
/* Fetch from image, even though this can be very slow.
237-
* This is run in a bg thread, so speed should not matter too much.
238-
*/
239-
update->result = !vips_getpoint(image,
240-
&update->vector, &update->n,
241-
update->image_x, update->image_y,
242-
"unpack_complex", TRUE,
243-
NULL);
233+
update->result = !vips_getpoint(image,
234+
&update->vector, &update->n,
235+
VIPS_CLIP(0, update->image_x, image->Xsize - 1),
236+
VIPS_CLIP(0, update->image_y, image->Ysize - 1),
237+
"unpack_complex", TRUE,
238+
NULL);
244239

245240
g_idle_add(infobar_update_pixel_idle, update);
246241
}
@@ -250,25 +245,33 @@ static void
250245
infobar_update_pixel(Infobar *infobar,
251246
Tilesource *tilesource, double image_x, double image_y)
252247
{
248+
/* We need to fetch pixels from base for histograms, from image
249+
* otherwise.
250+
*/
251+
VipsImage *base = tilesource_get_base_image(tilesource);
252+
VipsImage *image = tilesource_get_image(tilesource);
253+
VipsImage *selected = base->Type == VIPS_INTERPRETATION_HISTOGRAM ?
254+
base : image;
255+
253256
if (!infobar->updating &&
254-
tilesource->image) {
257+
selected) {
255258
infobar->updating = TRUE;
256259

257260
PixelUpdate *update = g_new0(PixelUpdate, 1);
258261
update->infobar = infobar;
259-
update->image = tilesource_get_base_image(tilesource);
260-
261-
/* Currently in level0 image coordinates ... we will fetch from
262-
* tilesource->image, the current pyr layer.
263-
*/
264-
int factor = tilesource->image_width / tilesource->image->Xsize;
265-
update->image_x = image_x / factor;
266-
update->image_y = image_y / factor;
262+
update->image = selected;
267263

268264
// must stay valid until we are done
269265
g_object_ref(update->infobar);
270266
g_object_ref(update->image);
271267

268+
/* Currently in level0 image coordinates ... we need to scale for the
269+
* selected image.
270+
*/
271+
int factor = tilesource->image_width / update->image->Xsize;
272+
update->image_x = image_x / factor;
273+
update->image_y = image_y / factor;
274+
272275
if (vips_thread_execute("pixel", infobar_get_pixel, update))
273276
// if we can't run a bg task, we must free the update
274277
infobar_update_free(update);

src/tilesource.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,6 @@ typedef struct _Tilesource {
222222

223223
/* The base image after the first stage of conversion for display (just
224224
* geometric conversion, no conversion to rgb).
225-
*
226-
* Plus a region to fetch pixel values for the infobar. Except for
227-
* histograms! We need to fetch pixels from base for them.
228225
*/
229226
VipsImage *image;
230227
VipsImage *mask;

0 commit comments

Comments
 (0)