Skip to content

Commit

Permalink
copy pallete data from pal8 frames
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Dec 16, 2016
1 parent fdc1d55 commit 5f1edc2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
13 changes: 6 additions & 7 deletions src/QtAV/VideoFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
/// TODO: fromAVFrame(const AVFrame* f);
namespace QtAV {

/// metadata: pallete for pal8
class VideoFramePrivate;
class Q_AV_EXPORT VideoFrame : public Frame
{
Expand Down Expand Up @@ -75,8 +76,11 @@ class Q_AV_EXPORT VideoFrame : public Frame
//int width(int plane = 0) const?
int width() const;
int height() const;
// plane width without padded bytes.
int effectivePlaneWidth(int plane) const;
/*!
* \brief effectiveBytesPerLine
* The plane bytes contains valid image data without padded data for alignment reason
*/
int effectiveBytesPerLine(int plane) const;
// plane width with padded bytes for alignment.
int planeWidth(int plane) const;
int planeHeight(int plane) const;
Expand All @@ -88,11 +92,6 @@ class Q_AV_EXPORT VideoFrame : public Frame
void setColorSpace(ColorSpace value);
ColorRange colorRange() const;
void setColorRange(ColorRange value);
/*!
* \brief effectiveBytesPerLine
* The plane bytes contains valid image data without padded data for alignment reason
*/
int effectiveBytesPerLine(int plane) const;
/*!
* \brief toImage
* Return a QImage of current video frame, with given format, image size and region of interest.
Expand Down
15 changes: 8 additions & 7 deletions src/VideoFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,6 @@ int VideoFrame::height() const
return d_func()->height;
}

int VideoFrame::effectivePlaneWidth(int plane) const
{
return planeWidth(plane)*effectiveBytesPerLine(plane)/bytesPerLine(plane);
}

int VideoFrame::planeWidth(int plane) const
{
Q_D(const VideoFrame);
Expand Down Expand Up @@ -520,12 +515,18 @@ VideoFrame VideoFrameConverter::convert(const VideoFrame &frame, int fffmt) cons
m_cvt->setInSize(frame.width(), frame.height());
m_cvt->setOutSize(frame.width(), frame.height());
m_cvt->setInRange(frame.colorRange());
QVector<const uchar*> pitch(format.planeCount());
QVector<int> stride(format.planeCount());
const int pal = format.hasPalette();
QVector<const uchar*> pitch(format.planeCount() + pal);
QVector<int> stride(format.planeCount() + pal);
for (int i = 0; i < format.planeCount(); ++i) {
pitch[i] = frame.constBits(i);
stride[i] = frame.bytesPerLine(i);
}
const QByteArray paldata(frame.metaData(QStringLiteral("pallete")).toByteArray());
if (pal > 0) {
pitch[1] = (const uchar*)paldata.constData();
stride[1] = paldata.size();
}
if (!m_cvt->convert(pitch.constData(), stride.constData())) {
return VideoFrame();
}
Expand Down
3 changes: 3 additions & 0 deletions src/codec/video/VideoDecoderFFmpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ VideoFrame VideoDecoderFFmpeg::frame()
frame.setTimestamp((double)d.frame->pkt_pts/1000.0);
frame.setMetaData(QStringLiteral("avbuf"), QVariant::fromValue(AVFrameBuffersRef(new AVFrameBuffers(d.frame))));
d.updateColorDetails(&frame);
if (frame.format().hasPalette()) {
frame.setMetaData(QStringLiteral("pallete"), QByteArray((const char*)d.frame->data[1], 256*4));
}
return frame;
}

Expand Down

0 comments on commit 5f1edc2

Please sign in to comment.