@@ -103,7 +103,8 @@ jobject decodeSampledImageImpl(JNIEnv *env, std::vector<uint8_t> &imageData, jin
103
103
imageData.clear ();
104
104
105
105
if (!iccProfile.empty ()) {
106
- size_t stride = (size_t ) xsize * 4 * (size_t )(useBitmapFloats ? sizeof (uint16_t ) : sizeof (uint8_t ));
106
+ size_t stride =
107
+ (size_t ) xsize * 4 * (size_t ) (useBitmapFloats ? sizeof (uint16_t ) : sizeof (uint8_t ));
107
108
convertUseDefinedColorSpace (rgbaPixels,
108
109
stride,
109
110
static_cast <size_t >(xsize),
@@ -113,11 +114,13 @@ jobject decodeSampledImageImpl(JNIEnv *env, std::vector<uint8_t> &imageData, jin
113
114
useBitmapFloats);
114
115
}
115
116
116
- bool useSampler = (scaledWidth > 0 || scaledHeight > 0 ) && (scaledWidth != 0 && scaledHeight != 0 );
117
+ bool
118
+ useSampler = (scaledWidth > 0 || scaledHeight > 0 ) && (scaledWidth != 0 && scaledHeight != 0 );
117
119
118
120
uint32_t finalWidth = xsize;
119
121
uint32_t finalHeight = ysize;
120
- uint32_t stride = static_cast <uint32_t >(finalWidth) * 4 * static_cast <uint32_t >(useBitmapFloats ? sizeof (uint16_t ) : sizeof (uint8_t ));
122
+ uint32_t stride = static_cast <uint32_t >(finalWidth) * 4
123
+ * static_cast <uint32_t >(useBitmapFloats ? sizeof (uint16_t ) : sizeof (uint8_t ));
121
124
122
125
if (useSampler) {
123
126
auto scaleResult = RescaleImage (rgbaPixels, env, &stride, useBitmapFloats,
@@ -248,7 +251,8 @@ jobject decodeSampledImageImpl(JNIEnv *env, std::vector<uint8_t> &imageData, jin
248
251
jobject rgba8888Obj = env->GetStaticObjectField (bitmapConfig, rgba8888FieldID);
249
252
250
253
jclass bitmapClass = env->FindClass (" android/graphics/Bitmap" );
251
- jmethodID createBitmapMethodID = env->GetStaticMethodID (bitmapClass, " createBitmap" ,
254
+ jmethodID createBitmapMethodID = env->GetStaticMethodID (bitmapClass,
255
+ " createBitmap" ,
252
256
" (IILandroid/graphics/Bitmap$Config;)Landroid/graphics/Bitmap;" );
253
257
jobject bitmapObj = env->CallStaticObjectMethod (bitmapClass, createBitmapMethodID,
254
258
static_cast <jint>(finalWidth),
@@ -317,6 +321,11 @@ Java_com_awxkee_jxlcoder_JxlCoder_decodeSampledImpl(JNIEnv *env, jobject thiz,
317
321
std::string errorString = " Not enough memory to decode this image" ;
318
322
throwException (env, errorString);
319
323
return nullptr ;
324
+ } catch (std::runtime_error &err) {
325
+ std::string w1 = err.what ();
326
+ std::string errorString = " Error while decoding: " + w1;
327
+ throwException (env, errorString);
328
+ return nullptr ;
320
329
}
321
330
}
322
331
@@ -346,6 +355,11 @@ Java_com_awxkee_jxlcoder_JxlCoder_decodeByteBufferSampledImpl(JNIEnv *env, jobje
346
355
std::string errorString = " Not enough memory to decode this image" ;
347
356
throwException (env, errorString);
348
357
return nullptr ;
358
+ } catch (std::runtime_error &err) {
359
+ std::string w1 = err.what ();
360
+ std::string errorString = " Error while decoding: " + w1;
361
+ throwException (env, errorString);
362
+ return nullptr ;
349
363
}
350
364
}
351
365
0 commit comments