MCPcopy Create free account
hub / github.com/32comic/image2pixel-web / parseGplWithMeta

Function parseGplWithMeta

scripts/convert-bead-palettes.js:136–176  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

134];
135
136function parseGplWithMeta(text) {
137 const lines = text.split(/\r?\n/);
138 const colors = [];
139 const meta = { brand: null, codeMap: {} };
140 let lastColorKey = null;
141
142 for (const line of lines) {
143 const trimmed = line.trim();
144
145 if (trimmed.startsWith('# META:')) {
146 const content = trimmed.substring(7).trim();
147 const eqIndex = content.indexOf('=');
148 if (eqIndex > 0) {
149 const key = content.substring(0, eqIndex).trim();
150 const value = content.substring(eqIndex + 1).trim();
151 if (key === 'brand') meta.brand = value;
152 }
153 continue;
154 }
155
156 if (trimmed.startsWith('# CODE:')) {
157 const code = trimmed.substring(7).trim();
158 if (lastColorKey) meta.codeMap[lastColorKey] = code;
159 continue;
160 }
161
162 if (!trimmed || trimmed.startsWith('#') || trimmed.toLowerCase().startsWith('gimp palette') || trimmed.toLowerCase().startsWith('name:') || trimmed.toLowerCase().startsWith('columns:')) continue;
163
164 const parts = trimmed.split(/\s+/);
165 if (parts.length >= 3) {
166 const r = parseInt(parts[0], 10);
167 const g = parseInt(parts[1], 10);
168 const b = parseInt(parts[2], 10);
169 if (!isNaN(r) && !isNaN(g) && !isNaN(b)) {
170 colors.push([r, g, b]);
171 lastColorKey = `${r},${g},${b}`;
172 }
173 }
174 }
175 return { colors, meta };
176}
177
178function convertPerlerCodeMap(codeMap) {
179 const newCodeMap = {};

Callers 1

Calls 1

splitMethod · 0.45

Tested by

no test coverage detected