Skip to content

Commit 85814d6

Browse files
committed
Display P3 encoding update
1 parent 532a088 commit 85814d6

File tree

7 files changed

+32
-38
lines changed

7 files changed

+32
-38
lines changed

app/src/main/java/com/radzivon/bartoshyk/avif/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class MainActivity : AppCompatActivity() {
9393
// HDR EXAMPLES - https://us.zonerama.com/williamskeaguidingphotography/Photo/1000120226/1004888131
9494
lifecycleScope.launch(Dispatchers.IO) {
9595
val coder = HeifCoder()
96-
val buffer = assets.open("pexels_house_wall_p3.jpg").source().buffer().readByteArray()
96+
val buffer = assets.open("screenshot_test.png").source().buffer().readByteArray()
9797
val bitmap = BitmapFactory.decodeByteArray(buffer, 0, buffer.size)
9898
val encoded = coder.encodeAvif(bitmap, quality = 99, preciseMode = PreciseMode.LOSSLESS)
9999
val decoded = coder.decode(encoded)

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,8 @@ jbyteArray encodeBitmap(JNIEnv *env, jobject thiz,
192192
int bitDepth = 8;
193193
if (info.format == ANDROID_BITMAP_FORMAT_RGB_565) {
194194
bitDepth = 8;
195-
} else if ((info.format == ANDROID_BITMAP_FORMAT_RGBA_F16 &&
196-
heifCompressionFormat == heif_compression_AV1) ||
197-
(info.format == ANDROID_BITMAP_FORMAT_RGBA_1010102 &&
198-
heifCompressionFormat == heif_compression_AV1)) {
195+
} else if ((info.format == ANDROID_BITMAP_FORMAT_RGBA_F16 && heifCompressionFormat == heif_compression_AV1) ||
196+
(info.format == ANDROID_BITMAP_FORMAT_RGBA_1010102 && heifCompressionFormat == heif_compression_AV1)) {
199197
bitDepth = 10;
200198
}
201199

avif-coder/src/main/cpp/colorspace/DataSpaceToNCLX.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ bool colorProfileFromDataSpace(uint8_t *data,
8383
profile->full_range_flag = true;
8484
isResolved = true;
8585
} else if (dataSpace == ADataSpace::ADATASPACE_DISPLAY_P3) {
86-
profile->transfer_characteristics = heif_transfer_characteristic_ITU_R_BT_709_5;
87-
profile->matrix_coefficients = heif_matrix_coefficients_ITU_R_BT_2020_2_non_constant_luminance;
86+
profile->transfer_characteristics = heif_transfer_characteristic_IEC_61966_2_1;
87+
profile->matrix_coefficients = heif_matrix_coefficients_ITU_R_BT_601_6;
8888
profile->color_primaries = heif_color_primaries_SMPTE_EG_432_1;
8989
profile->full_range_flag = true;
9090
isResolved = true;

avif-coder/src/main/cpp/colorspace/eotf-inl.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,33 @@ HWY_FAST_MATH_INLINE V SRGBEotf(D d, V v) {
172172
return result;
173173
}
174174

175+
HWY_FAST_MATH_INLINE float TransferFunction(float v,
176+
const float c0,
177+
const float c1,
178+
const float c2,
179+
const float c3,
180+
const float cutoff,
181+
const float gamma,
182+
const float c4,
183+
const float c5) {
184+
if (v < 0) {
185+
return 0.f;
186+
} else if (v >= cutoff) {
187+
return c0 * std::powf(c1 * v + c2, gamma) + c3;
188+
} else if (v < 1) {
189+
return c4 * v + c5;
190+
} else {
191+
return 1.f;
192+
}
193+
}
194+
175195
HWY_FAST_MATH_INLINE float SRGBOetf(const float linear) {
176196
if (linear < 0.0f) {
177197
return 0.0f;
178198
} else if (linear < 0.0030412825601275209f) {
179199
return linear * 12.92f;
180200
} else if (linear < 1.0f) {
181-
return 1.0550107189475866f * powf(linear, 1.0f / 2.4f) - 0.0550107189475866f;
201+
return 1.0550107189475866f * std::powf(linear, 1.0f / 2.4f) - 0.0550107189475866f;
182202
} else {
183203
return 1.0f;
184204
}

avif-coder/src/main/cpp/hwy/ops/generic_ops-inl.h

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2599,38 +2599,14 @@ HWY_API VFromD<DN> ReorderDemote2To(DN dn, V a, V b) {
25992599

26002600
template<class D, HWY_IF_F32_D(D)>
26012601
HWY_API VFromD<D> PromoteTo(D df, Vec<Rebind<uint16_t, D>> v) {
2602-
const RebindToUnsigned<decltype(df)> du32;
2603-
2604-
// Floats have 23 bits of mantissa.
2605-
// We want least significant 8 bits to be shifted to [ 0 .. 255 ], therefore need to add 2^23
2606-
// See this page for details: https://www.h-schmidt.net/FloatConverter/IEEE754.html
2607-
// If you want output floats in [ 0 .. 255.0 / 256.0 ] interval, change into 2^15 = 0x47000000
2608-
constexpr uint32_t offsetValue = 0x4b000000;
2609-
// Check disassembly & verify your compiler has moved this initialization outside the loop
2610-
const auto offsetInt = Set(du32, offsetValue);
2611-
// Bitwise is probably slightly faster than addition, delivers same results for our input
2612-
auto u32 = PromoteTo(du32, v);
2613-
u32 = Or(u32, offsetInt);
2614-
// The only FP operation required is subtraction, hopefully faster than UCVTF
2615-
return Sub(BitCast(df, u32), BitCast(df, offsetInt));
2602+
const RebindToUnsigned<decltype(df)> du32;
2603+
return ConvertTo(df, PromoteTo(du32, v));
26162604
}
26172605

26182606
template<class D, HWY_IF_F32_D(D)>
26192607
HWY_API VFromD<D> PromoteTo(D df, Vec<Rebind<uint8_t, D>> v) {
2620-
const RebindToUnsigned<decltype(df)> du32;
2621-
2622-
// Floats have 23 bits of mantissa.
2623-
// We want least significant 8 bits to be shifted to [ 0 .. 255 ], therefore need to add 2^23
2624-
// See this page for details: https://www.h-schmidt.net/FloatConverter/IEEE754.html
2625-
// If you want output floats in [ 0 .. 255.0 / 256.0 ] interval, change into 2^15 = 0x47000000
2626-
constexpr uint32_t offsetValue = 0x4b000000;
2627-
// Check disassembly & verify your compiler has moved this initialization outside the loop
2628-
const auto offsetInt = Set(du32, offsetValue);
2629-
// Bitwise is probably slightly faster than addition, delivers same results for our input
2630-
auto u32 = PromoteTo(du32, v);
2631-
u32 = Or(u32, offsetInt);
2632-
// The only FP operation required is subtraction, hopefully faster than UCVTF
2633-
return Sub(BitCast(df, u32), BitCast(df, offsetInt));
2608+
const RebindToUnsigned<decltype(df)> du32;
2609+
return ConvertTo(df, PromoteTo(du32, v));
26342610
}
26352611

26362612
template<class D, HWY_IF_U8_D(D)>

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
plugins {
33
id 'com.android.application' version '8.2.0' apply false
4-
id 'com.android.library' version '8.3.0' apply false
4+
id 'com.android.library' version '8.3.1' apply false
55
id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
66
id 'com.google.devtools.ksp' version '1.8.10-1.0.9' apply false
77
}

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
#Wed Dec 28 11:02:12 ICT 2022
2727
distributionBase=GRADLE_USER_HOME
28-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
28+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
2929
distributionPath=wrapper/dists
3030
zipStorePath=wrapper/dists
3131
zipStoreBase=GRADLE_USER_HOME

0 commit comments

Comments
 (0)