min and max changed to vncmin and vncmax. This solves many problems: Some platforms predefines or redefines these symbols. Some platforms have header files which chokes if min or max are defined.
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@96 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/rfb/ComparingUpdateTracker.cxx b/rfb/ComparingUpdateTracker.cxx
index 0c44d85..0b548a6 100644
--- a/rfb/ComparingUpdateTracker.cxx
+++ b/rfb/ComparingUpdateTracker.cxx
@@ -60,7 +60,7 @@
// since in effect the entire framebuffer has changed.
oldFb.setSize(fb->width(), fb->height());
for (int y=0; y<fb->height(); y+=BLOCK_SIZE) {
- Rect pos(0, y, fb->width(), min(fb->height(), y+BLOCK_SIZE));
+ Rect pos(0, y, fb->width(), vncmin(fb->height(), y+BLOCK_SIZE));
int srcStride;
const rdr::U8* srcData = fb->getPixelsR(pos, &srcStride);
oldFb.imageRect(pos, srcData, srcStride);
@@ -100,20 +100,20 @@
for (int blockTop = r.tl.y; blockTop < r.br.y; blockTop += BLOCK_SIZE)
{
// Get a strip of the source buffer
- Rect pos(r.tl.x, blockTop, r.br.x, min(r.br.y, blockTop+BLOCK_SIZE));
+ Rect pos(r.tl.x, blockTop, r.br.x, vncmin(r.br.y, blockTop+BLOCK_SIZE));
int fbStride;
const rdr::U8* newBlockPtr = fb->getPixelsR(pos, &fbStride);
int newStrideBytes = fbStride * bytesPerPixel;
rdr::U8* oldBlockPtr = oldData;
- int blockBottom = min(blockTop+BLOCK_SIZE, r.br.y);
+ int blockBottom = vncmin(blockTop+BLOCK_SIZE, r.br.y);
for (int blockLeft = r.tl.x; blockLeft < r.br.x; blockLeft += BLOCK_SIZE)
{
const rdr::U8* newPtr = newBlockPtr;
rdr::U8* oldPtr = oldBlockPtr;
- int blockRight = min(blockLeft+BLOCK_SIZE, r.br.x);
+ int blockRight = vncmin(blockLeft+BLOCK_SIZE, r.br.x);
int blockWidthInBytes = (blockRight-blockLeft) * bytesPerPixel;
for (int y = blockTop; y < blockBottom; y++)
diff --git a/rfb/Rect.h b/rfb/Rect.h
index ee43e66..0ddf36c 100644
--- a/rfb/Rect.h
+++ b/rfb/Rect.h
@@ -21,13 +21,7 @@
#ifndef __RFB_RECT_INCLUDED__
#define __RFB_RECT_INCLUDED__
-#ifndef max
-#define max(a,b) (((a) > (b)) ? (a) : (b))
-#endif
-
-#ifndef min
-#define min(a,b) (((a) < (b)) ? (a) : (b))
-#endif
+#include <rfb/util.h>
namespace rfb {
@@ -70,20 +64,20 @@
}
inline Rect intersect(const Rect &r) const {
Rect result;
- result.tl.x = max(tl.x, r.tl.x);
- result.tl.y = max(tl.y, r.tl.y);
- result.br.x = max(min(br.x, r.br.x), result.tl.x);
- result.br.y = max(min(br.y, r.br.y), result.tl.y);
+ result.tl.x = vncmax(tl.x, r.tl.x);
+ result.tl.y = vncmax(tl.y, r.tl.y);
+ result.br.x = vncmax(vncmin(br.x, r.br.x), result.tl.x);
+ result.br.y = vncmax(vncmin(br.y, r.br.y), result.tl.y);
return result;
}
inline Rect union_boundary(const Rect &r) const {
if (r.is_empty()) return *this;
if (is_empty()) return r;
Rect result;
- result.tl.x = min(tl.x, r.tl.x);
- result.tl.y = min(tl.y, r.tl.y);
- result.br.x = max(br.x, r.br.x);
- result.br.y = max(br.y, r.br.y);
+ result.tl.x = vncmin(tl.x, r.tl.x);
+ result.tl.y = vncmin(tl.y, r.tl.y);
+ result.br.x = vncmax(br.x, r.br.x);
+ result.br.y = vncmax(br.y, r.br.y);
return result;
}
inline Rect translate(const Point &p) const {
diff --git a/rfb/hextileDecode.h b/rfb/hextileDecode.h
index dc685e3..0c5559a 100644
--- a/rfb/hextileDecode.h
+++ b/rfb/hextileDecode.h
@@ -52,11 +52,11 @@
for (t.tl.y = r.tl.y; t.tl.y < r.br.y; t.tl.y += 16) {
- t.br.y = min(r.br.y, t.tl.y + 16);
+ t.br.y = vncmin(r.br.y, t.tl.y + 16);
for (t.tl.x = r.tl.x; t.tl.x < r.br.x; t.tl.x += 16) {
- t.br.x = min(r.br.x, t.tl.x + 16);
+ t.br.x = vncmin(r.br.x, t.tl.x + 16);
int tileType = is->readU8();
diff --git a/rfb/hextileEncode.h b/rfb/hextileEncode.h
index a55842a..15c8862 100644
--- a/rfb/hextileEncode.h
+++ b/rfb/hextileEncode.h
@@ -60,11 +60,11 @@
for (t.tl.y = r.tl.y; t.tl.y < r.br.y; t.tl.y += 16) {
- t.br.y = min(r.br.y, t.tl.y + 16);
+ t.br.y = vncmin(r.br.y, t.tl.y + 16);
for (t.tl.x = r.tl.x; t.tl.x < r.br.x; t.tl.x += 16) {
- t.br.x = min(r.br.x, t.tl.x + 16);
+ t.br.x = vncmin(r.br.x, t.tl.x + 16);
GET_IMAGE_INTO_BUF(t,buf);
diff --git a/rfb/util.h b/rfb/util.h
index d792c8d..b654170 100644
--- a/rfb/util.h
+++ b/rfb/util.h
@@ -23,6 +23,13 @@
#ifndef __RFB_UTIL_H__
#define __RFB_UTIL_H__
+#ifndef vncmin
+#define vncmin(a,b) (((a) < (b)) ? (a) : (b))
+#endif
+#ifndef vncmax
+#define vncmax(a,b) (((a) > (b)) ? (a) : (b))
+#endif
+
#include <string.h>
namespace rfb {
@@ -67,21 +74,6 @@
}
#endif
-// Some platforms (e.g. Windows) include max() and min() macros in their
-// standard headers, so we define them only when not already defined. Note
-// also that max() & min() are standard C++ template functions, so some C++
-// headers will undefine them. We place our definitions outside the #ifndef
-// __RFB_UTIL_H__, so that you can always guarantee they will be defined if
-// this file is the last #include before you use them.
-
-#ifndef max
-#define max(a,b) (((a) > (b)) ? (a) : (b))
-#endif
-
-#ifndef min
-#define min(a,b) (((a) < (b)) ? (a) : (b))
-#endif
-
// -=- PLATFORM SPECIFIC UTILITY FUNCTIONS/IMPLEMENTATIONS
#ifdef WIN32
diff --git a/rfb/zrleDecode.h b/rfb/zrleDecode.h
index b5391b1..e1f85f7 100644
--- a/rfb/zrleDecode.h
+++ b/rfb/zrleDecode.h
@@ -61,11 +61,11 @@
for (t.tl.y = r.tl.y; t.tl.y < r.br.y; t.tl.y += 64) {
- t.br.y = min(r.br.y, t.tl.y + 64);
+ t.br.y = vncmin(r.br.y, t.tl.y + 64);
for (t.tl.x = r.tl.x; t.tl.x < r.br.x; t.tl.x += 64) {
- t.br.x = min(r.br.x, t.tl.x + 64);
+ t.br.x = vncmin(r.br.x, t.tl.x + 64);
int mode = zis->readU8();
bool rle = mode & 128;
diff --git a/rfb/zrleEncode.h b/rfb/zrleEncode.h
index a1582f2..42505a3 100644
--- a/rfb/zrleEncode.h
+++ b/rfb/zrleEncode.h
@@ -130,7 +130,7 @@
for (t.tl.y = r.tl.y; t.tl.y < r.br.y; t.tl.y += 64) {
- t.br.y = min(r.br.y, t.tl.y + 64);
+ t.br.y = vncmin(r.br.y, t.tl.y + 64);
if (os->length() + worstCaseLine > maxLen) {
if (t.tl.y == r.tl.y)
@@ -143,7 +143,7 @@
for (t.tl.x = r.tl.x; t.tl.x < r.br.x; t.tl.x += 64) {
- t.br.x = min(r.br.x, t.tl.x + 64);
+ t.br.x = vncmin(r.br.x, t.tl.x + 64);
GET_IMAGE_INTO_BUF(t,buf);