Movatterモバイル変換


[0]ホーム

URL:


libvips

A fast image processing library with low memory needs.

DownloadInstallDocumentationIssuesWikilibvips projectslibvips on GitHub
Top  | Description  | Object Hierarchy  | Properties  | SignalsHomeUpPrevNext

VipsConnection

VipsConnection — a source/sink of bytes, perhaps a network socket

Stability Level

Stable, unless otherwise indicated

Functions

constchar *vips_connection_filename ()
constchar *vips_connection_nick ()
voidvips_pipe_read_limit_set ()
VipsSource *vips_source_new_from_descriptor ()
VipsSource *vips_source_new_from_file ()
VipsSource *vips_source_new_from_blob ()
VipsSource *vips_source_new_from_target ()
VipsSource *vips_source_new_from_memory ()
VipsSource *vips_source_new_from_options ()
voidvips_source_minimise ()
intvips_source_unminimise ()
intvips_source_decode ()
gint64vips_source_read ()
gbooleanvips_source_is_mappable ()
gbooleanvips_source_is_file ()
constvoid *vips_source_map ()
VipsBlob *vips_source_map_blob ()
gint64vips_source_seek ()
intvips_source_rewind ()
gint64vips_source_sniff_at_most ()
unsignedchar *vips_source_sniff ()
gint64vips_source_length ()
VipsSourceCustom *vips_source_custom_new ()
GInputStream *vips_g_input_stream_new_from_source ()
VipsSourceGInputStream *vips_source_g_input_stream_new ()
VipsTarget *vips_target_new_to_descriptor ()
VipsTarget *vips_target_new_to_file ()
VipsTarget *vips_target_new_to_memory ()
VipsTarget *vips_target_new_temp ()
intvips_target_write ()
gint64vips_target_read ()
gint64vips_target_seek ()
intvips_target_end ()
unsignedchar *vips_target_steal ()
char *vips_target_steal_text ()
intvips_target_putc ()
#defineVIPS_TARGET_PUTC()
intvips_target_writes ()
intvips_target_writef ()
intvips_target_write_amp ()
VipsTargetCustom *vips_target_custom_new ()

Properties

intdescriptorRead / Write
char *filenameRead / Write
VipsBlob *blobRead / Write
VipsBlob *blobRead / Write
gbooleanmemoryRead / Write

Signals

gint64readAction
gint64seekAction
intendAction
voidfinishAction
gint64readAction
gint64seekAction
gint64writeAction

Types and Values

 VipsSourceGInputStream
 VipsSourceGInputStreamClass
#defineVIPS_TARGET_BUFFER_SIZE
#defineVIPS_TARGET_CUSTOM_BUFFER_SIZE

Object Hierarchy

    GObject├── GInputStream╰── VipsGInputStream╰──VipsObject╰── VipsConnection├── VipsSource╰── VipsSourceCustom╰── VipsTarget╰── VipsTargetCustom

Includes

#include <vips/vips.h>

Description

AVipsConnection is a source or sink of bytes for something like jpegloading, see for examplevips_jpegload_source().

It can be connected to a network socket, for example, or perhapsa node.js stream, or to an area of memory.

Subclass to add other input sources. UseVipsSourceCustom andVipsTargetCustom to make a source or target with action signals for::read, ::write and ::seek.

Functions

vips_connection_filename ()

constchar *vips_connection_filename (VipsConnection *connection);

Parameters

connection

connection to operate on

 

Returns

any filename associated with this connection, or NULL.


vips_connection_nick ()

constchar *vips_connection_nick (VipsConnection *connection);

Parameters

connection

connection to operate on

 

Returns

a string describing this connection which could be displayed to auser.


vips_pipe_read_limit_set ()

voidvips_pipe_read_limit_set (gint64 limit);

If a source does not support mmap or seek and the source isused with a loader that can only work from memory, then the data will beautomatically read into memory to EOF before the loader starts. This canproduce high memory use if the descriptor represents a large object.

Usevips_pipe_read_limit_set() to limit the size of object thatwill be read in this way. The default is 1GB.

Set a value of -1 to mean no limit.

