Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libktx: update ktxTexture2_setImageFromStream to allow setting the entire level's data in one call #794

Merged
merged 1 commit into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/ktx.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* @snippet{doc} version.h API version
*/

#include <limits.h>
#include <stdio.h>
#include <stdbool.h>
#include <sys/types.h>
Expand Down Expand Up @@ -156,6 +157,7 @@ extern "C" {
* @brief Required unpack alignment
*/
#define KTX_GL_UNPACK_ALIGNMENT 4
#define KTX_FACESLICE_WHOLE_LEVEL UINT_MAX

#define KTX_TRUE true
#define KTX_FALSE false
Expand Down
30 changes: 19 additions & 11 deletions lib/writer2.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ appendLibId(ktxHashList* head, ktxHashListEntry* writerEntry)
* @param[in] This pointer to the target ktxTexture object.
* @param[in] level mip level of the image to set.
* @param[in] layer array layer of the image to set.
* @param[in] faceSlice cube map face or depth slice of the image to set.
* @param[in] faceSlice cube map face or depth slice of the image to set or
* KTX_FACESLICE_WHOLE_LEVEL to set the entire level.
* @param[in] src ktxStream pointer to the source.
* @param[in] srcSize size of the source image in bytes.
*
Expand Down Expand Up @@ -208,13 +209,19 @@ ktxTexture2_setImageFromStream(ktxTexture2* This, ktx_uint32_t level,
if (!This->pData)
return KTX_INVALID_OPERATION;

result = ktxTexture_GetImageOffset(ktxTexture(This),
level, layer, faceSlice,
&imageByteOffset);
if (result != KTX_SUCCESS)
return result;

imageByteLength = ktxTexture_GetImageSize(ktxTexture(This), level);
if (faceSlice == KTX_FACESLICE_WHOLE_LEVEL) {
result = ktxTexture_GetImageOffset(ktxTexture(This), level, layer, 0, &imageByteOffset);
if (result != KTX_SUCCESS) {
return result;
}
imageByteLength = ktxTexture_calcLevelSize(ktxTexture(This), level, KTX_FORMAT_VERSION_TWO);
} else {
result = ktxTexture_GetImageOffset(ktxTexture(This), level, layer, faceSlice, &imageByteOffset);
if (result != KTX_SUCCESS) {
return result;
}
imageByteLength = ktxTexture_GetImageSize(ktxTexture(This), level);
}

if (srcSize != imageByteLength)
return KTX_INVALID_OPERATION;
Expand Down Expand Up @@ -242,7 +249,8 @@ ktxTexture2_setImageFromStream(ktxTexture2* This, ktx_uint32_t level,
* @param[in] This pointer to the target ktxTexture object.
* @param[in] level mip level of the image to set.
* @param[in] layer array layer of the image to set.
* @param[in] faceSlice cube map face or depth slice of the image to set.
* @param[in] faceSlice cube map face or depth slice of the image to set or
* KTX_FACESLICE_WHOLE_LEVEL to set the entire level.
* @param[in] src stdio stream pointer to the source.
* @param[in] srcSize size of the source image in bytes.
*
Expand Down Expand Up @@ -287,7 +295,8 @@ ktxTexture2_SetImageFromStdioStream(ktxTexture2* This, ktx_uint32_t level,
* @param[in] This pointer to the target ktxTexture object.
* @param[in] level mip level of the image to set.
* @param[in] layer array layer of the image to set.
* @param[in] faceSlice cube map face or depth slice of the image to set.
* @param[in] faceSlice cube map face or depth slice of the image to set or
* KTX_FACESLICE_WHOLE_LEVEL to set the entire level.
* @param[in] src pointer to the image source in memory.
* @param[in] srcSize size of the source image in bytes.
*
Expand Down Expand Up @@ -941,4 +950,3 @@ ktxTexture2_DeflateZLIB(ktxTexture2* This, ktx_uint32_t compressionLevel)
}

/** @} */