Fix issue with 1px letterbox in atuodetection

This commit is contained in:
Tamius Han 2019-08-24 22:35:56 +02:00
parent d7b3508f85
commit dba9b054d4
3 changed files with 106 additions and 94 deletions

View File

@ -765,11 +765,15 @@ class ArDetector {
if(Debug.debug && Debug.debugArDetect){
console.log(`%c[ArDetect::frameCheck] Triggering aspect ration change! new ar: ${newAr}`, "color: #aaf");
}
this.processAr(newAr);
// we also know edges for guardline, so set them.
// we need to be mindful of fallbackMode though
// if edges are okay and not invalid, we also
// allow automatic aspect ratio correction. If edges
// are bogus, we remain aspect ratio unchanged.
try {
if (!this.fallbackMode) {
// throws error if top/bottom are invalid
this.guardLine.setBlackbar({top: edgePost.guardLineTop, bottom: edgePost.guardLineBottom});
} else {
if (this.conf.player.dimensions){
@ -783,6 +787,14 @@ class ArDetector {
}
}
this.processAr(newAr);
} catch (e) {
// edges weren't gucci, so we'll just reset
// the aspect ratio to defaults
this.guardline.reset();
this.conf.resizer.setAr({type: AspectRatio.Automatic, ratio: this.getDefaultAr()});
}
// }
// else{
// console.log("detected text on edges, dooing nothing")

View File

@ -34,9 +34,7 @@ class GuardLine {
// to odstrani vse neveljavne nastavitve in vse možnosti, ki niso smiselne
// this removes any configs with invalid values or values that dont make sense
if (bbTop < 0 || bbBottom >= this.conf.canvas.height ){
console.log("%c[GuardLine::setBlackbar] INVALID SETTINGS IN GUARDLINE","background: #000; color: #fff")
this.reset();
return;
throw "INVALID_SETTINGS_IN_GUARDLINE"
}
this.blackbar = {

View File

@ -257,7 +257,7 @@ class EdgeDetect{
sampleStart = 0;
sampleEnd = sampleStart + this.sampleWidthBase;
if(sampleEnd > this.conf.canvasImageDataRowLength)
if (sampleEnd > this.conf.canvasImageDataRowLength)
sampleEnd = this.conf.canvasImageDataRowLength;
// calculate row offsets for imageData array
@ -268,7 +268,7 @@ class EdgeDetect{
// even a single black edge violation means the candidate is not an edge
loopEnd = sampleRow_black + sampleEnd;
if(Debug.debugCanvas.enabled){
if (Debug.debugCanvas.enabled){
blackEdgeViolation = this._blackbarTest_dbg(image, sampleRow_black + sampleStart, loopEnd);
} else {
blackEdgeViolation = this._blackbarTest(image, sampleRow_black + sampleStart, loopEnd);
@ -283,7 +283,7 @@ class EdgeDetect{
detections = 0;
loopEnd = sampleRow_color + sampleEnd;
if(Debug.debugCanvas.enabled) {
if (Debug.debugCanvas.enabled) {
this._imageTest_dbg(image, sampleRow_color + sampleStart, loopEnd, sample.black, edgeCandidatesTop)
} else {
this._imageTest(image, sampleRow_color + sampleStart, loopEnd, sample.black, edgeCandidatesTop);
@ -623,7 +623,9 @@ class EdgeDetect{
if (reverseSearchDirection) {
increment = -this.conf.canvasImageDataRowLength;
arrayStart = bottom - this.conf.canvasImageDataRowLength;
// don't subtract this.conf.canvasImageDataRowLength — it has already been accounted for
// when we calculated bottom and top
arrayStart = bottom;
arrayEnd = top;
// this is a hack so we get pointer-like things rather than values