Skip to content

Commit

Permalink
Expose supercompression functions via JNI (#879)
Browse files Browse the repository at this point in the history
This builds upon #876 ,
which is already merged.

It exposes the `deflateZstd` and `deflateZLIB` functions of the
`ktxTexture2` class to the Java `KtxTexture2` class.
  • Loading branch information
javagl authored Apr 15, 2024
1 parent 0bca55a commit 7abffbd
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
12 changes: 12 additions & 0 deletions interface/java_binding/src/main/cpp/KtxTexture2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,16 @@ extern "C" JNIEXPORT jobject JNICALL Java_org_khronos_ktx_KtxTexture2_createFrom
return make_ktx2_wrapper(env, instance);
}

extern "C" JNIEXPORT jint JNICALL Java_org_khronos_ktx_KtxTexture2_deflateZstd(JNIEnv *env,
jobject thiz,
jint level)
{
return ktxTexture2_DeflateZstd(get_ktx2_texture(env, thiz), static_cast<ktx_uint32_t>(level));
}

extern "C" JNIEXPORT jint JNICALL Java_org_khronos_ktx_KtxTexture2_deflateZLIB(JNIEnv *env,
jobject thiz,
jint level)
{
return ktxTexture2_DeflateZLIB(get_ktx2_texture(env, thiz), static_cast<ktx_uint32_t>(level));
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,30 @@ public static native KtxTexture2 createFromNamedFile(String filename,
public static KtxTexture2 createFromNamedFile(String filename) {
return createFromNamedFile(filename, KtxTextureCreateFlagBits.LOAD_IMAGE_DATA_BIT);
}

/**
* Deflate the data in a {@link KtxTexture2} object using Zstandard.
*
* The texture's levelIndex, dataSize, DFD, data pointer, and supercompressionScheme will
* all be updated after successful deflation to reflect the deflated data.
*
* @param level Set speed vs compression ratio trade-off. Values
* between 1 and 22 are accepted. The lower the level the faster. Values
* above 20 should be used with caution as they require more memory.
* @return A {@link KtxErrorCode} value
*/
public native int deflateZstd(int level);

/**
* Deflate the data in a {@link KtxTexture2} object using miniz (ZLIB)
*
* The texture's levelIndex, dataSize, DFD, data pointer, and supercompressionScheme will
* all be updated after successful deflation to reflect the deflated data.
*
* @param level Set speed vs compression ratio trade-off. Values
* between 1 and 9 are accepted. The lower the level the faster.
* @return A {@link KtxErrorCode} value
*/
public native int deflateZLIB(int level);

}
4 changes: 2 additions & 2 deletions lib/texture2.c
Original file line number Diff line number Diff line change
Expand Up @@ -2471,7 +2471,7 @@ ktx_uint64_t ktxTexture2_levelDataOffset(ktxTexture2* This, ktx_uint32_t level)
* @~English
* @brief Inflate the data in a ktxTexture2 object using Zstandard.
*
* The texture's levelIndex, dataSize, DFD and supercompressionScheme will
* The texture's levelIndex, dataSize, DFD, data pointer, and supercompressionScheme will
* all be updated after successful inflation to reflect the inflated data.
*
* @param[in] This pointer to the ktxTexture2 object of interest.
Expand Down Expand Up @@ -2583,7 +2583,7 @@ ktxTexture2_inflateZstdInt(ktxTexture2* This, ktx_uint8_t* pDeflatedData,
* @~English
* @brief Inflate the data in a ktxTexture2 object using miniz (ZLIB).
*
* The texture's levelIndex, dataSize, DFD and supercompressionScheme will
* The texture's levelIndex, dataSize, DFD, data pointer, and supercompressionScheme will
* all be updated after successful inflation to reflect the inflated data.
*
* @param[in] This pointer to the ktxTexture2 object of interest.
Expand Down
4 changes: 2 additions & 2 deletions lib/writer2.c
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ ktxTexture2_WriteToMemory(ktxTexture2* This,
* @~English
* @brief Deflate the data in a ktxTexture2 object using Zstandard.
*
* The texture's levelIndex, dataSize, DFD and supercompressionScheme will
* The texture's levelIndex, dataSize, DFD, data pointer, and supercompressionScheme will
* all be updated after successful deflation to reflect the deflated data.
*
* @param[in] This pointer to the ktxTexture2 object of interest.
Expand Down Expand Up @@ -890,7 +890,7 @@ ktxTexture2_DeflateZstd(ktxTexture2* This, ktx_uint32_t compressionLevel)
* @~English
* @brief Deflate the data in a ktxTexture2 object using miniz (ZLIB).
*
* The texture's levelIndex, dataSize, DFD and supercompressionScheme will
* The texture's levelIndex, dataSize, DFD, data pointer, and supercompressionScheme will
* all be updated after successful deflation to reflect the deflated data.
*
* @param[in] This pointer to the ktxTexture2 object of interest.
Expand Down

0 comments on commit 7abffbd

Please sign in to comment.