See also:--vips-pipe-read-limit and the environment variableVIPS_PIPE_READ_LIMIT.

Parameters

limit

maximum number of bytes to buffer from a pipe

 

vips_source_new_from_descriptor ()

VipsSource *vips_source_new_from_descriptor (int descriptor);

Create an source attached to a file descriptor.descriptor isclosed withclose() when source is finalized.

Parameters

descriptor

read from this file descriptor

 

Returns

a new source.


vips_source_new_from_file ()

VipsSource *vips_source_new_from_file (constchar *filename);

Create an source attached to a file.

If this descriptor does not support mmap and the source isused with a loader that can only work from memory, then the data will beautomatically read into memory to EOF before the loader starts. This canproduce high memory use if the descriptor represents a large object.

Usevips_pipe_read_limit_set() to limit the size of object thatwill be read in this way. The default is 1GB.

Parameters

descriptor

read from this filename

 

Returns

a new source.


vips_source_new_from_blob ()

VipsSource *vips_source_new_from_blob (VipsBlob *blob);

Create a source attached to an area of memory.

Parameters

blob

memory area to load

 

Returns

a new source.


vips_source_new_from_target ()

VipsSource *vips_source_new_from_target (VipsTarget *target);

Create a source from a temp target that has been written to.

Parameters

target

build the source from this target

 

Returns

a new source.


vips_source_new_from_memory ()

VipsSource *vips_source_new_from_memory (constvoid *data,size_t size);

Create a source attached to an area of memory.

You must not freedata while the source is active.

Parameters

data

memory area to load

 

length

size of memory area

 

Returns

a new source.


vips_source_new_from_options ()

VipsSource *vips_source_new_from_options (constchar *options);

Create a source from an option string.

Parameters

options

option string

 

Returns

a new source.


vips_source_minimise ()

voidvips_source_minimise (VipsSource *source);

Minimise the source. As many resources as can be safely removed areremoved. Usevips_source_unminimise() to restore the source if you wish touse it again.

Loaders should call this in response to the minimise signal on their outputimage.

Parameters

source

source to operate on

 

vips_source_unminimise ()

intvips_source_unminimise (VipsSource *source);

Restore the source after minimisation. This is called at the startof every source method, so loaders should not usually need this.

See also:vips_source_minimise().

Parameters

source

source to operate on

 

Returns

0 on success, or -1 on error.


vips_source_decode ()

intvips_source_decode (VipsSource *source);

Signal the end of header read and the start of the pixel decode phase.After this, you can no longer seek on this source.

Loaders should call this at the end of header read.

See also:vips_source_unminimise().

Parameters

source

source to operate on

 

Returns

0 on success, -1 on error.


vips_source_read ()

gint64vips_source_read (VipsSource *source,void *data,size_t length);

Read up tolength bytes fromsource and store the bytes inbuffer.Return the number of bytes actually read. If all bytes have been read fromthe file, return 0.

Arguments exactly as read(2).

Parameters

source

source to operate on

 

buffer

store bytes here

 

length

length ofbufferin bytes

 

Returns

the number of bytes read, 0 on end of file, -1 on error.


vips_source_is_mappable ()

gbooleanvips_source_is_mappable (VipsSource *source);

Some sources can be efficiently mapped into memory.You can still usevips_source_map() if this function returnsFALSE,but it will be slow.

Parameters

source

source to operate on

 

Returns

TRUE if the source can be efficiently mapped into memory.


vips_source_is_file ()

gbooleanvips_source_is_file (VipsSource *source);

Test if this source is a simple file with support for seek. Named pipes,for example, will fail this test. If TRUE, you can usevips_connection_filename() to find the filename.

Use this to add basic source support for older loaders which can only workon files.

Parameters

source

source to operate on

 

Returns

TRUE if the source is a simple file.


vips_source_map ()

constvoid *vips_source_map (VipsSource *source,size_t *length);

Map the source entirely into memory and return a pointer to thestart. Iflength_out is non-NULL, the source size is written to it.

This operation can take a long time. Usevips_source_is_mappable() tocheck if a source can be mapped efficiently.

