slightly less stupid float->int mask

still not quite right
This commit is contained in:
John Cupitt 2015-11-11 16:51:08 +00:00
parent f32ab06a1c
commit 03a4e54649
3 changed files with 26 additions and 32 deletions

8
TODO
View File

@ -1,11 +1,3 @@
- test suite is broken, float->int mask I guess
yes, what about the case where float mask sums to zero, we'll /0 when scaling
the output mask
not sure the fix is right, think again
maybe look at change in sum? add difference to scale?
- looks like we have a race in tiled threadcache? see - looks like we have a race in tiled threadcache? see

View File

@ -25,6 +25,7 @@ TARGET_DIR=$(HTML_DIR)/$(DOC_MODULE)
SETUP_FILES = \ SETUP_FILES = \
$(content_files) \ $(content_files) \
$(expand_content_files) \
$(DOC_MAIN_SGML_FILE) \ $(DOC_MAIN_SGML_FILE) \
$(DOC_MODULE)-sections.txt \ $(DOC_MODULE)-sections.txt \
$(DOC_MODULE)-overrides.txt $(DOC_MODULE)-overrides.txt
@ -86,7 +87,7 @@ GTK_DOC_V_SETUP_0=@echo " DOC Preparing build";
setup-build.stamp: setup-build.stamp:
-$(GTK_DOC_V_SETUP)if test "$(abs_srcdir)" != "$(abs_builddir)" ; then \ -$(GTK_DOC_V_SETUP)if test "$(abs_srcdir)" != "$(abs_builddir)" ; then \
files=`echo $(SETUP_FILES) $(expand_content_files) $(DOC_MODULE).types`; \ files=`echo $(SETUP_FILES) $(DOC_MODULE).types`; \
if test "x$$files" != "x" ; then \ if test "x$$files" != "x" ; then \
for file in $$files ; do \ for file in $$files ; do \
destdir=`dirname $(abs_builddir)/$$file`; \ destdir=`dirname $(abs_builddir)/$$file`; \
@ -118,7 +119,7 @@ scan-build.stamp: setup-build.stamp $(HFILE_GLOB) $(CFILE_GLOB)
$(GTK_DOC_V_INTROSPECT)if grep -l '^..*$$' $(DOC_MODULE).types > /dev/null 2>&1 ; then \ $(GTK_DOC_V_INTROSPECT)if grep -l '^..*$$' $(DOC_MODULE).types > /dev/null 2>&1 ; then \
scanobj_options=""; \ scanobj_options=""; \
gtkdoc-scangobj 2>&1 --help | grep >/dev/null "\-\-verbose"; \ gtkdoc-scangobj 2>&1 --help | grep >/dev/null "\-\-verbose"; \
if test "$(?)" = "0"; then \ if test "$$?" = "0"; then \
if test "x$(V)" = "x1"; then \ if test "x$(V)" = "x1"; then \
scanobj_options="--verbose"; \ scanobj_options="--verbose"; \
fi; \ fi; \
@ -162,17 +163,17 @@ GTK_DOC_V_XREF=$(GTK_DOC_V_XREF_$(V))
GTK_DOC_V_XREF_=$(GTK_DOC_V_XREF_$(AM_DEFAULT_VERBOSITY)) GTK_DOC_V_XREF_=$(GTK_DOC_V_XREF_$(AM_DEFAULT_VERBOSITY))
GTK_DOC_V_XREF_0=@echo " DOC Fixing cross-references"; GTK_DOC_V_XREF_0=@echo " DOC Fixing cross-references";
html-build.stamp: sgml.stamp $(DOC_MAIN_SGML_FILE) $(content_files) html-build.stamp: sgml.stamp $(DOC_MAIN_SGML_FILE) $(content_files) $(expand_content_files)
$(GTK_DOC_V_HTML)rm -rf html && mkdir html && \ $(GTK_DOC_V_HTML)rm -rf html && mkdir html && \
mkhtml_options=""; \ mkhtml_options=""; \
gtkdoc-mkhtml 2>&1 --help | grep >/dev/null "\-\-verbose"; \ gtkdoc-mkhtml 2>&1 --help | grep >/dev/null "\-\-verbose"; \
if test "$(?)" = "0"; then \ if test "$$?" = "0"; then \
if test "x$(V)" = "x1"; then \ if test "x$(V)" = "x1"; then \
mkhtml_options="$$mkhtml_options --verbose"; \ mkhtml_options="$$mkhtml_options --verbose"; \
fi; \ fi; \
fi; \ fi; \
gtkdoc-mkhtml 2>&1 --help | grep >/dev/null "\-\-path"; \ gtkdoc-mkhtml 2>&1 --help | grep >/dev/null "\-\-path"; \
if test "$(?)" = "0"; then \ if test "$$?" = "0"; then \
mkhtml_options="$$mkhtml_options --path=\"$(abs_srcdir)\""; \ mkhtml_options="$$mkhtml_options --path=\"$(abs_srcdir)\""; \
fi; \ fi; \
cd html && gtkdoc-mkhtml $$mkhtml_options $(MKHTML_OPTIONS) $(DOC_MODULE) ../$(DOC_MAIN_SGML_FILE) cd html && gtkdoc-mkhtml $$mkhtml_options $(MKHTML_OPTIONS) $(DOC_MODULE) ../$(DOC_MAIN_SGML_FILE)
@ -194,11 +195,11 @@ GTK_DOC_V_PDF=$(GTK_DOC_V_PDF_$(V))
GTK_DOC_V_PDF_=$(GTK_DOC_V_PDF_$(AM_DEFAULT_VERBOSITY)) GTK_DOC_V_PDF_=$(GTK_DOC_V_PDF_$(AM_DEFAULT_VERBOSITY))
GTK_DOC_V_PDF_0=@echo " DOC Building PDF"; GTK_DOC_V_PDF_0=@echo " DOC Building PDF";
pdf-build.stamp: sgml.stamp $(DOC_MAIN_SGML_FILE) $(content_files) pdf-build.stamp: sgml.stamp $(DOC_MAIN_SGML_FILE) $(content_files) $(expand_content_files)
$(GTK_DOC_V_PDF)rm -f $(DOC_MODULE).pdf && \ $(GTK_DOC_V_PDF)rm -f $(DOC_MODULE).pdf && \
mkpdf_options=""; \ mkpdf_options=""; \
gtkdoc-mkpdf 2>&1 --help | grep >/dev/null "\-\-verbose"; \ gtkdoc-mkpdf 2>&1 --help | grep >/dev/null "\-\-verbose"; \
if test "$(?)" = "0"; then \ if test "$$?" = "0"; then \
if test "x$(V)" = "x1"; then \ if test "x$(V)" = "x1"; then \
mkpdf_options="$$mkpdf_options --verbose"; \ mkpdf_options="$$mkpdf_options --verbose"; \
fi; \ fi; \
@ -223,12 +224,15 @@ clean-local:
@if echo $(SCAN_OPTIONS) | grep -q "\-\-rebuild-types" ; then \ @if echo $(SCAN_OPTIONS) | grep -q "\-\-rebuild-types" ; then \
rm -f $(DOC_MODULE).types; \ rm -f $(DOC_MODULE).types; \
fi fi
@if echo $(SCAN_OPTIONS) | grep -q "\-\-rebuild-sections" ; then \
rm -f $(DOC_MODULE)-sections.txt; \
fi
distclean-local: distclean-local:
@rm -rf xml html $(REPORT_FILES) $(DOC_MODULE).pdf \ @rm -rf xml html $(REPORT_FILES) $(DOC_MODULE).pdf \
$(DOC_MODULE)-decl-list.txt $(DOC_MODULE)-decl.txt $(DOC_MODULE)-decl-list.txt $(DOC_MODULE)-decl.txt
@if test "$(abs_srcdir)" != "$(abs_builddir)" ; then \ @if test "$(abs_srcdir)" != "$(abs_builddir)" ; then \
rm -f $(SETUP_FILES) $(expand_content_files) $(DOC_MODULE).types; \ rm -f $(SETUP_FILES) $(DOC_MODULE).types; \
fi fi
maintainer-clean-local: maintainer-clean-local:

