Skip to content

Commit fca81c9

Browse files
committed
add AvifSpeed enum & rm speed in HEIF
1 parent cef16c6 commit fca81c9

File tree

3 files changed

+57
-9
lines changed

3 files changed

+57
-9
lines changed

avif-coder/src/main/cpp/JniEncoder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ jbyteArray encodeBitmap(JNIEnv *env, jobject thiz,
114114
throwException(env, str);
115115
return static_cast<jbyteArray>(nullptr);
116116
}
117-
if(speed > 0 && speed < 20){
117+
if(speed > 0 && speed < 10){
118118
result = heif_encoder_set_parameter_string(encoder.get(), "speed", speed)
119119
if (result.code != heif_error_Ok) {
120120
std::string choke(result.message);
@@ -361,15 +361,15 @@ Java_com_radzivon_bartoshyk_avif_coder_HeifCoder_encodeAvifImpl(JNIEnv *env, job
361361
extern "C"
362362
JNIEXPORT jbyteArray JNICALL
363363
Java_com_radzivon_bartoshyk_avif_coder_HeifCoder_encodeHeicImpl(JNIEnv *env, jobject thiz,
364-
jobject bitmap, jint quality, jint speed,
364+
jobject bitmap, jint quality,
365365
jint dataSpace, jint qualityMode) {
366366
try {
367367
return encodeBitmap(env,
368368
thiz,
369369
bitmap,
370370
heif_compression_HEVC,
371371
quality,
372-
speed,
372+
0,
373373
dataSpace,
374374
static_cast<AvifQualityMode>(qualityMode));
375375
} catch (std::bad_alloc &err) {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2023 Radzivon Bartoshyk
5+
* avif-coder [https://github.com/awxkee/avif-coder]
6+
*
7+
* Created by Radzivon Bartoshyk on 23/9/2023
8+
*
9+
* Permission is hereby granted, free of charge, to any person obtaining a copy
10+
* of this software and associated documentation files (the "Software"), to deal
11+
* in the Software without restriction, including without limitation the rights
12+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
* copies of the Software, and to permit persons to whom the Software is
14+
* furnished to do so, subject to the following conditions:
15+
*
16+
* The above copyright notice and this permission notice shall be included in all
17+
* copies or substantial portions of the Software.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25+
* SOFTWARE.
26+
*
27+
*/
28+
29+
package com.radzivon.bartoshyk.avif.coder
30+
31+
/**
32+
* Enum representing speed values from 0 to 10 (slowest-fastest).
33+
* Default iis 6.
34+
* https://github.com/AOMediaCodec/libavif/blob/main/doc/avifenc.1.md
35+
*/
36+
enum class AvifSpeed(internal val value: Int) {
37+
ZERO(0), // Speed 0
38+
ONE(1), // Speed 1
39+
TWO(2), // Speed 2
40+
THREE(3), // Speed 3
41+
FOUR(4), // Speed 4
42+
FIVE(5), // Speed 5
43+
SIX(6), // Speed 6
44+
SEVEN(7), // Speed 7
45+
EIGHT(8), // Speed 8
46+
NINE(9), // Speed 9
47+
TEN(10) // Speed 10
48+
}

avif-coder/src/main/java/com/radzivon/bartoshyk/avif/coder/HeifCoder.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,25 +116,25 @@ class HeifCoder(
116116
)
117117
}
118118

119-
fun encodeAvif(bitmap: Bitmap, quality: Int = 80, speed: Int = 0, preciseMode: PreciseMode = PreciseMode.LOSSY): ByteArray {
119+
fun encodeAvif(bitmap: Bitmap, quality: Int = 80, speed: AvifSpeed = AvifSpeed.SIX, preciseMode: PreciseMode = PreciseMode.LOSSY): ByteArray {
120120
require(quality in 0..100) {
121121
throw IllegalStateException("Quality should be in 0..100 range")
122122
}
123123
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
124-
encodeAvifImpl(bitmap, quality, speed, bitmap.colorSpace?.dataSpace ?: -1, preciseMode.value)
124+
encodeAvifImpl(bitmap, quality, speed.value, bitmap.colorSpace?.dataSpace ?: -1, preciseMode.value)
125125
} else {
126-
encodeAvifImpl(bitmap, quality, speed, -1, preciseMode.value)
126+
encodeAvifImpl(bitmap, quality, speed.value, -1, preciseMode.value)
127127
}
128128
}
129129

130-
fun encodeHeic(bitmap: Bitmap, quality: Int = 80, speed: Int = 0, preciseMode: PreciseMode = PreciseMode.LOSSY): ByteArray {
130+
fun encodeHeic(bitmap: Bitmap, quality: Int = 80, preciseMode: PreciseMode = PreciseMode.LOSSY): ByteArray {
131131
require(quality in 0..100) {
132132
throw IllegalStateException("Quality should be in 0..100 range")
133133
}
134134
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
135-
encodeHeicImpl(bitmap, quality, speed, bitmap.colorSpace?.dataSpace ?: -1, preciseMode.value)
135+
encodeHeicImpl(bitmap, quality, bitmap.colorSpace?.dataSpace ?: -1, preciseMode.value)
136136
} else {
137-
encodeHeicImpl(bitmap, quality, speed, -1, preciseMode.value)
137+
encodeHeicImpl(bitmap, quality, -1, preciseMode.value)
138138
}
139139
}
140140

0 commit comments

Comments
 (0)