The pointer is valid for as long assource is alive.

Parameters

source

source to operate on

 

length_out

return the file length here, or NULL

 

Returns

a pointer to the start of the file contents, or NULL on error.


vips_source_map_blob ()

VipsBlob *vips_source_map_blob (VipsSource *source);

Just likevips_source_map(), but return aVipsBlob containing thepointer.source will stay alive as long as the result is alive.

Parameters

source

source to operate on

 

Returns

a newVipsBlob containing the data, or NULL on error.


vips_source_seek ()

gint64vips_source_seek (VipsSource *source,gint64 offset,int whence);

Move the file read position. You can't call this after pixel decode starts.The arguments are exactly as lseek(2).

Parameters

source

source to operate on

 

offset

seek by this offset

 

whence

seek relative to this point

 

Returns

the new file position, or -1 on error.


vips_source_rewind ()

intvips_source_rewind (VipsSource *source);

Rewind the source to the start.

You can't always do this after the pixel decode phase starts -- forexample, pipe-like sources can't be rewound.

Parameters

source

source to operate on

 

Returns

0 on success, or -1 on error.


vips_source_sniff_at_most ()

gint64vips_source_sniff_at_most (VipsSource *source,unsignedchar **data,size_t length);

Attempt to sniff at mostlength bytes from the start of the source. Apointer to the bytes is returned indata. The number of bytes actuallyread is returned -- it may be less thanlength if the file is shorter thanlength. A negative number indicates a read error.

Parameters

source

peek this source

 

data

return a pointer to the bytes read here

 

length

max number of bytes to read

 

Returns

number of bytes read, or -1 on error.


vips_source_sniff ()

unsignedchar *vips_source_sniff (VipsSource *source,size_t length);

Return a pointer to the first few bytes of the file. If the file is tooshort, return NULL.

Parameters

source

sniff this source

 

length

number of bytes to sniff

 

Returns

a pointer to the bytes at the start of the file, or NULL on error.


vips_source_length ()

gint64vips_source_length (VipsSource *source);

Return the length in bytes of the source. Unseekable sources, forexample pipes, will have to be read entirely into memory before the lengthcan be found, so this operation can take a long time.

Parameters

source

source to operate on

 

Returns

number of bytes in source, or -1 on error.


vips_source_custom_new ()

VipsSourceCustom *vips_source_custom_new (void);

Create aVipsSourceCustom. Attach signals to implement read and seek.

Returns

a newVipsSourceCustom


vips_g_input_stream_new_from_source ()

GInputStream *vips_g_input_stream_new_from_source (VipsSource *source);

Create a newGInputStream wrapping aVipsSource. This is useful forloaders like SVG and PDF which support GInput methods.

Parameters

source

vips source to wrap

 

Returns

a newGInputStream


vips_source_g_input_stream_new ()

VipsSourceGInputStream *vips_source_g_input_stream_new (GInputStream *stream);

Create aVipsSourceGInputStream which wrapsstream.

Parameters

stream

read from this stream

 

Returns

the new source.


vips_target_new_to_descriptor ()

VipsTarget *vips_target_new_to_descriptor (int descriptor);

Create a target attached to a file descriptor.descriptor is kept open until the target is finalized.

See also:vips_target_new_to_file().

Parameters

descriptor

write to this file descriptor

 

Returns

a new target.


vips_target_new_to_file ()

VipsTarget *vips_target_new_to_file (constchar *filename);

Create a target attached to a file.

Parameters

filename

write to this file

 

Returns

a new target.


vips_target_new_to_memory ()

VipsTarget *vips_target_new_to_memory (void);

Create a target which will write to a memory area. Read fromblob to getmemory.

See also:vips_target_new_to_file().

Returns

a newVipsConnection


vips_target_new_temp ()

VipsTarget *vips_target_new_temp (VipsTarget *target);

Create a temporary target -- either a temporary file on disc, or an area inmemory, depending on what sort of targetbased_on is.

See also:vips_target_new_to_file().

Parameters

based_on

base the temporary target on this target

 

Returns

a new target.