View File

@ -145,8 +145,8 @@ im_vips2imask( IMAGE *in, const char *filename )
double *data; double *data;
int x, y; int x, y;
double double_ratio; double double_result;
int int_ratio; int int_result;
/* double* only: cast if necessary. /* double* only: cast if necessary.
*/ */
@ -203,11 +203,11 @@ im_vips2imask( IMAGE *in, const char *filename )
* Imaging an input image where every pixel is 1, what will the output * Imaging an input image where every pixel is 1, what will the output
* be? * be?
*/ */
double_ratio = 0; double_result = 0;
for( y = 0; y < height; y++ ) for( y = 0; y < height; y++ )
for( x = 0; x < width; x++ ) for( x = 0; x < width; x++ )
double_ratio += data[x + width * y]; double_result += data[x + width * y];
double_ratio /= vips_image_get_scale( in ); double_result /= vips_image_get_scale( in );
for( y = 0; y < height; y++ ) for( y = 0; y < height; y++ )
for( x = 0; x < width; x++ ) for( x = 0; x < width; x++ )
@ -222,26 +222,24 @@ im_vips2imask( IMAGE *in, const char *filename )
VIPS_RINT( data[x + y * width] ); VIPS_RINT( data[x + y * width] );
out->scale = VIPS_RINT( vips_image_get_scale( in ) ); out->scale = VIPS_RINT( vips_image_get_scale( in ) );
if( out->scale == 0 )
out->scale = 1;
out->offset = VIPS_RINT( vips_image_get_offset( in ) ); out->offset = VIPS_RINT( vips_image_get_offset( in ) );
/* Now convolve a 1 everywhere image with the int version we've made, /* Now convolve a 1 everywhere image with the int version we've made,
* what do we get? * what do we get?
*/ */
int_ratio = 0; int_result = 0;
for( y = 0; y < height; y++ ) for( y = 0; y < height; y++ )
for( x = 0; x < width; x++ ) for( x = 0; x < width; x++ )
int_ratio += out->coeff[x + width * y]; int_result += out->coeff[x + width * y];
int_ratio /= out->scale; int_result /= out->scale;
/* And adjust the scale to get as close to a match as we can. This /* And adjust the scale to get as close to a match as we can.
* won't work for masks which sum to zero, obviously :-(
*/ */
if( double_ratio != 0.0 ) { out->scale = VIPS_RINT( out->scale + (int_result - double_result) );
out->scale = VIPS_RINT( out->scale * int_ratio / double_ratio ); if( out->scale == 0 )
if( out->scale == 0 ) { out->scale = 1;
out->scale = 1;
}
}
/* We should probably do the same for offset, somehow. /* We should probably do the same for offset, somehow.
*/ */