Search in sources :

Example 1 with ProceduralVisualClip

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);
}
Also used : GetFrameRequest(com.helospark.tactview.core.timeline.GetFrameRequest) ReadOnlyClipImage(com.helospark.tactview.core.timeline.image.ReadOnlyClipImage) ClipImage(com.helospark.tactview.core.timeline.image.ClipImage) BufferedImage(java.awt.image.BufferedImage) Graphics(java.awt.Graphics) ProceduralVisualClip(com.helospark.tactview.core.timeline.proceduralclip.ProceduralVisualClip) ReadOnlyClipImage(com.helospark.tactview.core.timeline.image.ReadOnlyClipImage) FrameExtendRequest(com.helospark.tactview.core.timeline.render.FrameExtender.FrameExtendRequest) VisualMediaMetadata(com.helospark.tactview.core.decoder.VisualMediaMetadata) TimelinePosition(com.helospark.tactview.core.timeline.TimelinePosition)

Example 2 with ProceduralVisualClip

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;
}
Also used : ProceduralVisualClip(com.helospark.tactview.core.timeline.proceduralclip.ProceduralVisualClip) ProceduralClipFactoryChainItem(com.helospark.tactview.core.timeline.proceduralclip.ProceduralClipFactoryChainItem)

Example 3 with ProceduralVisualClip

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;
}
Also used : ProceduralVisualClip(com.helospark.tactview.core.timeline.proceduralclip.ProceduralVisualClip) ProceduralClipFactoryChainItem(com.helospark.tactview.core.timeline.proceduralclip.ProceduralClipFactoryChainItem)

Aggregations

ProceduralVisualClip (com.helospark.tactview.core.timeline.proceduralclip.ProceduralVisualClip)3 ProceduralClipFactoryChainItem (com.helospark.tactview.core.timeline.proceduralclip.ProceduralClipFactoryChainItem)2 VisualMediaMetadata (com.helospark.tactview.core.decoder.VisualMediaMetadata)1 GetFrameRequest (com.helospark.tactview.core.timeline.GetFrameRequest)1 TimelinePosition (com.helospark.tactview.core.timeline.TimelinePosition)1 ClipImage (com.helospark.tactview.core.timeline.image.ClipImage)1 ReadOnlyClipImage (com.helospark.tactview.core.timeline.image.ReadOnlyClipImage)1 FrameExtendRequest (com.helospark.tactview.core.timeline.render.FrameExtender.FrameExtendRequest)1 Graphics (java.awt.Graphics)1 BufferedImage (java.awt.image.BufferedImage)1