{"id":885,"date":"2023-05-16T15:57:06","date_gmt":"2023-05-16T07:57:06","guid":{"rendered":"http:\/\/www.olinone.com\/?p=885"},"modified":"2023-05-16T23:43:18","modified_gmt":"2023-05-16T15:43:18","slug":"pag%e5%8a%a8%e6%95%88%e6%a1%86%e6%9e%b6%e6%ba%90%e7%a0%81%e7%ac%94%e8%ae%b0-%ef%bc%88%e4%ba%8c%ef%bc%89%e5%b1%82%e7%ba%a7%e8%a7%86%e5%9b%be","status":"publish","type":"post","link":"http:\/\/www.olinone.com\/?p=885","title":{"rendered":"PAG\u52a8\u6548\u6846\u67b6\u6e90\u7801\u7b14\u8bb0 \uff08\u4e8c\uff09\u5c42\u7ea7\u89c6\u56fe"},"content":{"rendered":"<p class=\"md-end-block md-p\"><span class=\"md-plain md-expand\">\u8f6c\u8f7d\u8bf7\u6ce8\u660e\u51fa\u5904\uff1a<\/span><span class=\"md-link md-pair-s\" spellcheck=\"false\"><a href=\"http:\/\/www.olinone.com\/\">http:\/\/www.olinone.com\/<\/a><\/span><\/p>\n<p class=\"md-end-block md-p\"><span class=\"md-plain\">\u5982\u4e0a\u7ae0\u6240\u8a00\uff0c\u7279\u6548\u64ad\u653e\u4e3b\u8981\u5305\u62ec\u5e94\u7528\u903b\u8f91\u5904\u7406\u548c\u56fe\u5f62\u6e32\u67d3\u4e24\u4e2a\u9636\u6bb5\uff0c\u5176\u4e2d\uff0c\u903b\u8f91\u5904\u7406\u53c8\u53ef\u4ee5\u770b\u505a\u6a21\u578b\u5bf9\u8c61\u7684\u5b9a\u4e49\u4e0e\u6d41\u8f6c<\/span><\/p>\n<h3 class=\"md-end-block md-heading\"><span class=\"md-plain\">\u6a21\u578b\u5206\u5c42<\/span><\/h3>\n<p class=\"md-end-block md-p\"><span class=\"md-plain\">PAG\u6846\u67b6\u6a21\u578b\u5927\u81f4\u53ef\u4ee5\u5206\u4e3a\u4e09\u90e8\u5206\uff1a<\/span><\/p>\n<p class=\"md-end-block md-p\"><span class=\"md-image md-img-loaded\" data-src=\"http:\/\/cdn.olinone.com\/pag_01_mode_flow.png\"><img decoding=\"async\" src=\"http:\/\/cdn.olinone.com\/pag_01_mode_flow.png\" alt=\"Alt text\" \/><\/span><\/p>\n<h5 class=\"md-end-block md-heading\"><span class=\"md-plain\">1\u3001\u7ec4\u4ef6\uff08PAGCompositon\uff09<\/span><\/h5>\n<p class=\"md-end-block md-p\"><span class=\"md-plain\">PAG\u6846\u67b6\u652f\u6301\u591a\u6587\u4ef6\u591a\u56fe\u5c42\u6e32\u67d3\uff0cPAGCompositon\u7ec4\u4ef6\u53ef\u4ee5\u540c\u65f6\u5bb9\u7eb3\u591a\u4e2aPAGFile\u6587\u4ef6\uff0c\u6bcf\u4e2aPAGFile\u6587\u4ef6\u53c8\u53ef\u4ee5\u5305\u542b\u591a\u4e2aLayer\u7ec4\u4ef6<\/span><\/p>\n<p class=\"md-end-block md-p\"><span class=\"md-plain\">PAGFile\u89e3\u6790\u81eaFile\u6e90\u6587\u4ef6\uff0c\u5176\u4e2dLayer\u7ec4\u4ef6\u53ef\u4ee5\u652f\u6301\u5143\u7d20\u66ff\u6362\uff0c\u6bd4\u5982\u53ef\u4ee5\u66ff\u6362PAGImageLayer\u4e2dPAGImage\u8d44\u6e90\u5bf9\u8c61\uff0c\u4ece\u800c\u5b9e\u73b0\u81ea\u5b9a\u4e49\u878d\u5408\u5143\u7d20<\/span><\/p>\n<h5 class=\"md-end-block md-heading\"><span class=\"md-plain\">2\u3001\u56fe\u5c42\uff08PAGStage\uff09<\/span><\/h5>\n<p class=\"md-end-block md-p\"><span class=\"md-plain\">PAGStage\u627f\u8f7d\u4e86\u5b8c\u6574\u7684\u7ec4\u4ef6\u56fe\u5c42\uff0c\u8bb0\u5f55\u4e86\u6bcf\u4e2a\u7ec4\u4ef6\u53ca\u5176\u8d44\u6e90\u5bf9\u8c61\u7684\u6620\u5c04\u5173\u7cfb\uff0c\u6bd4\u5982PAGImage\u53ca\u5176\u5173\u8054\u7684PAGImageLayer\u5bf9\u8c61\uff0c\u5b9e\u73b0\u901a\u8fc7\u8d44\u6e90\u5bf9\u8c61\u67e5\u627e\u5bf9\u5e94Layer\u5bf9\u8c61\u7684\u80fd\u529b<\/span><\/p>\n<p class=\"md-end-block md-p\"><span class=\"md-plain\">\u6b64\u5916\uff0cPAGStage\u901a\u8fc7SequenceCache\u8fd8\u7f13\u5b58\u4e86\u8d44\u6e90\u5bf9\u8c61\u4e0eGraphic\u89c6\u56fe\u5bf9\u8c61\u7684\u6620\u5c04\u5173\u7cfb\uff0c\u7c7b\u4f3c\u4e8e\u6e32\u67d3\u7f13\u5b58\u7684\u804c\u8d23<\/span><\/p>\n<h5 class=\"md-end-block md-heading\"><span class=\"md-plain\">3\u3001\u56fe\u5f62\uff08LayerGraphic\uff09<\/span><\/h5>\n<p class=\"md-end-block md-p\"><span class=\"md-plain\">\u7ec4\u4ef6\u6a21\u5757\u52a0\u4e0a\u65f6\u95f4\u6233\uff0c\u5c31\u751f\u6210\u5bf9\u5e94\u65f6\u523b\u7684\u56fe\u5f62\u5bf9\u8c61Graphic\uff0c\u6bd4\u5982\u7eb9\u7406\u56fe\u5f62Picture\uff0c\u6216\u8005\u6587\u672c\u56fe\u5f62Text<\/span><\/p>\n<p class=\"md-end-block md-p\"><span class=\"md-plain\">LayerGraphic\u4f5c\u4e3a\u56fe\u5f62\u6a21\u578b\u7684\u5bb9\u5668\uff0c\u7ee7\u627f\u81eaComposeGraphic\u5bf9\u8c61\uff0c\u5305\u542b\u5f53\u524d\u64ad\u653e\u65f6\u523b\u6240\u6709\u7684\u56fe\u50cf\u5bf9\u8c61\uff0c\u6bcf\u4e00\u4e2a\u56fe\u5f62\u5bf9\u8c61\u53ef\u4ee5\u901a\u8fc7\u88c5\u9970\u5668\u6dfb\u52a0\u88c1\u5207\u6216\u8005\u8499\u7248\u7b49\u591a\u79cd\u5904\u7406\u6548\u679c<\/span><\/p>\n<h3 class=\"md-end-block md-heading\"><span class=\"md-plain\">\u6e90\u7801\u6d45\u6790<\/span><\/h3>\n<p class=\"md-end-block md-p\"><span class=\"md-plain\">1\u3001File\u6587\u4ef6\u89e3\u6790<\/span><\/p>\n<pre class=\"lang:objc highlight:0 decode:true\">\/\/ \u6587\u4ef6\u4e8c\u8fdb\u5236\u89e3\u6790\r\nstd::shared_ptr&lt;File&gt; File::Load(const void* bytes, size_t length, const std::string&amp; filePath, const std::string&amp;) {\r\nfile = Codec::Decode(bytes, static_cast&lt;uint32_t&gt;(length), filePath);\r\n...\r\nreturn file;\r\n}\r\n\u200b\r\n\/\/ File\u5bf9\u8c61\u521d\u59cb\u5316\r\nFile::File(std::vector&lt;Composition*&gt; compositionList, std::vector&lt;pag::ImageBytes*&gt; imageList) : images(std::move(imageList)), compositions(std::move(compositionList)) {\r\n\/\/ \u6bcf\u4e00\u4e2aFile\u6587\u4ef6\u90fd\u6709\u5bf9\u5e94\u7684mainComposition\u5bf9\u8c61\uff0c\u7ec4\u4ef6\u5143\u4fe1\u606f\u5176\u5b9e\u90fd\u5b58\u5728compositon\u91cc\u9762\r\nmainComposition = compositions.back();\r\nrootLayer = PreComposeLayer::Wrap(mainComposition).release();\r\n...\r\n}<\/pre>\n<p class=\"md-end-block md-p\"><span class=\"md-plain\">2\u3001PAGFile\u6784\u9020<\/span><\/p>\n<pre class=\"lang:objc highlight:0 decode:true\">\/\/ \u901a\u8fc7File\u6784\u9020PAGFile\r\nstd::shared_ptr&lt;PAGFile&gt; PAGFile::MakeFrom(std::shared_ptr&lt;File&gt; file) {\r\n  \/\/ \u89e3\u6790File\u6784\u9020\u7ec4\u4ef6\u6a21\u578b\r\n  auto pagLayer = BuildPAGLayer(file, file-&gt;getRootLayer());\r\n  pagLayer-&gt;gotoTime(0);\r\n  auto pagFile = std::static_pointer_cast&lt;PAGFile&gt;(pagLayer);\r\n  ...\r\n  return pagFile;\r\n}\r\n\r\n\/\/ \u6bcf\u4e00\u4e2a\u7ec4\u4ef6\u5bf9\u8c61\u5176\u5b9e\u90fd\u6301\u6709\u539f\u59cbFile\u5bf9\u8c61\r\nstd::shared_ptr&lt;PAGLayer&gt; PAGFile::BuildPAGLayer(std::shared_ptr&lt;File&gt; file, Layer* layer) {\r\n  PAGLayer* pagLayer;\r\n  switch (layer-&gt;type()) {\r\n    case LayerType::Text: {\r\n      pagLayer = new PAGTextLayer(file, static_cast&lt;TextLayer*&gt;(layer));\r\n    } break;\r\n    case LayerType::Image: {\r\n      pagLayer = new PAGImageLayer(file, static_cast&lt;ImageLayer*&gt;(layer));\r\n    } break;\r\n    case LayerType::PreCompose: {\r\n      ...\r\n      if (composition-&gt;type() == CompositionType::Vector) {\r\n        auto&amp; layers = static_cast&lt;VectorComposition*&gt;(composition)-&gt;layers;\r\n        \/\/ \u904d\u5386\u7ec4\u4ef6\u5217\u8868\r\n        for (int i = static_cast&lt;int&gt;(layers.size()) - 1; i &gt;= 0; i--) {\r\n          auto childLayer = layers[i];\r\n          auto childPAGLayer = BuildPAGLayer(file, childLayer);\r\n\t\t\t\t\t...\r\n        }\r\n      }\r\n    } break;\r\n  }\r\n}<\/pre>\n<p class=\"md-end-block md-p\"><span class=\"md-plain\">3\u3001PAGStage\u56fe\u5c42\u586b\u5145<\/span><\/p>\n<pre class=\"lang:objc highlight:0 decode:true\">\/\/ PAGComposition\u53ef\u4ee5\u5bb9\u7eb3\u591a\u4e2aPAGFile\r\n- (PAGComposition *)makeComposition {\r\n    PAGComposition* compostion = [PAGComposition Make:self.view.bounds.size];\r\n    PAGFile* file = [PAGFile Load:[[NSBundle mainBundle] pathForResource:@\"data-TimeStretch\" ofType:@\"pag\"]];\r\n    \/\/ \u53ef\u4ee5\u66ff\u6362PAGImage\u8d44\u6e90\u5bf9\u8c61\uff0c\u5e95\u5c42\u5176\u5b9e\u662f\u64cd\u4f5cPAGImageLayer\r\n    [file replaceImage:0 data:[PAGImage FromPath:[[NSBundle mainBundle] pathForResource:@\"test\" ofType:@\"png\"]]];\r\n    [compostion addLayer:file];\r\n    \r\n    file = [PAGFile Load:[[NSBundle mainBundle] pathForResource:@\"data_video\" ofType:@\"pag\"]];\r\n    [compostion addLayer:file atIndex:0];\r\n    return compostion;\r\n}\r\n\r\nvoid PAGPlayer::setComposition(std::shared_ptr&lt;PAGComposition&gt; newComposition) {\r\n  ...\r\n  pagComposition = newComposition;\r\n  if (pagComposition) {\r\n    \/\/ \u586b\u5145\u5bb9\u5668\r\n    stage-&gt;doAddLayer(pagComposition, 0);\r\n  }\r\n}\r\n\r\n\/\/ \u5efa\u7acb\u7d22\u5f15\u7f13\u5b58\r\nvoid PAGStage::addReference(PAGLayer* pagLayer) {\r\n  addToReferenceMap(pagLayer-&gt;uniqueID(), pagLayer);\r\n  addToReferenceMap(pagLayer-&gt;layer-&gt;uniqueID, pagLayer);\r\n  if (pagLayer-&gt;layerType() == LayerType::PreCompose) {\r\n    auto composition = static_cast&lt;PreComposeLayer*&gt;(pagLayer-&gt;layer)-&gt;composition;\r\n    addToReferenceMap(composition-&gt;uniqueID, pagLayer);\r\n  } else if (pagLayer-&gt;layerType() == LayerType::Image) {\r\n    auto imageBytes = static_cast&lt;ImageLayer*&gt;(pagLayer-&gt;layer)-&gt;imageBytes;\r\n    addToReferenceMap(imageBytes-&gt;uniqueID, pagLayer);\r\n    auto pagImage = static_cast&lt;PAGImageLayer*&gt;(pagLayer)-&gt;getPAGImage();\r\n    if (pagImage != nullptr) {\r\n      addReference(pagImage.get(), pagLayer);\r\n    }\r\n  }\r\n\t...\r\n}\r\n\r\n\/\/ \u53ef\u4ee5\u901a\u8fc7\u8d44\u6e90ID\u67e5\u627e\u6e32\u67d3\u7f13\u5b58\r\nstd::shared_ptr&lt;Graphic&gt; PAGStage::getSequenceGraphic(Composition* composition,\r\n                                                      Frame compositionFrame) {\r\n\t...\r\n  SequenceCache cache = {};\r\n  cache.graphic = RenderSequenceComposition(composition, compositionFrame);\r\n  cache.compositionFrame = compositionFrame;\r\n  sequenceCache[composition-&gt;uniqueID] = cache;\r\n  return cache.graphic;\r\n}<\/pre>\n<p class=\"md-end-block md-p\"><span class=\"md-plain\">4\u3001Graphic\u56fe\u5f62\u751f\u6210<\/span><\/p>\n<pre class=\"lang:objc highlight:0 decode:true\">\/\/ \u64ad\u653e\u8fdb\u5ea6\r\nvoid PAGPlayer::setProgress(double percent) {\r\n  auto pagComposition = stage-&gt;getRootComposition();\r\n  ...\r\n  pagComposition-&gt;setProgressInternal(realProgress);\r\n}\r\n\r\n\/\/ \u751f\u6210\u56fe\u5f62\r\nvoid PAGPlayer::prepareInternal() {\r\n  renderCache-&gt;beginFrame();\r\n  auto result = updateStageSize();\r\n  if (result &amp;&amp; contentVersion != stage-&gt;getContentVersion()) {\r\n    contentVersion = stage-&gt;getContentVersion();\r\n    Recorder recorder = {};\r\n    \/\/ \u901a\u8fc7recorder\u8bb0\u5f55\u6bcf\u4e2a\u53ef\u7ed8\u5236\u7ec4\u4ef6Layer\r\n    stage-&gt;draw(&amp;recorder);\r\n    \/\/ \u5bfc\u51fa\u6240\u6709\u56fe\u5f62\u5bf9\u8c61\r\n    lastGraphic = recorder.makeGraphic();\r\n  }\r\n}\r\n\r\n\/\/ recorder\u7c7b\u4f3c\u4e8e\u4e8c\u53c9\u6811\uff0c\u8bb0\u5f55\u4e86\u6bcf\u4e2aLayer\u7ec4\u4ef6\u5f53\u524d\u65f6\u523b\u5bf9\u5e94\u7684Graphic\r\nvoid PAGComposition::draw(Recorder* recorder) {\r\n  ...\r\n  auto composition = preComposeLayer-&gt;composition;\r\n  if (composition-&gt;type() == CompositionType::Bitmap ||\r\n      composition-&gt;type() == CompositionType::Video) {\r\n    auto layerFrame = layer-&gt;startTime + contentFrame;\r\n    auto compositionFrame = preComposeLayer-&gt;getCompositionFrame(layerFrame);\r\n    auto graphic = stage-&gt;getSequenceGraphic(composition, compositionFrame);\r\n    recorder-&gt;drawGraphic(graphic);\r\n  }\r\n\t...\r\n  if (hasClip()) {\r\n    \/\/ \u88c1\u5207\u88c5\u9970\u5668\r\n    recorder-&gt;saveClip(0, 0, static_cast&lt;float&gt;(_width), static_cast&lt;float&gt;(_height));\r\n  }\r\n  \/\/ \u5806\u6808\u6a21\u5f0f\u5904\u7406\u6bcf\u4e2a\u89c6\u56fe\u53ca\u5176\u5b50\u89c6\u56fe\uff0c\u4fdd\u8bc1\u6bcf\u4e2a\u89c6\u56fe\u53ca\u5176\u5b50\u89c6\u56fe\u6e32\u67d3\u73af\u5883\u4e00\u81f4\u6027\uff0c\u6bd4\u5982matrix\u53d8\u5316\u7b49\r\n  for (int i = 0; i &lt; count; i++) {\r\n    DrawChildLayer(recorder, childLayer.get());\r\n  }\r\n  if (hasClip()) {\r\n    recorder-&gt;restore();\r\n  }\r\n}<\/pre>\n<h3>\u603b\u7ed3<\/h3>\n<p>\u4e3a\u4e86\u652f\u6301\u591a\u6587\u4ef6\u591a\u56fe\u5c42\u6e32\u67d3\uff0cPAG\u6846\u67b6\u8bbe\u8ba1\u4e86\u4e00\u5957\u5b8c\u6574\u7684\u6846\u67b6\u6a21\u578b\uff0c\u5176\u590d\u6742\u7684\u5bf9\u8c61\u7ee7\u627f\u5173\u7cfb\uff0c\u52a0\u6df1\u4e86\u4ee3\u7801\u9605\u8bfb\u7406\u89e3\u96be\u5ea6\uff0c\u5728\u7406\u89e3\u5176\u8bbe\u8ba1\u601d\u8def\u540e\uff0c\u624d\u80fd\u77e5\u5176\u7136\u77e5\u5176\u6240\u4ee5\u7136<\/p>\n<hr \/>\n<p><em>\u5199\u5728\u6587\u540e\uff1a<\/em><\/p>\n<p><em>\u672c\u6587\u5e76\u672a\u63d0\u53caFile\u6587\u4ef6\u89e3\u6790\u8fc7\u7a0b\uff0c\u4e3b\u8981\u539f\u56e0\u5728\u4e8e\u6211\u4eec\u9879\u76ee\u4e2d\u7279\u6548\u4f7f\u7528MP4\u6587\u4ef6\u5b9e\u73b0\uff0c\u56e0\u6b64\u6682\u672a\u7ec6\u7814\u5176\u6280\u672f\u7ec6\u8282\uff0c\u540e\u7eed\u6709\u673a\u4f1a\u518d\u5355\u5f00\u7ec6\u804a<\/em><\/p>\n<p><em>PAG\u5b98\u65b9\u6682\u672a\u5f00\u6e90\u6587\u4ef6\u751f\u6210\u6e90\u7801\uff0c\u5982\u679c\u53ea\u662f\u9488\u5bf9\u4f20\u7edf\u7684\u793c\u7269\u7279\u6548\u573a\u666f\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u4f7f\u7528MP4\u4f5c\u4e3a\u66ff\u6362\u5bb9\u5668<\/em><\/p>\n<p>^-^<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8f6c\u8f7d\u8bf7\u6ce8\u660e\u51fa\u5904\uff1ahttp:\/\/www.olinone.com\/ \u5982\u4e0a\u7ae0\u6240\u8a00\uff0c\u7279\u6548\u64ad\u653e\u4e3b\u8981\u5305\u62ec\u5e94\u7528\u903b\u8f91\u5904\u7406\u548c\u56fe\u5f62\u2026 <span class=\"read-more\"><a href=\"http:\/\/www.olinone.com\/?p=885\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[],"_links":{"self":[{"href":"http:\/\/www.olinone.com\/index.php?rest_route=\/wp\/v2\/posts\/885"}],"collection":[{"href":"http:\/\/www.olinone.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.olinone.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.olinone.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.olinone.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=885"}],"version-history":[{"count":11,"href":"http:\/\/www.olinone.com\/index.php?rest_route=\/wp\/v2\/posts\/885\/revisions"}],"predecessor-version":[{"id":899,"href":"http:\/\/www.olinone.com\/index.php?rest_route=\/wp\/v2\/posts\/885\/revisions\/899"}],"wp:attachment":[{"href":"http:\/\/www.olinone.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=885"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.olinone.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=885"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.olinone.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=885"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}