Created attachment 162210 [details] test krita file 5.2.0-rc1 Appimage SUMMARY Reading the pixelData for the RGBA channels of a node (and printing the output) doesn't seem correct. There is a very slight something in the byte array but it's very nearly all zeros, and copying that channel pixelData to the channel of a new node doesn't produce anything useful. I'm able to use the full node pixelData or projectionPixelData just fine (this is how I'm exporting maps in my plugin currently), but reading/writing channels pixelData seems broken. It doesn't produce any errors, it just doesn't work. I may be doing something wrong (am I?), but I would assume copying from the channel of one node into the channel of another node should be possible, right? For context, I'm trying to pack three grayscale (but RGBA color space) textures into the channels of a single node (ambient occlusion, roughness, metallic, i.e. ORM), but I haven't gotten that far because being able to read/write channel data is the first step and I'm blocked here. STEPS TO REPRODUCE Copy the following script and run it in scripter while the "pixels" layer of the attached .kra file is selected. from krita import Krita from PyQt5.QtCore import QByteArray, QRect KI = Krita.instance() doc = KI.activeDocument() activeNode = doc.activeNode() root = doc.rootNode() fullPixels = QByteArray() rChannel = QByteArray() gChannel = QByteArray() bChannel = QByteArray() aChannel = QByteArray() xDocSize = 3 yDocSize = 1 rect = QRect(0, 0, xDocSize, yDocSize) print("\nOriginal node pixel data") fullPixels = activeNode.pixelData(0, 0, xDocSize, yDocSize) print(fullPixels) print("\n" + activeNode.channels()[2].name()) rChannel = activeNode.channels()[2].pixelData(rect) print(rChannel) print("\n" + activeNode.channels()[1].name()) gChannel = activeNode.channels()[1].pixelData(rect) print(gChannel) print("\n" + activeNode.channels()[0].name()) bChannel = activeNode.channels()[0].pixelData(rect) print(bChannel) print("\n" + activeNode.channels()[3].name()) aChannel = activeNode.channels()[3].pixelData(rect) print(aChannel) newNode = doc.createNode("channels copy (doesnt work)", 'paintlayer') newNode.channels()[2].setPixelData(rChannel, rect) newNode.channels()[1].setPixelData(gChannel, rect) newNode.channels()[0].setPixelData(bChannel, rect) newNode.channels()[3].setPixelData(aChannel, rect) print("\nOriginal channels copied into new node channels") print(newNode.pixelData(0, 0, xDocSize, yDocSize)) fullCopy = doc.createNode("full copy (works)", 'paintlayer') fullCopy.setPixelData(fullPixels, 0, 0, xDocSize, yDocSize) print("\nFull copy of original pixel data into new node") print(fullCopy.pixelData(0, 0, xDocSize, yDocSize)) root.addChildNode(newNode, None) root.addChildNode(fullCopy, None) OBSERVED RESULT 1. It should be clear from the script output that the pixelData for the entire layer seems normal and can be copied to another node properly. A new node will be added to the stack with an exact copy of the pixels. 2. It should also be clear that doing the same thing for the individual channels doesn't produce the desired result. The printed QByteArray output seems wrong, and recomposing a node using the copied channel pixelData produces an empty layer in the stack. EXPECTED RESULT I would expect to be able to read the pixelData of each channel in a node and copy it to a channel in a new node, thereby reconstituting an exact copy of the original node, or swapping channels around. I would also expect to be able to copy the full pixelData from, say, three different nodes and pack those into the individual channels of a new node.
A possibly relevant merge request was started @ https://invent.kde.org/graphics/krita/-/merge_requests/1969
Git commit 67d6388931722fe3bf33f8141cdfb0846076b41d by Dmitry Kazakov, on behalf of Freya Lupen. Committed on 24/10/2023 at 14:29. Pushed by dkazakov into branch 'master'. Fix Channel scripting API's pixel data handling Channel.pixelData and Channel.setPixelData were both broken. M +16 -9 libs/libkis/Channel.cpp https://invent.kde.org/graphics/krita/-/commit/67d6388931722fe3bf33f8141cdfb0846076b41d
Git commit d9942ec53cc1ed1c454e122496f9a201c4066c71 by Dmitry Kazakov, on behalf of Freya Lupen. Committed on 24/10/2023 at 14:30. Pushed by dkazakov into branch 'krita/5.2'. Fix Channel scripting API's pixel data handling Channel.pixelData and Channel.setPixelData were both broken. (cherry picked from commit 67d6388931722fe3bf33f8141cdfb0846076b41d) M +16 -9 libs/libkis/Channel.cpp https://invent.kde.org/graphics/krita/-/commit/d9942ec53cc1ed1c454e122496f9a201c4066c71