1 #include "ZXingBarcodeReaderAppView.h"
\r
4 #include <zxing/qrcode/QRCodeReader.h>
\r
6 #include <zxing/common/GlobalHistogramBinarizer.h>
\r
7 #include <zxing/Binarizer.h>
\r
8 #include <zxing/BinaryBitmap.h>
\r
9 #include <CameraImage.h>
\r
11 #include <aknmessagequerydialog.h>
\r
12 #include "ZXingBarcodeReader_0xEF24C10A.rsg"
\r
14 using namespace zxing;
\r
15 using namespace zxing::qrcode;
\r
17 void CZXingBarcodeReaderAppView::StartTimer()
\r
19 const TInt tickInterval=2000000;
\r
20 iPeriodic=CPeriodic::NewL(0); // neutral priority
\r
22 //CleanupStack::PushL(iPeriodic);
\r
24 iPeriodic->Start(tickInterval,tickInterval,TCallBack(&CZXingBarcodeReaderAppView::Tick, this));
\r
26 // CleanupStack::PopAndDestroy(iPeriodic);
\r
29 TInt CZXingBarcodeReaderAppView::Tick(TAny* aObject)
\r
31 // cast, and call non-static function
\r
32 ((CZXingBarcodeReaderAppView*)aObject)->decodeBackbufferImage();
\r
36 void CZXingBarcodeReaderAppView::decodeBackbufferImage()
\r
38 QRCodeReader decoder;
\r
41 image.setImage(iBackBuffer);
\r
48 Ref<LuminanceSource> imageRef(new CameraImage(image));
\r
49 GlobalHistogramBinarizer* binz = new GlobalHistogramBinarizer(imageRef);
\r
51 Ref<Binarizer> bz (binz);
\r
52 BinaryBitmap* bb = new BinaryBitmap(bz);
\r
54 Ref<BinaryBitmap> ref(bb);
\r
56 res = decoder.decode(ref);
\r
58 string string = res->getText()->getText();
\r
59 HBufC8 *pHeap8 = HBufC8::NewMaxLC(string.size());
\r
60 pHeap8->Des().Copy((const TUint8 *)string.c_str());
\r
62 HBufC *pHeap16 = HBufC::NewMaxLC(pHeap8->Length());
\r
63 pHeap16->Des().Copy(*pHeap8);
\r
65 ShowResultL(*pHeap16);
\r
67 catch(zxing::Exception& e)
\r
69 /*string string = "Error...retrying...";
\r
70 HBufC8 *pHeap8 = HBufC8::NewMaxLC(string.size());
\r
71 pHeap8->Des().Copy((const TUint8 *)string.c_str());
\r
73 HBufC *pHeap16 = HBufC::NewMaxLC(pHeap8->Length());
\r
74 pHeap16->Des().Copy(*pHeap8);
\r
76 ShowResultL(*pHeap16);*/
\r
80 void CZXingBarcodeReaderAppView::ShowResultL(TDesC16& message)
\r
84 CAknMessageQueryDialog* dlg = new (ELeave) CAknMessageQueryDialog ();
\r
86 dlg->PrepareLC(R_TEXT_QUERY_DIALOG );
\r
88 //HBufC* title = NULL;
\r
89 //title = iEikonEnv->AllocReadResourceLC ( TEXT_DIALOG_TITLE );
\r
90 dlg->QueryHeading ()->SetTextL (_L("Information") );
\r
92 dlg->SetMessageTextL ( message );
\r
96 CleanupStack::PopAndDestroy();
\r