@@ -79,7 +79,7 @@ struct heif_error writeHeifData(struct heif_context *ctx,
7979
8080jbyteArray encodeBitmap (JNIEnv *env, jobject thiz,
8181 jobject bitmap, heif_compression_format heifCompressionFormat,
82- const int quality, const int dataSpace, const AvifQualityMode qualityMode) {
82+ const int quality, const int speed, const int dataSpace, const AvifQualityMode qualityMode) {
8383 std::shared_ptr<heif_context> ctx (heif_context_alloc (),
8484 [](heif_context *c) { heif_context_free (c); });
8585 if (!ctx) {
@@ -114,6 +114,15 @@ jbyteArray encodeBitmap(JNIEnv *env, jobject thiz,
114114 throwException (env, str);
115115 return static_cast <jbyteArray>(nullptr );
116116 }
117+ if (speed > 0 && speed < 20 ){
118+ result = heif_encoder_set_parameter_string (encoder.get (), " speed" , speed)
119+ if (result.code != heif_error_Ok) {
120+ std::string choke (result.message );
121+ std::string str = " Can't set speed/effort: " + choke;
122+ throwException (env, str);
123+ return static_cast <jbyteArray>(nullptr );
124+ }
125+ }
117126 }
118127 } else if (qualityMode == AVIF_LOSELESS_MODE) {
119128 result = heif_encoder_set_lossless (encoder.get (), true );
@@ -331,14 +340,15 @@ jbyteArray encodeBitmap(JNIEnv *env, jobject thiz,
331340extern " C"
332341JNIEXPORT jbyteArray JNICALL
333342Java_com_radzivon_bartoshyk_avif_coder_HeifCoder_encodeAvifImpl (JNIEnv *env, jobject thiz,
334- jobject bitmap, jint quality,
343+ jobject bitmap, jint quality, jint speed,
335344 jint dataSpace, jint qualityMode) {
336345 try {
337346 return encodeBitmap (env,
338347 thiz,
339348 bitmap,
340349 heif_compression_AV1,
341350 quality,
351+ speed,
342352 dataSpace,
343353 static_cast <AvifQualityMode>(qualityMode));
344354 } catch (std::bad_alloc &err) {
@@ -351,14 +361,15 @@ Java_com_radzivon_bartoshyk_avif_coder_HeifCoder_encodeAvifImpl(JNIEnv *env, job
351361extern " C"
352362JNIEXPORT jbyteArray JNICALL
353363Java_com_radzivon_bartoshyk_avif_coder_HeifCoder_encodeHeicImpl (JNIEnv *env, jobject thiz,
354- jobject bitmap, jint quality,
364+ jobject bitmap, jint quality, jint speed,
355365 jint dataSpace, jint qualityMode) {
356366 try {
357367 return encodeBitmap (env,
358368 thiz,
359369 bitmap,
360370 heif_compression_HEVC,
361371 quality,
372+ speed,
362373 dataSpace,
363374 static_cast <AvifQualityMode>(qualityMode));
364375 } catch (std::bad_alloc &err) {
0 commit comments