1 From 8f82e51563f0e1bc9b7a8adf669ad2b66e7ce3e5 Mon Sep 17 00:00:00 2001
2 From: Bernd Kuhls <bernd.kuhls@t-online.de>
3 Date: Thu, 28 Apr 2016 17:17:40 +0200
4 Subject: [PATCH] lib/cximage-6.0: fix compilation with gcc6
6 For a quick fix I renamed min() to cxmin() and max() to cxmax() to
7 prevent the conflict with the gcc definition.
9 Forum thread for reference:
10 http://forum.kodi.tv/showthread.php?tid=263884
12 Signed-off-by: Bernd Kuhls <bernd.kuhls@t-online.de>
13 (Patch sent upstream: https://github.com/xbmc/xbmc/pull/9703)
15 lib/cximage-6.0/CxImage/ximabmp.cpp | 6 +-
16 lib/cximage-6.0/CxImage/ximadef.h | 8 +-
17 lib/cximage-6.0/CxImage/ximadsp.cpp | 182 +++++++++++++++++------------------
18 lib/cximage-6.0/CxImage/ximage.cpp | 4 +-
19 lib/cximage-6.0/CxImage/ximagif.cpp | 6 +-
20 lib/cximage-6.0/CxImage/ximahist.cpp | 12 +--
21 lib/cximage-6.0/CxImage/ximaint.cpp | 8 +-
22 lib/cximage-6.0/CxImage/ximaiter.h | 4 +-
23 lib/cximage-6.0/CxImage/ximajbg.cpp | 2 +-
24 lib/cximage-6.0/CxImage/ximapal.cpp | 14 +--
25 lib/cximage-6.0/CxImage/ximapng.cpp | 12 +--
26 lib/cximage-6.0/CxImage/ximaraw.cpp | 4 +-
27 lib/cximage-6.0/CxImage/ximasel.cpp | 50 +++++-----
28 lib/cximage-6.0/CxImage/ximath.cpp | 8 +-
29 lib/cximage-6.0/CxImage/ximatif.cpp | 6 +-
30 lib/cximage-6.0/CxImage/ximatran.cpp | 138 +++++++++++++-------------
31 lib/cximage-6.0/CxImage/ximawnd.cpp | 16 +--
32 17 files changed, 236 insertions(+), 244 deletions(-)
34 diff --git a/lib/cximage-6.0/CxImage/ximabmp.cpp b/lib/cximage-6.0/CxImage/ximabmp.cpp
35 index 726ff91..55842b1 100644
36 --- a/lib/cximage-6.0/CxImage/ximabmp.cpp
37 +++ b/lib/cximage-6.0/CxImage/ximabmp.cpp
38 @@ -46,7 +46,7 @@ bool CxImageBMP::Encode(CxFile * hFile)
41 // Write the file header
42 - hFile->Write(&hdr,min(14,sizeof(BITMAPFILEHEADER)),1);
43 + hFile->Write(&hdr,cxmin(14,sizeof(BITMAPFILEHEADER)),1);
44 hFile->Write(&infohdr,sizeof(BITMAPINFOHEADER),1);
45 //and DIB+ALPHA interlaced
46 BYTE *srcalpha = AlphaGetPointer();
47 @@ -64,7 +64,7 @@ bool CxImageBMP::Encode(CxFile * hFile)
48 #endif //CXIMAGE_SUPPORT_ALPHA
50 // Write the file header
51 - hFile->Write(&hdr,min(14,sizeof(BITMAPFILEHEADER)),1);
52 + hFile->Write(&hdr,cxmin(14,sizeof(BITMAPFILEHEADER)),1);
54 memcpy(pDib,&head,sizeof(BITMAPINFOHEADER));
55 bihtoh((BITMAPINFOHEADER*)pDib);
56 @@ -86,7 +86,7 @@ bool CxImageBMP::Decode(CxFile * hFile)
58 DWORD off = hFile->Tell(); //<CSC>
60 - if (hFile->Read(&bf,min(14,sizeof(bf)),1)==0) cx_throw("Not a BMP");
61 + if (hFile->Read(&bf,cxmin(14,sizeof(bf)),1)==0) cx_throw("Not a BMP");
63 bf.bfSize = my_ntohl(bf.bfSize);
64 bf.bfOffBits = my_ntohl(bf.bfOffBits);
65 diff --git a/lib/cximage-6.0/CxImage/ximadef.h b/lib/cximage-6.0/CxImage/ximadef.h
66 index fe383bf..53ea452 100644
67 --- a/lib/cximage-6.0/CxImage/ximadef.h
68 +++ b/lib/cximage-6.0/CxImage/ximadef.h
70 #define CXIMAGE_SUPPORT_WINDOWS 0
74 -#define min(a,b) (((a)<(b))?(a):(b))
77 -#define max(a,b) (((a)>(b))?(a):(b))
79 +#define cxmin(a,b) (((a)<(b))?(a):(b))
80 +#define cxmax(a,b) (((a)>(b))?(a):(b))
83 #define PI 3.141592653589793f
84 diff --git a/lib/cximage-6.0/CxImage/ximadsp.cpp b/lib/cximage-6.0/CxImage/ximadsp.cpp
85 index 8425bb2..813253b 100644
86 --- a/lib/cximage-6.0/CxImage/ximadsp.cpp
87 +++ b/lib/cximage-6.0/CxImage/ximadsp.cpp
88 @@ -389,8 +389,8 @@ RGBQUAD CxImage::RGBtoHSL(RGBQUAD lRGBColor)
89 G = lRGBColor.rgbGreen;
90 B = lRGBColor.rgbBlue;
92 - cMax = max( max(R,G), B); /* calculate lightness */
93 - cMin = min( min(R,G), B);
94 + cMax = cxmax( cxmax(R,G), B); /* calculate lightness */
95 + cMin = cxmin( cxmin(R,G), B);
96 L = (BYTE)((((cMax+cMin)*HSLMAX)+RGBMAX)/(2*RGBMAX));
98 if (cMax==cMin){ /* r=g=b --> achromatic case */
99 @@ -489,9 +489,9 @@ RGBQUAD CxImage::YUVtoRGB(RGBQUAD lYUVColor)
100 G = (int)( Y - 0.344f * U - 0.714f * V);
101 B = (int)( Y + 1.770f * U);
103 - R= min(255,max(0,R));
104 - G= min(255,max(0,G));
105 - B= min(255,max(0,B));
106 + R= cxmin(255,cxmax(0,R));
107 + G= cxmin(255,cxmax(0,G));
108 + B= cxmin(255,cxmax(0,B));
109 RGBQUAD rgb={(BYTE)B,(BYTE)G,(BYTE)R,0};
112 @@ -510,9 +510,9 @@ RGBQUAD CxImage::RGBtoYUV(RGBQUAD lRGBColor)
113 U = (int)((B-Y) * 0.565f + 128);
114 V = (int)((R-Y) * 0.713f + 128);
116 - Y= min(255,max(0,Y));
117 - U= min(255,max(0,U));
118 - V= min(255,max(0,V));
119 + Y= cxmin(255,cxmax(0,Y));
120 + U= cxmin(255,cxmax(0,U));
121 + V= cxmin(255,cxmax(0,V));
122 RGBQUAD yuv={(BYTE)V,(BYTE)U,(BYTE)Y,0};
125 @@ -528,9 +528,9 @@ RGBQUAD CxImage::YIQtoRGB(RGBQUAD lYIQColor)
126 G = (int)( Y - 0.273f * I - 0.647f * Q);
127 B = (int)( Y - 1.104f * I + 1.701f * Q);
129 - R= min(255,max(0,R));
130 - G= min(255,max(0,G));
131 - B= min(255,max(0,B));
132 + R= cxmin(255,cxmax(0,R));
133 + G= cxmin(255,cxmax(0,G));
134 + B= cxmin(255,cxmax(0,B));
135 RGBQUAD rgb={(BYTE)B,(BYTE)G,(BYTE)R,0};
138 @@ -546,9 +546,9 @@ RGBQUAD CxImage::RGBtoYIQ(RGBQUAD lRGBColor)
139 I = (int)( 0.5960f * R - 0.2742f * G - 0.3219f * B + 128);
140 Q = (int)( 0.2109f * R - 0.5229f * G + 0.3120f * B + 128);
142 - Y= min(255,max(0,Y));
143 - I= min(255,max(0,I));
144 - Q= min(255,max(0,Q));
145 + Y= cxmin(255,cxmax(0,Y));
146 + I= cxmin(255,cxmax(0,I));
147 + Q= cxmin(255,cxmax(0,Q));
148 RGBQUAD yiq={(BYTE)Q,(BYTE)I,(BYTE)Y,0};
151 @@ -565,9 +565,9 @@ RGBQUAD CxImage::XYZtoRGB(RGBQUAD lXYZColor)
152 G = (int)( -0.969256f * X + 1.875992f * Y + 0.041556f * Z * k);
153 B = (int)( 0.055648f * X - 0.204043f * Y + 1.057311f * Z * k);
155 - R= min(255,max(0,R));
156 - G= min(255,max(0,G));
157 - B= min(255,max(0,B));
158 + R= cxmin(255,cxmax(0,R));
159 + G= cxmin(255,cxmax(0,G));
160 + B= cxmin(255,cxmax(0,B));
161 RGBQUAD rgb={(BYTE)B,(BYTE)G,(BYTE)R,0};
164 @@ -583,9 +583,9 @@ RGBQUAD CxImage::RGBtoXYZ(RGBQUAD lRGBColor)
165 Y = (int)( 0.212671f * R + 0.715160f * G + 0.072169f * B);
166 Z = (int)((0.019334f * R + 0.119193f * G + 0.950227f * B)*0.918483657f);
168 - //X= min(255,max(0,X));
169 - //Y= min(255,max(0,Y));
170 - //Z= min(255,max(0,Z));
171 + //X= cxmin(255,cxmax(0,X));
172 + //Y= cxmin(255,cxmax(0,Y));
173 + //Z= cxmin(255,cxmax(0,Z));
174 RGBQUAD xyz={(BYTE)Z,(BYTE)Y,(BYTE)X,0};
177 @@ -707,7 +707,7 @@ bool CxImage::Light(long brightness, long contrast)
179 BYTE cTable[256]; //<nipper>
180 for (int i=0;i<256;i++) {
181 - cTable[i] = (BYTE)max(0,min(255,(int)((i-128)*c + brightness + 0.5f)));
182 + cTable[i] = (BYTE)cxmax(0,cxmin(255,(int)((i-128)*c + brightness + 0.5f)));
186 @@ -830,11 +830,11 @@ bool CxImage::Filter(long* kernel, long Ksize, long Kfactor, long Koffset)
189 if (Kfactor==0 || ksumcur==0){
190 - cPtr2[iY1] = (BYTE)min(255, max(0,(int)(b + Koffset)));
191 + cPtr2[iY1] = (BYTE)cxmin(255, cxmax(0,(int)(b + Koffset)));
192 } else if (ksumtot == ksumcur) {
193 - cPtr2[iY1] = (BYTE)min(255, max(0,(int)(b/Kfactor + Koffset)));
194 + cPtr2[iY1] = (BYTE)cxmin(255, cxmax(0,(int)(b/Kfactor + Koffset)));
196 - cPtr2[iY1] = (BYTE)min(255, max(0,(int)((b*ksumtot)/(ksumcur*Kfactor) + Koffset)));
197 + cPtr2[iY1] = (BYTE)cxmin(255, cxmax(0,(int)((b*ksumtot)/(ksumcur*Kfactor) + Koffset)));
201 @@ -863,17 +863,17 @@ bool CxImage::Filter(long* kernel, long Ksize, long Kfactor, long Koffset)
204 if (Kfactor==0 || ksumcur==0){
205 - c.rgbRed = (BYTE)min(255, max(0,(int)(r + Koffset)));
206 - c.rgbGreen = (BYTE)min(255, max(0,(int)(g + Koffset)));
207 - c.rgbBlue = (BYTE)min(255, max(0,(int)(b + Koffset)));
208 + c.rgbRed = (BYTE)cxmin(255, cxmax(0,(int)(r + Koffset)));
209 + c.rgbGreen = (BYTE)cxmin(255, cxmax(0,(int)(g + Koffset)));
210 + c.rgbBlue = (BYTE)cxmin(255, cxmax(0,(int)(b + Koffset)));
211 } else if (ksumtot == ksumcur) {
212 - c.rgbRed = (BYTE)min(255, max(0,(int)(r/Kfactor + Koffset)));
213 - c.rgbGreen = (BYTE)min(255, max(0,(int)(g/Kfactor + Koffset)));
214 - c.rgbBlue = (BYTE)min(255, max(0,(int)(b/Kfactor + Koffset)));
215 + c.rgbRed = (BYTE)cxmin(255, cxmax(0,(int)(r/Kfactor + Koffset)));
216 + c.rgbGreen = (BYTE)cxmin(255, cxmax(0,(int)(g/Kfactor + Koffset)));
217 + c.rgbBlue = (BYTE)cxmin(255, cxmax(0,(int)(b/Kfactor + Koffset)));
219 - c.rgbRed = (BYTE)min(255, max(0,(int)((r*ksumtot)/(ksumcur*Kfactor) + Koffset)));
220 - c.rgbGreen = (BYTE)min(255, max(0,(int)((g*ksumtot)/(ksumcur*Kfactor) + Koffset)));
221 - c.rgbBlue = (BYTE)min(255, max(0,(int)((b*ksumtot)/(ksumcur*Kfactor) + Koffset)));
222 + c.rgbRed = (BYTE)cxmin(255, cxmax(0,(int)((r*ksumtot)/(ksumcur*Kfactor) + Koffset)));
223 + c.rgbGreen = (BYTE)cxmin(255, cxmax(0,(int)((g*ksumtot)/(ksumcur*Kfactor) + Koffset)));
224 + c.rgbBlue = (BYTE)cxmin(255, cxmax(0,(int)((b*ksumtot)/(ksumcur*Kfactor) + Koffset)));
226 tmp.BlindSetPixelColor(x,y,c);
228 @@ -1078,8 +1078,8 @@ bool CxImage::Edge(long Ksize)
230 void CxImage::Mix(CxImage & imgsrc2, ImageOpType op, long lXOffset, long lYOffset, bool bMixAlpha)
232 - long lWide = min(GetWidth(),imgsrc2.GetWidth()-lXOffset);
233 - long lHeight = min(GetHeight(),imgsrc2.GetHeight()-lYOffset);
234 + long lWide = cxmin(GetWidth(),imgsrc2.GetWidth()-lXOffset);
235 + long lHeight = cxmin(GetHeight(),imgsrc2.GetHeight()-lYOffset);
237 bool bEditAlpha = imgsrc2.AlphaIsValid() & bMixAlpha;
239 @@ -1112,16 +1112,16 @@ void CxImage::Mix(CxImage & imgsrc2, ImageOpType op, long lXOffset, long lYOffse
240 if (bEditAlpha) rgbDest.rgbReserved = (BYTE)((rgb1.rgbReserved+rgb2.rgbReserved)/2);
243 - rgbDest.rgbBlue = (BYTE)max(0,min(255,rgb1.rgbBlue+rgb2.rgbBlue));
244 - rgbDest.rgbGreen = (BYTE)max(0,min(255,rgb1.rgbGreen+rgb2.rgbGreen));
245 - rgbDest.rgbRed = (BYTE)max(0,min(255,rgb1.rgbRed+rgb2.rgbRed));
246 - if (bEditAlpha) rgbDest.rgbReserved = (BYTE)max(0,min(255,rgb1.rgbReserved+rgb2.rgbReserved));
247 + rgbDest.rgbBlue = (BYTE)cxmax(0,cxmin(255,rgb1.rgbBlue+rgb2.rgbBlue));
248 + rgbDest.rgbGreen = (BYTE)cxmax(0,cxmin(255,rgb1.rgbGreen+rgb2.rgbGreen));
249 + rgbDest.rgbRed = (BYTE)cxmax(0,cxmin(255,rgb1.rgbRed+rgb2.rgbRed));
250 + if (bEditAlpha) rgbDest.rgbReserved = (BYTE)cxmax(0,cxmin(255,rgb1.rgbReserved+rgb2.rgbReserved));
253 - rgbDest.rgbBlue = (BYTE)max(0,min(255,rgb1.rgbBlue-rgb2.rgbBlue));
254 - rgbDest.rgbGreen = (BYTE)max(0,min(255,rgb1.rgbGreen-rgb2.rgbGreen));
255 - rgbDest.rgbRed = (BYTE)max(0,min(255,rgb1.rgbRed-rgb2.rgbRed));
256 - if (bEditAlpha) rgbDest.rgbReserved = (BYTE)max(0,min(255,rgb1.rgbReserved-rgb2.rgbReserved));
257 + rgbDest.rgbBlue = (BYTE)cxmax(0,cxmin(255,rgb1.rgbBlue-rgb2.rgbBlue));
258 + rgbDest.rgbGreen = (BYTE)cxmax(0,cxmin(255,rgb1.rgbGreen-rgb2.rgbGreen));
259 + rgbDest.rgbRed = (BYTE)cxmax(0,cxmin(255,rgb1.rgbRed-rgb2.rgbRed));
260 + if (bEditAlpha) rgbDest.rgbReserved = (BYTE)cxmax(0,cxmin(255,rgb1.rgbReserved-rgb2.rgbReserved));
263 rgbDest.rgbBlue = (BYTE)(rgb1.rgbBlue&rgb2.rgbBlue);
264 @@ -1202,11 +1202,11 @@ void CxImage::Mix(CxImage & imgsrc2, ImageOpType op, long lXOffset, long lYOffse
265 double dSmallAmt = dSmall*((double)rgb2.rgbBlue);
267 if( lAverage < lThresh+1){
268 - rgbDest.rgbBlue = (BYTE)max(0,min(255,(int)(dLarge*((double)rgb1.rgbBlue) +
269 + rgbDest.rgbBlue = (BYTE)cxmax(0,cxmin(255,(int)(dLarge*((double)rgb1.rgbBlue) +
271 - rgbDest.rgbGreen = (BYTE)max(0,min(255,(int)(dLarge*((double)rgb1.rgbGreen) +
272 + rgbDest.rgbGreen = (BYTE)cxmax(0,cxmin(255,(int)(dLarge*((double)rgb1.rgbGreen) +
274 - rgbDest.rgbRed = (BYTE)max(0,min(255,(int)(dLarge*((double)rgb1.rgbRed) +
275 + rgbDest.rgbRed = (BYTE)cxmax(0,cxmin(255,(int)(dLarge*((double)rgb1.rgbRed) +
279 @@ -1274,9 +1274,9 @@ bool CxImage::ShiftRGB(long r, long g, long b)
280 #endif //CXIMAGE_SUPPORT_SELECTION
282 color = BlindGetPixelColor(x,y);
283 - color.rgbRed = (BYTE)max(0,min(255,(int)(color.rgbRed + r)));
284 - color.rgbGreen = (BYTE)max(0,min(255,(int)(color.rgbGreen + g)));
285 - color.rgbBlue = (BYTE)max(0,min(255,(int)(color.rgbBlue + b)));
286 + color.rgbRed = (BYTE)cxmax(0,cxmin(255,(int)(color.rgbRed + r)));
287 + color.rgbGreen = (BYTE)cxmax(0,cxmin(255,(int)(color.rgbGreen + g)));
288 + color.rgbBlue = (BYTE)cxmax(0,cxmin(255,(int)(color.rgbBlue + b)));
289 BlindSetPixelColor(x,y,color);
292 @@ -1284,9 +1284,9 @@ bool CxImage::ShiftRGB(long r, long g, long b)
294 for(DWORD j=0; j<head.biClrUsed; j++){
295 color = GetPaletteColor((BYTE)j);
296 - color.rgbRed = (BYTE)max(0,min(255,(int)(color.rgbRed + r)));
297 - color.rgbGreen = (BYTE)max(0,min(255,(int)(color.rgbGreen + g)));
298 - color.rgbBlue = (BYTE)max(0,min(255,(int)(color.rgbBlue + b)));
299 + color.rgbRed = (BYTE)cxmax(0,cxmin(255,(int)(color.rgbRed + r)));
300 + color.rgbGreen = (BYTE)cxmax(0,cxmin(255,(int)(color.rgbGreen + g)));
301 + color.rgbBlue = (BYTE)cxmax(0,cxmin(255,(int)(color.rgbBlue + b)));
302 SetPaletteColor((BYTE)j,color);
305 @@ -1310,7 +1310,7 @@ bool CxImage::Gamma(float gamma)
307 BYTE cTable[256]; //<nipper>
308 for (int i=0;i<256;i++) {
309 - cTable[i] = (BYTE)max(0,min(255,(int)( pow((double)i, dinvgamma) / dMax)));
310 + cTable[i] = (BYTE)cxmax(0,cxmin(255,(int)( pow((double)i, dinvgamma) / dMax)));
314 @@ -1337,21 +1337,21 @@ bool CxImage::GammaRGB(float gammaR, float gammaG, float gammaB)
315 dMax = pow(255.0, dinvgamma) / 255.0;
317 for (i=0;i<256;i++) {
318 - cTableR[i] = (BYTE)max(0,min(255,(int)( pow((double)i, dinvgamma) / dMax)));
319 + cTableR[i] = (BYTE)cxmax(0,cxmin(255,(int)( pow((double)i, dinvgamma) / dMax)));
322 dinvgamma = 1/gammaG;
323 dMax = pow(255.0, dinvgamma) / 255.0;
325 for (i=0;i<256;i++) {
326 - cTableG[i] = (BYTE)max(0,min(255,(int)( pow((double)i, dinvgamma) / dMax)));
327 + cTableG[i] = (BYTE)cxmax(0,cxmin(255,(int)( pow((double)i, dinvgamma) / dMax)));
330 dinvgamma = 1/gammaB;
331 dMax = pow(255.0, dinvgamma) / 255.0;
333 for (i=0;i<256;i++) {
334 - cTableB[i] = (BYTE)max(0,min(255,(int)( pow((double)i, dinvgamma) / dMax)));
335 + cTableB[i] = (BYTE)cxmax(0,cxmin(255,(int)( pow((double)i, dinvgamma) / dMax)));
338 return Lut(cTableR, cTableG, cTableB);
339 @@ -1442,11 +1442,11 @@ bool CxImage::Noise(long level)
341 color = BlindGetPixelColor(x,y);
342 n=(long)((rand()/(float)RAND_MAX - 0.5)*level);
343 - color.rgbRed = (BYTE)max(0,min(255,(int)(color.rgbRed + n)));
344 + color.rgbRed = (BYTE)cxmax(0,cxmin(255,(int)(color.rgbRed + n)));
345 n=(long)((rand()/(float)RAND_MAX - 0.5)*level);
346 - color.rgbGreen = (BYTE)max(0,min(255,(int)(color.rgbGreen + n)));
347 + color.rgbGreen = (BYTE)cxmax(0,cxmin(255,(int)(color.rgbGreen + n)));
348 n=(long)((rand()/(float)RAND_MAX - 0.5)*level);
349 - color.rgbBlue = (BYTE)max(0,min(255,(int)(color.rgbBlue + n)));
350 + color.rgbBlue = (BYTE)cxmax(0,cxmin(255,(int)(color.rgbBlue + n)));
351 BlindSetPixelColor(x,y,color);
354 @@ -1561,8 +1561,8 @@ bool CxImage::FFT2(CxImage* srcReal, CxImage* srcImag, CxImage* dstReal, CxImage
357 double *real2,*imag2;
358 - real2 = (double*)malloc(max(w,h) * sizeof(double));
359 - imag2 = (double*)malloc(max(w,h) * sizeof(double));
360 + real2 = (double*)malloc(cxmax(w,h) * sizeof(double));
361 + imag2 = (double*)malloc(cxmax(w,h) * sizeof(double));
363 /* Transform the rows */
364 real = (double *)malloc(w * sizeof(double));
365 @@ -1617,7 +1617,7 @@ bool CxImage::FFT2(CxImage* srcReal, CxImage* srcImag, CxImage* dstReal, CxImage
367 /* converting from double to byte, there is a HUGE loss in the dynamics
368 "nn" tries to keep an acceptable SNR, but 8bit=48dB: don't ask more */
369 - double nn=pow((double)2,(double)log((double)max(w,h))/(double)log((double)2)-4);
370 + double nn=pow((double)2,(double)log((double)cxmax(w,h))/(double)log((double)2)-4);
371 //reversed gain for reversed transform
372 if (direction==-1) nn=1/nn;
373 //bMagnitude : just to see it on the screen
374 @@ -1626,15 +1626,15 @@ bool CxImage::FFT2(CxImage* srcReal, CxImage* srcImag, CxImage* dstReal, CxImage
378 - tmpReal->SetPixelIndex(k,j,(BYTE)max(0,min(255,(nn*(3+log(_cabs(grid[k][j])))))));
379 + tmpReal->SetPixelIndex(k,j,(BYTE)cxmax(0,cxmin(255,(nn*(3+log(_cabs(grid[k][j])))))));
380 if (grid[k][j].x==0){
381 - tmpImag->SetPixelIndex(k,j,(BYTE)max(0,min(255,(128+(atan(grid[k][j].y/0.0000000001)*nn)))));
382 + tmpImag->SetPixelIndex(k,j,(BYTE)cxmax(0,cxmin(255,(128+(atan(grid[k][j].y/0.0000000001)*nn)))));
384 - tmpImag->SetPixelIndex(k,j,(BYTE)max(0,min(255,(128+(atan(grid[k][j].y/grid[k][j].x)*nn)))));
385 + tmpImag->SetPixelIndex(k,j,(BYTE)cxmax(0,cxmin(255,(128+(atan(grid[k][j].y/grid[k][j].x)*nn)))));
388 - tmpReal->SetPixelIndex(k,j,(BYTE)max(0,min(255,(128 + grid[k][j].x*nn))));
389 - tmpImag->SetPixelIndex(k,j,(BYTE)max(0,min(255,(128 + grid[k][j].y*nn))));
390 + tmpReal->SetPixelIndex(k,j,(BYTE)cxmax(0,cxmin(255,(128 + grid[k][j].x*nn))));
391 + tmpImag->SetPixelIndex(k,j,(BYTE)cxmax(0,cxmin(255,(128 + grid[k][j].y*nn))));
395 @@ -1922,7 +1922,7 @@ bool CxImage::RepairChannel(CxImage *ch, float radius)
397 correction = ((1.0+iy*iy)*ixx - ix*iy*ixy + (1.0+ix*ix)*iyy)/(1.0+ix*ix+iy*iy);
399 - tmp.BlindSetPixelIndex(x,y,(BYTE)min(255,max(0,(xy0 + radius * correction + 0.5))));
400 + tmp.BlindSetPixelIndex(x,y,(BYTE)cxmin(255,cxmax(0,(xy0 + radius * correction + 0.5))));
404 @@ -1943,7 +1943,7 @@ bool CxImage::RepairChannel(CxImage *ch, float radius)
406 correction = ((1.0+iy*iy)*ixx - ix*iy*ixy + (1.0+ix*ix)*iyy)/(1.0+ix*ix+iy*iy);
408 - tmp.BlindSetPixelIndex(x,y,(BYTE)min(255,max(0,(xy0 + radius * correction + 0.5))));
409 + tmp.BlindSetPixelIndex(x,y,(BYTE)cxmin(255,cxmax(0,(xy0 + radius * correction + 0.5))));
413 @@ -1963,7 +1963,7 @@ bool CxImage::RepairChannel(CxImage *ch, float radius)
415 correction = ((1.0+iy*iy)*ixx - ix*iy*ixy + (1.0+ix*ix)*iyy)/(1.0+ix*ix+iy*iy);
417 - tmp.BlindSetPixelIndex(x,y,(BYTE)min(255,max(0,(xy0 + radius * correction + 0.5))));
418 + tmp.BlindSetPixelIndex(x,y,(BYTE)cxmin(255,cxmax(0,(xy0 + radius * correction + 0.5))));
422 @@ -2621,8 +2621,8 @@ bool CxImage::SelectiveBlur(float radius, BYTE threshold, CxImage* iDst)
425 //build the difference mask
426 - BYTE thresh_dw = (BYTE)max( 0 ,(int)(128 - threshold));
427 - BYTE thresh_up = (BYTE)min(255,(int)(128 + threshold));
428 + BYTE thresh_dw = (BYTE)cxmax( 0 ,(int)(128 - threshold));
429 + BYTE thresh_up = (BYTE)cxmin(255,(int)(128 + threshold));
430 long kernel[]={-100,-100,-100,-100,801,-100,-100,-100,-100};
431 if (!Tmp.Filter(kernel,3,800,128)){
433 @@ -2755,7 +2755,7 @@ bool CxImage::UnsharpMask(float radius /*= 5.0*/, float amount /*= 0.5*/, int th
434 if (abs(diff) < threshold){
435 dest_row[z] = cur_row[z];
437 - dest_row[z] = (BYTE)min(255, max(0,(int)(cur_row[z] + amount * diff)));
438 + dest_row[z] = (BYTE)cxmin(255, cxmax(0,(int)(cur_row[z] + amount * diff)));
442 @@ -2952,7 +2952,7 @@ bool CxImage::RedEyeRemove(float strength)
443 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)));
445 color = BlindGetPixelColor(x,y);
446 - color.rgbRed = (BYTE)(a*min(color.rgbGreen,color.rgbBlue)+(1.0f-a)*color.rgbRed);
447 + color.rgbRed = (BYTE)(a*cxmin(color.rgbGreen,color.rgbBlue)+(1.0f-a)*color.rgbRed);
448 BlindSetPixelColor(x,y,color);
451 @@ -2990,7 +2990,7 @@ bool CxImage::Saturate(const long saturation, const long colorspace)
454 for (int i=0;i<256;i++) {
455 - cTable[i] = (BYTE)max(0,min(255,(int)(i + saturation)));
456 + cTable[i] = (BYTE)cxmax(0,cxmin(255,(int)(i + saturation)));
458 for(long y=ymin; y<ymax; y++){
459 info.nProgress = (long)(100*(y-ymin)/(ymax-ymin));
460 @@ -3012,7 +3012,7 @@ bool CxImage::Saturate(const long saturation, const long colorspace)
463 for (int i=0;i<256;i++) {
464 - cTable[i] = (BYTE)max(0,min(255,(int)((i-128)*(100 + saturation)/100.0f + 128.5f)));
465 + cTable[i] = (BYTE)cxmax(0,cxmin(255,(int)((i-128)*(100 + saturation)/100.0f + 128.5f)));
467 for(long y=ymin; y<ymax; y++){
468 info.nProgress = (long)(100*(y-ymin)/(ymax-ymin));
469 @@ -3242,10 +3242,10 @@ int CxImage::OptimalThreshold(long method, RECT * pBox, CxImage* pContrastMask)
471 long xmin,xmax,ymin,ymax;
473 - xmin = max(pBox->left,0);
474 - xmax = min(pBox->right,head.biWidth);
475 - ymin = max(pBox->bottom,0);
476 - ymax = min(pBox->top,head.biHeight);
477 + xmin = cxmax(pBox->left,0);
478 + xmax = cxmin(pBox->right,head.biWidth);
479 + ymin = cxmax(pBox->bottom,0);
480 + ymax = cxmin(pBox->top,head.biHeight);
483 xmax = head.biWidth; ymax=head.biHeight;
484 @@ -3463,7 +3463,7 @@ bool CxImage::AdaptiveThreshold(long method, long nBoxSize, CxImage* pContrastMa
485 r.top = r.bottom + nBoxSize;
486 int threshold = OptimalThreshold(method, &r, pContrastMask);
487 if (threshold <0) return false;
488 - mask.SetPixelIndex(x,y,(BYTE)max(0,min(255,nBias+((1.0f-fGlobalLocalBalance)*threshold + fGlobalLocalBalance*globalthreshold))));
489 + mask.SetPixelIndex(x,y,(BYTE)cxmax(0,cxmin(255,nBias+((1.0f-fGlobalLocalBalance)*threshold + fGlobalLocalBalance*globalthreshold))));
493 @@ -3490,10 +3490,6 @@ bool CxImage::AdaptiveThreshold(long method, long nBoxSize, CxImage* pContrastMa
494 * Note: nOpacity=0 && bSelectFilledArea=true act as a "magic wand"
495 * \return true if everything is ok
497 -#if defined(XBMC) && !defined(_WIN32)
498 -int max(int a, int b) { return a > b ? a : b; }
499 -int min(int a, int b) { return a < b ? a : b; }
502 bool CxImage::FloodFill(const long xStart, const long yStart, const RGBQUAD cFillColor, const BYTE nTolerance,
503 BYTE nOpacity, const bool bSelectFilledArea, const BYTE nSelectionLevel)
504 @@ -3538,8 +3534,8 @@ bool CxImage::FloodFill(const long xStart, const long yStart, const RGBQUAD cFil
505 if (IsIndexed()){ //--- Generic indexed image, no tolerance OR Grayscale image with tolerance
506 BYTE idxRef = GetPixelIndex(xStart,yStart);
507 BYTE idxFill = GetNearestIndex(cFillColor);
508 - BYTE idxMin = (BYTE)min(255, max(0,(int)(idxRef - nTolerance)));
509 - BYTE idxMax = (BYTE)min(255, max(0,(int)(idxRef + nTolerance)));
510 + BYTE idxMin = (BYTE)cxmin(255, cxmax(0,(int)(idxRef - nTolerance)));
511 + BYTE idxMax = (BYTE)cxmin(255, cxmax(0,(int)(idxRef + nTolerance)));
515 @@ -3575,12 +3571,12 @@ bool CxImage::FloodFill(const long xStart, const long yStart, const RGBQUAD cFil
516 } else { //--- RGB image
517 RGBQUAD cRef = GetPixelColor(xStart,yStart);
518 RGBQUAD cRefMin, cRefMax;
519 - cRefMin.rgbRed = (BYTE)min(255, max(0,(int)(cRef.rgbRed - nTolerance)));
520 - cRefMin.rgbGreen = (BYTE)min(255, max(0,(int)(cRef.rgbGreen - nTolerance)));
521 - cRefMin.rgbBlue = (BYTE)min(255, max(0,(int)(cRef.rgbBlue - nTolerance)));
522 - cRefMax.rgbRed = (BYTE)min(255, max(0,(int)(cRef.rgbRed + nTolerance)));
523 - cRefMax.rgbGreen = (BYTE)min(255, max(0,(int)(cRef.rgbGreen + nTolerance)));
524 - cRefMax.rgbBlue = (BYTE)min(255, max(0,(int)(cRef.rgbBlue + nTolerance)));
525 + cRefMin.rgbRed = (BYTE)cxmin(255, cxmax(0,(int)(cRef.rgbRed - nTolerance)));
526 + cRefMin.rgbGreen = (BYTE)cxmin(255, cxmax(0,(int)(cRef.rgbGreen - nTolerance)));
527 + cRefMin.rgbBlue = (BYTE)cxmin(255, cxmax(0,(int)(cRef.rgbBlue - nTolerance)));
528 + cRefMax.rgbRed = (BYTE)cxmin(255, cxmax(0,(int)(cRef.rgbRed + nTolerance)));
529 + cRefMax.rgbGreen = (BYTE)cxmin(255, cxmax(0,(int)(cRef.rgbGreen + nTolerance)));
530 + cRefMax.rgbBlue = (BYTE)cxmin(255, cxmax(0,(int)(cRef.rgbBlue + nTolerance)));
534 diff --git a/lib/cximage-6.0/CxImage/ximage.cpp b/lib/cximage-6.0/CxImage/ximage.cpp
535 index e81d3c6..26c6993 100644
536 --- a/lib/cximage-6.0/CxImage/ximage.cpp
537 +++ b/lib/cximage-6.0/CxImage/ximage.cpp
538 @@ -460,7 +460,7 @@ bool CxImage::CreateFromArray(BYTE* pArray,DWORD dwWidth,DWORD dwHeight,DWORD dw
542 - memcpy(dst,src,min(info.dwEffWidth,dwBytesperline));
543 + memcpy(dst,src,cxmin(info.dwEffWidth,dwBytesperline));
547 @@ -500,7 +500,7 @@ bool CxImage::CreateFromMatrix(BYTE** ppMatrix,DWORD dwWidth,DWORD dwHeight,DWOR
551 - memcpy(dst,src,min(info.dwEffWidth,dwBytesperline));
552 + memcpy(dst,src,cxmin(info.dwEffWidth,dwBytesperline));
556 diff --git a/lib/cximage-6.0/CxImage/ximagif.cpp b/lib/cximage-6.0/CxImage/ximagif.cpp
557 index b89e061..64b1ccc 100644
558 --- a/lib/cximage-6.0/CxImage/ximagif.cpp
559 +++ b/lib/cximage-6.0/CxImage/ximagif.cpp
560 @@ -478,7 +478,7 @@ bool CxImageGIF::Encode(CxFile * fp, CxImage ** pImages, int pagecount, bool bLo
561 ghost.EncodeHeader(fp);
564 - ghost.SetLoops(max(0,m_loops-1));
565 + ghost.SetLoops(cxmax(0,m_loops-1));
566 ghost.EncodeLoopExtension(fp);
569 @@ -1340,10 +1340,10 @@ void CxImageGIF::GetComment(char* sz_comment_out)
570 ////////////////////////////////////////////////////////////////////////////////
571 void CxImageGIF::GifMix(CxImage & imgsrc2, struct_image & imgdesc)
573 - long ymin = max(0,(long)(GetHeight()-imgdesc.t - imgdesc.h));
574 + long ymin = cxmax(0,(long)(GetHeight()-imgdesc.t - imgdesc.h));
575 long ymax = GetHeight()-imgdesc.t;
576 long xmin = imgdesc.l;
577 - long xmax = min(GetWidth(), (DWORD)(imgdesc.l + imgdesc.w));
578 + long xmax = cxmin(GetWidth(), (DWORD)(imgdesc.l + imgdesc.w));
580 long ibg2= imgsrc2.GetTransIndex();
582 diff --git a/lib/cximage-6.0/CxImage/ximahist.cpp b/lib/cximage-6.0/CxImage/ximahist.cpp
583 index a2aed03..5391107 100644
584 --- a/lib/cximage-6.0/CxImage/ximahist.cpp
585 +++ b/lib/cximage-6.0/CxImage/ximahist.cpp
586 @@ -110,7 +110,7 @@ bool CxImage::HistogramStretch(long method, double threshold)
589 for (x = 0; x <256; x++){
590 - lut[x] = (BYTE)max(0,min(255,(255 * (x - minc) / (maxc - minc))));
591 + lut[x] = (BYTE)cxmax(0,cxmin(255,(255 * (x - minc) / (maxc - minc))));
594 for (y=0; y<head.biHeight; y++) {
595 @@ -152,7 +152,7 @@ bool CxImage::HistogramStretch(long method, double threshold)
598 for (x = 0; x <256; x++){
599 - lut[x] = (BYTE)max(0,min(255,(255 * (x - minc) / (maxc - minc))));
600 + lut[x] = (BYTE)cxmax(0,cxmin(255,(255 * (x - minc) / (maxc - minc))));
604 @@ -225,7 +225,7 @@ bool CxImage::HistogramStretch(long method, double threshold)
605 BYTE range = maxR - minR;
607 for (x = 0; x <256; x++){
608 - lutR[x] = (BYTE)max(0,min(255,(255 * (x - minR) / range)));
609 + lutR[x] = (BYTE)cxmax(0,cxmin(255,(255 * (x - minR) / range)));
611 } else lutR[minR] = minR;
613 @@ -233,7 +233,7 @@ bool CxImage::HistogramStretch(long method, double threshold)
616 for (x = 0; x <256; x++){
617 - lutG[x] = (BYTE)max(0,min(255,(255 * (x - minG) / range)));
618 + lutG[x] = (BYTE)cxmax(0,cxmin(255,(255 * (x - minG) / range)));
620 } else lutG[minG] = minG;
622 @@ -241,7 +241,7 @@ bool CxImage::HistogramStretch(long method, double threshold)
625 for (x = 0; x <256; x++){
626 - lutB[x] = (BYTE)max(0,min(255,(255 * (x - minB) / range)));
627 + lutB[x] = (BYTE)cxmax(0,cxmin(255,(255 * (x - minB) / range)));
629 } else lutB[minB] = minB;
631 @@ -292,7 +292,7 @@ bool CxImage::HistogramStretch(long method, double threshold)
634 for (x = 0; x <256; x++){
635 - lut[x] = (BYTE)max(0,min(255,(255 * (x - minc) / (maxc - minc))));
636 + lut[x] = (BYTE)cxmax(0,cxmin(255,(255 * (x - minc) / (maxc - minc))));
639 for(y=0; y<head.biHeight; y++){
640 diff --git a/lib/cximage-6.0/CxImage/ximaint.cpp b/lib/cximage-6.0/CxImage/ximaint.cpp
641 index 989d76c..5d49213 100644
642 --- a/lib/cximage-6.0/CxImage/ximaint.cpp
643 +++ b/lib/cximage-6.0/CxImage/ximaint.cpp
644 @@ -26,8 +26,8 @@ void CxImage::OverflowCoordinates(long &x, long &y, OverflowMethod const ofMetho
648 - x=max(x,0); x=min(x, head.biWidth-1);
649 - y=max(y,0); y=min(y, head.biHeight-1);
650 + x=cxmax(x,0); x=cxmin(x, head.biWidth-1);
651 + y=cxmax(y,0); y=cxmin(y, head.biHeight-1);
655 @@ -59,8 +59,8 @@ void CxImage::OverflowCoordinates(float &x, float &y, OverflowMethod const ofMet
659 - x=max(x,0); x=min(x, head.biWidth-1);
660 - y=max(y,0); y=min(y, head.biHeight-1);
661 + x=cxmax(x,0); x=cxmin(x, head.biWidth-1);
662 + y=cxmax(y,0); y=cxmin(y, head.biHeight-1);
666 diff --git a/lib/cximage-6.0/CxImage/ximaiter.h b/lib/cximage-6.0/CxImage/ximaiter.h
667 index 9788919..01a720b 100644
668 --- a/lib/cximage-6.0/CxImage/ximaiter.h
669 +++ b/lib/cximage-6.0/CxImage/ximaiter.h
670 @@ -140,7 +140,7 @@ inline void CImageIterator::SetY(int y)
671 inline void CImageIterator::SetRow(BYTE *buf, int n)
673 if (n<0) n = (int)ima->GetEffWidth();
674 - else n = min(n,(int)ima->GetEffWidth());
675 + else n = cxmin(n,(int)ima->GetEffWidth());
677 if ((IterImage!=NULL)&&(buf!=NULL)&&(n>0)) memcpy(IterImage,buf,n);
679 @@ -148,7 +148,7 @@ inline void CImageIterator::SetRow(BYTE *buf, int n)
680 inline void CImageIterator::GetRow(BYTE *buf, int n)
682 if ((IterImage!=NULL)&&(buf!=NULL)&&(n>0))
683 - memcpy(buf,IterImage,min(n,(int)ima->GetEffWidth()));
684 + memcpy(buf,IterImage,cxmin(n,(int)ima->GetEffWidth()));
686 /////////////////////////////////////////////////////////////////////
687 inline BYTE* CImageIterator::GetRow()
688 diff --git a/lib/cximage-6.0/CxImage/ximajbg.cpp b/lib/cximage-6.0/CxImage/ximajbg.cpp
689 index 06fb9bf..8a01e28 100644
690 --- a/lib/cximage-6.0/CxImage/ximajbg.cpp
691 +++ b/lib/cximage-6.0/CxImage/ximajbg.cpp
692 @@ -145,7 +145,7 @@ bool CxImageJBG::Encode(CxFile * hFile)
693 jbg_enc_init(&jbig_state, w, h, planes, &buffer, jbig_data_out, hFile);
695 //jbg_enc_layers(&jbig_state, 2);
696 - //jbg_enc_lrlmax(&jbig_state, 800, 600);
697 + //jbg_enc_lrlcxmax(&jbig_state, 800, 600);
699 // Specify a few other options (each is ignored if negative)
700 int dl = -1, dh = -1, d = -1, l0 = -1, mx = -1;
701 diff --git a/lib/cximage-6.0/CxImage/ximapal.cpp b/lib/cximage-6.0/CxImage/ximapal.cpp
702 index b3bd3da..3788c98 100644
703 --- a/lib/cximage-6.0/CxImage/ximapal.cpp
704 +++ b/lib/cximage-6.0/CxImage/ximapal.cpp
705 @@ -398,8 +398,8 @@ void CxImage::RGBtoBGR(BYTE *buffer, int length)
707 if (buffer && (head.biClrUsed==0)){
709 - length = min(length,(int)info.dwEffWidth);
710 - length = min(length,(int)(3*head.biWidth));
711 + length = cxmin(length,(int)info.dwEffWidth);
712 + length = cxmin(length,(int)(3*head.biWidth));
713 for (int i=0;i<length;i+=3){
714 temp = buffer[i]; buffer[i] = buffer[i+2]; buffer[i+2] = temp;
716 @@ -444,7 +444,7 @@ void CxImage::SetPalette(DWORD n, BYTE *r, BYTE *g, BYTE *b)
719 RGBQUAD* ppal=GetPalette();
720 - DWORD m=min(n,head.biClrUsed);
721 + DWORD m=cxmin(n,head.biClrUsed);
722 for (DWORD i=0; i<m;i++){
724 ppal[i].rgbGreen=g[i];
725 @@ -457,7 +457,7 @@ void CxImage::SetPalette(rgb_color *rgb,DWORD nColors)
727 if ((!rgb)||(pDib==NULL)||(head.biClrUsed==0)) return;
728 RGBQUAD* ppal=GetPalette();
729 - DWORD m=min(nColors,head.biClrUsed);
730 + DWORD m=cxmin(nColors,head.biClrUsed);
731 for (DWORD i=0; i<m;i++){
732 ppal[i].rgbRed=rgb[i].r;
733 ppal[i].rgbGreen=rgb[i].g;
734 @@ -469,7 +469,7 @@ void CxImage::SetPalette(rgb_color *rgb,DWORD nColors)
735 void CxImage::SetPalette(RGBQUAD* pPal,DWORD nColors)
737 if ((pPal==NULL)||(pDib==NULL)||(head.biClrUsed==0)) return;
738 - memcpy(GetPalette(),pPal,min(GetPaletteSize(),nColors*sizeof(RGBQUAD)));
739 + memcpy(GetPalette(),pPal,cxmin(GetPaletteSize(),nColors*sizeof(RGBQUAD)));
740 info.last_c_isvalid = false;
742 ////////////////////////////////////////////////////////////////////////////////
743 @@ -654,10 +654,10 @@ void CxImage::SetClrImportant(DWORD ncolors)
745 switch(head.biBitCount){
747 - head.biClrImportant = min(ncolors,2);
748 + head.biClrImportant = cxmin(ncolors,2);
751 - head.biClrImportant = min(ncolors,16);
752 + head.biClrImportant = cxmin(ncolors,16);
755 head.biClrImportant = ncolors;
756 diff --git a/lib/cximage-6.0/CxImage/ximapng.cpp b/lib/cximage-6.0/CxImage/ximapng.cpp
757 index a58441c..4b5cc50 100644
758 --- a/lib/cximage-6.0/CxImage/ximapng.cpp
759 +++ b/lib/cximage-6.0/CxImage/ximapng.cpp
760 @@ -206,9 +206,9 @@ bool CxImagePNG::Decode(CxFile *hFile)
761 } else SetGrayPalette(); //<DP> needed for grayscale PNGs
763 #ifdef USE_NEW_LIBPNG_API
764 - int nshift = max(0,(_bit_depth>>3)-1)<<3;
765 + int nshift = cxmax(0,(_bit_depth>>3)-1)<<3;
767 - int nshift = max(0,(info_ptr->bit_depth>>3)-1)<<3;
768 + int nshift = cxmax(0,(info_ptr->bit_depth>>3)-1)<<3;
771 #ifdef USE_NEW_LIBPNG_API
772 @@ -255,10 +255,10 @@ bool CxImagePNG::Decode(CxFile *hFile)
775 #ifdef USE_NEW_LIBPNG_API
776 - for (ip=0;ip<min(head.biClrUsed,(unsigned long)_num_trans);ip++)
777 + for (ip=0;ip<cxmin(head.biClrUsed,(unsigned long)_num_trans);ip++)
778 pal[ip].rgbReserved=_trans_alpha[ip];
780 - for (ip=0;ip<min(head.biClrUsed,(unsigned long)info_ptr->num_trans);ip++)
781 + for (ip=0;ip<cxmin(head.biClrUsed,(unsigned long)info_ptr->num_trans);ip++)
782 #if PNG_LIBPNG_VER > 10399
783 pal[ip].rgbReserved=info_ptr->trans_alpha[ip];
785 @@ -737,9 +737,9 @@ bool CxImagePNG::Encode(CxFile *hFile)
786 #endif // CXIMAGE_SUPPORT_ALPHA // <vho>
788 #ifdef USE_NEW_LIBPNG_API
789 - int row_size = max(info.dwEffWidth, (_width * _channels * _bit_depth / 8));
790 + int row_size = cxmax(info.dwEffWidth, (_width * _channels * _bit_depth / 8));
792 - int row_size = max(info.dwEffWidth, info_ptr->width*info_ptr->channels*(info_ptr->bit_depth/8));
793 + int row_size = cxmax(info.dwEffWidth, info_ptr->width*info_ptr->channels*(info_ptr->bit_depth/8));
794 info_ptr->rowbytes = row_size;
796 BYTE *row_pointers = new BYTE[row_size];
797 diff --git a/lib/cximage-6.0/CxImage/ximaraw.cpp b/lib/cximage-6.0/CxImage/ximaraw.cpp
798 index fd86f96..52d964d 100644
799 --- a/lib/cximage-6.0/CxImage/ximaraw.cpp
800 +++ b/lib/cximage-6.0/CxImage/ximaraw.cpp
801 @@ -216,7 +216,7 @@ bool CxImageRAW::Decode(CxFile *hFile)
803 DWORD size = dcr.width * (dcr.colors*dcr.opt.output_bps/8);
805 - memcpy(GetBits(dcr.height - 1 - row), ppm, min(size,GetEffWidth()));
806 + memcpy(GetBits(dcr.height - 1 - row), ppm, cxmin(size,GetEffWidth()));
810 @@ -298,7 +298,7 @@ bool CxImageRAW::GetExifThumbnail(const char *filename, const char *outname, int
812 if (image.GetWidth() > 256 || image.GetHeight() > 256)
814 - float amount = 256.0f / max(image.GetWidth(), image.GetHeight());
815 + float amount = 256.0f / cxmax(image.GetWidth(), image.GetHeight());
816 image.Resample((long)(image.GetWidth() * amount), (long)(image.GetHeight() * amount), 0);
819 diff --git a/lib/cximage-6.0/CxImage/ximasel.cpp b/lib/cximage-6.0/CxImage/ximasel.cpp
820 index 3a7c9a1..37cd10f 100644
821 --- a/lib/cximage-6.0/CxImage/ximasel.cpp
822 +++ b/lib/cximage-6.0/CxImage/ximasel.cpp
823 @@ -113,15 +113,15 @@ bool CxImage::SelectionAddRect(RECT r, BYTE level)
824 if (r.left<r.right) {r2.left=r.left; r2.right=r.right; } else {r2.left=r.right ; r2.right=r.left; }
825 if (r.bottom<r.top) {r2.bottom=r.bottom; r2.top=r.top; } else {r2.bottom=r.top ; r2.top=r.bottom; }
827 - if (info.rSelectionBox.top <= r2.top) info.rSelectionBox.top = max(0L,min(head.biHeight,r2.top+1));
828 - if (info.rSelectionBox.left > r2.left) info.rSelectionBox.left = max(0L,min(head.biWidth,r2.left));
829 - if (info.rSelectionBox.right <= r2.right) info.rSelectionBox.right = max(0L,min(head.biWidth,r2.right+1));
830 - if (info.rSelectionBox.bottom > r2.bottom) info.rSelectionBox.bottom = max(0L,min(head.biHeight,r2.bottom));
831 + if (info.rSelectionBox.top <= r2.top) info.rSelectionBox.top = cxmax(0L,cxmin(head.biHeight,r2.top+1));
832 + if (info.rSelectionBox.left > r2.left) info.rSelectionBox.left = cxmax(0L,cxmin(head.biWidth,r2.left));
833 + if (info.rSelectionBox.right <= r2.right) info.rSelectionBox.right = cxmax(0L,cxmin(head.biWidth,r2.right+1));
834 + if (info.rSelectionBox.bottom > r2.bottom) info.rSelectionBox.bottom = cxmax(0L,cxmin(head.biHeight,r2.bottom));
836 - long ymin = max(0L,min(head.biHeight,r2.bottom));
837 - long ymax = max(0L,min(head.biHeight,r2.top+1));
838 - long xmin = max(0L,min(head.biWidth,r2.left));
839 - long xmax = max(0L,min(head.biWidth,r2.right+1));
840 + long ymin = cxmax(0L,cxmin(head.biHeight,r2.bottom));
841 + long ymax = cxmax(0L,cxmin(head.biHeight,r2.top+1));
842 + long xmin = cxmax(0L,cxmin(head.biWidth,r2.left));
843 + long xmax = cxmax(0L,cxmin(head.biWidth,r2.right+1));
845 for (long y=ymin; y<ymax; y++)
846 memset(pSelection + xmin + y * head.biWidth, level, xmax-xmin);
847 @@ -144,18 +144,18 @@ bool CxImage::SelectionAddEllipse(RECT r, BYTE level)
848 long xcenter = (r.right + r.left)/2;
849 long ycenter = (r.top + r.bottom)/2;
851 - if (info.rSelectionBox.left > (xcenter - xradius)) info.rSelectionBox.left = max(0L,min(head.biWidth,(xcenter - xradius)));
852 - if (info.rSelectionBox.right <= (xcenter + xradius)) info.rSelectionBox.right = max(0L,min(head.biWidth,(xcenter + xradius + 1)));
853 - if (info.rSelectionBox.bottom > (ycenter - yradius)) info.rSelectionBox.bottom = max(0L,min(head.biHeight,(ycenter - yradius)));
854 - if (info.rSelectionBox.top <= (ycenter + yradius)) info.rSelectionBox.top = max(0L,min(head.biHeight,(ycenter + yradius + 1)));
855 + if (info.rSelectionBox.left > (xcenter - xradius)) info.rSelectionBox.left = cxmax(0L,cxmin(head.biWidth,(xcenter - xradius)));
856 + if (info.rSelectionBox.right <= (xcenter + xradius)) info.rSelectionBox.right = cxmax(0L,cxmin(head.biWidth,(xcenter + xradius + 1)));
857 + if (info.rSelectionBox.bottom > (ycenter - yradius)) info.rSelectionBox.bottom = cxmax(0L,cxmin(head.biHeight,(ycenter - yradius)));
858 + if (info.rSelectionBox.top <= (ycenter + yradius)) info.rSelectionBox.top = cxmax(0L,cxmin(head.biHeight,(ycenter + yradius + 1)));
860 - long xmin = max(0L,min(head.biWidth,xcenter - xradius));
861 - long xmax = max(0L,min(head.biWidth,xcenter + xradius + 1));
862 - long ymin = max(0L,min(head.biHeight,ycenter - yradius));
863 - long ymax = max(0L,min(head.biHeight,ycenter + yradius + 1));
864 + long xmin = cxmax(0L,cxmin(head.biWidth,xcenter - xradius));
865 + long xmax = cxmax(0L,cxmin(head.biWidth,xcenter + xradius + 1));
866 + long ymin = cxmax(0L,cxmin(head.biHeight,ycenter - yradius));
867 + long ymax = cxmax(0L,cxmin(head.biHeight,ycenter + yradius + 1));
870 - for (y=ymin; y<min(ycenter,ymax); y++){
871 + for (y=ymin; y<cxmin(ycenter,ymax); y++){
872 for (long x=xmin; x<xmax; x++){
873 yo = (long)(ycenter - yradius * sqrt(1-pow((float)(x - xcenter)/(float)xradius,2)));
874 if (yo<y) pSelection[x + y * head.biWidth] = level;
875 @@ -268,10 +268,10 @@ bool CxImage::SelectionAddPolygon(POINT *points, long npoints, BYTE level)
877 if (current->x < next->x) {r2.left=current->x; r2.right=next->x; } else {r2.left=next->x ; r2.right=current->x; }
878 if (current->y < next->y) {r2.bottom=current->y; r2.top=next->y; } else {r2.bottom=next->y ; r2.top=current->y; }
879 - if (localbox.top < r2.top) localbox.top = max(0L,min(head.biHeight-1,r2.top+1));
880 - if (localbox.left > r2.left) localbox.left = max(0L,min(head.biWidth-1,r2.left-1));
881 - if (localbox.right < r2.right) localbox.right = max(0L,min(head.biWidth-1,r2.right+1));
882 - if (localbox.bottom > r2.bottom) localbox.bottom = max(0L,min(head.biHeight-1,r2.bottom-1));
883 + if (localbox.top < r2.top) localbox.top = cxmax(0L,cxmin(head.biHeight-1,r2.top+1));
884 + if (localbox.left > r2.left) localbox.left = cxmax(0L,cxmin(head.biWidth-1,r2.left-1));
885 + if (localbox.right < r2.right) localbox.right = cxmax(0L,cxmin(head.biWidth-1,r2.right+1));
886 + if (localbox.bottom > r2.bottom) localbox.bottom = cxmax(0L,cxmin(head.biHeight-1,r2.bottom-1));
890 @@ -385,10 +385,10 @@ bool CxImage::SelectionAddPolygon(POINT *points, long npoints, BYTE level)
891 for (x=localbox.left; x<=localbox.right; x++)
892 if (plocal[x + yoffset]!=1) pSelection[x + yoffset]=level;
894 - if (info.rSelectionBox.top <= localbox.top) info.rSelectionBox.top = min(head.biHeight,localbox.top + 1);
895 - if (info.rSelectionBox.left > localbox.left) info.rSelectionBox.left = min(head.biWidth,localbox.left);
896 - if (info.rSelectionBox.right <= localbox.right) info.rSelectionBox.right = min(head.biWidth,localbox.right + 1);
897 - if (info.rSelectionBox.bottom > localbox.bottom) info.rSelectionBox.bottom = min(head.biHeight,localbox.bottom);
898 + if (info.rSelectionBox.top <= localbox.top) info.rSelectionBox.top = cxmin(head.biHeight,localbox.top + 1);
899 + if (info.rSelectionBox.left > localbox.left) info.rSelectionBox.left = cxmin(head.biWidth,localbox.left);
900 + if (info.rSelectionBox.right <= localbox.right) info.rSelectionBox.right = cxmin(head.biWidth,localbox.right + 1);
901 + if (info.rSelectionBox.bottom > localbox.bottom) info.rSelectionBox.bottom = cxmin(head.biHeight,localbox.bottom);
905 diff --git a/lib/cximage-6.0/CxImage/ximath.cpp b/lib/cximage-6.0/CxImage/ximath.cpp
906 index 37533e2..f84eb72 100644
907 --- a/lib/cximage-6.0/CxImage/ximath.cpp
908 +++ b/lib/cximage-6.0/CxImage/ximath.cpp
909 @@ -64,10 +64,10 @@ CxRect2 CxRect2::CrossSection(CxRect2 const &r2) const
913 - cs.botLeft.x=max(botLeft.x, r2.botLeft.x);
914 - cs.botLeft.y=max(botLeft.y, r2.botLeft.y);
915 - cs.topRight.x=min(topRight.x, r2.topRight.x);
916 - cs.topRight.y=min(topRight.y, r2.topRight.y);
917 + cs.botLeft.x=cxmax(botLeft.x, r2.botLeft.x);
918 + cs.botLeft.y=cxmax(botLeft.y, r2.botLeft.y);
919 + cs.topRight.x=cxmin(topRight.x, r2.topRight.x);
920 + cs.topRight.y=cxmin(topRight.y, r2.topRight.y);
921 if (cs.botLeft.x<=cs.topRight.x && cs.botLeft.y<=cs.topRight.y) {
924 diff --git a/lib/cximage-6.0/CxImage/ximatif.cpp b/lib/cximage-6.0/CxImage/ximatif.cpp
925 index 658392a..002766c 100644
926 --- a/lib/cximage-6.0/CxImage/ximatif.cpp
927 +++ b/lib/cximage-6.0/CxImage/ximatif.cpp
928 @@ -470,9 +470,9 @@ bool CxImageTIF::Decode(CxFile * hFile)
929 if ( cb > 0.00304 ) cb = 1.055 * pow(cb,0.41667) - 0.055;
930 else cb = 12.92 * cb;
932 - c.rgbRed =(BYTE)max(0,min(255,(int)(cr*255)));
933 - c.rgbGreen=(BYTE)max(0,min(255,(int)(cg*255)));
934 - c.rgbBlue =(BYTE)max(0,min(255,(int)(cb*255)));
935 + c.rgbRed =(BYTE)cxmax(0,cxmin(255,(int)(cr*255)));
936 + c.rgbGreen=(BYTE)cxmax(0,cxmin(255,(int)(cg*255)));
937 + c.rgbBlue =(BYTE)cxmax(0,cxmin(255,(int)(cb*255)));
939 SetPixelColor(xi,yi,c);
940 #if CXIMAGE_SUPPORT_ALPHA
941 diff --git a/lib/cximage-6.0/CxImage/ximatran.cpp b/lib/cximage-6.0/CxImage/ximatran.cpp
942 index 64a71e7..84d5e03 100644
943 --- a/lib/cximage-6.0/CxImage/ximatran.cpp
944 +++ b/lib/cximage-6.0/CxImage/ximatran.cpp
945 @@ -302,12 +302,12 @@ bool CxImage::RotateLeft(CxImage* iDst)
946 for (ys = 0; ys < newHeight; ys+=RBLOCK) {
947 if (head.biBitCount==24) {
948 //RGB24 optimized pixel access:
949 - for (x = xs; x < min(newWidth, xs+RBLOCK); x++){ //do rotation
950 + for (x = xs; x < cxmin(newWidth, xs+RBLOCK); x++){ //do rotation
951 info.nProgress = (long)(100*x/newWidth);
953 dstPtr = (BYTE*) imgDest.BlindGetPixelPointer(x,ys);
954 srcPtr = (BYTE*) BlindGetPixelPointer(ys, x2);
955 - for (y = ys; y < min(newHeight, ys+RBLOCK); y++){
956 + for (y = ys; y < cxmin(newHeight, ys+RBLOCK); y++){
957 //imgDest.SetPixelColor(x, y, GetPixelColor(y, x2));
958 *(dstPtr) = *(srcPtr);
959 *(dstPtr+1) = *(srcPtr+1);
960 @@ -318,19 +318,19 @@ bool CxImage::RotateLeft(CxImage* iDst)
963 //anything else than 24bpp (and 1bpp): palette
964 - for (x = xs; x < min(newWidth, xs+RBLOCK); x++){
965 + for (x = xs; x < cxmin(newWidth, xs+RBLOCK); x++){
966 info.nProgress = (long)(100*x/newWidth); //<Anatoly Ivasyuk>
968 - for (y = ys; y < min(newHeight, ys+RBLOCK); y++){
969 + for (y = ys; y < cxmin(newHeight, ys+RBLOCK); y++){
970 imgDest.SetPixelIndex(x, y, BlindGetPixelIndex(y, x2));
973 }//if (version selection)
974 #if CXIMAGE_SUPPORT_ALPHA
975 if (AlphaIsValid()) {
976 - for (x = xs; x < min(newWidth, xs+RBLOCK); x++){
977 + for (x = xs; x < cxmin(newWidth, xs+RBLOCK); x++){
979 - for (y = ys; y < min(newHeight, ys+RBLOCK); y++){
980 + for (y = ys; y < cxmin(newHeight, ys+RBLOCK); y++){
981 imgDest.AlphaSet(x,y,BlindAlphaGet(y, x2));
984 @@ -343,9 +343,9 @@ bool CxImage::RotateLeft(CxImage* iDst)
985 imgDest.info.rSelectionBox.right = newWidth-info.rSelectionBox.bottom;
986 imgDest.info.rSelectionBox.bottom = info.rSelectionBox.left;
987 imgDest.info.rSelectionBox.top = info.rSelectionBox.right;
988 - for (x = xs; x < min(newWidth, xs+RBLOCK); x++){
989 + for (x = xs; x < cxmin(newWidth, xs+RBLOCK); x++){
991 - for (y = ys; y < min(newHeight, ys+RBLOCK); y++){
992 + for (y = ys; y < cxmin(newHeight, ys+RBLOCK); y++){
993 imgDest.SelectionSet(x,y,BlindSelectionGet(y, x2));
996 @@ -447,12 +447,12 @@ bool CxImage::RotateRight(CxImage* iDst)
997 for (ys = 0; ys < newHeight; ys+=RBLOCK) {
998 if (head.biBitCount==24) {
999 //RGB24 optimized pixel access:
1000 - for (y = ys; y < min(newHeight, ys+RBLOCK); y++){
1001 + for (y = ys; y < cxmin(newHeight, ys+RBLOCK); y++){
1002 info.nProgress = (long)(100*y/newHeight); //<Anatoly Ivasyuk>
1004 dstPtr = (BYTE*) imgDest.BlindGetPixelPointer(xs,y);
1005 srcPtr = (BYTE*) BlindGetPixelPointer(y2, xs);
1006 - for (x = xs; x < min(newWidth, xs+RBLOCK); x++){
1007 + for (x = xs; x < cxmin(newWidth, xs+RBLOCK); x++){
1008 //imgDest.SetPixelColor(x, y, GetPixelColor(y2, x));
1009 *(dstPtr) = *(srcPtr);
1010 *(dstPtr+1) = *(srcPtr+1);
1011 @@ -463,19 +463,19 @@ bool CxImage::RotateRight(CxImage* iDst)
1014 //anything else than BW & RGB24: palette
1015 - for (y = ys; y < min(newHeight, ys+RBLOCK); y++){
1016 + for (y = ys; y < cxmin(newHeight, ys+RBLOCK); y++){
1017 info.nProgress = (long)(100*y/newHeight); //<Anatoly Ivasyuk>
1019 - for (x = xs; x < min(newWidth, xs+RBLOCK); x++){
1020 + for (x = xs; x < cxmin(newWidth, xs+RBLOCK); x++){
1021 imgDest.SetPixelIndex(x, y, BlindGetPixelIndex(y2, x));
1025 #if CXIMAGE_SUPPORT_ALPHA
1026 if (AlphaIsValid()){
1027 - for (y = ys; y < min(newHeight, ys+RBLOCK); y++){
1028 + for (y = ys; y < cxmin(newHeight, ys+RBLOCK); y++){
1030 - for (x = xs; x < min(newWidth, xs+RBLOCK); x++){
1031 + for (x = xs; x < cxmin(newWidth, xs+RBLOCK); x++){
1032 imgDest.AlphaSet(x,y,BlindAlphaGet(y2, x));
1035 @@ -488,9 +488,9 @@ bool CxImage::RotateRight(CxImage* iDst)
1036 imgDest.info.rSelectionBox.right = info.rSelectionBox.top;
1037 imgDest.info.rSelectionBox.bottom = newHeight-info.rSelectionBox.right;
1038 imgDest.info.rSelectionBox.top = newHeight-info.rSelectionBox.left;
1039 - for (y = ys; y < min(newHeight, ys+RBLOCK); y++){
1040 + for (y = ys; y < cxmin(newHeight, ys+RBLOCK); y++){
1042 - for (x = xs; x < min(newWidth, xs+RBLOCK); x++){
1043 + for (x = xs; x < cxmin(newWidth, xs+RBLOCK); x++){
1044 imgDest.SelectionSet(x,y,BlindSelectionGet(y2, x));
1047 @@ -608,10 +608,10 @@ bool CxImage::Rotate(float angle, CxImage* iDst)
1048 newP4.x = (float)(p4.x*cos_angle - p4.y*sin_angle);
1049 newP4.y = (float)(p4.x*sin_angle + p4.y*cos_angle);
1051 - leftTop.x = min(min(newP1.x,newP2.x),min(newP3.x,newP4.x));
1052 - leftTop.y = min(min(newP1.y,newP2.y),min(newP3.y,newP4.y));
1053 - rightBottom.x = max(max(newP1.x,newP2.x),max(newP3.x,newP4.x));
1054 - rightBottom.y = max(max(newP1.y,newP2.y),max(newP3.y,newP4.y));
1055 + leftTop.x = cxmin(cxmin(newP1.x,newP2.x),cxmin(newP3.x,newP4.x));
1056 + leftTop.y = cxmin(cxmin(newP1.y,newP2.y),cxmin(newP3.y,newP4.y));
1057 + rightBottom.x = cxmax(cxmax(newP1.x,newP2.x),cxmax(newP3.x,newP4.x));
1058 + rightBottom.y = cxmax(cxmax(newP1.y,newP2.y),cxmax(newP3.y,newP4.y));
1059 leftBottom.x = leftTop.x;
1060 leftBottom.y = rightBottom.y;
1061 rightTop.x = rightBottom.x;
1062 @@ -740,10 +740,10 @@ bool CxImage::Rotate2(float angle,
1065 //(read new dimensions from location of corners)
1066 - float minx = (float) min(min(newp[0].x,newp[1].x),min(newp[2].x,newp[3].x));
1067 - float miny = (float) min(min(newp[0].y,newp[1].y),min(newp[2].y,newp[3].y));
1068 - float maxx = (float) max(max(newp[0].x,newp[1].x),max(newp[2].x,newp[3].x));
1069 - float maxy = (float) max(max(newp[0].y,newp[1].y),max(newp[2].y,newp[3].y));
1070 + float minx = (float) cxmin(cxmin(newp[0].x,newp[1].x),cxmin(newp[2].x,newp[3].x));
1071 + float miny = (float) cxmin(cxmin(newp[0].y,newp[1].y),cxmin(newp[2].y,newp[3].y));
1072 + float maxx = (float) cxmax(cxmax(newp[0].x,newp[1].x),cxmax(newp[2].x,newp[3].x));
1073 + float maxy = (float) cxmax(cxmax(newp[0].y,newp[1].y),cxmax(newp[2].y,newp[3].y));
1074 int newWidth = (int) floor(maxx-minx+0.5f);
1075 int newHeight= (int) floor(maxy-miny+0.5f);
1076 float ssx=((maxx+minx)- ((float) newWidth-1))/2.0f; //start for x
1077 @@ -1003,12 +1003,12 @@ bool CxImage::Resample(long newx, long newy, int mode, CxImage* iDst)
1078 if (info.nEscape) break;
1081 - ifY1 = min(ymax, ifY+1);
1082 + ifY1 = cxmin(ymax, ifY+1);
1084 for(long x=0; x<newx; x++){
1087 - ifX1 = min(xmax, ifX+1);
1088 + ifX1 = cxmin(xmax, ifX+1);
1090 // Interpolate using the four nearest pixels in the source
1091 if (head.biClrUsed){
1092 @@ -1328,9 +1328,9 @@ bool CxImage::DecreaseBpp(DWORD nbit, bool errordiffusion, RGBQUAD* ppal, DWORD
1093 eb=(long)c.rgbBlue - (long)ce.rgbBlue;
1095 c = GetPixelColor(x+1,y);
1096 - c.rgbRed = (BYTE)min(255L,max(0L,(long)c.rgbRed + ((er*7)/16)));
1097 - c.rgbGreen = (BYTE)min(255L,max(0L,(long)c.rgbGreen + ((eg*7)/16)));
1098 - c.rgbBlue = (BYTE)min(255L,max(0L,(long)c.rgbBlue + ((eb*7)/16)));
1099 + c.rgbRed = (BYTE)cxmin(255L,cxmax(0L,(long)c.rgbRed + ((er*7)/16)));
1100 + c.rgbGreen = (BYTE)cxmin(255L,cxmax(0L,(long)c.rgbGreen + ((eg*7)/16)));
1101 + c.rgbBlue = (BYTE)cxmin(255L,cxmax(0L,(long)c.rgbBlue + ((eb*7)/16)));
1102 SetPixelColor(x+1,y,c);
1104 for(int i=-1; i<2; i++){
1105 @@ -1343,9 +1343,9 @@ bool CxImage::DecreaseBpp(DWORD nbit, bool errordiffusion, RGBQUAD* ppal, DWORD
1108 c = GetPixelColor(x+i,y+1);
1109 - c.rgbRed = (BYTE)min(255L,max(0L,(long)c.rgbRed + ((er * coeff)/16)));
1110 - c.rgbGreen = (BYTE)min(255L,max(0L,(long)c.rgbGreen + ((eg * coeff)/16)));
1111 - c.rgbBlue = (BYTE)min(255L,max(0L,(long)c.rgbBlue + ((eb * coeff)/16)));
1112 + c.rgbRed = (BYTE)cxmin(255L,cxmax(0L,(long)c.rgbRed + ((er * coeff)/16)));
1113 + c.rgbGreen = (BYTE)cxmin(255L,cxmax(0L,(long)c.rgbGreen + ((eg * coeff)/16)));
1114 + c.rgbBlue = (BYTE)cxmin(255L,cxmax(0L,(long)c.rgbBlue + ((eb * coeff)/16)));
1115 SetPixelColor(x+i,y+1,c);
1118 @@ -1566,10 +1566,10 @@ bool CxImage::Dither(long method)
1121 nlevel = GetPixelIndex(x + 1, y) + (error * 8) / TotalCoeffSum;
1122 - level = (BYTE)min(255, max(0, (int)nlevel));
1123 + level = (BYTE)cxmin(255, cxmax(0, (int)nlevel));
1124 SetPixelIndex(x + 1, y, level);
1125 nlevel = GetPixelIndex(x + 2, y) + (error * 4) / TotalCoeffSum;
1126 - level = (BYTE)min(255, max(0, (int)nlevel));
1127 + level = (BYTE)cxmin(255, cxmax(0, (int)nlevel));
1128 SetPixelIndex(x + 2, y, level);
1130 for (i = -2; i < 3; i++) {
1131 @@ -1591,7 +1591,7 @@ bool CxImage::Dither(long method)
1134 nlevel = GetPixelIndex(x + i, y + 1) + (error * coeff) / TotalCoeffSum;
1135 - level = (BYTE)min(255, max(0, (int)nlevel));
1136 + level = (BYTE)cxmin(255, cxmax(0, (int)nlevel));
1137 SetPixelIndex(x + i, y + 1, level);
1140 @@ -1620,10 +1620,10 @@ bool CxImage::Dither(long method)
1143 nlevel = GetPixelIndex(x + 1, y) + (error * 8) / TotalCoeffSum;
1144 - level = (BYTE)min(255, max(0, (int)nlevel));
1145 + level = (BYTE)cxmin(255, cxmax(0, (int)nlevel));
1146 SetPixelIndex(x + 1, y, level);
1147 nlevel = GetPixelIndex(x + 2, y) + (error * 4) / TotalCoeffSum;
1148 - level = (BYTE)min(255, max(0, (int)nlevel));
1149 + level = (BYTE)cxmin(255, cxmax(0, (int)nlevel));
1150 SetPixelIndex(x + 2, y, level);
1152 for (i = -2; i < 3; i++) {
1153 @@ -1645,7 +1645,7 @@ bool CxImage::Dither(long method)
1156 nlevel = GetPixelIndex(x + i, y + 1) + (error * coeff) / TotalCoeffSum;
1157 - level = (BYTE)min(255, max(0, (int)nlevel));
1158 + level = (BYTE)cxmin(255, cxmax(0, (int)nlevel));
1159 SetPixelIndex(x + i, y + 1, level);
1161 for (i = -2; i < 3; i++) {
1162 @@ -1667,7 +1667,7 @@ bool CxImage::Dither(long method)
1165 nlevel = GetPixelIndex(x + i, y + 2) + (error * coeff) / TotalCoeffSum;
1166 - level = (BYTE)min(255, max(0, (int)nlevel));
1167 + level = (BYTE)cxmin(255, cxmax(0, (int)nlevel));
1168 SetPixelIndex(x + i, y + 2, level);
1171 @@ -1696,10 +1696,10 @@ bool CxImage::Dither(long method)
1174 nlevel = GetPixelIndex(x + 1, y) + (error * 7) / TotalCoeffSum;
1175 - level = (BYTE)min(255, max(0, (int)nlevel));
1176 + level = (BYTE)cxmin(255, cxmax(0, (int)nlevel));
1177 SetPixelIndex(x + 1, y, level);
1178 nlevel = GetPixelIndex(x + 2, y) + (error * 5) / TotalCoeffSum;
1179 - level = (BYTE)min(255, max(0, (int)nlevel));
1180 + level = (BYTE)cxmin(255, cxmax(0, (int)nlevel));
1181 SetPixelIndex(x + 2, y, level);
1183 for (i = -2; i < 3; i++) {
1184 @@ -1721,7 +1721,7 @@ bool CxImage::Dither(long method)
1187 nlevel = GetPixelIndex(x + i, y + 1) + (error * coeff) / TotalCoeffSum;
1188 - level = (BYTE)min(255, max(0, (int)nlevel));
1189 + level = (BYTE)cxmin(255, cxmax(0, (int)nlevel));
1190 SetPixelIndex(x + i, y + 1, level);
1192 for (i = -2; i < 3; i++) {
1193 @@ -1743,7 +1743,7 @@ bool CxImage::Dither(long method)
1196 nlevel = GetPixelIndex(x + i, y + 2) + (error * coeff) / TotalCoeffSum;
1197 - level = (BYTE)min(255, max(0, (int)nlevel));
1198 + level = (BYTE)cxmin(255, cxmax(0, (int)nlevel));
1199 SetPixelIndex(x + i, y + 2, level);
1202 @@ -1772,10 +1772,10 @@ bool CxImage::Dither(long method)
1205 nlevel = GetPixelIndex(x + 1, y) + (error * 5) / TotalCoeffSum;
1206 - level = (BYTE)min(255, max(0, (int)nlevel));
1207 + level = (BYTE)cxmin(255, cxmax(0, (int)nlevel));
1208 SetPixelIndex(x + 1, y, level);
1209 nlevel = GetPixelIndex(x + 2, y) + (error * 3) / TotalCoeffSum;
1210 - level = (BYTE)min(255, max(0, (int)nlevel));
1211 + level = (BYTE)cxmin(255, cxmax(0, (int)nlevel));
1212 SetPixelIndex(x + 2, y, level);
1214 for (i = -2; i < 3; i++) {
1215 @@ -1797,7 +1797,7 @@ bool CxImage::Dither(long method)
1218 nlevel = GetPixelIndex(x + i, y + 1) + (error * coeff) / TotalCoeffSum;
1219 - level = (BYTE)min(255, max(0, (int)nlevel));
1220 + level = (BYTE)cxmin(255, cxmax(0, (int)nlevel));
1221 SetPixelIndex(x + i, y + 1, level);
1223 for (i = -1; i < 2; i++) {
1224 @@ -1813,7 +1813,7 @@ bool CxImage::Dither(long method)
1227 nlevel = GetPixelIndex(x + i, y + 2) + (error * coeff) / TotalCoeffSum;
1228 - level = (BYTE)min(255, max(0, (int)nlevel));
1229 + level = (BYTE)cxmin(255, cxmax(0, (int)nlevel));
1230 SetPixelIndex(x + i, y + 2, level);
1233 @@ -1845,76 +1845,76 @@ bool CxImage::Dither(long method)
1234 int tmp_index_y = y;
1236 nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1237 - level = (BYTE)min(255, max(0, (int)nlevel));
1238 + level = (BYTE)cxmin(255, cxmax(0, (int)nlevel));
1239 SetPixelIndex(tmp_index_x, tmp_index_y, level);
1241 tmp_index_x = x - 3;
1242 tmp_index_y = y + 1;
1244 nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1245 - level = (BYTE)min(255, max(0, (int)nlevel));
1246 + level = (BYTE)cxmin(255, cxmax(0, (int)nlevel));
1247 SetPixelIndex(tmp_index_x, tmp_index_y, level);
1249 tmp_index_x = x - 1;
1251 nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1252 - level = (BYTE)min(255, max(0, (int)nlevel));
1253 + level = (BYTE)cxmin(255, cxmax(0, (int)nlevel));
1254 SetPixelIndex(tmp_index_x, tmp_index_y, level);
1256 tmp_index_x = x + 1;
1258 nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1259 - level = (BYTE)min(255, max(0, (int)nlevel));
1260 + level = (BYTE)cxmin(255, cxmax(0, (int)nlevel));
1261 SetPixelIndex(tmp_index_x, tmp_index_y, level);
1263 tmp_index_x = x + 3;
1265 nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1266 - level = (BYTE)min(255, max(0, (int)nlevel));
1267 + level = (BYTE)cxmin(255, cxmax(0, (int)nlevel));
1268 SetPixelIndex(tmp_index_x, tmp_index_y, level);
1270 tmp_index_x = x - 2;
1271 tmp_index_y = y + 2;
1273 nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1274 - level = (BYTE)min(255, max(0, (int)nlevel));
1275 + level = (BYTE)cxmin(255, cxmax(0, (int)nlevel));
1276 SetPixelIndex(tmp_index_x, tmp_index_y, level);
1280 nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1281 - level = (BYTE)min(255, max(0, (int)nlevel));
1282 + level = (BYTE)cxmin(255, cxmax(0, (int)nlevel));
1283 SetPixelIndex(tmp_index_x, tmp_index_y, level);
1285 tmp_index_x = x + 2;
1287 nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1288 - level = (BYTE)min(255, max(0, (int)nlevel));
1289 + level = (BYTE)cxmin(255, cxmax(0, (int)nlevel));
1290 SetPixelIndex(tmp_index_x, tmp_index_y, level);
1292 tmp_index_x = x - 3;
1293 tmp_index_y = y + 3;
1295 nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1296 - level = (BYTE)min(255, max(0, (int)nlevel));
1297 + level = (BYTE)cxmin(255, cxmax(0, (int)nlevel));
1298 SetPixelIndex(tmp_index_x, tmp_index_y, level);
1300 tmp_index_x = x - 1;
1302 nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1303 - level = (BYTE)min(255, max(0, (int)nlevel));
1304 + level = (BYTE)cxmin(255, cxmax(0, (int)nlevel));
1305 SetPixelIndex(tmp_index_x, tmp_index_y, level);
1307 tmp_index_x = x + 1;
1309 nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1310 - level = (BYTE)min(255, max(0, (int)nlevel));
1311 + level = (BYTE)cxmin(255, cxmax(0, (int)nlevel));
1312 SetPixelIndex(tmp_index_x, tmp_index_y, level);
1314 tmp_index_x = x + 3;
1316 nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1317 - level = (BYTE)min(255, max(0, (int)nlevel));
1318 + level = (BYTE)cxmin(255, cxmax(0, (int)nlevel));
1319 SetPixelIndex(tmp_index_x, tmp_index_y, level);
1322 @@ -1941,7 +1941,7 @@ bool CxImage::Dither(long method)
1323 Bmatrix[i] = (BYTE)(dither);
1326 - int scale = max(0,(8-2*order));
1327 + int scale = cxmax(0,(8-2*order));
1329 for (long y=0;y<head.biHeight;y++){
1330 info.nProgress = (long)(100*y/head.biHeight);
1331 @@ -1981,7 +1981,7 @@ bool CxImage::Dither(long method)
1334 nlevel = GetPixelIndex(x+1,y) + (error * 7)/16;
1335 - level = (BYTE)min(255,max(0,(int)nlevel));
1336 + level = (BYTE)cxmin(255,cxmax(0,(int)nlevel));
1337 SetPixelIndex(x+1,y,level);
1338 for(int i=-1; i<2; i++){
1340 @@ -1993,7 +1993,7 @@ bool CxImage::Dither(long method)
1343 nlevel = GetPixelIndex(x+i,y+1) + (error * coeff)/16;
1344 - level = (BYTE)min(255,max(0,(int)nlevel));
1345 + level = (BYTE)cxmin(255,cxmax(0,(int)nlevel));
1346 SetPixelIndex(x+i,y+1,level);
1349 @@ -2031,7 +2031,7 @@ bool CxImage::CropRotatedRectangle( long topx, long topy, long width, long heigh
1350 if ( fabs(angle)<0.0002 )
1351 return Crop( topx, topy, topx+width, topy+height, iDst);
1353 - startx = min(topx, topx - (long)(sin_angle*(double)height));
1354 + startx = cxmin(topx, topx - (long)(sin_angle*(double)height));
1355 endx = topx + (long)(cos_angle*(double)width);
1356 endy = topy + (long)(cos_angle*(double)height + sin_angle*(double)width);
1357 // check: corners of the rectangle must be inside
1358 @@ -2079,10 +2079,10 @@ bool CxImage::Crop(long left, long top, long right, long bottom, CxImage* iDst)
1360 if (!pDib) return false;
1362 - long startx = max(0L,min(left,head.biWidth));
1363 - long endx = max(0L,min(right,head.biWidth));
1364 - long starty = head.biHeight - max(0L,min(top,head.biHeight));
1365 - long endy = head.biHeight - max(0L,min(bottom,head.biHeight));
1366 + long startx = cxmax(0L,cxmin(left,head.biWidth));
1367 + long endx = cxmax(0L,cxmin(right,head.biWidth));
1368 + long starty = head.biHeight - cxmax(0L,cxmin(top,head.biHeight));
1369 + long endy = head.biHeight - cxmax(0L,cxmin(bottom,head.biHeight));
1371 if (startx==endx || starty==endy) return false;
1373 @@ -2443,8 +2443,8 @@ bool CxImage::CircleTransform(int type,long rmax,float Koeff)
1377 -// nx=max(xmin,min(nx,xmax));
1378 -// ny=max(ymin,min(ny,ymax));
1379 +// nx=cxmax(xmin,cxmin(nx,xmax));
1380 +// ny=cxmax(ymin,cxmin(ny,ymax));
1382 else { nx=-1;ny=-1;}
1383 if (head.biClrUsed==0){
1384 diff --git a/lib/cximage-6.0/CxImage/ximawnd.cpp b/lib/cximage-6.0/CxImage/ximawnd.cpp
1385 index 2ae2f93..7029cc7 100644
1386 --- a/lib/cximage-6.0/CxImage/ximawnd.cpp
1387 +++ b/lib/cximage-6.0/CxImage/ximawnd.cpp
1388 @@ -682,10 +682,10 @@ long CxImage::Draw(HDC hdc, long x, long y, long cx, long cy, RECT* pClipRect, b
1389 RECT clipbox,paintbox;
1390 GetClipBox(hdc,&clipbox);
1392 - paintbox.top = min(clipbox.bottom,max(clipbox.top,y));
1393 - paintbox.left = min(clipbox.right,max(clipbox.left,x));
1394 - paintbox.right = max(clipbox.left,min(clipbox.right,x+cx));
1395 - paintbox.bottom = max(clipbox.top,min(clipbox.bottom,y+cy));
1396 + paintbox.top = cxmin(clipbox.bottom,cxmax(clipbox.top,y));
1397 + paintbox.left = cxmin(clipbox.right,cxmax(clipbox.left,x));
1398 + paintbox.right = cxmax(clipbox.left,cxmin(clipbox.right,x+cx));
1399 + paintbox.bottom = cxmax(clipbox.top,cxmin(clipbox.bottom,y+cy));
1401 long destw = paintbox.right - paintbox.left;
1402 long desth = paintbox.bottom - paintbox.top;
1403 @@ -730,12 +730,12 @@ long CxImage::Draw(HDC hdc, long x, long y, long cx, long cy, RECT* pClipRect, b
1405 for(yy=0;yy<desth;yy++){
1406 dy = head.biHeight-(ymax-yy-y)*fy;
1407 - sy = max(0L,(long)floor(dy));
1408 + sy = cxmax(0L,(long)floor(dy));
1409 psrc = info.pImage+sy*info.dwEffWidth;
1411 for(xx=0;xx<destw;xx++){
1412 dx = (xx+xmin-x)*fx;
1413 - sx = max(0L,(long)floor(dx));
1414 + sx = cxmax(0L,(long)floor(dx));
1415 #if CXIMAGE_SUPPORT_INTERPOLATION
1417 if (fx > 1 && fy > 1) {
1418 @@ -813,7 +813,7 @@ long CxImage::Draw(HDC hdc, long x, long y, long cx, long cy, RECT* pClipRect, b
1420 for(yy=0;yy<desth;yy++){
1421 dy = head.biHeight-(ymax-yy-y)*fy;
1422 - sy = max(0L,(long)floor(dy));
1423 + sy = cxmax(0L,(long)floor(dy));
1425 alphaoffset = sy*head.biWidth;
1426 pdst = pbase + yy*ew;
1427 @@ -821,7 +821,7 @@ long CxImage::Draw(HDC hdc, long x, long y, long cx, long cy, RECT* pClipRect, b
1429 for(xx=0;xx<destw;xx++){
1430 dx = (xx+xmin-x)*fx;
1431 - sx = max(0L,(long)floor(dx));
1432 + sx = cxmax(0L,(long)floor(dx));
1434 if (bAlpha) a=pAlpha[alphaoffset+sx]; else a=255;
1435 a =(BYTE)((a*(1+info.nAlphaMax))>>8);