/var/www/greso.tech/server/nsm/node_modules/pngjs/coverage/lcov-report
NameSizeModeActions
base.css54620644editdlrm
bitmapper.js.html352720644editdlrm
bitpacker.js.html269970644editdlrm
block-navigation.js21220644editdlrm
chunkstream.js.html255310644editdlrm
constants.js.html64900644editdlrm
crc.js.html73470644editdlrm
favicon.png5400644editdlrm
filter-pack.js.html237360644editdlrm
filter-parse-async.js.html55870644editdlrm
filter-parse-sync.js.html52500644editdlrm
filter-parse.js.html240040644editdlrm
format-normaliser.js.html137590644editdlrm
index.html187730644editdlrm
interlace.js.html134990644editdlrm
packer-async.js.html86100644editdlrm
packer-sync.js.html103690644editdlrm
packer.js.html190950644editdlrm
paeth-predictor.js.html47160644editdlrm
parser-async.js.html232050644editdlrm
parser-sync.js.html156030644editdlrm
parser.js.html387420644editdlrm
png-sync.js.html43090644editdlrm
png.js.html285510644editdlrm
prettify.css10600644editdlrm
prettify.js272070644editdlrm
sort-arrow-sprite.png2090644editdlrm
sorter.js44950644editdlrm
sync-inflate.js.html242340644editdlrm
sync-reader.js.html84360644editdlrm
Edit: /var/www/greso.tech/server/nsm/node_modules/pngjs/coverage/lcov-report/format-normaliser.js.html (13759B)
Code coverage report for format-normaliser.js

All files format-normaliser.js

98.21% Statements 55/56
95.24% Branches 20/21
100% Functions 4/4
97.87% Lines 46/47

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94      131x   131x 4912x 1418436x   1418436x       1418436x 5673744x   1418436x           12x 12x 384x 12288x   12288x 6144x 2762x   6144x         2718x   12288x 5480x 21920x     12288x           106x 106x 106x   106x 3392x 108544x 434176x       108544x         1x 335x 335x 335x 335x 335x 335x   335x   335x   131x   204x 12x     204x   106x 66x   106x     335x    
"use strict";
 
function dePalette(indata, outdata, width, height, palette) {
  let pxPos = 0;
  // use values from palette
  for (let y = 0; y < height; y++) {
    for (let x = 0; x < width; x++) {
      let color = palette[indata[pxPos]];
 
      Iif (!color) {
        throw new Error("index " + indata[pxPos] + " not in palette");
      }
 
      for (let i = 0; i < 4; i++) {
        outdata[pxPos + i] = color[i];
      }
      pxPos += 4;
    }
  }
}
 
function replaceTransparentColor(indata, outdata, width, height, transColor) {
  let pxPos = 0;
  for (let y = 0; y < height; y++) {
    for (let x = 0; x < width; x++) {
      let makeTrans = false;
 
      if (transColor.length === 1) {
        if (transColor[0] === indata[pxPos]) {
          makeTrans = true;
        }
      } else if (
        transColor[0] === indata[pxPos] &&
        transColor[1] === indata[pxPos + 1] &&
        transColor[2] === indata[pxPos + 2]
      ) {
        makeTrans = true;
      }
      if (makeTrans) {
        for (let i = 0; i < 4; i++) {
          outdata[pxPos + i] = 0;
        }
      }
      pxPos += 4;
    }
  }
}
 
function scaleDepth(indata, outdata, width, height, depth) {
  let maxOutSample = 255;
  let maxInSample = Math.pow(2, depth) - 1;
  let pxPos = 0;
 
  for (let y = 0; y < height; y++) {
    for (let x = 0; x < width; x++) {
      for (let i = 0; i < 4; i++) {
        outdata[pxPos + i] = Math.floor(
          (indata[pxPos + i] * maxOutSample) / maxInSample + 0.5
        );
      }
      pxPos += 4;
    }
  }
}
 
module.exports = function (indata, imageData) {
  let depth = imageData.depth;
  let width = imageData.width;
  let height = imageData.height;
  let colorType = imageData.colorType;
  let transColor = imageData.transColor;
  let palette = imageData.palette;
 
  let outdata = indata; // only different for 16 bits
 
  if (colorType === 3) {
    // paletted
    dePalette(indata, outdata, width, height, palette);
  } else {
    if (transColor) {
      replaceTransparentColor(indata, outdata, width, height, transColor);
    }
    // if it needs scaling
    if (depth !== 8) {
      // if we need to change the buffer size
      if (depth === 16) {
        outdata = Buffer.alloc(width * height * 4);
      }
      scaleDepth(indata, outdata, width, height, depth);
    }
  }
  return outdata;
};