use of com.helospark.tactview.core.timeline.proceduralclip.ProceduralVisualClip in project tactview by helospark.
the class TimelineImagePatternService method createTimelinePattern.
public Image createTimelinePattern(VisualTimelineClip videoClip, int expectedWidth, double visibleStartPosition, double visibleEndPosition) {
VisualMediaMetadata metadata = videoClip.getMediaMetadata();
int scaledFrameWidth = (int) ((double) metadata.getWidth() / metadata.getHeight() * PREVIEW_HEIGHT);
int scaledFrameHeight = PREVIEW_HEIGHT;
int numberOfFrames = (int) Math.ceil((double) (expectedWidth + BLACK_FILM_TAPE_LINE_WIDTH) / scaledFrameWidth);
double timejump = (visibleEndPosition - visibleStartPosition) / numberOfFrames;
BufferedImage result = new BufferedImage(expectedWidth, RECTANGLE_HEIGHT, TYPE_INT_RGB);
Graphics graphics = result.getGraphics();
graphics.setColor(Color.BLACK);
graphics.fillRect(0, 0, expectedWidth, FILM_TAPE_SIZE);
boolean isDynamicallyGenerated = videoClip instanceof ProceduralVisualClip;
int index = 0;
for (double seconds = visibleStartPosition; seconds < visibleEndPosition; seconds += timejump, ++index) {
TimelinePosition position = TimelinePosition.ofSeconds(seconds);
int width = isDynamicallyGenerated ? uiProjectRepository.getPreviewWidth() : videoClip.getMediaMetadata().getWidth();
int height = isDynamicallyGenerated ? uiProjectRepository.getPreviewHeight() : videoClip.getMediaMetadata().getHeight();
GetFrameRequest frameRequest = GetFrameRequest.builder().withApplyEffects(false).withUseApproximatePosition(true).withExpectedWidth(width).withExpectedHeight(height).withRelativePosition(position).withScale(uiProjectRepository.getScaleFactor()).build();
ReadOnlyClipImage frame = videoClip.getFrame(frameRequest);
if (isDynamicallyGenerated) {
FrameExtendRequest extendFrameRequest = FrameExtendRequest.builder().withClip(videoClip).withFrameResult(frame).withPreviewWidth(uiProjectRepository.getPreviewWidth()).withPreviewHeight(uiProjectRepository.getPreviewHeight()).withScale(uiProjectRepository.getScaleFactor()).withTimelinePosition(position.add(videoClip.getInterval().getStartPosition())).build();
ClipImage expandedFrame = frameExtender.expandFrame(extendFrameRequest);
BufferedImage bf = byteBufferToImageConverter.byteBufferToBufferedImage(expandedFrame.getBuffer(), expandedFrame.getWidth(), expandedFrame.getHeight());
java.awt.Image img = bf.getScaledInstance(scaledFrameWidth, scaledFrameHeight, BufferedImage.SCALE_SMOOTH);
GlobalMemoryManagerAccessor.memoryManager.returnBuffer(frame.getBuffer());
GlobalMemoryManagerAccessor.memoryManager.returnBuffer(expandedFrame.getBuffer());
graphics.drawImage(img, index * (scaledFrameWidth + BLACK_FILM_TAPE_LINE_WIDTH) + BLACK_FILM_TAPE_LINE_WIDTH, FILM_TAPE_SIZE, null);
} else {
BufferedImage bf = byteBufferToImageConverter.byteBufferToBufferedImage(frame.getBuffer(), frame.getWidth(), frame.getHeight());
java.awt.Image img = bf.getScaledInstance(scaledFrameWidth, scaledFrameHeight, BufferedImage.SCALE_SMOOTH);
graphics.drawImage(img, index * (scaledFrameWidth + BLACK_FILM_TAPE_LINE_WIDTH) + BLACK_FILM_TAPE_LINE_WIDTH, FILM_TAPE_SIZE, null);
GlobalMemoryManagerAccessor.memoryManager.returnBuffer(frame.getBuffer());
}
}
dragFilmEffect(expectedWidth, graphics);
return byteBufferToJavaFxImageConverter.convertToJavafxImage(result);
}
use of com.helospark.tactview.core.timeline.proceduralclip.ProceduralVisualClip in project tactview by helospark.
the class ProceduralClipFactory method createClip.
@Override
public TimelineClip createClip(AddClipRequest request) {
ProceduralClipFactoryChainItem proceduralFactory = factories.stream().filter(factory -> factory.doesSupport(request)).findFirst().orElseThrow(() -> new IllegalArgumentException("Nothing can handle " + request));
ProceduralVisualClip proceduralTimelineClip = proceduralFactory.create(request);
proceduralTimelineClip.setProceduralFactoryId(proceduralFactory.getId());
proceduralTimelineClip.setCreatorFactoryId(getId());
return proceduralTimelineClip;
}
use of com.helospark.tactview.core.timeline.proceduralclip.ProceduralVisualClip in project tactview by helospark.
the class ProceduralClipFactory method restoreClip.
@Override
public TimelineClip restoreClip(JsonNode savedClip, LoadMetadata metadata) {
String proceduralFactoryId = savedClip.get("proceduralFactoryId").asText();
ProceduralClipFactoryChainItem proceduralFactory = factories.stream().filter(factory -> factory.getProceduralClipId().equals(proceduralFactoryId)).findFirst().orElseThrow(() -> new IllegalArgumentException("Nothing can handle " + proceduralFactoryId));
ProceduralVisualClip result = proceduralFactory.restoreClip(savedClip, metadata);
result.setProceduralFactoryId(proceduralFactoryId);
return result;
}
Aggregations