Fix crash using negative numbers in Deskpeckle filter

This commit is contained in:
David Capello 2017-10-03 12:14:14 -03:00
parent 3af0983022
commit aa93666481
2 changed files with 17 additions and 8 deletions

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2015 David Capello
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
@ -60,8 +60,14 @@ public:
private:
void onSizeChange()
{
m_filter.setSize(m_widthEntry->textInt(),
m_heightEntry->textInt());
gfx::Size newSize(m_widthEntry->textInt(),
m_heightEntry->textInt());
// Avoid negative numbers
newSize.w = MAX(1, newSize.w);
newSize.h = MAX(1, newSize.h);
m_filter.setSize(newSize.w, newSize.h);
restartPreview();
}

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2015 David Capello
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
@ -90,8 +90,8 @@ namespace {
MedianFilter::MedianFilter()
: m_tiledMode(TiledMode::NONE)
, m_width(0)
, m_height(0)
, m_width(1)
, m_height(1)
, m_ncolors(0)
, m_channel(4)
{
@ -104,8 +104,11 @@ void MedianFilter::setTiledMode(TiledMode tiled)
void MedianFilter::setSize(int width, int height)
{
m_width = width;
m_height = height;
ASSERT(width >= 1);
ASSERT(height >= 1);
m_width = MAX(1, width);
m_height = MAX(1, height);
m_ncolors = width*height;
for (int c = 0; c < 4; ++c)