Commit 28a3921a by Arnold Szabo

Add color decoding tests to SsaDecoderTest, remove SubStation Alpha colors" from…

Add color decoding tests to SsaDecoderTest, remove SubStation Alpha colors" from media.exolist.json.
parent f8a47bc8
...@@ -507,13 +507,6 @@ ...@@ -507,13 +507,6 @@
"subtitle_language": "en" "subtitle_language": "en"
}, },
{ {
"name": "SubStation Alpha colors",
"uri": "https://storage.googleapis.com/exoplayer-test-media-1/gen-3/screens/dash-vod-single-segment/video-avc-baseline-480.mp4",
"subtitle_uri": "https://drive.google.com/uc?export=download&id=13EdW4Qru-vQerUlwS_Ht5Cely_Tn0tQe",
"subtitle_mime_type": "text/x-ssa",
"subtitle_language": "en"
},
{
"name": "MPEG-4 Timed Text", "name": "MPEG-4 Timed Text",
"uri": "https://storage.googleapis.com/exoplayer-test-media-1/mp4/dizzy-with-tx3g.mp4" "uri": "https://storage.googleapis.com/exoplayer-test-media-1/mp4/dizzy-with-tx3g.mp4"
} }
......
...@@ -18,7 +18,10 @@ package com.google.android.exoplayer2.text.ssa; ...@@ -18,7 +18,10 @@ package com.google.android.exoplayer2.text.ssa;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage; import static com.google.common.truth.Truth.assertWithMessage;
import android.graphics.Color;
import android.text.Layout; import android.text.Layout;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import androidx.test.core.app.ApplicationProvider; import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.testutil.TestUtil; import com.google.android.exoplayer2.testutil.TestUtil;
...@@ -44,6 +47,7 @@ public final class SsaDecoderTest { ...@@ -44,6 +47,7 @@ public final class SsaDecoderTest {
private static final String INVALID_TIMECODES = "media/ssa/invalid_timecodes"; private static final String INVALID_TIMECODES = "media/ssa/invalid_timecodes";
private static final String INVALID_POSITIONS = "media/ssa/invalid_positioning"; private static final String INVALID_POSITIONS = "media/ssa/invalid_positioning";
private static final String POSITIONS_WITHOUT_PLAYRES = "media/ssa/positioning_without_playres"; private static final String POSITIONS_WITHOUT_PLAYRES = "media/ssa/positioning_without_playres";
private static final String COLORS = "media/ssa/colors";
@Test @Test
public void decodeEmpty() throws IOException { public void decodeEmpty() throws IOException {
...@@ -267,6 +271,46 @@ public final class SsaDecoderTest { ...@@ -267,6 +271,46 @@ public final class SsaDecoderTest {
assertTypicalCue3(subtitle, 0); assertTypicalCue3(subtitle, 0);
} }
@Test
public void decodeColors() throws IOException {
SsaDecoder decoder = new SsaDecoder();
byte[] bytes = TestUtil.getByteArray(ApplicationProvider.getApplicationContext(), COLORS);
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
assertThat(subtitle.getEventTimeCount()).isEqualTo(12);
// &H000000FF (AABBGGRR) -> #FFFF0000 (AARRGGBB)
Cue firstCue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(0)));
ForegroundColorSpan firstSpan = getSpan(firstCue, ForegroundColorSpan.class);
assertThat(firstSpan.getForegroundColor()).isEqualTo(Color.RED);
// &H0000FFFF (AABBGGRR) -> #FFFFFF00 (AARRGGBB)
Cue secondCue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(2)));
ForegroundColorSpan secondSpan = getSpan(secondCue, ForegroundColorSpan.class);
assertThat(secondSpan.getForegroundColor()).isEqualTo(Color.YELLOW);
// &HFF00 (GGRR) -> #FF00FF00 (AARRGGBB)
Cue thirdClue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(4)));
ForegroundColorSpan thirdSpan = getSpan(thirdClue, ForegroundColorSpan.class);
assertThat(thirdSpan.getForegroundColor()).isEqualTo(Color.GREEN);
// &H400000FF (AABBGGRR) -> #BFFF0000 (AARRGGBB) -> -1073807360
Cue forthClue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(6)));
ForegroundColorSpan forthSpan = getSpan(forthClue, ForegroundColorSpan.class);
assertThat(forthSpan.getForegroundColor()).isEqualTo(-1073807360);
// 16711680 (AABBGGRR) -> &H00FF0000 (AABBGGRR) -> #FF0000FF (AARRGGBB) -> -16776961
Cue fifthClue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(8)));
ForegroundColorSpan fifthSpan = getSpan(fifthClue, ForegroundColorSpan.class);
assertThat(fifthSpan.getForegroundColor()).isEqualTo(-16776961);
// 2164195328 (AABBGGRR) -> &H80FF0000 (AABBGGRR) -> #7F0000FF (AARRGGBB) -> 2130706687
Cue sixthClue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(10)));
ForegroundColorSpan sixthSpan = getSpan(sixthClue, ForegroundColorSpan.class);
assertThat(sixthSpan.getForegroundColor()).isEqualTo(2130706687);
}
private static <T> T getSpan(Cue cue, Class<T> clazz) {
return getSpan(cue, 0, cue.text.length(), clazz);
}
private static <T> T getSpan(Cue cue, int start, int end, Class<T> clazz) {
return SpannableString.valueOf(cue.text).getSpans(start, end, clazz)[0];
}
private static void assertTypicalCue1(Subtitle subtitle, int eventIndex) { private static void assertTypicalCue1(Subtitle subtitle, int eventIndex) {
assertThat(subtitle.getEventTime(eventIndex)).isEqualTo(0); assertThat(subtitle.getEventTime(eventIndex)).isEqualTo(0);
assertThat(subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString()) assertThat(subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString())
......
[Script Info]
Title: Coloring
Script Type: V4.00+
PlayResX: 1280
PlayResY: 720
[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: PrimaryColourStyleHexRed ,Roboto,50,&H000000FF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,3,0,2,50,50,70,1
Style: PrimaryColourStyleHexYellow ,Roboto,50,&H0000FFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,3,0,2,50,50,70,1
Style: PrimaryColourStyleHexGreen ,Roboto,50,&HFF00 ,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,3,0,2,50,50,70,1
Style: PrimaryColourStyleHexAlpha ,Roboto,50,&H400000FF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,3,0,2,50,50,70,1
Style: PrimaryColourStyleDecimal ,Roboto,50,16711680 ,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,3,0,2,50,50,70,1
Style: PrimaryColourStyleDecimalAlpha ,Roboto,50,2164195328,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,3,0,2,50,50,70,1
[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:00:00.95,0:00:03.11,PrimaryColourStyleHexRed ,Arnold,0,0,0,,First line in RED (&H000000FF).
Dialogue: 0,0:00:04.50,0:00:07.50,PrimaryColourStyleHexYellow ,Arnold,0,0,0,,Second line in YELLOW (&H0000FFFF).
Dialogue: 0,0:00:08.50,0:00:11.50,PrimaryColourStyleHexGreen ,Arnold,0,0,0,,Third line in GREEN (leading zeros &HFF00).
Dialogue: 0,0:00:12.50,0:00:15.50,PrimaryColourStyleHexAlpha ,Arnold,0,0,0,,Fourth line in RED with alpha (&H400000FF).
Dialogue: 0,0:00:16.50,0:00:19.50,PrimaryColourStyleDecimal ,Arnold,0,0,0,,Fifth line in BLUE (16711680).
Dialogue: 0,0:00:20.70,0:00:23.00,PrimaryColourStyleDecimalAlpha ,Arnold,0,0,0,,Sixth line in BLUE with alpha (2164195328).
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment