Skip to content

Commit

Permalink
apply code-format changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kevingpqi123 authored and actions-user committed Jan 25, 2022
1 parent 4af6567 commit 1b1efa6
Show file tree
Hide file tree
Showing 478 changed files with 25,735 additions and 25,667 deletions.
148 changes: 74 additions & 74 deletions src/base/BitmapComposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,103 +22,103 @@

namespace pag {
BitmapComposition::~BitmapComposition() {
for (auto sequence : sequences) {
delete sequence;
}
for (auto sequence : sequences) {
delete sequence;
}
}

CompositionType BitmapComposition::type() const {
return CompositionType::Bitmap;
return CompositionType::Bitmap;
}

static bool IsEmptyBitmapFrame(BitmapFrame* frame) {
// There was a bug in PAGExporter that causes an empty frame being exported as 1x1 frame, so we
// need to identify this kind of empty frame here.
for (auto bitmap : frame->bitmaps) {
if (bitmap->x != 0 || bitmap->y != 0) {
return false;
}
if (bitmap->fileBytes->length() > 150) {
return false;
}
// There was a bug in PAGExporter that causes an empty frame being exported as 1x1 frame, so we
// need to identify this kind of empty frame here.
for (auto bitmap : frame->bitmaps) {
if (bitmap->x != 0 || bitmap->y != 0) {
return false;
}
if (bitmap->fileBytes->length() > 150) {
return false;
}

int width = 0;
int height = 0;
if (!WebPGetInfo(bitmap->fileBytes->data(), bitmap->fileBytes->length(), &width, &height)) {
LOGE("Get webP size fail.");
}
if (width > 1 || height > 1) {
return false;
int width = 0;
int height = 0;
if (!WebPGetInfo(bitmap->fileBytes->data(), bitmap->fileBytes->length(), &width, &height)) {
LOGE("Get webP size fail.");
}
if (width > 1 || height > 1) {
return false;
}
}
}
return true;
return true;
}

static TimeRange MakeTimeRange(Frame start, Frame end, float timeScale) {
auto startFrame = static_cast<Frame>(roundf(start * timeScale));
auto endFrame = static_cast<Frame>(roundf(end * timeScale));
return {startFrame, endFrame};
auto startFrame = static_cast<Frame>(roundf(start * timeScale));
auto endFrame = static_cast<Frame>(roundf(end * timeScale));
return {startFrame, endFrame};
}

void BitmapComposition::updateStaticTimeRanges() {
staticTimeRanges = {};
if (duration <= 1) {
return;
}
if (!sequences.empty()) {
Frame start = 0;
Frame end = 0;
size_t index = 0;
auto sequence = sequences[0];
for (size_t i = 1; i < sequences.size(); i++) {
auto item = sequences[i];
if (item->frameRate > sequence->frameRate) {
sequence = item;
}
staticTimeRanges = {};
if (duration <= 1) {
return;
}
float timeScale = frameRate / sequence->frameRate;
for (auto frame : sequence->frames) {
if (IsEmptyBitmapFrame(frame)) {
end = index;
} else {
if (!sequences.empty()) {
Frame start = 0;
Frame end = 0;
size_t index = 0;
auto sequence = sequences[0];
for (size_t i = 1; i < sequences.size(); i++) {
auto item = sequences[i];
if (item->frameRate > sequence->frameRate) {
sequence = item;
}
}
float timeScale = frameRate / sequence->frameRate;
for (auto frame : sequence->frames) {
if (IsEmptyBitmapFrame(frame)) {
end = index;
} else {
if (end > start) {
auto range = MakeTimeRange(start, end, timeScale);
staticTimeRanges.push_back(range);
}
start = end = index;
}
index++;
}
if (end > start) {
auto range = MakeTimeRange(start, end, timeScale);
staticTimeRanges.push_back(range);
auto range = MakeTimeRange(start, end, timeScale);
staticTimeRanges.push_back(range);
}
start = end = index;
}
index++;
}
if (end > start) {
auto range = MakeTimeRange(start, end, timeScale);
staticTimeRanges.push_back(range);
} else {
TimeRange range = {0, duration - 1};
staticTimeRanges.push_back(range);
}
} else {
TimeRange range = {0, duration - 1};
staticTimeRanges.push_back(range);
}
}

bool BitmapComposition::hasImageContent() const {
return true;
return true;
}

bool BitmapComposition::verify() const {
if (!Composition::verify()) {
VerifyFailed();
return false;
}
if (sequences.empty()) {
VerifyFailed();
return false;
}
auto sequenceValid = [](BitmapSequence* sequence) {
return sequence != nullptr && sequence->verify();
};
if (!std::all_of(sequences.begin(), sequences.end(), sequenceValid)) {
VerifyFailed();
return false;
}
return true;
if (!Composition::verify()) {
VerifyFailed();
return false;
}
if (sequences.empty()) {
VerifyFailed();
return false;
}
auto sequenceValid = [](BitmapSequence* sequence) {
return sequence != nullptr && sequence->verify();
};
if (!std::all_of(sequences.begin(), sequences.end(), sequenceValid)) {
VerifyFailed();
return false;
}
return true;
}
} // namespace pag
44 changes: 23 additions & 21 deletions src/base/BitmapSequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,40 @@

namespace pag {
BitmapRect::~BitmapRect() {
delete fileBytes;
delete fileBytes;
}

BitmapFrame::~BitmapFrame() {
for (auto image : bitmaps) {
delete image;
}
for (auto image : bitmaps) {
delete image;
}
}

bool BitmapFrame::verify() const {
auto bitmapNotNull = [](BitmapRect* bitmap) {
return bitmap != nullptr && bitmap->fileBytes != nullptr;
};
VerifyAndReturn(std::all_of(bitmaps.begin(), bitmaps.end(), bitmapNotNull));
auto bitmapNotNull = [](BitmapRect* bitmap) {
return bitmap != nullptr && bitmap->fileBytes != nullptr;
};
VerifyAndReturn(std::all_of(bitmaps.begin(), bitmaps.end(), bitmapNotNull));
}

BitmapSequence::~BitmapSequence() {
for (auto frame : frames) {
delete frame;
}
for (auto frame : frames) {
delete frame;
}
}

bool BitmapSequence::verify() const {
if (!Sequence::verify() || frames.empty()) {
VerifyFailed();
return false;
}
auto frameNotNull = [](BitmapFrame* frame) { return frame != nullptr && frame->verify(); };
if (!std::all_of(frames.begin(), frames.end(), frameNotNull)) {
VerifyFailed();
return false;
}
return true;
if (!Sequence::verify() || frames.empty()) {
VerifyFailed();
return false;
}
auto frameNotNull = [](BitmapFrame* frame) {
return frame != nullptr && frame->verify();
};
if (!std::all_of(frames.begin(), frames.end(), frameNotNull)) {
VerifyFailed();
return false;
}
return true;
}
} // namespace pag
68 changes: 34 additions & 34 deletions src/base/ByteData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,52 +21,52 @@

namespace pag {
std::unique_ptr<ByteData> ByteData::FromPath(const std::string& filePath) {
auto stream = Stream::MakeFromFile(filePath);
if (stream == nullptr) {
return nullptr;
}
auto data = ByteData::Make(stream->size());
if (data == nullptr) {
return nullptr;
}
stream->read(data->data(), stream->size());
return data;
auto stream = Stream::MakeFromFile(filePath);
if (stream == nullptr) {
return nullptr;
}
auto data = ByteData::Make(stream->size());
if (data == nullptr) {
return nullptr;
}
stream->read(data->data(), stream->size());
return data;
}

std::unique_ptr<ByteData> ByteData::MakeCopy(const void* bytes, size_t length) {
if (length == 0) {
return Make(0);
}
auto data = new (std::nothrow) uint8_t[length];
if (data == nullptr) {
return nullptr;
}
memcpy(data, bytes, length);
auto byteData = new ByteData(data, length);
return std::unique_ptr<ByteData>(byteData);
if (length == 0) {
return Make(0);
}
auto data = new (std::nothrow) uint8_t[length];
if (data == nullptr) {
return nullptr;
}
memcpy(data, bytes, length);
auto byteData = new ByteData(data, length);
return std::unique_ptr<ByteData>(byteData);
}

std::unique_ptr<ByteData> ByteData::MakeWithoutCopy(void* data, size_t length) {
if (length == 0) {
return Make(0);
}
auto byteData = new ByteData(reinterpret_cast<uint8_t*>(data), length, nullptr);
return std::unique_ptr<ByteData>(byteData);
if (length == 0) {
return Make(0);
}
auto byteData = new ByteData(reinterpret_cast<uint8_t*>(data), length, nullptr);
return std::unique_ptr<ByteData>(byteData);
}

std::unique_ptr<ByteData> ByteData::MakeAdopted(uint8_t* data, size_t length,
std::function<void(uint8_t*)> releaseCallback) {
if (length == 0) {
data = nullptr;
}
auto byteData = new ByteData(data, length, releaseCallback);
return std::unique_ptr<ByteData>(byteData);
std::function<void(uint8_t*)> releaseCallback) {
if (length == 0) {
data = nullptr;
}
auto byteData = new ByteData(data, length, releaseCallback);
return std::unique_ptr<ByteData>(byteData);
}

std::unique_ptr<ByteData> ByteData::Make(size_t length) {
auto data = length > 0 ? new (std::nothrow) uint8_t[length] : nullptr;
auto byteData = new ByteData(data, length);
return std::unique_ptr<ByteData>(byteData);
auto data = length > 0 ? new (std::nothrow) uint8_t[length] : nullptr;
auto byteData = new ByteData(data, length);
return std::unique_ptr<ByteData>(byteData);
}

} // namespace pag
32 changes: 16 additions & 16 deletions src/base/Composition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,36 @@ Composition::Composition() : uniqueID(UniqueID::Next()) {
}

Composition::~Composition() {
delete cache;
delete audioBytes;
for (auto& marker : audioMarkers) {
delete marker;
}
delete cache;
delete audioBytes;
for (auto& marker : audioMarkers) {
delete marker;
}
}

bool Composition::staticContent() const {
return staticTimeRanges.size() == 1 && staticTimeRanges.front().start == 0 &&
staticTimeRanges.front().end == duration - 1;
return staticTimeRanges.size() == 1 && staticTimeRanges.front().start == 0 &&
staticTimeRanges.front().end == duration - 1;
}

bool Composition::hasImageContent() const {
return false;
return false;
}

CompositionType Composition::type() const {
return CompositionType::Unknown;
return CompositionType::Unknown;
}

void Composition::updateStaticTimeRanges() {
TimeRange timeRange = {0, duration - 1};
staticTimeRanges = {timeRange};
TimeRange timeRange = {0, duration - 1};
staticTimeRanges = {timeRange};
}

bool Composition::verify() const {
if (audioBytes != nullptr && audioBytes->length() == 0) {
VerifyFailed();
return false;
}
VerifyAndReturn(width > 0 && height > 0 && duration > 0 && frameRate > 0);
if (audioBytes != nullptr && audioBytes->length() == 0) {
VerifyFailed();
return false;
}
VerifyAndReturn(width > 0 && height > 0 && duration > 0 && frameRate > 0);
}
} // namespace pag
Loading

0 comments on commit 1b1efa6

Please sign in to comment.