diff --git a/libs/libkis/Node.h b/libs/libkis/Node.h --- a/libs/libkis/Node.h +++ b/libs/libkis/Node.h @@ -330,6 +330,17 @@ QByteArray pixelData(int x, int y, int w, int h) const; /** + * @brief pixelDataAtTime a basic function to get pixeldata from an animated node at a given time. + * @param x the position from the left to start reading. + * @param y the position from the top to start reader + * @param w the row length to read + * @param h the number of rows to read + * @param time the frame number + * @return a QByteArray with the pixel data. The byte array may be empty. + */ + QByteArray pixelDataAtTime(int x, int y, int w, int h, int time) const; + + /** * @brief projectionPixelData reads the given rectangle from the Node's projection (that is, what the node * looks like after all sub-Nodes (like layers in a group or masks on a layer) have been applied, * and returns it as a byte array. The pixel data starts top-left, and is ordered row-first. diff --git a/libs/libkis/Node.cpp b/libs/libkis/Node.cpp --- a/libs/libkis/Node.cpp +++ b/libs/libkis/Node.cpp @@ -46,6 +46,9 @@ #include #include +#include +#include + #include "Krita.h" #include "Node.h" #include "Channel.h" @@ -383,6 +386,27 @@ return ba; } +QByteArray Node::pixelDataAtTime(int x, int y, int w, int h, int time) const +{ + QByteArray ba; + + if (!d->node || !d->node->isAnimated()) return ba; + + // + KisRasterKeyframeChannel *rkc = dynamic_cast(d->node->getKeyframeChannel(KisKeyframeChannel::Content.id())); + if (!rkc) return ba; + KisKeyframeSP frame = rkc->keyframeAt(time); + if (!frame) return ba; + KisPaintDeviceSP dev = d->node->paintDevice(); + if (!dev) return ba; + + rkc->fetchFrame(frame, dev); + + ba.resize(w * h * dev->pixelSize()); + dev->readBytes(reinterpret_cast(ba.data()), x, y, w, h); + return ba; +} + QByteArray Node::projectionPixelData(int x, int y, int w, int h) const { diff --git a/plugins/extensions/pykrita/sip/krita/Node.sip b/plugins/extensions/pykrita/sip/krita/Node.sip --- a/plugins/extensions/pykrita/sip/krita/Node.sip +++ b/plugins/extensions/pykrita/sip/krita/Node.sip @@ -42,6 +42,7 @@ bool visible() const; void setVisible(bool value); QByteArray pixelData(int x, int y, int w, int h) const; + QByteArray pixelDataAtTime(int x, int y, int w, int h, int time) const; QByteArray projectionPixelData(int x, int y, int w, int h) const; void setPixelData(QByteArray value, int x, int y, int w, int h); QRect bounds() const;