]> source.dussan.org Git - tigervnc.git/commitdiff
min and max changed to vncmin and vncmax. This solves many problems: Some platforms...
authorPeter Åstrand <astrand@cendio.se>
Thu, 13 Jan 2005 22:11:30 +0000 (22:11 +0000)
committerPeter Åstrand <astrand@cendio.se>
Thu, 13 Jan 2005 22:11:30 +0000 (22:11 +0000)
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@96 3789f03b-4d11-0410-bbf8-ca57d06f2519

15 files changed:
Xregion/Region.c
Xregion/Xregion.h
rdr/FdInStream.cxx
rfb/ComparingUpdateTracker.cxx
rfb/Rect.h
rfb/hextileDecode.h
rfb/hextileEncode.h
rfb/util.h
rfb/zrleDecode.h
rfb/zrleEncode.h
tx/TXButton.h
tx/TXCheckbox.h
tx/TXEntry.h
tx/TXImage.cxx
tx/TXLabel.h

index bf2d123b2b24c7d073958bb5d689772714fcca62..c0b1e5a21899e91bd20c6567f25308669119a69b 100644 (file)
@@ -78,6 +78,13 @@ SOFTWARE.
 #include "region.h"
 //#include "poly.h"
 
+#ifndef min
+#define min(a,b)            (((a) < (b)) ? (a) : (b))
+#endif
+#ifndef max
+#define max(a,b)            (((a) > (b)) ? (a) : (b))
+#endif
+
 #ifdef DEBUG
 #include <stdio.h>
 #define assert(expr) {if (!(expr)) fprintf(stderr,\
index 7fa44d965db9b44e82243a51022191ec6714b282..e8c9a4f9469f1a9353e188b90b939a6f505a6bfa 100644 (file)
@@ -61,14 +61,6 @@ SOFTWARE.
 #define Xfree free
 #define Xrealloc realloc
 
-#ifndef max
-#define max(a,b)            (((a) > (b)) ? (a) : (b))
-#endif
-
-#ifndef min
-#define min(a,b)            (((a) < (b)) ? (a) : (b))
-#endif
-
 #define NeedFunctionPrototypes 1
 
 // - Cribbed from Xlib.h
index 38e12acfdb962714906f791aa71db3dccb72b59b..b65566dc084bd5d0b9a15d26c9ba156e08dd64d4 100644 (file)
 #include <sys/time.h>
 #endif
 
-#ifndef min
-#define min(a,b)            (((a) < (b)) ? (a) : (b))
+#ifndef vncmin
+#define vncmin(a,b)            (((a) < (b)) ? (a) : (b))
 #endif
-
-#ifndef max
-#define max(a,b)            (((a) > (b)) ? (a) : (b))
+#ifndef vncmax
+#define vncmax(a,b)            (((a) > (b)) ? (a) : (b))
 #endif
 
 // XXX should use autoconf HAVE_SYS_SELECT_H
@@ -146,7 +145,7 @@ int FdInStream::overrun(int itemSize, int nItems, bool wait)
       // during timing=1 can be satisfied without calling
       // readWithTimeoutOrCallback. However, reading only 1 or 2 bytes
       // bytes is ineffecient.
-      bytes_to_read = min(bytes_to_read, max(itemSize*nItems, 8));
+      bytes_to_read = vncmin(bytes_to_read, vncmax(itemSize*nItems, 8));
     }
     int n = readWithTimeoutOrCallback((U8*)end, bytes_to_read, wait);
     if (n == 0) return 0;
index 0c44d85ab792a08b290c61275308685ecd8e099a..0b548a6cd8d83aa9a09d10d228c73ebe77687b25 100644 (file)
@@ -60,7 +60,7 @@ void ComparingUpdateTracker::compare()
     // 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 @@ void ComparingUpdateTracker::compareRect(const Rect& r, Region* newChanged)
   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++)
