Skip to content

Commit

Permalink
Add option to control how much size may vary until the prerender cach…
Browse files Browse the repository at this point in the history
…e is cleared
  • Loading branch information
JustAMan committed Mar 25, 2020
1 parent bcf4b5f commit 5256b63
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/subtitles-octopus.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var SubtitlesOctopus = function (options) {
self.prescaleTradeoff = options.prescaleTradeoff || null; // render subtitles less than viewport when less than 1.0 to improve speed, render to more than 1.0 to improve quality; set to null to disable scaling
self.softHeightLimit = options.softHeightLimit || 1080; // don't apply prescaleTradeoff < 1 when viewport height is less that this limit
self.hardHeightLimit = options.hardHeightLimit || 2160; // don't ever go above this limit
self.resizeVariation = options.resizeVariation || 0.2; // by how many a size can vary before it would cause clearance of prerendered buffer

self.renderAhead = options.renderAhead || 0; // how many MiB to render ahead and store; 0 to disable (approximate)
self.isOurCanvas = false; // (internal) we created canvas and manage it
Expand Down Expand Up @@ -403,10 +404,10 @@ var SubtitlesOctopus = function (options) {
function resetRenderAheadCache() {
if (self.renderAhead > 0) {
if (self.oneshotState.prevHeight && self.oneshotState.prevWidth) {
if (self.canvas.height >= self.oneshotState.prevHeight * 0.8 &&
self.canvas.height <= self.oneshotState.prevHeight * 1.2 &&
self.canvas.width >= self.oneshotState.prevWidth * 0.8 &&
self.canvas.width <= self.oneshotState.prevWidth * 1.2) {
if (self.canvas.height >= self.oneshotState.prevHeight * (1.0 - self.resizeVariation) &&
self.canvas.height <= self.oneshotState.prevHeight * (1.0 + self.resizeVariation) &&
self.canvas.width >= self.oneshotState.prevWidth * (1.0 - self.resizeVariation) &&
self.canvas.width <= self.oneshotState.prevWidth * (1.0 + self.resizeVariation)) {
console.debug('not resetting prerender cache - keep using current');
// keep rendering canvas size the same,
// otherwise subtitles got placed incorrectly
Expand Down

0 comments on commit 5256b63

Please sign in to comment.