MCPcopy Create free account
hub / github.com/Tencent/libpag / GetGradientColorsFromFileBytes

Method GetGradientColorsFromFileBytes

exporter/src/utils/PAGExportSession.cpp:85–150  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83}
84
85pag::GradientColorHandle PAGExportSession::GetGradientColorsFromFileBytes(
86 const std::vector<std::string>& matchNames, int index, int keyFrameIndex) {
87 if (fileBytes.empty()) {
88 fileBytes = GetProjectFileBytes();
89 }
90 if (fileBytes.empty()) {
91 return GetDefaultGradientColors();
92 }
93
94 ByteArray bytes(reinterpret_cast<uint8_t*>(fileBytes.data()), fileBytes.size());
95 bytes = ReadBody(&bytes);
96 auto compositions = ReadCompositions(&bytes);
97
98 ByteArray layerBytes = {};
99 for (auto& composition : compositions) {
100 if (composition.id == static_cast<int>(compID)) {
101 auto layers = ReadLayers(&composition.bytes);
102 for (const auto& layer : layers) {
103 if (static_cast<pag::ID>(layer.id) == layerID) {
104 layerBytes = layer.bytes;
105 break;
106 }
107 }
108 break;
109 }
110 }
111
112 if (layerBytes.empty()) {
113 return GetDefaultGradientColors();
114 }
115
116 std::string gradientText;
117 for (int i = 0; layerBytes.bytesAvailable() > 0 && i <= index; ++i) {
118 auto groupTag = ReadFirstGroupByMatchNames(&layerBytes, matchNames);
119 if (groupTag.bytes.empty()) {
120 break;
121 }
122
123 if (i == index) {
124 auto tag = ReadFirstTagByName(&groupTag.bytes, "GCky");
125 if (tag.bytes.empty()) {
126 break;
127 }
128
129 int frameIndex = 0;
130 while (tag.bytes.bytesAvailable()) {
131 auto stringTag = ReadTag(&tag.bytes);
132 if (stringTag.bytes.empty()) {
133 break;
134 }
135 if (frameIndex == keyFrameIndex) {
136 if (!stringTag.bytes.empty() && stringTag.bytes.bytesAvailable() > 0) {
137 if (stringTag.bytes.position() < stringTag.bytes.length()) {
138 gradientText = stringTag.bytes.readUTF8String();
139 }
140 }
141 break;
142 }

Callers 1

getGradientColorsMethod · 0.80

Calls 15

GetProjectFileBytesFunction · 0.85
GetDefaultGradientColorsFunction · 0.85
ReadBodyFunction · 0.85
ReadCompositionsFunction · 0.85
ReadLayersFunction · 0.85
ReadFirstTagByNameFunction · 0.85
ReadTagFunction · 0.85
XmlToGradientColorFunction · 0.85
emptyMethod · 0.80
sizeMethod · 0.80
dataMethod · 0.45

Tested by

no test coverage detected