index ee43e669ced719f643b8985680e2cf8e685bd3b1..0ddf36cbe40e8f84d6a0f5f357071e965bbca2bf 100644 (file)
 #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 @@ namespace rfb {
     }
     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 {
index dc685e3aa425e1c0571261ee3b8c02846f1b6e97..0c5559a454619743d77b27e3bfcd7920b918cdf0 100644 (file)
@@ -52,11 +52,11 @@ void HEXTILE_DECODE (const Rect& r, rdr::InStream* is, PIXEL_T* buf
 
   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();
 
index a55842a0728da41b1fab984a80419f437da1be4e..15c8862ece941ed1af56bbb61d3f55372e670678 100644 (file)
@@ -60,11 +60,11 @@ void HEXTILE_ENCODE(const Rect& r, rdr::OutStream* os
 
   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);
 
index d792c8d1262c19ce1b2b626c178b534121dbff6f..b65417004e4efc61cfc60c6d37ec820bae519e23 100644 (file)
 #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 @@ namespace rfb {
 }
 #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
index b5391b1181c703024ae9e8cd84fb4d35b2bef0b4..e1f85f77c7354013577b305153148f2fc8724c24 100644 (file)
@@ -61,11 +61,11 @@ void ZRLE_DECODE (const Rect& r, rdr::InStream* is,
 
   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;
index a1582f2a491316e6f1f3b5d4da352afbc54268dc..42505a3137d654275f4a43d27559b8985f2887f6 100644 (file)
@@ -130,7 +130,7 @@ bool ZRLE_ENCODE (const Rect& r, rdr::OutStream* os,
 
   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 @@ bool ZRLE_ENCODE (const Rect& r, rdr::OutStream* os,
 
     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);
 
index 3f0c57e6f6f4ec56de50b8915404317856e35927..c22dbf9461e82f77a32c894683ef3f25687df8ea 100644 (file)
@@ -62,8 +62,8 @@ public:
     text.buf = rfb::strDup(text_);
     int textWidth = XTextWidth(defaultFS, text.buf, strlen(text.buf));
     int textHeight = (defaultFS->ascent + defaultFS->descent);
-    int newWidth = max(width(), textWidth + xPad*2 + bevel*2);
-    int newHeight = max(height(), textHeight + yPad*2 + bevel*2);
+    int newWidth = vncmax(width(), textWidth + xPad*2 + bevel*2);
+    int newHeight = vncmax(height(), textHeight + yPad*2 + bevel*2);
     if (width() < newWidth || height() < newHeight) {
       resize(newWidth, newHeight);
     }
index 146091d0d59d567c51de2c70b8ec47f88b1a01ad..41eef27cb6a1da5482ac56714a8e20d11194aed5 100644 (file)
@@ -71,8 +71,8 @@ public:
     text = strdup(text_);
     int textWidth = XTextWidth(defaultFS, text, strlen(text));
     int textHeight = (defaultFS->ascent + defaultFS->descent);
-    int newWidth = max(width(), textWidth + xPad*2 + boxPad*2 + boxSize);
-    int newHeight = max(height(), textHeight + yPad*2);
+    int newWidth = vncmax(width(), textWidth + xPad*2 + boxPad*2 + boxSize);
+    int newHeight = vncmax(height(), textHeight + yPad*2);
     if (width() < newWidth || height() < newHeight) {
       resize(newWidth, newHeight);
     }
index b51946e3591d7501595bbc2e644a8ba17f203392..0d1f005ff6e9802aeb11213a2caca933a5c163f5 100644 (file)
@@ -58,7 +58,7 @@ public:
                  | ButtonPressMask);
     text[0] = 0;
     int textHeight = (defaultFS->ascent + defaultFS->descent);
-    int newHeight = max(height(), textHeight + yPad*2 + bevel*2);
+    int newHeight = vncmax(height(), textHeight + yPad*2 + bevel*2);
     if (height() < newHeight) {
       resize(width(), newHeight);
     }
index d5b064931b8b450f032be88bfeb34d851411e53e..caaeec43c3a1a8f090f6e42d3133bbf5c5d165ae 100644 (file)
@@ -71,8 +71,8 @@ void TXImage::resize(int w, int h)
   if (w == width() && h == height()) return;
 
   int oldStrideBytes = getStride() * (format.bpp/8);
-  int rowsToCopy = min(h, height());
-  int bytesPerRow = min(w, width()) * (format.bpp/8);
+  int rowsToCopy = vncmin(h, height());
+  int bytesPerRow = vncmin(w, width()) * (format.bpp/8);
   rdr::U8* oldData = 0;
   bool allocData = false;
 
index 44f70477b7e86a9938e4986064946f5ec118bf77..bbd893a564d7a718353c3cf3b92ccd6fb4a9d783 100644 (file)
@@ -64,8 +64,8 @@ public:
     int textHeight = ((defaultFS->ascent + defaultFS->descent + lineSpacing)
                       * lines);
 
-    int newWidth = max(width(), textWidth + xPad*2);
-    int newHeight = max(height(), textHeight + yPad*2);
+    int newWidth = vncmax(width(), textWidth + xPad*2);
+    int newHeight = vncmax(height(), textHeight + yPad*2);
     if (width() < newWidth || height() < newHeight) {
       resize(newWidth, newHeight);
     }