Changes of Revision 29

kodi-noX-raspberry-pi.changes Changed
x
 
1
@@ -1,4 +1,9 @@
2
 -------------------------------------------------------------------
3
+Fri Jul 29 08:44:03 UTC 2016 - olaf@aepfle.de
4
+
5
+- kodi.cximage.gcc6.patch
6
+
7
+-------------------------------------------------------------------
8
 Sun Apr 24 11:55:31 UTC 2016 - sagiben at gmail dot com
9
 
10
 - Version update to Kodi 16.1 Jarvis:
11
kodi-noX-raspberry-pi2.changes Changed
11
 
1
@@ -1,4 +1,9 @@
2
 -------------------------------------------------------------------
3
+Fri Jul 29 08:44:03 UTC 2016 - olaf@aepfle.de
4
+
5
+- kodi.cximage.gcc6.patch
6
+
7
+-------------------------------------------------------------------
8
 Sun Apr 24 11:55:31 UTC 2016 - sagiben at gmail dot com
9
 
10
 - Version update to Kodi 16.1 Jarvis:
11
kodi-noX.changes Changed
11
 
1
@@ -1,4 +1,9 @@
2
 -------------------------------------------------------------------
3
+Fri Jul 29 08:44:03 UTC 2016 - olaf@aepfle.de
4
+
5
+- kodi.cximage.gcc6.patch
6
+
7
+-------------------------------------------------------------------
8
 Sun Apr 24 11:55:31 UTC 2016 - sagiben at gmail dot com
9
 
10
 - Version update to Kodi 16.1 Jarvis:
11
kodi.changes Changed
11
 
1
@@ -1,4 +1,9 @@
2
 -------------------------------------------------------------------
3
+Fri Jul 29 08:44:03 UTC 2016 - olaf@aepfle.de
4
+
5
+- kodi.cximage.gcc6.patch
6
+
7
+-------------------------------------------------------------------
8
 Sun Apr 24 11:55:31 UTC 2016 - sagiben at gmail dot com
9
 
10
 - Version update to Kodi 16.1 Jarvis:
11
kodi-noX-raspberry-pi.spec Changed
17
 
1
@@ -59,6 +59,7 @@
2
 Patch2:         kodi-texturepacker.patch
3
 Patch3:         crossguid_build64.patch
4
 Patch4:         add_rpi2_support.patch
5
+Patch6:         kodi.cximage.gcc6.patch
6
 BuildRequires:  avahi-devel
7
 BuildRequires:  boost-devel
8
 BuildRequires:  byacc
9
@@ -246,6 +247,7 @@
10
 %patch2
11
 %patch3
12
 %patch4 -p0
13
+%patch6 -p1
14
 
15
 
16
 # Remove build time references so build-compare can do its work
17
kodi-noX-raspberry-pi2.spec Changed
17
 
1
@@ -59,6 +59,7 @@
2
 Patch2:         kodi-texturepacker.patch
3
 Patch3:         crossguid_build64.patch
4
 Patch4:         add_rpi2_support.patch
5
+Patch6:         kodi.cximage.gcc6.patch
6
 BuildRequires:  avahi-devel
7
 BuildRequires:  boost-devel
8
 BuildRequires:  byacc
9
@@ -246,6 +247,7 @@
10
 %patch2
11
 %patch3
12
 %patch4 -p0
13
+%patch6 -p1
14
 
15
 
16
 # Remove build time references so build-compare can do its work
17
kodi-noX.spec Changed
17
 
1
@@ -59,6 +59,7 @@
2
 Patch2:         kodi-texturepacker.patch
3
 Patch3:         crossguid_build64.patch
4
 Patch4:         add_rpi2_support.patch
5
+Patch6:         kodi.cximage.gcc6.patch
6
 BuildRequires:  avahi-devel
7
 BuildRequires:  boost-devel
8
 BuildRequires:  byacc
9
@@ -246,6 +247,7 @@
10
 %patch2
11
 %patch3
12
 %patch4 -p0
13
+%patch6 -p1
14
 
15
 
16
 # Remove build time references so build-compare can do its work
17
kodi.spec Changed
17
 
1
@@ -59,6 +59,7 @@
2
 Patch2:         kodi-texturepacker.patch
3
 Patch3:         crossguid_build64.patch
4
 Patch4:         add_rpi2_support.patch
5
+Patch6:         kodi.cximage.gcc6.patch
6
 BuildRequires:  avahi-devel
7
 BuildRequires:  boost-devel
8
 BuildRequires:  byacc
9
@@ -246,6 +247,7 @@
10
 %patch2
11
 %patch3
12
 %patch4 -p0
13
+%patch6 -p1
14
 
15
 
16
 # Remove build time references so build-compare can do its work
17
kodi.cximage.gcc6.patch Added
1393
 
