Skip to content

Commit

Permalink
Fix TTML bitmap subtitles
Browse files Browse the repository at this point in the history
+ Use start for anchoring, instead of center.
+ Add the height to the TTML bitmap cue rendering layout.

Issue:#5633
PiperOrigin-RevId: 250519710
  • Loading branch information
AquilesCanta authored and ojw28 committed May 31, 2019
1 parent 082aee6 commit 9da9941
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
3 changes: 3 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

### 2.10.2 ###

* Subtitles:
* TTML: Fix bitmap rendering
([#5633](https://github.com/google/ExoPlayer/pull/5633)).
* UI:
* Allow setting `DefaultTimeBar` attributes on `PlayerView` and
`PlayerControlView`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ private TtmlRegion parseRegionAttributes(
/* lineType= */ Cue.LINE_TYPE_FRACTION,
lineAnchor,
width,
height,
/* textSizeType= */ Cue.TEXT_SIZE_TYPE_FRACTIONAL_IGNORE_PADDING,
/* textSize= */ regionTextHeight);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,11 @@ public List<Cue> getCues(
new Cue(
bitmap,
region.position,
Cue.ANCHOR_TYPE_MIDDLE,
Cue.ANCHOR_TYPE_START,
region.line,
region.lineAnchor,
region.width,
/* height= */ Cue.DIMEN_UNSET));
region.height));
}

// Create text based cues.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
public final @Cue.LineType int lineType;
public final @Cue.AnchorType int lineAnchor;
public final float width;
public final float height;
public final @Cue.TextSizeType int textSizeType;
public final float textSize;

Expand All @@ -39,6 +40,7 @@ public TtmlRegion(String id) {
/* lineType= */ Cue.TYPE_UNSET,
/* lineAnchor= */ Cue.TYPE_UNSET,
/* width= */ Cue.DIMEN_UNSET,
/* height= */ Cue.DIMEN_UNSET,
/* textSizeType= */ Cue.TYPE_UNSET,
/* textSize= */ Cue.DIMEN_UNSET);
}
Expand All @@ -50,6 +52,7 @@ public TtmlRegion(
@Cue.LineType int lineType,
@Cue.AnchorType int lineAnchor,
float width,
float height,
int textSizeType,
float textSize) {
this.id = id;
Expand All @@ -58,6 +61,7 @@ public TtmlRegion(
this.lineType = lineType;
this.lineAnchor = lineAnchor;
this.width = width;
this.height = height;
this.textSizeType = textSizeType;
this.textSize = textSize;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ public void testBitmapPercentageRegion() throws IOException, SubtitleDecoderExce
assertThat(cue.position).isEqualTo(24f / 100f);
assertThat(cue.line).isEqualTo(28f / 100f);
assertThat(cue.size).isEqualTo(51f / 100f);
assertThat(cue.bitmapHeight).isEqualTo(Cue.DIMEN_UNSET);
assertThat(cue.bitmapHeight).isEqualTo(12f / 100f);

cues = subtitle.getCues(4000000);
assertThat(cues).hasSize(1);
Expand All @@ -524,7 +524,7 @@ public void testBitmapPercentageRegion() throws IOException, SubtitleDecoderExce
assertThat(cue.position).isEqualTo(21f / 100f);
assertThat(cue.line).isEqualTo(35f / 100f);
assertThat(cue.size).isEqualTo(57f / 100f);
assertThat(cue.bitmapHeight).isEqualTo(Cue.DIMEN_UNSET);
assertThat(cue.bitmapHeight).isEqualTo(6f / 100f);

cues = subtitle.getCues(7500000);
assertThat(cues).hasSize(1);
Expand All @@ -534,7 +534,7 @@ public void testBitmapPercentageRegion() throws IOException, SubtitleDecoderExce
assertThat(cue.position).isEqualTo(24f / 100f);
assertThat(cue.line).isEqualTo(28f / 100f);
assertThat(cue.size).isEqualTo(51f / 100f);
assertThat(cue.bitmapHeight).isEqualTo(Cue.DIMEN_UNSET);
assertThat(cue.bitmapHeight).isEqualTo(12f / 100f);
}

@Test
Expand All @@ -549,7 +549,7 @@ public void testBitmapPixelRegion() throws IOException, SubtitleDecoderException
assertThat(cue.position).isEqualTo(307f / 1280f);
assertThat(cue.line).isEqualTo(562f / 720f);
assertThat(cue.size).isEqualTo(653f / 1280f);
assertThat(cue.bitmapHeight).isEqualTo(Cue.DIMEN_UNSET);
assertThat(cue.bitmapHeight).isEqualTo(86f / 720f);

cues = subtitle.getCues(4000000);
assertThat(cues).hasSize(1);
Expand All @@ -559,7 +559,7 @@ public void testBitmapPixelRegion() throws IOException, SubtitleDecoderException
assertThat(cue.position).isEqualTo(269f / 1280f);
assertThat(cue.line).isEqualTo(612f / 720f);
assertThat(cue.size).isEqualTo(730f / 1280f);
assertThat(cue.bitmapHeight).isEqualTo(Cue.DIMEN_UNSET);
assertThat(cue.bitmapHeight).isEqualTo(43f / 720f);
}

@Test
Expand Down

0 comments on commit 9da9941

Please sign in to comment.