Skip to content

Commit

Permalink
add api to get plane data ptr and line size from ImageConverter
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Nov 9, 2013
1 parent 6795a10 commit 5f87499
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 35 deletions.
38 changes: 37 additions & 1 deletion src/ImageConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,45 @@ bool ImageConverter::isInterlaced() const
return d_func().interlaced;
}

QVector<quint8*> ImageConverter::outPlanes() const
{
DPTR_D(const ImageConverter);
QVector<quint8*> planes(4, 0);
planes[0] = d.picture.data[0];
planes[1] = d.picture.data[1];
planes[2] = d.picture.data[2];
planes[3] = d.picture.data[3];
return planes;
}

QVector<int> ImageConverter::outLineSizes() const
{
DPTR_D(const ImageConverter);
QVector<int> lineSizes(4, 0);
lineSizes[0] = d.picture.linesize[0];
lineSizes[1] = d.picture.linesize[1];
lineSizes[2] = d.picture.linesize[2];
lineSizes[3] = d.picture.linesize[3];
return lineSizes;
}

bool ImageConverter::prepareData()
{
return false;
DPTR_D(ImageConverter);
//TODO: AVPixelFormat. move define to compat.h
int bytes = avpicture_get_size((PixelFormat)d.fmt_out, d.w_out, d.h_out);
//if (d.data_out.size() < bytes) {
d.data_out.resize(bytes);
//}
//picture的数据按PIX_FMT格式自动"关联"到 data
avpicture_fill(
&d.picture,
reinterpret_cast<uint8_t*>(d.data_out.data()),
(PixelFormat)d.fmt_out,
d.w_out,
d.h_out
);
return true;
}

} //namespace QtAV
21 changes: 0 additions & 21 deletions src/ImageConverterFF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ class ImageConverterFF : public ImageConverter //Q_AV_EXPORT is not needed
public:
ImageConverterFF();
virtual bool convert(const quint8 *const srcSlice[], const int srcStride[]);
protected:
virtual bool prepareData(); //Allocate memory for out data
};


Expand All @@ -58,7 +56,6 @@ class ImageConverterFFPrivate : public ImageConverterPrivate
}

SwsContext *sws_ctx;
AVPicture picture;
};

ImageConverterFF::ImageConverterFF()
Expand Down Expand Up @@ -139,22 +136,4 @@ bool ImageConverterFF::convert(const quint8 *const srcSlice[], const int srcStri
return true;
}

bool ImageConverterFF::prepareData()
{
DPTR_D(ImageConverterFF);
int bytes = avpicture_get_size((PixelFormat)d.fmt_out, d.w_out, d.h_out);
//if (d.data_out.size() < bytes) {
d.data_out.resize(bytes);
//}
//picture的数据按PIX_FMT格式自动"关联"到 data
avpicture_fill(
&d.picture,
reinterpret_cast<uint8_t*>(d.data_out.data()),
(PixelFormat)d.fmt_out,
d.w_out,
d.h_out
);
return true;
}

} //namespace QtAV
13 changes: 1 addition & 12 deletions src/ImageConverterIPP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,7 @@ bool ImageConverterIPP::prepareData()
d.orig_ori_rgb.resize(bytes);
//}
}
//for resize
d.need_scale = d.w_in != d.w_out || d.h_in != d.h_out;
if (d.w_out > 0 && d.h_out > 0) {
qDebug("out size=%d x %d", d.w_out, d.h_out);
if (d.need_scale) {
int bytes = avpicture_get_size((PixelFormat)d.fmt_out, d.w_out, d.h_out);
//if(d.data_out.size() < bytes) {
d.data_out.resize(bytes);
//}
}
}
return true;
return ImageConverter::prepareData();
}

} //namespace QtAV
5 changes: 4 additions & 1 deletion src/QtAV/ImageConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <QtAV/QtAV_Global.h>
#include <QtAV/FactoryDefine.h>
#include <QtCore/QVector>

namespace QtAV {

Expand All @@ -48,13 +49,15 @@ class Q_AV_EXPORT ImageConverter //export is not needed
void setOutFormat(int format);
void setInterlaced(bool interlaced);
bool isInterlaced() const;
QVector<quint8*> outPlanes() const;
QVector<int> outLineSizes() const;
virtual bool convert(const quint8 *const srcSlice[], const int srcStride[]) = 0;
//virtual bool convertColor(const quint8 *const srcSlice[], const int srcStride[]) = 0;
//virtual bool resize(const quint8 *const srcSlice[], const int srcStride[]) = 0;
protected:
ImageConverter(ImageConverterPrivate& d);
//Allocate memory for out data. Called in setOutFormat()
virtual bool prepareData();
virtual bool prepareData(); //Allocate memory for out data
DPTR_DECLARE(ImageConverter)
};

Expand Down
1 change: 1 addition & 0 deletions src/QtAV/private/ImageConverter_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Q_AV_EXPORT ImageConverterPrivate : public DPtrPrivate<ImageConverter>
int w_in, h_in, w_out, h_out;
int fmt_in, fmt_out;
QByteArray data_out;
AVPicture picture;
};

} //namespace QtAV
Expand Down

0 comments on commit 5f87499

Please sign in to comment.