Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bitmap.prototype.getAlphaPixel return the wrong type #107

Open
niokasgami opened this issue May 17, 2017 · 4 comments
Open

Bitmap.prototype.getAlphaPixel return the wrong type #107

niokasgami opened this issue May 17, 2017 · 4 comments

Comments

@niokasgami
Copy link
Contributor

Hello,
I noticed meanwhile working on the typescript conversion I noticed that
Bitmap.prototype.getAlphaPixel is supposed to return a String although my linter show it's return an Uint8ClampedArray

wich is making the documentation wrong.

I suggest for fix this to either change the return type from the comment from String to Uint8ClampedArray or to do this :

    Bitmap.prototype.getAlphaPixel = function(x,  y) {
        var data = this._context.getImageData(x, y, 1, 1).data;
        return data[3].toString();
    };

thanks for your time!

@niokasgami
Copy link
Contributor Author

Nevermind my version was outdated without I noticed
Closing this.

@niokasgami
Copy link
Contributor Author

I am reopening again due that I noticed that yes this was indeed having a error

/**
 * Returns pixel color at the specified point.
 *
 * @method getPixel
 * @param {Number} x The x coordinate of the pixel in the bitmap
 * @param {Number} y The y coordinate of the pixel in the bitmap
 * @return {String} The pixel color (hex format)
 */
Bitmap.prototype.getPixel = function(x, y) {
    var data = this._context.getImageData(x, y, 1, 1).data;
    var result = '#';
    for (var i = 0; i < 3; i++) {
        result += data[i].toString(16).padZero(2);
    }
    return result;
};

/**
 * Returns alpha pixel value at the specified point.
 *
 * @method getAlphaPixel
 * @param {Number} x The x coordinate of the pixel in the bitmap
 * @param {Number} y The y coordinate of the pixel in the bitmap
 * @return {String} The alpha value
 */
Bitmap.prototype.getAlphaPixel = function(x, y) {
    var data = this._context.getImageData(x, y, 1, 1).data;
    return data[3];
};

getPixel is indeed converted but not AlphaPixel

@niokasgami niokasgami reopened this May 17, 2017
@molingyu
Copy link

Should we add color class?

@ghost
Copy link

ghost commented May 18, 2017

getAlphaPixel returns alpha value of specified pixel, so It's correct.
We agree method name doesn't have clear intention,
But for compatibility, We cannot change it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants