add vips_image_new_from_memory_copy()
takes a copy of a memory area when making an image ... this helps bindings for languages which don't have much control over memory see https://github.com/jcupitt/libvips/issues/346
This commit is contained in:
parent
6573af3c2a
commit
2409767679
|
@ -15,6 +15,7 @@
|
||||||
- try to improve vips_resize() quality a little more
|
- try to improve vips_resize() quality a little more
|
||||||
- vips_resize() can do non-square resizes
|
- vips_resize() can do non-square resizes
|
||||||
- dzsave removes tile metadata by default, thanks Benjamin
|
- dzsave removes tile metadata by default, thanks Benjamin
|
||||||
|
- added vips_image_new_from_memory_copy()
|
||||||
|
|
||||||
7/5/15 started 8.1.1
|
7/5/15 started 8.1.1
|
||||||
- oop, vips-8.0 wrapper script should be vips-8.1, thanks Danilo
|
- oop, vips-8.0 wrapper script should be vips-8.1, thanks Danilo
|
||||||
|
|
|
@ -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:
|
||||||
|
|
|
@ -429,6 +429,8 @@ VipsImage *vips_image_new_from_file_raw( const char *filename,
|
||||||
int xsize, int ysize, int bands, guint64 offset );
|
int xsize, int ysize, int bands, guint64 offset );
|
||||||
VipsImage *vips_image_new_from_memory( const void *data, size_t size,
|
VipsImage *vips_image_new_from_memory( const void *data, size_t size,
|
||||||
int width, int height, int bands, VipsBandFormat format );
|
int width, int height, int bands, VipsBandFormat format );
|
||||||
|
VipsImage *vips_image_new_from_memory_copy( const void *data, size_t size,
|
||||||
|
int width, int height, int bands, VipsBandFormat format );
|
||||||
VipsImage *vips_image_new_from_buffer( const void *buf, size_t len,
|
VipsImage *vips_image_new_from_buffer( const void *buf, size_t len,
|
||||||
const char *option_string, ... )
|
const char *option_string, ... )
|
||||||
__attribute__((sentinel));
|
__attribute__((sentinel));
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
* - vips_image_write() didn't ref non-partial sources
|
* - vips_image_write() didn't ref non-partial sources
|
||||||
* 18/4/15
|
* 18/4/15
|
||||||
* - add vips_image_copy_memory()
|
* - add vips_image_copy_memory()
|
||||||
|
* 25/11/15
|
||||||
|
* - add vips_image_new_from_memory_copy()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1979,9 +1981,15 @@ vips_image_new_from_file_raw( const char *filename,
|
||||||
* responsibility for the area of memory, it's up to you to make sure it's
|
* responsibility for the area of memory, it's up to you to make sure it's
|
||||||
* freed when the image is closed. See for example #VipsObject::close.
|
* freed when the image is closed. See for example #VipsObject::close.
|
||||||
*
|
*
|
||||||
|
* Because VIPS is "borrowing" @data from the caller, this function is
|
||||||
|
* extremely dangerous. Unless you are very careful, you will get crashes or
|
||||||
|
* memory corruption. Use vips_image_new_from_memory_copy() instead if you are
|
||||||
|
* at all unsure.
|
||||||
|
*
|
||||||
* Use vips_copy() to set other image properties.
|
* Use vips_copy() to set other image properties.
|
||||||
*
|
*
|
||||||
* See also: vips_image_new(), vips_image_write_to_memory().
|
* See also: vips_image_new(), vips_image_write_to_memory(),
|
||||||
|
* vips_image_new_from_memory_copy().
|
||||||
*
|
*
|
||||||
* Returns: (transfer full): the new #VipsImage, or %NULL on error.
|
* Returns: (transfer full): the new #VipsImage, or %NULL on error.
|
||||||
*/
|
*/
|
||||||
|
@ -2014,7 +2022,7 @@ vips_image_new_from_memory( const void *data, size_t size,
|
||||||
if( size > 0 &&
|
if( size > 0 &&
|
||||||
size < VIPS_IMAGE_SIZEOF_IMAGE( image ) ) {
|
size < VIPS_IMAGE_SIZEOF_IMAGE( image ) ) {
|
||||||
vips_error( "VipsImage",
|
vips_error( "VipsImage",
|
||||||
_( "buffer too small --- "
|
_( "memory area too small --- "
|
||||||
"should be %zd bytes, you passed %zd" ),
|
"should be %zd bytes, you passed %zd" ),
|
||||||
VIPS_IMAGE_SIZEOF_IMAGE( image ), size );
|
VIPS_IMAGE_SIZEOF_IMAGE( image ), size );
|
||||||
VIPS_UNREF( image );
|
VIPS_UNREF( image );
|
||||||
|
@ -2024,6 +2032,54 @@ vips_image_new_from_memory( const void *data, size_t size,
|
||||||
return( image );
|
return( image );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
vips_image_new_from_memory_copy_cb( VipsImage *image, void *data_copy )
|
||||||
|
{
|
||||||
|
vips_tracked_free( data_copy );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* vips_image_new_from_memory_copy:
|
||||||
|
* @data: (array length=size) (element-type guint8) (transfer none): start of memory area
|
||||||
|
* @size: length of memory area
|
||||||
|
* @width: image width
|
||||||
|
* @height: image height
|
||||||
|
* @bands: image bands (or bytes per pixel)
|
||||||
|
* @format: image format
|
||||||
|
*
|
||||||
|
* Like vips_image_new_from_memory(), but VIPS will make a copy of the memory
|
||||||
|
* area. This
|
||||||
|
* means more memory use and an extra copy operation, but is much simpler and
|
||||||
|
* safer.
|
||||||
|
*
|
||||||
|
* See also: vips_image_new_from_memory().
|
||||||
|
*
|
||||||
|
* Returns: (transfer full): the new #VipsImage, or %NULL on error.
|
||||||
|
*/
|
||||||
|
VipsImage *
|
||||||
|
vips_image_new_from_memory_copy( const void *data, size_t size,
|
||||||
|
int width, int height, int bands, VipsBandFormat format )
|
||||||
|
{
|
||||||
|
void *data_copy;
|
||||||
|
VipsImage *image;
|
||||||
|
|
||||||
|
vips_check_init();
|
||||||
|
|
||||||
|
if( !(data_copy = vips_tracked_malloc( size )) )
|
||||||
|
return( NULL );
|
||||||
|
memcpy( data_copy, data, size );
|
||||||
|
if( !(image = vips_image_new_from_memory( data_copy, size,
|
||||||
|
width, height, bands, format )) ) {
|
||||||
|
vips_tracked_free( data_copy );
|
||||||
|
return( NULL );
|
||||||
|
}
|
||||||
|
|
||||||
|
g_signal_connect( image, "close",
|
||||||
|
G_CALLBACK( vips_image_new_from_memory_copy_cb ), data_copy );
|
||||||
|
|
||||||
|
return( image );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* vips_image_new_from_buffer:
|
* vips_image_new_from_buffer:
|
||||||
* @buf: (array length=len) (element-type guint8) (transfer none): image data
|
* @buf: (array length=len) (element-type guint8) (transfer none): image data
|
||||||
|
|
Loading…
Reference in New Issue