diff options
author | Max Horn | 2002-08-25 11:38:40 +0000 |
---|---|---|
committer | Max Horn | 2002-08-25 11:38:40 +0000 |
commit | a0c0880ec7098ac1e9afd3000f5dfd42d11fda97 (patch) | |
tree | 80b1060e1e1e0bf443ff4d6578288ee2a0e408df /scumm/smush | |
parent | d473d295c4513db29ddefeed321d5c4ee48b6195 (diff) | |
download | scummvm-rg350-a0c0880ec7098ac1e9afd3000f5dfd42d11fda97.tar.gz scummvm-rg350-a0c0880ec7098ac1e9afd3000f5dfd42d11fda97.tar.bz2 scummvm-rg350-a0c0880ec7098ac1e9afd3000f5dfd42d11fda97.zip |
more optimizations
svn-id: r4847
Diffstat (limited to 'scumm/smush')
-rw-r--r-- | scumm/smush/palette.cpp | 56 | ||||
-rw-r--r-- | scumm/smush/palette.h | 24 | ||||
-rw-r--r-- | scumm/smush/rect.cpp | 62 | ||||
-rw-r--r-- | scumm/smush/rect.h | 38 |
4 files changed, 38 insertions, 142 deletions
diff --git a/scumm/smush/palette.cpp b/scumm/smush/palette.cpp deleted file mode 100644 index 033c6b2563..0000000000 --- a/scumm/smush/palette.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* ScummVM - Scumm Interpreter - * Copyright (C) 2001/2002 The ScummVM project - * - * 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. - * - * $Header$ - * - */ - -#include <stdafx.h> -#include "palette.h" -#include "assert.h" - -Palette::Palette() { -} - -Palette::Palette(unsigned char * ptr) { - for(int i = 0; i < 256; i++) { - _colors[i] = Color(ptr[3 * i + 0], ptr[3 * i + 1], ptr[3 * i + 2]); - } -} - -Palette::Palette(const Palette & p) { - for(int i = 0; i < 256; i++) { - _colors[i] = p._colors[i]; - } -} - -const Color & Palette::operator[](int a) const { - assert(a >= 0 && a < 256); - return _colors[a]; -} - -Color & Palette::operator[](int a) { - assert(a >= 0 && a < 256); - return _colors[a]; -} - -Palette & Palette::operator=(const Palette & p) { - for(int i = 0; i < 256; i++) { - _colors[i] = p._colors[i]; - } - return *this; -} diff --git a/scumm/smush/palette.h b/scumm/smush/palette.h index 147e103324..6ffb08cf78 100644 --- a/scumm/smush/palette.h +++ b/scumm/smush/palette.h @@ -34,12 +34,24 @@ class Palette { private: Color _colors[256]; public: - Palette(); - Palette(unsigned char *); - Palette(const Palette &); - const Color & operator[](int) const; - Color & operator[](int); - Palette & operator=(const Palette &); + Palette() {} + Palette(unsigned char *ptr) + { + for(int i = 0; i < 256; i++) { + _colors[i] = Color(ptr[3 * i + 0], ptr[3 * i + 1], ptr[3 * i + 2]); + } + + } + const Color & operator[](int a) const + { + assert(a >= 0 && a < 256); + return _colors[a]; + } + Color & operator[](int a) + { + assert(a >= 0 && a < 256); + return _colors[a]; + } }; #endif diff --git a/scumm/smush/rect.cpp b/scumm/smush/rect.cpp deleted file mode 100644 index deb1d5b35f..0000000000 --- a/scumm/smush/rect.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* ScummVM - Scumm Interpreter - * Copyright (C) 2001/2002 The ScummVM project - * - * 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. - * - * $Header$ - * - */ - -#include <stdafx.h> -#include "rect.h" - -Rect::Rect() : _topLeft(0, 0), _bottomRight(0,0) { -} - -Rect::Rect(int x, int y) : _topLeft(0, 0), _bottomRight(x, y) { - check(); -} - -Rect::Rect(int x1, int y1, int x2, int y2) : _topLeft(x1, y1), _bottomRight(x2, y2) { - check(); -} - -Rect::Rect(const Rect & r) : _topLeft(r._topLeft), _bottomRight(r._bottomRight) { -} - -Rect & Rect::operator=(const Rect & r) { - _topLeft = r._topLeft; - _bottomRight = r._bottomRight; - return *this; -} - -bool Rect::operator==(const Rect & r) const { - return _topLeft == r._topLeft && _bottomRight == r._bottomRight; -} - -void Rect::check() { - if ((_topLeft.getX() < 0) || (_bottomRight.getX() < _topLeft.getX()) || (_topLeft.getY() < 0) || (_bottomRight.getY() < _topLeft.getY())) { - error("Invalid rect"); - } -} - -bool Rect::isInside(int x, int y) const { - return _topLeft.getX() >= x && _bottomRight.getX() < x && _topLeft.getY() >= y && _bottomRight.getY() < y; -} - -bool Rect::isInside(const Point & p) const { - return (left() <= p.getX()) && (right() > p.getX()) && (top() <= p.getY()) && (bottom() > p.getY()); -} - diff --git a/scumm/smush/rect.h b/scumm/smush/rect.h index 1a7801ce65..e02d6858be 100644 --- a/scumm/smush/rect.h +++ b/scumm/smush/rect.h @@ -29,6 +29,7 @@ This small class is an helper for position and size values. */ class Point { + friend class Rect; private: int _x; //!< The horizontal part of the point int _y; //!< The vertical part of the point @@ -59,24 +60,17 @@ class Rect { private: Point _topLeft; //!< The point at the top left of the rectangle Point _bottomRight; //!< The point at the bottom right of the rectangle -protected: - void check(); public: - Rect(); - Rect(int x, int y); - explicit Rect(const Point & size); - Rect(int x1, int y1, int x2, int y2); - Rect(const Point & topleft, const Point & bottomright); - Rect(const Rect & r); - Rect & operator=(const Rect & r); - bool operator==(const Rect & r) const; + Rect() : _topLeft(0, 0), _bottomRight(0,0) {} + Rect(int x, int y) : _topLeft(0, 0), _bottomRight(x, y) {} + Rect(int x1, int y1, int x2, int y2) : _topLeft(x1, y1), _bottomRight(x2, y2) {} Point size() const { return (_bottomRight - _topLeft); }; - int width() const { return size().getX(); } - int height() const { return size().getY(); } - int left() const { return _topLeft.getX(); } - int right() const { return _bottomRight.getX(); } - int top() const { return _topLeft.getY(); } - int bottom() const { return _bottomRight.getY(); } + int width() const { return size()._x; } + int height() const { return size()._y; } + int left() const { return _topLeft._x; } + int right() const { return _bottomRight._x; } + int top() const { return _topLeft._y; } + int bottom() const { return _bottomRight._y; } const Point & topLeft() const { return _topLeft; } const Point & bottomRight() const { return _bottomRight; } @@ -87,14 +81,22 @@ public: @return true if the given position is inside the rectangle, false otherwise */ - bool isInside(int x, int y) const; + bool isInside(int x, int y) const + { + return (_topLeft._x <= x) && (_bottomRight._x > x) && (_topLeft._y <= y) && (_bottomRight._y > y); + } /*! @brief check if given point is inside the rectangle @param p the point to check @return true if the given point is inside the rectangle, false otherwise */ - bool isInside(const Point & p) const; + bool isInside(const Point & p) const + { + return (_topLeft._x <= p._x) && (_bottomRight._x > p._x) && (_topLeft._y <= p._y) && (_bottomRight._y > p._y); + } + + bool clip(Rect & r) const; }; |