Skip to content

Commit

Permalink
Fixes & Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
awxkee committed Feb 1, 2024
1 parent 96f1856 commit 2521baa
Show file tree
Hide file tree
Showing 11 changed files with 316 additions and 343 deletions.
73 changes: 39 additions & 34 deletions app/src/main/java/com/awxkee/jxlcoder/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -156,53 +156,58 @@ class MainActivity : ComponentActivity() {
// }
// }
val assets = (this@MainActivity.assets.list("") ?: return@launch)
.filter { it == "0000ResizedImage_2024-02-01_12-37-42_1822.jpg" }
for (asset in assets) {
try {
val buffer4 =
this@MainActivity.assets.open(asset).source().buffer()
.readByteArray()

// val largeImageSize = JxlCoder().getSize(buffer4)
// if (largeImageSize != null) {
// var srcImage = JxlCoder().decodeSampled(
// buffer4,
// largeImageSize.width / 2,
// largeImageSize.height / 2,
// preferredColorConfig = PreferredColorConfig.RGBA_8888,
// com.awxkee.jxlcoder.ScaleMode.FIT,
// JxlResizeFilter.BICUBIC,
// toneMapper = JxlToneMapper.LOGARITHMIC,
// )
val srcImage = BitmapFactory.decodeByteArray(buffer4, 0, buffer4.size)
var radius = 5
repeat(25) {
val largeImageSize = JxlCoder().getSize(buffer4)
if (largeImageSize != null) {
var srcImage = JxlCoder().decodeSampled(
buffer4,
largeImageSize.width / 2,
largeImageSize.height / 2,
preferredColorConfig = PreferredColorConfig.RGBA_8888,
com.awxkee.jxlcoder.ScaleMode.FIT,
JxlResizeFilter.BICUBIC,
toneMapper = JxlToneMapper.LOGARITHMIC,
)
// val srcImage = BitmapFactory.decodeByteArray(buffer4, 0, buffer4.size)
var radius = 15
repeat(5) {
val cPlusPlusDoneIn = measureTimeMillis {
val image: Bitmap = srcImage.stackBlur(1.0f, radius)
val image: Bitmap = BitmapProcessor.stackBlur(srcImage, radius)
lifecycleScope.launch(Dispatchers.Main) {
imagesArray.add(image)
}
}
val ccPlusPlusDoneIn = measureTimeMillis {
val image: Bitmap = BitmapProcessor.stackBlur(srcImage, radius)
lifecycleScope.launch(Dispatchers.Main) {
imagesArray.add(image)
}
}
val gaussDoneIn = measureTimeMillis {
val image =
BitmapProcessor.gaussBlur(srcImage, radius.toFloat(), 3f)
lifecycleScope.launch(Dispatchers.Main) {
imagesArray.add(image)
}
}
val boxBlurDoneIn = measureTimeMillis {
val image = BitmapProcessor.boxBlur(srcImage, radius)
lifecycleScope.launch(Dispatchers.Main) {
imagesArray.add(image)
}
}
// val gaussDoneIn = measureTimeMillis {
// val image =
// BitmapProcessor.gaussBlur(srcImage, radius.toFloat(), 3f)
// lifecycleScope.launch(Dispatchers.Main) {
// imagesArray.add(image)
// }
// }
// val boxBlurDoneIn = measureTimeMillis {
// val image = BitmapProcessor.boxBlur(srcImage, radius)
// lifecycleScope.launch(Dispatchers.Main) {
// imagesArray.add(image)
// }
// }
radius += 1
// Log.d(
// "JxlCoder",
// "C++ Radius ${radius} StackBlur done in ${cPlusPlusDoneIn}ms, gauss ${gaussDoneIn}ms, box blur done in ${boxBlurDoneIn}"
// )
Log.d(
"JxlCoder",
"C++ Radius ${radius} StackBlur done in ${cPlusPlusDoneIn}ms, gauss ${gaussDoneIn}ms, box blur done in ${boxBlurDoneIn}"
)
}
// }
}
} catch (e: Exception) {
if (e !is FileNotFoundException) {
throw e
Expand Down
2 changes: 1 addition & 1 deletion jxlcoder/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ afterEvaluate {
create<MavenPublication>("mavenJava") {
groupId = "com.github.awxkee"
artifactId = "jxl-coder"
version = "1.8.7"
version = "1.8.8"
from(components["release"])
// artifact(androidSourcesJar)
}
Expand Down
3 changes: 2 additions & 1 deletion jxlcoder/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ add_library(${CMAKE_PROJECT_NAME} SHARED
JxlAnimatedDecoderCoordinator.cpp JxlAnimatedEncoderCoordinator.cpp BitmapScaler.cpp colorspaces/CoderCms.cpp
colorspaces/HDRTransferAdapter.cpp BoxBlur.cpp processing/BoxBlur.cpp GaussBlur.cpp processing/GaussBlur.cpp
BilateralBlur.cpp processing/BilateralBlur.cpp MedianBlur.cpp processing/MedianBlur.cpp
TiltShift.cpp processing/TiltShift.cpp StackBlur.cpp processing/StackBlur.cpp)
TiltShift.cpp processing/TiltShift.cpp processing/ShgStackBlur.cpp
CStackBlur.cpp)

target_include_directories("jxlcoder" PRIVATE ${CMAKE_SOURCE_DIR}/jxl ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/libyuv)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

//
// Created by Radzivon Bartoshyk on 31/01/2024.
// Created by Radzivon Bartoshyk on 01/02/2024.
//

#include "processing/StackBlur.h"
#include "processing/ShgStackBlur.h"
#include <jni.h>
#include <android/bitmap.h>
#include <vector>
Expand All @@ -18,8 +19,8 @@ using namespace std;

extern "C"
JNIEXPORT jobject JNICALL
Java_com_awxkee_jxlcoder_processing_BitmapProcessor_stackBlurImpl(JNIEnv *env, jobject thiz,
jobject bitmap, jint radius) {
Java_com_awxkee_jxlcoder_processing_BitmapProcessor_cstackBlurImpl(JNIEnv *env, jobject thiz,
jobject bitmap, jint radius) {
try {
AndroidBitmapInfo info;
if (AndroidBitmap_getInfo(env, bitmap, &info) < 0) {
Expand Down Expand Up @@ -107,7 +108,7 @@ Java_com_awxkee_jxlcoder_processing_BitmapProcessor_stackBlurImpl(JNIEnv *env, j

uint8_t *src = rgbPixels.data();

stackBlurU8(src, info.width, info.height, radius);
shgStackBlur(src, info.width, info.height, radius);

std::string bitmapPixelConfig = "ARGB_8888";
jclass bitmapConfig = env->FindClass("android/graphics/Bitmap$Config");
Expand Down
36 changes: 0 additions & 36 deletions jxlcoder/src/main/cpp/processing/BoxBlur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,6 @@ namespace coder::HWY_NAMESPACE {

int r = -radius;

for (; r + 4 <= radius && x + 16 < width; r += 4) {
int pos = clamp((x + r), 0, width - 1) * 4;
VU8x16 pixels = LoadU(du8x16, &src[pos]);
store = Add(store, ConvertTo(dfx4, PromoteLowerTo(du32x4, LowerHalf(pixels))));
store = Add(store,
ConvertTo(dfx4, PromoteLowerTo(du32x4, UpperHalf(du8x8, pixels))));
store = Add(store,
ConvertTo(dfx4, PromoteUpperTo(du32x4,
PromoteTo(du16x8, LowerHalf(pixels)))));
store = Add(store,
ConvertTo(dfx4, PromoteUpperTo(du32x4, PromoteTo(du16x8,
UpperHalf(du8x8,
pixels)))));
}

for (; r <= radius; ++r) {
int pos = clamp((x + r), 0, width - 1) * 4;
VU pixels = LoadU(du8, &src[pos]);
Expand Down Expand Up @@ -151,27 +136,6 @@ namespace coder::HWY_NAMESPACE {

int r = -radius;

for (; r + 4 <= radius && x + 4 < width; r += 4) {
int pos = x * 4;

auto src1 = reinterpret_cast<uint8_t *>(transient.data() +
clamp((r + y), 0, height - 1) * stride);
VU pixels = LoadU(du8, &src1[pos]);
store = Add(store, ConvertTo(dfx4, PromoteTo(du32x4, pixels)));
auto src2 = reinterpret_cast<uint8_t *>(transient.data() +
clamp((r + 1 + y), 0, height - 1) * stride);
pixels = LoadU(du8, &src2[pos]);
store = Add(store, ConvertTo(dfx4, PromoteTo(du32x4, pixels)));
auto src3 = reinterpret_cast<uint8_t *>(transient.data() +
clamp((r + 2 + y), 0, height - 1) * stride);
pixels = LoadU(du8, &src3[pos]);
store = Add(store, ConvertTo(dfx4, PromoteTo(du32x4, pixels)));
auto src4 = reinterpret_cast<uint8_t *>(transient.data() +
clamp((r + 3 + y), 0, height - 1) * stride);
pixels = LoadU(du8, &src4[pos]);
store = Add(store, ConvertTo(dfx4, PromoteTo(du32x4, pixels)));
}

for (; r <= radius; ++r) {
auto src = reinterpret_cast<uint8_t *>(transient.data() +
clamp((r + y), 0, height - 1) * stride);
Expand Down
47 changes: 0 additions & 47 deletions jxlcoder/src/main/cpp/processing/GaussBlur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,27 +87,6 @@ namespace coder::HWY_NAMESPACE {

int r = -iRadius;

for (; r + 4 <= iRadius && x + 16 < width; r += 4) {
int pos = clamp((x + r), 0, width - 1) * 4;
VF weights = LoadU(dfx4, &kernelData[r + iRadius]);
auto v1 = Set(dfx4, ExtractLane(weights, 0));
auto v2 = Set(dfx4, ExtractLane(weights, 1));
auto v3 = Set(dfx4, ExtractLane(weights, 2));
auto v4 = Set(dfx4, ExtractLane(weights, 3));
VU8x16 pixels = LoadU(du8x16, &src[pos]);
auto lowlow = ConvertTo(dfx4, PromoteLowerTo(du32x4, LowerHalf(pixels)));
store = Add(store, Mul(lowlow, v4));
auto lowup = ConvertTo(dfx4, PromoteLowerTo(du32x4, UpperHalf(du8x8, pixels)));
store = Add(store, Mul(v3, lowup));
auto upperlow = ConvertTo(dfx4, PromoteUpperTo(du32x4,
PromoteTo(du16x8, LowerHalf(pixels))));
store = Add(store, Mul(v2, upperlow));
auto upperup = ConvertTo(dfx4, PromoteUpperTo(du32x4, PromoteTo(du16x8,
UpperHalf(du8x8,
pixels))));
store = Add(store, Mul(upperup, v1));
}

for (; r <= iRadius; ++r) {
int pos = clamp((x + r), 0, width - 1) * 4;
float weight = kernel[r + iRadius];
Expand Down Expand Up @@ -152,32 +131,6 @@ namespace coder::HWY_NAMESPACE {

int r = -iRadius;

for (; r + 4 <= iRadius && x + 4 < width; r += 4) {
int pos = x * 4;
VF weights = LoadU(dfx4, &kernelData[r + iRadius]);
auto v1 = Set(dfx4, ExtractLane(weights, 0));
auto v2 = Set(dfx4, ExtractLane(weights, 1));
auto v3 = Set(dfx4, ExtractLane(weights, 2));
auto v4 = Set(dfx4, ExtractLane(weights, 3));

auto src1 = reinterpret_cast<uint8_t *>(transient.data() +
clamp((r + y), 0, height - 1) * stride);
VU pixels = LoadU(du8, &src1[pos]);
store = Add(store, Mul(ConvertTo(dfx4, PromoteTo(du32x4, pixels)), v1));
auto src2 = reinterpret_cast<uint8_t *>(transient.data() +
clamp((r + 1 + y), 0, height - 1) * stride);
pixels = LoadU(du8, &src2[pos]);
store = Add(store, Mul(ConvertTo(dfx4, PromoteTo(du32x4, pixels)), v2));
auto src3 = reinterpret_cast<uint8_t *>(transient.data() +
clamp((r + 2 + y), 0, height - 1) * stride);
pixels = LoadU(du8, &src3[pos]);
store = Add(store, Mul(ConvertTo(dfx4, PromoteTo(du32x4, pixels)), v3));
auto src4 = reinterpret_cast<uint8_t *>(transient.data() +
clamp((r + 3 + y), 0, height - 1) * stride);
pixels = LoadU(du8, &src4[pos]);
store = Add(store, Mul(ConvertTo(dfx4, PromoteTo(du32x4, pixels)), v4));
}

for (; r <= iRadius; ++r) {
auto src = reinterpret_cast<uint8_t *>(transient.data() +
clamp((r + y), 0, height - 1) * stride);
Expand Down
Loading

0 comments on commit 2521baa

Please sign in to comment.