diff --git a/CMakeLists.txt b/CMakeLists.txt index b8503b9215..146c2e5dde 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -160,7 +160,6 @@ set(KTX_MAIN_SRC lib/ktxint.h lib/memstream.c lib/memstream.h - lib/stream.h lib/strings.c lib/swap.c lib/texture.c diff --git a/include/ktx.h b/include/ktx.h index 950bb94ebe..e9b1a6c794 100644 --- a/include/ktx.h +++ b/include/ktx.h @@ -27,6 +27,7 @@ #include #include +#include /* * Don't use khrplatform.h in order not to break apps existing @@ -202,6 +203,8 @@ typedef enum ktx_error_code_e { */ typedef struct ktxKVListEntry* ktxHashList; +typedef struct ktxStream ktxStream; + #define KTX_APIENTRYP KTX_APIENTRY * /** * @class ktxHashListEntry @@ -477,6 +480,9 @@ typedef KTX_error_code typedef KTX_error_code (KTX_APIENTRY* PFNKTEXWRITETOMEMORY)(ktxTexture* This, ktx_uint8_t** bytes, ktx_size_t* size); +typedef KTX_error_code + (KTX_APIENTRY* PFNKTEXWRITETOSTREAM)(ktxTexture* This, + ktxStream* dststr); /** * @memberof ktxTexture @@ -497,6 +503,7 @@ typedef KTX_error_code PFNKTEXWRITETOSTDIOSTREAM WriteToStdioStream; PFNKTEXWRITETONAMEDFILE WriteToNamedFile; PFNKTEXWRITETOMEMORY WriteToMemory; + PFNKTEXWRITETOSTREAM WriteToStream; }; /**************************************************************** @@ -617,6 +624,14 @@ typedef KTX_error_code #define ktxTexture_WriteToMemory(This, ppDstBytes, pSize) \ (This)->vtbl->WriteToMemory(This, ppDstBytes, pSize) +/** + * @~English + * @brief Helper for calling the WriteToStream virtual method of a ktxTexture. + * @copydoc ktxTexture2_WriteToStream + */ +#define ktxTexture_WriteToStream(This, dststr) \ + (This)->vtbl->WriteToStream(This, dststr) + /** * @class ktxTexture1 @@ -755,13 +770,120 @@ enum ktxTextureCreateFlagBits { */ typedef ktx_uint32_t ktxTextureCreateFlags; +/*===========================================================* +* ktxStream +*===========================================================*/ + +/* + * This is unsigned to allow ktxmemstreams to use the + * full amount of memory available. Platforms will + * limit the size of ktxfilestreams to, e.g, MAX_LONG + * on 32-bit and ktxfilestreams raises errors if + * offset values exceed the limits. This choice may + * need to be revisited if we ever start needing -ve + * offsets. + * + * Should the 2GB file size handling limit on 32-bit + * platforms become a problem, ktxfilestream will have + * to be changed to explicitly handle large files by + * using the 64-bit stream functions. + */ +#if defined(_MSC_VER) && defined(_WIN64) + typedef unsigned __int64 ktx_off_t; +#else + typedef off_t ktx_off_t; +#endif +typedef struct ktxMem ktxMem; +typedef struct ktxStream ktxStream; + +enum streamType { eStreamTypeFile = 1, eStreamTypeMemory = 2, eStreamTypeCustom = 3 }; + +/** + * @~English + * @brief type for a pointer to a stream reading function + */ +typedef KTX_error_code (*ktxStream_read)(ktxStream* str, void* dst, + const ktx_size_t count); +/** + * @~English + * @brief type for a pointer to a stream skipping function + */ +typedef KTX_error_code (*ktxStream_skip)(ktxStream* str, + const ktx_size_t count); + +/** + * @~English + * @brief type for a pointer to a stream reading function + */ +typedef KTX_error_code (*ktxStream_write)(ktxStream* str, const void *src, + const ktx_size_t size, + const ktx_size_t count); + +/** + * @~English + * @brief type for a pointer to a stream position query function + */ +typedef KTX_error_code (*ktxStream_getpos)(ktxStream* str, ktx_off_t* const offset); + +/** + * @~English + * @brief type for a pointer to a stream position query function + */ +typedef KTX_error_code (*ktxStream_setpos)(ktxStream* str, const ktx_off_t offset); + +/** + * @~English + * @brief type for a pointer to a stream size query function + */ +typedef KTX_error_code (*ktxStream_getsize)(ktxStream* str, ktx_size_t* const size); + +/** + * @~English + * @brief Destruct a stream + */ +typedef void (*ktxStream_destruct)(ktxStream* str); + +/** + * @~English + * + * @brief Interface of ktxStream. + * + * @author Maksim Kolesin + * @author Georg Kolling, Imagination Technology + * @author Mark Callow, HI Corporation + */ +struct ktxStream +{ + ktxStream_read read; /*!< @internal pointer to function for reading bytes. */ + ktxStream_skip skip; /*!< @internal pointer to function for skipping bytes. */ + ktxStream_write write; /*!< @internal pointer to function for writing bytes. */ + ktxStream_getpos getpos; /*!< @internal pointer to function for getting current position in stream. */ + ktxStream_setpos setpos; /*!< @internal pointer to function for setting current position in stream. */ + ktxStream_getsize getsize; /*!< @internal pointer to function for querying size. */ + ktxStream_destruct destruct; /*!< @internal destruct the stream. */ + + enum streamType type; + union { + FILE* file; + ktxMem* mem; + struct + { + void* address; + void* allocatorAddress; + ktx_size_t size; + } custom_ptr; + } data; /**< @internal pointer to the stream data. */ + ktx_off_t readpos; /**< @internal used by FileStream for stdin. */ + ktx_bool_t closeOnDestruct; /**< @internal Close FILE* or dispose of memory on destruct. */ +}; + /* * See the implementation files for the full documentation of the following * functions. */ /* - * These three create a ktxTexture1 or ktxTexture2 according to the data + * These four create a ktxTexture1 or ktxTexture2 according to the data * header, and return a pointer to the base ktxTexture class. */ KTX_API KTX_error_code KTX_APIENTRY @@ -779,6 +901,11 @@ ktxTexture_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size, ktxTextureCreateFlags createFlags, ktxTexture** newTex); +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture_CreateFromStream(ktxStream* stream, + ktxTextureCreateFlags createFlags, + ktxTexture** newTex); + /* * Returns a pointer to the image data of a ktxTexture object. */ @@ -824,7 +951,7 @@ ktxTexture1_Create(ktxTextureCreateInfo* createInfo, ktxTexture1** newTex); /* - * These three create a ktxTexture1 provided the data is in KTX format. + * These four create a ktxTexture1 provided the data is in KTX format. */ KTX_API KTX_error_code KTX_APIENTRY ktxTexture1_CreateFromStdioStream(FILE* stdioStream, @@ -841,6 +968,11 @@ ktxTexture1_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size, ktxTextureCreateFlags createFlags, ktxTexture1** newTex); +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_CreateFromStream(ktxStream* stream, + ktxTextureCreateFlags createFlags, + ktxTexture1** newTex); + KTX_API ktx_bool_t KTX_APIENTRY ktxTexture1_NeedsTranscoding(ktxTexture1* This); @@ -863,6 +995,12 @@ KTX_API KTX_error_code KTX_APIENTRY ktxTexture1_WriteKTX2ToMemory(ktxTexture1* This, ktx_uint8_t** bytes, ktx_size_t* size); +/* + * Write a ktxTexture object to a ktxStream in KTX format. + */ +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture1_WriteKTX2ToStream(ktxTexture1* This, ktxStream *dststr); + /* * Create a new ktxTexture2. */ @@ -878,7 +1016,7 @@ KTX_API KTX_error_code KTX_APIENTRY ktxTexture2_CreateCopy(ktxTexture2* orig, ktxTexture2** newTex); /* - * These three create a ktxTexture2 provided the data is in KTX2 format. + * These four create a ktxTexture2 provided the data is in KTX2 format. */ KTX_API KTX_error_code KTX_APIENTRY ktxTexture2_CreateFromStdioStream(FILE* stdioStream, @@ -895,6 +1033,11 @@ ktxTexture2_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size, ktxTextureCreateFlags createFlags, ktxTexture2** newTex); +KTX_API KTX_error_code KTX_APIENTRY +ktxTexture2_CreateFromStream(ktxStream* stream, + ktxTextureCreateFlags createFlags, + ktxTexture2** newTex); + KTX_API KTX_error_code KTX_APIENTRY ktxTexture2_CompressBasis(ktxTexture2* This, ktx_uint32_t quality); diff --git a/lib/filestream.h b/lib/filestream.h index ada5c65334..5c0ea7d2dd 100644 --- a/lib/filestream.h +++ b/lib/filestream.h @@ -15,7 +15,6 @@ #define FILESTREAM_H #include "ktx.h" -#include "stream.h" /* * ktxFileInit: Initialize a ktxStream to a ktxFileStream with a FILE object diff --git a/lib/info.c b/lib/info.c index 071724243b..7a671524c5 100644 --- a/lib/info.c +++ b/lib/info.c @@ -31,7 +31,6 @@ #include #include "dfdutils/dfd.h" -#include "stream.h" #include "filestream.h" #include "memstream.h" #include "ktxint.h" diff --git a/lib/ktxint.h b/lib/ktxint.h index 79811ed2a4..e36ad79b5e 100644 --- a/lib/ktxint.h +++ b/lib/ktxint.h @@ -17,7 +17,6 @@ #define KTXINT_H #include -#include "stream.h" /* Define this to include the ETC unpack software in the library. */ #ifndef SUPPORT_SOFTWARE_ETC_UNPACK diff --git a/lib/libktx.gypi b/lib/libktx.gypi index a5a5a512d5..ff85dc0ff0 100644 --- a/lib/libktx.gypi +++ b/lib/libktx.gypi @@ -88,7 +88,6 @@ 'ktxint.h', 'memstream.c', 'memstream.h', - 'stream.h', 'strings.c', 'swap.c', 'texture.c', diff --git a/lib/memstream.h b/lib/memstream.h index f75fac64fe..4ef8d59cd2 100644 --- a/lib/memstream.h +++ b/lib/memstream.h @@ -22,7 +22,6 @@ #define MEMSTREAM_H #include "ktx.h" -#include "stream.h" /* * Initialize a ktxStream to a ktxMemStream with internally diff --git a/lib/stream.h b/lib/stream.h deleted file mode 100644 index f062247c68..0000000000 --- a/lib/stream.h +++ /dev/null @@ -1,127 +0,0 @@ -/* -*- tab-width: 4; -*- */ -/* vi: set sw=2 ts=4 expandtab: */ - -/* - * Copyright 2010-2020 The Khronos Group Inc. - * SPDX-License-Identifier: Apache-2.0 - */ - -/** - * @internal - * @file - * @~English - * - * @brief Interface of ktxStream. - * - * @author Maksim Kolesin - * @author Georg Kolling, Imagination Technology - * @author Mark Callow, HI Corporation - */ - -#ifndef KTXSTREAM_H -#define KTXSTREAM_H - -#include -#include "ktx.h" - -/* - * This is unsigned to allow ktxmemstreams to use the - * full amount of memory available. Platforms will - * limit the size of ktxfilestreams to, e.g, MAX_LONG - * on 32-bit and ktxfilestreams raises errors if - * offset values exceed the limits. This choice may - * need to be revisited if we ever start needing -ve - * offsets. - * - * Should the 2GB file size handling limit on 32-bit - * platforms become a problem, ktxfilestream will have - * to be changed to explicitly handle large files by - * using the 64-bit stream functions. - */ -#if defined(_MSC_VER) && defined(_WIN64) - typedef unsigned __int64 ktx_off_t; -#else - typedef off_t ktx_off_t; -#endif -typedef struct ktxMem ktxMem; -typedef struct ktxStream ktxStream; - -enum streamType { eStreamTypeFile = 1, eStreamTypeMemory = 2 }; - -/** - * @internal - * @~English - * @brief type for a pointer to a stream reading function - */ -typedef KTX_error_code (*ktxStream_read)(ktxStream* str, void* dst, - const ktx_size_t count); -/** - * @internal - * @~English - * @brief type for a pointer to a stream skipping function - */ -typedef KTX_error_code (*ktxStream_skip)(ktxStream* str, - const ktx_size_t count); - -/** - * @internal - * @~English - * @brief type for a pointer to a stream reading function - */ -typedef KTX_error_code (*ktxStream_write)(ktxStream* str, const void *src, - const ktx_size_t size, - const ktx_size_t count); - -/** - * @internal - * @~English - * @brief type for a pointer to a stream position query function - */ -typedef KTX_error_code (*ktxStream_getpos)(ktxStream* str, ktx_off_t* const offset); - -/** - * @internal - * @~English - * @brief type for a pointer to a stream position query function - */ -typedef KTX_error_code (*ktxStream_setpos)(ktxStream* str, const ktx_off_t offset); - -/** - * @internal - * @~English - * @brief type for a pointer to a stream size query function - */ -typedef KTX_error_code (*ktxStream_getsize)(ktxStream* str, ktx_size_t* const size); - -/** - * @internal - * @~English - * @brief Destruct a stream - */ -typedef void (*ktxStream_destruct)(ktxStream* str); - -/** - * @internal - * @~English - * @brief KTX stream class - */ -struct ktxStream -{ - ktxStream_read read; /*!< @internal pointer to function for reading bytes. */ - ktxStream_skip skip; /*!< @internal pointer to function for skipping bytes. */ - ktxStream_write write; /*!< @internal pointer to function for writing bytes. */ - ktxStream_getpos getpos; /*!< @internal pointer to function for getting current position in stream. */ - ktxStream_setpos setpos; /*!< @internal pointer to function for setting current position in stream. */ - ktxStream_getsize getsize; /*!< @internal pointer to function for querying size. */ - ktxStream_destruct destruct; /*!< @internal destruct the stream. */ - - enum streamType type; - union { - FILE* file; - ktxMem* mem; - } data; /**< @internal pointer to the stream data. */ - ktx_off_t readpos; /**< @internal used by FileStream for stdin. */ - ktx_bool_t closeOnDestruct; /**< @internal Close FILE* or dispose of memory on destruct. */ -}; - -#endif /* KTXSTREAM_H */ diff --git a/lib/texture.c b/lib/texture.c index db32ddc7cc..830095e0cb 100644 --- a/lib/texture.c +++ b/lib/texture.c @@ -32,7 +32,6 @@ #include "ktx.h" #include "ktxint.h" #include "formatsize.h" -#include "stream.h" #include "filestream.h" #include "memstream.h" #include "texture1.h" @@ -200,7 +199,8 @@ ktxTexture_constructFromStream(ktxTexture* This, ktxStream* pStream, assert(This != NULL); assert(pStream->data.mem != NULL); assert(pStream->type == eStreamTypeFile - || pStream->type == eStreamTypeMemory); + || pStream->type == eStreamTypeMemory + || pStream->type == eStreamTypeCustom); This->_protected = (struct ktxTexture_protected *) malloc(sizeof(struct ktxTexture_protected)); @@ -275,7 +275,8 @@ ktxDetermineFileType_(ktxStream* pStream, ktxFileType_* pFileType, assert(pStream != NULL && pFileType != NULL); assert(pStream->data.mem != NULL); assert(pStream->type == eStreamTypeFile - || pStream->type == eStreamTypeMemory); + || pStream->type == eStreamTypeMemory + || pStream->type == eStreamTypeCustom); result = pStream->read(pStream, pHeader, sizeof(ktx2_ident_ref)); if (result == KTX_SUCCESS) { @@ -304,7 +305,7 @@ ktxDetermineFileType_(ktxStream* pStream, ktxFileType_* pFileType, } /** - * @memberof ktxTexture @private + * @memberof ktxTexture * @~English * @brief Construct (initialize) a ktx1 or ktx2 texture according to the stream * data. @@ -312,7 +313,7 @@ ktxDetermineFileType_(ktxStream* pStream, ktxFileType_* pFileType, * @copydetails ktxTexture_CreateFromStdioStream */ KTX_error_code -ktxTexture_createFromStream(ktxStream* pStream, +ktxTexture_CreateFromStream(ktxStream* pStream, ktxTextureCreateFlags createFlags, ktxTexture** newTex) { @@ -375,7 +376,7 @@ ktxTexture_CreateFromStdioStream(FILE* stdioStream, result = ktxFileStream_construct(&stream, stdioStream, KTX_FALSE); if (result == KTX_SUCCESS) { - result = ktxTexture_createFromStream(&stream, createFlags, newTex); + result = ktxTexture_CreateFromStream(&stream, createFlags, newTex); } return result; } @@ -428,7 +429,7 @@ ktxTexture_CreateFromNamedFile(const char* const filename, result = ktxFileStream_construct(&stream, file, KTX_TRUE); if (result == KTX_SUCCESS) { - result = ktxTexture_createFromStream(&stream, createFlags, newTex); + result = ktxTexture_CreateFromStream(&stream, createFlags, newTex); } return result; } @@ -476,7 +477,7 @@ ktxTexture_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size, result = ktxMemStream_construct_ro(&stream, bytes, size); if (result == KTX_SUCCESS) { - result = ktxTexture_createFromStream(&stream, createFlags, newTex); + result = ktxTexture_CreateFromStream(&stream, createFlags, newTex); } return result;} diff --git a/lib/texture.h b/lib/texture.h index eee9c3cf25..e415a09d6a 100644 --- a/lib/texture.h +++ b/lib/texture.h @@ -22,7 +22,6 @@ #include "ktx.h" #include "formatsize.h" -#include "stream.h" #define DECLARE_PRIVATE(class) class ## _private* private = This->_private #define DECLARE_PROTECTED(class) class ## _protected* prtctd = This->_protected; diff --git a/lib/texture1.c b/lib/texture1.c index dc0388c8fc..de7280c105 100644 --- a/lib/texture1.c +++ b/lib/texture1.c @@ -26,7 +26,6 @@ #include "dfdutils/dfd.h" #include "ktx.h" #include "ktxint.h" -#include "stream.h" #include "filestream.h" #include "memstream.h" #include "texture1.h" @@ -780,6 +779,57 @@ ktxTexture1_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size, return result; } +/** + * @memberof ktxTexture1 + * @~English + * @brief Create a ktxTexture1 from KTX-formatted data from a `ktxStream`. + * + * The address of a newly created ktxTexture1 reflecting the contents of the + * serialized KTX data is written to the location pointed at by @p newTex. + * + * The create flag KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT should not be set, + * if the ktxTexture1 is ultimately to be uploaded to OpenGL or Vulkan. This + * will minimize memory usage by allowing, for example, loading the images + * directly from the source into a Vulkan staging buffer. + * + * The create flag KTX_TEXTURE_CREATE_RAW_KVDATA_BIT should not be used. It is + * provided solely to enable implementation of the @e libktx v1 API on top of + * ktxTexture1. + * + * @param[in] stream pointer to the stream to read KTX data from. + * @param[in] createFlags bitmask requesting specific actions during creation. + * @param[in,out] newTex pointer to a location in which store the address of + * the newly created texture. + * + * @return KTX_SUCCESS on success, other KTX_* enum values on error. + * + * @exception KTX_INVALID_VALUE Either @p bytes is NULL or @p size is 0. + * + * For other exceptions, see ktxTexture_CreateFromStdioStream(). + */ +KTX_error_code +ktxTexture1_CreateFromStream(ktxStream* stream, + ktxTextureCreateFlags createFlags, + ktxTexture1** newTex) +{ + KTX_error_code result; + if (newTex == NULL) + return KTX_INVALID_VALUE; + + ktxTexture1* tex = (ktxTexture1*)malloc(sizeof(ktxTexture1)); + if (tex == NULL) + return KTX_OUT_OF_MEMORY; + + result = ktxTexture1_constructFromStream(tex, stream, createFlags); + if (result == KTX_SUCCESS) + *newTex = (ktxTexture1*)tex; + else { + free(tex); + *newTex = NULL; + } + return result; +} + /** * @memberof ktxTexture1 * @~English @@ -1366,6 +1416,15 @@ ktxTexture1_WriteToMemory(ktxTexture1* This, return KTX_INVALID_OPERATION; } +KTX_error_code +ktxTexture1_WriteToStream(ktxTexture1* This, + ktxStream* dststr) +{ + UNUSED(This); + UNUSED(dststr); + return KTX_INVALID_OPERATION; +} + #endif /* @@ -1393,6 +1452,7 @@ struct ktxTexture_vtbl ktxTexture1_vtbl = { (PFNKTEXWRITETOSTDIOSTREAM)ktxTexture1_WriteToStdioStream, (PFNKTEXWRITETONAMEDFILE)ktxTexture1_WriteToNamedFile, (PFNKTEXWRITETOMEMORY)ktxTexture1_WriteToMemory, + (PFNKTEXWRITETOSTREAM)ktxTexture1_WriteToStream, }; /** @} */ diff --git a/lib/texture2.c b/lib/texture2.c index 05bfd38fce..90a80003f5 100644 --- a/lib/texture2.c +++ b/lib/texture2.c @@ -29,7 +29,6 @@ #include "dfdutils/dfd.h" #include "ktx.h" #include "ktxint.h" -#include "stream.h" #include "filestream.h" #include "memstream.h" #include "texture2.h" @@ -1319,6 +1318,57 @@ ktxTexture2_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size, return result; } +/** + * @memberof ktxTexture2 + * @~English + * @brief Create a ktxTexture2 from KTX-formatted data from a stream. + * + * The address of a newly created ktxTexture2 reflecting the contents of the + * serialized KTX data is written to the location pointed at by @p newTex. + * + * The create flag KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT should not be set, + * if the ktxTexture is ultimately to be uploaded to OpenGL or Vulkan. This + * will minimize memory usage by allowing, for example, loading the images + * directly from the source into a Vulkan staging buffer. + * + * The create flag KTX_TEXTURE_CREATE_RAW_KVDATA_BIT should not be used. It is + * provided solely to enable implementation of the @e libktx v1 API on top of + * ktxTexture. + * + * @param[in] stream pointer to the stream to read KTX data from. + * @param[in] createFlags bitmask requesting specific actions during creation. + * @param[in,out] newTex pointer to a location in which store the address of + * the newly created texture. + * + * @return KTX_SUCCESS on success, other KTX_* enum values on error. + * + * @exception KTX_INVALID_VALUE Either @p bytes is NULL or @p size is 0. + * + * For other exceptions, see ktxTexture_CreateFromStdioStream(). + */ +KTX_error_code +ktxTexture2_CreateFromStream(ktxStream* stream, + ktxTextureCreateFlags createFlags, + ktxTexture2** newTex) +{ + KTX_error_code result; + if (newTex == NULL) + return KTX_INVALID_VALUE; + + ktxTexture2* tex = (ktxTexture2*)malloc(sizeof(ktxTexture2)); + if (tex == NULL) + return KTX_OUT_OF_MEMORY; + + result = ktxTexture2_constructFromStream(tex, stream, createFlags); + if (result == KTX_SUCCESS) + *newTex = (ktxTexture2*)tex; + else { + free(tex); + *newTex = NULL; + } + return result; +} + /** * @memberof ktxTexture2 * @~English @@ -2358,6 +2408,15 @@ ktxTexture2_WriteToMemory(ktxTexture2* This, return KTX_INVALID_OPERATION; } +KTX_error_code +ktxTexture2_WriteToStream(ktxTexture2* This, + ktxStream* dststr) +{ + UNUSED(This); + UNUSED(dststr); + return KTX_INVALID_OPERATION; +} + #endif /* @@ -2385,6 +2444,7 @@ struct ktxTexture_vtbl ktxTexture2_vtbl = { (PFNKTEXWRITETOSTDIOSTREAM)ktxTexture2_WriteToStdioStream, (PFNKTEXWRITETONAMEDFILE)ktxTexture2_WriteToNamedFile, (PFNKTEXWRITETOMEMORY)ktxTexture2_WriteToMemory, + (PFNKTEXWRITETOSTREAM)ktxTexture2_WriteToStream, }; /** @} */ diff --git a/lib/texture_funcs.inl b/lib/texture_funcs.inl index f1effc2df8..5de16a396b 100644 --- a/lib/texture_funcs.inl +++ b/lib/texture_funcs.inl @@ -62,6 +62,8 @@ KTX_error_code CLASS_FUNC(WriteToNamedFile)(CLASS* This, const char* const dstname); KTX_error_code CLASS_FUNC(WriteToMemory)(CLASS* This, ktx_uint8_t** ppDstBytes, ktx_size_t* pSize); +KTX_error_code CLASS_FUNC(WriteToStream)(CLASS* This, + ktxStream* dststr); /* ====================================== diff --git a/lib/writer1.c b/lib/writer1.c index 6afae54e65..3c99316db0 100644 --- a/lib/writer1.c +++ b/lib/writer1.c @@ -30,7 +30,6 @@ #include "ktx.h" #include "ktxint.h" -#include "stream.h" #include "filestream.h" #include "memstream.h" #include "texture1.h" @@ -241,7 +240,7 @@ ktxTexture1_SetImageFromMemory(ktxTexture1* This, ktx_uint32_t level, } /** - * @memberof ktxTexture @private + * @memberof ktxTexture * @~English * @brief Write a ktxTexture object to a ktxStream in KTX format. * @@ -261,8 +260,8 @@ ktxTexture1_SetImageFromMemory(ktxTexture1* This, ktx_uint32_t level, * @exception KTX_FILE_WRITE_ERROR * An error occurred while writing the file. */ -static KTX_error_code -ktxTexture1_writeToStream(ktxTexture1* This, ktxStream* dststr) +KTX_error_code +ktxTexture1_WriteToStream(ktxTexture1* This, ktxStream* dststr) { KTX_header header = { .identifier = KTX_IDENTIFIER_REF }; KTX_error_code result = KTX_SUCCESS; @@ -390,7 +389,7 @@ ktxTexture1_WriteToStdioStream(ktxTexture1* This, FILE* dstsstr) if (result != KTX_SUCCESS) return result; - return ktxTexture1_writeToStream(This, &stream); + return ktxTexture1_WriteToStream(This, &stream); } /** @@ -478,7 +477,7 @@ ktxTexture1_WriteToMemory(ktxTexture1* This, if (result != KTX_SUCCESS) return result; - result = ktxTexture1_writeToStream(This, &dststr); + result = ktxTexture1_WriteToStream(This, &dststr); if(result != KTX_SUCCESS) { ktxMemStream_destruct(&dststr); @@ -502,7 +501,7 @@ KTX_error_code appendLibId(ktxHashList* head, ktxHashListEntry* writerEntry); /** - * @memberof ktxTexture @private + * @memberof ktxTexture * @~English * @brief Write a ktxTexture object to a ktxStream in KTX 2 format. * @@ -522,8 +521,8 @@ KTX_error_code appendLibId(ktxHashList* head, * @exception KTX_FILE_WRITE_ERROR * An error occurred while writing the file. */ -static KTX_error_code -ktxTexture1_writeKTX2ToStream(ktxTexture1* This, ktxStream* dststr) +KTX_error_code +ktxTexture1_WriteKTX2ToStream(ktxTexture1* This, ktxStream* dststr) { KTX_header2 header = { .identifier = KTX2_IDENTIFIER_REF }; KTX_error_code result; @@ -827,7 +826,7 @@ ktxTexture1_WriteKTX2ToStdioStream(ktxTexture1* This, FILE* dstsstr) if (result != KTX_SUCCESS) return result; - return ktxTexture1_writeKTX2ToStream(This, &stream); + return ktxTexture1_WriteKTX2ToStream(This, &stream); } /** @@ -937,7 +936,7 @@ ktxTexture1_WriteKTX2ToMemory(ktxTexture1* This, if (result != KTX_SUCCESS) return result; - result = ktxTexture1_writeKTX2ToStream(This, &dststr); + result = ktxTexture1_WriteKTX2ToStream(This, &dststr); if(result != KTX_SUCCESS) { ktxMemStream_destruct(&dststr); diff --git a/lib/writer2.c b/lib/writer2.c index 461a5730ed..e92a4678f7 100644 --- a/lib/writer2.c +++ b/lib/writer2.c @@ -33,7 +33,6 @@ #include "ktx.h" #include "ktxint.h" -#include "stream.h" #include "filestream.h" #include "memstream.h" #include "texture2.h" @@ -245,7 +244,7 @@ ktx_bool_t __disableWriterMetadata__ = KTX_FALSE; #endif /** - * @memberof ktxTexture2 @private + * @memberof ktxTexture2 * @~English * @brief Write a ktxTexture object to a ktxStream in KTX format. * @@ -265,8 +264,8 @@ ktx_bool_t __disableWriterMetadata__ = KTX_FALSE; * @exception KTX_FILE_WRITE_ERROR * An error occurred while writing the file. */ -static KTX_error_code -ktxTexture2_writeToStream(ktxTexture2* This, ktxStream* dststr) +KTX_error_code +ktxTexture2_WriteToStream(ktxTexture2* This, ktxStream* dststr) { DECLARE_PRIVATE(ktxTexture2); KTX_header2 header = { .identifier = KTX2_IDENTIFIER_REF }; @@ -532,7 +531,7 @@ ktxTexture2_WriteToStdioStream(ktxTexture2* This, FILE* dstsstr) if (result != KTX_SUCCESS) return result; - return ktxTexture2_writeToStream(This, &stream); + return ktxTexture2_WriteToStream(This, &stream); } /** @@ -642,7 +641,7 @@ ktxTexture2_WriteToMemory(ktxTexture2* This, if (result != KTX_SUCCESS) return result; - result = ktxTexture2_writeToStream(This, &dststr); + result = ktxTexture2_WriteToStream(This, &dststr); if(result != KTX_SUCCESS) { ktxMemStream_destruct(&dststr);