MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / run

Method run

tools/png2bmp.js:302–482  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

300 }
301
302 run() {
303 let inputPaths = this.inputPaths;
304 let c = inputPaths.length;
305 let width, height;
306 let buffer;
307 let offset = 0;
308 let y = 0;
309 if (c == 1) {
310 let pngPath = inputPaths[0];
311 let png = new PNG(this.readFileBuffer(pngPath));
312 if (!this.checkPNG(png))
313 throw new Error("'" + pngPath + "': invalid PNG format!");
314 let pngWidth = png.width;
315 let pngHeight = png.height;
316 if ((this.rotation == 0) || (this.rotation == 180)) {
317 width = this.pad(pngWidth);
318 height = pngHeight;
319 }
320 else {
321 width = pngWidth;
322 height = this.pad(pngHeight);
323 }
324 buffer = new Uint8Array(width * height * 4);
325 while (y < pngHeight) {
326 let x = 0;
327 this.transferLine(png, buffer, offset);
328 offset += (pngWidth * 4);
329 x += pngWidth;
330 while (x < width) {
331 buffer[offset++] = 0;
332 buffer[offset++] = 0;
333 buffer[offset++] = 0;
334 buffer[offset++] = 255;
335 x++;
336 }
337 y++;
338 }
339 }
340 else {
341 let pngs = new Array(c).fill();
342 let pngWidth, pngHeight;
343 for (let i = 0; i < c; i++) {
344 let pngPath = inputPaths[i];
345 let png = new PNG(this.readFileBuffer(pngPath));
346 if (!this.checkPNG(png))
347 throw new Error("'" + pngPath + "': invalid PNG format!");
348 if (i == 0) {
349 pngWidth = png.width;
350 pngHeight = png.height;
351 }
352 else {
353 if (pngWidth != png.width)
354 throw new Error("'" + pngPath + "': invalid width!");
355 if (pngHeight != png.height)
356 throw new Error("'" + pngPath + "': invalid height!");
357 }
358 pngs[i] = png;
359 }

Callers

nothing calls this directly

Calls 12

checkPNGMethod · 0.80
transferLineMethod · 0.80
fillMethod · 0.65
beginMethod · 0.65
endMethod · 0.65
padMethod · 0.45
rotate90Method · 0.45
rotate180Method · 0.45
rotate270Method · 0.45
pixelsToBytesMethod · 0.45
processMethod · 0.45
sendMethod · 0.45

Tested by

no test coverage detected