@@ -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
250245infobar_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 );
0 commit comments