Skip to content

Commit

Permalink
Fix crash on aspect fit scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
awxkee committed Jan 9, 2025
1 parent 326b429 commit 726d4d2
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 22 deletions.
21 changes: 7 additions & 14 deletions app/src/main/java/com/awxkee/jxlcoder/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -216,27 +216,20 @@ class MainActivity : ComponentActivity() {
val largeImageSize = JxlCoder.getSize(buffer4)
if (largeImageSize != null) {
val time = measureTimeMillis {
// val srcImage = JxlCoder.decodeSampled(
// buffer4,
// largeImageSize.width / 2,
// largeImageSize.height / 2,
// preferredColorConfig = PreferredColorConfig.HARDWARE,
// com.awxkee.jxlcoder.ScaleMode.FIT,
// toneMapper = JxlToneMapper.REC2408,
// )
val animatedImage = JxlAnimatedImage(
val srcImage = JxlCoder.decodeSampled(
buffer4,
-1,
largeImageSize.height / 2,
preferredColorConfig = PreferredColorConfig.HARDWARE,
scaleMode = ScaleMode.FIT,
com.awxkee.jxlcoder.ScaleMode.FIT,
toneMapper = JxlToneMapper.REC2408,
)
drawablesArray.add(animatedImage.animatedDrawable)
// val srcImage = JxlCoder.decode(buffer4,
// preferredColorConfig = PreferredColorConfig.RGB_565,
// toneMapper = JxlToneMapper.REC2408)
// lifecycleScope.launch {
// imagesArray.add(srcImage)
// }
lifecycleScope.launch {
imagesArray.add(srcImage)
}
}
Log.d("JXLCoder", "Decoding done in ${time}ms")
}
Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id("com.android.application") version "8.7.2" apply false
id("com.android.application") version "8.8.0-rc02" apply false
id("org.jetbrains.kotlin.android") version "2.0.20" apply false
id("com.android.library") version "8.7.2" apply false
id("com.android.library") version "8.8.0-rc02" apply false
id("com.google.devtools.ksp") version "2.0.20-1.0.25" apply false
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sun Aug 20 15:15:13 GET 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
7 changes: 3 additions & 4 deletions jxlcoder/src/main/cpp/SizeScaler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ bool RescaleImage(std::vector<uint8_t> &rgbaData,
uint32_t *stride,
bool useFloats,
uint32_t *imageWidthPtr, uint32_t *imageHeightPtr,
uint32_t scaledWidth, uint32_t scaledHeight,
int scaledWidth, int scaledHeight,
uint32_t bitDepth,
bool alphaPremultiplied,
ScaleMode scaleMode,
Expand All @@ -57,11 +57,11 @@ bool RescaleImage(std::vector<uint8_t> &rgbaData,
if (scaleMode == Fit || scaleMode == Fill) {
std::pair<int, int> currentSize(imageWidth, imageHeight);
if (scaledHeight > 0 && scaledWidth < 0) {
auto newBounds = ResizeAspectHeight(currentSize, scaledHeight, scaledWidth == -2);
auto newBounds = ResizeAspectHeight(currentSize, scaledHeight, scaledHeight == -2);
scaledWidth = newBounds.first;
scaledHeight = newBounds.second;
} else if (scaledHeight < 0) {
auto newBounds = ResizeAspectWidth(currentSize, scaledHeight, scaledHeight == -2);
auto newBounds = ResizeAspectWidth(currentSize, scaledWidth, scaledWidth == -2);
scaledWidth = newBounds.first;
scaledHeight = newBounds.second;
} else {
Expand Down Expand Up @@ -157,7 +157,6 @@ bool RescaleImage(std::vector<uint8_t> &rgbaData,
imageHeight = scaledHeight;

if (xTranslation > 0 || yTranslation > 0) {

int left = std::max(xTranslation, 0);
int right = xTranslation + canvasWidth;
int top = std::max(yTranslation, 0);
Expand Down
2 changes: 1 addition & 1 deletion jxlcoder/src/main/cpp/SizeScaler.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ bool RescaleImage(std::vector<uint8_t> &rgbaData,
uint32_t *stride,
bool useFloats,
uint32_t *imageWidthPtr, uint32_t *imageHeightPtr,
uint32_t scaledWidth, uint32_t scaledHeight,
int scaledWidth, int scaledHeight,
uint32_t bit_depth,
bool alphaPremultiplied,
ScaleMode scaleMode,
Expand Down

0 comments on commit 726d4d2

Please sign in to comment.