Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML Canvas bug with getImageData with 5.0 and 5.1, or am I doing something wrong? [Fixed] Not really.
Forum Updated to NodeBB v4.3 + New Features

QML Canvas bug with getImageData with 5.0 and 5.1, or am I doing something wrong? [Fixed] Not really.

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 2.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vallidor
    wrote on last edited by
    #1

    I'm not certain, but I think I've stumbled onto a bug with Canvas in Qt 5.0 and 5.1

    [code]
    var ctx = canvas.getContext('2d');
    var imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
    [/code]

    Now, as far as I understand imageData.data should now contain the pixel data. Using a C++ method I attempt to handle it (as a QVariantList) with:

    [code]
    setFromData(imageData.data, imageData.width, imageData.height);
    [/code]

    This method creates a uchar* array of the pixels, creates a QImage from it, then returns.

    Except this code doesn't work. The array received is 0 bytes long.

    If I make a deep copy of the pixel array (in JS) into a new array and pass the copy it works perfectly:

    [code]
    var copied = new Array();
    for( var x=0; x < imageData.data.length; x++ )

    = imageData.data[x];

    printer.setFromData(copied, imageData.width, imageData.height);
    [/code]

    I have made a fairly minimal example which reproduces the effect:

    http://foxmoxie.net/~doneill/canvastest.tar.bz2

    I have a suspicion that the offending code is here: http://qt.gitorious.org/qt/qtdeclarative/blobs/stable/src/qml/qml/v8/qv8engine.cpp#line241

    It looks like if it's a pixel array it returns an empty QVariant. Am I right?

    Any thoughts at all on this would be appreciated, thanks.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      chrisadams
      wrote on last edited by
      #2

      Hi,

      This does look like a bug. I do wonder which conversion codepath is taken for the second (manually deep-copied) array, though.
      In any event, please file a bug report with the minimal example attached. Very soon I think v8 is going away, to be replaced by v4vm, so it's possible that this is already fixed in what will become 5.2.

      Cheers,
      Chris.

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vallidor
        wrote on last edited by
        #3

        My bug report became a feature request since it "never has worked".

        It will most likely stay a stub which does nothing (not even a warning) and will instead return an empty QVariant to the native method.

        In short the correct way is to quite literally copy the contents into a new array object (in JS) and return that.

        Weak? I thought so too.

        https://bugreports.qt-project.org/browse/QTBUG-33167

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved