-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor some of: utils, jsfeat, Tracker
- Loading branch information
Showing
8 changed files
with
198 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export const requestAnimFrame = (function () { | ||
return window.requestAnimationFrame || | ||
window.webkitRequestAnimationFrame || | ||
window.mozRequestAnimationFrame || | ||
window.oRequestAnimationFrame || | ||
window.msRequestAnimationFrame || | ||
function(/* function FrameRequestCallback */ callback, /* DOMElement Element */ element) { | ||
return window.setTimeout(callback, 1000 / 60); | ||
}; | ||
})(); | ||
|
||
export const cancelRequestAnimFrame = (function () { | ||
return window.cancelAnimationFrame || | ||
window.webkitCancelRequestAnimationFrame || | ||
window.mozCancelRequestAnimationFrame || | ||
window.oCancelRequestAnimationFrame || | ||
window.msCancelRequestAnimationFrame || | ||
window.clearTimeout; | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// function to draw pixeldata on some canvas, only used for debugging | ||
export const drawData = (canvasContext, data, width, height, transposed, drawX, drawY) => { | ||
const psci = canvasContext.createImageData(width, height); | ||
const pscidata = psci.data; | ||
for (let j = 0; j < width * height; j++) { | ||
let val; | ||
if (!transposed) { | ||
val = data[(j % width) + ((j / width) >> 0) * width]; | ||
} else { | ||
val = data[(j % height) * height + ((j / height) >> 0)]; | ||
} | ||
val = val > 255 ? 255 : val; | ||
val = val < 0 ? 0 : val; | ||
pscidata[j * 4] = val; | ||
pscidata[(j * 4) + 1] = val; | ||
pscidata[(j * 4) + 2] = val; | ||
pscidata[(j * 4) + 3] = 255; | ||
} | ||
canvasContext.putImageData(psci, drawX, drawY); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
let VIDEO_EL; | ||
|
||
const getVideoEl = () => { | ||
if (!VIDEO_EL) { | ||
VIDEO_EL = document.createElement('video'); | ||
} | ||
return VIDEO_EL; | ||
}; | ||
|
||
|
||
export const supportsVideo = () => { | ||
return !!getVideoEl().canPlayType; | ||
}; | ||
|
||
|
||
export const supportsH264BaselineVideo = () => { | ||
if (!supportsVideo()) { | ||
return false; | ||
} | ||
return getVideoEl().canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"'); | ||
}; | ||
|
||
|
||
export const supportsOggTheoraVideo = () => { | ||
if (!supportsVideo()) { | ||
return false; | ||
} | ||
return getVideoEl().canPlayType('video/ogg; codecs="theora, vorbis"'); | ||
}; | ||
|
||
|
||
export const URL = ( | ||
window.URL || window.webkitURL || window.msURL || window.mozURL | ||
); | ||
|
||
|
||
export const getUserMedia = ( | ||
navigator.getUserMedia || | ||
navigator.webkitGetUserMedia || | ||
navigator.mozGetUserMedia || | ||
navigator.msGetUserMedia | ||
); | ||
|
||
|
||
export const supportsUserMedia = () => { | ||
return !!getUserMedia; | ||
}; | ||
|
||
|
||
export const supportsWebGL = () => { | ||
let webGLContext; | ||
let webGLTestCanvas = document.createElement('canvas'); | ||
|
||
if (!window.WebGLRenderingContext) { | ||
return false; | ||
} | ||
|
||
webGLContext = ( | ||
webGLTestCanvas.getContext('webgl') || | ||
webGLTestCanvas.getContext('experimental-webgl') | ||
); | ||
|
||
if (!webGLContext || !webGLContext.getExtension('OES_texture_float')) { | ||
webGLContext = null; | ||
} | ||
|
||
return webGLContext != null; | ||
}; | ||
|
||
|
||
export const loadVideo = (cb) => { | ||
if (!getUserMedia) { | ||
cb(new Error('browser does not support getUserMedia')); | ||
return; | ||
} | ||
// set up stream | ||
|
||
let videoSelector = { video: true }; | ||
const appVersion = window.navigator.appVersion; | ||
if (appVersion.match(/Chrome\/(.*?) /)) { | ||
const chromeVersion = parseInt( | ||
appVersion.match(/Chrome\/(\d+)\./)[1], | ||
10 | ||
); | ||
if (chromeVersion < 20) { | ||
videoSelector = 'video'; | ||
} | ||
}; | ||
|
||
getUserMedia(videoSelector, (stream) => { | ||
cb(null, stream); | ||
}, () => { | ||
cb(new Error('problem trying to fetch video from your webcam')); | ||
}); | ||
}; | ||
|
||
|
||
export const setVideoSrc = (videoEl, src) => { | ||
if (videoEl.mozCaptureStream) { | ||
videoEl.mozSrcObject = src; | ||
} else { | ||
videoEl.src = (URL && URL.createObjectURL(src)) || src; | ||
} | ||
} |