static makeTextureSizePowerOfTwoUp()

in src/engine/loaders/voltools.js [893:965]


  static makeTextureSizePowerOfTwoUp(pixelsSrc, xDimSrc, yDimSrc, zDimSrc, xDimDst, yDimDst) {
    const zDimDst = zDimSrc;
    const HALF = 2;
    if (xDimDst < xDimSrc) {
      console.log(`Error: ${xDimDst} < ${xDimSrc}`);
    }
    if (yDimDst < yDimSrc) {
      console.log(`Error: ${yDimDst} < ${yDimSrc}`);
    }
    const xShift = Math.floor((xDimDst - xDimSrc) / HALF);
    const yShift = Math.floor((yDimDst - yDimSrc) / HALF);
    const numPixelsSrc = xDimSrc * yDimSrc * zDimSrc;
    const numBytesPerPixel = Math.floor(pixelsSrc.length / numPixelsSrc);
    const FOUR = 4;
    if (numBytesPerPixel !== 1 && numBytesPerPixel !== FOUR) {
      console.log(`Error source volume bpp:  = ${xDimSrc} * ${yDimSrc} * ${zDimSrc}, bpp = ${numBytesPerPixel}`);
    }
    const numPixelsDst = xDimDst * yDimDst * zDimDst * numBytesPerPixel;
    const pixelsDst = new Uint8Array(numPixelsDst);
    let i;
    for (i = 0; i < numPixelsDst; i++) {
      pixelsDst[i] = 0;
    }
    let offSrc = 0;
    if (numBytesPerPixel === 1) {
      for (let z = 0; z < zDimSrc; z++) {
        const zOffDst = z * xDimDst * yDimDst;
        for (let y = 0; y < yDimSrc; y++) {
          const yOffDst = (y + yShift) * xDimDst;
          let offDst = xShift + yOffDst + zOffDst;
          for (let x = 0; x < xDimSrc; x++, offDst++) {
            const val = pixelsSrc[offSrc];
            pixelsDst[offDst] = val;
            offSrc++;
          } // for (x) source
        } // for (y) source
      } // for (z) source
    } else if (numBytesPerPixel === FOUR) {
      for (let z = 0; z < zDimSrc; z++) {
        const zOffDst = z * xDimDst * yDimDst;
        for (let y = 0; y < yDimSrc; y++) {
          const yOffDst = (y + yShift) * xDimDst;
          let offDst = xShift + yOffDst + zOffDst;
          for (let x = 0; x < xDimSrc; x++, offDst++) {
            let offSrc4 = offSrc + offSrc + offSrc + offSrc;
            let offDst4 = offDst + offDst + offDst + offDst;
            let val;

            val = pixelsSrc[offSrc4];
            pixelsDst[offDst4] = val;
            offSrc4++;
            offDst4++;

            val = pixelsSrc[offSrc4];
            pixelsDst[offDst4] = val;
            offSrc4++;
            offDst4++;

            val = pixelsSrc[offSrc4];
            pixelsDst[offDst4] = val;
            offSrc4++;
            offDst4++;

            val = pixelsSrc[offSrc4];
            pixelsDst[offDst4] = val;

            offSrc++;
          } // for (x) source
        } // for (y) source
      } // for (z) source
    }
    return pixelsDst;
  } // end of makeTextureSizePowerOfTwoUp