vips_target_write ()

intvips_target_write (VipsTarget *target,constvoid *data,size_t length);

Writelength bytes frombuffer to the output.

Parameters

target

target to operate on

 

buffer

bytes to write

 

length

length ofbufferin bytes

 

Returns

0 on success, -1 on error.


vips_target_read ()

gint64vips_target_read (VipsTarget *target,void *buffer,size_t length);

Read up tolength bytes fromtarget and store the bytes inbuffer.Return the number of bytes actually read. If all bytes have been read fromthe file, return 0.

Arguments exactly as read(2).

Reading from a target sounds weird, but libtiff needs this formulti-page writes. This method will fail for targets like pipes.

Parameters

target

target to operate on

 

buffer

store bytes here

 

length

length ofbufferin bytes

 

Returns

the number of bytes read, 0 on end of file, -1 on error.


vips_target_seek ()

gint64vips_target_seek (VipsTarget *target,gint64 offset,int whence);

Seek the target. This behaves exactly as lseek(2).

Seeking a target sounds weird, but libtiff needs this. This method willfail for targets like pipes.

Parameters

target

target to operate on

 

position

position to seek to

 

whence

seek relative to beginning, offset, or end

 

Returns

the new seek position, -1 on error.


vips_target_end ()

intvips_target_end (VipsTarget *target);

Call this at the end of write to make the target do any cleaning up. Youcan call it many times.

After a target has been ended, further writes will do nothing.

Parameters

target

target to operate on

 

buffer

bytes to write

 

length

length ofbufferin bytes

 

Returns

0 on success, -1 on error.


vips_target_steal ()

unsignedchar *vips_target_steal (VipsTarget *target,size_t *length);

Memory targets only (seevips_target_new_to_memory()). Steal all datawritten to the target so far, and callvips_target_end().

You must free the returned pointer withg_free().

The data is NOT automatically null-terminated.vips_target_putc() a '\0'before calling this to get a null-terminated string.

You can't call this aftervips_target_end(), since that moves the data to ablob, and we can't steal from that in case the pointer has been be shared.

You can't call this function more than once.

Parameters

target

target to operate on

 

length

return number of bytes of data

 

Returns

thedata.

[array length=length][element-type guint8][transfer full]


vips_target_steal_text ()

char *vips_target_steal_text (VipsTarget *target);

Asvips_target_steal_text(), but return a null-terminated string.

Parameters

target

target to operate on

 

Returns

target contents as a null-terminated string.

[transfer full]


vips_target_putc ()

intvips_target_putc (VipsTarget *target,int ch);

Write a single characterch totarget. See the macroVIPS_TARGET_PUTC()for a faster way to do this.

Parameters

target

target to operate on

 

ch

character to write

 

Returns

0 on success, -1 on error.


VIPS_TARGET_PUTC()

#define             VIPS_TARGET_PUTC(S, C)

vips_target_writes ()

intvips_target_writes (VipsTarget *target,constchar *str);

Write a null-terminated string totarget.

Parameters

target

target to operate on

 

str

string to write

 

Returns

0 on success, and -1 on error.


vips_target_writef ()

intvips_target_writef (VipsTarget *target,constchar *fmt,...);

Format the string and write totarget.

Parameters

target

target to operate on

 

fmt

printf()-style format string

 

...

arguments to format string

 

Returns

0 on success, and -1 on error.


vips_target_write_amp ()

intvips_target_write_amp (VipsTarget *target,constchar *str);

Writestr totarget, but escape stuff that xml hates in text. Ourargument string is utf-8.

XML rules:

  • We must escape &<>

  • Don't escape \n, \t, \r

  • Do escape the other ASCII codes.

Parameters

target

target to operate on

 

str

string to write

 

Returns

0 on success, -1 on error.


vips_target_custom_new ()

VipsTargetCustom *vips_target_custom_new (void);

Create aVipsTargetCustom. Attach signals to implement write and finish.

Returns

a newVipsTargetCustom

Types and Values

VipsSourceGInputStream

typedef struct {VipsSource parent_instance;} VipsSourceGInputStream;

VipsSourceGInputStreamClass

typedef struct {VipsSourceClass parent_class;} VipsSourceGInputStreamClass;

VIPS_TARGET_BUFFER_SIZE

#define VIPS_TARGET_BUFFER_SIZE (8500)

VIPS_TARGET_CUSTOM_BUFFER_SIZE

#define VIPS_TARGET_CUSTOM_BUFFER_SIZE (4096)

Property Details

The“descriptor” property

  “descriptor”int

File descriptor for read or write.

Owner: VipsConnection

Flags: Read / Write

Allowed values: [-1,1000000000]

Default value: 0


The“filename” property

  “filename”char *

Name of file to open.

Owner: VipsConnection

Flags: Read / Write

Default value: NULL


The“blob” property

  “blob”VipsBlob *

Blob to load from.

Owner: VipsSource

Flags: Read / Write


The“blob” property

  “blob”VipsBlob *

Blob to save to.

Owner: VipsTarget

Flags: Read / Write


The“memory” property

  “memory”gboolean

File descriptor should output to memory.

Owner: VipsTarget

Flags: Read / Write

Default value: FALSE

Signal Details

The“read” signal

gint64user_function (VipsSourceCustom *source_custom,gpointer          buffer,gint64            size,gpointer          user_data)

This signal is emitted to read bytes from the source intobuffer.

Parameters

source_custom

the source being operated on

 

buffer

gpointer, buffer to fill

 

size

gint64, size of buffer

 

user_data

user data set when the signal handler was connected.

 

Returns

the number of bytes read. Return 0 for EOF.

Flags: Action


The“seek” signal

gint64user_function (VipsSourceCustom *source_custom,gint64            offset,int               whence,gpointer          user_data)

This signal is emitted to seek the source. The handler shouldchange the source position appropriately.

The handler for an unseekable source should always return -1.

Parameters

source_custom

the source being operated on

 

offset

gint64, seek offset

 

whence

gint, seek origin

 

user_data

user data set when the signal handler was connected.

 

Returns

the new seek position.

Flags: Action


The“end” signal

intuser_function (VipsTargetCustom *target_custom,gpointer          user_data)

This signal is emitted at the end of write. The target should doany finishing necessary.

Parameters

target_custom

the target being operated on

 

user_data

user data set when the signal handler was connected.

 

Returns

0 on success, -1 on error.

Flags: Action


The“finish” signal

voiduser_function (VipsTargetCustom *target_custom,gpointer          user_data)

Deprecated for VipsTargetCustom::end.

Parameters

target_custom

the target being operated on

 

user_data

user data set when the signal handler was connected.

 

Flags: Action


The“read” signal

gint64user_function (VipsTargetCustom *target_custom,gpointer          buffer,gint64            size,gpointer          user_data)

This signal is emitted to read bytes from the target intobuffer.

The handler for an unreadable target should always return -1.

Parameters

target_custom

the target being operated on

 

buffer

gpointer, buffer to fill

 

size

gint64, size of buffer

 

user_data

user data set when the signal handler was connected.

 

Returns

the number of bytes read. Return 0 for EOF.

Flags: Action


The“seek” signal

gint64user_function (VipsTargetCustom *target_custom,gint64            offset,int               whence,gpointer          user_data)

This signal is emitted to seek the target. The handler shouldchange the target position appropriately.

The handler for an unseekable target should always return -1.

Parameters

target_custom

the target being operated on

 

offset

gint64, seek offset

 

whence

gint, seek origin

 

user_data

user data set when the signal handler was connected.

 

Returns

the new seek position.

Flags: Action


The“write” signal

gint64user_function (VipsTargetCustom *target_custom,gpointer          data,gint64            length,gpointer          user_data)

This signal is emitted to write bytes to the target.

Parameters

target_custom

the target being operated on

 

data

pointer, bytes to write

 

length

gint64, number of bytes

 

user_data

user data set when the signal handler was connected.

 

Returns

the number of bytes written.

Flags: Action

See Also

foreign

Generated by GTK-Doc V1.34.0

[8]ページ先頭

©2009-2025 Movatter.jp