mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-25 06:39:58 +00:00
Change Mask member functions to use gfx::Rect instead of x,y,w,h args
This commit is contained in:
parent
9f0d460624
commit
f66b48c698
@ -82,13 +82,11 @@ void InvertMaskCommand::onExecute(Context* context)
|
||||
if (undo.isEnabled())
|
||||
undo.pushUndoer(new undoers::SetMask(undo.getObjects(), document));
|
||||
|
||||
/* create a new mask */
|
||||
// Select all the sprite area
|
||||
base::UniquePtr<Mask> mask(new Mask());
|
||||
mask->replace(sprite->bounds());
|
||||
|
||||
/* select all the sprite area */
|
||||
mask->replace(0, 0, sprite->width(), sprite->height());
|
||||
|
||||
/* remove in the new mask the current sprite marked region */
|
||||
// Remove in the new mask the current sprite marked region
|
||||
const gfx::Rect& maskBounds = document->mask()->bounds();
|
||||
doc::fill_rect(mask->bitmap(),
|
||||
maskBounds.x, maskBounds.y,
|
||||
|
@ -65,7 +65,7 @@ void MaskAllCommand::onExecute(Context* context)
|
||||
undo.pushUndoer(new undoers::SetMask(undo.getObjects(), document));
|
||||
|
||||
// Change the selection
|
||||
document->mask()->replace(0, 0, sprite->width(), sprite->height());
|
||||
document->mask()->replace(sprite->bounds());
|
||||
document->setMaskVisible(true);
|
||||
document->resetTransformation();
|
||||
|
||||
|
@ -155,9 +155,10 @@ protected:
|
||||
}
|
||||
|
||||
// create the new rotated mask
|
||||
new_mask->replace(x, y,
|
||||
new_mask->replace(
|
||||
gfx::Rect(x, y,
|
||||
m_angle == 180 ? origBounds.w: origBounds.h,
|
||||
m_angle == 180 ? origBounds.h: origBounds.w);
|
||||
m_angle == 180 ? origBounds.h: origBounds.w));
|
||||
doc::rotate_image(origMask->bitmap(), new_mask->bitmap(), m_angle);
|
||||
|
||||
// Copy new mask
|
||||
|
@ -132,8 +132,10 @@ protected:
|
||||
int w = scale_x(old_bitmap->width());
|
||||
int h = scale_y(old_bitmap->height());
|
||||
base::UniquePtr<Mask> new_mask(new Mask);
|
||||
new_mask->replace(scale_x(m_document->mask()->bounds().x-1),
|
||||
scale_y(m_document->mask()->bounds().y-1), MAX(1, w), MAX(1, h));
|
||||
new_mask->replace(
|
||||
gfx::Rect(
|
||||
scale_x(m_document->mask()->bounds().x-1),
|
||||
scale_y(m_document->mask()->bounds().y-1), MAX(1, w), MAX(1, h)));
|
||||
algorithm::resize_image(old_bitmap, new_mask->bitmap(),
|
||||
m_resize_method,
|
||||
m_sprite->getPalette(FrameNumber(0)), // Ignored
|
||||
|
@ -116,9 +116,10 @@ void FilterManagerImpl::beginForPreview()
|
||||
m_preview_mask.reset(new Mask(*document->mask()));
|
||||
else {
|
||||
m_preview_mask.reset(new Mask());
|
||||
m_preview_mask->replace(m_offset_x, m_offset_y,
|
||||
m_preview_mask->replace(
|
||||
gfx::Rect(m_offset_x, m_offset_y,
|
||||
m_src->width(),
|
||||
m_src->height());
|
||||
m_src->height()));
|
||||
}
|
||||
|
||||
m_row = 0;
|
||||
|
@ -1218,7 +1218,7 @@ static Mask* ase_file_read_mask_chunk(FILE* f)
|
||||
|
||||
mask = new Mask();
|
||||
mask->setName(name.c_str());
|
||||
mask->replace(x, y, w, h);
|
||||
mask->replace(gfx::Rect(x, y, w, h));
|
||||
|
||||
// Read image data
|
||||
for (v=0; v<h; v++)
|
||||
|
@ -288,10 +288,12 @@ public:
|
||||
switch (loop->getSelectionMode()) {
|
||||
case kDefaultSelectionMode:
|
||||
case kAddSelectionMode:
|
||||
loop->getMask()->add(x1-offset.x, y-offset.y, x2-x1+1, 1);
|
||||
loop->getMask()->add(
|
||||
gfx::Rect(x1-offset.x, y-offset.y, x2-x1+1, 1));
|
||||
break;
|
||||
case kSubtractSelectionMode:
|
||||
loop->getMask()->subtract(x1-offset.x, y-offset.y, x2-x1+1, 1);
|
||||
loop->getMask()->subtract(
|
||||
gfx::Rect(x1-offset.x, y-offset.y, x2-x1+1, 1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -312,7 +314,7 @@ public:
|
||||
undo->pushUndoer(new undoers::SetMask(undo->getObjects(), loop->getDocument()));
|
||||
|
||||
loop->getMask()->freeze();
|
||||
loop->getMask()->reserve(0, 0, loop->sprite()->width(), loop->sprite()->height());
|
||||
loop->getMask()->reserve(loop->sprite()->bounds());
|
||||
}
|
||||
else {
|
||||
loop->getMask()->unfreeze();
|
||||
|
@ -588,7 +588,7 @@ void PixelsMovement::redrawCurrentMask()
|
||||
|
||||
// Transform mask
|
||||
|
||||
m_currentMask->replace(0, 0, m_sprite->width(), m_sprite->height());
|
||||
m_currentMask->replace(m_sprite->bounds());
|
||||
m_currentMask->freeze();
|
||||
clear_image(m_currentMask->bitmap(), 0);
|
||||
drawParallelogram(m_currentMask->bitmap(), m_initialMask->bitmap(),
|
||||
|
@ -60,7 +60,7 @@ Mask* load_msk_file(const char* filename)
|
||||
// Animator MSK format
|
||||
else if (orig_size == 8000) {
|
||||
mask = new Mask();
|
||||
mask->replace(0, 0, 320, 200);
|
||||
mask->replace(gfx::Rect(0, 0, 320, 200));
|
||||
|
||||
u = v = 0;
|
||||
for (i=0; i<8000; i++) {
|
||||
|
122
src/doc/mask.cpp
122
src/doc/mask.cpp
@ -136,69 +136,36 @@ void Mask::invert()
|
||||
}
|
||||
}
|
||||
|
||||
void Mask::replace(int x, int y, int w, int h)
|
||||
void Mask::replace(const gfx::Rect& bounds)
|
||||
{
|
||||
m_bounds = gfx::Rect(x, y, w, h);
|
||||
m_bounds = bounds;
|
||||
|
||||
delete m_bitmap;
|
||||
m_bitmap = Image::create(IMAGE_BITMAP, w, h);
|
||||
m_bitmap = Image::create(IMAGE_BITMAP, bounds.w, bounds.h);
|
||||
|
||||
clear_image(m_bitmap, 1);
|
||||
}
|
||||
|
||||
void Mask::replace(const gfx::Rect& bounds)
|
||||
{
|
||||
replace(bounds.x, bounds.y, bounds.w, bounds.h);
|
||||
}
|
||||
|
||||
void Mask::add(int x, int y, int w, int h)
|
||||
{
|
||||
if (m_freeze_count == 0)
|
||||
reserve(x, y, w, h);
|
||||
|
||||
fill_rect(m_bitmap,
|
||||
x-m_bounds.x, y-m_bounds.y,
|
||||
x-m_bounds.x+w-1, y-m_bounds.y+h-1, 1);
|
||||
}
|
||||
|
||||
void Mask::add(const gfx::Rect& bounds)
|
||||
{
|
||||
add(bounds.x, bounds.y, bounds.w, bounds.h);
|
||||
}
|
||||
if (m_freeze_count == 0)
|
||||
reserve(bounds);
|
||||
|
||||
void Mask::subtract(int x, int y, int w, int h)
|
||||
{
|
||||
if (m_bitmap) {
|
||||
fill_rect(m_bitmap,
|
||||
x-m_bounds.x,
|
||||
y-m_bounds.y,
|
||||
x-m_bounds.x+w-1,
|
||||
y-m_bounds.y+h-1, 0);
|
||||
shrink();
|
||||
}
|
||||
bounds.x-m_bounds.x,
|
||||
bounds.y-m_bounds.y,
|
||||
bounds.x-m_bounds.x+bounds.w-1,
|
||||
bounds.y-m_bounds.y+bounds.h-1, 1);
|
||||
}
|
||||
|
||||
void Mask::subtract(const gfx::Rect& bounds)
|
||||
{
|
||||
subtract(bounds.x, bounds.y, bounds.w, bounds.h);
|
||||
}
|
||||
|
||||
void Mask::intersect(int x, int y, int w, int h)
|
||||
{
|
||||
if (m_bitmap) {
|
||||
int x1 = m_bounds.x;
|
||||
int y1 = m_bounds.y;
|
||||
int x2 = MIN(m_bounds.x+m_bounds.w-1, x+w-1);
|
||||
int y2 = MIN(m_bounds.y+m_bounds.h-1, y+h-1);
|
||||
|
||||
m_bounds.x = MAX(x, x1);
|
||||
m_bounds.y = MAX(y, y1);
|
||||
m_bounds.w = x2 - m_bounds.x + 1;
|
||||
m_bounds.h = y2 - m_bounds.y + 1;
|
||||
|
||||
Image* image = crop_image(m_bitmap, m_bounds.x-x1, m_bounds.y-y1, m_bounds.w, m_bounds.h, 0);
|
||||
delete m_bitmap;
|
||||
m_bitmap = image;
|
||||
fill_rect(m_bitmap,
|
||||
bounds.x-m_bounds.x,
|
||||
bounds.y-m_bounds.y,
|
||||
bounds.x-m_bounds.x+bounds.w-1,
|
||||
bounds.y-m_bounds.y+bounds.h-1, 0);
|
||||
|
||||
shrink();
|
||||
}
|
||||
@ -206,12 +173,30 @@ void Mask::intersect(int x, int y, int w, int h)
|
||||
|
||||
void Mask::intersect(const gfx::Rect& bounds)
|
||||
{
|
||||
intersect(bounds.x, bounds.y, bounds.w, bounds.h);
|
||||
if (m_bitmap) {
|
||||
gfx::Rect newBounds = m_bounds.createIntersect(bounds);
|
||||
|
||||
Image* image = NULL;
|
||||
|
||||
if (!newBounds.isEmpty()) {
|
||||
image = crop_image(m_bitmap,
|
||||
newBounds.x-m_bounds.x,
|
||||
newBounds.y-m_bounds.y,
|
||||
newBounds.w,
|
||||
newBounds.h, 0);
|
||||
}
|
||||
|
||||
delete m_bitmap;
|
||||
m_bitmap = image;
|
||||
m_bounds = newBounds;
|
||||
|
||||
shrink();
|
||||
}
|
||||
}
|
||||
|
||||
void Mask::byColor(const Image *src, int color, int fuzziness)
|
||||
{
|
||||
replace(0, 0, src->width(), src->height());
|
||||
replace(src->bounds());
|
||||
|
||||
Image* dst = m_bitmap;
|
||||
|
||||
@ -371,47 +356,34 @@ void Mask::crop(const Image *image)
|
||||
get_pixel(image, c, y2));
|
||||
|
||||
if (done_count < 4)
|
||||
intersect(x1, y1, x2-x1+1, y2-y1+1);
|
||||
intersect(gfx::Rect(x1, y1, x2-x1+1, y2-y1+1));
|
||||
else
|
||||
clear();
|
||||
|
||||
#undef ADVANCE
|
||||
}
|
||||
|
||||
void Mask::reserve(int x, int y, int w, int h)
|
||||
void Mask::reserve(const gfx::Rect& bounds)
|
||||
{
|
||||
ASSERT(w > 0 && h > 0);
|
||||
ASSERT(!bounds.isEmpty());
|
||||
|
||||
if (!m_bitmap) {
|
||||
m_bounds.x = x;
|
||||
m_bounds.y = y;
|
||||
m_bounds.w = w;
|
||||
m_bounds.h = h;
|
||||
m_bitmap = Image::create(IMAGE_BITMAP, w, h);
|
||||
m_bounds = bounds;
|
||||
m_bitmap = Image::create(IMAGE_BITMAP, bounds.w, bounds.h);
|
||||
clear_image(m_bitmap, 0);
|
||||
}
|
||||
else {
|
||||
int x1 = m_bounds.x;
|
||||
int y1 = m_bounds.y;
|
||||
int x2 = MAX(m_bounds.x+m_bounds.w-1, x+w-1);
|
||||
int y2 = MAX(m_bounds.y+m_bounds.h-1, y+h-1);
|
||||
int new_mask_x = MIN(x, x1);
|
||||
int new_mask_y = MIN(y, y1);
|
||||
int new_mask_w = x2 - new_mask_x + 1;
|
||||
int new_mask_h = y2 - new_mask_y + 1;
|
||||
gfx::Rect newBounds = m_bounds.createUnion(bounds);
|
||||
|
||||
if (m_bounds.x != new_mask_x ||
|
||||
m_bounds.y != new_mask_y ||
|
||||
m_bounds.w != new_mask_w ||
|
||||
m_bounds.h != new_mask_h) {
|
||||
m_bounds.x = new_mask_x;
|
||||
m_bounds.y = new_mask_y;
|
||||
m_bounds.w = new_mask_w;
|
||||
m_bounds.h = new_mask_h;
|
||||
|
||||
Image* image = crop_image(m_bitmap, m_bounds.x-x1, m_bounds.y-y1, m_bounds.w, m_bounds.h, 0);
|
||||
if (m_bounds != newBounds) {
|
||||
Image* image = crop_image(m_bitmap,
|
||||
newBounds.x-m_bounds.x,
|
||||
newBounds.y-m_bounds.y,
|
||||
newBounds.w,
|
||||
newBounds.h, 0);
|
||||
delete m_bitmap; // image
|
||||
m_bitmap = image;
|
||||
m_bounds = newBounds;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -73,26 +73,21 @@ namespace doc {
|
||||
void copyFrom(const Mask* sourceMask);
|
||||
|
||||
// Replace the whole mask with the given region.
|
||||
void replace(int x, int y, int w, int h);
|
||||
void replace(const gfx::Rect& bounds);
|
||||
|
||||
// Inverts the mask.
|
||||
void invert();
|
||||
|
||||
// Adds the specified rectangle in the mask/selection
|
||||
void add(int x, int y, int w, int h);
|
||||
void add(const gfx::Rect& bounds);
|
||||
|
||||
void subtract(int x, int y, int w, int h);
|
||||
void subtract(const gfx::Rect& bounds);
|
||||
void intersect(int x, int y, int w, int h);
|
||||
void intersect(const gfx::Rect& bounds);
|
||||
void byColor(const Image* image, int color, int fuzziness);
|
||||
void crop(const Image* image);
|
||||
|
||||
// Reserves a rectangle to draw onto the bitmap (you should call
|
||||
// shrink after you draw in the bitmap)
|
||||
void reserve(int x, int y, int w, int h);
|
||||
void reserve(const gfx::Rect& bounds);
|
||||
|
||||
// Shrinks all sides of the mask to the minimum possible looking at
|
||||
// empty pixels in the bitmap
|
||||
|
@ -58,7 +58,7 @@ Mask* read_mask(std::istream& is)
|
||||
if (w > 0 && h > 0) {
|
||||
int size = BitmapTraits::getRowStrideBytes(w);
|
||||
|
||||
mask->add(x, y, w, h);
|
||||
mask->add(gfx::Rect(x, y, w, h));
|
||||
for (int c=0; c<mask->bounds().h; c++)
|
||||
is.read((char*)mask->bitmap()->getPixelAddress(0, c), size);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user