libktx Reference 4.3.2
Libraries and tools to create and read KTX image texture files.
Loading...
Searching...
No Matches
memstream.c File Reference

Implementation of ktxStream for memory. More...

#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include "ktx.h"
#include "ktxint.h"
#include "memstream.h"

Macros

#define KTX_MEM_DEFAULT_ALLOCATED_SIZE   256
 Default allocation size for a ktxMemStream.
 

Functions

KTX_error_code ktxMemStream_getdata (ktxStream *str, ktx_uint8_t **ppBytes)
 Get a pointer to a ktxMemStream's data.
 
void ktxMemStream_setup (ktxStream *str)
 Setup ktxMemStream function pointers.
 
KTX_error_code ktxMemStream_construct (ktxStream *str, ktx_bool_t freeOnDestruct)
 Initialize a read-write ktxMemStream.
 
KTX_error_code ktxMemStream_construct_ro (ktxStream *str, const ktx_uint8_t *bytes, const ktx_size_t numBytes)
 Initialize a read-only ktxMemStream.
 
void ktxMemStream_destruct (ktxStream *str)
 Free the memory used by a ktxMemStream.
 

Detailed Description

Implementation of ktxStream for memory.

Author
Maksim Kolesin, Under Development
Georg Kolling, Imagination Technology
Mark Callow, HI Corporation

Function Documentation

◆ ktxMemStream_construct()

KTX_error_code ktxMemStream_construct ( ktxStream str,
ktx_bool_t  freeOnDestruct 
)

Initialize a read-write ktxMemStream.

Memory is allocated as data is written. The caller of this is responsible for freeing this memory unless freeOnDestruct is not KTX_FALSE.

Parameters
[in]strpointer to a ktxStream struct to initialize.
[in]freeOnDestructIf not KTX_FALSE memory holding the data will be freed by the destructor.
Returns
KTX_SUCCESS on success, other KTX_* enum values on error.
Exceptions
KTX_INVALID_VALUEstr is NULL.
KTX_OUT_OF_MEMORYsystem failed to allocate sufficient memory.

◆ ktxMemStream_construct_ro()

KTX_error_code ktxMemStream_construct_ro ( ktxStream str,
const ktx_uint8_t *  bytes,
const ktx_size_t  numBytes 
)

Initialize a read-only ktxMemStream.

Parameters
[in]strpointer to a ktxStream struct to initialize.
[in]bytespointer to an array of bytes containing the data.
[in]numBytessize of array of data for ktxMemStream.
Returns
KTX_SUCCESS on success, other KTX_* enum values on error.
Exceptions
KTX_INVALID_VALUEstr or mem is NULL or numBytes is 0. or size is less than 0.
KTX_OUT_OF_MEMORYsystem failed to allocate sufficient memory.

◆ ktxMemStream_destruct()

void ktxMemStream_destruct ( ktxStream str)

Free the memory used by a ktxMemStream.

This only frees the memory used to store the data written to the stream, if the freeOnDestruct parameter to ktxMemStream_construct() was not KTX_FALSE. Otherwise it is the responsibility of the caller of ktxMemStream_construct() and a pointer to this memory should be retrieved using ktxMemStream_getdata() before calling this function.

See also
ktxMemStream_construct, ktxMemStream_getdata.
Parameters
[in]strpointer to the ktxStream whose memory is to be freed.

◆ ktxMemStream_getdata()

KTX_error_code ktxMemStream_getdata ( ktxStream str,
ktx_uint8_t **  ppBytes 
)

Get a pointer to a ktxMemStream's data.

Gets a pointer to data that has been written to the stream. Returned pointer will be 0 if stream is read-only.

Parameters
[in]strpointer to the ktxStream whose data pointer is to be queried.
[in,out]ppBytespointer to a variable in which the data pointer will be written.
Returns
KTX_SUCCESS on success, other KTX_* enum values on error.
Exceptions
KTX_INVALID_VALUEstr or ppBytes is NULL.