Code Monkey home page Code Monkey logo

canvas-renderer's People

Contributors

0jinxing avatar bertyhell avatar dmester avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

canvas-renderer's Issues

Remove use of writeUInt32BE noAssert argument

Symptoms

The following exception is thrown:

RangeError [ERR_OUT_OF_RANGE]: The value of "value" is out of range. It must be >= 0 and <= 4294967295. Received -1109855489
    at checkInt (internal/buffer.js:35:11)
    at writeU_Int32BE (internal/buffer.js:623:3)
    at Buffer.writeUInt32BE (internal/buffer.js:636:10)
    at PngEncoder_writeTrueColorWithAlpha [as writeTrueColorWithAlpha] (F:\CanvasRenderer\lib\png\pngEncoder.js:79:24)
    at Canvas_toPng [as toPng] (F:\CanvasRenderer\lib\canvas.js:113:13)
    at Canvas_toDataURL [as toDataURL] (F:\CanvasRenderer\lib\canvas.js:131:20)
    at Object.<anonymous> (F:\CanvasRenderer\tests\trueColorTest.js:67:58)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:282:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)

The exception is only thrown for images that contain more than 256 colors, where at least one color has a red channel value over 127.

This was reported in dmester/jdenticon#33.

Cause

When the reulting image contains more than 256 colors, it can no longer be represented as a PNG with a palette, but is instead saved as a true-color PNG. Node function Buffer.writeUInt32BE is used to write the color data to the PNG data stream. This function had a parameter called noAssert which essentially forced the value to an unsigned 32 bit integer, even when the value was a negative number.

In Node 10.x and later, noAssert has been removed, and the function will now instead throw an exception when a negative number is passed to the function. This was sometimes done by canvas-renderer when the red component of the color was larger than 127, since canvas-renderer handled both unsigned and signed integers as color values.

Solution

Convert all color functions to return signed integers as color values. Signed integers are prefered over unsigned integers since all bitwise operators in JS convert all operands to signed 32-bit integers.

Also replace Buffer.writeUInt32BE with Buffer.writeInt32BE.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.