File indexing completed on 2024-12-22 04:12:14
0001 /* 0002 * SPDX-FileCopyrightText: 2019 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.1-or-later 0005 */ 0006 0007 #include "KisAnimationRenderingOptions.h" 0008 0009 #include <QStandardPaths> 0010 #include <QFileInfo> 0011 0012 #include <KisFileUtils.h> 0013 0014 KisAnimationRenderingOptions::KisAnimationRenderingOptions() 0015 : videoMimeType("video/mp4"), 0016 frameMimeType("image/png"), 0017 basename("frame"), 0018 directory("") 0019 { 0020 0021 } 0022 0023 QString KisAnimationRenderingOptions::resolveAbsoluteDocumentFilePath(const QString &documentPath) const 0024 { 0025 return 0026 !documentPath.isEmpty() ? 0027 documentPath : 0028 QStandardPaths::writableLocation(QStandardPaths::PicturesLocation); 0029 } 0030 0031 QString KisAnimationRenderingOptions::resolveAbsoluteVideoFilePath(const QString &documentPath) const 0032 { 0033 const QString basePath = resolveAbsoluteDocumentFilePath(documentPath); 0034 return KritaUtils::resolveAbsoluteFilePath(basePath, videoFileName); 0035 } 0036 0037 QString KisAnimationRenderingOptions::resolveAbsoluteFramesDirectory(const QString &documentPath) const 0038 { 0039 if (renderMode() == RENDER_VIDEO_ONLY) { 0040 return QFileInfo(resolveAbsoluteVideoFilePath()).absolutePath(); 0041 } 0042 0043 const QString basePath = resolveAbsoluteDocumentFilePath(documentPath); 0044 return KritaUtils::resolveAbsoluteFilePath(basePath, directory); 0045 } 0046 0047 QString KisAnimationRenderingOptions::resolveAbsoluteVideoFilePath() const 0048 { 0049 return resolveAbsoluteVideoFilePath(lastDocumentPath); 0050 } 0051 0052 QString KisAnimationRenderingOptions::resolveAbsoluteFramesDirectory() const 0053 { 0054 return resolveAbsoluteFramesDirectory(lastDocumentPath); 0055 } 0056 0057 KisAnimationRenderingOptions::RenderMode KisAnimationRenderingOptions::renderMode() const 0058 { 0059 if (shouldDeleteSequence) { 0060 KIS_SAFE_ASSERT_RECOVER_NOOP(shouldEncodeVideo); 0061 return RENDER_VIDEO_ONLY; 0062 } else if (!shouldEncodeVideo) { 0063 KIS_SAFE_ASSERT_RECOVER_NOOP(!shouldDeleteSequence); 0064 return RENDER_FRAMES_ONLY; 0065 } else { 0066 return RENDER_FRAMES_AND_VIDEO; 0067 } 0068 } 0069 0070 KisPropertiesConfigurationSP KisAnimationRenderingOptions::toProperties() const 0071 { 0072 KisPropertiesConfigurationSP config = new KisPropertiesConfiguration(); 0073 0074 config->setProperty("basename", basename); 0075 config->setProperty("last_document_path", lastDocumentPath); 0076 config->setProperty("directory", directory); 0077 config->setProperty("first_frame", firstFrame); 0078 config->setProperty("last_frame", lastFrame); 0079 config->setProperty("sequence_start", sequenceStart); 0080 config->setProperty("video_mimetype", videoMimeType); 0081 config->setProperty("frame_mimetype", frameMimeType); 0082 0083 config->setProperty("encode_video", shouldEncodeVideo); 0084 config->setProperty("delete_sequence", shouldDeleteSequence); 0085 config->setProperty("only_unique_frames", wantsOnlyUniqueFrameSequence); 0086 0087 config->setProperty("ffmpeg_path", ffmpegPath); 0088 config->setProperty("framerate", frameRate); 0089 config->setProperty("height", height); 0090 config->setProperty("width", width); 0091 config->setProperty("include_audio", includeAudio); 0092 config->setProperty("filename", videoFileName); 0093 config->setProperty("custom_ffmpeg_options", customFFMpegOptions); 0094 0095 config->setPrefixedProperties("frame_export/", frameExportConfig); 0096 0097 return config; 0098 } 0099 0100 void KisAnimationRenderingOptions::fromProperties(KisPropertiesConfigurationSP config) 0101 { 0102 basename = config->getPropertyLazy("basename", basename); 0103 lastDocumentPath = config->getPropertyLazy("last_document_path", ""); 0104 directory = config->getPropertyLazy("directory", directory); 0105 firstFrame = config->getPropertyLazy("first_frame", 0); 0106 lastFrame = config->getPropertyLazy("last_frame", 0); 0107 sequenceStart = config->getPropertyLazy("sequence_start", 0); 0108 videoMimeType = config->getPropertyLazy("video_mimetype", videoMimeType); 0109 frameMimeType = config->getPropertyLazy("frame_mimetype", frameMimeType); 0110 0111 shouldEncodeVideo = config->getPropertyLazy("encode_video", false); 0112 shouldDeleteSequence = config->getPropertyLazy("delete_sequence", false); 0113 wantsOnlyUniqueFrameSequence = config->getPropertyLazy("only_unique_frames", false); 0114 0115 ffmpegPath = config->getPropertyLazy("ffmpeg_path", ""); 0116 frameRate = config->getPropertyLazy("framerate", 25); 0117 height = config->getPropertyLazy("height", 0); 0118 width = config->getPropertyLazy("width", 0); 0119 includeAudio = config->getPropertyLazy("include_audio", true); 0120 videoFileName = config->getPropertyLazy("filename", ""); 0121 customFFMpegOptions = config->getPropertyLazy("custom_ffmpeg_options", ""); 0122 0123 frameExportConfig = new KisPropertiesConfiguration(); 0124 frameExportConfig->setPrefixedProperties("frame_export/", frameExportConfig); 0125 0126 }