mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-30 06:32:42 +00:00
Replace doc::LayerImage::getCel() with doc::Layer::cel()
This commit is contained in:
parent
06d18f1e8a
commit
603dde343f
2
TODO.md
2
TODO.md
@ -46,8 +46,6 @@
|
|||||||
* Convert doc::PixelFormat to a enum class
|
* Convert doc::PixelFormat to a enum class
|
||||||
* Add doc::Spec with width/height/channels/ColorMode/ncolors
|
* Add doc::Spec with width/height/channels/ColorMode/ncolors
|
||||||
* Convert doc::LayerIndex -> typedef int doc::layer_t;
|
* Convert doc::LayerIndex -> typedef int doc::layer_t;
|
||||||
* Replace doc::LayerImage::getCel() with doc::Layer::cel()
|
|
||||||
* Replace doc::Sprite::getPalette() with doc::Sprite::palette()
|
|
||||||
* Replace doc::Palette::getEntry() with doc::Palette::entry()
|
* Replace doc::Palette::getEntry() with doc::Palette::entry()
|
||||||
* Remove LayerFolder, replace it with an array of layers
|
* Remove LayerFolder, replace it with an array of layers
|
||||||
* Add new "level" into Layer class
|
* Add new "level" into Layer class
|
||||||
|
@ -91,8 +91,8 @@ void MergeDownLayerCommand::onExecute(Context* context)
|
|||||||
|
|
||||||
for (frame_t frpos = 0; frpos<sprite->totalFrames(); ++frpos) {
|
for (frame_t frpos = 0; frpos<sprite->totalFrames(); ++frpos) {
|
||||||
// Get frames
|
// Get frames
|
||||||
Cel* src_cel = static_cast<LayerImage*>(src_layer)->getCel(frpos);
|
Cel* src_cel = src_layer->cel(frpos);
|
||||||
Cel* dst_cel = static_cast<LayerImage*>(dst_layer)->getCel(frpos);
|
Cel* dst_cel = dst_layer->cel(frpos);
|
||||||
|
|
||||||
// Get images
|
// Get images
|
||||||
Image* src_image;
|
Image* src_image;
|
||||||
|
@ -178,7 +178,7 @@ void NewFileCommand::onExecute(Context* context)
|
|||||||
LayerImage* layerImage = static_cast<LayerImage*>(layer);
|
LayerImage* layerImage = static_cast<LayerImage*>(layer);
|
||||||
layerImage->configureAsBackground();
|
layerImage->configureAsBackground();
|
||||||
|
|
||||||
Image* image = layerImage->getCel(frame_t(0))->image();
|
Image* image = layerImage->cel(frame_t(0))->image();
|
||||||
doc::clear_image(image,
|
doc::clear_image(image,
|
||||||
color_utils::color_for_target(color,
|
color_utils::color_for_target(color,
|
||||||
ColorTarget(
|
ColorTarget(
|
||||||
|
@ -76,7 +76,7 @@ void ContextFlags::update(Context* context)
|
|||||||
if (layer->isImage()) {
|
if (layer->isImage()) {
|
||||||
m_flags |= ActiveLayerIsImage;
|
m_flags |= ActiveLayerIsImage;
|
||||||
|
|
||||||
Cel* cel = static_cast<LayerImage*>(layer)->getCel(location.frame());
|
Cel* cel = layer->cel(location.frame());
|
||||||
if (cel) {
|
if (cel) {
|
||||||
m_flags |= HasActiveCel;
|
m_flags |= HasActiveCel;
|
||||||
|
|
||||||
|
@ -304,8 +304,7 @@ void DocumentApi::displaceFrames(Layer* layer, frame_t frame)
|
|||||||
|
|
||||||
// Displace all cels in '>=frame' to the next frame.
|
// Displace all cels in '>=frame' to the next frame.
|
||||||
for (frame_t c=sprite->lastFrame(); c>=frame; --c) {
|
for (frame_t c=sprite->lastFrame(); c>=frame; --c) {
|
||||||
Cel* cel = imglayer->getCel(c);
|
if (Cel* cel = imglayer->cel(c))
|
||||||
if (cel)
|
|
||||||
setCelFramePosition(imglayer, cel, cel->frame()+1);
|
setCelFramePosition(imglayer, cel, cel->frame()+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -392,11 +391,11 @@ void DocumentApi::removeFrameOfLayer(Layer* layer, frame_t frame)
|
|||||||
|
|
||||||
case ObjectType::LayerImage: {
|
case ObjectType::LayerImage: {
|
||||||
LayerImage* imglayer = static_cast<LayerImage*>(layer);
|
LayerImage* imglayer = static_cast<LayerImage*>(layer);
|
||||||
if (Cel* cel = imglayer->getCel(frame))
|
if (Cel* cel = imglayer->cel(frame))
|
||||||
removeCel(cel);
|
removeCel(cel);
|
||||||
|
|
||||||
for (++frame; frame<sprite->totalFrames(); ++frame)
|
for (++frame; frame<sprite->totalFrames(); ++frame)
|
||||||
if (Cel* cel = imglayer->getCel(frame))
|
if (Cel* cel = imglayer->cel(frame))
|
||||||
setCelFramePosition(imglayer, cel, cel->frame()-1);
|
setCelFramePosition(imglayer, cel, cel->frame()-1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -671,8 +670,7 @@ void DocumentApi::cropCel(Sprite* sprite, Cel* cel, int x, int y, int w, int h)
|
|||||||
|
|
||||||
void DocumentApi::clearCel(LayerImage* layer, frame_t frame)
|
void DocumentApi::clearCel(LayerImage* layer, frame_t frame)
|
||||||
{
|
{
|
||||||
Cel* cel = layer->getCel(frame);
|
if (Cel* cel = layer->cel(frame))
|
||||||
if (cel)
|
|
||||||
clearCel(cel);
|
clearCel(cel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -713,8 +711,8 @@ void DocumentApi::moveCel(
|
|||||||
clearCel(dstLayer, dstFrame);
|
clearCel(dstLayer, dstFrame);
|
||||||
addEmptyFramesTo(dstSprite, dstFrame);
|
addEmptyFramesTo(dstSprite, dstFrame);
|
||||||
|
|
||||||
Cel* srcCel = srcLayer->getCel(srcFrame);
|
Cel* srcCel = srcLayer->cel(srcFrame);
|
||||||
Cel* dstCel = dstLayer->getCel(dstFrame);
|
Cel* dstCel = dstLayer->cel(dstFrame);
|
||||||
Image* srcImage = (srcCel ? srcCel->image(): NULL);
|
Image* srcImage = (srcCel ? srcCel->image(): NULL);
|
||||||
Image* dstImage = (dstCel ? dstCel->image(): NULL);
|
Image* dstImage = (dstCel ? dstCel->image(): NULL);
|
||||||
|
|
||||||
@ -780,8 +778,8 @@ void DocumentApi::copyCel(
|
|||||||
clearCel(dstLayer, dstFrame);
|
clearCel(dstLayer, dstFrame);
|
||||||
addEmptyFramesTo(dstSprite, dstFrame);
|
addEmptyFramesTo(dstSprite, dstFrame);
|
||||||
|
|
||||||
Cel* srcCel = srcLayer->getCel(srcFrame);
|
Cel* srcCel = srcLayer->cel(srcFrame);
|
||||||
Cel* dstCel = dstLayer->getCel(dstFrame);
|
Cel* dstCel = dstLayer->cel(dstFrame);
|
||||||
Image* srcImage = (srcCel ? srcCel->image(): NULL);
|
Image* srcImage = (srcCel ? srcCel->image(): NULL);
|
||||||
Image* dstImage = (dstCel ? dstCel->image(): NULL);
|
Image* dstImage = (dstCel ? dstCel->image(): NULL);
|
||||||
|
|
||||||
@ -826,8 +824,8 @@ void DocumentApi::swapCel(
|
|||||||
ASSERT(frame2 >= 0 && frame2 < sprite->totalFrames());
|
ASSERT(frame2 >= 0 && frame2 < sprite->totalFrames());
|
||||||
(void)sprite; // To avoid unused variable warning on Release mode
|
(void)sprite; // To avoid unused variable warning on Release mode
|
||||||
|
|
||||||
Cel* cel1 = layer->getCel(frame1);
|
Cel* cel1 = layer->cel(frame1);
|
||||||
Cel* cel2 = layer->getCel(frame2);
|
Cel* cel2 = layer->cel(frame2);
|
||||||
|
|
||||||
if (cel1) setCelFramePosition(layer, cel1, frame2);
|
if (cel1) setCelFramePosition(layer, cel1, frame2);
|
||||||
if (cel2) setCelFramePosition(layer, cel2, frame1);
|
if (cel2) setCelFramePosition(layer, cel2, frame1);
|
||||||
@ -1020,7 +1018,7 @@ void DocumentApi::backgroundFromLayer(LayerImage* layer)
|
|||||||
|
|
||||||
// Fill all empty cels with a flat-image filled with bgcolor
|
// Fill all empty cels with a flat-image filled with bgcolor
|
||||||
for (frame_t frame(0); frame<sprite->totalFrames(); ++frame) {
|
for (frame_t frame(0); frame<sprite->totalFrames(); ++frame) {
|
||||||
Cel* cel = layer->getCel(frame);
|
Cel* cel = layer->cel(frame);
|
||||||
if (!cel) {
|
if (!cel) {
|
||||||
Image* cel_image = Image::create(sprite->pixelFormat(), sprite->width(), sprite->height());
|
Image* cel_image = Image::create(sprite->pixelFormat(), sprite->width(), sprite->height());
|
||||||
clear_image(cel_image, bgcolor);
|
clear_image(cel_image, bgcolor);
|
||||||
@ -1088,7 +1086,7 @@ void DocumentApi::flattenLayers(Sprite* sprite)
|
|||||||
clear_image(image, bgcolor);
|
clear_image(image, bgcolor);
|
||||||
render.renderSprite(image, sprite, frame);
|
render.renderSprite(image, sprite, frame);
|
||||||
|
|
||||||
cel = background->getCel(frame);
|
cel = background->cel(frame);
|
||||||
if (cel) {
|
if (cel) {
|
||||||
cel_image = cel->image();
|
cel_image = cel->image();
|
||||||
ASSERT(cel_image != NULL);
|
ASSERT(cel_image != NULL);
|
||||||
@ -1170,7 +1168,7 @@ Cel* DocumentApi::addImage(LayerImage* layer, frame_t frameNumber, Image* image)
|
|||||||
{
|
{
|
||||||
int imageIndex = addImageInStock(layer->sprite(), image);
|
int imageIndex = addImageInStock(layer->sprite(), image);
|
||||||
|
|
||||||
ASSERT(layer->getCel(frameNumber) == NULL);
|
ASSERT(layer->cel(frameNumber) == NULL);
|
||||||
|
|
||||||
base::UniquePtr<Cel> cel(new Cel(frameNumber, imageIndex));
|
base::UniquePtr<Cel> cel(new Cel(frameNumber, imageIndex));
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ TEST(DocumentApi, MoveCel) {
|
|||||||
LayerImage* layer1 = dynamic_cast<LayerImage*>(sprite->folder()->getFirstLayer());
|
LayerImage* layer1 = dynamic_cast<LayerImage*>(sprite->folder()->getFirstLayer());
|
||||||
LayerImage* layer2 = new LayerImage(sprite);
|
LayerImage* layer2 = new LayerImage(sprite);
|
||||||
|
|
||||||
Cel* cel1 = layer1->getCel(frame_t(0));
|
Cel* cel1 = layer1->cel(frame_t(0));
|
||||||
cel1->setPosition(2, -2);
|
cel1->setPosition(2, -2);
|
||||||
cel1->setOpacity(128);
|
cel1->setOpacity(128);
|
||||||
|
|
||||||
@ -55,9 +55,9 @@ TEST(DocumentApi, MoveCel) {
|
|||||||
layer1, frame_t(0),
|
layer1, frame_t(0),
|
||||||
layer2, frame_t(1));
|
layer2, frame_t(1));
|
||||||
|
|
||||||
EXPECT_EQ(NULL, layer1->getCel(frame_t(0)));
|
EXPECT_EQ(NULL, layer1->cel(frame_t(0)));
|
||||||
|
|
||||||
Cel* cel2 = layer2->getCel(frame_t(1));
|
Cel* cel2 = layer2->cel(frame_t(1));
|
||||||
ASSERT_TRUE(cel2 != NULL);
|
ASSERT_TRUE(cel2 != NULL);
|
||||||
|
|
||||||
Image* image2 = cel2->image();
|
Image* image2 = cel2->image();
|
||||||
|
@ -249,9 +249,8 @@ void DocumentExporter::exportSheet()
|
|||||||
createEmptyTexture(samples));
|
createEmptyTexture(samples));
|
||||||
|
|
||||||
Sprite* texture = textureDocument->sprite();
|
Sprite* texture = textureDocument->sprite();
|
||||||
Image* textureImage = static_cast<LayerImage*>(
|
Image* textureImage = texture->folder()->getFirstLayer()
|
||||||
texture->folder()->getFirstLayer())
|
->cel(frame_t(0))->image();
|
||||||
->getCel(frame_t(0))->image();
|
|
||||||
|
|
||||||
renderTexture(samples, textureImage);
|
renderTexture(samples, textureImage);
|
||||||
|
|
||||||
@ -296,8 +295,7 @@ void DocumentExporter::captureSamples(Samples& samples)
|
|||||||
Sample sample(doc, sprite, layer, frame, filename);
|
Sample sample(doc, sprite, layer, frame, filename);
|
||||||
|
|
||||||
if (m_ignoreEmptyCels) {
|
if (m_ignoreEmptyCels) {
|
||||||
if (layer && layer->isImage() &&
|
if (layer && layer->isImage() && !layer->cel(frame)) {
|
||||||
!static_cast<LayerImage*>(layer)->getCel(frame)) {
|
|
||||||
// Empty cel this sample completely
|
// Empty cel this sample completely
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -50,16 +50,16 @@ Palette* DocumentLocation::palette()
|
|||||||
|
|
||||||
const Cel* DocumentLocation::cel() const
|
const Cel* DocumentLocation::cel() const
|
||||||
{
|
{
|
||||||
if (m_layer && m_layer->isImage())
|
if (m_layer)
|
||||||
return static_cast<const LayerImage*>(m_layer)->getCel(m_frame);
|
return m_layer->cel(m_frame);
|
||||||
else
|
else
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Cel* DocumentLocation::cel()
|
Cel* DocumentLocation::cel()
|
||||||
{
|
{
|
||||||
if (m_layer && m_layer->isImage())
|
if (m_layer)
|
||||||
return static_cast<LayerImage*>(m_layer)->getCel(m_frame);
|
return m_layer->cel(m_frame);
|
||||||
else
|
else
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ public:
|
|||||||
LayerImage* layer = static_cast<LayerImage*>(sprite->indexToLayer(LayerIndex(i)));
|
LayerImage* layer = static_cast<LayerImage*>(sprite->indexToLayer(LayerIndex(i)));
|
||||||
|
|
||||||
for (int j=0; j<4; j++) {
|
for (int j=0; j<4; j++) {
|
||||||
Cel* cel = layer->getCel(frame_t(j));
|
Cel* cel = layer->cel(frame_t(j));
|
||||||
Image* image;
|
Image* image;
|
||||||
if (cel)
|
if (cel)
|
||||||
image = cel->image();
|
image = cel->image();
|
||||||
@ -143,7 +143,7 @@ protected:
|
|||||||
return expect_layer_frame(sprite->layerToIndex(expected_layer), -1, layer, -1);
|
return expect_layer_frame(sprite->layerToIndex(expected_layer), -1, layer, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool expect_frame(int expected_frame, int frame) {
|
bool expect_frame(int expected_frame, frame_t frame) {
|
||||||
for (int i=0; i<(int)sprite->countLayers(); ++i) {
|
for (int i=0; i<(int)sprite->countLayers(); ++i) {
|
||||||
if (!expect_layer_frame(i, expected_frame, i, frame))
|
if (!expect_layer_frame(i, expected_frame, i, frame))
|
||||||
return false;
|
return false;
|
||||||
@ -151,13 +151,13 @@ protected:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool expect_layer_frame(int expected_layer, int expected_frame, int layer, int frame) {
|
bool expect_layer_frame(int expected_layer, int expected_frame, int layer, frame_t frame) {
|
||||||
if (frame >= 0) {
|
if (frame >= 0) {
|
||||||
if (!expect_cel(expected_layer, expected_frame, layer, frame))
|
if (!expect_cel(expected_layer, expected_frame, layer, frame))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
EXPECT_EQ((expected_frame+1), sprite->frameDuration(frame_t(frame)));
|
EXPECT_EQ((expected_frame+1), sprite->frameDuration(frame));
|
||||||
return ((expected_frame+1) == sprite->frameDuration(frame_t(frame)));
|
return ((expected_frame+1) == sprite->frameDuration(frame));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (layer >= 0) {
|
if (layer >= 0) {
|
||||||
@ -171,12 +171,12 @@ protected:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool expect_cel(int expected_layer, int expected_frame, int layer, int frame) {
|
bool expect_cel(int expected_layer, int expected_frame, int layer, frame_t frame) {
|
||||||
color_t expected_color = white;
|
color_t expected_color = white;
|
||||||
|
|
||||||
color_t color = get_pixel(
|
color_t color = get_pixel(
|
||||||
static_cast<LayerImage*>(sprite->indexToLayer(LayerIndex(layer)))
|
sprite->indexToLayer(LayerIndex(layer))
|
||||||
->getCel(frame_t(frame))->image(),
|
->cel(frame)->image(),
|
||||||
expected_layer, expected_frame);
|
expected_layer, expected_frame);
|
||||||
|
|
||||||
EXPECT_EQ(expected_color, color);
|
EXPECT_EQ(expected_color, color);
|
||||||
@ -184,9 +184,8 @@ protected:
|
|||||||
return (expected_color == color);
|
return (expected_color == color);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool expect_empty_cel(int layer, int frame) {
|
bool expect_empty_cel(int layer, frame_t frame) {
|
||||||
Cel* cel = static_cast<LayerImage*>(sprite->indexToLayer(LayerIndex(layer)))
|
Cel* cel = sprite->indexToLayer(LayerIndex(layer))->cel(frame);
|
||||||
->getCel(frame_t(frame));
|
|
||||||
|
|
||||||
EXPECT_EQ(NULL, cel);
|
EXPECT_EQ(NULL, cel);
|
||||||
return (cel == NULL);
|
return (cel == NULL);
|
||||||
@ -203,17 +202,17 @@ protected:
|
|||||||
color_t white;
|
color_t white;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline DocumentRange range(Layer* fromLayer, int fromFrNum, Layer* toLayer, int toFrNum, DocumentRange::Type type) {
|
inline DocumentRange range(Layer* fromLayer, frame_t fromFrNum, Layer* toLayer, frame_t toFrNum, DocumentRange::Type type) {
|
||||||
DocumentRange r;
|
DocumentRange r;
|
||||||
r.startRange(fromLayer->sprite()->layerToIndex(fromLayer), frame_t(fromFrNum), type);
|
r.startRange(fromLayer->sprite()->layerToIndex(fromLayer), fromFrNum, type);
|
||||||
r.endRange(toLayer->sprite()->layerToIndex(toLayer), frame_t(toFrNum));
|
r.endRange(toLayer->sprite()->layerToIndex(toLayer), toFrNum);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline DocumentRange range(int fromLayer, int fromFrNum, int toLayer, int toFrNum, DocumentRange::Type type) {
|
inline DocumentRange range(int fromLayer, frame_t fromFrNum, int toLayer, frame_t toFrNum, DocumentRange::Type type) {
|
||||||
DocumentRange r;
|
DocumentRange r;
|
||||||
r.startRange(LayerIndex(fromLayer), frame_t(fromFrNum), type);
|
r.startRange(LayerIndex(fromLayer), fromFrNum, type);
|
||||||
r.endRange(LayerIndex(toLayer), frame_t(toFrNum));
|
r.endRange(LayerIndex(toLayer), toFrNum);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,15 +232,15 @@ inline DocumentRange layers_range(int layer) {
|
|||||||
return range(layer, -1, layer, -1, DocumentRange::kLayers);
|
return range(layer, -1, layer, -1, DocumentRange::kLayers);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline DocumentRange frames_range(int fromFrame, int toFrame) {
|
inline DocumentRange frames_range(frame_t fromFrame, frame_t toFrame) {
|
||||||
return range(0, fromFrame, 0, toFrame, DocumentRange::kFrames);
|
return range(0, fromFrame, 0, toFrame, DocumentRange::kFrames);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline DocumentRange frames_range(int frame) {
|
inline DocumentRange frames_range(frame_t frame) {
|
||||||
return range(0, frame, 0, frame, DocumentRange::kFrames);
|
return range(0, frame, 0, frame, DocumentRange::kFrames);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline DocumentRange cels_range(int fromLayer, int fromFrNum, int toLayer, int toFrNum) {
|
inline DocumentRange cels_range(int fromLayer, frame_t fromFrNum, int toLayer, frame_t toFrNum) {
|
||||||
return range(fromLayer, fromFrNum, toLayer, toFrNum, DocumentRange::kCels);
|
return range(fromLayer, fromFrNum, toLayer, toFrNum, DocumentRange::kCels);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -498,7 +498,7 @@ static void ase_file_write_layers(FILE* f, ASE_FrameHeader* frame_header, Layer*
|
|||||||
static void ase_file_write_cels(FILE* f, ASE_FrameHeader* frame_header, Sprite* sprite, Layer* layer, frame_t frame)
|
static void ase_file_write_cels(FILE* f, ASE_FrameHeader* frame_header, Sprite* sprite, Layer* layer, frame_t frame)
|
||||||
{
|
{
|
||||||
if (layer->isImage()) {
|
if (layer->isImage()) {
|
||||||
Cel* cel = static_cast<LayerImage*>(layer)->getCel(frame);
|
Cel* cel = layer->cel(frame);
|
||||||
if (cel) {
|
if (cel) {
|
||||||
/* fop_error(fop, "New cel in frame %d, in layer %d\n", */
|
/* fop_error(fop, "New cel in frame %d, in layer %d\n", */
|
||||||
/* frame, sprite_layer2index(sprite, layer)); */
|
/* frame, sprite_layer2index(sprite, layer)); */
|
||||||
@ -1058,7 +1058,7 @@ static Cel* ase_file_read_cel_chunk(FILE* f, Sprite* sprite, frame_t frame,
|
|||||||
case ASE_FILE_LINK_CEL: {
|
case ASE_FILE_LINK_CEL: {
|
||||||
// Read link position
|
// Read link position
|
||||||
frame_t link_frame = frame_t(fgetw(f));
|
frame_t link_frame = frame_t(fgetw(f));
|
||||||
Cel* link = static_cast<LayerImage*>(layer)->getCel(link_frame);
|
Cel* link = layer->cel(link_frame);
|
||||||
|
|
||||||
if (link) {
|
if (link) {
|
||||||
// Create a copy of the linked cel (avoid using links cel)
|
// Create a copy of the linked cel (avoid using links cel)
|
||||||
|
@ -50,9 +50,9 @@ TEST(File, SeveralSizes)
|
|||||||
doc->setFilename(&fn[0]);
|
doc->setFilename(&fn[0]);
|
||||||
|
|
||||||
// Random pixels
|
// Random pixels
|
||||||
LayerImage* layer = dynamic_cast<LayerImage*>(doc->sprite()->folder()->getFirstLayer());
|
Layer* layer = doc->sprite()->folder()->getFirstLayer();
|
||||||
ASSERT_TRUE(layer != NULL);
|
ASSERT_TRUE(layer != NULL);
|
||||||
Image* image = layer->getCel(frame_t(0))->image();
|
Image* image = layer->cel(frame_t(0))->image();
|
||||||
std::srand(w*h);
|
std::srand(w*h);
|
||||||
int c = std::rand()%256;
|
int c = std::rand()%256;
|
||||||
for (int y=0; y<h; y++) {
|
for (int y=0; y<h; y++) {
|
||||||
@ -74,9 +74,9 @@ TEST(File, SeveralSizes)
|
|||||||
ASSERT_EQ(h, doc->sprite()->height());
|
ASSERT_EQ(h, doc->sprite()->height());
|
||||||
|
|
||||||
// Same random pixels (see the seed)
|
// Same random pixels (see the seed)
|
||||||
LayerImage* layer = dynamic_cast<LayerImage*>(doc->sprite()->folder()->getFirstLayer());
|
Layer* layer = doc->sprite()->folder()->getFirstLayer();
|
||||||
ASSERT_TRUE(layer != NULL);
|
ASSERT_TRUE(layer != NULL);
|
||||||
Image* image = layer->getCel(frame_t(0))->image();
|
Image* image = layer->cel(frame_t(0))->image();
|
||||||
std::srand(w*h);
|
std::srand(w*h);
|
||||||
int c = std::rand()%256;
|
int c = std::rand()%256;
|
||||||
for (int y=0; y<h; y++) {
|
for (int y=0; y<h; y++) {
|
||||||
|
@ -54,7 +54,7 @@ TEST_F(GifFormat, Dimensions)
|
|||||||
LayerImage* layer = dynamic_cast<LayerImage*>(sprite->folder()->getFirstLayer());
|
LayerImage* layer = dynamic_cast<LayerImage*>(sprite->folder()->getFirstLayer());
|
||||||
ASSERT_NE((LayerImage*)NULL, layer);
|
ASSERT_NE((LayerImage*)NULL, layer);
|
||||||
|
|
||||||
Image* image = layer->getCel(frame_t(0))->image();
|
Image* image = layer->cel(frame_t(0))->image();
|
||||||
clear_image(image, doc->sprite()->transparentColor());
|
clear_image(image, doc->sprite()->transparentColor());
|
||||||
|
|
||||||
save_document(&m_ctx, doc);
|
save_document(&m_ctx, doc);
|
||||||
@ -98,7 +98,7 @@ TEST_F(GifFormat, OpaqueIndexed)
|
|||||||
layer->setBackground(true);
|
layer->setBackground(true);
|
||||||
ASSERT_NE((LayerImage*)NULL, layer);
|
ASSERT_NE((LayerImage*)NULL, layer);
|
||||||
|
|
||||||
Image* image = layer->getCel(frame_t(0))->image();
|
Image* image = layer->cel(frame_t(0))->image();
|
||||||
image->putPixel(0, 0, 0);
|
image->putPixel(0, 0, 0);
|
||||||
image->putPixel(0, 1, 1);
|
image->putPixel(0, 1, 1);
|
||||||
image->putPixel(1, 0, 2);
|
image->putPixel(1, 0, 2);
|
||||||
@ -124,7 +124,7 @@ TEST_F(GifFormat, OpaqueIndexed)
|
|||||||
EXPECT_EQ(rgb(129, 255, 32), pal->getEntry(2));
|
EXPECT_EQ(rgb(129, 255, 32), pal->getEntry(2));
|
||||||
EXPECT_EQ(rgb(0, 0, 255), pal->getEntry(3));
|
EXPECT_EQ(rgb(0, 0, 255), pal->getEntry(3));
|
||||||
|
|
||||||
Image* image = layer->getCel(frame_t(0))->image();
|
Image* image = layer->cel(frame_t(0))->image();
|
||||||
EXPECT_EQ(0, sprite->transparentColor());
|
EXPECT_EQ(0, sprite->transparentColor());
|
||||||
EXPECT_EQ(0, image->getPixel(0, 0));
|
EXPECT_EQ(0, image->getPixel(0, 0));
|
||||||
EXPECT_EQ(1, image->getPixel(0, 1));
|
EXPECT_EQ(1, image->getPixel(0, 1));
|
||||||
@ -154,7 +154,7 @@ TEST_F(GifFormat, TransparentIndexed)
|
|||||||
LayerImage* layer = dynamic_cast<LayerImage*>(sprite->folder()->getFirstLayer());
|
LayerImage* layer = dynamic_cast<LayerImage*>(sprite->folder()->getFirstLayer());
|
||||||
ASSERT_NE((LayerImage*)NULL, layer);
|
ASSERT_NE((LayerImage*)NULL, layer);
|
||||||
|
|
||||||
Image* image = layer->getCel(frame_t(0))->image();
|
Image* image = layer->cel(frame_t(0))->image();
|
||||||
image->putPixel(0, 0, 0);
|
image->putPixel(0, 0, 0);
|
||||||
image->putPixel(0, 1, 1);
|
image->putPixel(0, 1, 1);
|
||||||
image->putPixel(1, 0, 2);
|
image->putPixel(1, 0, 2);
|
||||||
@ -180,7 +180,7 @@ TEST_F(GifFormat, TransparentIndexed)
|
|||||||
EXPECT_EQ(rgb(129, 255, 32), pal->getEntry(2));
|
EXPECT_EQ(rgb(129, 255, 32), pal->getEntry(2));
|
||||||
EXPECT_EQ(rgb(0, 0, 255), pal->getEntry(3));
|
EXPECT_EQ(rgb(0, 0, 255), pal->getEntry(3));
|
||||||
|
|
||||||
Image* image = layer->getCel(frame_t(0))->image();
|
Image* image = layer->cel(frame_t(0))->image();
|
||||||
EXPECT_EQ(0, sprite->transparentColor());
|
EXPECT_EQ(0, sprite->transparentColor());
|
||||||
EXPECT_EQ(0, image->getPixel(0, 0));
|
EXPECT_EQ(0, image->getPixel(0, 0));
|
||||||
EXPECT_EQ(1, image->getPixel(0, 1));
|
EXPECT_EQ(1, image->getPixel(0, 1));
|
||||||
@ -204,7 +204,7 @@ TEST_F(GifFormat, TransparentRgbQuantization)
|
|||||||
LayerImage* layer = dynamic_cast<LayerImage*>(sprite->folder()->getFirstLayer());
|
LayerImage* layer = dynamic_cast<LayerImage*>(sprite->folder()->getFirstLayer());
|
||||||
ASSERT_NE((LayerImage*)NULL, layer);
|
ASSERT_NE((LayerImage*)NULL, layer);
|
||||||
|
|
||||||
Image* image = layer->getCel(frame_t(0))->image();
|
Image* image = layer->cel(frame_t(0))->image();
|
||||||
image->putPixel(0, 0, rgba(0, 0, 0, 0));
|
image->putPixel(0, 0, rgba(0, 0, 0, 0));
|
||||||
image->putPixel(0, 1, rgb(255, 0, 0));
|
image->putPixel(0, 1, rgb(255, 0, 0));
|
||||||
image->putPixel(1, 0, rgb(0, 255, 0));
|
image->putPixel(1, 0, rgb(0, 255, 0));
|
||||||
@ -224,7 +224,7 @@ TEST_F(GifFormat, TransparentRgbQuantization)
|
|||||||
ASSERT_NE((LayerImage*)NULL, layer);
|
ASSERT_NE((LayerImage*)NULL, layer);
|
||||||
|
|
||||||
Palette* pal = sprite->palette(frame_t(0));
|
Palette* pal = sprite->palette(frame_t(0));
|
||||||
Image* image = layer->getCel(frame_t(0))->image();
|
Image* image = layer->cel(frame_t(0))->image();
|
||||||
EXPECT_EQ(0, sprite->transparentColor());
|
EXPECT_EQ(0, sprite->transparentColor());
|
||||||
EXPECT_EQ(0, image->getPixel(0, 0));
|
EXPECT_EQ(0, image->getPixel(0, 0));
|
||||||
EXPECT_EQ(rgb(255, 0, 0), pal->getEntry(image->getPixel(0, 1)));
|
EXPECT_EQ(rgb(255, 0, 0), pal->getEntry(image->getPixel(0, 1)));
|
||||||
@ -250,7 +250,7 @@ TEST_F(GifFormat, OpaqueRgbQuantization)
|
|||||||
ASSERT_NE((LayerImage*)NULL, layer);
|
ASSERT_NE((LayerImage*)NULL, layer);
|
||||||
EXPECT_NE((LayerImage*)NULL, sprite->backgroundLayer());
|
EXPECT_NE((LayerImage*)NULL, sprite->backgroundLayer());
|
||||||
|
|
||||||
Image* image = layer->getCel(frame_t(0))->image();
|
Image* image = layer->cel(frame_t(0))->image();
|
||||||
image->putPixel(0, 0, rgb(0, 0, 0));
|
image->putPixel(0, 0, rgb(0, 0, 0));
|
||||||
image->putPixel(0, 1, rgb(255, 0, 0));
|
image->putPixel(0, 1, rgb(255, 0, 0));
|
||||||
image->putPixel(1, 0, rgb(0, 255, 0));
|
image->putPixel(1, 0, rgb(0, 255, 0));
|
||||||
@ -272,7 +272,7 @@ TEST_F(GifFormat, OpaqueRgbQuantization)
|
|||||||
EXPECT_EQ(layer, sprite->backgroundLayer());
|
EXPECT_EQ(layer, sprite->backgroundLayer());
|
||||||
|
|
||||||
Palette* pal = sprite->palette(frame_t(0));
|
Palette* pal = sprite->palette(frame_t(0));
|
||||||
Image* image = layer->getCel(frame_t(0))->image();
|
Image* image = layer->cel(frame_t(0))->image();
|
||||||
EXPECT_EQ(0, sprite->transparentColor());
|
EXPECT_EQ(0, sprite->transparentColor());
|
||||||
EXPECT_EQ(rgb(0, 0, 0), pal->getEntry(image->getPixel(0, 0)));
|
EXPECT_EQ(rgb(0, 0, 0), pal->getEntry(image->getPixel(0, 0)));
|
||||||
EXPECT_EQ(rgb(255, 0, 0), pal->getEntry(image->getPixel(0, 1)));
|
EXPECT_EQ(rgb(255, 0, 0), pal->getEntry(image->getPixel(0, 1)));
|
||||||
@ -299,7 +299,7 @@ TEST_F(GifFormat, OpaqueRgbQuantizationTwoLayers)
|
|||||||
LayerImage* layer2 = new LayerImage(sprite);
|
LayerImage* layer2 = new LayerImage(sprite);
|
||||||
sprite->folder()->addLayer(layer2);
|
sprite->folder()->addLayer(layer2);
|
||||||
|
|
||||||
Image* image1 = layer1->getCel(frame_t(0))->image();
|
Image* image1 = layer1->cel(frame_t(0))->image();
|
||||||
Image* image2 = Image::create(IMAGE_RGB, 2, 2);
|
Image* image2 = Image::create(IMAGE_RGB, 2, 2);
|
||||||
int image2Idx = sprite->stock()->addImage(image2);
|
int image2Idx = sprite->stock()->addImage(image2);
|
||||||
Cel* cel2 = new Cel(frame_t(0), image2Idx);
|
Cel* cel2 = new Cel(frame_t(0), image2Idx);
|
||||||
@ -330,7 +330,7 @@ TEST_F(GifFormat, OpaqueRgbQuantizationTwoLayers)
|
|||||||
ASSERT_TRUE(layer->isBackground());
|
ASSERT_TRUE(layer->isBackground());
|
||||||
|
|
||||||
Palette* pal = sprite->palette(frame_t(0));
|
Palette* pal = sprite->palette(frame_t(0));
|
||||||
Image* image = layer->getCel(frame_t(0))->image();
|
Image* image = layer->cel(frame_t(0))->image();
|
||||||
EXPECT_EQ(0, sprite->transparentColor());
|
EXPECT_EQ(0, sprite->transparentColor());
|
||||||
|
|
||||||
EXPECT_EQ(1, image->getPixel(0, 0));
|
EXPECT_EQ(1, image->getPixel(0, 0));
|
||||||
|
@ -117,8 +117,8 @@ bool save_palette(const char *filename, Palette* pal)
|
|||||||
Sprite* sprite = doc->sprite();
|
Sprite* sprite = doc->sprite();
|
||||||
doc->sprite()->setPalette(pal, false);
|
doc->sprite()->setPalette(pal, false);
|
||||||
|
|
||||||
LayerImage* layer = dynamic_cast<LayerImage*>(sprite->folder()->getFirstLayer());
|
Layer* layer = sprite->folder()->getFirstLayer();
|
||||||
Image* image = layer->getCel(frame_t(0))->image();
|
Image* image = layer->cel(frame_t(0))->image();
|
||||||
|
|
||||||
int x, y, c;
|
int x, y, c;
|
||||||
for (y=c=0; y<16; y++)
|
for (y=c=0; y<16; y++)
|
||||||
|
@ -80,7 +80,7 @@ static bool has_cels(const Layer* layer, frame_t frame)
|
|||||||
switch (layer->type()) {
|
switch (layer->type()) {
|
||||||
|
|
||||||
case ObjectType::LayerImage:
|
case ObjectType::LayerImage:
|
||||||
return static_cast<const LayerImage*>(layer)->getCel(frame) ? true: false;
|
return (layer->cel(frame) ? true: false);
|
||||||
|
|
||||||
case ObjectType::LayerFolder: {
|
case ObjectType::LayerFolder: {
|
||||||
LayerConstIterator it = static_cast<const LayerFolder*>(layer)->getLayerBegin();
|
LayerConstIterator it = static_cast<const LayerFolder*>(layer)->getLayerBegin();
|
||||||
|
@ -50,7 +50,7 @@ MovingCelState::MovingCelState(Editor* editor, MouseMessage* msg)
|
|||||||
LayerImage* layer = static_cast<LayerImage*>(editor->layer());
|
LayerImage* layer = static_cast<LayerImage*>(editor->layer());
|
||||||
ASSERT(layer->isImage());
|
ASSERT(layer->isImage());
|
||||||
|
|
||||||
m_cel = layer->getCel(editor->frame());
|
m_cel = layer->cel(editor->frame());
|
||||||
if (m_cel) {
|
if (m_cel) {
|
||||||
m_celStart = m_cel->position();
|
m_celStart = m_cel->position();
|
||||||
}
|
}
|
||||||
|
@ -1787,7 +1787,7 @@ void Timeline::updateStatusBar(ui::Message* msg)
|
|||||||
|
|
||||||
case A_PART_CEL:
|
case A_PART_CEL:
|
||||||
if (layer) {
|
if (layer) {
|
||||||
Cel* cel = (layer->isImage() ? static_cast<LayerImage*>(layer)->getCel(m_hot_frame): NULL);
|
Cel* cel = (layer->isImage() ? layer->cel(m_hot_frame): NULL);
|
||||||
StatusBar::instance()->setStatusText(0,
|
StatusBar::instance()->setStatusText(0,
|
||||||
"%s at frame %d",
|
"%s at frame %d",
|
||||||
cel ? "Cel": "Empty cel",
|
cel ? "Cel": "Empty cel",
|
||||||
|
@ -320,7 +320,7 @@ void clipboard::paste()
|
|||||||
i >= srcRange.layerBegin() &&
|
i >= srcRange.layerBegin() &&
|
||||||
i >= LayerIndex(0) &&
|
i >= LayerIndex(0) &&
|
||||||
j >= LayerIndex(0); --i, --j) {
|
j >= LayerIndex(0); --i, --j) {
|
||||||
Cel* cel = static_cast<LayerImage*>(srcLayers[i])->getCel(frame);
|
Cel* cel = srcLayers[i]->cel(frame);
|
||||||
|
|
||||||
if (cel && cel->image()) {
|
if (cel && cel->image()) {
|
||||||
api.copyCel(
|
api.copyCel(
|
||||||
@ -328,7 +328,7 @@ void clipboard::paste()
|
|||||||
static_cast<LayerImage*>(dstLayers[j]), dstFrame);
|
static_cast<LayerImage*>(dstLayers[j]), dstFrame);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Cel* dstCel = static_cast<LayerImage*>(dstLayers[j])->getCel(dstFrame);
|
Cel* dstCel = dstLayers[j]->cel(dstFrame);
|
||||||
if (dstCel)
|
if (dstCel)
|
||||||
api.clearCel(dstCel);
|
api.clearCel(dstCel);
|
||||||
}
|
}
|
||||||
@ -354,7 +354,7 @@ void clipboard::paste()
|
|||||||
j = LayerIndex(dstLayers.size()-1);
|
j = LayerIndex(dstLayers.size()-1);
|
||||||
i >= LayerIndex(0) &&
|
i >= LayerIndex(0) &&
|
||||||
j >= LayerIndex(0); --i, --j) {
|
j >= LayerIndex(0); --i, --j) {
|
||||||
Cel* cel = static_cast<LayerImage*>(srcLayers[i])->getCel(frame);
|
Cel* cel = static_cast<LayerImage*>(srcLayers[i])->cel(frame);
|
||||||
if (cel && cel->image()) {
|
if (cel && cel->image()) {
|
||||||
api.copyCel(
|
api.copyCel(
|
||||||
static_cast<LayerImage*>(srcLayers[i]), frame,
|
static_cast<LayerImage*>(srcLayers[i]), frame,
|
||||||
|
@ -86,7 +86,7 @@ ExpandCelCanvas::ExpandCelCanvas(Context* context, TiledMode tiledMode, UndoTran
|
|||||||
m_layer = location.layer();
|
m_layer = location.layer();
|
||||||
|
|
||||||
if (m_layer->isImage()) {
|
if (m_layer->isImage()) {
|
||||||
m_cel = static_cast<LayerImage*>(m_layer)->getCel(location.frame());
|
m_cel = m_layer->cel(location.frame());
|
||||||
if (m_cel)
|
if (m_cel)
|
||||||
m_celImage = m_cel->image();
|
m_celImage = m_cel->image();
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ CelList get_cels_in_range(Sprite* sprite, const DocumentRange& range)
|
|||||||
begin = range.frameBegin()-1;
|
begin = range.frameBegin()-1;
|
||||||
frame != begin;
|
frame != begin;
|
||||||
--frame) {
|
--frame) {
|
||||||
Cel* cel = layerImage->getCel(frame);
|
Cel* cel = layerImage->cel(frame);
|
||||||
if (cel)
|
if (cel)
|
||||||
cels.push_back(cel);
|
cels.push_back(cel);
|
||||||
}
|
}
|
||||||
|
@ -43,14 +43,12 @@ void ImagesCollector::collectFromLayer(Layer* layer, frame_t frame)
|
|||||||
case ObjectType::LayerImage: {
|
case ObjectType::LayerImage: {
|
||||||
if (m_allFrames) {
|
if (m_allFrames) {
|
||||||
for (frame_t frame(0); frame<sprite->totalFrames(); ++frame) {
|
for (frame_t frame(0); frame<sprite->totalFrames(); ++frame) {
|
||||||
Cel* cel = static_cast<LayerImage*>(layer)->getCel(frame);
|
if (Cel* cel = layer->cel(frame))
|
||||||
if (cel != NULL)
|
|
||||||
collectImage(layer, cel);
|
collectImage(layer, cel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Cel* cel = static_cast<LayerImage*>(layer)->getCel(frame);
|
if (Cel* cel = layer->cel(frame))
|
||||||
if (cel != NULL)
|
|
||||||
collectImage(layer, cel);
|
collectImage(layer, cel);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -131,7 +131,16 @@ void LayerImage::destroyAllCels()
|
|||||||
|
|
||||||
Cel* LayerImage::cel(frame_t frame) const
|
Cel* LayerImage::cel(frame_t frame) const
|
||||||
{
|
{
|
||||||
return const_cast<Cel*>(getCel(frame_t(frame)));
|
CelConstIterator it = getCelBegin();
|
||||||
|
CelConstIterator end = getCelEnd();
|
||||||
|
|
||||||
|
for (; it != end; ++it) {
|
||||||
|
Cel* cel = *it;
|
||||||
|
if (cel->frame() == frame)
|
||||||
|
return cel;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayerImage::getCels(CelList& cels) const
|
void LayerImage::getCels(CelList& cels) const
|
||||||
@ -188,25 +197,6 @@ void LayerImage::moveCel(Cel* cel, frame_t frame)
|
|||||||
addCel(cel);
|
addCel(cel);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Cel* LayerImage::getCel(frame_t frame) const
|
|
||||||
{
|
|
||||||
CelConstIterator it = getCelBegin();
|
|
||||||
CelConstIterator end = getCelEnd();
|
|
||||||
|
|
||||||
for (; it != end; ++it) {
|
|
||||||
const Cel* cel = *it;
|
|
||||||
if (cel->frame() == frame)
|
|
||||||
return cel;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
Cel* LayerImage::getCel(frame_t frame)
|
|
||||||
{
|
|
||||||
return const_cast<Cel*>(static_cast<const LayerImage*>(this)->getCel(frame));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures some properties of the specified layer to make it as the
|
* Configures some properties of the specified layer to make it as the
|
||||||
* "Background" of the sprite.
|
* "Background" of the sprite.
|
||||||
|
@ -115,8 +115,6 @@ namespace doc {
|
|||||||
void addCel(Cel *cel);
|
void addCel(Cel *cel);
|
||||||
void removeCel(Cel *cel);
|
void removeCel(Cel *cel);
|
||||||
void moveCel(Cel *cel, frame_t frame);
|
void moveCel(Cel *cel, frame_t frame);
|
||||||
const Cel* getCel(frame_t frame) const;
|
|
||||||
Cel* getCel(frame_t frame);
|
|
||||||
Cel* cel(frame_t frame) const override;
|
Cel* cel(frame_t frame) const override;
|
||||||
void getCels(CelList& cels) const override;
|
void getCels(CelList& cels) const override;
|
||||||
Cel* getLastCel() const;
|
Cel* getLastCel() const;
|
||||||
|
@ -472,7 +472,7 @@ void Sprite::pickCels(int x, int y, frame_t frame, int opacityThreshold, CelList
|
|||||||
if (!layer->isImage() || !layer->isVisible())
|
if (!layer->isImage() || !layer->isVisible())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Cel* cel = static_cast<LayerImage*>(layer)->getCel(frame);
|
Cel* cel = layer->cel(frame);
|
||||||
if (!cel)
|
if (!cel)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -590,7 +590,7 @@ void Render::renderLayer(
|
|||||||
(!render_transparent && !layer->isBackground()))
|
(!render_transparent && !layer->isBackground()))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
const Cel* cel = static_cast<const LayerImage*>(layer)->getCel(frame);
|
const Cel* cel = layer->cel(frame);
|
||||||
if (cel != NULL) {
|
if (cel != NULL) {
|
||||||
Image* src_image;
|
Image* src_image;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user