mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-29 10:20:48 +00:00
Fix webp export to export one tag correctly instead of all frames (fix #3622)
This commit is contained in:
parent
dbfc7d745f
commit
afbede3eae
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2018-2022 Igara Studio S.A.
|
||||
// Copyright (C) 2018-2023 Igara Studio S.A.
|
||||
// Copyright (C) 2015-2018 David Capello
|
||||
// Copyright (C) 2015 Gabriel Rauter
|
||||
//
|
||||
@ -257,7 +257,6 @@ bool WebPFormat::onSave(FileOp* fop)
|
||||
FILE* fp = handle.get();
|
||||
|
||||
const FileAbstractImage* sprite = fop->abstractImage();
|
||||
const doc::frame_t totalFrames = sprite->frames();
|
||||
const int w = sprite->width();
|
||||
const int h = sprite->height();
|
||||
|
||||
@ -302,6 +301,7 @@ bool WebPFormat::onSave(FileOp* fop)
|
||||
|
||||
ImageRef image(Image::create(IMAGE_RGB, w, h));
|
||||
|
||||
const doc::frame_t totalFrames = fop->roi().frames();
|
||||
WriterData wd(fp, fop, 0, totalFrames, 0.0);
|
||||
WebPPicture pic;
|
||||
WebPPictureInit(&pic);
|
||||
@ -315,10 +315,18 @@ bool WebPFormat::onSave(FileOp* fop)
|
||||
|
||||
WebPAnimEncoder* enc = WebPAnimEncoderNew(w, h, &enc_options);
|
||||
int timestamp_ms = 0;
|
||||
auto frame_beg = fop->roi().selectedFrames().begin();
|
||||
#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
|
||||
clear_image(image.get(), image->maskColor());
|
||||
sprite->renderFrame(f, image.get());
|
||||
sprite->renderFrame(frame, image.get());
|
||||
|
||||
// Switch R <-> B channels because WebPAnimEncoderAssemble()
|
||||
// expects MODE_BGRA pictures.
|
||||
@ -342,7 +350,7 @@ bool WebPFormat::onSave(FileOp* fop)
|
||||
else
|
||||
return true;
|
||||
}
|
||||
timestamp_ms += sprite->frameDuration(f);
|
||||
timestamp_ms += sprite->frameDuration(frame);
|
||||
|
||||
wd.f = f;
|
||||
}
|
||||
|
@ -322,3 +322,38 @@ d=$t/save-as-with-slice
|
||||
$ASEPRITE -b sprites/slices.aseprite -save-as $d/{slice}.png
|
||||
expect "line.png
|
||||
square.png" "list_files $d"
|
||||
|
||||
# Test https://github.com/aseprite/aseprite/issues/3622
|
||||
# Test that -save-as -tag will save the right tag frames in webp file format
|
||||
|
||||
d=$t/save-as-tag-webp
|
||||
mkdir $d # TODO why do we need this?
|
||||
$ASEPRITE -b -frame-tag "a" sprites/1empty3.aseprite -save-as $d/save-as-tag.webp || exit 1
|
||||
expect "save-as-tag.webp" "list_files $d"
|
||||
cat >$d/compare.lua <<EOF
|
||||
local a = app.open("sprites/1empty3.aseprite")
|
||||
app.command.FlattenLayers()
|
||||
local b = app.open("$d/save-as-tag.webp")
|
||||
-- Shrink frames:
|
||||
for f = 1,#b.frames do
|
||||
local oldColor = b.layers[1]:cel(f).image:getPixel(0,0)
|
||||
app.useTool{tool="pencil", points={Point(0,0)}, color=Color(255,0,0)}
|
||||
app.useTool{tool='pencil', points={Point(0,0)}, color=oldColor}
|
||||
end
|
||||
local tagA = a.tags[1]
|
||||
assert(tagA.name == "a")
|
||||
assert(tagA.frames == #b.frames)
|
||||
local cleanImage = Image(b.spec)
|
||||
cleanImage:clear()
|
||||
for f = 1,#b.frames do
|
||||
local celA = a.layers[1]:cel(f + tagA.fromFrame.frameNumber - 1)
|
||||
local celB = b.layers[1]:cel(f)
|
||||
if celA and celB then
|
||||
assert(celA.image:isEqual(celB.image))
|
||||
else
|
||||
assert(not celA)
|
||||
assert(not celB or celB.image:isEqual(cleanImage))
|
||||
end
|
||||
end
|
||||
EOF
|
||||
$ASEPRITE -b -script "$d/compare.lua" || exit 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user