fix window cycling
we were repeatedly free-ing and new-ing input mmap windows ... this made things like zoom out on large images in nip2 much slower than they needed to be
This commit is contained in:
parent
e9b7231ac0
commit
3c0a2e4837
@ -1,3 +1,6 @@
|
|||||||
|
10/12/17 started 8.6.1
|
||||||
|
- stop window new/free cycling .. faster zoom out on large images in nip2
|
||||||
|
|
||||||
15/4/17 started 8.6.0
|
15/4/17 started 8.6.0
|
||||||
- supports fits images with leading non-image HDUs, thanks benepo
|
- supports fits images with leading non-image HDUs, thanks benepo
|
||||||
- add vips_image_new_from_image() and vips_image_new_from_image1() ... make a
|
- add vips_image_new_from_image() and vips_image_new_from_image1() ... make a
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
# also update the version number in the m4 macros below
|
# also update the version number in the m4 macros below
|
||||||
|
|
||||||
AC_INIT([vips], [8.6.0], [vipsip@jiscmail.ac.uk])
|
AC_INIT([vips], [8.6.1], [vipsip@jiscmail.ac.uk])
|
||||||
# required for gobject-introspection
|
# required for gobject-introspection
|
||||||
AC_PREREQ(2.62)
|
AC_PREREQ(2.62)
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ AC_CONFIG_MACRO_DIR([m4])
|
|||||||
# user-visible library versioning
|
# user-visible library versioning
|
||||||
m4_define([vips_major_version], [8])
|
m4_define([vips_major_version], [8])
|
||||||
m4_define([vips_minor_version], [6])
|
m4_define([vips_minor_version], [6])
|
||||||
m4_define([vips_micro_version], [0])
|
m4_define([vips_micro_version], [1])
|
||||||
m4_define([vips_version],
|
m4_define([vips_version],
|
||||||
[vips_major_version.vips_minor_version.vips_micro_version])
|
[vips_major_version.vips_minor_version.vips_micro_version])
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ VIPS_VERSION_STRING=$VIPS_VERSION-`date`
|
|||||||
# binary interface changes not backwards compatible?: reset age to 0
|
# binary interface changes not backwards compatible?: reset age to 0
|
||||||
|
|
||||||
LIBRARY_CURRENT=50
|
LIBRARY_CURRENT=50
|
||||||
LIBRARY_REVISION=0
|
LIBRARY_REVISION=1
|
||||||
LIBRARY_AGE=8
|
LIBRARY_AGE=8
|
||||||
|
|
||||||
# patched into include/vips/version.h
|
# patched into include/vips/version.h
|
||||||
|
@ -73,7 +73,8 @@ typedef struct {
|
|||||||
|
|
||||||
/* window manager.
|
/* window manager.
|
||||||
*/
|
*/
|
||||||
VipsWindow *vips_window_ref( struct _VipsImage *im, int top, int height );
|
VipsWindow *vips_window_ref( VipsWindow *window,
|
||||||
|
struct _VipsImage *im, int top, int height );
|
||||||
int vips_window_unref( VipsWindow *window );
|
int vips_window_unref( VipsWindow *window );
|
||||||
void vips_window_print( VipsWindow *window );
|
void vips_window_print( VipsWindow *window );
|
||||||
|
|
||||||
|
@ -652,23 +652,21 @@ vips_region_image( VipsRegion *reg, const VipsRect *r )
|
|||||||
all.height = image->Ysize;
|
all.height = image->Ysize;
|
||||||
vips_rect_intersectrect( r, &all, &clipped );
|
vips_rect_intersectrect( r, &all, &clipped );
|
||||||
|
|
||||||
/* Test for empty.
|
|
||||||
*/
|
|
||||||
if( vips_rect_isempty( &clipped ) ) {
|
if( vips_rect_isempty( &clipped ) ) {
|
||||||
vips_error( "VipsRegion",
|
vips_error( "VipsRegion",
|
||||||
"%s", _( "valid clipped to nothing" ) );
|
"%s", _( "valid clipped to nothing" ) );
|
||||||
return( -1 );
|
return( -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
VIPS_FREEF( vips_buffer_unref, reg->buffer );
|
|
||||||
VIPS_FREEF( vips_window_unref, reg->window );
|
|
||||||
reg->invalid = FALSE;
|
reg->invalid = FALSE;
|
||||||
|
|
||||||
if( image->data ) {
|
if( image->data ) {
|
||||||
/* We have the whole image available ... easy!
|
/* We have the whole image available ... easy!
|
||||||
*/
|
*/
|
||||||
|
VIPS_FREEF( vips_buffer_unref, reg->buffer );
|
||||||
|
VIPS_FREEF( vips_window_unref, reg->window );
|
||||||
|
|
||||||
/* We can't just set valid = clipped, since this may be an
|
/* We can't just set valid = whole image, since this may be an
|
||||||
* incompletely calculated memory buffer. Just set valid to r.
|
* incompletely calculated memory buffer. Just set valid to r.
|
||||||
*/
|
*/
|
||||||
reg->valid = clipped;
|
reg->valid = clipped;
|
||||||
@ -677,20 +675,15 @@ vips_region_image( VipsRegion *reg, const VipsRect *r )
|
|||||||
reg->type = VIPS_REGION_OTHER_IMAGE;
|
reg->type = VIPS_REGION_OTHER_IMAGE;
|
||||||
}
|
}
|
||||||
else if( image->dtype == VIPS_IMAGE_OPENIN ) {
|
else if( image->dtype == VIPS_IMAGE_OPENIN ) {
|
||||||
|
VIPS_FREEF( vips_buffer_unref, reg->buffer );
|
||||||
|
|
||||||
/* No complete image data ... but we can use a rolling window.
|
/* No complete image data ... but we can use a rolling window.
|
||||||
*/
|
*/
|
||||||
if( reg->type != VIPS_REGION_WINDOW ||
|
reg->type = VIPS_REGION_WINDOW;
|
||||||
!reg->window ||
|
if( !(reg->window = vips_window_ref( reg->window, image,
|
||||||
reg->window->top > clipped.top ||
|
|
||||||
reg->window->top + reg->window->height <
|
|
||||||
clipped.top + clipped.height ) {
|
|
||||||
if( !(reg->window = vips_window_ref( image,
|
|
||||||
clipped.top, clipped.height )) )
|
clipped.top, clipped.height )) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
||||||
reg->type = VIPS_REGION_WINDOW;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Note the area the window actually represents.
|
/* Note the area the window actually represents.
|
||||||
*/
|
*/
|
||||||
reg->valid.left = 0;
|
reg->valid.left = 0;
|
||||||
@ -701,6 +694,9 @@ vips_region_image( VipsRegion *reg, const VipsRect *r )
|
|||||||
reg->data = reg->window->data;
|
reg->data = reg->window->data;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
VIPS_FREEF( vips_buffer_unref, reg->buffer );
|
||||||
|
VIPS_FREEF( vips_window_unref, reg->window );
|
||||||
|
|
||||||
vips_error( "VipsRegion", "%s", _( "bad image type" ) );
|
vips_error( "VipsRegion", "%s", _( "bad image type" ) );
|
||||||
return( -1 );
|
return( -1 );
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,6 @@
|
|||||||
#ifdef HAVE_SYS_MMAN_H
|
#ifdef HAVE_SYS_MMAN_H
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#endif
|
#endif
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#include <vips/vips.h>
|
#include <vips/vips.h>
|
||||||
#include <vips/internal.h>
|
#include <vips/internal.h>
|
||||||
@ -96,7 +95,7 @@ vips_window_unmap( VipsWindow *window )
|
|||||||
#ifdef DEBUG_TOTAL
|
#ifdef DEBUG_TOTAL
|
||||||
g_mutex_lock( vips__global_lock );
|
g_mutex_lock( vips__global_lock );
|
||||||
total_mmap_usage -= window->length;
|
total_mmap_usage -= window->length;
|
||||||
assert( total_mmap_usage >= 0 );
|
g_assert( total_mmap_usage >= 0 );
|
||||||
g_mutex_unlock( vips__global_lock );
|
g_mutex_unlock( vips__global_lock );
|
||||||
#endif /*DEBUG_TOTAL*/
|
#endif /*DEBUG_TOTAL*/
|
||||||
|
|
||||||
@ -111,13 +110,20 @@ vips_window_unmap( VipsWindow *window )
|
|||||||
static int
|
static int
|
||||||
vips_window_free( VipsWindow *window )
|
vips_window_free( VipsWindow *window )
|
||||||
{
|
{
|
||||||
assert( window->ref_count == 0 );
|
VipsImage *im = window->im;
|
||||||
|
|
||||||
|
g_assert( window->ref_count == 0 );
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf( "** vips_window_free: window top = %d, height = %d (%p)\n",
|
printf( "** vips_window_free: window top = %d, height = %d (%p)\n",
|
||||||
window->top, window->height, window );
|
window->top, window->height, window );
|
||||||
|
printf( "vips_window_unref: %d windows left\n",
|
||||||
|
g_slist_length( im->windows ) );
|
||||||
#endif /*DEBUG*/
|
#endif /*DEBUG*/
|
||||||
|
|
||||||
|
g_assert( g_slist_find( im->windows, window ) );
|
||||||
|
im->windows = g_slist_remove( im->windows, window );
|
||||||
|
|
||||||
if( vips_window_unmap( window ) )
|
if( vips_window_unmap( window ) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
||||||
@ -140,19 +146,11 @@ vips_window_unref( VipsWindow *window )
|
|||||||
window->top, window->height, window->ref_count );
|
window->top, window->height, window->ref_count );
|
||||||
#endif /*DEBUG*/
|
#endif /*DEBUG*/
|
||||||
|
|
||||||
assert( window->ref_count > 0 );
|
g_assert( window->ref_count > 0 );
|
||||||
|
|
||||||
window->ref_count -= 1;
|
window->ref_count -= 1;
|
||||||
|
|
||||||
if( window->ref_count == 0 ) {
|
if( window->ref_count == 0 ) {
|
||||||
assert( g_slist_find( im->windows, window ) );
|
|
||||||
im->windows = g_slist_remove( im->windows, window );
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
printf( "vips_window_unref: %d windows left\n",
|
|
||||||
g_slist_length( im->windows ) );
|
|
||||||
#endif /*DEBUG*/
|
|
||||||
|
|
||||||
if( vips_window_free( window ) ) {
|
if( vips_window_free( window ) ) {
|
||||||
g_mutex_unlock( im->sslock );
|
g_mutex_unlock( im->sslock );
|
||||||
return( -1 );
|
return( -1 );
|
||||||
@ -276,22 +274,20 @@ vips_window_new( VipsImage *im, int top, int height )
|
|||||||
if( !(window = VIPS_NEW( NULL, VipsWindow )) )
|
if( !(window = VIPS_NEW( NULL, VipsWindow )) )
|
||||||
return( NULL );
|
return( NULL );
|
||||||
|
|
||||||
window->ref_count = 0;
|
window->ref_count = 1;
|
||||||
window->im = im;
|
window->im = im;
|
||||||
window->top = 0;
|
window->top = 0;
|
||||||
window->height = 0;
|
window->height = 0;
|
||||||
window->data = NULL;
|
window->data = NULL;
|
||||||
window->baseaddr = NULL;
|
window->baseaddr = NULL;
|
||||||
window->length = 0;
|
window->length = 0;
|
||||||
|
im->windows = g_slist_prepend( im->windows, window );
|
||||||
|
|
||||||
if( vips_window_set( window, top, height ) ) {
|
if( vips_window_set( window, top, height ) ) {
|
||||||
vips_window_free( window );
|
vips_window_free( window );
|
||||||
return( NULL );
|
return( NULL );
|
||||||
}
|
}
|
||||||
|
|
||||||
im->windows = g_slist_prepend( im->windows, window );
|
|
||||||
window->ref_count += 1;
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf( "** vips_window_new: window top = %d, height = %d (%p)\n",
|
printf( "** vips_window_new: window top = %d, height = %d (%p)\n",
|
||||||
window->top, window->height, window );
|
window->top, window->height, window );
|
||||||
@ -343,27 +339,59 @@ vips_window_find( VipsImage *im, int top, int height )
|
|||||||
return( window );
|
return( window );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return a ref to a window that encloses top/height.
|
/* Update a ref to a window to make it enclose top/height.
|
||||||
*/
|
*/
|
||||||
VipsWindow *
|
VipsWindow *
|
||||||
vips_window_ref( VipsImage *im, int top, int height )
|
vips_window_ref( VipsWindow *window, VipsImage *im, int top, int height )
|
||||||
{
|
{
|
||||||
VipsWindow *window;
|
int margin;
|
||||||
|
|
||||||
|
/* We have a window and it has the pixels we need.
|
||||||
|
*/
|
||||||
|
if( window &&
|
||||||
|
window->top <= top &&
|
||||||
|
window->top + window->height >= top + height )
|
||||||
|
return( window );
|
||||||
|
|
||||||
g_mutex_lock( im->sslock );
|
g_mutex_lock( im->sslock );
|
||||||
|
|
||||||
if( !(window = vips_window_find( im, top, height )) ) {
|
/* We have a window and we are the only ref to it ... scroll.
|
||||||
/* No existing window ... make a new one. Ask for a larger
|
|
||||||
* window than we strictly need. There's no point making tiny
|
|
||||||
* windows.
|
|
||||||
*/
|
*/
|
||||||
int margin = VIPS_MIN( vips__window_margin_pixels,
|
if( window &&
|
||||||
vips__window_margin_bytes /
|
window->ref_count == 1 ) {
|
||||||
VIPS_IMAGE_SIZEOF_LINE( im ) );
|
if( vips_window_set( window, top, height ) ) {
|
||||||
|
g_mutex_unlock( im->sslock );
|
||||||
|
vips_window_unref( window );
|
||||||
|
|
||||||
|
return( NULL );
|
||||||
|
}
|
||||||
|
|
||||||
|
g_mutex_unlock( im->sslock );
|
||||||
|
|
||||||
|
return( window );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* There's more than one ref to the window. We can just decrement.
|
||||||
|
* Don't call _unref, since we've inside the lock.
|
||||||
|
*/
|
||||||
|
if( window )
|
||||||
|
window->ref_count -= 1;
|
||||||
|
|
||||||
|
/* Is there an existing window we can reuse?
|
||||||
|
*/
|
||||||
|
if( (window = vips_window_find( im, top, height )) ) {
|
||||||
|
g_mutex_unlock( im->sslock );
|
||||||
|
|
||||||
|
return( window );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* We have to make a new window. Make it a bit bigger than strictly
|
||||||
|
* necessary.
|
||||||
|
*/
|
||||||
|
margin = VIPS_MIN( vips__window_margin_pixels,
|
||||||
|
vips__window_margin_bytes / VIPS_IMAGE_SIZEOF_LINE( im ) );
|
||||||
top -= margin;
|
top -= margin;
|
||||||
height += margin * 2;
|
height += margin * 2;
|
||||||
|
|
||||||
top = VIPS_CLIP( 0, top, im->Ysize - 1 );
|
top = VIPS_CLIP( 0, top, im->Ysize - 1 );
|
||||||
height = VIPS_CLIP( 0, height, im->Ysize - top );
|
height = VIPS_CLIP( 0, height, im->Ysize - top );
|
||||||
|
|
||||||
@ -371,7 +399,6 @@ vips_window_ref( VipsImage *im, int top, int height )
|
|||||||
g_mutex_unlock( im->sslock );
|
g_mutex_unlock( im->sslock );
|
||||||
return( NULL );
|
return( NULL );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
g_mutex_unlock( im->sslock );
|
g_mutex_unlock( im->sslock );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user