Skip to content

Commit 84771a5

Browse files
authored
Expose supercompression functions via JNI (KhronosGroup#879)
This builds upon KhronosGroup#876 , which is already merged. It exposes the `deflateZstd` and `deflateZLIB` functions of the `ktxTexture2` class to the Java `KtxTexture2` class.
1 parent 4b15ab6 commit 84771a5

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-4
lines changed

interface/java_binding/src/main/cpp/KtxTexture2.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,16 @@ extern "C" JNIEXPORT jobject JNICALL Java_org_khronos_ktx_KtxTexture2_createFrom
133133
return make_ktx2_wrapper(env, instance);
134134
}
135135

136+
extern "C" JNIEXPORT jint JNICALL Java_org_khronos_ktx_KtxTexture2_deflateZstd(JNIEnv *env,
137+
jobject thiz,
138+
jint level)
139+
{
140+
return ktxTexture2_DeflateZstd(get_ktx2_texture(env, thiz), static_cast<ktx_uint32_t>(level));
141+
}
136142

143+
extern "C" JNIEXPORT jint JNICALL Java_org_khronos_ktx_KtxTexture2_deflateZLIB(JNIEnv *env,
144+
jobject thiz,
145+
jint level)
146+
{
147+
return ktxTexture2_DeflateZLIB(get_ktx2_texture(env, thiz), static_cast<ktx_uint32_t>(level));
148+
}

interface/java_binding/src/main/java/org/khronos/ktx/KtxTexture2.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,30 @@ public static native KtxTexture2 createFromNamedFile(String filename,
4545
public static KtxTexture2 createFromNamedFile(String filename) {
4646
return createFromNamedFile(filename, KtxTextureCreateFlagBits.LOAD_IMAGE_DATA_BIT);
4747
}
48+
49+
/**
50+
* Deflate the data in a {@link KtxTexture2} object using Zstandard.
51+
*
52+
* The texture's levelIndex, dataSize, DFD, data pointer, and supercompressionScheme will
53+
* all be updated after successful deflation to reflect the deflated data.
54+
*
55+
* @param level Set speed vs compression ratio trade-off. Values
56+
* between 1 and 22 are accepted. The lower the level the faster. Values
57+
* above 20 should be used with caution as they require more memory.
58+
* @return A {@link KtxErrorCode} value
59+
*/
60+
public native int deflateZstd(int level);
61+
62+
/**
63+
* Deflate the data in a {@link KtxTexture2} object using miniz (ZLIB)
64+
*
65+
* The texture's levelIndex, dataSize, DFD, data pointer, and supercompressionScheme will
66+
* all be updated after successful deflation to reflect the deflated data.
67+
*
68+
* @param level Set speed vs compression ratio trade-off. Values
69+
* between 1 and 9 are accepted. The lower the level the faster.
70+
* @return A {@link KtxErrorCode} value
71+
*/
72+
public native int deflateZLIB(int level);
73+
4874
}

lib/texture2.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2471,7 +2471,7 @@ ktx_uint64_t ktxTexture2_levelDataOffset(ktxTexture2* This, ktx_uint32_t level)
24712471
* @~English
24722472
* @brief Inflate the data in a ktxTexture2 object using Zstandard.
24732473
*
2474-
* The texture's levelIndex, dataSize, DFD and supercompressionScheme will
2474+
* The texture's levelIndex, dataSize, DFD, data pointer, and supercompressionScheme will
24752475
* all be updated after successful inflation to reflect the inflated data.
24762476
*
24772477
* @param[in] This pointer to the ktxTexture2 object of interest.
@@ -2583,7 +2583,7 @@ ktxTexture2_inflateZstdInt(ktxTexture2* This, ktx_uint8_t* pDeflatedData,
25832583
* @~English
25842584
* @brief Inflate the data in a ktxTexture2 object using miniz (ZLIB).
25852585
*
2586-
* The texture's levelIndex, dataSize, DFD and supercompressionScheme will
2586+
* The texture's levelIndex, dataSize, DFD, data pointer, and supercompressionScheme will
25872587
* all be updated after successful inflation to reflect the inflated data.
25882588
*
25892589
* @param[in] This pointer to the ktxTexture2 object of interest.

lib/writer2.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ ktxTexture2_WriteToMemory(ktxTexture2* This,
761761
* @~English
762762
* @brief Deflate the data in a ktxTexture2 object using Zstandard.
763763
*
764-
* The texture's levelIndex, dataSize, DFD and supercompressionScheme will
764+
* The texture's levelIndex, dataSize, DFD, data pointer, and supercompressionScheme will
765765
* all be updated after successful deflation to reflect the deflated data.
766766
*
767767
* @param[in] This pointer to the ktxTexture2 object of interest.
@@ -890,7 +890,7 @@ ktxTexture2_DeflateZstd(ktxTexture2* This, ktx_uint32_t compressionLevel)
890890
* @~English
891891
* @brief Deflate the data in a ktxTexture2 object using miniz (ZLIB).
892892
*
893-
* The texture's levelIndex, dataSize, DFD and supercompressionScheme will
893+
* The texture's levelIndex, dataSize, DFD, data pointer, and supercompressionScheme will
894894
* all be updated after successful deflation to reflect the deflated data.
895895
*
896896
* @param[in] This pointer to the ktxTexture2 object of interest.

0 commit comments

Comments
 (0)