@@ -194,7 +194,7 @@ static jobject NewError(JNIEnv* env, const Error& error)
194194 return env->NewObject (cls, midInit, NewEnum (env, JavaErrorTypeName (error.type ()), " ErrorType" ), C2JString (env, error.msg ()));
195195}
196196
197- static jobject NewResult (JNIEnv* env, const Result& result, int time )
197+ static jobject NewResult (JNIEnv* env, const Result& result)
198198{
199199 jclass cls = env->FindClass (PACKAGE " Result" );
200200 jmethodID midInit = env->GetMethodID (
@@ -213,7 +213,7 @@ static jobject NewResult(JNIEnv* env, const Result& result, int time)
213213 " Z"
214214 " I"
215215 " L" PACKAGE " Error;"
216- " I )V" );
216+ " )V" );
217217 bool valid = result.isValid ();
218218 return env->NewObject (cls, midInit,
219219 NewEnum (env, JavaBarcodeFormatName (result.format ()), " Format" ),
@@ -229,12 +229,11 @@ static jobject NewResult(JNIEnv* env, const Result& result, int time)
229229 valid ? C2JString (env, result.sequenceId ()) : nullptr ,
230230 result.readerInit (),
231231 result.lineCount (),
232- result.error () ? NewError (env, result.error ()) : nullptr ,
233- time
232+ result.error () ? NewError (env, result.error ()) : nullptr
234233 );
235234}
236235
237- static jobject Read (JNIEnv *env, ImageView image, const DecodeHints& hints)
236+ static jobject Read (JNIEnv *env, jobject thiz, ImageView image, const DecodeHints& hints)
238237{
239238 try {
240239 auto startTime = std::chrono::high_resolution_clock::now ();
@@ -243,12 +242,14 @@ static jobject Read(JNIEnv *env, ImageView image, const DecodeHints& hints)
243242// LOGD("time: %4d ms\n", (int)std::chrono::duration_cast<std::chrono::milliseconds>(duration).count());
244243 auto time = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count ();
245244
245+ env->SetIntField (thiz, env->GetFieldID (env->GetObjectClass (thiz), " lastReadTime" , " I" ), time);
246+
246247 jclass clsList = env->FindClass (" java/util/ArrayList" );
247248 jobject objList = env->NewObject (clsList, env->GetMethodID (clsList, " <init>" , " ()V" ));
248249 if (!results.empty ()) {
249250 jmethodID midAdd = env->GetMethodID (clsList, " add" , " (Ljava/lang/Object;)Z" );
250251 for (const auto & result: results)
251- env->CallBooleanMethod (objList, midAdd, NewResult (env, result, time ));
252+ env->CallBooleanMethod (objList, midAdd, NewResult (env, result));
252253 }
253254 return objList;
254255 } catch (const std::exception& e) {
@@ -329,7 +330,7 @@ Java_zxingcpp_BarcodeReader_readYBuffer(
329330 ImageView{pixels + top * rowStride + left, width, height, ImageFormat::Lum, rowStride}
330331 .rotated (rotation);
331332
332- return Read (env, image, CreateDecodeHints (env, options));
333+ return Read (env, thiz, image, CreateDecodeHints (env, options));
333334}
334335
335336struct LockedPixels
@@ -376,5 +377,5 @@ Java_zxingcpp_BarcodeReader_readBitmap(
376377 .cropped (left, top, width, height)
377378 .rotated (rotation);
378379
379- return Read (env, image, CreateDecodeHints (env, options));
380+ return Read (env, thiz, image, CreateDecodeHints (env, options));
380381}
0 commit comments