---
Language: Cpp
-# BasedOnStyle: Tizen
+BasedOnStyle: Google
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
-/*
+/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "config.h"
-#include "rlottie.h"
#include "lottieitem.h"
#include "lottieloader.h"
#include "lottiemodel.h"
+#include "rlottie.h"
#include <fstream>
RenderTask() { receiver = sender.get_future(); }
std::promise<Surface> sender;
std::future<Surface> receiver;
- AnimationImpl *playerImpl{nullptr};
- size_t frameNo{0};
- Surface surface;
+ AnimationImpl * playerImpl{nullptr};
+ size_t frameNo{0};
+ Surface surface;
};
using SharedRenderTask = std::shared_ptr<RenderTask>;
class AnimationImpl {
-
public:
void init(const std::shared_ptr<LOTModel> &model);
bool update(size_t frameNo, const VSize &size);
- VSize size() const {return mCompItem->size();}
- double duration() const {return mModel->duration();}
- double frameRate() const {return mModel->frameRate();}
- size_t totalFrame() const {return mModel->totalFrame();}
- size_t frameAtPos(double pos) const {return mModel->frameAtPos(pos);}
+ VSize size() const { return mCompItem->size(); }
+ double duration() const { return mModel->duration(); }
+ double frameRate() const { return mModel->frameRate(); }
+ size_t totalFrame() const { return mModel->totalFrame(); }
+ size_t frameAtPos(double pos) const { return mModel->frameAtPos(pos); }
Surface render(size_t frameNo, const Surface &surface);
std::future<Surface> renderAsync(size_t frameNo, Surface &&surface);
- const LOTLayerNode *
- renderTree(size_t frameNo, const VSize &size);
+ const LOTLayerNode * renderTree(size_t frameNo, const VSize &size);
- const LayerInfoList& layerInfoList() const { return mModel->layerInfoList();}
+ const LayerInfoList &layerInfoList() const
+ {
+ return mModel->layerInfoList();
+ }
void setValue(const std::string &keypath, LOTVariant &&value);
void removeFilter(const std::string &keypath, Property prop);
+
private:
std::string mFilePath;
std::shared_ptr<LOTModel> mModel;
const LOTLayerNode *AnimationImpl::renderTree(size_t frameNo, const VSize &size)
{
if (update(frameNo, size)) {
- mCompItem->buildRenderTree();
+ mCompItem->buildRenderTree();
}
return mCompItem->renderTree();
}
bool AnimationImpl::update(size_t frameNo, const VSize &size)
{
- frameNo += mModel->startFrame();
+ frameNo += mModel->startFrame();
- if (frameNo > mModel->endFrame())
- frameNo = mModel->endFrame();
+ if (frameNo > mModel->endFrame()) frameNo = mModel->endFrame();
- if (frameNo < mModel->startFrame())
- frameNo = mModel->startFrame();
+ if (frameNo < mModel->startFrame()) frameNo = mModel->startFrame();
- mCompItem->resize(size);
- return mCompItem->update(frameNo);
+ mCompItem->resize(size);
+ return mCompItem->update(frameNo);
}
Surface AnimationImpl::render(size_t frameNo, const Surface &surface)
{
bool renderInProgress = mRenderInProgress.load();
- if (renderInProgress)
- {
+ if (renderInProgress) {
vCritical << "Already Rendering Scheduled for this Animation";
return surface;
- }
+ }
mRenderInProgress.store(true);
- update(frameNo, VSize(surface.drawRegionWidth(), surface.drawRegionHeight()));
+ update(frameNo,
+ VSize(surface.drawRegionWidth(), surface.drawRegionHeight()));
mCompItem->render(surface);
mRenderInProgress.store(false);
#ifdef LOTTIE_THREAD_SUPPORT
-#include "vtaskqueue.h"
#include <thread>
+#include "vtaskqueue.h"
/*
* Implement a task stealing schduler to perform render task
const unsigned _count{std::thread::hardware_concurrency()};
std::vector<std::thread> _threads;
std::vector<TaskQueue<SharedRenderTask>> _q{_count};
- std::atomic<unsigned> _index{0};
+ std::atomic<unsigned> _index{0};
void run(unsigned i)
{
while (true) {
- bool success = false;
+ bool success = false;
SharedRenderTask task;
for (unsigned n = 0; n != _count * 32; ++n) {
if (_q[(i + n) % _count].try_pop(task)) {
}
if (!success && !_q[i].pop(task)) break;
- auto result = task->playerImpl->render(task->frameNo, task->surface);
+ auto result =
+ task->playerImpl->render(task->frameNo, task->surface);
task->sender.set_value(result);
}
}
}
public:
- static RenderTaskScheduler& instance()
+ static RenderTaskScheduler &instance()
{
- static RenderTaskScheduler singleton;
- return singleton;
+ static RenderTaskScheduler singleton;
+ return singleton;
}
~RenderTaskScheduler()
#else
class RenderTaskScheduler {
public:
- static RenderTaskScheduler& instance()
+ static RenderTaskScheduler &instance()
{
- static RenderTaskScheduler singleton;
- return singleton;
+ static RenderTaskScheduler singleton;
+ return singleton;
}
std::future<Surface> process(SharedRenderTask task)
};
#endif
-
-std::future<Surface> AnimationImpl::renderAsync(size_t frameNo, Surface &&surface)
+std::future<Surface> AnimationImpl::renderAsync(size_t frameNo,
+ Surface &&surface)
{
if (!mTask) {
mTask = std::make_shared<RenderTask>();
* Description about the setFilePath Api
* @param path add the details
*/
-std::unique_ptr<Animation>
-Animation::loadFromData(std::string jsonData, const std::string &key, const std::string &resourcePath)
+std::unique_ptr<Animation> Animation::loadFromData(
+ std::string jsonData, const std::string &key,
+ const std::string &resourcePath)
{
if (jsonData.empty()) {
vWarning << "jason data is empty";
return nullptr;
}
-std::unique_ptr<Animation>
-Animation::loadFromFile(const std::string &path)
+std::unique_ptr<Animation> Animation::loadFromFile(const std::string &path)
{
if (path.empty()) {
vWarning << "File path is empty";
return d->frameAtPos(pos);
}
-const LOTLayerNode *
-Animation::renderTree(size_t frameNo, size_t width, size_t height) const
+const LOTLayerNode *Animation::renderTree(size_t frameNo, size_t width,
+ size_t height) const
{
return d->renderTree(frameNo, VSize(width, height));
}
d->render(frameNo, surface);
}
-const LayerInfoList& Animation::layers() const
+const LayerInfoList &Animation::layers() const
{
return d->layerInfoList();
}
-void Animation::setValue(Color_Type,Property prop,
- const std::string &keypath,
+void Animation::setValue(Color_Type, Property prop, const std::string &keypath,
Color value)
{
- d->setValue(keypath, LOTVariant(prop, [value](const FrameInfo &){ return value;}));
+ d->setValue(keypath,
+ LOTVariant(prop, [value](const FrameInfo &) { return value; }));
}
-void Animation::setValue(Float_Type, Property prop,
- const std::string &keypath,
+void Animation::setValue(Float_Type, Property prop, const std::string &keypath,
float value)
{
- d->setValue(keypath, LOTVariant(prop, [value](const FrameInfo &){ return value;}));
+ d->setValue(keypath,
+ LOTVariant(prop, [value](const FrameInfo &) { return value; }));
}
-void Animation::setValue(Size_Type,Property prop,
- const std::string &keypath,
+void Animation::setValue(Size_Type, Property prop, const std::string &keypath,
Size value)
{
- d->setValue(keypath, LOTVariant(prop, [value](const FrameInfo &){ return value;}));
+ d->setValue(keypath,
+ LOTVariant(prop, [value](const FrameInfo &) { return value; }));
}
-void Animation::setValue(Point_Type, Property prop,
- const std::string &keypath,
+void Animation::setValue(Point_Type, Property prop, const std::string &keypath,
Point value)
{
- d->setValue(keypath, LOTVariant(prop, [value](const FrameInfo &){ return value;}));
+ d->setValue(keypath,
+ LOTVariant(prop, [value](const FrameInfo &) { return value; }));
}
-void Animation::setValue(Color_Type,Property prop,
- const std::string &keypath,
- std::function<Color(const FrameInfo &)> && value)
+void Animation::setValue(Color_Type, Property prop, const std::string &keypath,
+ std::function<Color(const FrameInfo &)> &&value)
{
d->setValue(keypath, LOTVariant(prop, value));
}
-void Animation::setValue(Float_Type, Property prop,
- const std::string &keypath,
- std::function<float(const FrameInfo &)> && value)
+void Animation::setValue(Float_Type, Property prop, const std::string &keypath,
+ std::function<float(const FrameInfo &)> &&value)
{
d->setValue(keypath, LOTVariant(prop, value));
}
-void Animation::setValue(Size_Type,Property prop,
- const std::string &keypath,
- std::function<Size(const FrameInfo &)> && value)
+void Animation::setValue(Size_Type, Property prop, const std::string &keypath,
+ std::function<Size(const FrameInfo &)> &&value)
{
d->setValue(keypath, LOTVariant(prop, value));
}
-void Animation::setValue(Point_Type, Property prop,
- const std::string &keypath,
- std::function<Point(const FrameInfo &)> && value)
+void Animation::setValue(Point_Type, Property prop, const std::string &keypath,
+ std::function<Point(const FrameInfo &)> &&value)
{
d->setValue(keypath, LOTVariant(prop, value));
}
-Animation::Animation(): d(std::make_unique<AnimationImpl>()) {}
+Animation::Animation() : d(std::make_unique<AnimationImpl>()) {}
/*
* this is only to supress build fail
* because unique_ptr expects the destructor in the same translation unit.
*/
-Animation::~Animation(){}
-
-Surface::Surface(uint32_t *buffer,
- size_t width, size_t height, size_t bytesPerLine)
- :mBuffer(buffer),
- mWidth(width),
- mHeight(height),
- mBytesPerLine(bytesPerLine)
+Animation::~Animation() {}
+
+Surface::Surface(uint32_t *buffer, size_t width, size_t height,
+ size_t bytesPerLine)
+ : mBuffer(buffer),
+ mWidth(width),
+ mHeight(height),
+ mBytesPerLine(bytesPerLine)
{
mDrawArea.w = mWidth;
mDrawArea.h = mHeight;
void Surface::setDrawRegion(size_t x, size_t y, size_t width, size_t height)
{
- if ((x + width > mWidth) ||
- (y + height > mHeight)) return;
+ if ((x + width > mWidth) || (y + height > mHeight)) return;
mDrawArea.x = x;
mDrawArea.y = y;
mDrawArea.h = height;
}
-
#ifdef LOTTIE_LOGGING_SUPPORT
void initLogging()
{
-/*
+/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "lottieitem.h"
-#include <cmath>
#include <algorithm>
-#include <iterator>
+#include <cmath>
+#include <iterator>
+#include "lottiekeypath.h"
#include "vbitmap.h"
#include "vdasher.h"
#include "vpainter.h"
#include "vraster.h"
-#include "lottiekeypath.h"
/* Lottie Layer Rules
* 1. time stretch is pre calculated and applied to all the properties of the
* AE. which means (start frame > endFrame) 3.
*/
-static
-bool transformProp(rlottie::Property prop)
+static bool transformProp(rlottie::Property prop)
{
switch (prop) {
- case rlottie::Property::TrAnchor:
- case rlottie::Property::TrScale:
- case rlottie::Property::TrOpacity:
- case rlottie::Property::TrPosition:
- case rlottie::Property::TrRotation:
- return true;
- default:
- return false;
+ case rlottie::Property::TrAnchor:
+ case rlottie::Property::TrScale:
+ case rlottie::Property::TrOpacity:
+ case rlottie::Property::TrPosition:
+ case rlottie::Property::TrRotation:
+ return true;
+ default:
+ return false;
}
}
-static
-bool fillProp(rlottie::Property prop)
+static bool fillProp(rlottie::Property prop)
{
switch (prop) {
- case rlottie::Property::FillColor:
- case rlottie::Property::FillOpacity:
- return true;
- default:
- return false;
+ case rlottie::Property::FillColor:
+ case rlottie::Property::FillOpacity:
+ return true;
+ default:
+ return false;
}
}
-static
-bool strokeProp(rlottie::Property prop)
+static bool strokeProp(rlottie::Property prop)
{
switch (prop) {
- case rlottie::Property::StrokeColor:
- case rlottie::Property::StrokeOpacity:
- case rlottie::Property::StrokeWidth:
- return true;
- default:
- return false;
+ case rlottie::Property::StrokeColor:
+ case rlottie::Property::StrokeOpacity:
+ case rlottie::Property::StrokeWidth:
+ return true;
+ default:
+ return false;
}
}
mRootLayer->resolveKeyPath(key, 0, value);
}
-std::unique_ptr<LOTLayerItem>
-LOTCompItem::createLayerItem(LOTLayerData *layerData)
+std::unique_ptr<LOTLayerItem> LOTCompItem::createLayerItem(
+ LOTLayerData *layerData)
{
switch (layerData->mLayerType) {
case LayerType::Precomp: {
mRootLayer->buildLayerNode();
}
-const LOTLayerNode * LOTCompItem::renderTree() const
+const LOTLayerNode *LOTCompItem::renderTree() const
{
return mRootLayer->layerNode();
}
bool LOTCompItem::render(const rlottie::Surface &surface)
{
- VBitmap bitmap(reinterpret_cast<uchar *>(surface.buffer()),
- surface.width(), surface.height(),
- surface.bytesPerLine(), VBitmap::Format::ARGB32_Premultiplied);
-
+ VBitmap bitmap(reinterpret_cast<uchar *>(surface.buffer()), surface.width(),
+ surface.height(), surface.bytesPerLine(),
+ VBitmap::Format::ARGB32_Premultiplied);
/* schedule all preprocess task for this frame at once.
*/
VPainter painter(&bitmap);
// set sub surface area for drawing.
- painter.setDrawRegion(VRect(surface.drawRegionPosX(), surface.drawRegionPosY(),
- surface.drawRegionWidth(), surface.drawRegionHeight()));
+ painter.setDrawRegion(
+ VRect(surface.drawRegionPosX(), surface.drawRegionPosY(),
+ surface.drawRegionWidth(), surface.drawRegionHeight()));
mRootLayer->render(&painter, {}, {});
return true;
}
-void LOTMaskItem::update(int frameNo, const VMatrix &parentMatrix,
+void LOTMaskItem::update(int frameNo, const VMatrix & parentMatrix,
float /*parentAlpha*/, const DirtyFlag &flag)
{
if (flag.testFlag(DirtyFlagBit::None) && mData->isStatic()) return;
mLayerCNode->mClipPath.elmCount = 0;
mLayerCNode->name = name().c_str();
}
- if (complexContent())
- mLayerCNode->mAlpha = combinedAlpha() * 255;
+ if (complexContent()) mLayerCNode->mAlpha = combinedAlpha() * 255;
mLayerCNode->mVisible = visible();
// update matte
if (hasMatte()) {
mMasksCNode.resize(mLayerMask->mMasks.size());
size_t i = 0;
for (const auto &mask : mLayerMask->mMasks) {
- LOTMask *cNode = &mMasksCNode[i++];
+ 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());
}
}
-void LOTLayerItem::render(VPainter *painter, const VRle &inheritMask, const VRle &matteRle)
+void LOTLayerItem::render(VPainter *painter, const VRle &inheritMask,
+ const VRle &matteRle)
{
mDrawableList.clear();
renderList(mDrawableList);
VRle mask;
if (mLayerMask) {
mask = mLayerMask->maskRle(painter->clipBoundingRect());
- if (!inheritMask.empty())
- mask = mask & inheritMask;
+ if (!inheritMask.empty()) mask = mask & inheritMask;
// if resulting mask is empty then return.
- if (mask.empty())
- return;
+ if (mask.empty()) return;
} else {
mask = inheritMask;
}
}
}
-void LOTLayerMaskItem::update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag)
+void LOTLayerMaskItem::update(int frameNo, const VMatrix &parentMatrix,
+ float parentAlpha, const DirtyFlag &flag)
{
if (flag.testFlag(DirtyFlagBit::None) && isStatic()) return;
break;
}
case LOTMaskData::Mode::Substarct: {
- if (rle.empty() && !clipRect.empty())
- rle = VRle::toRle(clipRect);
+ if (rle.empty() && !clipRect.empty()) rle = VRle::toRle(clipRect);
rle = rle - i.rle();
break;
}
case LOTMaskData::Mode::Intersect: {
- if (rle.empty() && !clipRect.empty())
- rle = VRle::toRle(clipRect);
+ if (rle.empty() && !clipRect.empty()) rle = VRle::toRle(clipRect);
rle = rle & i.rle();
break;
}
return mRle;
}
-
-LOTLayerItem::LOTLayerItem(LOTLayerData *layerData): mLayerData(layerData)
+LOTLayerItem::LOTLayerItem(LOTLayerData *layerData) : mLayerData(layerData)
{
if (mLayerData->mHasMask)
mLayerMask = std::make_unique<LOTLayerMaskItem>(mLayerData);
LOTVariant &value)
{
if (!keyPath.matches(name(), depth)) {
- return false;
+ return false;
}
if (!keyPath.skip(name())) {
- if (keyPath.fullyResolvesTo(name(), depth) &&
- transformProp(value.property())) {
- //@TODO handle propery update.
- }
+ if (keyPath.fullyResolvesTo(name(), depth) &&
+ transformProp(value.property())) {
+ //@TODO handle propery update.
+ }
}
return true;
}
bool LOTShapeLayerItem::resolveKeyPath(LOTKeyPath &keyPath, uint depth,
LOTVariant &value)
{
- if (LOTLayerItem::resolveKeyPath(keyPath, depth, value)){
+ if (LOTLayerItem::resolveKeyPath(keyPath, depth, value)) {
if (keyPath.propagate(name(), depth)) {
uint newDepth = keyPath.nextDepth(name(), depth);
mRoot->resolveKeyPath(keyPath, newDepth, value);
if (keyPath.propagate(name(), depth)) {
uint newDepth = keyPath.nextDepth(name(), depth);
for (const auto &layer : mLayers) {
- layer->resolveKeyPath( keyPath, newDepth, value);
+ layer->resolveKeyPath(keyPath, newDepth, value);
}
}
return true;
VMatrix m = matrix(frameNo());
m *= parentMatrix;
-
// 3. update the dirty flag based on the change
if (!mCombinedMatrix.fuzzyCompare(m)) {
mDirtyFlag |= DirtyFlagBit::Matrix;
}
// 5. if no parent property change and layer is static then nothing to do.
- if (!mLayerData->precompLayer() &&
- flag().testFlag(DirtyFlagBit::None) &&
- isStatic()) return;
+ if (!mLayerData->precompLayer() && flag().testFlag(DirtyFlagBit::None) &&
+ isStatic())
+ return;
// 6. update the content of the layer
updateContent();
VMatrix LOTLayerItem::matrix(int frameNo) const
{
- return mParentLayer ?
- (mLayerData->matrix(frameNo) * mParentLayer->matrix(frameNo)) :
- mLayerData->matrix(frameNo);
+ return mParentLayer
+ ? (mLayerData->matrix(frameNo) * mParentLayer->matrix(frameNo))
+ : mLayerData->matrix(frameNo);
}
bool LOTLayerItem::visible() const
LOTCompLayerItem::LOTCompLayerItem(LOTLayerData *layerModel)
: LOTLayerItem(layerModel)
-{
+{
// 1. create layer item
for (auto &i : mLayerData->mChildren) {
LOTLayerData *layerModel = static_cast<LOTLayerData *>(i.get());
- auto layerItem = LOTCompItem::createLayerItem(layerModel);
+ auto layerItem = LOTCompItem::createLayerItem(layerModel);
if (layerItem) mLayers.push_back(std::move(layerItem));
}
for (const auto &layer : mLayers) {
int id = layer->parentId();
if (id >= 0) {
- auto search = std::find_if(mLayers.begin(), mLayers.end(),
- [id](const auto& val){ return val->id() == id;});
+ auto search =
+ std::find_if(mLayers.begin(), mLayers.end(),
+ [id](const auto &val) { return val->id() == id; });
if (search != mLayers.end()) layer->setParentLayer((*search).get());
}
}
}
}
-void LOTCompLayerItem::render(VPainter *painter, const VRle &inheritMask, const VRle &matteRle)
+void LOTCompLayerItem::render(VPainter *painter, const VRle &inheritMask,
+ const VRle &matteRle)
{
if (vIsZero(combinedAlpha())) return;
renderHelper(painter, inheritMask, matteRle);
} else {
if (complexContent()) {
- VSize size = painter->clipBoundingRect().size();
+ VSize size = painter->clipBoundingRect().size();
VPainter srcPainter;
- VBitmap srcBitmap(size.width(), size.height(), VBitmap::Format::ARGB32_Premultiplied);
+ VBitmap srcBitmap(size.width(), size.height(),
+ VBitmap::Format::ARGB32_Premultiplied);
srcPainter.begin(&srcBitmap);
renderHelper(&srcPainter, inheritMask, matteRle);
srcPainter.end();
}
}
-void LOTCompLayerItem::renderHelper(VPainter *painter, const VRle &inheritMask, const VRle &matteRle)
+void LOTCompLayerItem::renderHelper(VPainter *painter, const VRle &inheritMask,
+ const VRle &matteRle)
{
VRle mask;
if (mLayerMask) {
mask = mLayerMask->maskRle(painter->clipBoundingRect());
- if (!inheritMask.empty())
- mask = mask & inheritMask;
+ if (!inheritMask.empty()) mask = mask & inheritMask;
// if resulting mask is empty then return.
- if (mask.empty())
- return;
+ if (mask.empty()) return;
} else {
mask = inheritMask;
}
if (layer->visible()) {
if (matte) {
if (matte->visible())
- renderMatteLayer(painter, mask, matteRle, matte, layer.get());
+ renderMatteLayer(painter, mask, matteRle, matte,
+ layer.get());
} else {
layer->render(painter, mask, matteRle);
}
}
}
-void LOTCompLayerItem::renderMatteLayer(VPainter *painter,
- const VRle &mask,
- const VRle &matteRle,
- LOTLayerItem *layer,
- LOTLayerItem *src)
+void LOTCompLayerItem::renderMatteLayer(VPainter *painter, const VRle &mask,
+ const VRle & matteRle,
+ LOTLayerItem *layer, LOTLayerItem *src)
{
VSize size = painter->clipBoundingRect().size();
// Decide if we can use fast matte.
// 1. draw src layer to matte buffer
VPainter srcPainter;
- src->bitmap().reset(size.width(), size.height(), VBitmap::Format::ARGB32_Premultiplied);
+ src->bitmap().reset(size.width(), size.height(),
+ VBitmap::Format::ARGB32_Premultiplied);
srcPainter.begin(&src->bitmap());
src->render(&srcPainter, mask, matteRle);
srcPainter.end();
// 2. draw layer to layer buffer
VPainter layerPainter;
- layer->bitmap().reset(size.width(), size.height(), VBitmap::Format::ARGB32_Premultiplied);
+ layer->bitmap().reset(size.width(), size.height(),
+ VBitmap::Format::ARGB32_Premultiplied);
layerPainter.begin(&layer->bitmap());
layer->render(&layerPainter, mask, matteRle);
switch (layer->matteType()) {
case MatteType::Alpha:
case MatteType::Luma: {
- layerPainter.setCompositionMode(VPainter::CompositionMode::CompModeDestIn);
+ layerPainter.setCompositionMode(
+ VPainter::CompositionMode::CompModeDestIn);
break;
}
case MatteType::AlphaInv:
case MatteType::LumaInv: {
- layerPainter.setCompositionMode(VPainter::CompositionMode::CompModeDestOut);
+ layerPainter.setCompositionMode(
+ VPainter::CompositionMode::CompModeDestOut);
break;
}
default:
break;
}
- //2.2 update srcBuffer if the matte is luma type
+ // 2.2 update srcBuffer if the matte is luma type
if (layer->matteType() == MatteType::Luma ||
layer->matteType() == MatteType::LumaInv) {
src->bitmap().updateLuma();
void LOTClipperItem::update(const VMatrix &matrix)
{
mPath.reset();
- mPath.addRect(VRectF(0,0, mSize.width(), mSize.height()));
+ mPath.addRect(VRectF(0, 0, mSize.width(), mSize.height()));
mPath.transform(matrix);
mRasterizer.rasterize(mPath);
}
if (mClipper && flag().testFlag(DirtyFlagBit::Matrix)) {
mClipper->update(combinedMatrix());
}
- int mappedFrame = mLayerData->timeRemap(frameNo());
+ int mappedFrame = mLayerData->timeRemap(frameNo());
float alpha = combinedAlpha();
if (complexContent()) alpha = 1;
for (const auto &layer : mLayers) {
- layer->update( mappedFrame, combinedMatrix(), alpha);
+ layer->update(mappedFrame, combinedMatrix(), alpha);
}
}
LOTSolidLayerItem::LOTSolidLayerItem(LOTLayerData *layerData)
: LOTLayerItem(layerData)
-{}
+{
+}
void LOTSolidLayerItem::updateContent()
{
{
if (flag() & DirtyFlagBit::Matrix) {
VPath path;
- path.addRect(
- VRectF(0, 0, mLayerData->mAsset->mWidth, mLayerData->mAsset->mHeight));
+ path.addRect(VRectF(0, 0, mLayerData->mAsset->mWidth,
+ mLayerData->mAsset->mHeight));
path.transform(combinedMatrix());
mRenderNode.mFlag |= VDrawable::DirtyState::Path;
mRenderNode.mPath = path;
LOTDrawable *lotDrawable = static_cast<LOTDrawable *>(i);
lotDrawable->sync();
- lotDrawable->mCNode->mImageInfo.data = lotDrawable->mBrush.mTexture.data();
- lotDrawable->mCNode->mImageInfo.width = lotDrawable->mBrush.mTexture.width();
- lotDrawable->mCNode->mImageInfo.height = lotDrawable->mBrush.mTexture.height();
+ lotDrawable->mCNode->mImageInfo.data =
+ lotDrawable->mBrush.mTexture.data();
+ lotDrawable->mCNode->mImageInfo.width =
+ lotDrawable->mBrush.mTexture.width();
+ lotDrawable->mCNode->mImageInfo.height =
+ lotDrawable->mBrush.mTexture.height();
lotDrawable->mCNode->mImageInfo.mMatrix.m11 = combinedMatrix().m_11();
lotDrawable->mCNode->mImageInfo.mMatrix.m12 = combinedMatrix().m_12();
}
}
-std::unique_ptr<LOTContentItem>
-LOTShapeLayerItem::createContentItem(LOTData *contentData)
+std::unique_ptr<LOTContentItem> LOTShapeLayerItem::createContentItem(
+ LOTData *contentData)
{
switch (contentData->type()) {
case LOTData::Type::ShapeGroup: {
static_cast<LOTGroupData *>(contentData));
}
case LOTData::Type::Rect: {
- return std::make_unique<LOTRectItem>(static_cast<LOTRectData *>(contentData));
+ return std::make_unique<LOTRectItem>(
+ static_cast<LOTRectData *>(contentData));
}
case LOTData::Type::Ellipse: {
- return std::make_unique<LOTEllipseItem>(static_cast<LOTEllipseData *>(contentData));
+ return std::make_unique<LOTEllipseItem>(
+ static_cast<LOTEllipseData *>(contentData));
}
case LOTData::Type::Shape: {
- return std::make_unique<LOTShapeItem>(static_cast<LOTShapeData *>(contentData));
+ return std::make_unique<LOTShapeItem>(
+ static_cast<LOTShapeData *>(contentData));
}
case LOTData::Type::Polystar: {
- return std::make_unique<LOTPolystarItem>(static_cast<LOTPolystarData *>(contentData));
+ return std::make_unique<LOTPolystarItem>(
+ static_cast<LOTPolystarData *>(contentData));
}
case LOTData::Type::Fill: {
- return std::make_unique<LOTFillItem>(static_cast<LOTFillData *>(contentData));
+ return std::make_unique<LOTFillItem>(
+ static_cast<LOTFillData *>(contentData));
}
case LOTData::Type::GFill: {
- return std::make_unique<LOTGFillItem>(static_cast<LOTGFillData *>(contentData));
+ return std::make_unique<LOTGFillItem>(
+ static_cast<LOTGFillData *>(contentData));
}
case LOTData::Type::Stroke: {
- return std::make_unique<LOTStrokeItem>(static_cast<LOTStrokeData *>(contentData));
+ return std::make_unique<LOTStrokeItem>(
+ static_cast<LOTStrokeData *>(contentData));
}
case LOTData::Type::GStroke: {
- return std::make_unique<LOTGStrokeItem>(static_cast<LOTGStrokeData *>(contentData));
+ return std::make_unique<LOTGStrokeItem>(
+ static_cast<LOTGStrokeData *>(contentData));
}
case LOTData::Type::Repeater: {
- return std::make_unique<LOTRepeaterItem>(static_cast<LOTRepeaterData *>(contentData));
+ return std::make_unique<LOTRepeaterItem>(
+ static_cast<LOTRepeaterData *>(contentData));
}
case LOTData::Type::Trim: {
- return std::make_unique<LOTTrimItem>(static_cast<LOTTrimData *>(contentData));
+ return std::make_unique<LOTTrimItem>(
+ static_cast<LOTTrimData *>(contentData));
}
default:
return nullptr;
mRoot->renderList(list);
}
-bool LOTContentGroupItem::resolveKeyPath(LOTKeyPath &keyPath, uint depth, LOTVariant &value)
+bool LOTContentGroupItem::resolveKeyPath(LOTKeyPath &keyPath, uint depth,
+ LOTVariant &value)
{
if (!keyPath.matches(name(), depth)) {
- return false;
+ return false;
}
if (!keyPath.skip(name())) {
- if (keyPath.fullyResolvesTo(name(), depth) &&
- transformProp(value.property())) {
- //@TODO handle property update
- }
+ if (keyPath.fullyResolvesTo(name(), depth) &&
+ transformProp(value.property())) {
+ //@TODO handle property update
+ }
}
if (keyPath.propagate(name(), depth)) {
uint newDepth = keyPath.nextDepth(name(), depth);
for (auto &child : mContents) {
- child->resolveKeyPath( keyPath, newDepth, value);
+ child->resolveKeyPath(keyPath, newDepth, value);
}
}
return true;
}
-bool LOTFillItem::resolveKeyPath(LOTKeyPath &keyPath, uint depth, LOTVariant &value)
+bool LOTFillItem::resolveKeyPath(LOTKeyPath &keyPath, uint depth,
+ LOTVariant &value)
{
if (!keyPath.matches(mModel.name(), depth)) {
- return false;
+ return false;
}
if (keyPath.fullyResolvesTo(mModel.name(), depth) &&
return false;
}
-bool LOTStrokeItem::resolveKeyPath(LOTKeyPath &keyPath, uint depth, LOTVariant &value)
+bool LOTStrokeItem::resolveKeyPath(LOTKeyPath &keyPath, uint depth,
+ LOTVariant &value)
{
if (!keyPath.matches(mModel.name(), depth)) {
- return false;
+ return false;
}
if (keyPath.fullyResolvesTo(mModel.name(), depth) &&
return false;
}
-LOTContentGroupItem::LOTContentGroupItem(LOTGroupData *data) :
- LOTContentItem(ContentType::Group),
- mData(data)
+LOTContentGroupItem::LOTContentGroupItem(LOTGroupData *data)
+ : LOTContentItem(ContentType::Group), mData(data)
{
addChildren(mData);
}
break;
}
case ContentType::Paint: {
- static_cast<LOTPaintDataItem *>(content)->addPathItems(list, curOpCount);
+ static_cast<LOTPaintDataItem *>(content)->addPathItems(list,
+ curOpCount);
break;
}
case ContentType::Group: {
- static_cast<LOTContentGroupItem *>(content)->processPaintItems(list);
+ static_cast<LOTContentGroupItem *>(content)->processPaintItems(
+ list);
break;
}
default:
}
}
-void LOTContentGroupItem::processTrimItems(
- std::vector<LOTPathDataItem *> &list)
+void LOTContentGroupItem::processTrimItems(std::vector<LOTPathDataItem *> &list)
{
int curOpCount = list.size();
for (auto i = mContents.rbegin(); i != mContents.rend(); ++i) {
* mTemp - keeps a referece to the mLocalPath and can be updated by the
* path operation objects(trim, merge path),
* mFinalPath - it takes a deep copy of the intermediate path(mTemp) each time
- * when the path is dirty(so if path changes every frame we don't realloc just copy to the
- * final path).
- * NOTE: As path objects are COW objects we have to be carefull about the refcount so that
- * we don't generate deep copy while modifying the path objects.
+ * when the path is dirty(so if path changes every frame we don't realloc just
+ * copy to the final path). NOTE: As path objects are COW objects we have to be
+ * carefull about the refcount so that we don't generate deep copy while
+ * modifying the path objects.
*/
-void LOTPathDataItem::update(int frameNo, const VMatrix &,
- float, const DirtyFlag &flag)
+void LOTPathDataItem::update(int frameNo, const VMatrix &, float,
+ const DirtyFlag &flag)
{
mPathChanged = false;
}
}
-const VPath & LOTPathDataItem::finalPath()
+const VPath &LOTPathDataItem::finalPath()
{
if (mPathChanged || mNeedUpdate) {
mFinalPath.clone(mTemp);
- mFinalPath.transform(static_cast<LOTContentGroupItem *>(parent())->matrix());
+ mFinalPath.transform(
+ static_cast<LOTContentGroupItem *>(parent())->matrix());
mNeedUpdate = false;
}
return mFinalPath;
{
}
-void LOTRectItem::updatePath(VPath& path, int frameNo)
+void LOTRectItem::updatePath(VPath &path, int frameNo)
{
VPointF pos = mData->mPos.value(frameNo);
VPointF size = mData->mSize.value(frameNo);
{
}
-void LOTEllipseItem::updatePath(VPath& path, int frameNo)
+void LOTEllipseItem::updatePath(VPath &path, int frameNo)
{
VPointF pos = mData->mPos.value(frameNo);
VPointF size = mData->mSize.value(frameNo);
{
}
-void LOTShapeItem::updatePath(VPath& path, int frameNo)
+void LOTShapeItem::updatePath(VPath &path, int frameNo)
{
mData->mShape.value(frameNo).toPath(path);
}
{
}
-void LOTPolystarItem::updatePath(VPath& path, int frameNo)
+void LOTPolystarItem::updatePath(VPath &path, int frameNo)
{
VPointF pos = mData->mPos.value(frameNo);
float points = mData->mPointCount.value(frameNo);
* PaintData Node handling
*
*/
-LOTPaintDataItem::LOTPaintDataItem(bool staticContent):
- LOTContentItem(ContentType::Paint),
- mStaticContent(staticContent){}
+LOTPaintDataItem::LOTPaintDataItem(bool staticContent)
+ : LOTContentItem(ContentType::Paint), mStaticContent(staticContent)
+{
+}
-void LOTPaintDataItem::update(int frameNo, const VMatrix &/*parentMatrix*/,
+void LOTPaintDataItem::update(int frameNo, const VMatrix & /*parentMatrix*/,
float parentAlpha, const DirtyFlag &flag)
{
mRenderNodeUpdate = true;
list.push_back(&mDrawable);
}
-
-void LOTPaintDataItem::addPathItems(std::vector<LOTPathDataItem *> &list, int startOffset)
+void LOTPaintDataItem::addPathItems(std::vector<LOTPathDataItem *> &list,
+ int startOffset)
{
- std::copy(list.begin() + startOffset, list.end(), back_inserter(mPathItems));
+ std::copy(list.begin() + startOffset, list.end(),
+ back_inserter(mPathItems));
}
-
LOTFillItem::LOTFillItem(LOTFillData *data)
: LOTPaintDataItem(data->isStatic()), mModel(data)
{
color.setAlpha(color.a * parentAlpha());
VBrush brush(color);
mDrawable.setBrush(brush);
- float scale = getScale(static_cast<LOTContentGroupItem *>(parent())->matrix());
- mDrawable.setStrokeInfo(mModel.capStyle(), mModel.joinStyle(), mModel.meterLimit(),
- mWidth * scale);
+ float scale =
+ getScale(static_cast<LOTContentGroupItem *>(parent())->matrix());
+ mDrawable.setStrokeInfo(mModel.capStyle(), mModel.joinStyle(),
+ mModel.meterLimit(), mWidth * scale);
if (mDashArraySize) {
- for (int i = 0 ; i < mDashArraySize ; i++)
- mDashArray[i] *= scale;
+ for (int i = 0; i < mDashArraySize; i++) mDashArray[i] *= scale;
/* AE draw the dash even if dash value is 0 */
- if (vCompare(mDashArray[0], 0.0f)) mDashArray[0]= 0.1;
+ if (vCompare(mDashArray[0], 0.0f)) mDashArray[0] = 0.1;
mDrawable.setDashInfo(mDashArray, mDashArraySize);
}
float scale = getScale(mGradient->mMatrix);
mGradient->setAlpha(mAlpha * parentAlpha());
mDrawable.setBrush(VBrush(mGradient.get()));
- mDrawable.setStrokeInfo(mCap, mJoin, mMiterLimit,
- mWidth * scale);
+ mDrawable.setStrokeInfo(mCap, mJoin, mMiterLimit, mWidth * scale);
if (mDashArraySize) {
- for (int i = 0 ; i < mDashArraySize ; i++)
- mDashArray[i] *= scale;
+ for (int i = 0; i < mDashArraySize; i++) mDashArray[i] *= scale;
mDrawable.setDashInfo(mDashArray, mDashArraySize);
}
}
-LOTTrimItem::LOTTrimItem(LOTTrimData *data):
- LOTContentItem(ContentType::Trim),
- mData(data) {}
+LOTTrimItem::LOTTrimItem(LOTTrimData *data)
+ : LOTContentItem(ContentType::Trim), mData(data)
+{
+}
-void LOTTrimItem::update(int frameNo, const VMatrix &/*parentMatrix*/,
- float /*parentAlpha*/, const DirtyFlag &/*flag*/)
+void LOTTrimItem::update(int frameNo, const VMatrix & /*parentMatrix*/,
+ float /*parentAlpha*/, const DirtyFlag & /*flag*/)
{
mDirty = false;
return;
}
- if (vCompare(std::fabs(mCache.mSegment.start - mCache.mSegment.end) , 1)) {
+ if (vCompare(std::fabs(mCache.mSegment.start - mCache.mSegment.end), 1)) {
for (auto &i : mPathItems) {
i->updatePath(i->localPath());
}
pm.setEnd(mCache.mSegment.end);
i->updatePath(pm.trim(i->localPath()));
}
- } else { // LOTTrimData::TrimType::Individually
+ } else { // LOTTrimData::TrimType::Individually
float totalLength = 0.0;
for (auto &i : mPathItems) {
totalLength += i->localPath().length();
}
float start = totalLength * mCache.mSegment.start;
- float end = totalLength * mCache.mSegment.end;
+ float end = totalLength * mCache.mSegment.end;
- if (start < end ) {
+ if (start < end) {
float curLen = 0.0;
for (auto &i : mPathItems) {
if (curLen > end) {
}
float len = i->localPath().length();
- if (curLen < start && curLen + len < start) {
+ if (curLen < start && curLen + len < start) {
curLen += len;
// update with empty path.
i->updatePath(VPath());
}
}
}
-
}
-
-void LOTTrimItem::addPathItems(std::vector<LOTPathDataItem *> &list, int startOffset)
+void LOTTrimItem::addPathItems(std::vector<LOTPathDataItem *> &list,
+ int startOffset)
{
- std::copy(list.begin() + startOffset, list.end(), back_inserter(mPathItems));
+ std::copy(list.begin() + startOffset, list.end(),
+ back_inserter(mPathItems));
}
-
LOTRepeaterItem::LOTRepeaterItem(LOTRepeaterData *data) : mRepeaterData(data)
{
assert(mRepeaterData->content());
mCopies = mRepeaterData->maxCopies();
- for (int i= 0; i < mCopies; i++) {
- auto content = std::make_unique<LOTContentGroupItem>(mRepeaterData->content());
+ for (int i = 0; i < mCopies; i++) {
+ auto content =
+ std::make_unique<LOTContentGroupItem>(mRepeaterData->content());
content->setParent(this);
mContents.push_back(std::move(content));
}
}
-void LOTRepeaterItem::update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag)
+void LOTRepeaterItem::update(int frameNo, const VMatrix &parentMatrix,
+ float parentAlpha, const DirtyFlag &flag)
{
-
DirtyFlag newFlag = flag;
float copies = mRepeaterData->copies(frameNo);
- int visibleCopies = int(copies);
+ int visibleCopies = int(copies);
if (visibleCopies == 0) {
mHidden = true;
newFlag |= DirtyFlagBit::Alpha;
for (int i = 0; i < mCopies; ++i) {
- float newAlpha = parentAlpha * lerp(startOpacity, endOpacity, i / copies);
+ float newAlpha =
+ parentAlpha * lerp(startOpacity, endOpacity, i / copies);
// hide rest of the copies , @TODO find a better solution.
- if ( i >= visibleCopies) newAlpha = 0;
+ if (i >= visibleCopies) newAlpha = 0;
- VMatrix result = mRepeaterData->mTransform.matrix(frameNo, i + offset) * parentMatrix;
+ VMatrix result = mRepeaterData->mTransform.matrix(frameNo, i + offset) *
+ parentMatrix;
mContents[i]->update(frameNo, result, newAlpha, newFlag);
}
}
static void updateGStops(LOTNode *n, const VGradient *grad)
{
if (grad->mStops.size() != n->mGradient.stopCount) {
- if (n->mGradient.stopCount)
- free(n->mGradient.stopPtr);
+ if (n->mGradient.stopCount) free(n->mGradient.stopPtr);
n->mGradient.stopCount = grad->mStops.size();
- n->mGradient.stopPtr = (LOTGradientStop *) malloc(n->mGradient.stopCount * sizeof(LOTGradientStop));
+ n->mGradient.stopPtr = (LOTGradientStop *)malloc(
+ n->mGradient.stopCount * sizeof(LOTGradientStop));
}
LOTGradientStop *ptr = n->mGradient.stopPtr;
ptr->b = i.second.blue();
ptr++;
}
-
}
void LOTDrawable::sync()
case VBrush::Type::LinearGradient: {
mCNode->mBrushType = LOTBrushType::BrushGradient;
mCNode->mGradient.type = LOTGradientType::GradientLinear;
- VPointF s = mBrush.mGradient->mMatrix.map({mBrush.mGradient->linear.x1,
- mBrush.mGradient->linear.y1});
- VPointF e = mBrush.mGradient->mMatrix.map({mBrush.mGradient->linear.x2,
- mBrush.mGradient->linear.y2});
+ VPointF s = mBrush.mGradient->mMatrix.map(
+ {mBrush.mGradient->linear.x1, mBrush.mGradient->linear.y1});
+ VPointF e = mBrush.mGradient->mMatrix.map(
+ {mBrush.mGradient->linear.x2, mBrush.mGradient->linear.y2});
mCNode->mGradient.start.x = s.x();
mCNode->mGradient.start.y = s.y();
mCNode->mGradient.end.x = e.x();
case VBrush::Type::RadialGradient: {
mCNode->mBrushType = LOTBrushType::BrushGradient;
mCNode->mGradient.type = LOTGradientType::GradientRadial;
- VPointF c = mBrush.mGradient->mMatrix.map({mBrush.mGradient->radial.cx,
- mBrush.mGradient->radial.cy});
- VPointF f = mBrush.mGradient->mMatrix.map({mBrush.mGradient->radial.fx,
- mBrush.mGradient->radial.fy});
+ VPointF c = mBrush.mGradient->mMatrix.map(
+ {mBrush.mGradient->radial.cx, mBrush.mGradient->radial.cy});
+ VPointF f = mBrush.mGradient->mMatrix.map(
+ {mBrush.mGradient->radial.fx, mBrush.mGradient->radial.fy});
mCNode->mGradient.center.x = c.x();
mCNode->mGradient.center.y = c.y();
mCNode->mGradient.focal.x = f.x();
LOTKeyPath::LOTKeyPath(const std::string &keyPath)
{
- std::stringstream ss (keyPath);
- std::string item;
+ std::stringstream ss(keyPath);
+ std::string item;
- while (getline (ss, item, '.')) {
- mKeys.push_back (item);
+ while (getline(ss, item, '.')) {
+ mKeys.push_back(item);
}
}
bool LOTKeyPath::matches(const std::string &key, uint depth)
{
- if (skip(key)) {
- // This is an object we programatically create.
- return true;
- }
- if (depth > size()) {
+ if (skip(key)) {
+ // This is an object we programatically create.
+ return true;
+ }
+ if (depth > size()) {
+ return false;
+ }
+ if ((mKeys[depth] == key) || (mKeys[depth] == "*") ||
+ (mKeys[depth] == "**")) {
+ return true;
+ }
return false;
- }
- if ((mKeys[depth] == key) ||
- (mKeys[depth] == "*") ||
- (mKeys[depth] == "**")) {
- return true;
- }
- return false;
}
-uint LOTKeyPath::nextDepth(const std::string key, uint depth) {
- if (skip(key)) {
- // If it's a container then we added programatically and it isn't a part of the keypath.
- return depth;
- }
- if ( mKeys[depth] != "**") {
- // If it's not a globstar then it is part of the keypath.
- return depth + 1;
- }
- if (depth == size()) {
- // The last key is a globstar.
+uint LOTKeyPath::nextDepth(const std::string key, uint depth)
+{
+ if (skip(key)) {
+ // If it's a container then we added programatically and it isn't a part
+ // of the keypath.
+ return depth;
+ }
+ if (mKeys[depth] != "**") {
+ // If it's not a globstar then it is part of the keypath.
+ return depth + 1;
+ }
+ if (depth == size()) {
+ // The last key is a globstar.
+ return depth;
+ }
+ if (mKeys[depth + 1] == key) {
+ // We are a globstar and the next key is our current key so consume
+ // both.
+ return depth + 2;
+ }
return depth;
- }
- if (mKeys[depth + 1] == key) {
- // We are a globstar and the next key is our current key so consume both.
- return depth + 2;
- }
- return depth;
}
-bool LOTKeyPath::fullyResolvesTo(const std::string key, uint depth) {
+bool LOTKeyPath::fullyResolvesTo(const std::string key, uint depth)
+{
if (depth > mKeys.size()) {
- return false;
+ return false;
}
bool isLastDepth = (depth == size());
if (!isGlobstar(depth)) {
- bool matches = (mKeys[depth] == key) || isGlob(depth);
- return (isLastDepth || (depth == size() - 1 && endsWithGlobstar())) && matches;
+ bool matches = (mKeys[depth] == key) || isGlob(depth);
+ return (isLastDepth || (depth == size() - 1 && endsWithGlobstar())) &&
+ matches;
}
bool isGlobstarButNextKeyMatches = !isLastDepth && mKeys[depth + 1] == key;
if (isGlobstarButNextKeyMatches) {
- return depth == size() - 1 ||
- (depth == size() - 2 && endsWithGlobstar());
+ return depth == size() - 1 ||
+ (depth == size() - 2 && endsWithGlobstar());
}
if (isLastDepth) {
- return true;
+ return true;
}
if (depth + 1 < size()) {
- // We are a globstar but there is more than 1 key after the globstar we we can't fully match.
- return false;
+ // We are a globstar but there is more than 1 key after the globstar we
+ // we can't fully match.
+ return false;
}
- // Return whether the next key (which we now know is the last one) is the same as the current
- // key.
+ // Return whether the next key (which we now know is the last one) is the
+ // same as the current key.
return mKeys[depth + 1] == key;
- }
+}
-/*
+/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "lottieloader.h"
#include "lottieparser.h"
+#include <cstring>
#include <fstream>
#include <unordered_map>
-#include <cstring>
using namespace std;
#ifdef LOTTIE_CACHE_SUPPORT
static LottieFileCache &instance()
{
static LottieFileCache CACHE;
- return CACHE;
- }
- std::shared_ptr<LOTModel> find(const std::string &)
- {
- return nullptr;
+ return CACHE;
}
+ std::shared_ptr<LOTModel> find(const std::string &) { return nullptr; }
void add(const std::string &, std::shared_ptr<LOTModel>) {}
};
#endif
-
-
static std::string dirname(const std::string &path)
{
const char *ptr = strrchr(path.c_str(), '/');
- int len = int(ptr + 1 - path.c_str()); // +1 to include '/'
+ int len = int(ptr + 1 - path.c_str()); // +1 to include '/'
return std::string(path, 0, len);
}
std::stringstream buf;
buf << f.rdbuf();
- LottieParser parser(const_cast<char *>(buf.str().data()), dirname(path).c_str());
+ LottieParser parser(const_cast<char *>(buf.str().data()),
+ dirname(path).c_str());
mModel = parser.model();
LottieFileCache::instance().add(path, mModel);
return true;
}
-bool LottieLoader::loadFromData(std::string &&jsonData, const std::string &key, const std::string &resourcePath)
+bool LottieLoader::loadFromData(std::string &&jsonData, const std::string &key,
+ const std::string &resourcePath)
{
mModel = LottieFileCache::instance().find(key);
if (mModel) return true;
- LottieParser parser(const_cast<char *>(jsonData.c_str()), resourcePath.c_str());
+ LottieParser parser(const_cast<char *>(jsonData.c_str()),
+ resourcePath.c_str());
mModel = parser.model();
LottieFileCache::instance().add(key, mModel);
-/*
+/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "lottiemodel.h"
-#include "vline.h"
-#include "vimageloader.h"
#include <cassert>
+#include <iterator>
#include <stack>
-#include <iterator>
+#include "vimageloader.h"
+#include "vline.h"
/*
* We process the iterator objects in the children list
* under a new shape group object which we add it as children to the repeater
* object.
* Then we visit the childrens of the newly created shape group object to
- * process the remaining repeater object(when children list contains more than one
- * repeater).
+ * process the remaining repeater object(when children list contains more than
+ * one repeater).
*
*/
class LottieRepeaterProcesser {
public:
- void visitChildren(LOTGroupData *obj) {
- for (auto i = obj->mChildren.rbegin(); i != obj->mChildren.rend(); ++i ) {
+ void visitChildren(LOTGroupData *obj)
+ {
+ for (auto i = obj->mChildren.rbegin(); i != obj->mChildren.rend();
+ ++i) {
auto child = (*i).get();
if (child->type() == LOTData::Type::Repeater) {
- LOTRepeaterData *repeater = static_cast<LOTRepeaterData *>(child);
+ LOTRepeaterData *repeater =
+ static_cast<LOTRepeaterData *>(child);
// check if this repeater is already processed
- // can happen if the layer is an asset and referenced by multiple layer.
+ // can happen if the layer is an asset and referenced by
+ // multiple layer.
if (repeater->content()) continue;
repeater->setContent(std::make_shared<LOTShapeGroupData>());
// object before the repeater
++i;
// 2. move all the children till repater to the group
- std::move(obj->mChildren.begin(),
- i.base(), back_inserter(content->mChildren));
+ std::move(obj->mChildren.begin(), i.base(),
+ back_inserter(content->mChildren));
// 3. erase the objects from the original children list
- obj->mChildren.erase(obj->mChildren.begin(),
- i.base());
+ obj->mChildren.erase(obj->mChildren.begin(), i.base());
- // 5. visit newly created group to process remaining repeater object.
+ // 5. visit newly created group to process remaining repeater
+ // object.
visitChildren(content);
// 6. exit the loop as the current iterators are invalid
break;
} else {
visit(child);
}
-
}
}
- void visit(LOTData *obj) {
+ void visit(LOTData *obj)
+ {
switch (obj->mType) {
case LOTData::Type::Repeater:
case LOTData::Type::ShapeGroup:
- case LOTData::Type::Layer:{
+ case LOTData::Type::Layer: {
visitChildren(static_cast<LOTGroupData *>(obj));
break;
}
}
};
-
void LOTCompositionData::processRepeaterObjects()
{
LottieRepeaterProcesser visitor;
scale.setY(std::pow(scale.y(), multiplier));
VMatrix m;
m.translate(mPosition.value(frameNo) * multiplier)
- .translate(mAnchor.value(frameNo))
- .scale(scale)
- .rotate(mRotation.value(frameNo) * multiplier)
- .translate(-mAnchor.value(frameNo));
+ .translate(mAnchor.value(frameNo))
+ .scale(scale)
+ .rotate(mRotation.value(frameNo) * multiplier)
+ .translate(-mAnchor.value(frameNo));
return m;
}
void LOTAsset::loadImageData(std::string data)
{
- if (!data.empty()) mBitmap = VImageLoader::instance().load(data.c_str(), data.length());
+ if (!data.empty())
+ mBitmap = VImageLoader::instance().load(data.c_str(), data.length());
}
void LOTAsset::loadImagePath(std::string path)
-/*
+/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "lottieparser.h"
-
//#define DEBUG_PARSER
//#define DEBUG_PRINT_TREE
class LottieParserImpl : protected LookaheadParserHandler {
public:
LottieParserImpl(char *str, const char *dir_path)
- :LookaheadParserHandler(str),
- mDirPath(dir_path){}
+ : LookaheadParserHandler(str), mDirPath(dir_path)
+ {
+ }
public:
bool EnterObject();
void resolveLayerRefs();
protected:
- std::unordered_map<std::string,
- std::shared_ptr<VInterpolator>> mInterpolatorCache;
+ std::unordered_map<std::string, std::shared_ptr<VInterpolator>>
+ mInterpolatorCache;
std::shared_ptr<LOTCompositionData> mComposition;
LOTCompositionData * compRef{nullptr};
LOTLayerData * curLayerRef{nullptr};
return -1;
}
-void LottieParserImpl::Skip(const char */*key*/)
+void LottieParserImpl::Skip(const char * /*key*/)
{
if (PeekType() == kArrayType) {
EnterArray();
void LottieParserImpl::resolveLayerRefs()
{
- for (const auto& i : mLayersToUpdate) {
+ for (const auto &i : mLayersToUpdate) {
LOTLayerData *layer = i.get();
auto search = compRef->mAssets.find(layer->mPreCompRefId);
if (search != compRef->mAssets.end()) {
layer->mAsset = search->second;
} else if (layer->mLayerType == LayerType::Precomp) {
layer->mChildren = search->second->mLayers;
- layer->setStatic(layer->isStatic() && search->second->isStatic());
+ layer->setStatic(layer->isStatic() &&
+ search->second->isStatic());
}
}
}
// update the precomp layers with the actual layer object
}
-static constexpr const unsigned char B64index[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 63, 62, 62, 63, 52, 53, 54, 55,
-56, 57, 58, 59, 60, 61, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6,
-7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0,
-0, 0, 0, 63, 0, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
-41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 };
+static constexpr const unsigned char B64index[256] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 62, 63, 62, 62, 63, 52, 53, 54, 55, 56, 57,
+ 58, 59, 60, 61, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6,
+ 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
+ 25, 0, 0, 0, 0, 63, 0, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
+ 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51};
-std::string b64decode(const void* data, const size_t len)
+std::string b64decode(const void *data, const size_t len)
{
- unsigned char* p = (unsigned char*)data;
- int pad = len > 0 && (len % 4 || p[len - 1] == '=');
- const size_t L = ((len + 3) / 4 - pad) * 4;
- std::string str(L / 4 * 3 + pad, '\0');
+ unsigned char *p = (unsigned char *)data;
+ int pad = len > 0 && (len % 4 || p[len - 1] == '=');
+ const size_t L = ((len + 3) / 4 - pad) * 4;
+ std::string str(L / 4 * 3 + pad, '\0');
- for (size_t i = 0, j = 0; i < L; i += 4)
- {
- int n = B64index[p[i]] << 18 | B64index[p[i + 1]] << 12 | B64index[p[i + 2]] << 6 | B64index[p[i + 3]];
+ for (size_t i = 0, j = 0; i < L; i += 4) {
+ int n = B64index[p[i]] << 18 | B64index[p[i + 1]] << 12 |
+ B64index[p[i + 2]] << 6 | B64index[p[i + 3]];
str[j++] = n >> 16;
str[j++] = n >> 8 & 0xFF;
str[j++] = n & 0xFF;
}
- if (pad)
- {
+ if (pad) {
int n = B64index[p[L]] << 18 | B64index[p[L + 1]] << 12;
str[str.size() - 1] = n >> 16;
- if (len > L + 2 && p[L + 2] != '=')
- {
+ if (len > L + 2 && p[L + 2] != '=') {
n |= B64index[p[L + 2]] << 6;
str.push_back(n >> 8 & 0xFF);
}
return str;
}
-static std::string
-convertFromBase64(const std::string &str)
+static std::string convertFromBase64(const std::string &str)
{
// usual header look like "data:image/png;base64,"
// so need to skip till ','.
int startIndex = str.find(",", 0);
- startIndex += 1; // skip ","
+ startIndex += 1; // skip ","
int length = str.length() - startIndex;
const char *b64Data = str.c_str() + startIndex;
RAPIDJSON_ASSERT(PeekType() == kObjectType);
std::shared_ptr<LOTAsset> sharedAsset = std::make_shared<LOTAsset>();
LOTAsset * asset = sharedAsset.get();
- std::string filename;
- std::string relativePath;
- bool embededResource = false;
+ std::string filename;
+ std::string relativePath;
+ bool embededResource = false;
EnterObject();
while (const char *key = NextObjectKey()) {
if (0 == strcmp(key, "w")) {
if (asset->mAssetType == LOTAsset::Type::Image) {
if (embededResource) {
// embeder resource should start with "data:"
- if (filename.compare(0, 5,"data:") == 0) {
+ if (filename.compare(0, 5, "data:") == 0) {
asset->loadImageData(convertFromBase64(filename));
}
} else {
LottieColor LottieParserImpl::toColor(const char *str)
{
LottieColor color;
- int len = strlen(str);
+ int len = strlen(str);
// some resource has empty color string
// return a default color for those cases.
- if (!len) return color;
+ if (!len) return color;
RAPIDJSON_ASSERT(len == 7);
RAPIDJSON_ASSERT(str[0] == '#');
} else if (0 == strcmp(key, "ddd")) { /*3d layer */
RAPIDJSON_ASSERT(PeekType() == kNumberType);
ddd = GetInt();
- } else if (0 == strcmp(key, "parent")) { /*Layer Parent. Uses "ind" of parent.*/
+ } else if (0 ==
+ strcmp(key,
+ "parent")) { /*Layer Parent. Uses "ind" of parent.*/
RAPIDJSON_ASSERT(PeekType() == kNumberType);
layer->mParentId = GetInt();
} else if (0 == strcmp(key, "refId")) { /*preComp Layer reference id*/
// update the static property of layer
bool staticFlag = true;
- for (const auto& child : layer->mChildren) {
+ for (const auto &child : layer->mChildren) {
staticFlag &= child.get()->isStatic();
}
- for (const auto& mask : layer->mMasks) {
+ for (const auto &mask : layer->mMasks) {
staticFlag &= mask->isStatic();
}
layer->setStatic(staticFlag && layer->mTransform->isStatic());
if (record) {
- mLayerInfoList.push_back(LayerInfo(layer->mName, layer->mInFrame, layer->mOutFrame));
+ mLayerInfoList.push_back(
+ LayerInfo(layer->mName, layer->mInFrame, layer->mOutFrame));
}
return sharedLayer;
}
} else if (0 == strcmp(type, "rp")) {
curLayerRef->mHasRepeater = true;
return parseReapeaterObject();
- } else if (0 == strcmp(type, "mm")) {
+ } else if (0 == strcmp(type, "mm")) {
vWarning << "Merge Path is not supported yet";
return nullptr;
} else {
}
}
bool staticFlag = true;
- for (const auto& child : group->mChildren) {
+ for (const auto &child : group->mChildren) {
staticFlag &= child.get()->isStatic();
}
}
}
-
std::shared_ptr<LOTData> LottieParserImpl::parseReapeaterObject()
{
std::shared_ptr<LOTRepeaterData> sharedRepeater =
obj->mName = GetString();
} else if (0 == strcmp(key, "c")) {
parseProperty(obj->mCopies);
- float maxCopy= 0.0;
+ float maxCopy = 0.0;
if (!obj->mCopies.isStatic()) {
- for(auto &keyFrame : obj->mCopies.animation().mKeyFrames) {
+ for (auto &keyFrame : obj->mCopies.animation().mKeyFrames) {
if (maxCopy < keyFrame.mValue.mStartValue)
maxCopy = keyFrame.mValue.mStartValue;
if (maxCopy < keyFrame.mValue.mEndValue)
/*
* https://github.com/airbnb/lottie-web/blob/master/docs/json/shapes/transform.json
*/
-std::shared_ptr<LOTTransformData> LottieParserImpl::parseTransformObject(bool ddd)
+std::shared_ptr<LOTTransformData> LottieParserImpl::parseTransformObject(
+ bool ddd)
{
std::shared_ptr<LOTTransformData> sharedTransform =
std::make_shared<LOTTransformData>();
parseProperty(obj->mX);
} else if (obj->mSeparate && (0 == strcmp(key, "y"))) {
parseProperty(obj->mY);
- }else {
+ } else {
Skip(key);
}
}
obj->mX.isStatic() && obj->mY.isStatic();
if (obj->m3D) {
obj->mStaticMatrix = obj->mStaticMatrix && obj->m3D->mRx.isStatic() &&
- obj->m3D->mRy.isStatic() && obj->m3D->mRz.isStatic();
+ obj->m3D->mRy.isStatic() &&
+ obj->m3D->mRz.isStatic();
}
obj->setStatic(obj->mStaticMatrix && obj->mOpacity.isStatic());
obj->mEnabled = GetBool();
} else if (0 == strcmp(key, "r")) {
obj->mFillRule = getFillRule();
- } else if (0 == strcmp(key, "hd")) {
+ } else if (0 == strcmp(key, "hd")) {
obj->mHidden = GetBool();
} else {
#ifdef DEBUG_PARSER
if (PeekType() == kArrayType) {
EnterArray();
if (NextArrayValue()) val = GetDouble();
- //discard rest
+ // discard rest
while (NextArrayValue()) {
GetDouble();
}
}
template <typename T>
-bool LottieParserImpl::parseKeyFrameValue(const char *,
- LOTKeyFrameValue<T> &){ return false;}
+bool LottieParserImpl::parseKeyFrameValue(const char *, LOTKeyFrameValue<T> &)
+{
+ return false;
+}
template <>
-bool LottieParserImpl::parseKeyFrameValue(const char * key,
+bool LottieParserImpl::parseKeyFrameValue(const char * key,
LOTKeyFrameValue<VPointF> &value)
{
- if (0 == strcmp(key, "ti")) {
+ if (0 == strcmp(key, "ti")) {
value.mPathKeyFrame = true;
getValue(value.mInTangent);
} else if (0 == strcmp(key, "to")) {
return true;
}
-std::shared_ptr<VInterpolator>
-LottieParserImpl::interpolator(VPointF inTangent, VPointF outTangent, std::string key)
+std::shared_ptr<VInterpolator> LottieParserImpl::interpolator(
+ VPointF inTangent, VPointF outTangent, std::string key)
{
if (key.empty()) {
std::array<char, 20> temp;
- snprintf(temp.data(), temp.size(), "%.2f_%.2f_%.2f_%.2f",
- inTangent.x(), inTangent.y(), outTangent.x(), outTangent.y());
+ snprintf(temp.data(), temp.size(), "%.2f_%.2f_%.2f_%.2f", inTangent.x(),
+ inTangent.y(), outTangent.x(), outTangent.y());
key = temp.data();
}
if (search != mInterpolatorCache.end()) {
return search->second;
} else {
- auto obj = std::make_shared<VInterpolator>(VInterpolator(outTangent, inTangent));
- mInterpolatorCache[std::move(key)] = obj;
+ auto obj = std::make_shared<VInterpolator>(
+ VInterpolator(outTangent, inTangent));
+ mInterpolatorCache[std::move(key)] = obj;
return obj;
}
}
{
struct ParsedField {
std::string interpolatorKey;
- bool interpolator{false};
- bool value{false};
- bool hold{false};
- bool noEndValue{true};
+ bool interpolator{false};
+ bool value{false};
+ bool hold{false};
+ bool noEndValue{true};
};
EnterObject();
parsed.value = true;
getValue(keyframe.mValue.mStartValue);
continue;
- } else if (0 == strcmp(key, "e")) {
+ } else if (0 == strcmp(key, "e")) {
parsed.noEndValue = false;
getValue(keyframe.mValue.mEndValue);
continue;
if (parsed.interpolatorKey.empty()) {
parsed.interpolatorKey = GetString();
} else {
- //skip rest of the string
+ // skip rest of the string
GetString();
}
}
// update the endFrame value of current keyframe
obj.mKeyFrames.back().mEndFrame = keyframe.mStartFrame;
// if no end value provided, copy start value to previous frame
- if (parsed.value &&
- parsed.noEndValue) {
- obj.mKeyFrames.back().mValue.mEndValue = keyframe.mValue.mStartValue;
+ if (parsed.value && parsed.noEndValue) {
+ obj.mKeyFrames.back().mValue.mEndValue =
+ keyframe.mValue.mStartValue;
}
}
keyframe.mEndFrame = keyframe.mStartFrame;
obj.mKeyFrames.push_back(keyframe);
} else if (parsed.interpolator) {
- keyframe.mInterpolator = interpolator(inTangent, outTangent, std::move(parsed.interpolatorKey));
+ keyframe.mInterpolator = interpolator(
+ inTangent, outTangent, std::move(parsed.interpolatorKey));
obj.mKeyFrames.push_back(keyframe);
} else {
- //its the last frame discard.
+ // its the last frame discard.
}
}
public:
void visit(LOTCompositionData *obj, std::string level)
{
- vDebug << " { "
- << level
- << "Composition:: a: " << !obj->isStatic()
- << ", v: " << obj->mVersion
- << ", stFm: " << obj->startFrame()
+ vDebug << " { " << level << "Composition:: a: " << !obj->isStatic()
+ << ", v: " << obj->mVersion << ", stFm: " << obj->startFrame()
<< ", endFm: " << obj->endFrame()
<< ", W: " << obj->size().width()
- << ", H: " << obj->size().height()
- << "\n";
+ << ", H: " << obj->size().height() << "\n";
level.append("\t");
visit(obj->mRootLayer.get(), level);
level.erase(level.end() - 1, level.end());
}
void visit(LOTLayerData *obj, std::string level)
{
- vDebug << level
- << "{ "
- << layerType(obj->mLayerType)
- << ", name: "<< obj->name()
- << ", id:" << obj->mId << " Pid:" << obj->mParentId
- << ", a:" << !obj->isStatic()
- << ", "<<matteType(obj->mMatteType)
- << ", mask:"<<obj->hasMask()
- << ", inFm:" << obj->mInFrame
- << ", outFm:" << obj->mOutFrame
- << ", stFm:" << obj->mStartFrame
- << ", ts:" << obj->mTimeStreatch
- << ", ao:" << obj->autoOrient()
+ vDebug << level << "{ " << layerType(obj->mLayerType)
+ << ", name: " << obj->name() << ", id:" << obj->mId
+ << " Pid:" << obj->mParentId << ", a:" << !obj->isStatic()
+ << ", " << matteType(obj->mMatteType)
+ << ", mask:" << obj->hasMask() << ", inFm:" << obj->mInFrame
+ << ", outFm:" << obj->mOutFrame << ", stFm:" << obj->mStartFrame
+ << ", ts:" << obj->mTimeStreatch << ", ao:" << obj->autoOrient()
<< ", ddd:" << (obj->mTransform ? obj->mTransform->ddd() : false)
<< ", W:" << obj->layerSize().width()
<< ", H:" << obj->layerSize().height();
if (obj->mLayerType == LayerType::Image)
- vDebug << level
- << "\t{ "
+ vDebug << level << "\t{ "
<< "ImageInfo:"
<< " W :" << obj->mAsset->mWidth
- << ", H :" << obj->mAsset->mHeight
- <<" }"
+ << ", H :" << obj->mAsset->mHeight << " }"
<< "\n";
else {
- vDebug<< level;
+ vDebug << level;
}
visitChildren(static_cast<LOTGroupData *>(obj), level);
- vDebug << level
- << "} "
- << layerType(obj->mLayerType).c_str()
+ vDebug << level << "} " << layerType(obj->mLayerType).c_str()
<< ", id: " << obj->mId << "\n";
}
void visitChildren(LOTGroupData *obj, std::string level)
{
level.append("\t");
- for (const auto& child : obj->mChildren) visit(child.get(), level);
- if (obj->mTransform)
- visit(obj->mTransform.get(), level);
+ for (const auto &child : obj->mChildren) visit(child.get(), level);
+ if (obj->mTransform) visit(obj->mTransform.get(), level);
}
- void visit(LOTData *obj, std::string level) {
+ void visit(LOTData *obj, std::string level)
+ {
switch (obj->mType) {
case LOTData::Type::Repeater: {
auto r = static_cast<LOTRepeaterData *>(obj);
- vDebug << level << "{ Repeater: name: "<<obj->name()<<" , a:" << !obj->isStatic()
+ vDebug << level << "{ Repeater: name: " << obj->name()
+ << " , a:" << !obj->isStatic()
<< ", copies:" << r->maxCopies()
<< ", offset:" << r->offset(0);
visitChildren(r->mContent.get(), level);
break;
}
case LOTData::Type::ShapeGroup: {
- vDebug << level << "{ ShapeGroup: name: "<<obj->name()<<" , a:" << !obj->isStatic();
+ vDebug << level << "{ ShapeGroup: name: " << obj->name()
+ << " , a:" << !obj->isStatic();
visitChildren(static_cast<LOTGroupData *>(obj), level);
vDebug << level << "} ShapeGroup";
break;
}
- case LOTData::Type::Layer:{
+ case LOTData::Type::Layer: {
visit(static_cast<LOTLayerData *>(obj), level);
break;
}
- case LOTData::Type::Trim:{
- vDebug << level << "{ Trim: name: "<<obj->name()<<" , a:" << !obj->isStatic() << " }";
+ case LOTData::Type::Trim: {
+ vDebug << level << "{ Trim: name: " << obj->name()
+ << " , a:" << !obj->isStatic() << " }";
break;
}
- case LOTData::Type::Rect:{
- vDebug << level << "{ Rect: name: "<<obj->name()<<" , a:" << !obj->isStatic() << " }";
+ case LOTData::Type::Rect: {
+ vDebug << level << "{ Rect: name: " << obj->name()
+ << " , a:" << !obj->isStatic() << " }";
break;
}
- case LOTData::Type::Ellipse:{
- vDebug << level << "{ Ellipse: name: "<<obj->name()<<" , a:" << !obj->isStatic() << " }";
+ case LOTData::Type::Ellipse: {
+ vDebug << level << "{ Ellipse: name: " << obj->name()
+ << " , a:" << !obj->isStatic() << " }";
break;
}
- case LOTData::Type::Shape:{
- vDebug << level << "{ Shape: name: "<<obj->name()<<" , a:" << !obj->isStatic() << " }";
+ case LOTData::Type::Shape: {
+ vDebug << level << "{ Shape: name: " << obj->name()
+ << " , a:" << !obj->isStatic() << " }";
break;
}
- case LOTData::Type::Polystar:{
- vDebug << level << "{ Polystar: name: "<<obj->name()<<" , a:" << !obj->isStatic() << " }";
+ case LOTData::Type::Polystar: {
+ vDebug << level << "{ Polystar: name: " << obj->name()
+ << " , a:" << !obj->isStatic() << " }";
break;
}
- case LOTData::Type::Transform:{
- vDebug << level << "{ Transform: name: "<<obj->name()<<" , a: " << !obj->isStatic() << " }";
+ case LOTData::Type::Transform: {
+ vDebug << level << "{ Transform: name: " << obj->name()
+ << " , a: " << !obj->isStatic() << " }";
break;
}
- case LOTData::Type::Stroke:{
- vDebug << level << "{ Stroke: name: "<<obj->name()<<" , a:" << !obj->isStatic() << " }";
+ case LOTData::Type::Stroke: {
+ vDebug << level << "{ Stroke: name: " << obj->name()
+ << " , a:" << !obj->isStatic() << " }";
break;
}
- case LOTData::Type::GStroke:{
- vDebug << level << "{ GStroke: name: "<<obj->name()<<" , a:" << !obj->isStatic() << " }";
+ case LOTData::Type::GStroke: {
+ vDebug << level << "{ GStroke: name: " << obj->name()
+ << " , a:" << !obj->isStatic() << " }";
break;
}
- case LOTData::Type::Fill:{
- vDebug << level << "{ Fill: name: "<<obj->name()<<" , a:" << !obj->isStatic() << " }";
+ case LOTData::Type::Fill: {
+ vDebug << level << "{ Fill: name: " << obj->name()
+ << " , a:" << !obj->isStatic() << " }";
break;
}
- case LOTData::Type::GFill:{
+ case LOTData::Type::GFill: {
auto f = static_cast<LOTGFillData *>(obj);
- vDebug << level << "{ GFill: name: "<<obj->name()<<" , a:" << !f->isStatic()
- << ", ty:" << f->mGradientType << ", s:" << f->mStartPoint.value(0)
+ vDebug << level << "{ GFill: name: " << obj->name()
+ << " , a:" << !f->isStatic() << ", ty:" << f->mGradientType
+ << ", s:" << f->mStartPoint.value(0)
<< ", e:" << f->mEndPoint.value(0) << " }";
break;
}
delete d;
}
-LottieParser::LottieParser(char *str, const char *dir_path) : d(new LottieParserImpl(str, dir_path))
+LottieParser::LottieParser(char *str, const char *dir_path)
+ : d(new LottieParserImpl(str, dir_path))
{
d->parseComposition();
}
* exported function wrapper from the library
*/
-LOT_EXPORT unsigned char *
-lottie_image_load(char const *filename, int *x, int *y, int *comp, int req_comp)
+LOT_EXPORT unsigned char *lottie_image_load(char const *filename, int *x,
+ int *y, int *comp, int req_comp)
{
return stbi_load(filename, x, y, comp, req_comp);
}
-LOT_EXPORT unsigned char *
-lottie_image_load_from_data(const char *imageData, int len, int *x, int *y, int *comp, int req_comp)
+LOT_EXPORT unsigned char *lottie_image_load_from_data(const char *imageData,
+ int len, int *x, int *y,
+ int *comp, int req_comp)
{
unsigned char *data = (unsigned char *)imageData;
return stbi_load_from_memory(data, len, x, y, comp, req_comp);
}
-LOT_EXPORT void
-lottie_image_free(unsigned char *data)
+LOT_EXPORT void lottie_image_free(unsigned char *data)
{
stbi_image_free(data);
}
-/*
+/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "vbezier.h"
-#include "vline.h"
#include <cmath>
+#include "vline.h"
V_BEGIN_NAMESPACE
VPointF VBezier::derivative(float t) const
{
- // p'(t) = 3 * (-(1-2t+t^2) * p0 + (1 - 4 * t + 3 * t^2) * p1 + (2 * t - 3 * t^2) * p2 + t^2 * p3)
+ // p'(t) = 3 * (-(1-2t+t^2) * p0 + (1 - 4 * t + 3 * t^2) * p1 + (2 * t - 3 *
+ // t^2) * p2 + t^2 * p3)
float m_t = 1. - t;
a * y1 + b * y2 + c * y3 + d * y4);
}
-
float VBezier::angleAt(float t) const
{
if (t < 0 || t > 1) {
return VLine({}, derivative(t)).angle();
}
-
V_END_NAMESPACE
-/*
+/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "vbitmap.h"
#include <string.h>
-#include "vglobal.h"
#include "vdrawhelper.h"
+#include "vglobal.h"
V_BEGIN_NAMESPACE
struct VBitmap::Impl {
- uchar * mData{nullptr};
- uint mWidth{0};
- uint mHeight{0};
- uint mStride{0};
- uint mBytes{0};
- uint mDepth{0};
- VBitmap::Format mFormat{VBitmap::Format::Invalid};
- bool mOwnData;
- bool mRoData;
-
- Impl() = delete ;
-
- Impl(uint width, uint height, VBitmap::Format format):
- mOwnData(true),
- mRoData(false)
+ uchar * mData{nullptr};
+ uint mWidth{0};
+ uint mHeight{0};
+ uint mStride{0};
+ uint mBytes{0};
+ uint mDepth{0};
+ VBitmap::Format mFormat{VBitmap::Format::Invalid};
+ bool mOwnData;
+ bool mRoData;
+
+ Impl() = delete;
+
+ Impl(uint width, uint height, VBitmap::Format format)
+ : mOwnData(true), mRoData(false)
{
reset(width, height, format);
}
void reset(uint width, uint height, VBitmap::Format format)
{
- if (mOwnData && mData) delete(mData);
+ if (mOwnData && mData) delete (mData);
mDepth = depth(format);
- uint stride = ((width * mDepth + 31) >> 5) << 2; // bytes per scanline (must be multiple of 4)
+ uint stride = ((width * mDepth + 31) >> 5)
+ << 2; // bytes per scanline (must be multiple of 4)
mWidth = width;
mHeight = height;
mData = reinterpret_cast<uchar *>(::operator new(mBytes));
}
- Impl(uchar *data, uint w, uint h, uint bytesPerLine, VBitmap::Format format):
- mOwnData(false),
- mRoData(false)
+ Impl(uchar *data, uint w, uint h, uint bytesPerLine, VBitmap::Format format)
+ : mOwnData(false), mRoData(false)
{
mWidth = w;
mHeight = h;
if (mOwnData && mData) ::operator delete(mData);
}
- uint stride() const {return mStride;}
- uint width() const {return mWidth;}
- uint height() const {return mHeight;}
- VBitmap::Format format() const {return mFormat;}
- uchar* data() { return mData;}
+ uint stride() const { return mStride; }
+ uint width() const { return mWidth; }
+ uint height() const { return mHeight; }
+ VBitmap::Format format() const { return mFormat; }
+ uchar * data() { return mData; }
static uint depth(VBitmap::Format format)
{
//@TODO
}
- void updateLuma() {
+ void updateLuma()
+ {
if (mFormat != VBitmap::Format::ARGB32_Premultiplied) return;
- for (uint col = 0 ; col < mHeight ; col++) {
- uint *pixel = (uint *) (mData + mStride * col);
- for (uint row = 0 ; row < mWidth; row++) {
+ for (uint col = 0; col < mHeight; col++) {
+ uint *pixel = (uint *)(mData + mStride * col);
+ for (uint row = 0; row < mWidth; row++) {
int alpha = vAlpha(*pixel);
if (alpha == 0) {
pixel++;
int blue = vBlue(*pixel);
if (alpha != 255) {
- //un multiply
+ // un multiply
red = (red * 255) / alpha;
green = (green * 255) / alpha;
blue = (blue * 255) / alpha;
}
- int luminosity = (0.299*red + 0.587*green + 0.114*blue);
+ int luminosity = (0.299 * red + 0.587 * green + 0.114 * blue);
*pixel = luminosity << 24;
pixel++;
}
VBitmap::VBitmap(uint width, uint height, VBitmap::Format format)
{
- if (width <=0 || height <=0 || format == Format::Invalid) return;
+ 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::Format format)
{
- if (!data ||
- width <=0 || height <=0 ||
- bytesPerLine <=0 ||
- format == Format::Invalid) return;
+ if (!data || width <= 0 || height <= 0 || bytesPerLine <= 0 ||
+ format == Format::Invalid)
+ return;
mImpl = std::make_shared<Impl>(data, width, height, bytesPerLine, format);
}
void VBitmap::reset(uint w, uint h, VBitmap::Format format)
{
if (mImpl) {
- if (w == mImpl->width() &&
- h == mImpl->height() &&
+ if (w == mImpl->width() && h == mImpl->height() &&
format == mImpl->format()) {
return;
}
-/*
+/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "vbrush.h"
-/*
+/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "vdrawhelper.h"
dest = d * sa * ca + d * cia
= d * (sa * ca + cia)
*/
-static void comp_func_solid_DestinationIn(uint *dest, int length, uint color, uint const_alpha)
+static void comp_func_solid_DestinationIn(uint *dest, int length, uint color,
+ uint const_alpha)
{
uint a = vAlpha(color);
if (const_alpha != 255) {
dest = d * sia * ca + d * cia
= d * (sia * ca + cia)
*/
-static void comp_func_solid_DestinationOut(uint *dest, int length, uint color, uint const_alpha)
+static void comp_func_solid_DestinationOut(uint *dest, int length, uint color,
+ uint const_alpha)
{
uint a = vAlpha(~color);
- if (const_alpha != 255)
- a = BYTE_MUL(a, const_alpha) + 255 - const_alpha;
+ if (const_alpha != 255) a = BYTE_MUL(a, const_alpha) + 255 - const_alpha;
for (int i = 0; i < length; ++i) {
dest[i] = BYTE_MUL(dest[i], a);
}
}
}
-void comp_func_DestinationIn(uint *dest, const uint *src, int length, uint const_alpha)
+void comp_func_DestinationIn(uint *dest, const uint *src, int length,
+ uint const_alpha)
{
if (const_alpha == 255) {
for (int i = 0; i < length; ++i) {
}
}
-void comp_func_DestinationOut(uint *dest, const uint *src, int length, uint const_alpha)
+void comp_func_DestinationOut(uint *dest, const uint *src, int length,
+ uint const_alpha)
{
if (const_alpha == 255) {
for (int i = 0; i < length; ++i) {
}
CompositionFunctionSolid COMP_functionForModeSolid_C[] = {
- comp_func_solid_Source,
- comp_func_solid_SourceOver,
- comp_func_solid_DestinationIn,
- comp_func_solid_DestinationOut
- };
+ comp_func_solid_Source, comp_func_solid_SourceOver,
+ comp_func_solid_DestinationIn, comp_func_solid_DestinationOut};
-CompositionFunction COMP_functionForMode_C[] = {comp_func_Source,
- comp_func_SourceOver,
- comp_func_DestinationIn,
- comp_func_DestinationOut
- };
+CompositionFunction COMP_functionForMode_C[] = {
+ comp_func_Source, comp_func_SourceOver, comp_func_DestinationIn,
+ comp_func_DestinationOut};
void vInitBlendFunctions() {}
-/*
+/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "vbezier.h"
{
mDashArray = reinterpret_cast<const VDasher::Dash *>(dashArray);
mArraySize = size / 2;
- if (size % 2)
- mDashOffset = dashArray[size - 1];
+ if (size % 2) mDashOffset = dashArray[size - 1];
mIndex = 0;
mCurrentLength = 0;
mDiscard = false;
void VDasher::addLine(const VPointF &p)
{
- if (mDiscard) return;
+ if (mDiscard) return;
- if (mStartNewSegment) {
+ if (mStartNewSegment) {
mResult.moveTo(mCurPt);
mStartNewSegment = false;
- }
- mResult.lineTo(p);
+ }
+ mResult.lineTo(p);
}
void VDasher::updateActiveSegment()
{
VBezier left, right;
VBezier b = VBezier::fromPoints(mCurPt, cp1, cp2, e);
- float bezLen = b.length();
+ float bezLen = b.length();
if (bezLen <= mCurrentLength) {
mCurrentLength -= bezLen;
-/*
+/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "vdebug.h"
char buffer[32];
strftime(buffer, 32, "%Y-%m-%d %T.", gmtime);
char microseconds[7];
- snprintf(microseconds, 7, "%06llu", (long long unsigned int)timestamp % 1000000);
+ snprintf(microseconds, 7, "%06llu",
+ (long long unsigned int)timestamp % 1000000);
os << '[' << buffer << microseconds << ']';
}
size_t const m_size;
Item* m_ring;
std::atomic<unsigned int> m_write_index;
+
public:
- char pad[64];
+ char pad[64];
+
private:
- unsigned int m_read_index;
+ unsigned int m_read_index;
};
class Buffer {
uint32_t log_file_roll_size_mb)
{
nanologger = std::make_unique<NanoLogger>(ngl, log_directory, log_file_name,
- log_file_roll_size_mb);
+ log_file_roll_size_mb);
atomic_nanologger.store(nanologger.get(), std::memory_order_seq_cst);
}
uint32_t log_file_roll_size_mb)
{
nanologger = std::make_unique<NanoLogger>(gl, log_directory, log_file_name,
- log_file_roll_size_mb);
+ log_file_roll_size_mb);
atomic_nanologger.store(nanologger.get(), std::memory_order_seq_cst);
}
loglevel.load(std::memory_order_relaxed);
}
-#endif //LOTTIE_LOGGING_SUPPORT
+#endif // LOTTIE_LOGGING_SUPPORT
-/*
+/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "vdrawable.h"
-/*
+/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/****************************************************************************
****************************************************************************/
#include "vdrawhelper.h"
+#include <algorithm>
#include <climits>
#include <cstring>
#include <mutex>
#include <unordered_map>
-#include <algorithm>
class VGradientCache {
public:
};
using VCacheData = std::shared_ptr<const CacheInfo>;
using VCacheKey = int64_t;
- using VGradientColorTableHash = std::unordered_multimap<VCacheKey, VCacheData>;
+ using VGradientColorTableHash =
+ std::unordered_multimap<VCacheKey, VCacheData>;
bool generateGradientColorTable(const VGradientStops &stops, float alpha,
uint32_t *colorTable, int size);
VCacheData getBuffer(const VGradient &gradient)
{
- VCacheKey hash_val = 0;
- VCacheData info;
+ VCacheKey hash_val = 0;
+ 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());
}
protected:
- uint maxCacheSize() const { return 60; }
+ uint maxCacheSize() const { return 60; }
VCacheData addCacheElement(VCacheKey hash_val, const VGradient &gradient)
{
if (mCache.size() == maxCacheSize()) {
- uint count = maxCacheSize()/10;
+ uint count = maxCacheSize() / 10;
while (count--) {
mCache.erase(mCache.begin());
}
}
auto cache_entry = std::make_shared<CacheInfo>(gradient.mStops);
- cache_entry->alpha = generateGradientColorTable(gradient.mStops,
- gradient.alpha(),
- cache_entry->buffer32,
- VGradient::colorTableSize);
+ cache_entry->alpha = generateGradientColorTable(
+ gradient.mStops, gradient.alpha(), cache_entry->buffer32,
+ VGradient::colorTableSize);
mCache.insert(std::make_pair(hash_val, cache_entry));
return cache_entry;
}
std::mutex mMutex;
};
-bool VGradientCache::generateGradientColorTable(const VGradientStops &stops, float opacity,
+bool VGradientCache::generateGradientColorTable(const VGradientStops &stops,
+ float opacity,
uint32_t *colorTable, int size)
{
int dist, idist, pos = 0, i;
}
}
-static inline Operator getOperator(const VSpanData * data,
- const VRle::Span *, size_t)
+static inline Operator getOperator(const VSpanData *data, const VRle::Span *,
+ size_t)
{
Operator op;
bool solidSource = false;
return op;
}
-static void blendColorARGB(size_t count, const VRle::Span *spans, void *userData)
+static void blendColorARGB(size_t count, const VRle::Span *spans,
+ void *userData)
{
VSpanData *data = (VSpanData *)(userData);
Operator op = getOperator(data, spans, count);
}
}
-template<class T>
-constexpr const T& clamp( const T& v, const T& lo, const T& hi)
+template <class T>
+constexpr const T &clamp(const T &v, const T &lo, const T &hi)
{
return v < lo ? lo : hi < v ? hi : v;
}
static const int buffer_size = 1024;
static const int fixed_scale = 1 << 16;
-static void blend_transformed_argb(size_t count, const VRle::Span *spans, void *userData)
+static void blend_transformed_argb(size_t count, const VRle::Span *spans,
+ void *userData)
{
VSpanData *data = reinterpret_cast<VSpanData *>(userData);
- if (data->mBitmap.format != VBitmap::Format::ARGB32_Premultiplied
- && data->mBitmap.format != VBitmap::Format::ARGB32) {
+ if (data->mBitmap.format != VBitmap::Format::ARGB32_Premultiplied &&
+ data->mBitmap.format != VBitmap::Format::ARGB32) {
//@TODO other formats not yet handled.
return;
}
Operator op = getOperator(data, spans, count);
- uint buffer[buffer_size];
+ uint buffer[buffer_size];
const int image_x1 = data->mBitmap.x1;
const int image_y1 = data->mBitmap.y1;
const float cx = spans->x + float(0.5);
const float cy = spans->y + float(0.5);
- int x = int((data->m21 * cy
- + data->m11 * cx + data->dx) * fixed_scale);
- int y = int((data->m22 * cy
- + data->m12 * cx + data->dy) * fixed_scale);
+ int x =
+ int((data->m21 * cy + data->m11 * cx + data->dx) * fixed_scale);
+ int y =
+ int((data->m22 * cy + data->m12 * cx + data->dy) * fixed_scale);
- int length = spans->len;
- const int coverage = (spans->coverage * data->mBitmap.const_alpha) >> 8;
+ int length = spans->len;
+ const int coverage =
+ (spans->coverage * data->mBitmap.const_alpha) >> 8;
while (length) {
- int l = std::min(length, buffer_size);
+ int l = std::min(length, buffer_size);
const uint *end = buffer + l;
- uint *b = buffer;
+ uint * b = buffer;
while (b < end) {
int px = clamp(x >> 16, image_x1, image_x2);
int py = clamp(y >> 16, image_y1, image_y2);
- *b = reinterpret_cast<const uint *>(data->mBitmap.scanLine(py))[px];
+ *b = reinterpret_cast<const uint *>(
+ data->mBitmap.scanLine(py))[px];
x += fdx;
y += fdy;
float y = data->m22 * cy + data->m12 * cx + data->dy;
float w = data->m23 * cy + data->m13 * cx + data->m33;
- int length = spans->len;
- const int coverage = (spans->coverage * data->mBitmap.const_alpha) >> 8;
+ int length = spans->len;
+ const int coverage =
+ (spans->coverage * data->mBitmap.const_alpha) >> 8;
while (length) {
- int l = std::min(length, buffer_size);
+ int l = std::min(length, buffer_size);
const uint *end = buffer + l;
- uint *b = buffer;
+ uint * b = buffer;
while (b < end) {
const float iw = w == 0 ? 1 : 1 / w;
const float tx = x * iw;
const float ty = y * iw;
- const int px = clamp(int(tx) - (tx < 0), image_x1, image_x2);
- const int py = clamp(int(ty) - (ty < 0), image_y1, image_y2);
+ const int px =
+ clamp(int(tx) - (tx < 0), image_x1, image_x2);
+ const int py =
+ clamp(int(ty) - (ty < 0), image_y1, image_y2);
- *b = reinterpret_cast<const uint *>(data->mBitmap.scanLine(py))[px];
+ *b = reinterpret_cast<const uint *>(
+ data->mBitmap.scanLine(py))[px];
x += fdx;
y += fdy;
w += fdw;
}
}
-static void blend_untransformed_argb(size_t count, const VRle::Span *spans, void *userData)
+static void blend_untransformed_argb(size_t count, const VRle::Span *spans,
+ void *userData)
{
VSpanData *data = reinterpret_cast<VSpanData *>(userData);
- if (data->mBitmap.format != VBitmap::Format::ARGB32_Premultiplied
- && data->mBitmap.format != VBitmap::Format::ARGB32) {
+ if (data->mBitmap.format != VBitmap::Format::ARGB32_Premultiplied &&
+ data->mBitmap.format != VBitmap::Format::ARGB32) {
//@TODO other formats not yet handled.
return;
}
length += sx;
sx = 0;
}
- if (sx + length > image_width)
- length = image_width - sx;
+ if (sx + length > image_width) length = image_width - sx;
if (length > 0) {
- const int coverage = (spans->coverage * data->mBitmap.const_alpha) >> 8;
+ const int coverage =
+ (spans->coverage * data->mBitmap.const_alpha) >> 8;
const uint *src = (const uint *)data->mBitmap.scanLine(sy) + sx;
- uint *dest = data->buffer(x, spans->y);
+ uint * dest = data->buffer(x, spans->y);
op.func(dest, src, length, coverage);
}
}
}
case VBrush::Type::Texture: {
mType = VSpanData::Type::Texture;
- initTexture(&brush.mTexture, 255, VBitmapData::Plain,
- VRect(0, 0, brush.mTexture.width(), brush.mTexture.height()));
+ initTexture(
+ &brush.mTexture, 255, VBitmapData::Plain,
+ VRect(0, 0, brush.mTexture.width(), brush.mTexture.height()));
setupMatrix(brush.mMatrix);
break;
}
dy = inv.mty;
transformType = inv.type();
- const bool affine = inv.isAffine();
+ const bool affine = inv.isAffine();
const float f1 = m11 * m11 + m21 * m21;
const float f2 = m12 * m12 + m22 * m22;
- fast_matrix = affine
- && f1 < 1e4
- && f2 < 1e4
- && f1 > (1.0 / 65536)
- && f2 > (1.0 / 65536)
- && fabs(dx) < 1e4
- && fabs(dy) < 1e4;
+ fast_matrix = affine && f1 < 1e4 && f2 < 1e4 && f1 > (1.0 / 65536) &&
+ f2 > (1.0 / 65536) && fabs(dx) < 1e4 && fabs(dy) < 1e4;
}
-void VSpanData::initTexture(const VBitmap *bitmap, int alpha, VBitmapData::Type type, const VRect &sourceRect)
+void VSpanData::initTexture(const VBitmap *bitmap, int alpha,
+ VBitmapData::Type type, const VRect &sourceRect)
{
mType = VSpanData::Type::Texture;
}
case VSpanData::Type::Texture: {
//@TODO update proper image function.
- if (transformType <= VMatrix::MatrixType::Translate){
+ if (transformType <= VMatrix::MatrixType::Translate) {
mUnclippedBlendFunc = &blend_untransformed_argb;
} else {
mUnclippedBlendFunc = &blend_transformed_argb;
#include "vdrawhelper.h"
-extern "C" void
-pixman_composite_src_n_8888_asm_neon (int32_t w,
- int32_t h,
- uint32_t *dst,
- int32_t dst_stride,
- uint32_t src);
+extern "C" void pixman_composite_src_n_8888_asm_neon(int32_t w, int32_t h,
+ uint32_t *dst,
+ int32_t dst_stride,
+ uint32_t src);
-extern "C" void
-pixman_composite_over_n_8888_asm_neon(int32_t w,
- int32_t h,
- uint32_t *dst,
- int32_t dst_stride,
- uint32_t src);
+extern "C" void pixman_composite_over_n_8888_asm_neon(int32_t w, int32_t h,
+ uint32_t *dst,
+ int32_t dst_stride,
+ uint32_t src);
void memfill32(uint32_t *dest, uint32_t value, int length)
{
- pixman_composite_src_n_8888_asm_neon(length,
- 1,
- dest,
- length,
- value);
+ pixman_composite_src_n_8888_asm_neon(length, 1, dest, length, value);
}
-void
-comp_func_solid_SourceOver_neon(uint32_t *dest, int length, uint32_t color,
- uint32_t const_alpha)
+void comp_func_solid_SourceOver_neon(uint32_t *dest, int length, uint32_t color,
+ uint32_t const_alpha)
{
if (const_alpha != 255) color = BYTE_MUL(color, const_alpha);
- pixman_composite_over_n_8888_asm_neon(length,
- 1,
- dest,
- length,
- color);
+ pixman_composite_over_n_8888_asm_neon(length, 1, dest, length, color);
}
#endif
-/*
+/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "velapsedtimer.h"
#include "vimageloader.h"
-#include "vdebug.h"
#include "config.h"
+#include "vdebug.h"
#ifndef WIN32
#include <dlfcn.h>
#else
#endif
#include <cstring>
-using lottie_image_load_f = unsigned char* (*)(const char *filename, int *x, int *y, int *comp, int req_comp);
-using lottie_image_load_data_f = unsigned char* (*)(const char *data, int len, int *x, int *y, int *comp, int req_comp);
+using lottie_image_load_f = unsigned char *(*)(const char *filename, int *x,
+ int *y, int *comp, int req_comp);
+using lottie_image_load_data_f = unsigned char *(*)(const char *data, int len,
+ int *x, int *y, int *comp,
+ int req_comp);
using lottie_image_free_f = void (*)(unsigned char *);
#ifdef __cplusplus
extern "C" {
#endif
-extern unsigned char * lottie_image_load(char const *filename, int *x, int *y, int *comp, int req_comp);
-extern unsigned char * lottie_image_load_from_data(const char *imageData, int len, int *x, int *y, int *comp, int req_comp);
-extern void lottie_image_free(unsigned char *data);
+extern unsigned char *lottie_image_load(char const *filename, int *x, int *y,
+ int *comp, int req_comp);
+extern unsigned char *lottie_image_load_from_data(const char *imageData,
+ int len, int *x, int *y,
+ int *comp, int req_comp);
+extern void lottie_image_free(unsigned char *data);
#ifdef __cplusplus
}
#endif
-
-struct VImageLoader::Impl
-{
+struct VImageLoader::Impl {
lottie_image_load_f imageLoad{nullptr};
lottie_image_free_f imageFree{nullptr};
lottie_image_load_data_f imageFromData{nullptr};
#ifndef LOTTIE_STATIC_IMAGE_LOADER
#ifdef WIN32
- HMODULE dl_handle{ nullptr };
- bool moduleLoad() {
+ HMODULE dl_handle{nullptr};
+ bool moduleLoad()
+ {
dl_handle = LoadLibraryA("librlottie-image-loader.dll");
return (dl_handle == nullptr);
}
- void moduleFree() {
+ void moduleFree()
+ {
if (dl_handle) FreeLibrary(dl_handle);
}
- void init() {
- imageLoad = (lottie_image_load_f)GetProcAddress(dl_handle, "lottie_image_load");
- imageFree = (lottie_image_free_f)GetProcAddress(dl_handle, "lottie_image_free");
- imageFromData = (lottie_image_load_data_f)GetProcAddress(dl_handle, "lottie_image_load_from_data");
+ void init()
+ {
+ imageLoad =
+ (lottie_image_load_f)GetProcAddress(dl_handle, "lottie_image_load");
+ imageFree =
+ (lottie_image_free_f)GetProcAddress(dl_handle, "lottie_image_free");
+ imageFromData = (lottie_image_load_data_f)GetProcAddress(
+ dl_handle, "lottie_image_load_from_data");
}
#else
- void *dl_handle{nullptr};
- void init() {
- imageLoad = (lottie_image_load_f) dlsym(dl_handle, "lottie_image_load");
- imageFree = (lottie_image_free_f) dlsym(dl_handle, "lottie_image_free");
- imageFromData = (lottie_image_load_data_f) dlsym(dl_handle, "lottie_image_load_from_data");
+ void *dl_handle{nullptr};
+ void init()
+ {
+ imageLoad = (lottie_image_load_f)dlsym(dl_handle, "lottie_image_load");
+ imageFree = (lottie_image_free_f)dlsym(dl_handle, "lottie_image_free");
+ imageFromData = (lottie_image_load_data_f)dlsym(
+ dl_handle, "lottie_image_load_from_data");
}
- void moduleFree() {
+ void moduleFree()
+ {
if (dl_handle) dlclose(dl_handle);
}
#ifdef __APPLE__
- bool moduleLoad() {
+ bool moduleLoad()
+ {
dl_handle = dlopen("librlottie-image-loader.dylib", RTLD_LAZY);
return (dl_handle == nullptr);
}
#else
- bool moduleLoad() {
+ bool moduleLoad()
+ {
dl_handle = dlopen("librlottie-image-loader.so", RTLD_LAZY);
return (dl_handle == nullptr);
}
-#endif
+#endif
#endif
#else
void *dl_handle{nullptr};
- void init() {
+ void init()
+ {
imageLoad = lottie_image_load;
imageFree = lottie_image_free;
imageFromData = lottie_image_load_from_data;
}
void moduleFree() {}
- bool moduleLoad() {return false;}
+ bool moduleLoad() { return false; }
#endif
-
Impl()
{
if (moduleLoad()) {
- vWarning<<"Failed to dlopen librlottie-image-loader library";
+ vWarning << "Failed to dlopen librlottie-image-loader library";
return;
}
-
+
init();
-
+
if (!imageLoad)
- vWarning<<"Failed to find symbol lottie_image_load in librlottie-image-loader library";
+ vWarning << "Failed to find symbol lottie_image_load in "
+ "librlottie-image-loader library";
if (!imageFree)
- vWarning<<"Failed to find symbol lottie_image_free in librlottie-image-loader library";
+ vWarning << "Failed to find symbol lottie_image_free in "
+ "librlottie-image-loader library";
if (!imageFromData)
- vWarning<<"Failed to find symbol lottie_image_load_data in librlottie-image-loader library";
+ vWarning << "Failed to find symbol lottie_image_load_data in "
+ "librlottie-image-loader library";
}
- ~Impl()
- {
- moduleFree();
- }
+ ~Impl() { moduleFree(); }
- VBitmap createBitmap(unsigned char *data, int width, int height, int channel)
+ VBitmap createBitmap(unsigned char *data, int width, int height,
+ int channel)
{
// premultiply alpha
if (channel == 4)
convertToBGRA(data, width, height);
// create a bitmap of same size.
- VBitmap result = VBitmap(width, height, VBitmap::Format::ARGB32_Premultiplied);
+ VBitmap result =
+ VBitmap(width, height, VBitmap::Format::ARGB32_Premultiplied);
// copy the data to bitmap buffer
memcpy(result.data(), data, width * height * 4);
{
if (!imageLoad) return VBitmap();
- int width, height, n;
+ int width, height, n;
unsigned char *data = imageLoad(fileName, &width, &height, &n, 4);
if (!data) {
{
if (!imageFromData) return VBitmap();
- int width, height, n;
- unsigned char *data = imageFromData(imageData, len, &width, &height, &n, 4);
+ int width, height, n;
+ unsigned char *data =
+ imageFromData(imageData, len, &width, &height, &n, 4);
if (!data) {
return VBitmap();
*/
void convertToBGRAPremul(unsigned char *bits, int width, int height)
{
- int pixelCount = width * height;
+ int pixelCount = width * height;
unsigned char *pix = bits;
for (int i = 0; i < pixelCount; i++) {
unsigned char r = pix[0];
*/
void convertToBGRA(unsigned char *bits, int width, int height)
{
- int pixelCount = width * height;
+ int pixelCount = width * height;
unsigned char *pix = bits;
for (int i = 0; i < pixelCount; i++) {
unsigned char r = pix[0];
}
};
-VImageLoader::VImageLoader():
- mImpl(std::make_unique<VImageLoader::Impl>())
-{
-
-}
+VImageLoader::VImageLoader() : mImpl(std::make_unique<VImageLoader::Impl>()) {}
VImageLoader::~VImageLoader() {}
{
return mImpl->load(data, len);
}
-
-/*
+/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "vmatrix.h"
-/*
+/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "vpainter.h"
-#include "vdrawhelper.h"
#include <algorithm>
+#include "vdrawhelper.h"
V_BEGIN_NAMESPACE
public:
void drawRle(const VPoint &pos, const VRle &rle);
void drawRle(const VRle &rle, const VRle &clip);
- void setCompositionMode(VPainter::CompositionMode mode) { mSpanData.mCompositionMode = mode;}
- void drawBitmapUntransform(const VRect &target, const VBitmap &bitmap, const VRect &source, uint8_t const_alpha);
+ void setCompositionMode(VPainter::CompositionMode mode)
+ {
+ mSpanData.mCompositionMode = mode;
+ }
+ void drawBitmapUntransform(const VRect &target, const VBitmap &bitmap,
+ const VRect &source, uint8_t const_alpha);
+
public:
VRasterBuffer mBuffer;
VSpanData mSpanData;
if (!mSpanData.mUnclippedBlendFunc) return;
- rle.intersect(clip, mSpanData.mUnclippedBlendFunc,
- &mSpanData);
+ rle.intersect(clip, mSpanData.mUnclippedBlendFunc, &mSpanData);
}
static void fillRect(const VRect &r, VSpanData *data)
y1 = std::max(r.y(), 0);
y2 = std::min(r.y() + r.height(), data->mDrawableSize.height());
- if (x2 <= x1 || y2 <= y1)
- return;
+ if (x2 <= x1 || y2 <= y1) return;
- const int nspans = 256;
+ const int nspans = 256;
VRle::Span spans[nspans];
int y = y1;
}
}
-void VPainterImpl::drawBitmapUntransform(const VRect &target,
- const VBitmap &bitmap,
- const VRect &source, uint8_t const_alpha)
+void VPainterImpl::drawBitmapUntransform(const VRect & target,
+ const VBitmap &bitmap,
+ const VRect & source,
+ uint8_t const_alpha)
{
mSpanData.initTexture(&bitmap, const_alpha, VBitmapData::Plain, source);
- if (!mSpanData.mUnclippedBlendFunc)
- return;
+ if (!mSpanData.mUnclippedBlendFunc) return;
mSpanData.dx = -target.x();
mSpanData.dy = -target.y();
fillRect(rr, &mSpanData);
}
-
-
VPainter::~VPainter()
{
delete mImpl;
}
void VPainter::end() {}
-void VPainter::setDrawRegion(const VRect ®ion)
+void VPainter::setDrawRegion(const VRect ®ion)
{
mImpl->mSpanData.setDrawRegion(region);
}
-
void VPainter::setBrush(const VBrush &brush)
{
mImpl->mSpanData.setup(brush);
}
-void VPainter::setCompositionMode(CompositionMode mode)
+void VPainter::setCompositionMode(CompositionMode mode)
{
mImpl->setCompositionMode(mode);
}
mImpl->drawRle(rle, clip);
}
-
VRect VPainter::clipBoundingRect() const
{
return mImpl->mSpanData.clipRect();
}
-void VPainter::drawBitmap(const VPoint &point, const VBitmap &bitmap, const VRect &source, uint8_t const_alpha)
+void VPainter::drawBitmap(const VPoint &point, const VBitmap &bitmap,
+ const VRect &source, uint8_t const_alpha)
{
if (!bitmap.valid()) return;
bitmap, source, const_alpha);
}
-void VPainter::drawBitmap(const VRect &target, const VBitmap &bitmap, const VRect &source, uint8_t const_alpha)
+void VPainter::drawBitmap(const VRect &target, const VBitmap &bitmap,
+ const VRect &source, uint8_t const_alpha)
{
if (!bitmap.valid()) return;
}
}
-void VPainter::drawBitmap(const VPoint &point, const VBitmap &bitmap, uint8_t const_alpha)
+void VPainter::drawBitmap(const VPoint &point, const VBitmap &bitmap,
+ uint8_t const_alpha)
{
if (!bitmap.valid()) return;
drawBitmap(VRect(point.x(), point.y(), bitmap.width(), bitmap.height()),
- bitmap, VRect(0, 0, bitmap.width(), bitmap.height()), const_alpha);
+ bitmap, VRect(0, 0, bitmap.width(), bitmap.height()),
+ const_alpha);
}
-void VPainter::drawBitmap(const VRect &rect, const VBitmap &bitmap, uint8_t const_alpha)
+void VPainter::drawBitmap(const VRect &rect, const VBitmap &bitmap,
+ uint8_t const_alpha)
{
if (!bitmap.valid()) return;
- drawBitmap(rect, bitmap, VRect(0, 0, bitmap.width(), bitmap.height()), const_alpha);
+ drawBitmap(rect, bitmap, VRect(0, 0, bitmap.width(), bitmap.height()),
+ const_alpha);
}
V_END_NAMESPACE
-/*
+/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "vpath.h"
#include <cassert>
+#include <iterator>
#include <vector>
-#include <iterator>
#include "vbezier.h"
#include "vdebug.h"
-#include "vrect.h"
#include "vline.h"
+#include "vrect.h"
V_BEGIN_NAMESPACE
i++;
break;
case VPath::Element::LineTo: {
- mLength += VLine( m_points[i-1], m_points[i]).length();
+ mLength += VLine(m_points[i - 1], m_points[i]).length();
i++;
break;
}
case VPath::Element::CubicTo: {
- mLength += VBezier::fromPoints(m_points[i-1], m_points[i],
- m_points[i+1], m_points[i+2]).length();
+ mLength += VBezier::fromPoints(m_points[i - 1], m_points[i],
+ m_points[i + 1], m_points[i + 2])
+ .length();
i += 3;
break;
}
}
}
-void VPath::VPathData::moveTo(float x, float y)
+void VPath::VPathData::moveTo(float x, float y)
{
mStartPoint = {x, y};
mNewSegment = false;
m_elements.emplace_back(VPath::Element::MoveTo);
- m_points.emplace_back(x,y);
+ m_points.emplace_back(x, y);
m_segments++;
mLengthDirty = true;
}
-void VPath::VPathData::lineTo(float x, float y)
+void VPath::VPathData::lineTo(float x, float y)
{
checkNewSegment();
m_elements.emplace_back(VPath::Element::LineTo);
- m_points.emplace_back(x,y);
+ m_points.emplace_back(x, y);
mLengthDirty = true;
}
-void VPath::VPathData::cubicTo(float cx1, float cy1, float cx2, float cy2,
- float ex, float ey)
+void VPath::VPathData::cubicTo(float cx1, float cy1, float cx2, float cy2,
+ float ex, float ey)
{
checkNewSegment();
m_elements.emplace_back(VPath::Element::CubicTo);
void VPath::VPathData::arcTo(const VRectF &rect, float startAngle,
float sweepLength, bool forceMoveTo)
{
- size_t point_count = 0;
+ size_t point_count = 0;
VPointF pts[15];
VPointF curve_start =
curvesForArc(rect, startAngle, sweepLength, pts, &point_count);
// moveto 12 o'clock.
moveTo(x + w2, y);
// 12 -> 3 o'clock
- cubicTo(x + w2 + w2k, y, x + w, y + h2 - h2k,
- x + w, y + h2);
+ cubicTo(x + w2 + w2k, y, x + w, y + h2 - h2k, x + w, y + h2);
// 3 -> 6 o'clock
- cubicTo(x + w, y + h2 + h2k, x + w2 + w2k, y + h,
- x + w2, y + h);
+ cubicTo(x + w, y + h2 + h2k, x + w2 + w2k, y + h, x + w2, y + h);
// 6 -> 9 o'clock
- cubicTo(x + w2 - w2k, y + h, x, y + h2 + h2k,
- x, y + h2);
+ cubicTo(x + w2 - w2k, y + h, x, y + h2 + h2k, x, y + h2);
// 9 -> 12 o'clock
- cubicTo(x, y + h2 - h2k, x + w2 - w2k, y,
- x + w2, y);
+ cubicTo(x, y + h2 - h2k, x + w2 - w2k, y, x + w2, y);
} else {
// moveto 12 o'clock.
moveTo(x + w2, y);
// 12 -> 9 o'clock
- cubicTo(x + w2 - w2k, y, x, y + h2 - h2k,
- x, y + h2);
+ cubicTo(x + w2 - w2k, y, x, y + h2 - h2k, x, y + h2);
// 9 -> 6 o'clock
- cubicTo(x, y + h2 + h2k, x + w2 - w2k, y + h,
- x + w2, y + h);
+ cubicTo(x, y + h2 + h2k, x + w2 - w2k, y + h, x + w2, y + h);
// 6 -> 3 o'clock
- cubicTo(x + w2 + w2k, y + h, x + w, y + h2 + h2k,
- x + w, y + h2);
+ cubicTo(x + w2 + w2k, y + h, x + w, y + h2 + h2k, x + w, y + h2);
// 3 -> 12 o'clock
- cubicTo(x + w, y + h2 - h2k, x + w2 + w2k, y,
- x + w2, y);
+ cubicTo(x + w, y + h2 - h2k, x + w2 + w2k, y, x + w2, y);
}
close();
}
void VPath::VPathData::addRoundRect(const VRectF &rect, float roundness,
VPath::Direction dir)
{
- if (2 * roundness > rect.width()) roundness = rect.width()/2.0f;
- if (2 * roundness > rect.height()) roundness = rect.height()/2.0f;
+ if (2 * roundness > rect.width()) roundness = rect.width() / 2.0f;
+ if (2 * roundness > rect.height()) roundness = rect.height() / 2.0f;
addRoundRect(rect, roundness, roundness, dir);
}
cp2y *= partialPointAmount;
}
- cubicTo(previousX - cp1x + cx, previousY - cp1y + cy,
- x + cp2x + cx, y + cp2y + cy,
- x + cx, y + cy);
+ cubicTo(previousX - cp1x + cx, previousY - cp1y + cy, x + cp2x + cx,
+ y + cp2y + cy, x + cx, y + cy);
} else {
lineTo(x + cx, y + cy);
}
float cp2x = radius * roundness * POLYGON_MAGIC_NUMBER * cp2Dx;
float cp2y = radius * roundness * POLYGON_MAGIC_NUMBER * cp2Dy;
- cubicTo(previousX - cp1x + cx, previousY - cp1y + cy,
- x + cp2x + cx, y + cp2y + cy, x, y);
+ cubicTo(previousX - cp1x + cx, previousY - cp1y + cy, x + cp2x + cx,
+ y + cp2y + cy, x, y);
} else {
lineTo(x + cx, y + cy);
}
if (m_elements.capacity() < m_elements.size() + path.m_elements.size())
m_elements.reserve(m_elements.size() + path.m_elements.size());
- std::copy(path.m_points.begin(), path.m_points.end(), back_inserter(m_points));
- std::copy(path.m_elements.begin(), path.m_elements.end(), back_inserter(m_elements));
+ std::copy(path.m_points.begin(), path.m_points.end(),
+ back_inserter(m_points));
+ std::copy(path.m_elements.begin(), path.m_elements.end(),
+ back_inserter(m_elements));
m_segments += segment;
mLengthDirty = true;
-/*
+/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "vpathmesure.h"
+#include <limits>
#include "vbezier.h"
#include "vdasher.h"
-#include <limits>
V_BEGIN_NAMESPACE
if (vCompare(mStart, mEnd)) return VPath();
if ((vCompare(mStart, 0.0f) && (vCompare(mEnd, 1.0f))) ||
- (vCompare(mStart, 1.0f) && (vCompare(mEnd, 0.0f)))) return path;
+ (vCompare(mStart, 1.0f) && (vCompare(mEnd, 0.0f))))
+ return path;
float length = path.length();
if (mStart < mEnd) {
- float array[4] = {0.0f, length * mStart, //1st segment
- (mEnd - mStart) * length, std::numeric_limits<float>::max(), //2nd segment
- };
+ float array[4] = {
+ 0.0f, length * mStart, // 1st segment
+ (mEnd - mStart) * length,
+ std::numeric_limits<float>::max(), // 2nd segment
+ };
VDasher dasher(array, 4);
return dasher.dashed(path);
} else {
- float array[4] = {length * mEnd, (mStart - mEnd) * length, //1st segment
- (1 - mStart) * length, std::numeric_limits<float>::max(), //2nd segment
- };
+ float array[4] = {
+ length * mEnd, (mStart - mEnd) * length, // 1st segment
+ (1 - mStart) * length,
+ std::numeric_limits<float>::max(), // 2nd segment
+ };
VDasher dasher(array, 4);
return dasher.dashed(path);
}
-/*
+/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "vraster.h"
#include <cstring>
#include <memory>
+#include "config.h"
#include "v_ft_raster.h"
#include "v_ft_stroker.h"
#include "vdebug.h"
#include "vmatrix.h"
#include "vpath.h"
#include "vrle.h"
-#include "config.h"
V_BEGIN_NAMESPACE
-template<typename T>
-class dyn_array
-{
+template <typename T>
+class dyn_array {
public:
- explicit dyn_array(size_t size):mCapacity(size),mData(std::make_unique<T[]>(mCapacity)){}
+ explicit dyn_array(size_t size)
+ : mCapacity(size), mData(std::make_unique<T[]>(mCapacity))
+ {
+ }
void reserve(size_t size)
{
if (mCapacity > size) return;
mCapacity = size;
mData = std::make_unique<T[]>(mCapacity);
}
- T* data() const {return mData.get();}
- dyn_array& operator=(dyn_array &&) noexcept = delete;
+ T * data() const { return mData.get(); }
+ dyn_array &operator=(dyn_array &&) noexcept = delete;
+
private:
- size_t mCapacity{0};
- std::unique_ptr<T[]> mData{nullptr};
+ size_t mCapacity{0};
+ std::unique_ptr<T[]> mData{nullptr};
};
struct FTOutline {
void close();
void end();
void transform(const VMatrix &m);
- SW_FT_Pos TO_FT_COORD(float x) { return SW_FT_Pos(x*64);} // to freetype 26.6 coordinate.
- SW_FT_Outline ft;
- bool closed{false};
- SW_FT_Stroker_LineCap ftCap;
- SW_FT_Stroker_LineJoin ftJoin;
- SW_FT_Fixed ftWidth;
- SW_FT_Fixed ftMeterLimit;
+ SW_FT_Pos TO_FT_COORD(float x)
+ {
+ return SW_FT_Pos(x * 64);
+ } // to freetype 26.6 coordinate.
+ SW_FT_Outline ft;
+ bool closed{false};
+ SW_FT_Stroker_LineCap ftCap;
+ SW_FT_Stroker_LineJoin ftJoin;
+ SW_FT_Fixed ftWidth;
+ SW_FT_Fixed ftMeterLimit;
dyn_array<SW_FT_Vector> mPointMemory{100};
dyn_array<char> mTagMemory{100};
dyn_array<short> mContourMemory{10};
static void rleGenerationCb(int count, const SW_FT_Span *spans, void *user)
{
- VRle * rle = static_cast<VRle *>(user);
+ VRle *rle = static_cast<VRle *>(user);
auto *rleSpan = reinterpret_cast<const VRle::Span *>(spans);
rle->addSpan(rleSpan, count);
}
static void bboxCb(int x, int y, int w, int h, void *user)
{
- VRle * rle = static_cast<VRle *>(user);
+ VRle *rle = static_cast<VRle *>(user);
rle->setBoundingRect({x, y, w, h});
}
-
class SharedRle {
public:
SharedRle() = default;
- VRle& unsafe(){ return _rle;}
- void notify() {
+ VRle &unsafe() { return _rle; }
+ void notify()
+ {
{
std::lock_guard<std::mutex> lock(_mutex);
_ready = true;
}
_cv.notify_one();
}
- VRle& get(){
-
+ VRle &get()
+ {
if (!_pending) return _rle;
std::unique_lock<std::mutex> lock(_mutex);
- while(!_ready) _cv.wait(lock);
+ while (!_ready) _cv.wait(lock);
_pending = false;
return _rle;
}
- void reset() {
+ void reset()
+ {
_ready = false;
_pending = true;
}
+
private:
- VRle _rle;
- std::mutex _mutex;
- std::condition_variable _cv;
- bool _ready{true};
- bool _pending{false};
+ VRle _rle;
+ std::mutex _mutex;
+ std::condition_variable _cv;
+ bool _ready{true};
+ bool _pending{false};
};
struct VRleTask {
- SharedRle mRle;
- VPath mPath;
- float mStrokeWidth;
- float mMeterLimit;
- VRect mClip;
- FillRule mFillRule;
- CapStyle mCap;
- JoinStyle mJoin;
- bool mGenerateStroke;
-
- VRle& rle() { return mRle.get();}
+ SharedRle mRle;
+ VPath mPath;
+ float mStrokeWidth;
+ float mMeterLimit;
+ VRect mClip;
+ FillRule mFillRule;
+ CapStyle mCap;
+ JoinStyle mJoin;
+ bool mGenerateStroke;
+
+ VRle &rle() { return mRle.get(); }
void update(VPath path, FillRule fillRule, const VRect &clip)
{
mGenerateStroke = false;
}
- void update(VPath path, CapStyle cap, JoinStyle join, float width, float meterLimit, const VRect &clip)
+ void update(VPath path, CapStyle cap, JoinStyle join, float width,
+ float meterLimit, const VRect &clip)
{
mRle.reset();
mPath = std::move(path);
if (!mClip.empty()) {
params.flags |= SW_FT_RASTER_FLAG_CLIP;
- params.clip_box.xMin = mClip.left();
- params.clip_box.yMin = mClip.top();
- params.clip_box.xMax = mClip.right();
- params.clip_box.yMax = mClip.bottom();
+ params.clip_box.xMin = mClip.left();
+ params.clip_box.yMin = mClip.top();
+ params.clip_box.xMax = mClip.right();
+ params.clip_box.yMax = mClip.bottom();
}
// compute rle
sw_ft_grays_raster.raster_render(nullptr, ¶ms);
uint points, contors;
- SW_FT_Stroker_Set(stroker, outRef.ftWidth, outRef.ftCap, outRef.ftJoin,
- outRef.ftMeterLimit);
+ SW_FT_Stroker_Set(stroker, outRef.ftWidth, outRef.ftCap,
+ outRef.ftJoin, outRef.ftMeterLimit);
SW_FT_Stroker_ParseOutline(stroker, &outRef.ft);
SW_FT_Stroker_GetCounts(stroker, &points, &contors);
#ifdef LOTTIE_THREAD_SUPPORT
-#include "vtaskqueue.h"
#include <thread>
+#include "vtaskqueue.h"
class RleTaskScheduler {
- const unsigned _count{std::thread::hardware_concurrency()};
- std::vector<std::thread> _threads;
- std::vector<TaskQueue<VTask>> _q{_count};
- std::atomic<unsigned> _index{0};
+ const unsigned _count{std::thread::hardware_concurrency()};
+ std::vector<std::thread> _threads;
+ std::vector<TaskQueue<VTask>> _q{_count};
+ std::atomic<unsigned> _index{0};
void run(unsigned i)
{
_threads.emplace_back([&, n] { run(n); });
}
}
+
public:
- static RleTaskScheduler& instance()
+ static RleTaskScheduler &instance()
{
- static RleTaskScheduler singleton;
- return singleton;
+ static RleTaskScheduler singleton;
+ return singleton;
}
~RleTaskScheduler()
public:
FTOutline outlineRef;
SW_FT_Stroker stroker;
+
public:
- static RleTaskScheduler& instance()
+ static RleTaskScheduler &instance()
{
- static RleTaskScheduler singleton;
- return singleton;
+ static RleTaskScheduler singleton;
+ return singleton;
}
- RleTaskScheduler()
- {
- SW_FT_Stroker_New(&stroker);
- }
+ RleTaskScheduler() { SW_FT_Stroker_New(&stroker); }
- ~RleTaskScheduler()
- {
- SW_FT_Stroker_Done(stroker);
- }
+ ~RleTaskScheduler() { SW_FT_Stroker_Done(stroker); }
- void process(VTask task)
- {
- (*task)(outlineRef, stroker);
- }
+ void process(VTask task) { (*task)(outlineRef, stroker); }
};
#endif
-
-struct VRasterizer::VRasterizerImpl
-{
+struct VRasterizer::VRasterizerImpl {
VRleTask mTask;
- VRle& rle(){ return mTask.rle(); }
- VRleTask& task(){ return mTask; }
+ VRle & rle() { return mTask.rle(); }
+ VRleTask &task() { return mTask; }
};
VRle VRasterizer::rle()
{
- if(!d) return VRle();
+ if (!d) return VRle();
return d->rle();
}
void VRasterizer::init()
{
- if(!d) d = std::make_shared<VRasterizerImpl>();
+ if (!d) d = std::make_shared<VRasterizerImpl>();
}
void VRasterizer::updateRequest()
updateRequest();
}
-void VRasterizer::rasterize(VPath path, CapStyle cap, JoinStyle join, float width, float meterLimit, const VRect &clip)
+void VRasterizer::rasterize(VPath path, CapStyle cap, JoinStyle join,
+ float width, float meterLimit, const VRect &clip)
{
init();
if (path.empty() || vIsZero(width)) {
-/*
+/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "vrect.h"
VRect VRect::operator&(const VRect &r) const
{
- if (empty())
- return VRect();
+ if (empty()) return VRect();
int l1 = x1;
int r1 = x1;
else
r2 = r.x2;
- if (l1 > r2 || l2 > r1)
- return VRect();
+ if (l1 > r2 || l2 > r1) return VRect();
int t1 = y1;
int b1 = y1;
else
b2 = r.y2;
- if (t1 > b2 || t2 > b1)
- return VRect();
+ if (t1 > b2 || t2 > b1) return VRect();
VRect tmp;
tmp.x1 = std::max(l1, l2);
-/*
+/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "vrle.h"
V_BEGIN_NAMESPACE
-enum class Operation {
- Add,
- Xor
-};
+enum class Operation { Add, Xor };
struct VRleHelper {
size_t alloc;
static void rleIntersectWithRle(VRleHelper *, int, int, VRleHelper *,
VRleHelper *);
static void rleIntersectWithRect(const VRect &, VRleHelper *, VRleHelper *);
-static void rleOpGeneric(VRleHelper *, VRleHelper *, VRleHelper *, Operation op);
+static void rleOpGeneric(VRleHelper *, VRleHelper *, VRleHelper *,
+ Operation op);
static void rleSubstractWithRle(VRleHelper *, VRleHelper *, VRleHelper *);
static inline uchar divBy255(int x)
mBboxDirty = false;
- int l = std::numeric_limits<int>::max();
+ int l = std::numeric_limits<int>::max();
const VRle::Span *span = mSpans.data();
mBbox = VRect();
return;
}
- VRect clip = r;
+ VRect clip = r;
VRleHelper tresult, tmp_obj;
std::array<VRle::Span, 256> array;
mBboxDirty = true;
}
-void VRle::VRleData::opGeneric(const VRle::VRleData &a, const VRle::VRleData &b, OpCode code)
+void VRle::VRleData::opGeneric(const VRle::VRleData &a, const VRle::VRleData &b,
+ OpCode code)
{
// This routine assumes, obj1(span_y) < obj2(span_y).
mBboxDirty = false;
}
-static void rle_cb(size_t count, const VRle::Span *spans, void *userData)
+static void rle_cb(size_t count, const VRle::Span *spans, void *userData)
{
auto vector = static_cast<std::vector<VRle::Span> *>(userData);
copyArrayToVector(spans, count, *vector);
}
-void opIntersectHelper(const VRle::VRleData &obj1,
- const VRle::VRleData &obj2,
+void opIntersectHelper(const VRle::VRleData &obj1, const VRle::VRleData &obj2,
VRle::VRleSpanCb cb, void *userData)
{
VRleHelper result, source, clip;
updateBbox();
}
-
#define VMIN(a, b) ((a) < (b) ? (a) : (b))
#define VMAX(a, b) ((a) > (b) ? (a) : (b))
result->size = result->alloc - available;
}
-void blitXor(VRle::Span *spans, int count, uchar *buffer,
- int offsetX)
+void blitXor(VRle::Span *spans, int count, uchar *buffer, int offsetX)
{
while (count--) {
- int x = spans->x + offsetX;
- int l = spans->len;
+ int x = spans->x + offsetX;
+ int l = spans->len;
uchar *ptr = buffer + x;
while (l--) {
int da = *ptr;
- *ptr = divBy255((255 - spans->coverage) * (da) + spans->coverage * (255 - da));
+ *ptr = divBy255((255 - spans->coverage) * (da) +
+ spans->coverage * (255 - da));
ptr++;
}
spans++;
int offsetX)
{
while (count--) {
- int x = spans->x + offsetX;
- int l = spans->len;
+ int x = spans->x + offsetX;
+ int l = spans->len;
uchar *ptr = buffer + x;
while (l--) {
*ptr = divBy255((255 - spans->coverage) * (*ptr));
void blitSrcOver(VRle::Span *spans, int count, uchar *buffer, int offsetX)
{
while (count--) {
- int x = spans->x + offsetX;
- int l = spans->len;
+ int x = spans->x + offsetX;
+ int l = spans->len;
uchar *ptr = buffer + x;
while (l--) {
*ptr = spans->coverage + divBy255((255 - spans->coverage) * (*ptr));
void blit(VRle::Span *spans, int count, uchar *buffer, int offsetX)
{
while (count--) {
- int x = spans->x + offsetX;
- int l = spans->len;
+ int x = spans->x + offsetX;
+ int l = spans->len;
uchar *ptr = buffer + x;
while (l--) {
*ptr = std::max(spans->coverage, *ptr);
size_t bufferToRle(uchar *buffer, int size, int offsetX, int y, VRle::Span *out)
{
- size_t count = 0;
- uchar value = buffer[0];
- int curIndex = 0;
+ size_t count = 0;
+ uchar value = buffer[0];
+ int curIndex = 0;
size = offsetX < 0 ? size + offsetX : size;
for (int i = 0; i < size; i++) {
return count;
}
-static void rleOpGeneric(VRleHelper *a, VRleHelper *b, VRleHelper *result, Operation op)
+static void rleOpGeneric(VRleHelper *a, VRleHelper *b, VRleHelper *result,
+ Operation op)
{
std::array<VRle::Span, 256> temp;
VRle::Span * out = result->spans;
blitXor(bStart, (bPtr - bStart), array.data(), -offset);
VRle::Span *tResult = temp.data();
size_t size = bufferToRle(array.data(), std::max(aLength, bLength),
- offset, y, tResult);
+ offset, y, tResult);
if (available >= size) {
while (size--) {
*out++ = *tResult++;
blitDestinationOut(bStart, (bPtr - bStart), array.data(), -offset);
VRle::Span *tResult = temp.data();
size_t size = bufferToRle(array.data(), std::max(aLength, bLength),
- offset, y, tResult);
+ offset, y, tResult);
if (available >= size) {
while (size--) {
*out++ = *tResult++;