size_t elmCount;
} mPath;
LOTMaskType mMode;
- int mAlpha;
+ unsigned char mAlpha;
}LOTMask;
typedef enum
struct {
unsigned char enable;
- int width;
+ float width;
LOTCapStyle cap;
LOTJoinStyle join;
- int meterLimit;
+ float meterLimit;
float *dashArray;
int dashArraySize;
} mStroke;
LOTMatteType mMatte;
int mVisible;
- int mAlpha;
+ unsigned char mAlpha;
const char *name;
} LOTLayerNode;
if (mRasterRequest) {
mRasterRequest = false;
if (!vCompare(mCombinedAlpha, 1.0f))
- mRasterizer.rle() *= (mCombinedAlpha * 255);
+ mRasterizer.rle() *= uchar(mCombinedAlpha * 255);
if (mData->mInv) mRasterizer.rle().invert();
}
return mRasterizer.rle();
mLayerCNode->mClipPath.elmCount = 0;
mLayerCNode->name = name().c_str();
}
- if (complexContent()) mLayerCNode->mAlpha = combinedAlpha() * 255.f;
+ if (complexContent()) mLayerCNode->mAlpha = uchar(combinedAlpha() * 255.f);
mLayerCNode->mVisible = visible();
// update matte
if (hasMatte()) {
LOTMask * cNode = &mMasksCNode[i++];
const std::vector<VPath::Element> &elm = mask.mFinalPath.elements();
const std::vector<VPointF> & pts = mask.mFinalPath.points();
- const float *ptPtr = reinterpret_cast<const float *>(pts.data());
- const char * elmPtr = reinterpret_cast<const char *>(elm.data());
+ auto ptPtr = reinterpret_cast<const float *>(pts.data());
+ auto elmPtr = reinterpret_cast<const char *>(elm.data());
cNode->mPath.ptPtr = ptPtr;
cNode->mPath.ptCount = pts.size();
cNode->mPath.elmPtr = elmPtr;
cNode->mPath.elmCount = elm.size();
- cNode->mAlpha = mask.mCombinedAlpha * 255.0f;
+ cNode->mAlpha = uchar(mask.mCombinedAlpha * 255.0f);
switch (mask.maskMode()) {
case LOTMaskData::Mode::Add:
cNode->mMode = MaskAdd;
bool LOTLayerItem::visible() const
{
- if (frameNo() >= mLayerData->inFrame() &&
- frameNo() < mLayerData->outFrame())
- return true;
- else
- return false;
+ return (frameNo() >= mLayerData->inFrame() &&
+ frameNo() < mLayerData->outFrame());
}
LOTCompLayerItem::LOTCompLayerItem(LOTLayerData *layerModel)
{
// 1. create layer item
for (auto &i : mLayerData->mChildren) {
- LOTLayerData *layerModel = static_cast<LOTLayerData *>(i.get());
- auto layerItem = LOTCompItem::createLayerItem(layerModel);
- if (layerItem) mLayers.push_back(std::move(layerItem));
+ auto model = static_cast<LOTLayerData *>(i.get());
+ auto item = LOTCompItem::createLayerItem(model);
+ if (item) mLayers.push_back(std::move(item));
}
// 2. update parent layer
if (mClipper) {
const std::vector<VPath::Element> &elm = mClipper->mPath.elements();
const std::vector<VPointF> & pts = mClipper->mPath.points();
- const float *ptPtr = reinterpret_cast<const float *>(pts.data());
- const char * elmPtr = reinterpret_cast<const char *>(elm.data());
+ auto ptPtr = reinterpret_cast<const float *>(pts.data());
+ auto elmPtr = reinterpret_cast<const char *>(elm.data());
layerNode()->mClipPath.ptPtr = ptPtr;
layerNode()->mClipPath.elmPtr = elmPtr;
layerNode()->mClipPath.ptCount = 2 * pts.size();
srcPainter.begin(&srcBitmap);
renderHelper(&srcPainter, inheritMask, matteRle);
srcPainter.end();
- painter->drawBitmap(VPoint(), srcBitmap, combinedAlpha() * 255.0f);
+ painter->drawBitmap(VPoint(), srcBitmap, uchar(combinedAlpha() * 255.0f));
} else {
renderHelper(painter, inheritMask, matteRle);
}
mCNodeList.clear();
for (auto &i : mDrawableList) {
- LOTDrawable *lotDrawable = static_cast<LOTDrawable *>(i);
+ auto lotDrawable = static_cast<LOTDrawable *>(i);
lotDrawable->sync();
mCNodeList.push_back(lotDrawable->mCNode.get());
}
mCNodeList.clear();
for (auto &i : mDrawableList) {
- LOTDrawable *lotDrawable = static_cast<LOTDrawable *>(i);
+ auto lotDrawable = static_cast<LOTDrawable *>(i);
lotDrawable->sync();
lotDrawable->mCNode->mImageInfo.data =
lotDrawable->mBrush.mTexture.data();
lotDrawable->mCNode->mImageInfo.width =
- lotDrawable->mBrush.mTexture.width();
+ int(lotDrawable->mBrush.mTexture.width());
lotDrawable->mCNode->mImageInfo.height =
- lotDrawable->mBrush.mTexture.height();
+ int(lotDrawable->mBrush.mTexture.height());
lotDrawable->mCNode->mImageInfo.mMatrix.m11 = combinedMatrix().m_11();
lotDrawable->mCNode->mImageInfo.mMatrix.m12 = combinedMatrix().m_12();
mCNodeList.clear();
for (auto &i : mDrawableList) {
- LOTDrawable *lotDrawable = static_cast<LOTDrawable *>(i);
+ auto lotDrawable = static_cast<LOTDrawable *>(i);
lotDrawable->sync();
mCNodeList.push_back(lotDrawable->mCNode.get());
}
LOTGradientStop *ptr = n->mGradient.stopPtr;
for (const auto &i : grad->mStops) {
ptr->pos = i.first;
- ptr->a = i.second.alpha() * grad->alpha();
+ ptr->a = uchar(i.second.alpha() * grad->alpha());
ptr->r = i.second.red();
ptr->g = i.second.green();
ptr->b = i.second.blue();
void LOTGradient::populate(VGradientStops &stops, int frameNo)
{
LottieGradient gradData = mGradient.value(frameNo);
- int size = int(gradData.mGradient.size());
+ auto size = gradData.mGradient.size();
float * ptr = gradData.mGradient.data();
int colorPoints = mColorPoints;
if (colorPoints == -1) { // for legacy bodymovin (ref: lottie-android)
- colorPoints = size / 4;
+ colorPoints = int(size / 4);
}
- int opacityArraySize = size - colorPoints * 4;
+ auto opacityArraySize = size - colorPoints * 4;
float *opacityPtr = ptr + (colorPoints * 4);
stops.clear();
- int j = 0;
+ size_t j = 0;
for (int i = 0; i < colorPoints; i++) {
float colorStop = ptr[0];
LottieColor color = LottieColor(ptr[1], ptr[2], ptr[3]);
uint mWidth{0};
uint mHeight{0};
uint mStride{0};
- uint mBytes{0};
- uint mDepth{0};
+ uchar mDepth{0};
VBitmap::Format mFormat{VBitmap::Format::Invalid};
bool mOwnData;
bool mRoData;
Impl& operator=(Impl&&) = delete;
Impl& operator=(Impl&) = delete;
- explicit Impl(uint width, uint height, VBitmap::Format format)
+ VRect rect() const
+ {
+ return VRect(0, 0, mWidth, mHeight);
+ }
+
+ VSize size() const
+ {
+ return VSize(mWidth, mHeight);
+ }
+
+ explicit Impl(size_t width, size_t height, VBitmap::Format format)
: mOwnData(true), mRoData(false)
{
reset(width, height, format);
}
- void reset(uint width, uint height, VBitmap::Format format)
+ void reset(size_t width, size_t height, VBitmap::Format format)
{
- if (mOwnData && mData) delete (mData);
+ if (mOwnData && mData) delete[] mData;
+
+ mWidth = uint(width);
+ mHeight = uint(height);
+ mFormat = format;
mDepth = depth(format);
- uint stride = ((width * mDepth + 31) >> 5)
+ mStride = ((mWidth * mDepth + 31) >> 5)
<< 2; // bytes per scanline (must be multiple of 4)
-
- mWidth = width;
- mHeight = height;
- mFormat = format;
- mStride = stride;
- mBytes = mStride * mHeight;
- mData = new uchar[mBytes];
+ mData = new uchar[mStride * mHeight];
}
- explicit Impl(uchar *data, uint w, uint h, uint bytesPerLine, VBitmap::Format format)
- : mData(data), mWidth(w), mHeight(h), mStride(bytesPerLine),
- mDepth(depth(format)), mFormat(format), mOwnData(false), mRoData(false)
- {
- mBytes = mStride * mHeight;
- }
+ explicit Impl(uchar *data, size_t w, size_t h, size_t bytesPerLine, VBitmap::Format format)
+ : mData(data), mWidth(uint(w)), mHeight(uint(h)), mStride(uint(bytesPerLine)),
+ mDepth(depth(format)), mFormat(format), mOwnData(false), mRoData(false){}
~Impl()
{
if (mOwnData && mData) delete[] mData;
}
- uint stride() const { return mStride; }
- uint width() const { return mWidth; }
- uint height() const { return mHeight; }
+ size_t stride() const { return mStride; }
+ size_t width() const { return mWidth; }
+ size_t height() const { return mHeight; }
VBitmap::Format format() const { return mFormat; }
uchar * data() { return mData; }
- static uint depth(VBitmap::Format format)
+ static uchar depth(VBitmap::Format format)
{
- uint depth = 1;
+ uchar depth = 1;
switch (format) {
case VBitmap::Format::Alpha8:
depth = 8;
}
};
-VBitmap::VBitmap(uint width, uint height, VBitmap::Format format)
+VBitmap::VBitmap(size_t width, size_t height, VBitmap::Format format)
{
if (width <= 0 || height <= 0 || format == Format::Invalid) return;
mImpl = std::make_shared<Impl>(width, height, format);
}
-VBitmap::VBitmap(uchar *data, uint width, uint height, uint bytesPerLine,
+VBitmap::VBitmap(uchar *data, size_t width, size_t height, size_t bytesPerLine,
VBitmap::Format format)
{
if (!data || width <= 0 || height <= 0 || bytesPerLine <= 0 ||
mImpl = std::make_shared<Impl>(data, width, height, bytesPerLine, format);
}
-void VBitmap::reset(uint w, uint h, VBitmap::Format format)
+void VBitmap::reset(size_t w, size_t h, VBitmap::Format format)
{
if (mImpl) {
if (w == mImpl->width() && h == mImpl->height() &&
}
}
-uint VBitmap::stride() const
+size_t VBitmap::stride() const
{
return mImpl ? mImpl->stride() : 0;
}
-uint VBitmap::width() const
+size_t VBitmap::width() const
{
return mImpl ? mImpl->width() : 0;
}
-uint VBitmap::height() const
+size_t VBitmap::height() const
{
return mImpl ? mImpl->height() : 0;
}
-uint VBitmap::depth() const
+size_t VBitmap::depth() const
{
return mImpl ? mImpl->mDepth : 0;
}
return mImpl ? mImpl->data() : nullptr;
}
+VRect VBitmap::rect() const
+{
+ return mImpl ? mImpl->rect() : VRect();
+}
+
+VSize VBitmap::size() const
+{
+ return mImpl ? mImpl->size() : VSize();
+}
+
bool VBitmap::valid() const
{
return (mImpl != nullptr);
};
VBitmap() = default;
- VBitmap(uint w, uint h, VBitmap::Format format);
- VBitmap(uchar *data, uint w, uint h, uint bytesPerLine, VBitmap::Format format);
-
- void reset(uint w, uint h, VBitmap::Format format=Format::ARGB32_Premultiplied);
- uint stride() const;
- uint width() const;
- uint height() const;
- uint depth() const;
+ VBitmap(size_t w, size_t h, VBitmap::Format format);
+ VBitmap(uchar *data, size_t w, size_t h, size_t bytesPerLine, VBitmap::Format format);
+
+ void reset(size_t w, size_t h, VBitmap::Format format=Format::ARGB32_Premultiplied);
+ size_t stride() const;
+ size_t width() const;
+ size_t height() const;
+ size_t depth() const;
VBitmap::Format format() const;
bool valid() const;
uchar * data();
uchar * data() const;
-
+ VRect rect() const;
+ VSize size() const;
void fill(uint pixel);
void updateLuma();
private:
* dest = source' + dest ( 1- source'a)
*/
for (int i = 0; i < length; ++i) {
- uint s = BYTE_MUL(src[i], const_alpha);
+ s = BYTE_MUL(src[i], const_alpha);
sia = vAlpha(~s);
dest[i] = s + BYTE_MUL(dest[i], sia);
}
VCacheData info;
const VGradientStops &stops = gradient.mStops;
for (uint i = 0; i < stops.size() && i <= 2; i++)
- hash_val += (stops[i].second.premulARGB() * gradient.alpha());
+ hash_val += VCacheKey(stops[i].second.premulARGB() * gradient.alpha());
{
std::lock_guard<std::mutex> guard(mMutex);
void VSpanData::init(VRasterBuffer *image)
{
mRasterBuffer = image;
- setDrawRegion(VRect(0, 0, image->width(), image->height()));
+ setDrawRegion(VRect(0, 0, int(image->width()), int(image->height())));
mType = VSpanData::Type::None;
mBlendFunc = nullptr;
mUnclippedBlendFunc = nullptr;
float rw = data->m23 * (y + float(0.5)) + data->m13 * (x + float(0.5)) +
data->m33;
while (buffer < end) {
- float x = rx / rw;
- float y = ry / rw;
- t = (op->linear.dx * x + op->linear.dy * y) + op->linear.off;
+ float xt = rx / rw;
+ float yt = ry / rw;
+ t = (op->linear.dx * xt + op->linear.dy * yt) + op->linear.off;
*buffer = gradientPixel(gradient, t);
rx += data->m11;
const int image_width = data->mBitmap.width;
const int image_height = data->mBitmap.height;
- int xoff = data->dx;
- int yoff = data->dy;
+ int xoff = int(data->dx);
+ int yoff = int(data->dy);
while (count--) {
int x = spans->x;
mType = VSpanData::Type::Texture;
initTexture(
&brush.mTexture, 255, VBitmapData::Plain,
- VRect(0, 0, brush.mTexture.width(), brush.mTexture.height()));
+ brush.mTexture.rect());
setupMatrix(brush.mMatrix);
break;
}
mType = VSpanData::Type::Texture;
mBitmap.imageData = bitmap->data();
- mBitmap.width = bitmap->width();
- mBitmap.height = bitmap->height();
+ mBitmap.width = int(bitmap->width());
+ mBitmap.height = int(bitmap->height());
mBitmap.bytesPerLine = bitmap->stride();
mBitmap.format = bitmap->format();
mBitmap.x1 = sourceRect.x();
inline uchar *scanLine(int y)
{
assert(y >= 0);
- assert(y < mHeight);
+ assert(size_t(y) < mHeight);
return mBuffer + y * mBytesPerLine;
}
- int width() const { return mWidth; }
- int height() const { return mHeight; }
- int bytesPerLine() const { return mBytesPerLine; }
- int bytesPerPixel() const { return mBytesPerPixel; }
+ size_t width() const { return mWidth; }
+ size_t height() const { return mHeight; }
+ size_t bytesPerLine() const { return mBytesPerLine; }
+ size_t bytesPerPixel() const { return mBytesPerPixel; }
VBitmap::Format mFormat{VBitmap::Format::ARGB32_Premultiplied};
private:
- int mWidth{0};
- int mHeight{0};
- int mBytesPerLine{0};
- int mBytesPerPixel{0};
- uchar *mBuffer{nullptr};
+ size_t mWidth{0};
+ size_t mHeight{0};
+ size_t mBytesPerLine{0};
+ size_t mBytesPerPixel{0};
+ uchar *mBuffer{nullptr};
};
struct VGradientData {
VBitmap VImageLoader::load(const char *data, size_t len)
{
- return mImpl->load(data, len);
+ return mImpl->load(data, int(len));
}
static void fillRect(const VRect &r, VSpanData *data)
{
- int x1, x2, y1, y2;
-
- x1 = std::max(r.x(), 0);
- x2 = std::min(r.x() + r.width(), data->mDrawableSize.width());
- y1 = std::max(r.y(), 0);
- y2 = std::min(r.y() + r.height(), data->mDrawableSize.height());
+ auto x1 = std::max(r.x(), 0);
+ auto x2 = std::min(r.x() + r.width(), data->mDrawableSize.width());
+ auto y1 = std::max(r.y(), 0);
+ auto y2 = std::min(r.y() + r.height(), data->mDrawableSize.height());
if (x2 <= x1 || y2 <= y1) return;
int n = std::min(nspans, y2 - y);
int i = 0;
while (i < n) {
- spans[i].x = x1;
- spans[i].len = x2 - x1;
- spans[i].y = y + i;
+ spans[i].x = short(x1);
+ spans[i].len = ushort(x2 - x1);
+ spans[i].y = short(y + i);
spans[i].coverage = 255;
++i;
}
{
mSpanData.initTexture(&bitmap, const_alpha, VBitmapData::Plain, source);
if (!mSpanData.mUnclippedBlendFunc) return;
- mSpanData.dx = -target.x();
- mSpanData.dy = -target.y();
+ mSpanData.dx = float(-target.x());
+ mSpanData.dy = float(-target.y());
VRect rr = source.translated(target.x(), target.y());
{
if (!bitmap.valid()) return;
- drawBitmap(VRect(point.x(), point.y(), bitmap.width(), bitmap.height()),
+ drawBitmap(VRect(point, bitmap.size()),
bitmap, source, const_alpha);
}
{
if (!bitmap.valid()) return;
- drawBitmap(VRect(point.x(), point.y(), bitmap.width(), bitmap.height()),
- bitmap, VRect(0, 0, bitmap.width(), bitmap.height()),
+ drawBitmap(VRect(point, bitmap.size()),
+ bitmap, bitmap.rect(),
const_alpha);
}
{
if (!bitmap.valid()) return;
- drawBitmap(rect, bitmap, VRect(0, 0, bitmap.width(), bitmap.height()),
+ drawBitmap(rect, bitmap, bitmap.rect(),
const_alpha);
}
public:
VRect() = default;
VRect(int x, int y, int w, int h):x1(x),y1(y),x2(x+w),y2(y+h){}
+ explicit VRect(VPoint pt, VSize sz):VRect(pt.x(), pt.y(), sz.width(), sz.height()){}
explicit VRect(const VRectF &r);
V_CONSTEXPR bool empty() const {return x1 >= x2 || y1 >= y2;}
V_CONSTEXPR int left() const {return x1;}
class VRectF {
public:
VRectF() = default;
- VRectF(float x, float y, float w, float h):x1(x),y1(y),x2(x+w),y2(y+h){}
- explicit VRectF(const VRect &r):x1(float(r.left())),y1(float(r.top())),
- x2(float(r.right())),y2(float(r.bottom())){}
+
+ explicit VRectF(float x, float y, float w, float h):x1(x),y1(y),x2(x+w),y2(y+h){}
+
+ explicit VRectF(int x, int y, int w, int h):x1(float(x)),y1(float(y)),
+ x2(float(x+w)),y2(float(y+h)){}
+
+ explicit VRectF(const VRect &r):VRectF(r.x(), r.y(), r.width(), r.height()){}
V_CONSTEXPR bool empty() const {return x1 >= x2 || y1 >= y2;}
V_CONSTEXPR float left() const {return x1;}