Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add durationPerFrame to Frameset #507

Merged
merged 1 commit into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ public List<Frameset> getFrames() throws ExtractionException {

for (int i = 1; i < spec.length; ++i) {
final String[] parts = spec[i].split("#");
if (parts.length != 8) {
if (parts.length != 8 || Integer.parseInt(parts[5]) == 0) {
continue;
}
final int frameWidth = Integer.parseInt(parts[0]);
Expand All @@ -1016,6 +1016,7 @@ public List<Frameset> getFrames() throws ExtractionException {
frameWidth,
frameHeight,
totalCount,
Integer.parseInt(parts[5]),
framesPerPageX,
framesPerPageY
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ public final class Frameset {
private int frameWidth;
private int frameHeight;
private int totalCount;
private int durationPerFrame;
private int framesPerPageX;
private int framesPerPageY;

public Frameset(List<String> urls, int frameWidth, int frameHeight, int totalCount, int framesPerPageX, int framesPerPageY) {
public Frameset(List<String> urls, int frameWidth, int frameHeight, int totalCount, int durationPerFrame, int framesPerPageX, int framesPerPageY) {
this.urls = urls;
this.totalCount = totalCount;
this.durationPerFrame = durationPerFrame;
this.frameWidth = frameWidth;
this.frameHeight = frameHeight;
this.framesPerPageX = framesPerPageX;
Expand Down Expand Up @@ -61,4 +63,48 @@ public int getFrameWidth() {
public int getFrameHeight() {
return frameHeight;
}

/**
* @return duration per frame in milliseconds
*/
public int getDurationPerFrame() {
return durationPerFrame;
}

/**
* Returns the information for the frame at stream position.
*
* @param position Position in milliseconds
* @return An <code>int</code>-array containing the bounds and URL where the indexes are specified as
* followed:
*
* <ul>
* <li><code>0</code>: Index of the URL</li>
* <li><code>1</code>: Left bound</li>
* <li><code>2</code>: Top bound</li>
* <li><code>3</code>: Right bound</li>
* <li><code>4</code>: Bottom bound</li>
* </ul>
*/
public int[] getFrameBoundsAt(long position) {
if (position < 0 || position > ((totalCount + 1) * durationPerFrame)) {
// Return the first frame as fallback
return new int[] { 0, 0, 0, frameWidth, frameHeight };
}

final int framesPerStoryboard = framesPerPageX * framesPerPageY;
final int absoluteFrameNumber = Math.min((int) (position / durationPerFrame), totalCount);

final int relativeFrameNumber = absoluteFrameNumber % framesPerStoryboard;

final int rowIndex = Math.floorDiv(relativeFrameNumber, framesPerPageX);
final int columnIndex = relativeFrameNumber % framesPerPageY;

return new int[] {
/* storyboardIndex */ Math.floorDiv(absoluteFrameNumber, framesPerStoryboard),
/* left */ columnIndex * frameWidth,
/* top */ rowIndex * frameHeight,
/* right */ columnIndex * frameWidth + frameWidth,
/* bottom */ rowIndex * frameHeight + frameHeight };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ public void testFrames() throws Exception {
assertIsValidUrl(url);
assertIsSecureUrl(url);
}
assertTrue(f.getDurationPerFrame() > 0);
assertEquals(f.getFrameBoundsAt(0)[3], f.getFrameWidth());
}
} else {
assertTrue(frames.isEmpty());
Expand Down