[aseprite] 28/134: Fix bug moving cels between layers

Tobias Hansen thansen at moszumanska.debian.org
Sat Mar 14 17:09:58 UTC 2015


This is an automated email from the git hooks/post-receive script.

thansen pushed a commit to branch master
in repository aseprite.

commit 8ac9ebb64dfa67d1e17d7fa0ebdf0970419a1f4c
Author: David Capello <davidcapello at gmail.com>
Date:   Sat Nov 1 15:38:26 2014 -0300

    Fix bug moving cels between layers
    
    The image wasn't being copied correctly when the
    source cel's (x,y) was != (0,0)
---
 src/app/document_api.cpp       |  7 ++--
 src/app/document_api_tests.cpp | 72 ++++++++++++++++++++++++++++++++++++++++++
 src/app/test_context.h         |  2 ++
 3 files changed, 76 insertions(+), 5 deletions(-)

diff --git a/src/app/document_api.cpp b/src/app/document_api.cpp
index 183ae49..895c3e0 100644
--- a/src/app/document_api.cpp
+++ b/src/app/document_api.cpp
@@ -740,13 +740,10 @@ void DocumentApi::moveCel(
     // Move the cel between different layers.
     else {
       if (!dstCel) {
+        dstImage = Image::createCopy(srcImage);
+
         dstCel = new Cel(*srcCel);
         dstCel->setFrame(dstFrame);
-        dstImage = crop_image(srcImage,
-          -srcCel->x(),
-          -srcCel->y(),
-          dstSprite->width(),   // TODO dstSprite or srcSprite
-          dstSprite->height(), 0);
         dstCel->setImage(addImageInStock(dstSprite, dstImage));
       }
 
diff --git a/src/app/document_api_tests.cpp b/src/app/document_api_tests.cpp
new file mode 100644
index 0000000..7942ff3
--- /dev/null
+++ b/src/app/document_api_tests.cpp
@@ -0,0 +1,72 @@
+/* Aseprite
+ * Copyright (C) 2001-2014  David Capello
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "tests/test.h"
+
+#include "app/document_api.h"
+#include "app/test_context.h"
+#include "base/unique_ptr.h"
+#include "raster/cel.h"
+#include "raster/image.h"
+#include "raster/primitives.h"
+
+using namespace app;
+using namespace raster;
+
+typedef base::UniquePtr<Document> DocumentPtr;
+
+TEST(DocumentApi, MoveCel) {
+  TestContext ctx;
+  DocumentPtr doc(static_cast<Document*>(ctx.documents().add(32, 16)));
+  Sprite* sprite = doc->sprite();
+  LayerImage* layer1 = dynamic_cast<LayerImage*>(sprite->folder()->getFirstLayer());
+  LayerImage* layer2 = new LayerImage(sprite);
+
+  Cel* cel1 = layer1->getCel(FrameNumber(0));
+  cel1->setPosition(2, -2);
+  cel1->setOpacity(128);
+
+  Image* image1 = cel1->image();
+  EXPECT_EQ(32, image1->width());
+  EXPECT_EQ(16, image1->height());
+  for (int v=0; v<image1->height(); ++v)
+    for (int u=0; u<image1->width(); ++u)
+      image1->putPixel(u, v, u+v*image1->width());
+
+  // Create a copy for later comparison.
+  base::UniquePtr<Image> expectedImage(Image::createCopy(image1));
+
+  doc->getApi().moveCel(
+    layer1, FrameNumber(0),
+    layer2, FrameNumber(1));
+
+  EXPECT_EQ(NULL, layer1->getCel(FrameNumber(0)));
+
+  Cel* cel2 = layer2->getCel(FrameNumber(1));
+  ASSERT_TRUE(cel2 != NULL);
+
+  Image* image2 = cel2->image();
+  EXPECT_EQ(32, image2->width());
+  EXPECT_EQ(16, image2->height());
+  EXPECT_EQ(0, count_diff_between_images(expectedImage, image2));
+  EXPECT_EQ(2, cel2->x());
+  EXPECT_EQ(-2, cel2->y());
+  EXPECT_EQ(128, cel2->opacity());
+
+  doc->close();
+}
diff --git a/src/app/test_context.h b/src/app/test_context.h
index 471b40d..6427fd8 100644
--- a/src/app/test_context.h
+++ b/src/app/test_context.h
@@ -21,9 +21,11 @@
 #pragma once
 
 #include "app/context.h"
+#include "app/document.h"
 #include "app/document_location.h"
 #include "doc/settings.h"
 #include "raster/layer.h"
+#include "raster/sprite.h"
 
 namespace app {
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/aseprite.git



More information about the Pkg-games-commits mailing list