_convertTo2DArray(imageArray) {
        // The image data array has elements in the order of RGBA,
        // so its length is quadrupled. This project cares not for color
        // and just needs to know if a pixel is present, so increment by 4.

        // The looping is done this way to maximize performance.
        // See the following for elaboration:
        // https://stackoverflow.com/questions/5349425/whats-the-fastest-way-to-loop-through-an-array-in-javascript
        // Also, forEach is not defined for this type.
        let currentRow = [];
        const _2dVersion = [];
        const imageArrayLength = imageArray.length;
        for (let i = 0; i < imageArrayLength; i += 4) {
            // switch to a new row if necessary
            if (currentRow.length === this._canvas.width) {
                _2dVersion.push(currentRow);
                currentRow = [];
            } // if

            // get byte representing the color from image data array
            const imageByteColor = imageArray[i];

            // 255 because font color was set to #ffffff in constructor.
            // Can't use black because that's the default.
            if (imageByteColor === 255) {
                currentRow.push(CharacterMapper.pixelPresent);
            } else {
                currentRow.push(CharacterMapper.pixelNotPresent);
            } // if
        } // for

        this._trimExcess(_2dVersion); // don't want to cahce empty columns
        return _2dVersion;
    } // _convertTo2DArray
/**
     * Returns the trimmed 2D version of an image data array.
     * @private
     * @param {Uint8ClampedArray} imageArray an image data array to convert
     * @return the 2D version of an image data array
     */
Returns the trimmed 2D version of an image data array.
@private
@param {Uint8ClampedArray} imageArray an image data array to convert
@return the 2D version of an image data array
Returns the trimmed 2D version of an image data array . @private @param { Uint8ClampedArray } imageArray an image data array to convert @return the 2D version of an image data array
_convertTo2DArray(imageArray) {
        let currentRow = [];
        const _2dVersion = [];
        const imageArrayLength = imageArray.length;
        for (let i = 0; i < imageArrayLength; i += 4) {
            if (currentRow.length === this._canvas.width) {
                _2dVersion.push(currentRow);
                currentRow = [];
            } 
            const imageByteColor = imageArray[i];
            if (imageByteColor === 255) {
                currentRow.push(CharacterMapper.pixelPresent);
            } else {
                currentRow.push(CharacterMapper.pixelNotPresent);
            } 
        } 
        this._trimExcess(_2dVersion); 
        return _2dVersion;
    } 
_convertTo2DArray ( imageArray ) { let currentRow = [ ] ; const _2dVersion = [ ] ; const imageArrayLength = imageArray . length ; for ( let i = 0 ; i < imageArrayLength ; i += 4 ) { if ( currentRow . length === this . _canvas . width ) { _2dVersion . push ( currentRow ) ; currentRow = [ ] ; } const imageByteColor = imageArray [ i ] ; if ( imageByteColor === 255 ) { currentRow . push ( CharacterMapper . pixelPresent ) ; } else { currentRow . push ( CharacterMapper . pixelNotPresent ) ; } } this . _trimExcess ( _2dVersion ) ; return _2dVersion ; }
Returns the trimmed 2D version of an image data array.
Returns the trimmed 2D version of an image data array .
// The image data array has elements in the order of RGBA, // so its length is quadrupled. This project cares not for color // and just needs to know if a pixel is present, so increment by 4. // The looping is done this way to maximize performance. // See the following for elaboration: // https://stackoverflow.com/questions/5349425/whats-the-fastest-way-to-loop-through-an-array-in-javascript // Also, forEach is not defined for this type. // switch to a new row if necessary // if // get byte representing the color from image data array // 255 because font color was set to #ffffff in constructor. // Can't use black because that's the default. // if // for // don't want to cahce empty columns // _convertTo2DArray