1
@@ -0,0 +1,1391 @@
2
+https://github.com/xbmc/xbmc/pull/9703
3
+---
4
+ lib/cximage-6.0/CxImage/ximabmp.cpp  |    6 -
5
+ lib/cximage-6.0/CxImage/ximadef.h    |    8 -
6
+ lib/cximage-6.0/CxImage/ximadsp.cpp  |  182 +++++++++++++++++------------------
7
+ lib/cximage-6.0/CxImage/ximage.cpp   |    4 
8
+ lib/cximage-6.0/CxImage/ximagif.cpp  |    6 -
9
+ lib/cximage-6.0/CxImage/ximahist.cpp |   12 +-
10
+ lib/cximage-6.0/CxImage/ximaint.cpp  |    8 -
11
+ lib/cximage-6.0/CxImage/ximaiter.h   |    4 
12
+ lib/cximage-6.0/CxImage/ximajpg.cpp  |    2 
13
+ lib/cximage-6.0/CxImage/ximapal.cpp  |   14 +-
14
+ lib/cximage-6.0/CxImage/ximapng.cpp  |   12 +-
15
+ lib/cximage-6.0/CxImage/ximaraw.cpp  |    4 
16
+ lib/cximage-6.0/CxImage/ximasel.cpp  |   54 +++++-----
17
+ lib/cximage-6.0/CxImage/ximath.cpp   |    8 -
18
+ lib/cximage-6.0/CxImage/ximatif.cpp  |    6 -
19
+ lib/cximage-6.0/CxImage/ximatran.cpp |  138 +++++++++++++-------------
20
+ lib/cximage-6.0/CxImage/ximawnd.cpp  |   16 +--
21
+ 17 files changed, 238 insertions(+), 246 deletions(-)
22
+
23
+--- a/lib/cximage-6.0/CxImage/ximabmp.cpp
24
++++ b/lib/cximage-6.0/CxImage/ximabmp.cpp
25
+@@ -46,7 +46,7 @@ bool CxImageBMP::Encode(CxFile * hFile)
26
+       bihtoh(&infohdr);
27
+ 
28
+       // Write the file header
29
+-      hFile->Write(&hdr,min(14,sizeof(BITMAPFILEHEADER)),1);
30
++      hFile->Write(&hdr,cmin(14,sizeof(BITMAPFILEHEADER)),1);
31
+       hFile->Write(&infohdr,sizeof(BITMAPINFOHEADER),1);
32
+        //and DIB+ALPHA interlaced
33
+       BYTE *srcalpha = AlphaGetPointer();
34
+@@ -64,7 +64,7 @@ bool CxImageBMP::Encode(CxFile * hFile)
35
+ #endif //CXIMAGE_SUPPORT_ALPHA
36
+   {
37
+       // Write the file header
38
+-      hFile->Write(&hdr,min(14,sizeof(BITMAPFILEHEADER)),1);
39
++      hFile->Write(&hdr,cmin(14,sizeof(BITMAPFILEHEADER)),1);
40
+       //copy attributes
41
+       memcpy(pDib,&head,sizeof(BITMAPINFOHEADER));
42
+       bihtoh((BITMAPINFOHEADER*)pDib);
43
+@@ -86,7 +86,7 @@ bool CxImageBMP::Decode(CxFile * hFile)
44
+   BITMAPFILEHEADER   bf;
45
+   DWORD off = hFile->Tell(); //<CSC>
46
+   cx_try {
47
+-  if (hFile->Read(&bf,min(14,sizeof(bf)),1)==0) cx_throw("Not a BMP");
48
++  if (hFile->Read(&bf,cmin(14,sizeof(bf)),1)==0) cx_throw("Not a BMP");
49
+ 
50
+   bf.bfSize = my_ntohl(bf.bfSize); 
51
+   bf.bfOffBits = my_ntohl(bf.bfOffBits); 
52
+--- a/lib/cximage-6.0/CxImage/ximadef.h
53
++++ b/lib/cximage-6.0/CxImage/ximadef.h
54
+@@ -53,12 +53,8 @@
55
+  #define CXIMAGE_SUPPORT_WINDOWS 0
56
+ #endif
57
+ 
58
+-#ifndef min
59
+-#define min(a,b) (((a)<(b))?(a):(b))
60
+-#endif
61
+-#ifndef max
62
+-#define max(a,b) (((a)>(b))?(a):(b))
63
+-#endif
64
++#define cmin(a,b) (((a)<(b))?(a):(b))
65
++#define cmax(a,b) (((a)>(b))?(a):(b))
66
+ 
67
+ #ifndef PI
68
+  #define PI 3.141592653589793f
69
+--- a/lib/cximage-6.0/CxImage/ximadsp.cpp
70
++++ b/lib/cximage-6.0/CxImage/ximadsp.cpp
71
+@@ -389,8 +389,8 @@ RGBQUAD CxImage::RGBtoHSL(RGBQUAD lRGBCo
72
+   G = lRGBColor.rgbGreen;
73
+   B = lRGBColor.rgbBlue;
74
+ 
75
+-  cMax = max( max(R,G), B);   /* calculate lightness */
76
+-  cMin = min( min(R,G), B);
77
++  cMax = cmax( cmax(R,G), B); /* calculate lightness */
78
++  cMin = cmin( cmin(R,G), B);
79
+   L = (BYTE)((((cMax+cMin)*HSLMAX)+RGBMAX)/(2*RGBMAX));
80
+ 
81
+   if (cMax==cMin){            /* r=g=b --> achromatic case */
82
+@@ -489,9 +489,9 @@ RGBQUAD CxImage::YUVtoRGB(RGBQUAD lYUVCo
83
+   G = (int)( Y - 0.344f * U - 0.714f * V);
84
+   B = (int)( Y + 1.770f * U);
85
+ 
86
+-  R= min(255,max(0,R));
87
+-  G= min(255,max(0,G));
88
+-  B= min(255,max(0,B));
89
++  R= cmin(255,cmax(0,R));
90
++  G= cmin(255,cmax(0,G));
91
++  B= cmin(255,cmax(0,B));
92
+   RGBQUAD rgb={(BYTE)B,(BYTE)G,(BYTE)R,0};
93
+   return rgb;
94
+ }
95
+@@ -510,9 +510,9 @@ RGBQUAD CxImage::RGBtoYUV(RGBQUAD lRGBCo
96
+   U = (int)((B-Y) * 0.565f + 128);
97
+   V = (int)((R-Y) * 0.713f + 128);
98
+ 
99
+-  Y= min(255,max(0,Y));
100
+-  U= min(255,max(0,U));
101
+-  V= min(255,max(0,V));
102
++  Y= cmin(255,cmax(0,Y));
103
++  U= cmin(255,cmax(0,U));
104
++  V= cmin(255,cmax(0,V));
105
+   RGBQUAD yuv={(BYTE)V,(BYTE)U,(BYTE)Y,0};
106
+   return yuv;
107
+ }
108
+@@ -528,9 +528,9 @@ RGBQUAD CxImage::YIQtoRGB(RGBQUAD lYIQCo
109
+   G = (int)( Y - 0.273f * I - 0.647f * Q);
110
+   B = (int)( Y - 1.104f * I + 1.701f * Q);
111
+ 
112
+-  R= min(255,max(0,R));
113
+-  G= min(255,max(0,G));
114
+-  B= min(255,max(0,B));
115
++  R= cmin(255,cmax(0,R));
116
++  G= cmin(255,cmax(0,G));
117
++  B= cmin(255,cmax(0,B));
118
+   RGBQUAD rgb={(BYTE)B,(BYTE)G,(BYTE)R,0};
119
+   return rgb;
120
+ }
121
+@@ -546,9 +546,9 @@ RGBQUAD CxImage::RGBtoYIQ(RGBQUAD lRGBCo
122
+   I = (int)( 0.5960f * R - 0.2742f * G - 0.3219f * B + 128);
123
+   Q = (int)( 0.2109f * R - 0.5229f * G + 0.3120f * B + 128);
124
+ 
125
+-  Y= min(255,max(0,Y));
126
+-  I= min(255,max(0,I));
127
+-  Q= min(255,max(0,Q));
128
++  Y= cmin(255,cmax(0,Y));
129
++  I= cmin(255,cmax(0,I));
130
++  Q= cmin(255,cmax(0,Q));
131
+   RGBQUAD yiq={(BYTE)Q,(BYTE)I,(BYTE)Y,0};
132
+   return yiq;
133
+ }
134
+@@ -565,9 +565,9 @@ RGBQUAD CxImage::XYZtoRGB(RGBQUAD lXYZCo
135
+   G = (int)( -0.969256f * X + 1.875992f * Y + 0.041556f * Z * k);
136
+   B = (int)(  0.055648f * X - 0.204043f * Y + 1.057311f * Z * k);
137
+ 
138
+-  R= min(255,max(0,R));
139
+-  G= min(255,max(0,G));
140
+-  B= min(255,max(0,B));
141
++  R= cmin(255,cmax(0,R));
142
++  G= cmin(255,cmax(0,G));
143
++  B= cmin(255,cmax(0,B));
144
+   RGBQUAD rgb={(BYTE)B,(BYTE)G,(BYTE)R,0};
145
+   return rgb;
146
+ }
147
+@@ -583,9 +583,9 @@ RGBQUAD CxImage::RGBtoXYZ(RGBQUAD lRGBCo
148
+   Y = (int)( 0.212671f * R + 0.715160f * G + 0.072169f * B);
149
+   Z = (int)((0.019334f * R + 0.119193f * G + 0.950227f * B)*0.918483657f);
150
+ 
151
+-  //X= min(255,max(0,X));
152
+-  //Y= min(255,max(0,Y));
153
+-  //Z= min(255,max(0,Z));
154
++  //X= cmin(255,cmax(0,X));
155
++  //Y= cmin(255,cmax(0,Y));
156
++  //Z= cmin(255,cmax(0,Z));
157
+   RGBQUAD xyz={(BYTE)Z,(BYTE)Y,(BYTE)X,0};
158
+   return xyz;
159
+ }
160
+@@ -707,7 +707,7 @@ bool CxImage::Light(long brightness, lon
161
+ 
162
+   BYTE cTable[256]; //<nipper>
163
+   for (int i=0;i<256;i++) {
164
+-      cTable[i] = (BYTE)max(0,min(255,(int)((i-128)*c + brightness + 0.5f)));
165
++      cTable[i] = (BYTE)cmax(0,cmin(255,(int)((i-128)*c + brightness + 0.5f)));
166
+   }
167
+ 
168
+   return Lut(cTable);
169
+@@ -830,11 +830,11 @@ bool CxImage::Filter(long* kernel, long
170
+                       }
171
+                   }
172
+                   if (Kfactor==0 || ksumcur==0){
173
+-                      cPtr2[iY1] = (BYTE)min(255, max(0,(int)(b + Koffset)));
174
++                      cPtr2[iY1] = (BYTE)cmin(255, cmax(0,(int)(b + Koffset)));
175
+                   } else if (ksumtot == ksumcur) {
176
+-                      cPtr2[iY1] = (BYTE)min(255, max(0,(int)(b/Kfactor + Koffset)));
177
++                      cPtr2[iY1] = (BYTE)cmin(255, cmax(0,(int)(b/Kfactor + Koffset)));
178
+                   } else {
179
+-                      cPtr2[iY1] = (BYTE)min(255, max(0,(int)((b*ksumtot)/(ksumcur*Kfactor) + Koffset)));
180
++                      cPtr2[iY1] = (BYTE)cmin(255, cmax(0,(int)((b*ksumtot)/(ksumcur*Kfactor) + Koffset)));
181
+                   }
182
+               }
183
+           }
184
+@@ -863,17 +863,17 @@ bool CxImage::Filter(long* kernel, long
185
+                       }
186
+                   }
187
+                   if (Kfactor==0 || ksumcur==0){
188
+-                      c.rgbRed   = (BYTE)min(255, max(0,(int)(r + Koffset)));
189
+-                      c.rgbGreen = (BYTE)min(255, max(0,(int)(g + Koffset)));
190
+-                      c.rgbBlue  = (BYTE)min(255, max(0,(int)(b + Koffset)));
191
++                      c.rgbRed   = (BYTE)cmin(255, cmax(0,(int)(r + Koffset)));
192
++                      c.rgbGreen = (BYTE)cmin(255, cmax(0,(int)(g + Koffset)));
193
++                      c.rgbBlue  = (BYTE)cmin(255, cmax(0,(int)(b + Koffset)));
194
+                   } else if (ksumtot == ksumcur) {
195
+-                      c.rgbRed   = (BYTE)min(255, max(0,(int)(r/Kfactor + Koffset)));
196
+-                      c.rgbGreen = (BYTE)min(255, max(0,(int)(g/Kfactor + Koffset)));
197
+-                      c.rgbBlue  = (BYTE)min(255, max(0,(int)(b/Kfactor + Koffset)));
198
++                      c.rgbRed   = (BYTE)cmin(255, cmax(0,(int)(r/Kfactor + Koffset)));
199
++                      c.rgbGreen = (BYTE)cmin(255, cmax(0,(int)(g/Kfactor + Koffset)));
200
++                      c.rgbBlue  = (BYTE)cmin(255, cmax(0,(int)(b/Kfactor + Koffset)));
201
+                   } else {
202
+-                      c.rgbRed   = (BYTE)min(255, max(0,(int)((r*ksumtot)/(ksumcur*Kfactor) + Koffset)));
203
+-                      c.rgbGreen = (BYTE)min(255, max(0,(int)((g*ksumtot)/(ksumcur*Kfactor) + Koffset)));
204
+-                      c.rgbBlue  = (BYTE)min(255, max(0,(int)((b*ksumtot)/(ksumcur*Kfactor) + Koffset)));
205
++                      c.rgbRed   = (BYTE)cmin(255, cmax(0,(int)((r*ksumtot)/(ksumcur*Kfactor) + Koffset)));
206
++                      c.rgbGreen = (BYTE)cmin(255, cmax(0,(int)((g*ksumtot)/(ksumcur*Kfactor) + Koffset)));
207
++                      c.rgbBlue  = (BYTE)cmin(255, cmax(0,(int)((b*ksumtot)/(ksumcur*Kfactor) + Koffset)));
208
+                   }
209
+                   tmp.BlindSetPixelColor(x,y,c);
210
+               }
211
+@@ -1078,8 +1078,8 @@ bool CxImage::Edge(long Ksize)
212
+ // 
213
+ void CxImage::Mix(CxImage & imgsrc2, ImageOpType op, long lXOffset, long lYOffset, bool bMixAlpha)
214
+ {
215
+-    long lWide = min(GetWidth(),imgsrc2.GetWidth()-lXOffset);
216
+-    long lHeight = min(GetHeight(),imgsrc2.GetHeight()-lYOffset);
217
++    long lWide = cmin(GetWidth(),imgsrc2.GetWidth()-lXOffset);
218
++    long lHeight = cmin(GetHeight(),imgsrc2.GetHeight()-lYOffset);
219
+ 
220
+   bool bEditAlpha = imgsrc2.AlphaIsValid() & bMixAlpha;
221
+ 
222
+@@ -1112,16 +1112,16 @@ void CxImage::Mix(CxImage & imgsrc2, Ima
223
+                       if (bEditAlpha) rgbDest.rgbReserved = (BYTE)((rgb1.rgbReserved+rgb2.rgbReserved)/2);
224
+                   break;
225
+                   case OpAdd:
226
+-                      rgbDest.rgbBlue = (BYTE)max(0,min(255,rgb1.rgbBlue+rgb2.rgbBlue));
227
+-                      rgbDest.rgbGreen = (BYTE)max(0,min(255,rgb1.rgbGreen+rgb2.rgbGreen));
228
+-                      rgbDest.rgbRed = (BYTE)max(0,min(255,rgb1.rgbRed+rgb2.rgbRed));
229
+-                      if (bEditAlpha) rgbDest.rgbReserved = (BYTE)max(0,min(255,rgb1.rgbReserved+rgb2.rgbReserved));
230
++                      rgbDest.rgbBlue = (BYTE)cmax(0,cmin(255,rgb1.rgbBlue+rgb2.rgbBlue));
231
++                      rgbDest.rgbGreen = (BYTE)cmax(0,cmin(255,rgb1.rgbGreen+rgb2.rgbGreen));
232
++                      rgbDest.rgbRed = (BYTE)cmax(0,cmin(255,rgb1.rgbRed+rgb2.rgbRed));
233
++                      if (bEditAlpha) rgbDest.rgbReserved = (BYTE)cmax(0,cmin(255,rgb1.rgbReserved+rgb2.rgbReserved));
234
+                   break;
235
+                   case OpSub:
236
+-                      rgbDest.rgbBlue = (BYTE)max(0,min(255,rgb1.rgbBlue-rgb2.rgbBlue));
237
+-                      rgbDest.rgbGreen = (BYTE)max(0,min(255,rgb1.rgbGreen-rgb2.rgbGreen));
238
+-                      rgbDest.rgbRed = (BYTE)max(0,min(255,rgb1.rgbRed-rgb2.rgbRed));
239
+-                      if (bEditAlpha) rgbDest.rgbReserved = (BYTE)max(0,min(255,rgb1.rgbReserved-rgb2.rgbReserved));
240
++                      rgbDest.rgbBlue = (BYTE)cmax(0,cmin(255,rgb1.rgbBlue-rgb2.rgbBlue));
241
++                      rgbDest.rgbGreen = (BYTE)cmax(0,cmin(255,rgb1.rgbGreen-rgb2.rgbGreen));
242
++                      rgbDest.rgbRed = (BYTE)cmax(0,cmin(255,rgb1.rgbRed-rgb2.rgbRed));
243
++                      if (bEditAlpha) rgbDest.rgbReserved = (BYTE)cmax(0,cmin(255,rgb1.rgbReserved-rgb2.rgbReserved));
244
+                   break;
245
+                   case OpAnd:
246
+                       rgbDest.rgbBlue = (BYTE)(rgb1.rgbBlue&rgb2.rgbBlue);
247
+@@ -1202,11 +1202,11 @@ void CxImage::Mix(CxImage & imgsrc2, Ima
248
+                           double dSmallAmt = dSmall*((double)rgb2.rgbBlue);
249
+ 
250
+                           if( lAverage < lThresh+1){
251
+-                              rgbDest.rgbBlue = (BYTE)max(0,min(255,(int)(dLarge*((double)rgb1.rgbBlue) +
252
++                              rgbDest.rgbBlue = (BYTE)cmax(0,cmin(255,(int)(dLarge*((double)rgb1.rgbBlue) +
253
+                                               dSmallAmt)));
254
+-                              rgbDest.rgbGreen = (BYTE)max(0,min(255,(int)(dLarge*((double)rgb1.rgbGreen) +
255
++                              rgbDest.rgbGreen = (BYTE)cmax(0,cmin(255,(int)(dLarge*((double)rgb1.rgbGreen) +
256
+                                               dSmallAmt)));
257
+-                              rgbDest.rgbRed = (BYTE)max(0,min(255,(int)(dLarge*((double)rgb1.rgbRed) +
258
++                              rgbDest.rgbRed = (BYTE)cmax(0,cmin(255,(int)(dLarge*((double)rgb1.rgbRed) +
259
+                                               dSmallAmt)));
260
+                           }
261
+                           else
262
+@@ -1274,9 +1274,9 @@ bool CxImage::ShiftRGB(long r, long g, l
263
+ #endif //CXIMAGE_SUPPORT_SELECTION
264
+               {
265
+                   color = BlindGetPixelColor(x,y);
266
+-                  color.rgbRed = (BYTE)max(0,min(255,(int)(color.rgbRed + r)));
267
+-                  color.rgbGreen = (BYTE)max(0,min(255,(int)(color.rgbGreen + g)));
268
+-                  color.rgbBlue = (BYTE)max(0,min(255,(int)(color.rgbBlue + b)));
269
++                  color.rgbRed = (BYTE)cmax(0,cmin(255,(int)(color.rgbRed + r)));
270
++                  color.rgbGreen = (BYTE)cmax(0,cmin(255,(int)(color.rgbGreen + g)));
271
++                  color.rgbBlue = (BYTE)cmax(0,cmin(255,(int)(color.rgbBlue + b)));
272
+                   BlindSetPixelColor(x,y,color);
273
+               }
274
+           }
275
+@@ -1284,9 +1284,9 @@ bool CxImage::ShiftRGB(long r, long g, l
276
+   } else {
277
+       for(DWORD j=0; j<head.biClrUsed; j++){
278
+           color = GetPaletteColor((BYTE)j);
279
+-          color.rgbRed = (BYTE)max(0,min(255,(int)(color.rgbRed + r)));
280
+-          color.rgbGreen = (BYTE)max(0,min(255,(int)(color.rgbGreen + g)));
281
+-          color.rgbBlue = (BYTE)max(0,min(255,(int)(color.rgbBlue + b)));
282
++          color.rgbRed = (BYTE)cmax(0,cmin(255,(int)(color.rgbRed + r)));
283
++          color.rgbGreen = (BYTE)cmax(0,cmin(255,(int)(color.rgbGreen + g)));
284
++          color.rgbBlue = (BYTE)cmax(0,cmin(255,(int)(color.rgbBlue + b)));
285
+           SetPaletteColor((BYTE)j,color);
286
+       }
287
+   }
288
+@@ -1310,7 +1310,7 @@ bool CxImage::Gamma(float gamma)
289
+ 
290
+   BYTE cTable[256]; //<nipper>
291
+   for (int i=0;i<256;i++) {
292
+-      cTable[i] = (BYTE)max(0,min(255,(int)( pow((double)i, dinvgamma) / dMax)));
293
++      cTable[i] = (BYTE)cmax(0,cmin(255,(int)( pow((double)i, dinvgamma) / dMax)));
294
+   }
295
+ 
296
+   return Lut(cTable);
297
+@@ -1337,21 +1337,21 @@ bool CxImage::GammaRGB(float gammaR, flo
298
+   dMax = pow(255.0, dinvgamma) / 255.0;
299
+   BYTE cTableR[256];
300
+   for (i=0;i<256;i++) {
301
+-      cTableR[i] = (BYTE)max(0,min(255,(int)( pow((double)i, dinvgamma) / dMax)));
302
++      cTableR[i] = (BYTE)cmax(0,cmin(255,(int)( pow((double)i, dinvgamma) / dMax)));
303
+   }
304
+ 
305
+   dinvgamma = 1/gammaG;
306
+   dMax = pow(255.0, dinvgamma) / 255.0;
307
+   BYTE cTableG[256];
308
+   for (i=0;i<256;i++) {
309
+-      cTableG[i] = (BYTE)max(0,min(255,(int)( pow((double)i, dinvgamma) / dMax)));
310
++      cTableG[i] = (BYTE)cmax(0,cmin(255,(int)( pow((double)i, dinvgamma) / dMax)));
311
+   }
312
+ 
313
+   dinvgamma = 1/gammaB;
314
+   dMax = pow(255.0, dinvgamma) / 255.0;
315
+   BYTE cTableB[256];
316
+   for (i=0;i<256;i++) {
317
+-      cTableB[i] = (BYTE)max(0,min(255,(int)( pow((double)i, dinvgamma) / dMax)));
318
++      cTableB[i] = (BYTE)cmax(0,cmin(255,(int)( pow((double)i, dinvgamma) / dMax)));
319
+   }
320
+ 
321
+   return Lut(cTableR, cTableG, cTableB);
322
+@@ -1442,11 +1442,11 @@ bool CxImage::Noise(long level)
323
+           {
324
+               color = BlindGetPixelColor(x,y);
325
+               n=(long)((rand()/(float)RAND_MAX - 0.5)*level);
326
+-              color.rgbRed = (BYTE)max(0,min(255,(int)(color.rgbRed + n)));
327
++              color.rgbRed = (BYTE)cmax(0,cmin(255,(int)(color.rgbRed + n)));
328
+               n=(long)((rand()/(float)RAND_MAX - 0.5)*level);
329
+-              color.rgbGreen = (BYTE)max(0,min(255,(int)(color.rgbGreen + n)));
330
++              color.rgbGreen = (BYTE)cmax(0,cmin(255,(int)(color.rgbGreen + n)));
331
+               n=(long)((rand()/(float)RAND_MAX - 0.5)*level);
332
+-              color.rgbBlue = (BYTE)max(0,min(255,(int)(color.rgbBlue + n)));
333
++              color.rgbBlue = (BYTE)cmax(0,cmin(255,(int)(color.rgbBlue + n)));
334
+               BlindSetPixelColor(x,y,color);
335
+           }
336
+       }
337
+@@ -1561,8 +1561,8 @@ bool CxImage::FFT2(CxImage* srcReal, CxI
338
+ 
339
+   //DFT buffers
340
+   double *real2,*imag2;
341
+-  real2 = (double*)malloc(max(w,h) * sizeof(double));
342
+-  imag2 = (double*)malloc(max(w,h) * sizeof(double));
343
++  real2 = (double*)malloc(cmax(w,h) * sizeof(double));
344
++  imag2 = (double*)malloc(cmax(w,h) * sizeof(double));
345
+ 
346
+   /* Transform the rows */
347
+   real = (double *)malloc(w * sizeof(double));
348
+@@ -1617,7 +1617,7 @@ bool CxImage::FFT2(CxImage* srcReal, CxI
349
+ 
350
+   /* converting from double to byte, there is a HUGE loss in the dynamics
351
+     "nn" tries to keep an acceptable SNR, but 8bit=48dB: don't ask more */
352
+-  double nn=pow((double)2,(double)log((double)max(w,h))/(double)log((double)2)-4);
353
++  double nn=pow((double)2,(double)log((double)cmax(w,h))/(double)log((double)2)-4);
354
+   //reversed gain for reversed transform
355
+   if (direction==-1) nn=1/nn;
356
+   //bMagnitude : just to see it on the screen
357
+@@ -1626,15 +1626,15 @@ bool CxImage::FFT2(CxImage* srcReal, CxI
358
+   for (j=0;j<h;j++) {
359
+       for (k=0;k<w;k++) {
360
+           if (bMagnitude){
361
+-              tmpReal->SetPixelIndex(k,j,(BYTE)max(0,min(255,(nn*(3+log(_cabs(grid[k][j])))))));
362
++              tmpReal->SetPixelIndex(k,j,(BYTE)cmax(0,cmin(255,(nn*(3+log(_cabs(grid[k][j])))))));
363
+               if (grid[k][j].x==0){
364
+-                  tmpImag->SetPixelIndex(k,j,(BYTE)max(0,min(255,(128+(atan(grid[k][j].y/0.0000000001)*nn)))));
365
++                  tmpImag->SetPixelIndex(k,j,(BYTE)cmax(0,cmin(255,(128+(atan(grid[k][j].y/0.0000000001)*nn)))));
366
+               } else {
367
+-                  tmpImag->SetPixelIndex(k,j,(BYTE)max(0,min(255,(128+(atan(grid[k][j].y/grid[k][j].x)*nn)))));
368
++                  tmpImag->SetPixelIndex(k,j,(BYTE)cmax(0,cmin(255,(128+(atan(grid[k][j].y/grid[k][j].x)*nn)))));
369
+               }
370
+           } else {
371
+-              tmpReal->SetPixelIndex(k,j,(BYTE)max(0,min(255,(128 + grid[k][j].x*nn))));
372
+-              tmpImag->SetPixelIndex(k,j,(BYTE)max(0,min(255,(128 + grid[k][j].y*nn))));
373
++              tmpReal->SetPixelIndex(k,j,(BYTE)cmax(0,cmin(255,(128 + grid[k][j].x*nn))));
374
++              tmpImag->SetPixelIndex(k,j,(BYTE)cmax(0,cmin(255,(128 + grid[k][j].y*nn))));
375
+           }
376
+       }
377
+   }
378
+@@ -1922,7 +1922,7 @@ bool CxImage::RepairChannel(CxImage *ch,
379
+ 
380
+           correction = ((1.0+iy*iy)*ixx - ix*iy*ixy + (1.0+ix*ix)*iyy)/(1.0+ix*ix+iy*iy);
381
+ 
382
+-          tmp.BlindSetPixelIndex(x,y,(BYTE)min(255,max(0,(xy0 + radius * correction + 0.5))));
383
++          tmp.BlindSetPixelIndex(x,y,(BYTE)cmin(255,cmax(0,(xy0 + radius * correction + 0.5))));
384
+       }
385
+   }
386
+ 
387
+@@ -1943,7 +1943,7 @@ bool CxImage::RepairChannel(CxImage *ch,
388
+ 
389
+           correction = ((1.0+iy*iy)*ixx - ix*iy*ixy + (1.0+ix*ix)*iyy)/(1.0+ix*ix+iy*iy);
390
+ 
391
+-          tmp.BlindSetPixelIndex(x,y,(BYTE)min(255,max(0,(xy0 + radius * correction + 0.5))));
392
++          tmp.BlindSetPixelIndex(x,y,(BYTE)cmin(255,cmax(0,(xy0 + radius * correction + 0.5))));
393
+       }
394
+   }
395
+   for (x=0;x<=w;x+=w){
396
+@@ -1963,7 +1963,7 @@ bool CxImage::RepairChannel(CxImage *ch,
397
+ 
398
+           correction = ((1.0+iy*iy)*ixx - ix*iy*ixy + (1.0+ix*ix)*iyy)/(1.0+ix*ix+iy*iy);
399
+ 
400
+-          tmp.BlindSetPixelIndex(x,y,(BYTE)min(255,max(0,(xy0 + radius * correction + 0.5))));
401
++          tmp.BlindSetPixelIndex(x,y,(BYTE)cmin(255,cmax(0,(xy0 + radius * correction + 0.5))));
402
+       }
403
+   }
404
+ 
405
+@@ -2621,8 +2621,8 @@ bool CxImage::SelectiveBlur(float radius
406
+   }
407
+ 
408
+   //build the difference mask
409
+-  BYTE thresh_dw = (BYTE)max( 0 ,(int)(128 - threshold));
410
+-  BYTE thresh_up = (BYTE)min(255,(int)(128 + threshold));
411
++  BYTE thresh_dw = (BYTE)cmax( 0 ,(int)(128 - threshold));
412
++  BYTE thresh_up = (BYTE)cmin(255,(int)(128 + threshold));
413
+   long kernel[]={-100,-100,-100,-100,801,-100,-100,-100,-100};
414
+   if (!Tmp.Filter(kernel,3,800,128)){
415
+       delete [] pPalette;
416
+@@ -2755,7 +2755,7 @@ bool CxImage::UnsharpMask(float radius /
417
+                   if (abs(diff) < threshold){
418
+                       dest_row[z] = cur_row[z];
419
+                   } else {
420
+-                      dest_row[z] = (BYTE)min(255, max(0,(int)(cur_row[z] + amount * diff)));
421
++                      dest_row[z] = (BYTE)cmin(255, cmax(0,(int)(cur_row[z] + amount * diff)));
422
+                   }
423
+               }
424
+           }
425
+@@ -2952,7 +2952,7 @@ bool CxImage::RedEyeRemove(float strengt
426
+               float a = 1.0f-5.0f*((float)((x-0.5f*(xmax+xmin))*(x-0.5f*(xmax+xmin))+(y-0.5f*(ymax+ymin))*(y-0.5f*(ymax+ymin))))/((float)((xmax-xmin)*(ymax-ymin)));
427
+               if (a<0) a=0;
428
+               color = BlindGetPixelColor(x,y);
429
+-              color.rgbRed = (BYTE)(a*min(color.rgbGreen,color.rgbBlue)+(1.0f-a)*color.rgbRed);
430
++              color.rgbRed = (BYTE)(a*cmin(color.rgbGreen,color.rgbBlue)+(1.0f-a)*color.rgbRed);
431
+               BlindSetPixelColor(x,y,color);
432
+           }
433
+       }
434
+@@ -2990,7 +2990,7 @@ bool CxImage::Saturate(const long satura
435
+   case 1:
436
+       {
437
+           for (int i=0;i<256;i++) {
438
+-              cTable[i] = (BYTE)max(0,min(255,(int)(i + saturation)));
439
++              cTable[i] = (BYTE)cmax(0,cmin(255,(int)(i + saturation)));
440
+           }
441
+           for(long y=ymin; y<ymax; y++){
442
+               info.nProgress = (long)(100*(y-ymin)/(ymax-ymin));
443
+@@ -3012,7 +3012,7 @@ bool CxImage::Saturate(const long satura
444
+   case 2:
445
+       {
446
+           for (int i=0;i<256;i++) {
447
+-              cTable[i] = (BYTE)max(0,min(255,(int)((i-128)*(100 + saturation)/100.0f + 128.5f)));
448
++              cTable[i] = (BYTE)cmax(0,cmin(255,(int)((i-128)*(100 + saturation)/100.0f + 128.5f)));
449
+           }
450
+           for(long y=ymin; y<ymax; y++){
451
+               info.nProgress = (long)(100*(y-ymin)/(ymax-ymin));
452
+@@ -3242,10 +3242,10 @@ int  CxImage::OptimalThreshold(long meth
453
+ 
454
+   long xmin,xmax,ymin,ymax;
455
+   if (pBox){
456
+-      xmin = max(pBox->left,0);
457
+-      xmax = min(pBox->right,head.biWidth);
458
+-      ymin = max(pBox->bottom,0);
459
+-      ymax = min(pBox->top,head.biHeight);
460
++      xmin = cmax(pBox->left,0);
461
++      xmax = cmin(pBox->right,head.biWidth);
462
++      ymin = cmax(pBox->bottom,0);
463
++      ymax = cmin(pBox->top,head.biHeight);
464
+   } else {
465
+       xmin = ymin = 0;
466
+       xmax = head.biWidth; ymax=head.biHeight;
467
+@@ -3463,7 +3463,7 @@ bool CxImage::AdaptiveThreshold(long met
468
+           r.top = r.bottom + nBoxSize;
469
+           int threshold = OptimalThreshold(method, &r, pContrastMask);
470
+           if (threshold <0) return false;
471
+-          mask.SetPixelIndex(x,y,(BYTE)max(0,min(255,nBias+((1.0f-fGlobalLocalBalance)*threshold + fGlobalLocalBalance*globalthreshold))));
472
++          mask.SetPixelIndex(x,y,(BYTE)cmax(0,cmin(255,nBias+((1.0f-fGlobalLocalBalance)*threshold + fGlobalLocalBalance*globalthreshold))));
473
+       }
474
+   }
475
+ 
476
+@@ -3490,10 +3490,6 @@ bool CxImage::AdaptiveThreshold(long met
477
+  * Note: nOpacity=0 && bSelectFilledArea=true act as a "magic wand"
478
+  * \return true if everything is ok
479
+  */
480
+-#if defined(XBMC) && !defined(_WIN32)
481
+-int max(int a, int b) { return a > b ? a : b; }
482
+-int min(int a, int b) { return a < b ? a : b; }
483
+-#endif
484
+ 
485
+ bool CxImage::FloodFill(const long xStart, const long yStart, const RGBQUAD cFillColor, const BYTE nTolerance,
486
+                       BYTE nOpacity, const bool bSelectFilledArea, const BYTE nSelectionLevel)
487
+@@ -3538,8 +3534,8 @@ bool CxImage::FloodFill(const long xStar
488
+   if (IsIndexed()){ //--- Generic indexed image, no tolerance OR Grayscale image with tolerance
489
+       BYTE idxRef = GetPixelIndex(xStart,yStart);
490
+       BYTE idxFill = GetNearestIndex(cFillColor);
491
+-      BYTE idxMin = (BYTE)min(255, max(0,(int)(idxRef - nTolerance)));
492
+-      BYTE idxMax = (BYTE)min(255, max(0,(int)(idxRef + nTolerance)));
493
++      BYTE idxMin = (BYTE)cmin(255, cmax(0,(int)(idxRef - nTolerance)));
494
++      BYTE idxMax = (BYTE)cmin(255, cmax(0,(int)(idxRef + nTolerance)));
495
+ 
496
+       while(!q.empty())
497
+       {
498
+@@ -3575,12 +3571,12 @@ bool CxImage::FloodFill(const long xStar
499
+   } else { //--- RGB image
500
+       RGBQUAD cRef = GetPixelColor(xStart,yStart);
501
+       RGBQUAD cRefMin, cRefMax;
502
+-      cRefMin.rgbRed   = (BYTE)min(255, max(0,(int)(cRef.rgbRed   - nTolerance)));
503
+-      cRefMin.rgbGreen = (BYTE)min(255, max(0,(int)(cRef.rgbGreen - nTolerance)));
504
+-      cRefMin.rgbBlue  = (BYTE)min(255, max(0,(int)(cRef.rgbBlue  - nTolerance)));
505
+-      cRefMax.rgbRed   = (BYTE)min(255, max(0,(int)(cRef.rgbRed   + nTolerance)));
506
+-      cRefMax.rgbGreen = (BYTE)min(255, max(0,(int)(cRef.rgbGreen + nTolerance)));
507
+-      cRefMax.rgbBlue  = (BYTE)min(255, max(0,(int)(cRef.rgbBlue  + nTolerance)));
508
++      cRefMin.rgbRed   = (BYTE)cmin(255, cmax(0,(int)(cRef.rgbRed   - nTolerance)));
509
++      cRefMin.rgbGreen = (BYTE)cmin(255, cmax(0,(int)(cRef.rgbGreen - nTolerance)));
510
++      cRefMin.rgbBlue  = (BYTE)cmin(255, cmax(0,(int)(cRef.rgbBlue  - nTolerance)));
511
++      cRefMax.rgbRed   = (BYTE)cmin(255, cmax(0,(int)(cRef.rgbRed   + nTolerance)));
512
++      cRefMax.rgbGreen = (BYTE)cmin(255, cmax(0,(int)(cRef.rgbGreen + nTolerance)));
513
++      cRefMax.rgbBlue  = (BYTE)cmin(255, cmax(0,(int)(cRef.rgbBlue  + nTolerance)));
514
+ 
515
+       while(!q.empty())
516
+       {
517
+--- a/lib/cximage-6.0/CxImage/ximage.cpp
518
++++ b/lib/cximage-6.0/CxImage/ximage.cpp
519
+@@ -460,7 +460,7 @@ bool CxImage::CreateFromArray(BYTE* pArr
520
+               src+=4;
521
+           }
522
+       } else {
523
+-          memcpy(dst,src,min(info.dwEffWidth,dwBytesperline));
524
++          memcpy(dst,src,cmin(info.dwEffWidth,dwBytesperline));
525
+       }
526
+   }
527
+   return true;
528
+@@ -500,7 +500,7 @@ bool CxImage::CreateFromMatrix(BYTE** pp
529
+                   src+=4;
530
+               }
531
+           } else {
532
+-              memcpy(dst,src,min(info.dwEffWidth,dwBytesperline));
533
++              memcpy(dst,src,cmin(info.dwEffWidth,dwBytesperline));
534
+           }
535
+       }
536
+   }
537
+--- a/lib/cximage-6.0/CxImage/ximagif.cpp
538
++++ b/lib/cximage-6.0/CxImage/ximagif.cpp
539
+@@ -478,7 +478,7 @@ bool CxImageGIF::Encode(CxFile * fp, CxI
540
+   ghost.EncodeHeader(fp);
541
+ 
542
+   if (m_loops!=1){
543
+-      ghost.SetLoops(max(0,m_loops-1));
544
++      ghost.SetLoops(cmax(0,m_loops-1));
545
+       ghost.EncodeLoopExtension(fp);
546
+   }
547
+ 
548
+@@ -1340,10 +1340,10 @@ void CxImageGIF::GetComment(char* sz_com
549
+ ////////////////////////////////////////////////////////////////////////////////
550
+ void CxImageGIF::GifMix(CxImage & imgsrc2, struct_image & imgdesc)
551
+ {
552
+-  long ymin = max(0,(long)(GetHeight()-imgdesc.t - imgdesc.h));
553
++  long ymin = cmax(0,(long)(GetHeight()-imgdesc.t - imgdesc.h));
554
+   long ymax = GetHeight()-imgdesc.t;
555
+   long xmin = imgdesc.l;
556
+-  long xmax = min(GetWidth(), (DWORD)(imgdesc.l + imgdesc.w));
557
++  long xmax = cmin(GetWidth(), (DWORD)(imgdesc.l + imgdesc.w));
558
+ 
559
+   long ibg2= imgsrc2.GetTransIndex();
560
+     BYTE i2;
561
+--- a/lib/cximage-6.0/CxImage/ximahist.cpp
562
++++ b/lib/cximage-6.0/CxImage/ximahist.cpp
563
+@@ -110,7 +110,7 @@ bool CxImage::HistogramStretch(long meth
564
+   // calculate LUT
565
+   BYTE lut[256];
566
+   for (x = 0; x <256; x++){
567
+-      lut[x] = (BYTE)max(0,min(255,(255 * (x - minc) / (maxc - minc))));
568
++      lut[x] = (BYTE)cmax(0,cmin(255,(255 * (x - minc) / (maxc - minc))));
569
+   }
570
+ 
571
+   for (y=0; y<head.biHeight; y++) {
572
+@@ -152,7 +152,7 @@ bool CxImage::HistogramStretch(long meth
573
+       // calculate LUT
574
+       BYTE lut[256];
575
+       for (x = 0; x <256; x++){
576
+-          lut[x] = (BYTE)max(0,min(255,(255 * (x - minc) / (maxc - minc))));
577
++          lut[x] = (BYTE)cmax(0,cmin(255,(255 * (x - minc) / (maxc - minc))));
578
+       }
579
+ 
580
+       // normalize image
581
+@@ -225,7 +225,7 @@ bool CxImage::HistogramStretch(long meth
582
+       BYTE range = maxR - minR;
583
+       if (range != 0) {
584
+           for (x = 0; x <256; x++){
585
+-              lutR[x] = (BYTE)max(0,min(255,(255 * (x - minR) / range)));
586
++              lutR[x] = (BYTE)cmax(0,cmin(255,(255 * (x - minR) / range)));
587
+           }
588
+       } else lutR[minR] = minR;
589
+ 
590
+@@ -233,7 +233,7 @@ bool CxImage::HistogramStretch(long meth
591
+       range = maxG - minG;
592
+       if (range != 0) {
593
+           for (x = 0; x <256; x++){
594
+-              lutG[x] = (BYTE)max(0,min(255,(255 * (x - minG) / range)));
595
++              lutG[x] = (BYTE)cmax(0,cmin(255,(255 * (x - minG) / range)));
596
+           }
597
+       } else lutG[minG] = minG;
598
+           
599
+@@ -241,7 +241,7 @@ bool CxImage::HistogramStretch(long meth
600
+       range = maxB - minB;
601
+       if (range != 0) {
602
+           for (x = 0; x <256; x++){
603
+-              lutB[x] = (BYTE)max(0,min(255,(255 * (x - minB) / range)));
604
++              lutB[x] = (BYTE)cmax(0,cmin(255,(255 * (x - minB) / range)));
605
+           }
606
+       } else lutB[minB] = minB;
607
+ 
608
+@@ -292,7 +292,7 @@ bool CxImage::HistogramStretch(long meth
609
+       // calculate LUT
610
+       BYTE lut[256];
611
+       for (x = 0; x <256; x++){
612
+-          lut[x] = (BYTE)max(0,min(255,(255 * (x - minc) / (maxc - minc))));
613
++          lut[x] = (BYTE)cmax(0,cmin(255,(255 * (x - minc) / (maxc - minc))));
614
+       }
615
+ 
616
+       for(y=0; y<head.biHeight; y++){
617
+--- a/lib/cximage-6.0/CxImage/ximaint.cpp
618
++++ b/lib/cximage-6.0/CxImage/ximaint.cpp
619
+@@ -26,8 +26,8 @@ void CxImage::OverflowCoordinates(long &
620
+   switch (ofMethod) {
621
+     case OM_REPEAT:
622
+       //clip coordinates
623
+-      x=max(x,0); x=min(x, head.biWidth-1);
624
+-      y=max(y,0); y=min(y, head.biHeight-1);
625
++      x=cmax(x,0); x=cmin(x, head.biWidth-1);
626
++      y=cmax(y,0); y=cmin(y, head.biHeight-1);
627
+       break;
628
+     case OM_WRAP:
629
+       //wrap coordinates
630
+@@ -59,8 +59,8 @@ void CxImage::OverflowCoordinates(float
631
+   switch (ofMethod) {
632
+     case OM_REPEAT:
633
+       //clip coordinates
634
+-      x=max(x,0); x=min(x, head.biWidth-1);
635
+-      y=max(y,0); y=min(y, head.biHeight-1);
636
++      x=cmax(x,0); x=cmin(x, head.biWidth-1);
637
++      y=cmax(y,0); y=cmin(y, head.biHeight-1);
638
+       break;
639
+     case OM_WRAP:
640
+       //wrap coordinates
641
+--- a/lib/cximage-6.0/CxImage/ximaiter.h
642
++++ b/lib/cximage-6.0/CxImage/ximaiter.h
643
+@@ -140,7 +140,7 @@ inline void CImageIterator::SetY(int y)
644
+ inline void CImageIterator::SetRow(BYTE *buf, int n)
645
+ {
646
+   if (n<0) n = (int)ima->GetEffWidth();
647
+-  else n = min(n,(int)ima->GetEffWidth());
648
++  else n = cmin(n,(int)ima->GetEffWidth());
649
+ 
650
+   if ((IterImage!=NULL)&&(buf!=NULL)&&(n>0)) memcpy(IterImage,buf,n);
651
+ }
652
+@@ -148,7 +148,7 @@ inline void CImageIterator::SetRow(BYTE
653
+ inline void CImageIterator::GetRow(BYTE *buf, int n)
654
+ {
655
+   if ((IterImage!=NULL)&&(buf!=NULL)&&(n>0))
656
+-      memcpy(buf,IterImage,min(n,(int)ima->GetEffWidth()));
657
++      memcpy(buf,IterImage,cmin(n,(int)ima->GetEffWidth()));
658
+ }
659
+ /////////////////////////////////////////////////////////////////////
660
+ inline BYTE* CImageIterator::GetRow()
661
+--- a/lib/cximage-6.0/CxImage/ximajpg.cpp
662
++++ b/lib/cximage-6.0/CxImage/ximajpg.cpp
663
+@@ -89,7 +89,7 @@ bool CxImageJPG::GetExifThumbnail(const
664
+     {
665
+       if (image.GetWidth() > 256 || image.GetHeight() > 256)
666
+       { // resize the image
667
+-//        float amount = 256.0f / max(image.GetWidth(), image.GetHeight());
668
++//        float amount = 256.0f / cmax(image.GetWidth(), image.GetHeight());
669
+ //        image.Resample((long)(image.GetWidth() * amount), (long)(image.GetHeight() * amount), 0);
670
+       }
671
+       if (m_exifinfo.Orientation != 1)
672
+--- a/lib/cximage-6.0/CxImage/ximapal.cpp
673
++++ b/lib/cximage-6.0/CxImage/ximapal.cpp
674
+@@ -398,8 +398,8 @@ void CxImage::RGBtoBGR(BYTE *buffer, int
675
+ {
676
+   if (buffer && (head.biClrUsed==0)){
677
+       BYTE temp;
678
+-      length = min(length,(int)info.dwEffWidth);
679
+-      length = min(length,(int)(3*head.biWidth));
680
++      length = cmin(length,(int)info.dwEffWidth);
681
++      length = cmin(length,(int)(3*head.biWidth));
682
+       for (int i=0;i<length;i+=3){
683
+           temp = buffer[i]; buffer[i] = buffer[i+2]; buffer[i+2] = temp;
684
+       }
685
+@@ -444,7 +444,7 @@ void CxImage::SetPalette(DWORD n, BYTE *
686
+   if (!g) g = r;
687
+   if (!b) b = g;
688
+   RGBQUAD* ppal=GetPalette();
689
+-  DWORD m=min(n,head.biClrUsed);
690
++  DWORD m=cmin(n,head.biClrUsed);
691
+   for (DWORD i=0; i<m;i++){
692
+       ppal[i].rgbRed=r[i];
693
+       ppal[i].rgbGreen=g[i];
694
+@@ -457,7 +457,7 @@ void CxImage::SetPalette(rgb_color *rgb,
695
+ {
696
+   if ((!rgb)||(pDib==NULL)||(head.biClrUsed==0)) return;
697
+   RGBQUAD* ppal=GetPalette();
698
+-  DWORD m=min(nColors,head.biClrUsed);
699
++  DWORD m=cmin(nColors,head.biClrUsed);
700
+   for (DWORD i=0; i<m;i++){
701
+       ppal[i].rgbRed=rgb[i].r;
702
+       ppal[i].rgbGreen=rgb[i].g;
703
+@@ -469,7 +469,7 @@ void CxImage::SetPalette(rgb_color *rgb,
704
+ void CxImage::SetPalette(RGBQUAD* pPal,DWORD nColors)
705
+ {
706
+   if ((pPal==NULL)||(pDib==NULL)||(head.biClrUsed==0)) return;
707
+-  memcpy(GetPalette(),pPal,min(GetPaletteSize(),nColors*sizeof(RGBQUAD)));
708
++  memcpy(GetPalette(),pPal,cmin(GetPaletteSize(),nColors*sizeof(RGBQUAD)));
709
+   info.last_c_isvalid = false;
710
+ }
711
+ ////////////////////////////////////////////////////////////////////////////////
712
+@@ -654,10 +654,10 @@ void CxImage::SetClrImportant(DWORD ncol
713
+ 
714
+   switch(head.biBitCount){
715
+   case 1:
716
+-      head.biClrImportant = min(ncolors,2);
717
++      head.biClrImportant = cmin(ncolors,2);
718
+       break;
719
+   case 4:
720
+-      head.biClrImportant = min(ncolors,16);
721
++      head.biClrImportant = cmin(ncolors,16);
722
+       break;
723
+   case 8:
724
+       head.biClrImportant = ncolors;
725
+--- a/lib/cximage-6.0/CxImage/ximapng.cpp
726
++++ b/lib/cximage-6.0/CxImage/ximapng.cpp
727
+@@ -206,9 +206,9 @@ bool CxImagePNG::Decode(CxFile *hFile)
728
+   } else SetGrayPalette(); //<DP> needed for grayscale PNGs
729
+   
730
+ #ifdef USE_NEW_LIBPNG_API
731
+-  int nshift = max(0,(_bit_depth>>3)-1)<<3;
732
++  int nshift = cmax(0,(_bit_depth>>3)-1)<<3;
733
+ #else
734
+-  int nshift = max(0,(info_ptr->bit_depth>>3)-1)<<3;
735
++  int nshift = cmax(0,(info_ptr->bit_depth>>3)-1)<<3;
736
+ #endif
737
+ 
738
+ #ifdef USE_NEW_LIBPNG_API
739
+@@ -255,10 +255,10 @@ bool CxImagePNG::Decode(CxFile *hFile)
740
+           if (pal){
741
+               DWORD ip;
742
+ #ifdef USE_NEW_LIBPNG_API
743
+-              for (ip=0;ip<min(head.biClrUsed,(unsigned long)_num_trans);ip++)
744
++              for (ip=0;ip<cmin(head.biClrUsed,(unsigned long)_num_trans);ip++)
745
+                   pal[ip].rgbReserved=_trans_alpha[ip];
746
+ #else
747
+-              for (ip=0;ip<min(head.biClrUsed,(unsigned long)info_ptr->num_trans);ip++)
748
++              for (ip=0;ip<cmin(head.biClrUsed,(unsigned long)info_ptr->num_trans);ip++)
749
+ #if PNG_LIBPNG_VER > 10399
750
+                   pal[ip].rgbReserved=info_ptr->trans_alpha[ip];
751
+ #else
752
+@@ -737,9 +737,9 @@ bool CxImagePNG::Encode(CxFile *hFile)
753
+ #endif // CXIMAGE_SUPPORT_ALPHA   // <vho>
754
+ 
755
+ #ifdef USE_NEW_LIBPNG_API
756
+-  int row_size = max(info.dwEffWidth, (_width * _channels * _bit_depth / 8));
757
++  int row_size = cmax(info.dwEffWidth, (_width * _channels * _bit_depth / 8));
758
+ #else
759
+-  int row_size = max(info.dwEffWidth, info_ptr->width*info_ptr->channels*(info_ptr->bit_depth/8));
760
++  int row_size = cmax(info.dwEffWidth, info_ptr->width*info_ptr->channels*(info_ptr->bit_depth/8));
761
+   info_ptr->rowbytes = row_size;
762
+ #endif
763
+   BYTE *row_pointers = new BYTE[row_size];
764
+--- a/lib/cximage-6.0/CxImage/ximaraw.cpp
765
++++ b/lib/cximage-6.0/CxImage/ximaraw.cpp
766
+@@ -216,7 +216,7 @@ bool CxImageRAW::Decode(CxFile *hFile)
767
+ 
768
+       DWORD size = dcr.width * (dcr.colors*dcr.opt.output_bps/8);
769
+       RGBtoBGR(ppm,size);
770
+-      memcpy(GetBits(dcr.height - 1 - row), ppm, min(size,GetEffWidth()));
771
++      memcpy(GetBits(dcr.height - 1 - row), ppm, cmin(size,GetEffWidth()));
772
+   }
773
+   free (ppm);
774
+ 
775
+@@ -298,7 +298,7 @@ bool CxImageRAW::GetExifThumbnail(const
776
+           // Resizing.
777
+               if (image.GetWidth() > 256 || image.GetHeight() > 256)
778
+           {
779
+-              float amount = 256.0f / max(image.GetWidth(), image.GetHeight());
780
++              float amount = 256.0f / cmax(image.GetWidth(), image.GetHeight());
781
+               image.Resample((long)(image.GetWidth() * amount), (long)(image.GetHeight() * amount), 0);
782
+           }
783
+           
784
+--- a/lib/cximage-6.0/CxImage/ximasel.cpp
785
++++ b/lib/cximage-6.0/CxImage/ximasel.cpp
786
+@@ -113,15 +113,15 @@ bool CxImage::SelectionAddRect(RECT r, B
787
+   if (r.left<r.right) {r2.left=r.left; r2.right=r.right; } else {r2.left=r.right ; r2.right=r.left; }
788
+   if (r.bottom<r.top) {r2.bottom=r.bottom; r2.top=r.top; } else {r2.bottom=r.top ; r2.top=r.bottom; }
789
+ 
790
+-  if (info.rSelectionBox.top <= r2.top) info.rSelectionBox.top = max(0L,min(head.biHeight,r2.top+1));
791
+-  if (info.rSelectionBox.left > r2.left) info.rSelectionBox.left = max(0L,min(head.biWidth,r2.left));
792
+-  if (info.rSelectionBox.right <= r2.right) info.rSelectionBox.right = max(0L,min(head.biWidth,r2.right+1));
793
+-  if (info.rSelectionBox.bottom > r2.bottom) info.rSelectionBox.bottom = max(0L,min(head.biHeight,r2.bottom));
794
+-
795
+-  long ymin = max(0L,min(head.biHeight,r2.bottom));
796
+-  long ymax = max(0L,min(head.biHeight,r2.top+1));
797
+-  long xmin = max(0L,min(head.biWidth,r2.left));
798
+-  long xmax = max(0L,min(head.biWidth,r2.right+1));
799
++  if (info.rSelectionBox.top <= r2.top) info.rSelectionBox.top = cmax(0L,cmin(head.biHeight,r2.top+1));
800
++  if (info.rSelectionBox.left > r2.left) info.rSelectionBox.left = cmax(0L,cmin(head.biWidth,r2.left));
801
++  if (info.rSelectionBox.right <= r2.right) info.rSelectionBox.right = cmax(0L,cmin(head.biWidth,r2.right+1));
802
++  if (info.rSelectionBox.bottom > r2.bottom) info.rSelectionBox.bottom = cmax(0L,cmin(head.biHeight,r2.bottom));
803
++
804
++  long ymin = cmax(0L,cmin(head.biHeight,r2.bottom));
805
++  long ymax = cmax(0L,cmin(head.biHeight,r2.top+1));
806
++  long xmin = cmax(0L,cmin(head.biWidth,r2.left));
807
++  long xmax = cmax(0L,cmin(head.biWidth,r2.right+1));
808
+ 
809
+   for (long y=ymin; y<ymax; y++)
810
+       memset(pSelection + xmin + y * head.biWidth, level, xmax-xmin);
811
+@@ -144,18 +144,18 @@ bool CxImage::SelectionAddEllipse(RECT r
812
+   long xcenter = (r.right + r.left)/2;
813
+   long ycenter = (r.top + r.bottom)/2;
814
+ 
815
+-  if (info.rSelectionBox.left > (xcenter - xradius)) info.rSelectionBox.left = max(0L,min(head.biWidth,(xcenter - xradius)));
816
+-  if (info.rSelectionBox.right <= (xcenter + xradius)) info.rSelectionBox.right = max(0L,min(head.biWidth,(xcenter + xradius + 1)));
817
+-  if (info.rSelectionBox.bottom > (ycenter - yradius)) info.rSelectionBox.bottom = max(0L,min(head.biHeight,(ycenter - yradius)));
818
+-  if (info.rSelectionBox.top <= (ycenter + yradius)) info.rSelectionBox.top = max(0L,min(head.biHeight,(ycenter + yradius + 1)));
819
+-
820
+-  long xmin = max(0L,min(head.biWidth,xcenter - xradius));
821
+-  long xmax = max(0L,min(head.biWidth,xcenter + xradius + 1));
822
+-  long ymin = max(0L,min(head.biHeight,ycenter - yradius));
823
+-  long ymax = max(0L,min(head.biHeight,ycenter + yradius + 1));
824
++  if (info.rSelectionBox.left > (xcenter - xradius)) info.rSelectionBox.left = cmax(0L,cmin(head.biWidth,(xcenter - xradius)));
825
++  if (info.rSelectionBox.right <= (xcenter + xradius)) info.rSelectionBox.right = cmax(0L,cmin(head.biWidth,(xcenter + xradius + 1)));
826
++  if (info.rSelectionBox.bottom > (ycenter - yradius)) info.rSelectionBox.bottom = cmax(0L,cmin(head.biHeight,(ycenter - yradius)));
827
++  if (info.rSelectionBox.top <= (ycenter + yradius)) info.rSelectionBox.top = cmax(0L,cmin(head.biHeight,(ycenter + yradius + 1)));
828
++
829
++  long xmin = cmax(0L,cmin(head.biWidth,xcenter - xradius));
830
++  long xmax = cmax(0L,cmin(head.biWidth,xcenter + xradius + 1));
831
++  long ymin = cmax(0L,cmin(head.biHeight,ycenter - yradius));
832
++  long ymax = cmax(0L,cmin(head.biHeight,ycenter + yradius + 1));
833
+ 
834
+   long y,yo;
835
+-  for (y=ymin; y<min(ycenter,ymax); y++){
836
++  for (y=ymin; y<cmin(ycenter,ymax); y++){
837
+       for (long x=xmin; x<xmax; x++){
838
+           yo = (long)(ycenter - yradius * sqrt(1-pow((float)(x - xcenter)/(float)xradius,2)));
839
+           if (yo<y) pSelection[x + y * head.biWidth] = level;
840
+@@ -268,10 +268,10 @@ bool CxImage::SelectionAddPolygon(POINT
841
+       RECT r2;
842
+       if (current->x < next->x) {r2.left=current->x; r2.right=next->x; } else {r2.left=next->x ; r2.right=current->x; }
843
+       if (current->y < next->y) {r2.bottom=current->y; r2.top=next->y; } else {r2.bottom=next->y ; r2.top=current->y; }
844
+-      if (localbox.top < r2.top) localbox.top = max(0L,min(head.biHeight-1,r2.top+1));
845
+-      if (localbox.left > r2.left) localbox.left = max(0L,min(head.biWidth-1,r2.left-1));
846
+-      if (localbox.right < r2.right) localbox.right = max(0L,min(head.biWidth-1,r2.right+1));
847
+-      if (localbox.bottom > r2.bottom) localbox.bottom = max(0L,min(head.biHeight-1,r2.bottom-1));
848
++      if (localbox.top < r2.top) localbox.top = cmax(0L,cmin(head.biHeight-1,r2.top+1));
849
++      if (localbox.left > r2.left) localbox.left = cmax(0L,cmin(head.biWidth-1,r2.left-1));
850
++      if (localbox.right < r2.right) localbox.right = cmax(0L,cmin(head.biWidth-1,r2.right+1));
851
++      if (localbox.bottom > r2.bottom) localbox.bottom = cmax(0L,cmin(head.biHeight-1,r2.bottom-1));
852
+ 
853
+       i++;
854
+   }
855
+@@ -385,10 +385,10 @@ bool CxImage::SelectionAddPolygon(POINT
856
+       for (x=localbox.left; x<=localbox.right; x++)
857
+           if (plocal[x + yoffset]!=1) pSelection[x + yoffset]=level;
858
+   }
859
+-  if (info.rSelectionBox.top <= localbox.top) info.rSelectionBox.top = min(head.biHeight,localbox.top + 1);
860
+-  if (info.rSelectionBox.left > localbox.left) info.rSelectionBox.left = min(head.biWidth,localbox.left);
861
+-  if (info.rSelectionBox.right <= localbox.right) info.rSelectionBox.right = min(head.biWidth,localbox.right + 1);
862
+-  if (info.rSelectionBox.bottom > localbox.bottom) info.rSelectionBox.bottom = min(head.biHeight,localbox.bottom);
863
++  if (info.rSelectionBox.top <= localbox.top) info.rSelectionBox.top = cmin(head.biHeight,localbox.top + 1);
864
++  if (info.rSelectionBox.left > localbox.left) info.rSelectionBox.left = cmin(head.biWidth,localbox.left);
865
++  if (info.rSelectionBox.right <= localbox.right) info.rSelectionBox.right = cmin(head.biWidth,localbox.right + 1);
866
++  if (info.rSelectionBox.bottom > localbox.bottom) info.rSelectionBox.bottom = cmin(head.biHeight,localbox.bottom);
867
+ 
868
+   free(plocal);
869
+   free(pix);
870
+--- a/lib/cximage-6.0/CxImage/ximath.cpp
871
++++ b/lib/cximage-6.0/CxImage/ximath.cpp
872
+@@ -64,10 +64,10 @@ CxRect2 CxRect2::CrossSection(CxRect2 co
873
+  */
874
+ {
875
+   CxRect2 cs;
876
+-  cs.botLeft.x=max(botLeft.x, r2.botLeft.x);
877
+-  cs.botLeft.y=max(botLeft.y, r2.botLeft.y);
878
+-  cs.topRight.x=min(topRight.x, r2.topRight.x);
879
+-  cs.topRight.y=min(topRight.y, r2.topRight.y);
880
++  cs.botLeft.x=cmax(botLeft.x, r2.botLeft.x);
881
++  cs.botLeft.y=cmax(botLeft.y, r2.botLeft.y);
882
++  cs.topRight.x=cmin(topRight.x, r2.topRight.x);
883
++  cs.topRight.y=cmin(topRight.y, r2.topRight.y);
884
+   if (cs.botLeft.x<=cs.topRight.x && cs.botLeft.y<=cs.topRight.y) {
885
+     return cs;
886
+   } else {
887
+--- a/lib/cximage-6.0/CxImage/ximatif.cpp
888
++++ b/lib/cximage-6.0/CxImage/ximatif.cpp
889
+@@ -470,9 +470,9 @@ bool CxImageTIF::Decode(CxFile * hFile)
890
+                       if ( cb > 0.00304 ) cb = 1.055 * pow(cb,0.41667) - 0.055;
891
+                           else            cb = 12.92 * cb;
892
+ 
893
+-                      c.rgbRed  =(BYTE)max(0,min(255,(int)(cr*255)));
894
+-                      c.rgbGreen=(BYTE)max(0,min(255,(int)(cg*255)));
895
+-                      c.rgbBlue =(BYTE)max(0,min(255,(int)(cb*255)));
896
++                      c.rgbRed  =(BYTE)cmax(0,cmin(255,(int)(cr*255)));
897
++                      c.rgbGreen=(BYTE)cmax(0,cmin(255,(int)(cg*255)));
898
++                      c.rgbBlue =(BYTE)cmax(0,cmin(255,(int)(cb*255)));
899
+ 
900
+                       SetPixelColor(xi,yi,c);
901
+ #if CXIMAGE_SUPPORT_ALPHA
902
+--- a/lib/cximage-6.0/CxImage/ximatran.cpp
903
++++ b/lib/cximage-6.0/CxImage/ximatran.cpp
904
+@@ -302,12 +302,12 @@ bool CxImage::RotateLeft(CxImage* iDst)
905
+           for (ys = 0; ys < newHeight; ys+=RBLOCK) {
906
+               if (head.biBitCount==24) {
907
+                   //RGB24 optimized pixel access:
908
+-                  for (x = xs; x < min(newWidth, xs+RBLOCK); x++){    //do rotation
909
++                  for (x = xs; x < cmin(newWidth, xs+RBLOCK); x++){    //do rotation
910
+                       info.nProgress = (long)(100*x/newWidth);
911
+                       x2=newWidth-x-1;
912
+                       dstPtr = (BYTE*) imgDest.BlindGetPixelPointer(x,ys);
913
+                       srcPtr = (BYTE*) BlindGetPixelPointer(ys, x2);
914
+-                      for (y = ys; y < min(newHeight, ys+RBLOCK); y++){
915
++                      for (y = ys; y < cmin(newHeight, ys+RBLOCK); y++){
916
+                           //imgDest.SetPixelColor(x, y, GetPixelColor(y, x2));
917
+                           *(dstPtr) = *(srcPtr);
918
+                           *(dstPtr+1) = *(srcPtr+1);
919
+@@ -318,19 +318,19 @@ bool CxImage::RotateLeft(CxImage* iDst)
920
+                   }//for x
921
+               } else {
922
+                   //anything else than 24bpp (and 1bpp): palette
923
+-                  for (x = xs; x < min(newWidth, xs+RBLOCK); x++){
924
++                  for (x = xs; x < cmin(newWidth, xs+RBLOCK); x++){
925
+                       info.nProgress = (long)(100*x/newWidth); //<Anatoly Ivasyuk>
926
+                       x2=newWidth-x-1;
927
+-                      for (y = ys; y < min(newHeight, ys+RBLOCK); y++){
928
++                      for (y = ys; y < cmin(newHeight, ys+RBLOCK); y++){
929
+                           imgDest.SetPixelIndex(x, y, BlindGetPixelIndex(y, x2));
930
+                       }//for y
931
+                   }//for x
932
+               }//if (version selection)
933
+ #if CXIMAGE_SUPPORT_ALPHA
934
+               if (AlphaIsValid()) {
935
+-                  for (x = xs; x < min(newWidth, xs+RBLOCK); x++){
936
++                  for (x = xs; x < cmin(newWidth, xs+RBLOCK); x++){
937
+                       x2=newWidth-x-1;
938
+-                      for (y = ys; y < min(newHeight, ys+RBLOCK); y++){
939
++                      for (y = ys; y < cmin(newHeight, ys+RBLOCK); y++){
940
+                           imgDest.AlphaSet(x,y,BlindAlphaGet(y, x2));
941
+                       }//for y
942
+                   }//for x
943
+@@ -343,9 +343,9 @@ bool CxImage::RotateLeft(CxImage* iDst)
944
+                   imgDest.info.rSelectionBox.right = newWidth-info.rSelectionBox.bottom;
945
+                   imgDest.info.rSelectionBox.bottom = info.rSelectionBox.left;
946
+                   imgDest.info.rSelectionBox.top = info.rSelectionBox.right;
947
+-                  for (x = xs; x < min(newWidth, xs+RBLOCK); x++){
948
++                  for (x = xs; x < cmin(newWidth, xs+RBLOCK); x++){
949
+                       x2=newWidth-x-1;
950
+-                      for (y = ys; y < min(newHeight, ys+RBLOCK); y++){
951
++                      for (y = ys; y < cmin(newHeight, ys+RBLOCK); y++){
952
+                           imgDest.SelectionSet(x,y,BlindSelectionGet(y, x2));
953
+                       }//for y
954
+                   }//for x
955
+@@ -447,12 +447,12 @@ bool CxImage::RotateRight(CxImage* iDst)
956
+           for (ys = 0; ys < newHeight; ys+=RBLOCK) {
957
+               if (head.biBitCount==24) {
958
+                   //RGB24 optimized pixel access:
959
+-                  for (y = ys; y < min(newHeight, ys+RBLOCK); y++){
960
++                  for (y = ys; y < cmin(newHeight, ys+RBLOCK); y++){
961
+                       info.nProgress = (long)(100*y/newHeight); //<Anatoly Ivasyuk>
962
+                       y2=newHeight-y-1;
963
+                       dstPtr = (BYTE*) imgDest.BlindGetPixelPointer(xs,y);
964
+                       srcPtr = (BYTE*) BlindGetPixelPointer(y2, xs);
965
+-                      for (x = xs; x < min(newWidth, xs+RBLOCK); x++){
966
++                      for (x = xs; x < cmin(newWidth, xs+RBLOCK); x++){
967
+                           //imgDest.SetPixelColor(x, y, GetPixelColor(y2, x));
968
+                           *(dstPtr) = *(srcPtr);
969
+                           *(dstPtr+1) = *(srcPtr+1);
970
+@@ -463,19 +463,19 @@ bool CxImage::RotateRight(CxImage* iDst)
971
+                   }//for y
972
+               } else {
973
+                   //anything else than BW & RGB24: palette
974
+-                  for (y = ys; y < min(newHeight, ys+RBLOCK); y++){
975
++                  for (y = ys; y < cmin(newHeight, ys+RBLOCK); y++){
976
+                       info.nProgress = (long)(100*y/newHeight); //<Anatoly Ivasyuk>
977
+                       y2=newHeight-y-1;
978
+-                      for (x = xs; x < min(newWidth, xs+RBLOCK); x++){
979
++                      for (x = xs; x < cmin(newWidth, xs+RBLOCK); x++){
980
+                           imgDest.SetPixelIndex(x, y, BlindGetPixelIndex(y2, x));
981
+                       }//for x
982
+                   }//for y
983
+               }//if
984
+ #if CXIMAGE_SUPPORT_ALPHA
985
+               if (AlphaIsValid()){
986
+-                  for (y = ys; y < min(newHeight, ys+RBLOCK); y++){
987
++                  for (y = ys; y < cmin(newHeight, ys+RBLOCK); y++){
988
+                       y2=newHeight-y-1;
989
+-                      for (x = xs; x < min(newWidth, xs+RBLOCK); x++){
990
++                      for (x = xs; x < cmin(newWidth, xs+RBLOCK); x++){
991
+                           imgDest.AlphaSet(x,y,BlindAlphaGet(y2, x));
992
+                       }//for x
993
+                   }//for y
994
+@@ -488,9 +488,9 @@ bool CxImage::RotateRight(CxImage* iDst)
995
+                   imgDest.info.rSelectionBox.right = info.rSelectionBox.top;
996
+                   imgDest.info.rSelectionBox.bottom = newHeight-info.rSelectionBox.right;
997
+                   imgDest.info.rSelectionBox.top = newHeight-info.rSelectionBox.left;
998
+-                  for (y = ys; y < min(newHeight, ys+RBLOCK); y++){
999
++                  for (y = ys; y < cmin(newHeight, ys+RBLOCK); y++){
1000
+                       y2=newHeight-y-1;
1001
+-                      for (x = xs; x < min(newWidth, xs+RBLOCK); x++){
1002
++                      for (x = xs; x < cmin(newWidth, xs+RBLOCK); x++){
1003
+                           imgDest.SelectionSet(x,y,BlindSelectionGet(y2, x));
1004
+                       }//for x
1005
+                   }//for y
1006
+@@ -608,10 +608,10 @@ bool CxImage::Rotate(float angle, CxImag
1007
+   newP4.x = (float)(p4.x*cos_angle - p4.y*sin_angle);
1008
+   newP4.y = (float)(p4.x*sin_angle + p4.y*cos_angle);
1009
+ 
1010
+-  leftTop.x = min(min(newP1.x,newP2.x),min(newP3.x,newP4.x));
1011
+-  leftTop.y = min(min(newP1.y,newP2.y),min(newP3.y,newP4.y));
1012
+-  rightBottom.x = max(max(newP1.x,newP2.x),max(newP3.x,newP4.x));
1013
+-  rightBottom.y = max(max(newP1.y,newP2.y),max(newP3.y,newP4.y));
1014
++  leftTop.x = cmin(cmin(newP1.x,newP2.x),cmin(newP3.x,newP4.x));
1015
++  leftTop.y = cmin(cmin(newP1.y,newP2.y),cmin(newP3.y,newP4.y));
1016
++  rightBottom.x = cmax(cmax(newP1.x,newP2.x),cmax(newP3.x,newP4.x));
1017
++  rightBottom.y = cmax(cmax(newP1.y,newP2.y),cmax(newP3.y,newP4.y));
1018
+   leftBottom.x = leftTop.x;
1019
+   leftBottom.y = rightBottom.y;
1020
+   rightTop.x = rightBottom.x;
1021
+@@ -740,10 +740,10 @@ bool CxImage::Rotate2(float angle,
1022
+   }//if
1023
+ 
1024
+   //(read new dimensions from location of corners)
1025
+-  float minx = (float) min(min(newp[0].x,newp[1].x),min(newp[2].x,newp[3].x));
1026
+-  float miny = (float) min(min(newp[0].y,newp[1].y),min(newp[2].y,newp[3].y));
1027
+-  float maxx = (float) max(max(newp[0].x,newp[1].x),max(newp[2].x,newp[3].x));
1028
+-  float maxy = (float) max(max(newp[0].y,newp[1].y),max(newp[2].y,newp[3].y));
1029
++  float minx = (float) cmin(cmin(newp[0].x,newp[1].x),cmin(newp[2].x,newp[3].x));
1030
++  float miny = (float) cmin(cmin(newp[0].y,newp[1].y),cmin(newp[2].y,newp[3].y));
1031
++  float maxx = (float) cmax(cmax(newp[0].x,newp[1].x),cmax(newp[2].x,newp[3].x));
1032
++  float maxy = (float) cmax(cmax(newp[0].y,newp[1].y),cmax(newp[2].y,newp[3].y));
1033
+   int newWidth = (int) floor(maxx-minx+0.5f);
1034
+   int newHeight= (int) floor(maxy-miny+0.5f);
1035
+   float ssx=((maxx+minx)- ((float) newWidth-1))/2.0f;   //start for x
1036
+@@ -1003,12 +1003,12 @@ bool CxImage::Resample(long newx, long n
1037
+               if (info.nEscape) break;
1038
+               fY = y * yScale;
1039
+               ifY = (int)fY;
1040
+-              ifY1 = min(ymax, ifY+1);
1041
++              ifY1 = cmin(ymax, ifY+1);
1042
+               dy = fY - ifY;
1043
+               for(long x=0; x<newx; x++){
1044
+                   fX = x * xScale;
1045
+                   ifX = (int)fX;
1046
+-                  ifX1 = min(xmax, ifX+1);
1047
++                  ifX1 = cmin(xmax, ifX+1);
1048
+                   dx = fX - ifX;
1049
+                   // Interpolate using the four nearest pixels in the source
1050
+                   if (head.biClrUsed){
1051
+@@ -1328,9 +1328,9 @@ bool CxImage::DecreaseBpp(DWORD nbit, bo
1052
+               eb=(long)c.rgbBlue - (long)ce.rgbBlue;
1053
+ 
1054
+               c = GetPixelColor(x+1,y);
1055
+-              c.rgbRed = (BYTE)min(255L,max(0L,(long)c.rgbRed + ((er*7)/16)));
1056
+-              c.rgbGreen = (BYTE)min(255L,max(0L,(long)c.rgbGreen + ((eg*7)/16)));
1057
+-              c.rgbBlue = (BYTE)min(255L,max(0L,(long)c.rgbBlue + ((eb*7)/16)));
1058
++              c.rgbRed = (BYTE)cmin(255L,cmax(0L,(long)c.rgbRed + ((er*7)/16)));
1059
++              c.rgbGreen = (BYTE)cmin(255L,cmax(0L,(long)c.rgbGreen + ((eg*7)/16)));
1060
++              c.rgbBlue = (BYTE)cmin(255L,cmax(0L,(long)c.rgbBlue + ((eb*7)/16)));
1061
+               SetPixelColor(x+1,y,c);
1062
+               int coeff=1;
1063
+               for(int i=-1; i<2; i++){
1064
+@@ -1343,9 +1343,9 @@ bool CxImage::DecreaseBpp(DWORD nbit, bo
1065
+                       coeff=1; break;
1066
+                   }
1067
+                   c = GetPixelColor(x+i,y+1);
1068
+-                  c.rgbRed = (BYTE)min(255L,max(0L,(long)c.rgbRed + ((er * coeff)/16)));
1069
+-                  c.rgbGreen = (BYTE)min(255L,max(0L,(long)c.rgbGreen + ((eg * coeff)/16)));
1070
+-                  c.rgbBlue = (BYTE)min(255L,max(0L,(long)c.rgbBlue + ((eb * coeff)/16)));
1071
++                  c.rgbRed = (BYTE)cmin(255L,cmax(0L,(long)c.rgbRed + ((er * coeff)/16)));
1072
++                  c.rgbGreen = (BYTE)cmin(255L,cmax(0L,(long)c.rgbGreen + ((eg * coeff)/16)));
1073
++                  c.rgbBlue = (BYTE)cmin(255L,cmax(0L,(long)c.rgbBlue + ((eb * coeff)/16)));
1074
+                   SetPixelColor(x+i,y+1,c);
1075
+               }
1076
+           }
1077
+@@ -1566,10 +1566,10 @@ bool CxImage::Dither(long method)
1078
+               }
1079
+ 
1080
+               nlevel = GetPixelIndex(x + 1, y) + (error * 8) / TotalCoeffSum;
1081
+-              level = (BYTE)min(255, max(0, (int)nlevel));
1082
++              level = (BYTE)cmin(255, cmax(0, (int)nlevel));
1083
+               SetPixelIndex(x + 1, y, level);
1084
+               nlevel = GetPixelIndex(x + 2, y) + (error * 4) / TotalCoeffSum;
1085
+-              level = (BYTE)min(255, max(0, (int)nlevel));
1086
++              level = (BYTE)cmin(255, cmax(0, (int)nlevel));
1087
+               SetPixelIndex(x + 2, y, level);
1088
+               int i;
1089
+               for (i = -2; i < 3; i++) {
1090
+@@ -1591,7 +1591,7 @@ bool CxImage::Dither(long method)
1091
+                       break;
1092
+                   }
1093
+                   nlevel = GetPixelIndex(x + i, y + 1) + (error * coeff) / TotalCoeffSum;
1094
+-                  level = (BYTE)min(255, max(0, (int)nlevel));
1095
++                  level = (BYTE)cmin(255, cmax(0, (int)nlevel));
1096
+                   SetPixelIndex(x + i, y + 1, level);
1097
+               }
1098
+           }
1099
+@@ -1620,10 +1620,10 @@ bool CxImage::Dither(long method)
1100
+               }
1101
+ 
1102
+               nlevel = GetPixelIndex(x + 1, y) + (error * 8) / TotalCoeffSum;
1103
+-              level = (BYTE)min(255, max(0, (int)nlevel));
1104
++              level = (BYTE)cmin(255, cmax(0, (int)nlevel));
1105
+               SetPixelIndex(x + 1, y, level);
1106
+               nlevel = GetPixelIndex(x + 2, y) + (error * 4) / TotalCoeffSum;
1107
+-              level = (BYTE)min(255, max(0, (int)nlevel));
1108
++              level = (BYTE)cmin(255, cmax(0, (int)nlevel));
1109
+               SetPixelIndex(x + 2, y, level);
1110
+               int i;
1111
+               for (i = -2; i < 3; i++) {
1112
+@@ -1645,7 +1645,7 @@ bool CxImage::Dither(long method)
1113
+                       break;
1114
+                   }
1115
+                   nlevel = GetPixelIndex(x + i, y + 1) + (error * coeff) / TotalCoeffSum;
1116
+-                  level = (BYTE)min(255, max(0, (int)nlevel));
1117
++                  level = (BYTE)cmin(255, cmax(0, (int)nlevel));
1118
+                   SetPixelIndex(x + i, y + 1, level);
1119
+               }
1120
+               for (i = -2; i < 3; i++) {
1121
+@@ -1667,7 +1667,7 @@ bool CxImage::Dither(long method)
1122
+                       break;
1123
+                   }
1124
+                   nlevel = GetPixelIndex(x + i, y + 2) + (error * coeff) / TotalCoeffSum;
1125
+-                  level = (BYTE)min(255, max(0, (int)nlevel));
1126
++                  level = (BYTE)cmin(255, cmax(0, (int)nlevel));
1127
+                   SetPixelIndex(x + i, y + 2, level);
1128
+               }
1129
+           }
1130
+@@ -1696,10 +1696,10 @@ bool CxImage::Dither(long method)
1131
+               }
1132
+ 
1133
+               nlevel = GetPixelIndex(x + 1, y) + (error * 7) / TotalCoeffSum;
1134
+-              level = (BYTE)min(255, max(0, (int)nlevel));
1135
++              level = (BYTE)cmin(255, cmax(0, (int)nlevel));
1136
+               SetPixelIndex(x + 1, y, level);
1137
+               nlevel = GetPixelIndex(x + 2, y) + (error * 5) / TotalCoeffSum;
1138
+-              level = (BYTE)min(255, max(0, (int)nlevel));
1139
++              level = (BYTE)cmin(255, cmax(0, (int)nlevel));
1140
+               SetPixelIndex(x + 2, y, level);
1141
+               int i;
1142
+               for (i = -2; i < 3; i++) {
1143
+@@ -1721,7 +1721,7 @@ bool CxImage::Dither(long method)
1144
+                       break;
1145
+                   }
1146
+                   nlevel = GetPixelIndex(x + i, y + 1) + (error * coeff) / TotalCoeffSum;
1147
+-                  level = (BYTE)min(255, max(0, (int)nlevel));
1148
++                  level = (BYTE)cmin(255, cmax(0, (int)nlevel));
1149
+                   SetPixelIndex(x + i, y + 1, level);
1150
+               }
1151
+               for (i = -2; i < 3; i++) {
1152
+@@ -1743,7 +1743,7 @@ bool CxImage::Dither(long method)
1153
+                       break;
1154
+                   }
1155
+                   nlevel = GetPixelIndex(x + i, y + 2) + (error * coeff) / TotalCoeffSum;
1156
+-                  level = (BYTE)min(255, max(0, (int)nlevel));
1157
++                  level = (BYTE)cmin(255, cmax(0, (int)nlevel));
1158
+                   SetPixelIndex(x + i, y + 2, level);
1159
+               }
1160
+           }
1161
+@@ -1772,10 +1772,10 @@ bool CxImage::Dither(long method)
1162
+               }
1163
+ 
1164
+               nlevel = GetPixelIndex(x + 1, y) + (error * 5) / TotalCoeffSum;
1165
+-              level = (BYTE)min(255, max(0, (int)nlevel));
1166
++              level = (BYTE)cmin(255, cmax(0, (int)nlevel));
1167
+               SetPixelIndex(x + 1, y, level);
1168
+               nlevel = GetPixelIndex(x + 2, y) + (error * 3) / TotalCoeffSum;
1169
+-              level = (BYTE)min(255, max(0, (int)nlevel));
1170
++              level = (BYTE)cmin(255, cmax(0, (int)nlevel));
1171
+               SetPixelIndex(x + 2, y, level);
1172
+               int i;
1173
+               for (i = -2; i < 3; i++) {
1174
+@@ -1797,7 +1797,7 @@ bool CxImage::Dither(long method)
1175
+                       break;
1176
+                   }
1177
+                   nlevel = GetPixelIndex(x + i, y + 1) + (error * coeff) / TotalCoeffSum;
1178
+-                  level = (BYTE)min(255, max(0, (int)nlevel));
1179
++                  level = (BYTE)cmin(255, cmax(0, (int)nlevel));
1180
+                   SetPixelIndex(x + i, y + 1, level);
1181
+               }
1182
+               for (i = -1; i < 2; i++) {
1183
+@@ -1813,7 +1813,7 @@ bool CxImage::Dither(long method)
1184
+                       break;
1185
+                   }
1186
+                   nlevel = GetPixelIndex(x + i, y + 2) + (error * coeff) / TotalCoeffSum;
1187
+-                  level = (BYTE)min(255, max(0, (int)nlevel));
1188
++                  level = (BYTE)cmin(255, cmax(0, (int)nlevel));
1189
+                   SetPixelIndex(x + i, y + 2, level);
1190
+               }
1191
+           }
1192
+@@ -1845,76 +1845,76 @@ bool CxImage::Dither(long method)
1193
+               int tmp_index_y = y;
1194
+               int tmp_coeff = 32;
1195
+               nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1196
+-              level = (BYTE)min(255, max(0, (int)nlevel));
1197
++              level = (BYTE)cmin(255, cmax(0, (int)nlevel));
1198
+               SetPixelIndex(tmp_index_x, tmp_index_y, level);
1199
+ 
1200
+               tmp_index_x = x - 3;
1201
+               tmp_index_y = y + 1;
1202
+               tmp_coeff = 12;
1203
+               nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1204
+-              level = (BYTE)min(255, max(0, (int)nlevel));
1205
++              level = (BYTE)cmin(255, cmax(0, (int)nlevel));
1206
+               SetPixelIndex(tmp_index_x, tmp_index_y, level);
1207
+ 
1208
+               tmp_index_x = x - 1;
1209
+               tmp_coeff = 26;
1210
+               nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1211
+-              level = (BYTE)min(255, max(0, (int)nlevel));
1212
++              level = (BYTE)cmin(255, cmax(0, (int)nlevel));
1213
+               SetPixelIndex(tmp_index_x, tmp_index_y, level);
1214
+ 
1215
+               tmp_index_x = x + 1;
1216
+               tmp_coeff = 30;
1217
+               nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1218
+-              level = (BYTE)min(255, max(0, (int)nlevel));
1219
++              level = (BYTE)cmin(255, cmax(0, (int)nlevel));
1220
+               SetPixelIndex(tmp_index_x, tmp_index_y, level);
1221
+ 
1222
+               tmp_index_x = x + 3;
1223
+               tmp_coeff = 16;
1224
+               nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1225
+-              level = (BYTE)min(255, max(0, (int)nlevel));
1226
++              level = (BYTE)cmin(255, cmax(0, (int)nlevel));
1227
+               SetPixelIndex(tmp_index_x, tmp_index_y, level);
1228
+ 
1229
+               tmp_index_x = x - 2;
1230
+               tmp_index_y = y + 2;
1231
+               tmp_coeff = 12;
1232
+               nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1233
+-              level = (BYTE)min(255, max(0, (int)nlevel));
1234
++              level = (BYTE)cmin(255, cmax(0, (int)nlevel));
1235
+               SetPixelIndex(tmp_index_x, tmp_index_y, level);
1236
+ 
1237
+               tmp_index_x = x;
1238
+               tmp_coeff = 26;
1239
+               nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1240
+-              level = (BYTE)min(255, max(0, (int)nlevel));
1241
++              level = (BYTE)cmin(255, cmax(0, (int)nlevel));
1242
+               SetPixelIndex(tmp_index_x, tmp_index_y, level);
1243
+ 
1244
+               tmp_index_x = x + 2;
1245
+               tmp_coeff = 12;
1246
+               nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1247
+-              level = (BYTE)min(255, max(0, (int)nlevel));
1248
++              level = (BYTE)cmin(255, cmax(0, (int)nlevel));
1249
+               SetPixelIndex(tmp_index_x, tmp_index_y, level);
1250
+ 
1251
+               tmp_index_x = x - 3;
1252
+               tmp_index_y = y + 3;
1253
+               tmp_coeff = 5;
1254
+               nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1255
+-              level = (BYTE)min(255, max(0, (int)nlevel));
1256
++              level = (BYTE)cmin(255, cmax(0, (int)nlevel));
1257
+               SetPixelIndex(tmp_index_x, tmp_index_y, level);
1258
+ 
1259
+               tmp_index_x = x - 1;
1260
+               tmp_coeff = 12;
1261
+               nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1262
+-              level = (BYTE)min(255, max(0, (int)nlevel));
1263
++              level = (BYTE)cmin(255, cmax(0, (int)nlevel));
1264
+               SetPixelIndex(tmp_index_x, tmp_index_y, level);
1265
+ 
1266
+               tmp_index_x = x + 1;
1267
+               tmp_coeff = 12;
1268
+               nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1269
+-              level = (BYTE)min(255, max(0, (int)nlevel));
1270
++              level = (BYTE)cmin(255, cmax(0, (int)nlevel));
1271
+               SetPixelIndex(tmp_index_x, tmp_index_y, level);
1272
+ 
1273
+               tmp_index_x = x + 3;
1274
+               tmp_coeff = 5;
1275
+               nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1276
+-              level = (BYTE)min(255, max(0, (int)nlevel));
1277
++              level = (BYTE)cmin(255, cmax(0, (int)nlevel));
1278
+               SetPixelIndex(tmp_index_x, tmp_index_y, level);
1279
+           }
1280
+       }
1281
+@@ -1941,7 +1941,7 @@ bool CxImage::Dither(long method)
1282
+           Bmatrix[i] = (BYTE)(dither);
1283
+       }
1284
+ 
1285
+-      int scale = max(0,(8-2*order));
1286
++      int scale = cmax(0,(8-2*order));
1287
+       int level;
1288
+       for (long y=0;y<head.biHeight;y++){
1289
+           info.nProgress = (long)(100*y/head.biHeight);
1290
+@@ -1981,7 +1981,7 @@ bool CxImage::Dither(long method)
1291
+               }
1292
+ 
1293
+               nlevel = GetPixelIndex(x+1,y) + (error * 7)/16;
1294
+-              level = (BYTE)min(255,max(0,(int)nlevel));
1295
++              level = (BYTE)cmin(255,cmax(0,(int)nlevel));
1296
+               SetPixelIndex(x+1,y,level);
1297
+               for(int i=-1; i<2; i++){
1298
+                   switch(i){
1299
+@@ -1993,7 +1993,7 @@ bool CxImage::Dither(long method)
1300
+                       coeff=1; break;
1301
+                   }
1302
+                   nlevel = GetPixelIndex(x+i,y+1) + (error * coeff)/16;
1303
+-                  level = (BYTE)min(255,max(0,(int)nlevel));
1304
++                  level = (BYTE)cmin(255,cmax(0,(int)nlevel));
1305
+                   SetPixelIndex(x+i,y+1,level);
1306
+               }
1307
+           }
1308
+@@ -2031,7 +2031,7 @@ bool CxImage::CropRotatedRectangle( long
1309
+   if ( fabs(angle)<0.0002 )
1310
+       return Crop( topx, topy, topx+width, topy+height, iDst);
1311
+ 
1312
+-  startx = min(topx, topx - (long)(sin_angle*(double)height));
1313
++  startx = cmin(topx, topx - (long)(sin_angle*(double)height));
1314
+   endx   = topx + (long)(cos_angle*(double)width);
1315
+   endy   = topy + (long)(cos_angle*(double)height + sin_angle*(double)width);
1316
+   // check: corners of the rectangle must be inside
1317
+@@ -2079,10 +2079,10 @@ bool CxImage::Crop(long left, long top,
1318
+ {
1319
+   if (!pDib) return false;
1320
+ 
1321
+-  long startx = max(0L,min(left,head.biWidth));
1322
+-  long endx = max(0L,min(right,head.biWidth));
1323
+-  long starty = head.biHeight - max(0L,min(top,head.biHeight));
1324
+-  long endy = head.biHeight - max(0L,min(bottom,head.biHeight));
1325
++  long startx = cmax(0L,cmin(left,head.biWidth));
1326
++  long endx = cmax(0L,cmin(right,head.biWidth));
1327
++  long starty = head.biHeight - cmax(0L,cmin(top,head.biHeight));
1328
++  long endy = head.biHeight - cmax(0L,cmin(bottom,head.biHeight));
1329
+ 
1330
+   if (startx==endx || starty==endy) return false;
1331
+ 
1332
+@@ -2443,8 +2443,8 @@ bool CxImage::CircleTransform(int type,l
1333
+                       nx=x+(x%32)-16;
1334
+                       ny=y;
1335
+                   }
1336
+-//                    nx=max(xmin,min(nx,xmax));
1337
+-//                    ny=max(ymin,min(ny,ymax));
1338
++//                    nx=cmax(xmin,cmin(nx,xmax));
1339
++//                    ny=cmax(ymin,cmin(ny,ymax));
1340
+               }
1341
+               else { nx=-1;ny=-1;}
1342
+               if (head.biClrUsed==0){
1343
+--- a/lib/cximage-6.0/CxImage/ximawnd.cpp
1344
++++ b/lib/cximage-6.0/CxImage/ximawnd.cpp
1345
+@@ -682,10 +682,10 @@ long CxImage::Draw(HDC hdc, long x, long
1346
+   RECT clipbox,paintbox;
1347
+   GetClipBox(hdc,&clipbox);
1348
+ 
1349
+-  paintbox.top = min(clipbox.bottom,max(clipbox.top,y));
1350
+-  paintbox.left = min(clipbox.right,max(clipbox.left,x));
1351
+-  paintbox.right = max(clipbox.left,min(clipbox.right,x+cx));
1352
+-  paintbox.bottom = max(clipbox.top,min(clipbox.bottom,y+cy));
1353
++  paintbox.top = cmin(clipbox.bottom,cmax(clipbox.top,y));
1354
++  paintbox.left = cmin(clipbox.right,cmax(clipbox.left,x));
1355
++  paintbox.right = cmax(clipbox.left,cmin(clipbox.right,x+cx));
1356
++  paintbox.bottom = cmax(clipbox.top,cmin(clipbox.bottom,y+cy));
1357
+ 
1358
+   long destw = paintbox.right - paintbox.left;
1359
+   long desth = paintbox.bottom - paintbox.top;
1360
+@@ -730,12 +730,12 @@ long CxImage::Draw(HDC hdc, long x, long
1361
+ 
1362
+               for(yy=0;yy<desth;yy++){
1363
+                   dy = head.biHeight-(ymax-yy-y)*fy;
1364
+-                  sy = max(0L,(long)floor(dy));
1365
++                  sy = cmax(0L,(long)floor(dy));
1366
+                   psrc = info.pImage+sy*info.dwEffWidth;
1367
+                   pdst = pbase+yy*ew;
1368
+                   for(xx=0;xx<destw;xx++){
1369
+                       dx = (xx+xmin-x)*fx;
1370
+-                      sx = max(0L,(long)floor(dx));
1371
++                      sx = cmax(0L,(long)floor(dx));
1372
+ #if CXIMAGE_SUPPORT_INTERPOLATION
1373
+                       if (bSmooth){
1374
+                           if (fx > 1 && fy > 1) { 
1375
+@@ -813,7 +813,7 @@ long CxImage::Draw(HDC hdc, long x, long
1376
+               
1377
+               for(yy=0;yy<desth;yy++){
1378
+                   dy = head.biHeight-(ymax-yy-y)*fy;
1379
+-                  sy = max(0L,(long)floor(dy));
1380
++                  sy = cmax(0L,(long)floor(dy));
1381
+ 
1382
+                   alphaoffset = sy*head.biWidth;
1383
+                   pdst = pbase + yy*ew;
1384
+@@ -821,7 +821,7 @@ long CxImage::Draw(HDC hdc, long x, long
1385
+ 
1386
+                   for(xx=0;xx<destw;xx++){
1387
+                       dx = (xx+xmin-x)*fx;
1388
+-                      sx = max(0L,(long)floor(dx));
1389
++                      sx = cmax(0L,(long)floor(dx));
1390
+ 
1391
+                       if (bAlpha) a=pAlpha[alphaoffset+sx]; else a=255;
1392
+                       a =(BYTE)((a*(1+info.nAlphaMax))>>8);
1393