mirror of
https://github.com/aseprite/aseprite.git
synced 2024-10-06 06:50:07 +00:00
Simplify iteration of frames in WebPFormat::onSave()
This commit is contained in:
parent
afbede3eae
commit
d75424fe87
@ -228,11 +228,12 @@ bool WebPFormat::onLoad(FileOp* fop)
|
|||||||
struct WriterData {
|
struct WriterData {
|
||||||
FILE* fp;
|
FILE* fp;
|
||||||
FileOp* fop;
|
FileOp* fop;
|
||||||
frame_t f, n;
|
frame_t f = 0;
|
||||||
double progress;
|
frame_t n;
|
||||||
|
double progress = 0.0;
|
||||||
|
|
||||||
WriterData(FILE* fp, FileOp* fop, frame_t f, frame_t n, double progress)
|
WriterData(FILE* fp, FileOp* fop, frame_t n)
|
||||||
: fp(fp), fop(fop), f(f), n(n), progress(progress) { }
|
: fp(fp), fop(fop), n(n) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
static int progress_report(int percent, const WebPPicture* pic)
|
static int progress_report(int percent, const WebPPicture* pic)
|
||||||
@ -302,7 +303,7 @@ bool WebPFormat::onSave(FileOp* fop)
|
|||||||
ImageRef image(Image::create(IMAGE_RGB, w, h));
|
ImageRef image(Image::create(IMAGE_RGB, w, h));
|
||||||
|
|
||||||
const doc::frame_t totalFrames = fop->roi().frames();
|
const doc::frame_t totalFrames = fop->roi().frames();
|
||||||
WriterData wd(fp, fop, 0, totalFrames, 0.0);
|
WriterData wd(fp, fop, totalFrames);
|
||||||
WebPPicture pic;
|
WebPPicture pic;
|
||||||
WebPPictureInit(&pic);
|
WebPPictureInit(&pic);
|
||||||
pic.width = w;
|
pic.width = w;
|
||||||
@ -315,15 +316,7 @@ bool WebPFormat::onSave(FileOp* fop)
|
|||||||
|
|
||||||
WebPAnimEncoder* enc = WebPAnimEncoderNew(w, h, &enc_options);
|
WebPAnimEncoder* enc = WebPAnimEncoderNew(w, h, &enc_options);
|
||||||
int timestamp_ms = 0;
|
int timestamp_ms = 0;
|
||||||
auto frame_beg = fop->roi().selectedFrames().begin();
|
for (frame_t frame : fop->roi().selectedFrames()) {
|
||||||
#if _DEBUG
|
|
||||||
auto frame_end = fop->roi().selectedFrames().end();
|
|
||||||
#endif
|
|
||||||
auto frame_it = frame_beg;
|
|
||||||
for (frame_t f=0; f<totalFrames; ++f) {
|
|
||||||
ASSERT(frame_it != frame_end);
|
|
||||||
frame_t frame = *frame_it;
|
|
||||||
++frame_it;
|
|
||||||
// Render the frame in the bitmap
|
// Render the frame in the bitmap
|
||||||
clear_image(image.get(), image->maskColor());
|
clear_image(image.get(), image->maskColor());
|
||||||
sprite->renderFrame(frame, image.get());
|
sprite->renderFrame(frame, image.get());
|
||||||
@ -344,7 +337,7 @@ bool WebPFormat::onSave(FileOp* fop)
|
|||||||
|
|
||||||
if (!WebPAnimEncoderAdd(enc, &pic, timestamp_ms, &config)) {
|
if (!WebPAnimEncoderAdd(enc, &pic, timestamp_ms, &config)) {
|
||||||
if (!fop->isStop()) {
|
if (!fop->isStop()) {
|
||||||
fop->setError("Error saving frame %d info\n", f);
|
fop->setError("Error saving frame %d info\n", frame);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -352,7 +345,7 @@ bool WebPFormat::onSave(FileOp* fop)
|
|||||||
}
|
}
|
||||||
timestamp_ms += sprite->frameDuration(frame);
|
timestamp_ms += sprite->frameDuration(frame);
|
||||||
|
|
||||||
wd.f = f;
|
wd.f++;
|
||||||
}
|
}
|
||||||
WebPAnimEncoderAdd(enc, nullptr, timestamp_ms, nullptr);
|
WebPAnimEncoderAdd(enc, nullptr, timestamp_ms, nullptr);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user