diff --git a/src/app/commands/cmd_flip.cpp b/src/app/commands/cmd_flip.cpp index ac136bfda..bcaba4cef 100644 --- a/src/app/commands/cmd_flip.cpp +++ b/src/app/commands/cmd_flip.cpp @@ -96,22 +96,20 @@ void FlipCommand::onExecute(Context* context) // whole image. if (document->isMaskVisible()) { mask = document->getMask(); - gfx::Rect maskBounds = mask->getBounds(); - - // Adjust the mask depending on the cel position. - maskBounds.offset(-x, -y); // Intersect the full area of the image with the mask's // bounds, so we don't request to flip an area outside the // image's bounds. - bounds = bounds.createIntersect(maskBounds); + bounds = bounds.createIntersect(gfx::Rect(mask->getBounds()).offset(-x, -y)); // If the mask isn't a rectangular area, we've to flip the mask too. if (mask->getBitmap() != NULL && !mask->isRectangular()) { int bgcolor = app_get_color_to_clear_layer(writer.layer()); // Flip the portion of image specified by the mask. + mask->offsetOrigin(-x, -y); api.flipImageWithMask(image, mask, m_flipType, bgcolor); + mask->offsetOrigin(x, y); alreadyFlipped = true; // Flip the mask. @@ -121,8 +119,7 @@ void FlipCommand::onExecute(Context* context) base::UniquePtr newMask(new Mask(*mask)); newMask->freeze(); raster::algorithm::flip_image(newMask->getBitmap(), - maskBitmap->getBounds(), - m_flipType); + maskBitmap->getBounds(), m_flipType); newMask->unfreeze(); // Change the current mask and generate the new boundaries. diff --git a/src/app/document_api.cpp b/src/app/document_api.cpp index aff94454c..e9e045ef6 100644 --- a/src/app/document_api.cpp +++ b/src/app/document_api.cpp @@ -990,9 +990,8 @@ void DocumentApi::clearMask(Layer* layer, Cel* cel, int bgcolor) } } -void DocumentApi::flipImage(Image* image, - const gfx::Rect& bounds, - raster::algorithm::FlipType flipType) +void DocumentApi::flipImage(Image* image, const gfx::Rect& bounds, + raster::algorithm::FlipType flipType) { // Insert the undo operation. if (undoEnabled()) { diff --git a/src/raster/algorithm/flip_image.cpp b/src/raster/algorithm/flip_image.cpp index 0256072b5..8bfe0b8aa 100644 --- a/src/raster/algorithm/flip_image.cpp +++ b/src/raster/algorithm/flip_image.cpp @@ -50,18 +50,14 @@ void flip_image(Image* image, const gfx::Rect& bounds, FlipType flipType) break; case FlipVertical: { - int section_size = image->getRowStrideSize(bounds.w); - std::vector tmpline(section_size); - int v = bounds.y+bounds.h-1; for (int y=bounds.y; ygetPixelAddress(bounds.x, y); - uint8_t* address2 = image->getPixelAddress(bounds.x, v); - - // Swap lines. - std::copy(address1, address1+section_size, tmpline.begin()); - std::copy(address2, address2+section_size, address1); - std::copy(tmpline.begin(), tmpline.end(), address2); + for (int x=bounds.x; x originalRow(Image::create(image->getPixelFormat(), mask->getBounds().w, 1)); + base::UniquePtr originalRow(Image::create(image->getPixelFormat(), bounds.w, 1)); for (int y=bounds.y; y originalCol(Image::create(image->getPixelFormat(), 1, mask->getBounds().h)); + case FlipVertical: { + base::UniquePtr originalCol(Image::create(image->getPixelFormat(), 1, bounds.h)); for (int x=bounds.x; x