Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 307x 307x 307x 307x 10x 307x 297x 297x 297x 10x 10x | interface ImageIdToPrefetch {
imageId: string;
imageIdIndex: number;
}
export default function getInterleavedFrames(imageIds: string[]): ImageIdToPrefetch[] {
Iif (imageIds.length === 0) {
return [];
}
Iif (imageIds.length === 1) {
return [{ imageId: imageIds[0], imageIdIndex: 0 }];
}
const minImageIdIndex = 0;
const maxImageIdIndex = imageIds.length - 1;
const middleImageIdIndex = Math.floor(imageIds.length / 2);
let lowerImageIdIndex = middleImageIdIndex;
let upperImageIdIndex = middleImageIdIndex;
// Build up an array of images to prefetch, starting with the current image.
const imageIdsToPrefetch: ImageIdToPrefetch[] = [
{ imageId: imageIds[middleImageIdIndex], imageIdIndex: middleImageIdIndex },
];
const prefetchQueuedFilled = {
currentPositionDownToMinimum: false,
currentPositionUpToMaximum: false,
};
// Check if on edges and some criteria is already fulfilled
Iif (middleImageIdIndex === minImageIdIndex) {
prefetchQueuedFilled.currentPositionDownToMinimum = true;
} else Iif (middleImageIdIndex === maxImageIdIndex) {
prefetchQueuedFilled.currentPositionUpToMaximum = true;
}
while (
!prefetchQueuedFilled.currentPositionDownToMinimum ||
!prefetchQueuedFilled.currentPositionUpToMaximum
) {
if (!prefetchQueuedFilled.currentPositionDownToMinimum) {
// Add imageId below
lowerImageIdIndex--;
imageIdsToPrefetch.push({
imageId: imageIds[lowerImageIdIndex],
imageIdIndex: lowerImageIdIndex,
});
if (lowerImageIdIndex === minImageIdIndex) {
prefetchQueuedFilled.currentPositionDownToMinimum = true;
}
}
if (!prefetchQueuedFilled.currentPositionUpToMaximum) {
// Add imageId above
upperImageIdIndex++;
imageIdsToPrefetch.push({
imageId: imageIds[upperImageIdIndex],
imageIdIndex: upperImageIdIndex,
});
if (upperImageIdIndex === maxImageIdIndex) {
prefetchQueuedFilled.currentPositionUpToMaximum = true;
}
}
}
return imageIdsToPrefetch;
}
|