mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-12 07:13:23 +00:00
Add support to copy cels from Indexed <-> Indexed with different palettes
This commit is contained in:
parent
bdbffc8e6c
commit
a1dcb05a99
@ -12,7 +12,10 @@
|
|||||||
#include "base/unique_ptr.h"
|
#include "base/unique_ptr.h"
|
||||||
#include "doc/cel.h"
|
#include "doc/cel.h"
|
||||||
#include "doc/image.h"
|
#include "doc/image.h"
|
||||||
|
#include "doc/layer.h"
|
||||||
|
#include "doc/palette.h"
|
||||||
#include "doc/sprite.h"
|
#include "doc/sprite.h"
|
||||||
|
#include "render/quantization.h"
|
||||||
#include "render/render.h"
|
#include "render/render.h"
|
||||||
|
|
||||||
namespace app {
|
namespace app {
|
||||||
@ -23,16 +26,50 @@ Cel* create_cel_copy(const Cel* srcCel,
|
|||||||
const Sprite* dstSprite,
|
const Sprite* dstSprite,
|
||||||
const frame_t dstFrame)
|
const frame_t dstFrame)
|
||||||
{
|
{
|
||||||
|
const Image* celImage = srcCel->image();
|
||||||
|
|
||||||
base::UniquePtr<Cel> dstCel(
|
base::UniquePtr<Cel> dstCel(
|
||||||
new Cel(dstFrame,
|
new Cel(dstFrame,
|
||||||
ImageRef(Image::create(dstSprite->pixelFormat(),
|
ImageRef(Image::create(dstSprite->pixelFormat(),
|
||||||
srcCel->image()->width(),
|
celImage->width(),
|
||||||
srcCel->image()->height()))));
|
celImage->height()))));
|
||||||
|
|
||||||
|
// If both images are indexed but with different palette, we can
|
||||||
|
// convert the source cel to RGB first.
|
||||||
|
if (dstSprite->pixelFormat() == IMAGE_INDEXED &&
|
||||||
|
celImage->pixelFormat() == IMAGE_INDEXED &&
|
||||||
|
srcCel->sprite()->palette(srcCel->frame())->countDiff(
|
||||||
|
dstSprite->palette(dstFrame), nullptr, nullptr)) {
|
||||||
|
ImageRef tmpImage(Image::create(IMAGE_RGB, celImage->width(), celImage->height()));
|
||||||
|
tmpImage->clear(0);
|
||||||
|
|
||||||
|
render::convert_pixel_format(
|
||||||
|
celImage,
|
||||||
|
tmpImage.get(),
|
||||||
|
IMAGE_RGB,
|
||||||
|
DitheringMethod::NONE,
|
||||||
|
srcCel->sprite()->rgbMap(srcCel->frame()),
|
||||||
|
srcCel->sprite()->palette(srcCel->frame()),
|
||||||
|
srcCel->layer()->isBackground(),
|
||||||
|
0);
|
||||||
|
|
||||||
|
render::convert_pixel_format(
|
||||||
|
tmpImage.get(),
|
||||||
|
dstCel->image(),
|
||||||
|
IMAGE_INDEXED,
|
||||||
|
DitheringMethod::NONE,
|
||||||
|
dstSprite->rgbMap(dstFrame),
|
||||||
|
dstSprite->palette(dstFrame),
|
||||||
|
srcCel->layer()->isBackground(),
|
||||||
|
dstSprite->transparentColor());
|
||||||
|
}
|
||||||
|
else {
|
||||||
render::composite_image(
|
render::composite_image(
|
||||||
dstCel->image(), srcCel->image(),
|
dstCel->image(),
|
||||||
srcCel->sprite()->palette(srcCel->frame()), // TODO add dst palette
|
celImage,
|
||||||
|
srcCel->sprite()->palette(srcCel->frame()),
|
||||||
0, 0, 255, BlendMode::SRC);
|
0, 0, 255, BlendMode::SRC);
|
||||||
|
}
|
||||||
|
|
||||||
dstCel->setPosition(srcCel->position());
|
dstCel->setPosition(srcCel->position());
|
||||||
dstCel->setOpacity(srcCel->opacity());
|
dstCel->setOpacity(srcCel->opacity());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user