buffer load/save in python works
This commit is contained in:
parent
8a976a1e73
commit
eca5ed12de
12
TODO
12
TODO
@ -1,9 +1,17 @@
|
||||
|
||||
- python:
|
||||
|
||||
- turns blobs into strings on return with .get()
|
||||
- new_from_memory() needs length as well as data so we can pass it a
|
||||
string
|
||||
|
||||
- do write_to_memory as well
|
||||
|
||||
- something to make a mask from a list of lists
|
||||
|
||||
- set scale and offset on masko
|
||||
|
||||
- how about the in-place things? draw a circle?
|
||||
|
||||
finish get_value
|
||||
|
||||
- add more constructors
|
||||
|
||||
|
@ -582,24 +582,26 @@ vips_foreign_find_load_buffer_sub( VipsForeignLoadClass *load_class,
|
||||
|
||||
/**
|
||||
* vips_foreign_find_load_buffer:
|
||||
* @buf: start of memory buffer
|
||||
* @len: length of memory buffer
|
||||
* @data: (array length=size) (element-type guint8) (transfer none): start of
|
||||
* memory buffer
|
||||
* @size: number of bytes in @data
|
||||
*
|
||||
* Searches for an operation you could use to load a memory buffer.
|
||||
*
|
||||
* See also: vips_image_new_from_buffer().
|
||||
*
|
||||
* Returns: the name of an operation on success, %NULL on error
|
||||
* Returns: (transfer none): the name of an operation on success, %NULL on
|
||||
* error.
|
||||
*/
|
||||
const char *
|
||||
vips_foreign_find_load_buffer( void *buf, size_t len )
|
||||
vips_foreign_find_load_buffer( void *data, size_t size )
|
||||
{
|
||||
VipsForeignLoadClass *load_class;
|
||||
|
||||
if( !(load_class = (VipsForeignLoadClass *) vips_foreign_map(
|
||||
"VipsForeignLoad",
|
||||
(VipsSListMap2Fn) vips_foreign_find_load_buffer_sub,
|
||||
&buf, &len )) ) {
|
||||
&data, &size )) ) {
|
||||
vips_error( "VipsForeignLoad",
|
||||
"%s", _( "buffer is not in a known format" ) );
|
||||
return( NULL );
|
||||
|
@ -214,7 +214,7 @@ typedef struct _VipsForeignLoadClass {
|
||||
GType vips_foreign_load_get_type( void );
|
||||
|
||||
const char *vips_foreign_find_load( const char *filename );
|
||||
const char *vips_foreign_find_load_buffer( void *buf, size_t len );
|
||||
const char *vips_foreign_find_load_buffer( void *data, size_t size );
|
||||
|
||||
VipsForeignFlags vips_foreign_flags( const char *loader, const char *filename );
|
||||
gboolean vips_foreign_is_a( const char *loader, const char *filename );
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
import sys
|
||||
|
||||
import logging
|
||||
logging.basicConfig(level = logging.DEBUG)
|
||||
#import logging
|
||||
#logging.basicConfig(level = logging.DEBUG)
|
||||
|
||||
from gi.repository import Vips
|
||||
from vips8 import vips
|
||||
@ -11,3 +11,5 @@ from vips8 import vips
|
||||
a = Vips.Image.new_from_file(sys.argv[1])
|
||||
|
||||
b = a.write_to_buffer(".jpg")
|
||||
|
||||
c = Vips.Image.new_from_buffer(b, "")
|
||||
|
@ -211,6 +211,15 @@ def vips_image_new_from_file(cls, vips_filename, **kwargs):
|
||||
|
||||
return _call_base(loader, [filename], kwargs, None, option_string)
|
||||
|
||||
# this is a class method
|
||||
def vips_image_new_from_buffer(cls, data, option_string, **kwargs):
|
||||
loader = Vips.Foreign.find_load_buffer(data)
|
||||
if loader == None:
|
||||
raise Error('No known loader for buffer.')
|
||||
logging.debug('Image.new_from_buffer: loader = %s' % loader)
|
||||
|
||||
return _call_base(loader, [data], kwargs, None, option_string)
|
||||
|
||||
def vips_image_getattr(self, name):
|
||||
logging.debug('Image.__getattr__ %s' % name)
|
||||
|
||||
@ -352,6 +361,7 @@ def vips_invert(self):
|
||||
|
||||
# class methods
|
||||
setattr(Vips.Image, 'new_from_file', classmethod(vips_image_new_from_file))
|
||||
setattr(Vips.Image, 'new_from_buffer', classmethod(vips_image_new_from_buffer))
|
||||
|
||||
# instance methods
|
||||
Vips.Image.write_to_file = vips_image_write_to_file
|
||||
|
Loading…
Reference in New Issue
Block a user