mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-23 09:41:04 +00:00
Use FileAbstractImage in .fli and .webp file formats (#3008)
This commit is contained in:
parent
9f8df8e914
commit
ab4088502c
@ -90,7 +90,7 @@ public:
|
||||
}
|
||||
|
||||
// FileAbstractImage impl
|
||||
doc::ImageSpec spec() const override {
|
||||
const doc::ImageSpec& spec() const override {
|
||||
return m_spec;
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,11 @@ namespace app {
|
||||
class FileAbstractImage {
|
||||
public:
|
||||
virtual ~FileAbstractImage() { }
|
||||
virtual doc::ImageSpec spec() const = 0;
|
||||
|
||||
virtual int width() const { return spec().width(); }
|
||||
virtual int height() const { return spec().height(); }
|
||||
|
||||
virtual const doc::ImageSpec& spec() const = 0;
|
||||
virtual os::ColorSpaceRef osColorSpace() const = 0;
|
||||
virtual bool needAlpha() const = 0;
|
||||
virtual bool isOpaque() const = 0;
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2018-2020 Igara Studio S.A.
|
||||
// Copyright (C) 2018-2022 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -48,7 +48,8 @@ class FliFormat : public FileFormat {
|
||||
FILE_SUPPORT_SAVE |
|
||||
FILE_SUPPORT_INDEXED |
|
||||
FILE_SUPPORT_FRAMES |
|
||||
FILE_SUPPORT_PALETTES;
|
||||
FILE_SUPPORT_PALETTES |
|
||||
FILE_ENCODE_ABSTRACT_IMAGE;
|
||||
}
|
||||
|
||||
bool onLoad(FileOp* fop) override;
|
||||
@ -174,7 +175,7 @@ bool FliFormat::onLoad(FileOp* fop)
|
||||
|
||||
#ifdef ENABLE_SAVE
|
||||
|
||||
static int get_time_precision(const Sprite* sprite,
|
||||
static int get_time_precision(const FileAbstractImage* sprite,
|
||||
const doc::SelectedFrames& selFrames)
|
||||
{
|
||||
// Check if all frames have the same duration
|
||||
@ -205,7 +206,7 @@ static int get_time_precision(const Sprite* sprite,
|
||||
|
||||
bool FliFormat::onSave(FileOp* fop)
|
||||
{
|
||||
const Sprite* sprite = fop->document()->sprite();
|
||||
const FileAbstractImage* sprite = fop->abstractImage();
|
||||
|
||||
// Open the file to write in binary mode
|
||||
FileHandle handle(open_file_with_exception_sync_on_close(fop->filename(), "wb"));
|
||||
@ -250,7 +251,7 @@ bool FliFormat::onSave(FileOp* fop)
|
||||
}
|
||||
|
||||
// Render the frame in the bitmap
|
||||
render.renderSprite(bmp.get(), sprite, frame);
|
||||
sprite->renderFrame(frame, bmp.get());
|
||||
|
||||
// How many times this frame should be written to get the same
|
||||
// time that it has in the sprite
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include "base/convert_to.h"
|
||||
#include "base/file_handle.h"
|
||||
#include "doc/doc.h"
|
||||
#include "render/render.h"
|
||||
#include "ui/manager.h"
|
||||
|
||||
#include "webp_options.xml.h"
|
||||
@ -61,7 +60,8 @@ class WebPFormat : public FileFormat {
|
||||
FILE_SUPPORT_RGB |
|
||||
FILE_SUPPORT_RGBA |
|
||||
FILE_SUPPORT_FRAMES |
|
||||
FILE_SUPPORT_GET_FORMAT_OPTIONS;
|
||||
FILE_SUPPORT_GET_FORMAT_OPTIONS |
|
||||
FILE_ENCODE_ABSTRACT_IMAGE;
|
||||
}
|
||||
|
||||
bool onLoad(FileOp* fop) override;
|
||||
@ -256,7 +256,8 @@ bool WebPFormat::onSave(FileOp* fop)
|
||||
FileHandle handle(open_file_with_exception_sync_on_close(fop->filename(), "wb"));
|
||||
FILE* fp = handle.get();
|
||||
|
||||
const Sprite* sprite = fop->document()->sprite();
|
||||
const FileAbstractImage* sprite = fop->abstractImage();
|
||||
const doc::frame_t totalFrames = sprite->frames();
|
||||
const int w = sprite->width();
|
||||
const int h = sprite->height();
|
||||
|
||||
@ -300,9 +301,8 @@ bool WebPFormat::onSave(FileOp* fop)
|
||||
1); // 1 = loop once
|
||||
|
||||
ImageRef image(Image::create(IMAGE_RGB, w, h));
|
||||
render::Render render;
|
||||
|
||||
WriterData wd(fp, fop, 0, sprite->totalFrames(), 0.0);
|
||||
WriterData wd(fp, fop, 0, totalFrames, 0.0);
|
||||
WebPPicture pic;
|
||||
WebPPictureInit(&pic);
|
||||
pic.width = w;
|
||||
@ -313,13 +313,12 @@ bool WebPFormat::onSave(FileOp* fop)
|
||||
pic.user_data = &wd;
|
||||
pic.progress_hook = progress_report;
|
||||
|
||||
WebPAnimEncoder* enc = WebPAnimEncoderNew(sprite->width(),
|
||||
sprite->height(),
|
||||
&enc_options);
|
||||
WebPAnimEncoder* enc = WebPAnimEncoderNew(w, h, &enc_options);
|
||||
int timestamp_ms = 0;
|
||||
for (frame_t f=0; f<sprite->totalFrames(); ++f) {
|
||||
for (frame_t f=0; f<totalFrames; ++f) {
|
||||
// Render the frame in the bitmap
|
||||
render.renderSprite(image.get(), sprite, f);
|
||||
clear_image(image.get(), image->maskColor());
|
||||
sprite->renderFrame(f, image.get());
|
||||
|
||||
// Switch R <-> B channels because WebPAnimEncoderAssemble()
|
||||
// expects MODE_BGRA pictures.
|
||||
|
Loading…
x
Reference in New Issue
Block a user