Skip to content

Commit

Permalink
Add option to limit canvas size
Browse files Browse the repository at this point in the history
JSO struggles with complex subtitles on HiDPI canvasses,
so limiting the size can make sense if such subtitles are expected.

This was ported from jellyfin's fork and jellyfin-web uses this on at
least some devices. In the original implementation prescaleHeightLimit
would override maxRenderHeight if it was larger. This undocumentend
behaviour was dropped here as it seemed unintuitive and unhelpful.

[Vasily <[email protected]>]
  Original implementation together with prescaling in
  jellyfin@345d701
  jellyfin@4c5f018
[Dmitry Lyzo]
  Rebased for upstream; seperated from the prescaling;
  removed default height limit and added docs
[Oneric]
  Renamed hardHeightLimit to maxRenderHeight;
  split from prescaling.

Co-Authored-By: Dmitry Lyzo <[email protected]>
  • Loading branch information
2 people authored and TheOneric committed Feb 16, 2022
1 parent e9fc7c5 commit 5ebf13d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ When creating an instance of SubtitleOctopus, you can set the following options:
(Default: `1.0` - no scaling; must be a number > 0)
- `prescaleHeightLimit`: The height beyond which the subtitles canvas won't be prescaled.
(Default: `1080`)
- `maxRenderHeight`: The maximum rendering height of the subtitles canvas.
Beyond this subtitles will be upscaled by the browser.
(Default: `0` - no limit)

### Rendering Modes
#### JS Blending
Expand Down
4 changes: 4 additions & 0 deletions src/subtitles-octopus.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var SubtitlesOctopus = function (options) {
self.targetFps = options.targetFps || 24;
self.prescaleFactor = options.prescaleFactor || 1.0;
self.prescaleHeightLimit = options.prescaleHeightLimit || 1080;
self.maxRenderHeight = options.maxRenderHeight || 0; // 0 - no limit
self.isOurCanvas = false; // (internal) we created canvas and manage it
self.video = options.video; // HTML video element (optional if canvas specified)
self.canvasParent = null; // (internal) HTML canvas parent element
Expand Down Expand Up @@ -420,6 +421,9 @@ var SubtitlesOctopus = function (options) {
else if (sgn * newH < sgn * self.prescaleHeightLimit)
newH = self.prescaleHeightLimit;

if (self.maxRenderHeight > 0 && newH > self.maxRenderHeight)
newH = self.maxRenderHeight;

width *= newH / height;
height = newH;
}
Expand Down

0 comments on commit 5ebf13d

Please sign in to comment.