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
12 using namespace zxing;
\r
13 using namespace zxing::qrcode;
\r
15 void CZXingBarcodeReaderAppView::StartTimer()
\r
17 const TInt tickInterval=2000000;
\r
18 iPeriodic=CPeriodic::NewL(0); // neutral priority
\r
20 //CleanupStack::PushL(iPeriodic);
\r
22 iPeriodic->Start(tickInterval,tickInterval,TCallBack(&CZXingBarcodeReaderAppView::Tick, this));
\r
24 // CleanupStack::PopAndDestroy(iPeriodic);
\r
27 TInt CZXingBarcodeReaderAppView::Tick(TAny* aObject)
\r
29 // cast, and call non-static function
\r
30 ((CZXingBarcodeReaderAppView*)aObject)->decodeBackbufferImage();
\r
34 void CZXingBarcodeReaderAppView::decodeBackbufferImage()
\r
36 QRCodeReader decoder;
\r
39 image.setImage(iBackBuffer);
\r
46 Ref<LuminanceSource> imageRef(new CameraImage(image));
\r
47 GlobalHistogramBinarizer* binz = new GlobalHistogramBinarizer(imageRef);
\r
49 Ref<Binarizer> bz (binz);
\r
50 BinaryBitmap* bb = new BinaryBitmap(bz);
\r
52 Ref<BinaryBitmap> ref(bb);
\r
54 res = decoder.decode(ref);
\r
56 string string = res->getText()->getText();
\r
57 HBufC8 *pHeap8 = HBufC8::NewMaxLC(string.size());
\r
58 pHeap8->Des().Copy((const TUint8 *)string.c_str());
\r
60 HBufC *pHeap16 = HBufC::NewMaxLC(pHeap8->Length());
\r
61 pHeap16->Des().Copy(*pHeap8);
\r
63 ShowResultL(*pHeap16);
\r
65 catch(zxing::Exception& e)
\r
67 string string = "Error...retrying...";
\r
68 HBufC8 *pHeap8 = HBufC8::NewMaxLC(string.size());
\r
69 pHeap8->Des().Copy((const TUint8 *)string.c_str());
\r
71 HBufC *pHeap16 = HBufC::NewMaxLC(pHeap8->Length());
\r
72 pHeap16->Des().Copy(*pHeap8);
\r
74 ShowResultL(*pHeap16);
\r
78 void CZXingBarcodeReaderAppView::ShowResultL(TDesC16& message)
\r
82 // Create the note once
\r
83 iNote = CAknInfoPopupNoteController::NewL();
\r
85 // Hide the note. The last note may be visible when creating the second
\r
86 iNote->HideInfoPopupNote();
\r
88 // Set the time delay period before the popup is shown (in milliseconds)
\r
89 iNote->SetTimeDelayBeforeShow(100);
\r
91 // Set the time period of how long the popup is in the view (in milliseconds)
\r
92 iNote->SetTimePopupInView(2*1000);
\r
95 iNote->SetTextL(message);
\r
100 iNote->SetPositionAndAlignment(TPoint(rect.Width()/5,rect.Height()/7),EHLeftVTop);
\r
103 iNote->ShowInfoPopupNote();
\r