Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
Removes intermediate winmd component from Win10 implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimir-kotikov committed Dec 22, 2015
1 parent 9c2da01 commit 521d427
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 14,944 deletions.
5 changes: 4 additions & 1 deletion plugin.xml
Expand Up @@ -313,8 +313,11 @@
<DeviceCapability Name="webcam" />
</config-file>

<framework src="src/windows/lib.UW/x86/ZXing.winmd" target-dir="x86" arch="x86" custom="true" versions=">8.1" />
<framework src="src/windows/lib.UW/x64/ZXing.winmd" target-dir="x64" arch="x64" custom="true" versions=">8.1" />
<framework src="src/windows/lib.UW/ARM/ZXing.winmd" target-dir="ARM" arch="ARM" custom="true" versions=">8.1" />
<framework src="src/windows/lib/WinRTBarcodeReader.csproj" custom="true" type="projectReference" versions="<=8.1"/>
<framework src="src/windows/lib.UW/WinRTBarcodeReader.UW.csproj" custom="true" type="projectReference" versions=">8.1"/>

<asset src="src/windows/assets/plugin-barcodeScanner.css" target="css/plugin-barcodeScanner.css" />
</platform>

Expand Down
90 changes: 77 additions & 13 deletions src/windows/BarcodeScannerProxy.js
Expand Up @@ -27,7 +27,7 @@ module.exports = {
closeButton,
capture,
reader;

/**
* Creates a preview frame and necessary objects
*/
Expand Down Expand Up @@ -85,15 +85,15 @@ module.exports = {

if (!controller) {
try {
controller = capture && capture.videoDeviceController
controller = capture && capture.videoDeviceController;
} catch (err) {
console.log('Failed to access focus control for current camera: ' + err);
return result;
}
}

if (!controller.focusControl || !controller.focusControl.supported) {
console.log('Focus control for current camera is not supported')
console.log('Focus control for current camera is not supported');
return result;
}

Expand Down Expand Up @@ -170,7 +170,14 @@ module.exports = {

setupFocus(controller.focusControl)
.then(function () {
startBarcodeSearch(maxResProps.width, maxResProps.height);
return startBarcodeSearch(maxResProps.width, maxResProps.height);
})
.done(function (result) {
destroyPreview();
success({ text: result && result.text, format: result && result.barcodeFormat, cancelled: !result });
}, function (error) {
destroyPreview();
fail(error);
});
});
});
Expand All @@ -182,14 +189,71 @@ module.exports = {
*/
function startBarcodeSearch(width, height) {

reader = new WinRTBarcodeReader.Reader();
reader.init(capture, width, height);
reader.readCode().done(function (result) {
destroyPreview();
success({ text: result && result.text, format: result && result.barcodeFormat, cancelled: !result });
}, function (err) {
destroyPreview();
fail(err);
if (!capture.getPreviewFrameAsync || !ZXing.BarcodeReader) {
// If there is no corresponding API (Win8/8.1/Phone8.1) use old approach with WinMD library
reader = new WinRTBarcodeReader.Reader();
reader.init(capture, width, height);
return reader.readCode();
}

reader = {
_promise: null,
_cancelled: false,
_zxingReader: new ZXing.BarcodeReader(),

readCode: function () {

var self = this;
return scanBarcodeAsync(capture, this._zxingReader, width, height)
.then(function (result) {
if (self._cancelled)
return null;

return result || (self._promise = self.readCode());
});
},

stop: function () {
this._cancelled = true;
}
};

// Add a small timeout before capturing first frame otherwise
// we would get an 'Invalid state' error from 'getPreviewFrameAsync'
return WinJS.Promise.timeout(200)
.then(function () {
return reader.readCode();
});
}

/**
* Grabs a frame from preview stream uning Win10-only API and tries to
* get a barcode using zxing reader provided. If there is no barcode
* found, returns null.
*/
function scanBarcodeAsync(mediaCapture, zxingReader, frameWidth, frameHeight) {
// Shortcuts for namespaces
var Imaging = Windows.Graphics.Imaging;
var Streams = Windows.Storage.Streams;

var frame = new Windows.Media.VideoFrame(Imaging.BitmapPixelFormat.bgra8, frameWidth, frameHeight);
return mediaCapture.getPreviewFrameAsync(frame)
.then(function (capturedFrame) {

// Copy captured frame to buffer for further deserialization
var bitmap = capturedFrame.softwareBitmap;
var rawBuffer = new Streams.Buffer(bitmap.pixelWidth * bitmap.pixelHeight * 4);
capturedFrame.softwareBitmap.copyToBuffer(rawBuffer);
capturedFrame.close();

// Get raw pixel data from buffer
var data = new Uint8Array(rawBuffer.length);
var dataReader = Streams.DataReader.fromBuffer(rawBuffer);
dataReader.readBytes(data);
dataReader.close();

var result = zxingReader.decode(data, frameWidth, frameHeight, ZXing.BitmapFormat.bgra32);
return WinJS.Promise.wrap(result);
});
}

Expand Down Expand Up @@ -221,7 +285,7 @@ module.exports = {
function cancelPreview() {
reader && reader.stop();
}

try {
createPreview();
startPreview();
Expand Down
29 changes: 0 additions & 29 deletions src/windows/lib.UW/Properties/AssemblyInfo.cs

This file was deleted.

173 changes: 0 additions & 173 deletions src/windows/lib.UW/Reader.cs

This file was deleted.

0 comments on commit 521d427

Please sign in to comment.