Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 592446 | Differences between
and this patch

Collapse All | Expand All

(-)a/lib/cximage-6.0/CxImage/ximabmp.cpp (-3 / +3 lines)
Lines 46-52 bool CxImageBMP::Encode(CxFile * hFile) Link Here
46
		bihtoh(&infohdr);
46
		bihtoh(&infohdr);
47
47
48
		// Write the file header
48
		// Write the file header
49
		hFile->Write(&hdr,min(14,sizeof(BITMAPFILEHEADER)),1);
49
		hFile->Write(&hdr,minimum(14,sizeof(BITMAPFILEHEADER)),1);
50
		hFile->Write(&infohdr,sizeof(BITMAPINFOHEADER),1);
50
		hFile->Write(&infohdr,sizeof(BITMAPINFOHEADER),1);
51
		 //and DIB+ALPHA interlaced
51
		 //and DIB+ALPHA interlaced
52
		BYTE *srcalpha = AlphaGetPointer();
52
		BYTE *srcalpha = AlphaGetPointer();
Lines 64-70 bool CxImageBMP::Encode(CxFile * hFile) Link Here
64
#endif //CXIMAGE_SUPPORT_ALPHA
64
#endif //CXIMAGE_SUPPORT_ALPHA
65
	{
65
	{
66
		// Write the file header
66
		// Write the file header
67
		hFile->Write(&hdr,min(14,sizeof(BITMAPFILEHEADER)),1);
67
		hFile->Write(&hdr,minimum(14,sizeof(BITMAPFILEHEADER)),1);
68
		//copy attributes
68
		//copy attributes
69
		memcpy(pDib,&head,sizeof(BITMAPINFOHEADER));
69
		memcpy(pDib,&head,sizeof(BITMAPINFOHEADER));
70
		bihtoh((BITMAPINFOHEADER*)pDib);
70
		bihtoh((BITMAPINFOHEADER*)pDib);
Lines 86-92 bool CxImageBMP::Decode(CxFile * hFile) Link Here
86
	BITMAPFILEHEADER   bf;
86
	BITMAPFILEHEADER   bf;
87
	DWORD off = hFile->Tell(); //<CSC>
87
	DWORD off = hFile->Tell(); //<CSC>
88
  cx_try {
88
  cx_try {
89
	if (hFile->Read(&bf,min(14,sizeof(bf)),1)==0) cx_throw("Not a BMP");
89
	if (hFile->Read(&bf,minimum(14,sizeof(bf)),1)==0) cx_throw("Not a BMP");
90
90
91
	bf.bfSize = my_ntohl(bf.bfSize); 
91
	bf.bfSize = my_ntohl(bf.bfSize); 
92
	bf.bfOffBits = my_ntohl(bf.bfOffBits); 
92
	bf.bfOffBits = my_ntohl(bf.bfOffBits); 
(-)a/lib/cximage-6.0/CxImage/ximadef.h (-4 / +4 lines)
Lines 53-63 Link Here
53
 #define CXIMAGE_SUPPORT_WINDOWS 0
53
 #define CXIMAGE_SUPPORT_WINDOWS 0
54
#endif
54
#endif
55
55
56
#ifndef min
56
#ifndef minimum
57
#define min(a,b) (((a)<(b))?(a):(b))
57
#define minimum(a,b) (((a)<(b))?(a):(b))
58
#endif
58
#endif
59
#ifndef max
59
#ifndef maximum
60
#define max(a,b) (((a)>(b))?(a):(b))
60
#define maximum(a,b) (((a)>(b))?(a):(b))
61
#endif
61
#endif
62
62
63
#ifndef PI
63
#ifndef PI
(-)a/lib/cximage-6.0/CxImage/ximadsp.cpp (-89 / +89 lines)
Lines 389-396 RGBQUAD CxImage::RGBtoHSL(RGBQUAD lRGBColor) Link Here
389
	G = lRGBColor.rgbGreen;
389
	G = lRGBColor.rgbGreen;
390
	B = lRGBColor.rgbBlue;
390
	B = lRGBColor.rgbBlue;
391
391
392
	cMax = max( max(R,G), B);	/* calculate lightness */
392
	cMax = maximum( maximum(R,G), B);	/* calculate lightness */
393
	cMin = min( min(R,G), B);
393
	cMin = minimum( minimum(R,G), B);
394
	L = (BYTE)((((cMax+cMin)*HSLMAX)+RGBMAX)/(2*RGBMAX));
394
	L = (BYTE)((((cMax+cMin)*HSLMAX)+RGBMAX)/(2*RGBMAX));
395
395
396
	if (cMax==cMin){			/* r=g=b --> achromatic case */
396
	if (cMax==cMin){			/* r=g=b --> achromatic case */
Lines 489-497 RGBQUAD CxImage::YUVtoRGB(RGBQUAD lYUVColor) Link Here
489
	G = (int)( Y - 0.344f * U - 0.714f * V);
489
	G = (int)( Y - 0.344f * U - 0.714f * V);
490
	B = (int)( Y + 1.770f * U);
490
	B = (int)( Y + 1.770f * U);
491
491
492
	R= min(255,max(0,R));
492
	R= minimum(255,maximum(0,R));
493
	G= min(255,max(0,G));
493
	G= minimum(255,maximum(0,G));
494
	B= min(255,max(0,B));
494
	B= minimum(255,maximum(0,B));
495
	RGBQUAD rgb={(BYTE)B,(BYTE)G,(BYTE)R,0};
495
	RGBQUAD rgb={(BYTE)B,(BYTE)G,(BYTE)R,0};
496
	return rgb;
496
	return rgb;
497
}
497
}
Lines 510-518 RGBQUAD CxImage::RGBtoYUV(RGBQUAD lRGBColor) Link Here
510
	U = (int)((B-Y) * 0.565f + 128);
510
	U = (int)((B-Y) * 0.565f + 128);
511
	V = (int)((R-Y) * 0.713f + 128);
511
	V = (int)((R-Y) * 0.713f + 128);
512
512
513
	Y= min(255,max(0,Y));
513
	Y= minimum(255,maximum(0,Y));
514
	U= min(255,max(0,U));
514
	U= minimum(255,maximum(0,U));
515
	V= min(255,max(0,V));
515
	V= minimum(255,maximum(0,V));
516
	RGBQUAD yuv={(BYTE)V,(BYTE)U,(BYTE)Y,0};
516
	RGBQUAD yuv={(BYTE)V,(BYTE)U,(BYTE)Y,0};
517
	return yuv;
517
	return yuv;
518
}
518
}
Lines 528-536 RGBQUAD CxImage::YIQtoRGB(RGBQUAD lYIQColor) Link Here
528
	G = (int)( Y - 0.273f * I - 0.647f * Q);
528
	G = (int)( Y - 0.273f * I - 0.647f * Q);
529
	B = (int)( Y - 1.104f * I + 1.701f * Q);
529
	B = (int)( Y - 1.104f * I + 1.701f * Q);
530
530
531
	R= min(255,max(0,R));
531
	R= minimum(255,maximum(0,R));
532
	G= min(255,max(0,G));
532
	G= minimum(255,maximum(0,G));
533
	B= min(255,max(0,B));
533
	B= minimum(255,maximum(0,B));
534
	RGBQUAD rgb={(BYTE)B,(BYTE)G,(BYTE)R,0};
534
	RGBQUAD rgb={(BYTE)B,(BYTE)G,(BYTE)R,0};
535
	return rgb;
535
	return rgb;
536
}
536
}
Lines 546-554 RGBQUAD CxImage::RGBtoYIQ(RGBQUAD lRGBColor) Link Here
546
	I = (int)( 0.5960f * R - 0.2742f * G - 0.3219f * B + 128);
546
	I = (int)( 0.5960f * R - 0.2742f * G - 0.3219f * B + 128);
547
	Q = (int)( 0.2109f * R - 0.5229f * G + 0.3120f * B + 128);
547
	Q = (int)( 0.2109f * R - 0.5229f * G + 0.3120f * B + 128);
548
548
549
	Y= min(255,max(0,Y));
549
	Y= minimum(255,maximum(0,Y));
550
	I= min(255,max(0,I));
550
	I= minimum(255,maximum(0,I));
551
	Q= min(255,max(0,Q));
551
	Q= minimum(255,maximum(0,Q));
552
	RGBQUAD yiq={(BYTE)Q,(BYTE)I,(BYTE)Y,0};
552
	RGBQUAD yiq={(BYTE)Q,(BYTE)I,(BYTE)Y,0};
553
	return yiq;
553
	return yiq;
554
}
554
}
Lines 565-573 RGBQUAD CxImage::XYZtoRGB(RGBQUAD lXYZColor) Link Here
565
	G = (int)( -0.969256f * X + 1.875992f * Y + 0.041556f * Z * k);
565
	G = (int)( -0.969256f * X + 1.875992f * Y + 0.041556f * Z * k);
566
	B = (int)(  0.055648f * X - 0.204043f * Y + 1.057311f * Z * k);
566
	B = (int)(  0.055648f * X - 0.204043f * Y + 1.057311f * Z * k);
567
567
568
	R= min(255,max(0,R));
568
	R= minimum(255,maximum(0,R));
569
	G= min(255,max(0,G));
569
	G= minimum(255,maximum(0,G));
570
	B= min(255,max(0,B));
570
	B= minimum(255,maximum(0,B));
571
	RGBQUAD rgb={(BYTE)B,(BYTE)G,(BYTE)R,0};
571
	RGBQUAD rgb={(BYTE)B,(BYTE)G,(BYTE)R,0};
572
	return rgb;
572
	return rgb;
573
}
573
}
Lines 583-591 RGBQUAD CxImage::RGBtoXYZ(RGBQUAD lRGBColor) Link Here
583
	Y = (int)( 0.212671f * R + 0.715160f * G + 0.072169f * B);
583
	Y = (int)( 0.212671f * R + 0.715160f * G + 0.072169f * B);
584
	Z = (int)((0.019334f * R + 0.119193f * G + 0.950227f * B)*0.918483657f);
584
	Z = (int)((0.019334f * R + 0.119193f * G + 0.950227f * B)*0.918483657f);
585
585
586
	//X= min(255,max(0,X));
586
	//X= minimum(255,maximum(0,X));
587
	//Y= min(255,max(0,Y));
587
	//Y= minimum(255,maximum(0,Y));
588
	//Z= min(255,max(0,Z));
588
	//Z= minimum(255,maximum(0,Z));
589
	RGBQUAD xyz={(BYTE)Z,(BYTE)Y,(BYTE)X,0};
589
	RGBQUAD xyz={(BYTE)Z,(BYTE)Y,(BYTE)X,0};
590
	return xyz;
590
	return xyz;
591
}
591
}
Lines 707-713 bool CxImage::Light(long brightness, long contrast) Link Here
707
707
708
	BYTE cTable[256]; //<nipper>
708
	BYTE cTable[256]; //<nipper>
709
	for (int i=0;i<256;i++)	{
709
	for (int i=0;i<256;i++)	{
710
		cTable[i] = (BYTE)max(0,min(255,(int)((i-128)*c + brightness + 0.5f)));
710
		cTable[i] = (BYTE)maximum(0,minimum(255,(int)((i-128)*c + brightness + 0.5f)));
711
	}
711
	}
712
712
713
	return Lut(cTable);
713
	return Lut(cTable);
Lines 830-840 bool CxImage::Filter(long* kernel, long Ksize, long Kfactor, long Koffset) Link Here
830
						}
830
						}
831
					}
831
					}
832
					if (Kfactor==0 || ksumcur==0){
832
					if (Kfactor==0 || ksumcur==0){
833
						cPtr2[iY1] = (BYTE)min(255, max(0,(int)(b + Koffset)));
833
						cPtr2[iY1] = (BYTE)minimum(255, maximum(0,(int)(b + Koffset)));
834
					} else if (ksumtot == ksumcur) {
834
					} else if (ksumtot == ksumcur) {
835
						cPtr2[iY1] = (BYTE)min(255, max(0,(int)(b/Kfactor + Koffset)));
835
						cPtr2[iY1] = (BYTE)minimum(255, maximum(0,(int)(b/Kfactor + Koffset)));
836
					} else {
836
					} else {
837
						cPtr2[iY1] = (BYTE)min(255, max(0,(int)((b*ksumtot)/(ksumcur*Kfactor) + Koffset)));
837
						cPtr2[iY1] = (BYTE)minimum(255, maximum(0,(int)((b*ksumtot)/(ksumcur*Kfactor) + Koffset)));
838
					}
838
					}
839
				}
839
				}
840
			}
840
			}
Lines 863-879 bool CxImage::Filter(long* kernel, long Ksize, long Kfactor, long Koffset) Link Here
863
						}
863
						}
864
					}
864
					}
865
					if (Kfactor==0 || ksumcur==0){
865
					if (Kfactor==0 || ksumcur==0){
866
						c.rgbRed   = (BYTE)min(255, max(0,(int)(r + Koffset)));
866
						c.rgbRed   = (BYTE)minimum(255, maximum(0,(int)(r + Koffset)));
867
						c.rgbGreen = (BYTE)min(255, max(0,(int)(g + Koffset)));
867
						c.rgbGreen = (BYTE)minimum(255, maximum(0,(int)(g + Koffset)));
868
						c.rgbBlue  = (BYTE)min(255, max(0,(int)(b + Koffset)));
868
						c.rgbBlue  = (BYTE)minimum(255, maximum(0,(int)(b + Koffset)));
869
					} else if (ksumtot == ksumcur) {
869
					} else if (ksumtot == ksumcur) {
870
						c.rgbRed   = (BYTE)min(255, max(0,(int)(r/Kfactor + Koffset)));
870
						c.rgbRed   = (BYTE)minimum(255, maximum(0,(int)(r/Kfactor + Koffset)));
871
						c.rgbGreen = (BYTE)min(255, max(0,(int)(g/Kfactor + Koffset)));
871
						c.rgbGreen = (BYTE)minimum(255, maximum(0,(int)(g/Kfactor + Koffset)));
872
						c.rgbBlue  = (BYTE)min(255, max(0,(int)(b/Kfactor + Koffset)));
872
						c.rgbBlue  = (BYTE)minimum(255, maximum(0,(int)(b/Kfactor + Koffset)));
873
					} else {
873
					} else {
874
						c.rgbRed   = (BYTE)min(255, max(0,(int)((r*ksumtot)/(ksumcur*Kfactor) + Koffset)));
874
						c.rgbRed   = (BYTE)minimum(255, maximum(0,(int)((r*ksumtot)/(ksumcur*Kfactor) + Koffset)));
875
						c.rgbGreen = (BYTE)min(255, max(0,(int)((g*ksumtot)/(ksumcur*Kfactor) + Koffset)));
875
						c.rgbGreen = (BYTE)minimum(255, maximum(0,(int)((g*ksumtot)/(ksumcur*Kfactor) + Koffset)));
876
						c.rgbBlue  = (BYTE)min(255, max(0,(int)((b*ksumtot)/(ksumcur*Kfactor) + Koffset)));
876
						c.rgbBlue  = (BYTE)minimum(255, maximum(0,(int)((b*ksumtot)/(ksumcur*Kfactor) + Koffset)));
877
					}
877
					}
878
					tmp.BlindSetPixelColor(x,y,c);
878
					tmp.BlindSetPixelColor(x,y,c);
879
				}
879
				}
Lines 1078-1085 bool CxImage::Edge(long Ksize) Link Here
1078
// 
1078
// 
1079
void CxImage::Mix(CxImage & imgsrc2, ImageOpType op, long lXOffset, long lYOffset, bool bMixAlpha)
1079
void CxImage::Mix(CxImage & imgsrc2, ImageOpType op, long lXOffset, long lYOffset, bool bMixAlpha)
1080
{
1080
{
1081
    long lWide = min(GetWidth(),imgsrc2.GetWidth()-lXOffset);
1081
    long lWide = minimum(GetWidth(),imgsrc2.GetWidth()-lXOffset);
1082
    long lHeight = min(GetHeight(),imgsrc2.GetHeight()-lYOffset);
1082
    long lHeight = minimum(GetHeight(),imgsrc2.GetHeight()-lYOffset);
1083
1083
1084
	bool bEditAlpha = imgsrc2.AlphaIsValid() & bMixAlpha;
1084
	bool bEditAlpha = imgsrc2.AlphaIsValid() & bMixAlpha;
1085
1085
Lines 1112-1127 void CxImage::Mix(CxImage & imgsrc2, ImageOpType op, long lXOffset, long lYOffse Link Here
1112
						if (bEditAlpha) rgbDest.rgbReserved = (BYTE)((rgb1.rgbReserved+rgb2.rgbReserved)/2);
1112
						if (bEditAlpha) rgbDest.rgbReserved = (BYTE)((rgb1.rgbReserved+rgb2.rgbReserved)/2);
1113
					break;
1113
					break;
1114
					case OpAdd:
1114
					case OpAdd:
1115
						rgbDest.rgbBlue = (BYTE)max(0,min(255,rgb1.rgbBlue+rgb2.rgbBlue));
1115
						rgbDest.rgbBlue = (BYTE)maximum(0,minimum(255,rgb1.rgbBlue+rgb2.rgbBlue));
1116
						rgbDest.rgbGreen = (BYTE)max(0,min(255,rgb1.rgbGreen+rgb2.rgbGreen));
1116
						rgbDest.rgbGreen = (BYTE)maximum(0,minimum(255,rgb1.rgbGreen+rgb2.rgbGreen));
1117
						rgbDest.rgbRed = (BYTE)max(0,min(255,rgb1.rgbRed+rgb2.rgbRed));
1117
						rgbDest.rgbRed = (BYTE)maximum(0,minimum(255,rgb1.rgbRed+rgb2.rgbRed));
1118
						if (bEditAlpha) rgbDest.rgbReserved = (BYTE)max(0,min(255,rgb1.rgbReserved+rgb2.rgbReserved));
1118
						if (bEditAlpha) rgbDest.rgbReserved = (BYTE)maximum(0,minimum(255,rgb1.rgbReserved+rgb2.rgbReserved));
1119
					break;
1119
					break;
1120
					case OpSub:
1120
					case OpSub:
1121
						rgbDest.rgbBlue = (BYTE)max(0,min(255,rgb1.rgbBlue-rgb2.rgbBlue));
1121
						rgbDest.rgbBlue = (BYTE)maximum(0,minimum(255,rgb1.rgbBlue-rgb2.rgbBlue));
1122
						rgbDest.rgbGreen = (BYTE)max(0,min(255,rgb1.rgbGreen-rgb2.rgbGreen));
1122
						rgbDest.rgbGreen = (BYTE)maximum(0,minimum(255,rgb1.rgbGreen-rgb2.rgbGreen));
1123
						rgbDest.rgbRed = (BYTE)max(0,min(255,rgb1.rgbRed-rgb2.rgbRed));
1123
						rgbDest.rgbRed = (BYTE)maximum(0,minimum(255,rgb1.rgbRed-rgb2.rgbRed));
1124
						if (bEditAlpha) rgbDest.rgbReserved = (BYTE)max(0,min(255,rgb1.rgbReserved-rgb2.rgbReserved));
1124
						if (bEditAlpha) rgbDest.rgbReserved = (BYTE)maximum(0,minimum(255,rgb1.rgbReserved-rgb2.rgbReserved));
1125
					break;
1125
					break;
1126
					case OpAnd:
1126
					case OpAnd:
1127
						rgbDest.rgbBlue = (BYTE)(rgb1.rgbBlue&rgb2.rgbBlue);
1127
						rgbDest.rgbBlue = (BYTE)(rgb1.rgbBlue&rgb2.rgbBlue);
Lines 1202-1212 void CxImage::Mix(CxImage & imgsrc2, ImageOpType op, long lXOffset, long lYOffse Link Here
1202
							double dSmallAmt = dSmall*((double)rgb2.rgbBlue);
1202
							double dSmallAmt = dSmall*((double)rgb2.rgbBlue);
1203
1203
1204
							if( lAverage < lThresh+1){
1204
							if( lAverage < lThresh+1){
1205
								rgbDest.rgbBlue = (BYTE)max(0,min(255,(int)(dLarge*((double)rgb1.rgbBlue) +
1205
								rgbDest.rgbBlue = (BYTE)maximum(0,minimum(255,(int)(dLarge*((double)rgb1.rgbBlue) +
1206
												dSmallAmt)));
1206
												dSmallAmt)));
1207
								rgbDest.rgbGreen = (BYTE)max(0,min(255,(int)(dLarge*((double)rgb1.rgbGreen) +
1207
								rgbDest.rgbGreen = (BYTE)maximum(0,minimum(255,(int)(dLarge*((double)rgb1.rgbGreen) +
1208
												dSmallAmt)));
1208
												dSmallAmt)));
1209
								rgbDest.rgbRed = (BYTE)max(0,min(255,(int)(dLarge*((double)rgb1.rgbRed) +
1209
								rgbDest.rgbRed = (BYTE)maximum(0,minimum(255,(int)(dLarge*((double)rgb1.rgbRed) +
1210
												dSmallAmt)));
1210
												dSmallAmt)));
1211
							}
1211
							}
1212
							else
1212
							else
Lines 1274-1282 bool CxImage::ShiftRGB(long r, long g, long b) Link Here
1274
#endif //CXIMAGE_SUPPORT_SELECTION
1274
#endif //CXIMAGE_SUPPORT_SELECTION
1275
				{
1275
				{
1276
					color = BlindGetPixelColor(x,y);
1276
					color = BlindGetPixelColor(x,y);
1277
					color.rgbRed = (BYTE)max(0,min(255,(int)(color.rgbRed + r)));
1277
					color.rgbRed = (BYTE)maximum(0,minimum(255,(int)(color.rgbRed + r)));
1278
					color.rgbGreen = (BYTE)max(0,min(255,(int)(color.rgbGreen + g)));
1278
					color.rgbGreen = (BYTE)maximum(0,minimum(255,(int)(color.rgbGreen + g)));
1279
					color.rgbBlue = (BYTE)max(0,min(255,(int)(color.rgbBlue + b)));
1279
					color.rgbBlue = (BYTE)maximum(0,minimum(255,(int)(color.rgbBlue + b)));
1280
					BlindSetPixelColor(x,y,color);
1280
					BlindSetPixelColor(x,y,color);
1281
				}
1281
				}
1282
			}
1282
			}
Lines 1284-1292 bool CxImage::ShiftRGB(long r, long g, long b) Link Here
1284
	} else {
1284
	} else {
1285
		for(DWORD j=0; j<head.biClrUsed; j++){
1285
		for(DWORD j=0; j<head.biClrUsed; j++){
1286
			color = GetPaletteColor((BYTE)j);
1286
			color = GetPaletteColor((BYTE)j);
1287
			color.rgbRed = (BYTE)max(0,min(255,(int)(color.rgbRed + r)));
1287
			color.rgbRed = (BYTE)maximum(0,minimum(255,(int)(color.rgbRed + r)));
1288
			color.rgbGreen = (BYTE)max(0,min(255,(int)(color.rgbGreen + g)));
1288
			color.rgbGreen = (BYTE)maximum(0,minimum(255,(int)(color.rgbGreen + g)));
1289
			color.rgbBlue = (BYTE)max(0,min(255,(int)(color.rgbBlue + b)));
1289
			color.rgbBlue = (BYTE)maximum(0,minimum(255,(int)(color.rgbBlue + b)));
1290
			SetPaletteColor((BYTE)j,color);
1290
			SetPaletteColor((BYTE)j,color);
1291
		}
1291
		}
1292
	}
1292
	}
Lines 1310-1316 bool CxImage::Gamma(float gamma) Link Here
1310
1310
1311
	BYTE cTable[256]; //<nipper>
1311
	BYTE cTable[256]; //<nipper>
1312
	for (int i=0;i<256;i++)	{
1312
	for (int i=0;i<256;i++)	{
1313
		cTable[i] = (BYTE)max(0,min(255,(int)( pow((double)i, dinvgamma) / dMax)));
1313
		cTable[i] = (BYTE)maximum(0,minimum(255,(int)( pow((double)i, dinvgamma) / dMax)));
1314
	}
1314
	}
1315
1315
1316
	return Lut(cTable);
1316
	return Lut(cTable);
Lines 1337-1357 bool CxImage::GammaRGB(float gammaR, float gammaG, float gammaB) Link Here
1337
	dMax = pow(255.0, dinvgamma) / 255.0;
1337
	dMax = pow(255.0, dinvgamma) / 255.0;
1338
	BYTE cTableR[256];
1338
	BYTE cTableR[256];
1339
	for (i=0;i<256;i++)	{
1339
	for (i=0;i<256;i++)	{
1340
		cTableR[i] = (BYTE)max(0,min(255,(int)( pow((double)i, dinvgamma) / dMax)));
1340
		cTableR[i] = (BYTE)maximum(0,minimum(255,(int)( pow((double)i, dinvgamma) / dMax)));
1341
	}
1341
	}
1342
1342
1343
	dinvgamma = 1/gammaG;
1343
	dinvgamma = 1/gammaG;
1344
	dMax = pow(255.0, dinvgamma) / 255.0;
1344
	dMax = pow(255.0, dinvgamma) / 255.0;
1345
	BYTE cTableG[256];
1345
	BYTE cTableG[256];
1346
	for (i=0;i<256;i++)	{
1346
	for (i=0;i<256;i++)	{
1347
		cTableG[i] = (BYTE)max(0,min(255,(int)( pow((double)i, dinvgamma) / dMax)));
1347
		cTableG[i] = (BYTE)maximum(0,minimum(255,(int)( pow((double)i, dinvgamma) / dMax)));
1348
	}
1348
	}
1349
1349
1350
	dinvgamma = 1/gammaB;
1350
	dinvgamma = 1/gammaB;
1351
	dMax = pow(255.0, dinvgamma) / 255.0;
1351
	dMax = pow(255.0, dinvgamma) / 255.0;
1352
	BYTE cTableB[256];
1352
	BYTE cTableB[256];
1353
	for (i=0;i<256;i++)	{
1353
	for (i=0;i<256;i++)	{
1354
		cTableB[i] = (BYTE)max(0,min(255,(int)( pow((double)i, dinvgamma) / dMax)));
1354
		cTableB[i] = (BYTE)maximum(0,minimum(255,(int)( pow((double)i, dinvgamma) / dMax)));
1355
	}
1355
	}
1356
1356
1357
	return Lut(cTableR, cTableG, cTableB);
1357
	return Lut(cTableR, cTableG, cTableB);
Lines 1442-1452 bool CxImage::Noise(long level) Link Here
1442
			{
1442
			{
1443
				color = BlindGetPixelColor(x,y);
1443
				color = BlindGetPixelColor(x,y);
1444
				n=(long)((rand()/(float)RAND_MAX - 0.5)*level);
1444
				n=(long)((rand()/(float)RAND_MAX - 0.5)*level);
1445
				color.rgbRed = (BYTE)max(0,min(255,(int)(color.rgbRed + n)));
1445
				color.rgbRed = (BYTE)maximum(0,minimum(255,(int)(color.rgbRed + n)));
1446
				n=(long)((rand()/(float)RAND_MAX - 0.5)*level);
1446
				n=(long)((rand()/(float)RAND_MAX - 0.5)*level);
1447
				color.rgbGreen = (BYTE)max(0,min(255,(int)(color.rgbGreen + n)));
1447
				color.rgbGreen = (BYTE)maximum(0,minimum(255,(int)(color.rgbGreen + n)));
1448
				n=(long)((rand()/(float)RAND_MAX - 0.5)*level);
1448
				n=(long)((rand()/(float)RAND_MAX - 0.5)*level);
1449
				color.rgbBlue = (BYTE)max(0,min(255,(int)(color.rgbBlue + n)));
1449
				color.rgbBlue = (BYTE)maximum(0,minimum(255,(int)(color.rgbBlue + n)));
1450
				BlindSetPixelColor(x,y,color);
1450
				BlindSetPixelColor(x,y,color);
1451
			}
1451
			}
1452
		}
1452
		}
Lines 1561-1568 bool CxImage::FFT2(CxImage* srcReal, CxImage* srcImag, CxImage* dstReal, CxImage Link Here
1561
1561
1562
	//DFT buffers
1562
	//DFT buffers
1563
	double *real2,*imag2;
1563
	double *real2,*imag2;
1564
	real2 = (double*)malloc(max(w,h) * sizeof(double));
1564
	real2 = (double*)malloc(maximum(w,h) * sizeof(double));
1565
	imag2 = (double*)malloc(max(w,h) * sizeof(double));
1565
	imag2 = (double*)malloc(maximum(w,h) * sizeof(double));
1566
1566
1567
	/* Transform the rows */
1567
	/* Transform the rows */
1568
	real = (double *)malloc(w * sizeof(double));
1568
	real = (double *)malloc(w * sizeof(double));
Lines 1617-1623 bool CxImage::FFT2(CxImage* srcReal, CxImage* srcImag, CxImage* dstReal, CxImage Link Here
1617
1617
1618
	/* converting from double to byte, there is a HUGE loss in the dynamics
1618
	/* converting from double to byte, there is a HUGE loss in the dynamics
1619
	  "nn" tries to keep an acceptable SNR, but 8bit=48dB: don't ask more */
1619
	  "nn" tries to keep an acceptable SNR, but 8bit=48dB: don't ask more */
1620
	double nn=pow((double)2,(double)log((double)max(w,h))/(double)log((double)2)-4);
1620
	double nn=pow((double)2,(double)log((double)maximum(w,h))/(double)log((double)2)-4);
1621
	//reversed gain for reversed transform
1621
	//reversed gain for reversed transform
1622
	if (direction==-1) nn=1/nn;
1622
	if (direction==-1) nn=1/nn;
1623
	//bMagnitude : just to see it on the screen
1623
	//bMagnitude : just to see it on the screen
Lines 1626-1640 bool CxImage::FFT2(CxImage* srcReal, CxImage* srcImag, CxImage* dstReal, CxImage Link Here
1626
	for (j=0;j<h;j++) {
1626
	for (j=0;j<h;j++) {
1627
		for (k=0;k<w;k++) {
1627
		for (k=0;k<w;k++) {
1628
			if (bMagnitude){
1628
			if (bMagnitude){
1629
				tmpReal->SetPixelIndex(k,j,(BYTE)max(0,min(255,(nn*(3+log(_cabs(grid[k][j])))))));
1629
				tmpReal->SetPixelIndex(k,j,(BYTE)maximum(0,minimum(255,(nn*(3+log(_cabs(grid[k][j])))))));
1630
				if (grid[k][j].x==0){
1630
				if (grid[k][j].x==0){
1631
					tmpImag->SetPixelIndex(k,j,(BYTE)max(0,min(255,(128+(atan(grid[k][j].y/0.0000000001)*nn)))));
1631
					tmpImag->SetPixelIndex(k,j,(BYTE)maximum(0,minimum(255,(128+(atan(grid[k][j].y/0.0000000001)*nn)))));
1632
				} else {
1632
				} else {
1633
					tmpImag->SetPixelIndex(k,j,(BYTE)max(0,min(255,(128+(atan(grid[k][j].y/grid[k][j].x)*nn)))));
1633
					tmpImag->SetPixelIndex(k,j,(BYTE)maximum(0,minimum(255,(128+(atan(grid[k][j].y/grid[k][j].x)*nn)))));
1634
				}
1634
				}
1635
			} else {
1635
			} else {
1636
				tmpReal->SetPixelIndex(k,j,(BYTE)max(0,min(255,(128 + grid[k][j].x*nn))));
1636
				tmpReal->SetPixelIndex(k,j,(BYTE)maximum(0,minimum(255,(128 + grid[k][j].x*nn))));
1637
				tmpImag->SetPixelIndex(k,j,(BYTE)max(0,min(255,(128 + grid[k][j].y*nn))));
1637
				tmpImag->SetPixelIndex(k,j,(BYTE)maximum(0,minimum(255,(128 + grid[k][j].y*nn))));
1638
			}
1638
			}
1639
		}
1639
		}
1640
	}
1640
	}
Lines 1922-1928 bool CxImage::RepairChannel(CxImage *ch, float radius) Link Here
1922
1922
1923
			correction = ((1.0+iy*iy)*ixx - ix*iy*ixy + (1.0+ix*ix)*iyy)/(1.0+ix*ix+iy*iy);
1923
			correction = ((1.0+iy*iy)*ixx - ix*iy*ixy + (1.0+ix*ix)*iyy)/(1.0+ix*ix+iy*iy);
1924
1924
1925
			tmp.BlindSetPixelIndex(x,y,(BYTE)min(255,max(0,(xy0 + radius * correction + 0.5))));
1925
			tmp.BlindSetPixelIndex(x,y,(BYTE)minimum(255,maximum(0,(xy0 + radius * correction + 0.5))));
1926
		}
1926
		}
1927
	}
1927
	}
1928
1928
Lines 1943-1949 bool CxImage::RepairChannel(CxImage *ch, float radius) Link Here
1943
1943
1944
			correction = ((1.0+iy*iy)*ixx - ix*iy*ixy + (1.0+ix*ix)*iyy)/(1.0+ix*ix+iy*iy);
1944
			correction = ((1.0+iy*iy)*ixx - ix*iy*ixy + (1.0+ix*ix)*iyy)/(1.0+ix*ix+iy*iy);
1945
1945
1946
			tmp.BlindSetPixelIndex(x,y,(BYTE)min(255,max(0,(xy0 + radius * correction + 0.5))));
1946
			tmp.BlindSetPixelIndex(x,y,(BYTE)minimum(255,maximum(0,(xy0 + radius * correction + 0.5))));
1947
		}
1947
		}
1948
	}
1948
	}
1949
	for (x=0;x<=w;x+=w){
1949
	for (x=0;x<=w;x+=w){
Lines 1963-1969 bool CxImage::RepairChannel(CxImage *ch, float radius) Link Here
1963
1963
1964
			correction = ((1.0+iy*iy)*ixx - ix*iy*ixy + (1.0+ix*ix)*iyy)/(1.0+ix*ix+iy*iy);
1964
			correction = ((1.0+iy*iy)*ixx - ix*iy*ixy + (1.0+ix*ix)*iyy)/(1.0+ix*ix+iy*iy);
1965
1965
1966
			tmp.BlindSetPixelIndex(x,y,(BYTE)min(255,max(0,(xy0 + radius * correction + 0.5))));
1966
			tmp.BlindSetPixelIndex(x,y,(BYTE)minimum(255,maximum(0,(xy0 + radius * correction + 0.5))));
1967
		}
1967
		}
1968
	}
1968
	}
1969
1969
Lines 2621-2628 bool CxImage::SelectiveBlur(float radius, BYTE threshold, CxImage* iDst) Link Here
2621
	}
2621
	}
2622
2622
2623
	//build the difference mask
2623
	//build the difference mask
2624
	BYTE thresh_dw = (BYTE)max( 0 ,(int)(128 - threshold));
2624
	BYTE thresh_dw = (BYTE)maximum( 0 ,(int)(128 - threshold));
2625
	BYTE thresh_up = (BYTE)min(255,(int)(128 + threshold));
2625
	BYTE thresh_up = (BYTE)minimum(255,(int)(128 + threshold));
2626
	long kernel[]={-100,-100,-100,-100,801,-100,-100,-100,-100};
2626
	long kernel[]={-100,-100,-100,-100,801,-100,-100,-100,-100};
2627
	if (!Tmp.Filter(kernel,3,800,128)){
2627
	if (!Tmp.Filter(kernel,3,800,128)){
2628
		delete [] pPalette;
2628
		delete [] pPalette;
Lines 2755-2761 bool CxImage::UnsharpMask(float radius /*= 5.0*/, float amount /*= 0.5*/, int th Link Here
2755
					if (abs(diff) < threshold){
2755
					if (abs(diff) < threshold){
2756
						dest_row[z] = cur_row[z];
2756
						dest_row[z] = cur_row[z];
2757
					} else {
2757
					} else {
2758
						dest_row[z] = (BYTE)min(255, max(0,(int)(cur_row[z] + amount * diff)));
2758
						dest_row[z] = (BYTE)minimum(255, maximum(0,(int)(cur_row[z] + amount * diff)));
2759
					}
2759
					}
2760
				}
2760
				}
2761
			}
2761
			}
Lines 2952-2958 bool CxImage::RedEyeRemove(float strength) Link Here
2952
				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)));
2952
				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)));
2953
				if (a<0) a=0;
2953
				if (a<0) a=0;
2954
				color = BlindGetPixelColor(x,y);
2954
				color = BlindGetPixelColor(x,y);
2955
				color.rgbRed = (BYTE)(a*min(color.rgbGreen,color.rgbBlue)+(1.0f-a)*color.rgbRed);
2955
				color.rgbRed = (BYTE)(a*minimum(color.rgbGreen,color.rgbBlue)+(1.0f-a)*color.rgbRed);
2956
				BlindSetPixelColor(x,y,color);
2956
				BlindSetPixelColor(x,y,color);
2957
			}
2957
			}
2958
		}
2958
		}
Lines 2990-2996 bool CxImage::Saturate(const long saturation, const long colorspace) Link Here
2990
	case 1:
2990
	case 1:
2991
		{
2991
		{
2992
			for (int i=0;i<256;i++)	{
2992
			for (int i=0;i<256;i++)	{
2993
				cTable[i] = (BYTE)max(0,min(255,(int)(i + saturation)));
2993
				cTable[i] = (BYTE)maximum(0,minimum(255,(int)(i + saturation)));
2994
			}
2994
			}
2995
			for(long y=ymin; y<ymax; y++){
2995
			for(long y=ymin; y<ymax; y++){
2996
				info.nProgress = (long)(100*(y-ymin)/(ymax-ymin));
2996
				info.nProgress = (long)(100*(y-ymin)/(ymax-ymin));
Lines 3012-3018 bool CxImage::Saturate(const long saturation, const long colorspace) Link Here
3012
	case 2:
3012
	case 2:
3013
		{
3013
		{
3014
			for (int i=0;i<256;i++)	{
3014
			for (int i=0;i<256;i++)	{
3015
				cTable[i] = (BYTE)max(0,min(255,(int)((i-128)*(100 + saturation)/100.0f + 128.5f)));
3015
				cTable[i] = (BYTE)maximum(0,minimum(255,(int)((i-128)*(100 + saturation)/100.0f + 128.5f)));
3016
			}
3016
			}
3017
			for(long y=ymin; y<ymax; y++){
3017
			for(long y=ymin; y<ymax; y++){
3018
				info.nProgress = (long)(100*(y-ymin)/(ymax-ymin));
3018
				info.nProgress = (long)(100*(y-ymin)/(ymax-ymin));
Lines 3242-3251 int CxImage::OptimalThreshold(long method, RECT * pBox, CxImage* pContrastMask) Link Here
3242
3242
3243
	long xmin,xmax,ymin,ymax;
3243
	long xmin,xmax,ymin,ymax;
3244
	if (pBox){
3244
	if (pBox){
3245
		xmin = max(pBox->left,0);
3245
		xmin = maximum(pBox->left,0);
3246
		xmax = min(pBox->right,head.biWidth);
3246
		xmax = minimum(pBox->right,head.biWidth);
3247
		ymin = max(pBox->bottom,0);
3247
		ymin = maximum(pBox->bottom,0);
3248
		ymax = min(pBox->top,head.biHeight);
3248
		ymax = minimum(pBox->top,head.biHeight);
3249
	} else {
3249
	} else {
3250
		xmin = ymin = 0;
3250
		xmin = ymin = 0;
3251
		xmax = head.biWidth; ymax=head.biHeight;
3251
		xmax = head.biWidth; ymax=head.biHeight;
Lines 3463-3469 bool CxImage::AdaptiveThreshold(long method, long nBoxSize, CxImage* pContrastMa Link Here
3463
			r.top = r.bottom + nBoxSize;
3463
			r.top = r.bottom + nBoxSize;
3464
			int threshold = OptimalThreshold(method, &r, pContrastMask);
3464
			int threshold = OptimalThreshold(method, &r, pContrastMask);
3465
			if (threshold <0) return false;
3465
			if (threshold <0) return false;
3466
			mask.SetPixelIndex(x,y,(BYTE)max(0,min(255,nBias+((1.0f-fGlobalLocalBalance)*threshold + fGlobalLocalBalance*globalthreshold))));
3466
			mask.SetPixelIndex(x,y,(BYTE)maximum(0,minimum(255,nBias+((1.0f-fGlobalLocalBalance)*threshold + fGlobalLocalBalance*globalthreshold))));
3467
		}
3467
		}
3468
	}
3468
	}
3469
3469
Lines 3538-3545 bool CxImage::FloodFill(const long xStart, const long yStart, const RGBQUAD cFil Link Here
3538
	if (IsIndexed()){ //--- Generic indexed image, no tolerance OR Grayscale image with tolerance
3538
	if (IsIndexed()){ //--- Generic indexed image, no tolerance OR Grayscale image with tolerance
3539
		BYTE idxRef = GetPixelIndex(xStart,yStart);
3539
		BYTE idxRef = GetPixelIndex(xStart,yStart);
3540
		BYTE idxFill = GetNearestIndex(cFillColor);
3540
		BYTE idxFill = GetNearestIndex(cFillColor);
3541
		BYTE idxMin = (BYTE)min(255, max(0,(int)(idxRef - nTolerance)));
3541
		BYTE idxMin = (BYTE)minimum(255, maximum(0,(int)(idxRef - nTolerance)));
3542
		BYTE idxMax = (BYTE)min(255, max(0,(int)(idxRef + nTolerance)));
3542
		BYTE idxMax = (BYTE)minimum(255, maximum(0,(int)(idxRef + nTolerance)));
3543
3543
3544
		while(!q.empty())
3544
		while(!q.empty())
3545
		{
3545
		{
Lines 3575-3586 bool CxImage::FloodFill(const long xStart, const long yStart, const RGBQUAD cFil Link Here
3575
	} else { //--- RGB image
3575
	} else { //--- RGB image
3576
		RGBQUAD cRef = GetPixelColor(xStart,yStart);
3576
		RGBQUAD cRef = GetPixelColor(xStart,yStart);
3577
		RGBQUAD cRefMin, cRefMax;
3577
		RGBQUAD cRefMin, cRefMax;
3578
		cRefMin.rgbRed   = (BYTE)min(255, max(0,(int)(cRef.rgbRed   - nTolerance)));
3578
		cRefMin.rgbRed   = (BYTE)minimum(255, maximum(0,(int)(cRef.rgbRed   - nTolerance)));
3579
		cRefMin.rgbGreen = (BYTE)min(255, max(0,(int)(cRef.rgbGreen - nTolerance)));
3579
		cRefMin.rgbGreen = (BYTE)minimum(255, maximum(0,(int)(cRef.rgbGreen - nTolerance)));
3580
		cRefMin.rgbBlue  = (BYTE)min(255, max(0,(int)(cRef.rgbBlue  - nTolerance)));
3580
		cRefMin.rgbBlue  = (BYTE)minimum(255, maximum(0,(int)(cRef.rgbBlue  - nTolerance)));
3581
		cRefMax.rgbRed   = (BYTE)min(255, max(0,(int)(cRef.rgbRed   + nTolerance)));
3581
		cRefMax.rgbRed   = (BYTE)minimum(255, maximum(0,(int)(cRef.rgbRed   + nTolerance)));
3582
		cRefMax.rgbGreen = (BYTE)min(255, max(0,(int)(cRef.rgbGreen + nTolerance)));
3582
		cRefMax.rgbGreen = (BYTE)minimum(255, maximum(0,(int)(cRef.rgbGreen + nTolerance)));
3583
		cRefMax.rgbBlue  = (BYTE)min(255, max(0,(int)(cRef.rgbBlue  + nTolerance)));
3583
		cRefMax.rgbBlue  = (BYTE)minimum(255, maximum(0,(int)(cRef.rgbBlue  + nTolerance)));
3584
3584
3585
		while(!q.empty())
3585
		while(!q.empty())
3586
		{
3586
		{
(-)a/lib/cximage-6.0/CxImage/ximage.cpp (-2 / +2 lines)
Lines 460-466 bool CxImage::CreateFromArray(BYTE* pArray,DWORD dwWidth,DWORD dwHeight,DWORD dw Link Here
460
				src+=4;
460
				src+=4;
461
			}
461
			}
462
		} else {
462
		} else {
463
			memcpy(dst,src,min(info.dwEffWidth,dwBytesperline));
463
			memcpy(dst,src,minimum(info.dwEffWidth,dwBytesperline));
464
		}
464
		}
465
	}
465
	}
466
	return true;
466
	return true;
Lines 500-506 bool CxImage::CreateFromMatrix(BYTE** ppMatrix,DWORD dwWidth,DWORD dwHeight,DWOR Link Here
500
					src+=4;
500
					src+=4;
501
				}
501
				}
502
			} else {
502
			} else {
503
				memcpy(dst,src,min(info.dwEffWidth,dwBytesperline));
503
				memcpy(dst,src,minimum(info.dwEffWidth,dwBytesperline));
504
			}
504
			}
505
		}
505
		}
506
	}
506
	}
(-)a/lib/cximage-6.0/CxImage/ximagif.cpp (-3 / +3 lines)
Lines 478-484 bool CxImageGIF::Encode(CxFile * fp, CxImage ** pImages, int pagecount, bool bLo Link Here
478
	ghost.EncodeHeader(fp);
478
	ghost.EncodeHeader(fp);
479
479
480
	if (m_loops!=1){
480
	if (m_loops!=1){
481
		ghost.SetLoops(max(0,m_loops-1));
481
		ghost.SetLoops(maximum(0,m_loops-1));
482
		ghost.EncodeLoopExtension(fp);
482
		ghost.EncodeLoopExtension(fp);
483
	}
483
	}
484
484
Lines 1340-1349 void CxImageGIF::GetComment(char* sz_comment_out) Link Here
1340
////////////////////////////////////////////////////////////////////////////////
1340
////////////////////////////////////////////////////////////////////////////////
1341
void CxImageGIF::GifMix(CxImage & imgsrc2, struct_image & imgdesc)
1341
void CxImageGIF::GifMix(CxImage & imgsrc2, struct_image & imgdesc)
1342
{
1342
{
1343
	long ymin = max(0,(long)(GetHeight()-imgdesc.t - imgdesc.h));
1343
	long ymin = maximum(0,(long)(GetHeight()-imgdesc.t - imgdesc.h));
1344
	long ymax = GetHeight()-imgdesc.t;
1344
	long ymax = GetHeight()-imgdesc.t;
1345
	long xmin = imgdesc.l;
1345
	long xmin = imgdesc.l;
1346
	long xmax = min(GetWidth(), (DWORD)(imgdesc.l + imgdesc.w));
1346
	long xmax = minimum(GetWidth(), (DWORD)(imgdesc.l + imgdesc.w));
1347
1347
1348
	long ibg2= imgsrc2.GetTransIndex();
1348
	long ibg2= imgsrc2.GetTransIndex();
1349
    BYTE i2;
1349
    BYTE i2;
(-)a/lib/cximage-6.0/CxImage/ximahist.cpp (-6 / +6 lines)
Lines 110-116 bool CxImage::HistogramStretch(long method, double threshold) Link Here
110
	// calculate LUT
110
	// calculate LUT
111
	BYTE lut[256];
111
	BYTE lut[256];
112
	for (x = 0; x <256; x++){
112
	for (x = 0; x <256; x++){
113
		lut[x] = (BYTE)max(0,min(255,(255 * (x - minc) / (maxc - minc))));
113
		lut[x] = (BYTE)maximum(0,minimum(255,(255 * (x - minc) / (maxc - minc))));
114
	}
114
	}
115
115
116
	for (y=0; y<head.biHeight; y++)	{
116
	for (y=0; y<head.biHeight; y++)	{
Lines 152-158 bool CxImage::HistogramStretch(long method, double threshold) Link Here
152
		// calculate LUT
152
		// calculate LUT
153
		BYTE lut[256];
153
		BYTE lut[256];
154
		for (x = 0; x <256; x++){
154
		for (x = 0; x <256; x++){
155
			lut[x] = (BYTE)max(0,min(255,(255 * (x - minc) / (maxc - minc))));
155
			lut[x] = (BYTE)maximum(0,minimum(255,(255 * (x - minc) / (maxc - minc))));
156
		}
156
		}
157
157
158
		// normalize image
158
		// normalize image
Lines 225-231 bool CxImage::HistogramStretch(long method, double threshold) Link Here
225
		BYTE range = maxR - minR;
225
		BYTE range = maxR - minR;
226
		if (range != 0)	{
226
		if (range != 0)	{
227
			for (x = 0; x <256; x++){
227
			for (x = 0; x <256; x++){
228
				lutR[x] = (BYTE)max(0,min(255,(255 * (x - minR) / range)));
228
				lutR[x] = (BYTE)maximum(0,minimum(255,(255 * (x - minR) / range)));
229
			}
229
			}
230
		} else lutR[minR] = minR;
230
		} else lutR[minR] = minR;
231
231
Lines 233-239 bool CxImage::HistogramStretch(long method, double threshold) Link Here
233
		range = maxG - minG;
233
		range = maxG - minG;
234
		if (range != 0)	{
234
		if (range != 0)	{
235
			for (x = 0; x <256; x++){
235
			for (x = 0; x <256; x++){
236
				lutG[x] = (BYTE)max(0,min(255,(255 * (x - minG) / range)));
236
				lutG[x] = (BYTE)maximum(0,minimum(255,(255 * (x - minG) / range)));
237
			}
237
			}
238
		} else lutG[minG] = minG;
238
		} else lutG[minG] = minG;
239
			
239
			
Lines 241-247 bool CxImage::HistogramStretch(long method, double threshold) Link Here
241
		range = maxB - minB;
241
		range = maxB - minB;
242
		if (range != 0)	{
242
		if (range != 0)	{
243
			for (x = 0; x <256; x++){
243
			for (x = 0; x <256; x++){
244
				lutB[x] = (BYTE)max(0,min(255,(255 * (x - minB) / range)));
244
				lutB[x] = (BYTE)maximum(0,minimum(255,(255 * (x - minB) / range)));
245
			}
245
			}
246
		} else lutB[minB] = minB;
246
		} else lutB[minB] = minB;
247
247
Lines 292-298 bool CxImage::HistogramStretch(long method, double threshold) Link Here
292
		// calculate LUT
292
		// calculate LUT
293
		BYTE lut[256];
293
		BYTE lut[256];
294
		for (x = 0; x <256; x++){
294
		for (x = 0; x <256; x++){
295
			lut[x] = (BYTE)max(0,min(255,(255 * (x - minc) / (maxc - minc))));
295
			lut[x] = (BYTE)maximum(0,minimum(255,(255 * (x - minc) / (maxc - minc))));
296
		}
296
		}
297
297
298
		for(y=0; y<head.biHeight; y++){
298
		for(y=0; y<head.biHeight; y++){
(-)a/lib/cximage-6.0/CxImage/ximaint.cpp (-4 / +4 lines)
Lines 26-33 void CxImage::OverflowCoordinates(long &x, long &y, OverflowMethod const ofMetho Link Here
26
  switch (ofMethod) {
26
  switch (ofMethod) {
27
    case OM_REPEAT:
27
    case OM_REPEAT:
28
      //clip coordinates
28
      //clip coordinates
29
      x=max(x,0); x=min(x, head.biWidth-1);
29
      x=maximum(x,0); x=minimum(x, head.biWidth-1);
30
      y=max(y,0); y=min(y, head.biHeight-1);
30
      y=maximum(y,0); y=minimum(y, head.biHeight-1);
31
      break;
31
      break;
32
    case OM_WRAP:
32
    case OM_WRAP:
33
      //wrap coordinates
33
      //wrap coordinates
Lines 59-66 void CxImage::OverflowCoordinates(float &x, float &y, OverflowMethod const ofMet Link Here
59
  switch (ofMethod) {
59
  switch (ofMethod) {
60
    case OM_REPEAT:
60
    case OM_REPEAT:
61
      //clip coordinates
61
      //clip coordinates
62
      x=max(x,0); x=min(x, head.biWidth-1);
62
      x=maximum(x,0); x=minimum(x, head.biWidth-1);
63
      y=max(y,0); y=min(y, head.biHeight-1);
63
      y=maximum(y,0); y=minimum(y, head.biHeight-1);
64
      break;
64
      break;
65
    case OM_WRAP:
65
    case OM_WRAP:
66
      //wrap coordinates
66
      //wrap coordinates
(-)a/lib/cximage-6.0/CxImage/ximaiter.h (-2 / +2 lines)
Lines 140-146 inline void CImageIterator::SetY(int y) Link Here
140
inline void CImageIterator::SetRow(BYTE *buf, int n)
140
inline void CImageIterator::SetRow(BYTE *buf, int n)
141
{
141
{
142
	if (n<0) n = (int)ima->GetEffWidth();
142
	if (n<0) n = (int)ima->GetEffWidth();
143
	else n = min(n,(int)ima->GetEffWidth());
143
	else n = minimum(n,(int)ima->GetEffWidth());
144
144
145
	if ((IterImage!=NULL)&&(buf!=NULL)&&(n>0)) memcpy(IterImage,buf,n);
145
	if ((IterImage!=NULL)&&(buf!=NULL)&&(n>0)) memcpy(IterImage,buf,n);
146
}
146
}
Lines 148-154 inline void CImageIterator::SetRow(BYTE *buf, int n) Link Here
148
inline void CImageIterator::GetRow(BYTE *buf, int n)
148
inline void CImageIterator::GetRow(BYTE *buf, int n)
149
{
149
{
150
	if ((IterImage!=NULL)&&(buf!=NULL)&&(n>0))
150
	if ((IterImage!=NULL)&&(buf!=NULL)&&(n>0))
151
		memcpy(buf,IterImage,min(n,(int)ima->GetEffWidth()));
151
		memcpy(buf,IterImage,minimum(n,(int)ima->GetEffWidth()));
152
}
152
}
153
/////////////////////////////////////////////////////////////////////
153
/////////////////////////////////////////////////////////////////////
154
inline BYTE* CImageIterator::GetRow()
154
inline BYTE* CImageIterator::GetRow()
(-)a/lib/cximage-6.0/CxImage/ximajbg.cpp (-1 / +1 lines)
Lines 145-151 bool CxImageJBG::Encode(CxFile * hFile) Link Here
145
	jbg_enc_init(&jbig_state, w, h, planes, &buffer, jbig_data_out, hFile);
145
	jbg_enc_init(&jbig_state, w, h, planes, &buffer, jbig_data_out, hFile);
146
146
147
    //jbg_enc_layers(&jbig_state, 2);
147
    //jbg_enc_layers(&jbig_state, 2);
148
    //jbg_enc_lrlmax(&jbig_state, 800, 600);
148
    //jbg_enc_lrlmaximum(&jbig_state, 800, 600);
149
149
150
	// Specify a few other options (each is ignored if negative)
150
	// Specify a few other options (each is ignored if negative)
151
	int dl = -1, dh = -1, d = -1, l0 = -1, mx = -1;
151
	int dl = -1, dh = -1, d = -1, l0 = -1, mx = -1;
(-)a/lib/cximage-6.0/CxImage/ximajpg.cpp (-1 / +1 lines)
Lines 89-95 bool CxImageJPG::GetExifThumbnail(const char *filename, const char *outname, int Link Here
89
    {
89
    {
90
      if (image.GetWidth() > 256 || image.GetHeight() > 256)
90
      if (image.GetWidth() > 256 || image.GetHeight() > 256)
91
      { // resize the image
91
      { // resize the image
92
//        float amount = 256.0f / max(image.GetWidth(), image.GetHeight());
92
//        float amount = 256.0f / maximum(image.GetWidth(), image.GetHeight());
93
//        image.Resample((long)(image.GetWidth() * amount), (long)(image.GetHeight() * amount), 0);
93
//        image.Resample((long)(image.GetWidth() * amount), (long)(image.GetHeight() * amount), 0);
94
      }
94
      }
95
      if (m_exifinfo.Orientation != 1)
95
      if (m_exifinfo.Orientation != 1)
(-)a/lib/cximage-6.0/CxImage/ximapal.cpp (-7 / +7 lines)
Lines 398-405 void CxImage::RGBtoBGR(BYTE *buffer, int length) Link Here
398
{
398
{
399
	if (buffer && (head.biClrUsed==0)){
399
	if (buffer && (head.biClrUsed==0)){
400
		BYTE temp;
400
		BYTE temp;
401
		length = min(length,(int)info.dwEffWidth);
401
		length = minimum(length,(int)info.dwEffWidth);
402
		length = min(length,(int)(3*head.biWidth));
402
		length = minimum(length,(int)(3*head.biWidth));
403
		for (int i=0;i<length;i+=3){
403
		for (int i=0;i<length;i+=3){
404
			temp = buffer[i]; buffer[i] = buffer[i+2]; buffer[i+2] = temp;
404
			temp = buffer[i]; buffer[i] = buffer[i+2]; buffer[i+2] = temp;
405
		}
405
		}
Lines 444-450 void CxImage::SetPalette(DWORD n, BYTE *r, BYTE *g, BYTE *b) Link Here
444
	if (!g) g = r;
444
	if (!g) g = r;
445
	if (!b) b = g;
445
	if (!b) b = g;
446
	RGBQUAD* ppal=GetPalette();
446
	RGBQUAD* ppal=GetPalette();
447
	DWORD m=min(n,head.biClrUsed);
447
	DWORD m=minimum(n,head.biClrUsed);
448
	for (DWORD i=0; i<m;i++){
448
	for (DWORD i=0; i<m;i++){
449
		ppal[i].rgbRed=r[i];
449
		ppal[i].rgbRed=r[i];
450
		ppal[i].rgbGreen=g[i];
450
		ppal[i].rgbGreen=g[i];
Lines 457-463 void CxImage::SetPalette(rgb_color *rgb,DWORD nColors) Link Here
457
{
457
{
458
	if ((!rgb)||(pDib==NULL)||(head.biClrUsed==0)) return;
458
	if ((!rgb)||(pDib==NULL)||(head.biClrUsed==0)) return;
459
	RGBQUAD* ppal=GetPalette();
459
	RGBQUAD* ppal=GetPalette();
460
	DWORD m=min(nColors,head.biClrUsed);
460
	DWORD m=minimum(nColors,head.biClrUsed);
461
	for (DWORD i=0; i<m;i++){
461
	for (DWORD i=0; i<m;i++){
462
		ppal[i].rgbRed=rgb[i].r;
462
		ppal[i].rgbRed=rgb[i].r;
463
		ppal[i].rgbGreen=rgb[i].g;
463
		ppal[i].rgbGreen=rgb[i].g;
Lines 469-475 void CxImage::SetPalette(rgb_color *rgb,DWORD nColors) Link Here
469
void CxImage::SetPalette(RGBQUAD* pPal,DWORD nColors)
469
void CxImage::SetPalette(RGBQUAD* pPal,DWORD nColors)
470
{
470
{
471
	if ((pPal==NULL)||(pDib==NULL)||(head.biClrUsed==0)) return;
471
	if ((pPal==NULL)||(pDib==NULL)||(head.biClrUsed==0)) return;
472
	memcpy(GetPalette(),pPal,min(GetPaletteSize(),nColors*sizeof(RGBQUAD)));
472
	memcpy(GetPalette(),pPal,minimum(GetPaletteSize(),nColors*sizeof(RGBQUAD)));
473
	info.last_c_isvalid = false;
473
	info.last_c_isvalid = false;
474
}
474
}
475
////////////////////////////////////////////////////////////////////////////////
475
////////////////////////////////////////////////////////////////////////////////
Lines 654-663 void CxImage::SetClrImportant(DWORD ncolors) Link Here
654
654
655
	switch(head.biBitCount){
655
	switch(head.biBitCount){
656
	case 1:
656
	case 1:
657
		head.biClrImportant = min(ncolors,2);
657
		head.biClrImportant = minimum(ncolors,2);
658
		break;
658
		break;
659
	case 4:
659
	case 4:
660
		head.biClrImportant = min(ncolors,16);
660
		head.biClrImportant = minimum(ncolors,16);
661
		break;
661
		break;
662
	case 8:
662
	case 8:
663
		head.biClrImportant = ncolors;
663
		head.biClrImportant = ncolors;
(-)a/lib/cximage-6.0/CxImage/ximapng.cpp (-6 / +6 lines)
Lines 206-214 bool CxImagePNG::Decode(CxFile *hFile) Link Here
206
	} else SetGrayPalette(); //<DP> needed for grayscale PNGs
206
	} else SetGrayPalette(); //<DP> needed for grayscale PNGs
207
	
207
	
208
#ifdef USE_NEW_LIBPNG_API
208
#ifdef USE_NEW_LIBPNG_API
209
	int nshift = max(0,(_bit_depth>>3)-1)<<3;
209
	int nshift = maximum(0,(_bit_depth>>3)-1)<<3;
210
#else
210
#else
211
	int nshift = max(0,(info_ptr->bit_depth>>3)-1)<<3;
211
	int nshift = maximum(0,(info_ptr->bit_depth>>3)-1)<<3;
212
#endif
212
#endif
213
213
214
#ifdef USE_NEW_LIBPNG_API
214
#ifdef USE_NEW_LIBPNG_API
Lines 255-264 bool CxImagePNG::Decode(CxFile *hFile) Link Here
255
			if (pal){
255
			if (pal){
256
				DWORD ip;
256
				DWORD ip;
257
#ifdef USE_NEW_LIBPNG_API
257
#ifdef USE_NEW_LIBPNG_API
258
				for (ip=0;ip<min(head.biClrUsed,(unsigned long)_num_trans);ip++)
258
				for (ip=0;ip<minimum(head.biClrUsed,(unsigned long)_num_trans);ip++)
259
					pal[ip].rgbReserved=_trans_alpha[ip];
259
					pal[ip].rgbReserved=_trans_alpha[ip];
260
#else
260
#else
261
				for (ip=0;ip<min(head.biClrUsed,(unsigned long)info_ptr->num_trans);ip++)
261
				for (ip=0;ip<minimum(head.biClrUsed,(unsigned long)info_ptr->num_trans);ip++)
262
#if PNG_LIBPNG_VER > 10399
262
#if PNG_LIBPNG_VER > 10399
263
					pal[ip].rgbReserved=info_ptr->trans_alpha[ip];
263
					pal[ip].rgbReserved=info_ptr->trans_alpha[ip];
264
#else
264
#else
Lines 737-745 bool CxImagePNG::Encode(CxFile *hFile) Link Here
737
#endif // CXIMAGE_SUPPORT_ALPHA	// <vho>
737
#endif // CXIMAGE_SUPPORT_ALPHA	// <vho>
738
738
739
#ifdef USE_NEW_LIBPNG_API
739
#ifdef USE_NEW_LIBPNG_API
740
	int row_size = max(info.dwEffWidth, (_width * _channels * _bit_depth / 8));
740
	int row_size = maximum(info.dwEffWidth, (_width * _channels * _bit_depth / 8));
741
#else
741
#else
742
	int row_size = max(info.dwEffWidth, info_ptr->width*info_ptr->channels*(info_ptr->bit_depth/8));
742
	int row_size = maximum(info.dwEffWidth, info_ptr->width*info_ptr->channels*(info_ptr->bit_depth/8));
743
	info_ptr->rowbytes = row_size;
743
	info_ptr->rowbytes = row_size;
744
#endif
744
#endif
745
	BYTE *row_pointers = new BYTE[row_size];
745
	BYTE *row_pointers = new BYTE[row_size];
(-)a/lib/cximage-6.0/CxImage/ximaraw.cpp (-2 / +2 lines)
Lines 216-222 bool CxImageRAW::Decode(CxFile *hFile) Link Here
216
216
217
		DWORD size = dcr.width * (dcr.colors*dcr.opt.output_bps/8);
217
		DWORD size = dcr.width * (dcr.colors*dcr.opt.output_bps/8);
218
		RGBtoBGR(ppm,size);
218
		RGBtoBGR(ppm,size);
219
		memcpy(GetBits(dcr.height - 1 - row), ppm, min(size,GetEffWidth()));
219
		memcpy(GetBits(dcr.height - 1 - row), ppm, minimum(size,GetEffWidth()));
220
	}
220
	}
221
	free (ppm);
221
	free (ppm);
222
222
Lines 298-304 bool CxImageRAW::GetExifThumbnail(const char *filename, const char *outname, int Link Here
298
			// Resizing.
298
			// Resizing.
299
      		if (image.GetWidth() > 256 || image.GetHeight() > 256)
299
      		if (image.GetWidth() > 256 || image.GetHeight() > 256)
300
		    {
300
		    {
301
				float amount = 256.0f / max(image.GetWidth(), image.GetHeight());
301
				float amount = 256.0f / maximum(image.GetWidth(), image.GetHeight());
302
				image.Resample((long)(image.GetWidth() * amount), (long)(image.GetHeight() * amount), 0);
302
				image.Resample((long)(image.GetWidth() * amount), (long)(image.GetHeight() * amount), 0);
303
		    }
303
		    }
304
	      	
304
	      	
(-)a/lib/cximage-6.0/CxImage/ximasel.cpp (-25 / +25 lines)
Lines 113-127 bool CxImage::SelectionAddRect(RECT r, BYTE level) Link Here
113
	if (r.left<r.right) {r2.left=r.left; r2.right=r.right; } else {r2.left=r.right ; r2.right=r.left; }
113
	if (r.left<r.right) {r2.left=r.left; r2.right=r.right; } else {r2.left=r.right ; r2.right=r.left; }
114
	if (r.bottom<r.top) {r2.bottom=r.bottom; r2.top=r.top; } else {r2.bottom=r.top ; r2.top=r.bottom; }
114
	if (r.bottom<r.top) {r2.bottom=r.bottom; r2.top=r.top; } else {r2.bottom=r.top ; r2.top=r.bottom; }
115
115
116
	if (info.rSelectionBox.top <= r2.top) info.rSelectionBox.top = max(0L,min(head.biHeight,r2.top+1));
116
	if (info.rSelectionBox.top <= r2.top) info.rSelectionBox.top = maximum(0L,minimum(head.biHeight,r2.top+1));
117
	if (info.rSelectionBox.left > r2.left) info.rSelectionBox.left = max(0L,min(head.biWidth,r2.left));
117
	if (info.rSelectionBox.left > r2.left) info.rSelectionBox.left = maximum(0L,minimum(head.biWidth,r2.left));
118
	if (info.rSelectionBox.right <= r2.right) info.rSelectionBox.right = max(0L,min(head.biWidth,r2.right+1));
118
	if (info.rSelectionBox.right <= r2.right) info.rSelectionBox.right = maximum(0L,minimum(head.biWidth,r2.right+1));
119
	if (info.rSelectionBox.bottom > r2.bottom) info.rSelectionBox.bottom = max(0L,min(head.biHeight,r2.bottom));
119
	if (info.rSelectionBox.bottom > r2.bottom) info.rSelectionBox.bottom = maximum(0L,minimum(head.biHeight,r2.bottom));
120
120
121
	long ymin = max(0L,min(head.biHeight,r2.bottom));
121
	long ymin = maximum(0L,minimum(head.biHeight,r2.bottom));
122
	long ymax = max(0L,min(head.biHeight,r2.top+1));
122
	long ymax = maximum(0L,minimum(head.biHeight,r2.top+1));
123
	long xmin = max(0L,min(head.biWidth,r2.left));
123
	long xmin = maximum(0L,minimum(head.biWidth,r2.left));
124
	long xmax = max(0L,min(head.biWidth,r2.right+1));
124
	long xmax = maximum(0L,minimum(head.biWidth,r2.right+1));
125
125
126
	for (long y=ymin; y<ymax; y++)
126
	for (long y=ymin; y<ymax; y++)
127
		memset(pSelection + xmin + y * head.biWidth, level, xmax-xmin);
127
		memset(pSelection + xmin + y * head.biWidth, level, xmax-xmin);
Lines 144-161 bool CxImage::SelectionAddEllipse(RECT r, BYTE level) Link Here
144
	long xcenter = (r.right + r.left)/2;
144
	long xcenter = (r.right + r.left)/2;
145
	long ycenter = (r.top + r.bottom)/2;
145
	long ycenter = (r.top + r.bottom)/2;
146
146
147
	if (info.rSelectionBox.left > (xcenter - xradius)) info.rSelectionBox.left = max(0L,min(head.biWidth,(xcenter - xradius)));
147
	if (info.rSelectionBox.left > (xcenter - xradius)) info.rSelectionBox.left = maximum(0L,minimum(head.biWidth,(xcenter - xradius)));
148
	if (info.rSelectionBox.right <= (xcenter + xradius)) info.rSelectionBox.right = max(0L,min(head.biWidth,(xcenter + xradius + 1)));
148
	if (info.rSelectionBox.right <= (xcenter + xradius)) info.rSelectionBox.right = maximum(0L,minimum(head.biWidth,(xcenter + xradius + 1)));
149
	if (info.rSelectionBox.bottom > (ycenter - yradius)) info.rSelectionBox.bottom = max(0L,min(head.biHeight,(ycenter - yradius)));
149
	if (info.rSelectionBox.bottom > (ycenter - yradius)) info.rSelectionBox.bottom = maximum(0L,minimum(head.biHeight,(ycenter - yradius)));
150
	if (info.rSelectionBox.top <= (ycenter + yradius)) info.rSelectionBox.top = max(0L,min(head.biHeight,(ycenter + yradius + 1)));
150
	if (info.rSelectionBox.top <= (ycenter + yradius)) info.rSelectionBox.top = maximum(0L,minimum(head.biHeight,(ycenter + yradius + 1)));
151
151
152
	long xmin = max(0L,min(head.biWidth,xcenter - xradius));
152
	long xmin = maximum(0L,minimum(head.biWidth,xcenter - xradius));
153
	long xmax = max(0L,min(head.biWidth,xcenter + xradius + 1));
153
	long xmax = maximum(0L,minimum(head.biWidth,xcenter + xradius + 1));
154
	long ymin = max(0L,min(head.biHeight,ycenter - yradius));
154
	long ymin = maximum(0L,minimum(head.biHeight,ycenter - yradius));
155
	long ymax = max(0L,min(head.biHeight,ycenter + yradius + 1));
155
	long ymax = maximum(0L,minimum(head.biHeight,ycenter + yradius + 1));
156
156
157
	long y,yo;
157
	long y,yo;
158
	for (y=ymin; y<min(ycenter,ymax); y++){
158
	for (y=ymin; y<minimum(ycenter,ymax); y++){
159
		for (long x=xmin; x<xmax; x++){
159
		for (long x=xmin; x<xmax; x++){
160
			yo = (long)(ycenter - yradius * sqrt(1-pow((float)(x - xcenter)/(float)xradius,2)));
160
			yo = (long)(ycenter - yradius * sqrt(1-pow((float)(x - xcenter)/(float)xradius,2)));
161
			if (yo<y) pSelection[x + y * head.biWidth] = level;
161
			if (yo<y) pSelection[x + y * head.biWidth] = level;
Lines 268-277 bool CxImage::SelectionAddPolygon(POINT *points, long npoints, BYTE level) Link Here
268
		RECT r2;
268
		RECT r2;
269
		if (current->x < next->x) {r2.left=current->x; r2.right=next->x; } else {r2.left=next->x ; r2.right=current->x; }
269
		if (current->x < next->x) {r2.left=current->x; r2.right=next->x; } else {r2.left=next->x ; r2.right=current->x; }
270
		if (current->y < next->y) {r2.bottom=current->y; r2.top=next->y; } else {r2.bottom=next->y ; r2.top=current->y; }
270
		if (current->y < next->y) {r2.bottom=current->y; r2.top=next->y; } else {r2.bottom=next->y ; r2.top=current->y; }
271
		if (localbox.top < r2.top) localbox.top = max(0L,min(head.biHeight-1,r2.top+1));
271
		if (localbox.top < r2.top) localbox.top = maximum(0L,minimum(head.biHeight-1,r2.top+1));
272
		if (localbox.left > r2.left) localbox.left = max(0L,min(head.biWidth-1,r2.left-1));
272
		if (localbox.left > r2.left) localbox.left = maximum(0L,minimum(head.biWidth-1,r2.left-1));
273
		if (localbox.right < r2.right) localbox.right = max(0L,min(head.biWidth-1,r2.right+1));
273
		if (localbox.right < r2.right) localbox.right = maximum(0L,minimum(head.biWidth-1,r2.right+1));
274
		if (localbox.bottom > r2.bottom) localbox.bottom = max(0L,min(head.biHeight-1,r2.bottom-1));
274
		if (localbox.bottom > r2.bottom) localbox.bottom = maximum(0L,minimum(head.biHeight-1,r2.bottom-1));
275
275
276
		i++;
276
		i++;
277
	}
277
	}
Lines 385-394 bool CxImage::SelectionAddPolygon(POINT *points, long npoints, BYTE level) Link Here
385
		for (x=localbox.left; x<=localbox.right; x++)
385
		for (x=localbox.left; x<=localbox.right; x++)
386
			if (plocal[x + yoffset]!=1) pSelection[x + yoffset]=level;
386
			if (plocal[x + yoffset]!=1) pSelection[x + yoffset]=level;
387
	}
387
	}
388
	if (info.rSelectionBox.top <= localbox.top) info.rSelectionBox.top = min(head.biHeight,localbox.top + 1);
388
	if (info.rSelectionBox.top <= localbox.top) info.rSelectionBox.top = minimum(head.biHeight,localbox.top + 1);
389
	if (info.rSelectionBox.left > localbox.left) info.rSelectionBox.left = min(head.biWidth,localbox.left);
389
	if (info.rSelectionBox.left > localbox.left) info.rSelectionBox.left = minimum(head.biWidth,localbox.left);
390
	if (info.rSelectionBox.right <= localbox.right) info.rSelectionBox.right = min(head.biWidth,localbox.right + 1);
390
	if (info.rSelectionBox.right <= localbox.right) info.rSelectionBox.right = minimum(head.biWidth,localbox.right + 1);
391
	if (info.rSelectionBox.bottom > localbox.bottom) info.rSelectionBox.bottom = min(head.biHeight,localbox.bottom);
391
	if (info.rSelectionBox.bottom > localbox.bottom) info.rSelectionBox.bottom = minimum(head.biHeight,localbox.bottom);
392
392
393
	free(plocal);
393
	free(plocal);
394
	free(pix);
394
	free(pix);
(-)a/lib/cximage-6.0/CxImage/ximath.cpp (-4 / +4 lines)
Lines 64-73 CxRect2 CxRect2::CrossSection(CxRect2 const &r2) const Link Here
64
 */
64
 */
65
{
65
{
66
  CxRect2 cs;
66
  CxRect2 cs;
67
  cs.botLeft.x=max(botLeft.x, r2.botLeft.x);
67
  cs.botLeft.x=maximum(botLeft.x, r2.botLeft.x);
68
  cs.botLeft.y=max(botLeft.y, r2.botLeft.y);
68
  cs.botLeft.y=maximum(botLeft.y, r2.botLeft.y);
69
  cs.topRight.x=min(topRight.x, r2.topRight.x);
69
  cs.topRight.x=minimum(topRight.x, r2.topRight.x);
70
  cs.topRight.y=min(topRight.y, r2.topRight.y);
70
  cs.topRight.y=minimum(topRight.y, r2.topRight.y);
71
  if (cs.botLeft.x<=cs.topRight.x && cs.botLeft.y<=cs.topRight.y) {
71
  if (cs.botLeft.x<=cs.topRight.x && cs.botLeft.y<=cs.topRight.y) {
72
    return cs;
72
    return cs;
73
  } else {
73
  } else {
(-)a/lib/cximage-6.0/CxImage/ximatif.cpp (-3 / +3 lines)
Lines 470-478 bool CxImageTIF::Decode(CxFile * hFile) Link Here
470
						if ( cb > 0.00304 ) cb = 1.055 * pow(cb,0.41667) - 0.055;
470
						if ( cb > 0.00304 ) cb = 1.055 * pow(cb,0.41667) - 0.055;
471
							else            cb = 12.92 * cb;
471
							else            cb = 12.92 * cb;
472
472
473
						c.rgbRed  =(BYTE)max(0,min(255,(int)(cr*255)));
473
						c.rgbRed  =(BYTE)maximum(0,minimum(255,(int)(cr*255)));
474
						c.rgbGreen=(BYTE)max(0,min(255,(int)(cg*255)));
474
						c.rgbGreen=(BYTE)maximum(0,minimum(255,(int)(cg*255)));
475
						c.rgbBlue =(BYTE)max(0,min(255,(int)(cb*255)));
475
						c.rgbBlue =(BYTE)maximum(0,minimum(255,(int)(cb*255)));
476
476
477
						SetPixelColor(xi,yi,c);
477
						SetPixelColor(xi,yi,c);
478
#if CXIMAGE_SUPPORT_ALPHA
478
#if CXIMAGE_SUPPORT_ALPHA
(-)a/lib/cximage-6.0/CxImage/ximatran.cpp (-69 / +69 lines)
Lines 302-313 bool CxImage::RotateLeft(CxImage* iDst) Link Here
302
			for (ys = 0; ys < newHeight; ys+=RBLOCK) {
302
			for (ys = 0; ys < newHeight; ys+=RBLOCK) {
303
				if (head.biBitCount==24) {
303
				if (head.biBitCount==24) {
304
					//RGB24 optimized pixel access:
304
					//RGB24 optimized pixel access:
305
					for (x = xs; x < min(newWidth, xs+RBLOCK); x++){    //do rotation
305
					for (x = xs; x < minimum(newWidth, xs+RBLOCK); x++){    //do rotation
306
						info.nProgress = (long)(100*x/newWidth);
306
						info.nProgress = (long)(100*x/newWidth);
307
						x2=newWidth-x-1;
307
						x2=newWidth-x-1;
308
						dstPtr = (BYTE*) imgDest.BlindGetPixelPointer(x,ys);
308
						dstPtr = (BYTE*) imgDest.BlindGetPixelPointer(x,ys);
309
						srcPtr = (BYTE*) BlindGetPixelPointer(ys, x2);
309
						srcPtr = (BYTE*) BlindGetPixelPointer(ys, x2);
310
						for (y = ys; y < min(newHeight, ys+RBLOCK); y++){
310
						for (y = ys; y < minimum(newHeight, ys+RBLOCK); y++){
311
							//imgDest.SetPixelColor(x, y, GetPixelColor(y, x2));
311
							//imgDest.SetPixelColor(x, y, GetPixelColor(y, x2));
312
							*(dstPtr) = *(srcPtr);
312
							*(dstPtr) = *(srcPtr);
313
							*(dstPtr+1) = *(srcPtr+1);
313
							*(dstPtr+1) = *(srcPtr+1);
Lines 318-336 bool CxImage::RotateLeft(CxImage* iDst) Link Here
318
					}//for x
318
					}//for x
319
				} else {
319
				} else {
320
					//anything else than 24bpp (and 1bpp): palette
320
					//anything else than 24bpp (and 1bpp): palette
321
					for (x = xs; x < min(newWidth, xs+RBLOCK); x++){
321
					for (x = xs; x < minimum(newWidth, xs+RBLOCK); x++){
322
						info.nProgress = (long)(100*x/newWidth); //<Anatoly Ivasyuk>
322
						info.nProgress = (long)(100*x/newWidth); //<Anatoly Ivasyuk>
323
						x2=newWidth-x-1;
323
						x2=newWidth-x-1;
324
						for (y = ys; y < min(newHeight, ys+RBLOCK); y++){
324
						for (y = ys; y < minimum(newHeight, ys+RBLOCK); y++){
325
							imgDest.SetPixelIndex(x, y, BlindGetPixelIndex(y, x2));
325
							imgDest.SetPixelIndex(x, y, BlindGetPixelIndex(y, x2));
326
						}//for y
326
						}//for y
327
					}//for x
327
					}//for x
328
				}//if (version selection)
328
				}//if (version selection)
329
#if CXIMAGE_SUPPORT_ALPHA
329
#if CXIMAGE_SUPPORT_ALPHA
330
				if (AlphaIsValid()) {
330
				if (AlphaIsValid()) {
331
					for (x = xs; x < min(newWidth, xs+RBLOCK); x++){
331
					for (x = xs; x < minimum(newWidth, xs+RBLOCK); x++){
332
						x2=newWidth-x-1;
332
						x2=newWidth-x-1;
333
						for (y = ys; y < min(newHeight, ys+RBLOCK); y++){
333
						for (y = ys; y < minimum(newHeight, ys+RBLOCK); y++){
334
							imgDest.AlphaSet(x,y,BlindAlphaGet(y, x2));
334
							imgDest.AlphaSet(x,y,BlindAlphaGet(y, x2));
335
						}//for y
335
						}//for y
336
					}//for x
336
					}//for x
Lines 343-351 bool CxImage::RotateLeft(CxImage* iDst) Link Here
343
					imgDest.info.rSelectionBox.right = newWidth-info.rSelectionBox.bottom;
343
					imgDest.info.rSelectionBox.right = newWidth-info.rSelectionBox.bottom;
344
					imgDest.info.rSelectionBox.bottom = info.rSelectionBox.left;
344
					imgDest.info.rSelectionBox.bottom = info.rSelectionBox.left;
345
					imgDest.info.rSelectionBox.top = info.rSelectionBox.right;
345
					imgDest.info.rSelectionBox.top = info.rSelectionBox.right;
346
					for (x = xs; x < min(newWidth, xs+RBLOCK); x++){
346
					for (x = xs; x < minimum(newWidth, xs+RBLOCK); x++){
347
						x2=newWidth-x-1;
347
						x2=newWidth-x-1;
348
						for (y = ys; y < min(newHeight, ys+RBLOCK); y++){
348
						for (y = ys; y < minimum(newHeight, ys+RBLOCK); y++){
349
							imgDest.SelectionSet(x,y,BlindSelectionGet(y, x2));
349
							imgDest.SelectionSet(x,y,BlindSelectionGet(y, x2));
350
						}//for y
350
						}//for y
351
					}//for x
351
					}//for x
Lines 447-458 bool CxImage::RotateRight(CxImage* iDst) Link Here
447
			for (ys = 0; ys < newHeight; ys+=RBLOCK) {
447
			for (ys = 0; ys < newHeight; ys+=RBLOCK) {
448
				if (head.biBitCount==24) {
448
				if (head.biBitCount==24) {
449
					//RGB24 optimized pixel access:
449
					//RGB24 optimized pixel access:
450
					for (y = ys; y < min(newHeight, ys+RBLOCK); y++){
450
					for (y = ys; y < minimum(newHeight, ys+RBLOCK); y++){
451
						info.nProgress = (long)(100*y/newHeight); //<Anatoly Ivasyuk>
451
						info.nProgress = (long)(100*y/newHeight); //<Anatoly Ivasyuk>
452
						y2=newHeight-y-1;
452
						y2=newHeight-y-1;
453
						dstPtr = (BYTE*) imgDest.BlindGetPixelPointer(xs,y);
453
						dstPtr = (BYTE*) imgDest.BlindGetPixelPointer(xs,y);
454
						srcPtr = (BYTE*) BlindGetPixelPointer(y2, xs);
454
						srcPtr = (BYTE*) BlindGetPixelPointer(y2, xs);
455
						for (x = xs; x < min(newWidth, xs+RBLOCK); x++){
455
						for (x = xs; x < minimum(newWidth, xs+RBLOCK); x++){
456
							//imgDest.SetPixelColor(x, y, GetPixelColor(y2, x));
456
							//imgDest.SetPixelColor(x, y, GetPixelColor(y2, x));
457
							*(dstPtr) = *(srcPtr);
457
							*(dstPtr) = *(srcPtr);
458
							*(dstPtr+1) = *(srcPtr+1);
458
							*(dstPtr+1) = *(srcPtr+1);
Lines 463-481 bool CxImage::RotateRight(CxImage* iDst) Link Here
463
					}//for y
463
					}//for y
464
				} else {
464
				} else {
465
					//anything else than BW & RGB24: palette
465
					//anything else than BW & RGB24: palette
466
					for (y = ys; y < min(newHeight, ys+RBLOCK); y++){
466
					for (y = ys; y < minimum(newHeight, ys+RBLOCK); y++){
467
						info.nProgress = (long)(100*y/newHeight); //<Anatoly Ivasyuk>
467
						info.nProgress = (long)(100*y/newHeight); //<Anatoly Ivasyuk>
468
						y2=newHeight-y-1;
468
						y2=newHeight-y-1;
469
						for (x = xs; x < min(newWidth, xs+RBLOCK); x++){
469
						for (x = xs; x < minimum(newWidth, xs+RBLOCK); x++){
470
							imgDest.SetPixelIndex(x, y, BlindGetPixelIndex(y2, x));
470
							imgDest.SetPixelIndex(x, y, BlindGetPixelIndex(y2, x));
471
						}//for x
471
						}//for x
472
					}//for y
472
					}//for y
473
				}//if
473
				}//if
474
#if CXIMAGE_SUPPORT_ALPHA
474
#if CXIMAGE_SUPPORT_ALPHA
475
				if (AlphaIsValid()){
475
				if (AlphaIsValid()){
476
					for (y = ys; y < min(newHeight, ys+RBLOCK); y++){
476
					for (y = ys; y < minimum(newHeight, ys+RBLOCK); y++){
477
						y2=newHeight-y-1;
477
						y2=newHeight-y-1;
478
						for (x = xs; x < min(newWidth, xs+RBLOCK); x++){
478
						for (x = xs; x < minimum(newWidth, xs+RBLOCK); x++){
479
							imgDest.AlphaSet(x,y,BlindAlphaGet(y2, x));
479
							imgDest.AlphaSet(x,y,BlindAlphaGet(y2, x));
480
						}//for x
480
						}//for x
481
					}//for y
481
					}//for y
Lines 488-496 bool CxImage::RotateRight(CxImage* iDst) Link Here
488
					imgDest.info.rSelectionBox.right = info.rSelectionBox.top;
488
					imgDest.info.rSelectionBox.right = info.rSelectionBox.top;
489
					imgDest.info.rSelectionBox.bottom = newHeight-info.rSelectionBox.right;
489
					imgDest.info.rSelectionBox.bottom = newHeight-info.rSelectionBox.right;
490
					imgDest.info.rSelectionBox.top = newHeight-info.rSelectionBox.left;
490
					imgDest.info.rSelectionBox.top = newHeight-info.rSelectionBox.left;
491
					for (y = ys; y < min(newHeight, ys+RBLOCK); y++){
491
					for (y = ys; y < minimum(newHeight, ys+RBLOCK); y++){
492
						y2=newHeight-y-1;
492
						y2=newHeight-y-1;
493
						for (x = xs; x < min(newWidth, xs+RBLOCK); x++){
493
						for (x = xs; x < minimum(newWidth, xs+RBLOCK); x++){
494
							imgDest.SelectionSet(x,y,BlindSelectionGet(y2, x));
494
							imgDest.SelectionSet(x,y,BlindSelectionGet(y2, x));
495
						}//for x
495
						}//for x
496
					}//for y
496
					}//for y
Lines 608-617 bool CxImage::Rotate(float angle, CxImage* iDst) Link Here
608
	newP4.x = (float)(p4.x*cos_angle - p4.y*sin_angle);
608
	newP4.x = (float)(p4.x*cos_angle - p4.y*sin_angle);
609
	newP4.y = (float)(p4.x*sin_angle + p4.y*cos_angle);
609
	newP4.y = (float)(p4.x*sin_angle + p4.y*cos_angle);
610
610
611
	leftTop.x = min(min(newP1.x,newP2.x),min(newP3.x,newP4.x));
611
	leftTop.x = minimum(minimum(newP1.x,newP2.x),minimum(newP3.x,newP4.x));
612
	leftTop.y = min(min(newP1.y,newP2.y),min(newP3.y,newP4.y));
612
	leftTop.y = minimum(minimum(newP1.y,newP2.y),minimum(newP3.y,newP4.y));
613
	rightBottom.x = max(max(newP1.x,newP2.x),max(newP3.x,newP4.x));
613
	rightBottom.x = maximum(maximum(newP1.x,newP2.x),maximum(newP3.x,newP4.x));
614
	rightBottom.y = max(max(newP1.y,newP2.y),max(newP3.y,newP4.y));
614
	rightBottom.y = maximum(maximum(newP1.y,newP2.y),maximum(newP3.y,newP4.y));
615
	leftBottom.x = leftTop.x;
615
	leftBottom.x = leftTop.x;
616
	leftBottom.y = rightBottom.y;
616
	leftBottom.y = rightBottom.y;
617
	rightTop.x = rightBottom.x;
617
	rightTop.x = rightBottom.x;
Lines 740-749 bool CxImage::Rotate2(float angle, Link Here
740
	}//if
740
	}//if
741
741
742
	//(read new dimensions from location of corners)
742
	//(read new dimensions from location of corners)
743
	float minx = (float) min(min(newp[0].x,newp[1].x),min(newp[2].x,newp[3].x));
743
	float minx = (float) minimum(minimum(newp[0].x,newp[1].x),minimum(newp[2].x,newp[3].x));
744
	float miny = (float) min(min(newp[0].y,newp[1].y),min(newp[2].y,newp[3].y));
744
	float miny = (float) minimum(minimum(newp[0].y,newp[1].y),minimum(newp[2].y,newp[3].y));
745
	float maxx = (float) max(max(newp[0].x,newp[1].x),max(newp[2].x,newp[3].x));
745
	float maxx = (float) maximum(maximum(newp[0].x,newp[1].x),maximum(newp[2].x,newp[3].x));
746
	float maxy = (float) max(max(newp[0].y,newp[1].y),max(newp[2].y,newp[3].y));
746
	float maxy = (float) maximum(maximum(newp[0].y,newp[1].y),maximum(newp[2].y,newp[3].y));
747
	int newWidth = (int) floor(maxx-minx+0.5f);
747
	int newWidth = (int) floor(maxx-minx+0.5f);
748
	int newHeight= (int) floor(maxy-miny+0.5f);
748
	int newHeight= (int) floor(maxy-miny+0.5f);
749
	float ssx=((maxx+minx)- ((float) newWidth-1))/2.0f;   //start for x
749
	float ssx=((maxx+minx)- ((float) newWidth-1))/2.0f;   //start for x
Lines 1003-1014 bool CxImage::Resample(long newx, long newy, int mode, CxImage* iDst) Link Here
1003
				if (info.nEscape) break;
1003
				if (info.nEscape) break;
1004
				fY = y * yScale;
1004
				fY = y * yScale;
1005
				ifY = (int)fY;
1005
				ifY = (int)fY;
1006
				ifY1 = min(ymax, ifY+1);
1006
				ifY1 = minimum(ymax, ifY+1);
1007
				dy = fY - ifY;
1007
				dy = fY - ifY;
1008
				for(long x=0; x<newx; x++){
1008
				for(long x=0; x<newx; x++){
1009
					fX = x * xScale;
1009
					fX = x * xScale;
1010
					ifX = (int)fX;
1010
					ifX = (int)fX;
1011
					ifX1 = min(xmax, ifX+1);
1011
					ifX1 = minimum(xmax, ifX+1);
1012
					dx = fX - ifX;
1012
					dx = fX - ifX;
1013
					// Interpolate using the four nearest pixels in the source
1013
					// Interpolate using the four nearest pixels in the source
1014
					if (head.biClrUsed){
1014
					if (head.biClrUsed){
Lines 1328-1336 bool CxImage::DecreaseBpp(DWORD nbit, bool errordiffusion, RGBQUAD* ppal, DWORD Link Here
1328
				eb=(long)c.rgbBlue - (long)ce.rgbBlue;
1328
				eb=(long)c.rgbBlue - (long)ce.rgbBlue;
1329
1329
1330
				c = GetPixelColor(x+1,y);
1330
				c = GetPixelColor(x+1,y);
1331
				c.rgbRed = (BYTE)min(255L,max(0L,(long)c.rgbRed + ((er*7)/16)));
1331
				c.rgbRed = (BYTE)minimum(255L,maximum(0L,(long)c.rgbRed + ((er*7)/16)));
1332
				c.rgbGreen = (BYTE)min(255L,max(0L,(long)c.rgbGreen + ((eg*7)/16)));
1332
				c.rgbGreen = (BYTE)minimum(255L,maximum(0L,(long)c.rgbGreen + ((eg*7)/16)));
1333
				c.rgbBlue = (BYTE)min(255L,max(0L,(long)c.rgbBlue + ((eb*7)/16)));
1333
				c.rgbBlue = (BYTE)minimum(255L,maximum(0L,(long)c.rgbBlue + ((eb*7)/16)));
1334
				SetPixelColor(x+1,y,c);
1334
				SetPixelColor(x+1,y,c);
1335
				int coeff=1;
1335
				int coeff=1;
1336
				for(int i=-1; i<2; i++){
1336
				for(int i=-1; i<2; i++){
Lines 1343-1351 bool CxImage::DecreaseBpp(DWORD nbit, bool errordiffusion, RGBQUAD* ppal, DWORD Link Here
1343
						coeff=1; break;
1343
						coeff=1; break;
1344
					}
1344
					}
1345
					c = GetPixelColor(x+i,y+1);
1345
					c = GetPixelColor(x+i,y+1);
1346
					c.rgbRed = (BYTE)min(255L,max(0L,(long)c.rgbRed + ((er * coeff)/16)));
1346
					c.rgbRed = (BYTE)minimum(255L,maximum(0L,(long)c.rgbRed + ((er * coeff)/16)));
1347
					c.rgbGreen = (BYTE)min(255L,max(0L,(long)c.rgbGreen + ((eg * coeff)/16)));
1347
					c.rgbGreen = (BYTE)minimum(255L,maximum(0L,(long)c.rgbGreen + ((eg * coeff)/16)));
1348
					c.rgbBlue = (BYTE)min(255L,max(0L,(long)c.rgbBlue + ((eb * coeff)/16)));
1348
					c.rgbBlue = (BYTE)minimum(255L,maximum(0L,(long)c.rgbBlue + ((eb * coeff)/16)));
1349
					SetPixelColor(x+i,y+1,c);
1349
					SetPixelColor(x+i,y+1,c);
1350
				}
1350
				}
1351
			}
1351
			}
Lines 1566-1575 bool CxImage::Dither(long method) Link Here
1566
				}
1566
				}
1567
1567
1568
				nlevel = GetPixelIndex(x + 1, y) + (error * 8) / TotalCoeffSum;
1568
				nlevel = GetPixelIndex(x + 1, y) + (error * 8) / TotalCoeffSum;
1569
				level = (BYTE)min(255, max(0, (int)nlevel));
1569
				level = (BYTE)minimum(255, maximum(0, (int)nlevel));
1570
				SetPixelIndex(x + 1, y, level);
1570
				SetPixelIndex(x + 1, y, level);
1571
				nlevel = GetPixelIndex(x + 2, y) + (error * 4) / TotalCoeffSum;
1571
				nlevel = GetPixelIndex(x + 2, y) + (error * 4) / TotalCoeffSum;
1572
				level = (BYTE)min(255, max(0, (int)nlevel));
1572
				level = (BYTE)minimum(255, maximum(0, (int)nlevel));
1573
				SetPixelIndex(x + 2, y, level);
1573
				SetPixelIndex(x + 2, y, level);
1574
				int i;
1574
				int i;
1575
				for (i = -2; i < 3; i++) {
1575
				for (i = -2; i < 3; i++) {
Lines 1591-1597 bool CxImage::Dither(long method) Link Here
1591
						break;
1591
						break;
1592
					}
1592
					}
1593
					nlevel = GetPixelIndex(x + i, y + 1) + (error * coeff) / TotalCoeffSum;
1593
					nlevel = GetPixelIndex(x + i, y + 1) + (error * coeff) / TotalCoeffSum;
1594
					level = (BYTE)min(255, max(0, (int)nlevel));
1594
					level = (BYTE)minimum(255, maximum(0, (int)nlevel));
1595
					SetPixelIndex(x + i, y + 1, level);
1595
					SetPixelIndex(x + i, y + 1, level);
1596
				}
1596
				}
1597
			}
1597
			}
Lines 1620-1629 bool CxImage::Dither(long method) Link Here
1620
				}
1620
				}
1621
1621
1622
				nlevel = GetPixelIndex(x + 1, y) + (error * 8) / TotalCoeffSum;
1622
				nlevel = GetPixelIndex(x + 1, y) + (error * 8) / TotalCoeffSum;
1623
				level = (BYTE)min(255, max(0, (int)nlevel));
1623
				level = (BYTE)minimum(255, maximum(0, (int)nlevel));
1624
				SetPixelIndex(x + 1, y, level);
1624
				SetPixelIndex(x + 1, y, level);
1625
				nlevel = GetPixelIndex(x + 2, y) + (error * 4) / TotalCoeffSum;
1625
				nlevel = GetPixelIndex(x + 2, y) + (error * 4) / TotalCoeffSum;
1626
				level = (BYTE)min(255, max(0, (int)nlevel));
1626
				level = (BYTE)minimum(255, maximum(0, (int)nlevel));
1627
				SetPixelIndex(x + 2, y, level);
1627
				SetPixelIndex(x + 2, y, level);
1628
				int i;
1628
				int i;
1629
				for (i = -2; i < 3; i++) {
1629
				for (i = -2; i < 3; i++) {
Lines 1645-1651 bool CxImage::Dither(long method) Link Here
1645
						break;
1645
						break;
1646
					}
1646
					}
1647
					nlevel = GetPixelIndex(x + i, y + 1) + (error * coeff) / TotalCoeffSum;
1647
					nlevel = GetPixelIndex(x + i, y + 1) + (error * coeff) / TotalCoeffSum;
1648
					level = (BYTE)min(255, max(0, (int)nlevel));
1648
					level = (BYTE)minimum(255, maximum(0, (int)nlevel));
1649
					SetPixelIndex(x + i, y + 1, level);
1649
					SetPixelIndex(x + i, y + 1, level);
1650
				}
1650
				}
1651
				for (i = -2; i < 3; i++) {
1651
				for (i = -2; i < 3; i++) {
Lines 1667-1673 bool CxImage::Dither(long method) Link Here
1667
						break;
1667
						break;
1668
					}
1668
					}
1669
					nlevel = GetPixelIndex(x + i, y + 2) + (error * coeff) / TotalCoeffSum;
1669
					nlevel = GetPixelIndex(x + i, y + 2) + (error * coeff) / TotalCoeffSum;
1670
					level = (BYTE)min(255, max(0, (int)nlevel));
1670
					level = (BYTE)minimum(255, maximum(0, (int)nlevel));
1671
					SetPixelIndex(x + i, y + 2, level);
1671
					SetPixelIndex(x + i, y + 2, level);
1672
				}
1672
				}
1673
			}
1673
			}
Lines 1696-1705 bool CxImage::Dither(long method) Link Here
1696
				}
1696
				}
1697
1697
1698
				nlevel = GetPixelIndex(x + 1, y) + (error * 7) / TotalCoeffSum;
1698
				nlevel = GetPixelIndex(x + 1, y) + (error * 7) / TotalCoeffSum;
1699
				level = (BYTE)min(255, max(0, (int)nlevel));
1699
				level = (BYTE)minimum(255, maximum(0, (int)nlevel));
1700
				SetPixelIndex(x + 1, y, level);
1700
				SetPixelIndex(x + 1, y, level);
1701
				nlevel = GetPixelIndex(x + 2, y) + (error * 5) / TotalCoeffSum;
1701
				nlevel = GetPixelIndex(x + 2, y) + (error * 5) / TotalCoeffSum;
1702
				level = (BYTE)min(255, max(0, (int)nlevel));
1702
				level = (BYTE)minimum(255, maximum(0, (int)nlevel));
1703
				SetPixelIndex(x + 2, y, level);
1703
				SetPixelIndex(x + 2, y, level);
1704
				int i;
1704
				int i;
1705
				for (i = -2; i < 3; i++) {
1705
				for (i = -2; i < 3; i++) {
Lines 1721-1727 bool CxImage::Dither(long method) Link Here
1721
						break;
1721
						break;
1722
					}
1722
					}
1723
					nlevel = GetPixelIndex(x + i, y + 1) + (error * coeff) / TotalCoeffSum;
1723
					nlevel = GetPixelIndex(x + i, y + 1) + (error * coeff) / TotalCoeffSum;
1724
					level = (BYTE)min(255, max(0, (int)nlevel));
1724
					level = (BYTE)minimum(255, maximum(0, (int)nlevel));
1725
					SetPixelIndex(x + i, y + 1, level);
1725
					SetPixelIndex(x + i, y + 1, level);
1726
				}
1726
				}
1727
				for (i = -2; i < 3; i++) {
1727
				for (i = -2; i < 3; i++) {
Lines 1743-1749 bool CxImage::Dither(long method) Link Here
1743
						break;
1743
						break;
1744
					}
1744
					}
1745
					nlevel = GetPixelIndex(x + i, y + 2) + (error * coeff) / TotalCoeffSum;
1745
					nlevel = GetPixelIndex(x + i, y + 2) + (error * coeff) / TotalCoeffSum;
1746
					level = (BYTE)min(255, max(0, (int)nlevel));
1746
					level = (BYTE)minimum(255, maximum(0, (int)nlevel));
1747
					SetPixelIndex(x + i, y + 2, level);
1747
					SetPixelIndex(x + i, y + 2, level);
1748
				}
1748
				}
1749
			}
1749
			}
Lines 1772-1781 bool CxImage::Dither(long method) Link Here
1772
				}
1772
				}
1773
1773
1774
				nlevel = GetPixelIndex(x + 1, y) + (error * 5) / TotalCoeffSum;
1774
				nlevel = GetPixelIndex(x + 1, y) + (error * 5) / TotalCoeffSum;
1775
				level = (BYTE)min(255, max(0, (int)nlevel));
1775
				level = (BYTE)minimum(255, maximum(0, (int)nlevel));
1776
				SetPixelIndex(x + 1, y, level);
1776
				SetPixelIndex(x + 1, y, level);
1777
				nlevel = GetPixelIndex(x + 2, y) + (error * 3) / TotalCoeffSum;
1777
				nlevel = GetPixelIndex(x + 2, y) + (error * 3) / TotalCoeffSum;
1778
				level = (BYTE)min(255, max(0, (int)nlevel));
1778
				level = (BYTE)minimum(255, maximum(0, (int)nlevel));
1779
				SetPixelIndex(x + 2, y, level);
1779
				SetPixelIndex(x + 2, y, level);
1780
				int i;
1780
				int i;
1781
				for (i = -2; i < 3; i++) {
1781
				for (i = -2; i < 3; i++) {
Lines 1797-1803 bool CxImage::Dither(long method) Link Here
1797
						break;
1797
						break;
1798
					}
1798
					}
1799
					nlevel = GetPixelIndex(x + i, y + 1) + (error * coeff) / TotalCoeffSum;
1799
					nlevel = GetPixelIndex(x + i, y + 1) + (error * coeff) / TotalCoeffSum;
1800
					level = (BYTE)min(255, max(0, (int)nlevel));
1800
					level = (BYTE)minimum(255, maximum(0, (int)nlevel));
1801
					SetPixelIndex(x + i, y + 1, level);
1801
					SetPixelIndex(x + i, y + 1, level);
1802
				}
1802
				}
1803
				for (i = -1; i < 2; i++) {
1803
				for (i = -1; i < 2; i++) {
Lines 1813-1819 bool CxImage::Dither(long method) Link Here
1813
						break;
1813
						break;
1814
					}
1814
					}
1815
					nlevel = GetPixelIndex(x + i, y + 2) + (error * coeff) / TotalCoeffSum;
1815
					nlevel = GetPixelIndex(x + i, y + 2) + (error * coeff) / TotalCoeffSum;
1816
					level = (BYTE)min(255, max(0, (int)nlevel));
1816
					level = (BYTE)minimum(255, maximum(0, (int)nlevel));
1817
					SetPixelIndex(x + i, y + 2, level);
1817
					SetPixelIndex(x + i, y + 2, level);
1818
				}
1818
				}
1819
			}
1819
			}
Lines 1845-1920 bool CxImage::Dither(long method) Link Here
1845
				int tmp_index_y = y;
1845
				int tmp_index_y = y;
1846
				int tmp_coeff = 32;
1846
				int tmp_coeff = 32;
1847
				nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1847
				nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1848
				level = (BYTE)min(255, max(0, (int)nlevel));
1848
				level = (BYTE)minimum(255, maximum(0, (int)nlevel));
1849
				SetPixelIndex(tmp_index_x, tmp_index_y, level);
1849
				SetPixelIndex(tmp_index_x, tmp_index_y, level);
1850
1850
1851
				tmp_index_x = x - 3;
1851
				tmp_index_x = x - 3;
1852
				tmp_index_y = y + 1;
1852
				tmp_index_y = y + 1;
1853
				tmp_coeff = 12;
1853
				tmp_coeff = 12;
1854
				nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1854
				nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1855
				level = (BYTE)min(255, max(0, (int)nlevel));
1855
				level = (BYTE)minimum(255, maximum(0, (int)nlevel));
1856
				SetPixelIndex(tmp_index_x, tmp_index_y, level);
1856
				SetPixelIndex(tmp_index_x, tmp_index_y, level);
1857
1857
1858
				tmp_index_x = x - 1;
1858
				tmp_index_x = x - 1;
1859
				tmp_coeff = 26;
1859
				tmp_coeff = 26;
1860
				nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1860
				nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1861
				level = (BYTE)min(255, max(0, (int)nlevel));
1861
				level = (BYTE)minimum(255, maximum(0, (int)nlevel));
1862
				SetPixelIndex(tmp_index_x, tmp_index_y, level);
1862
				SetPixelIndex(tmp_index_x, tmp_index_y, level);
1863
1863
1864
				tmp_index_x = x + 1;
1864
				tmp_index_x = x + 1;
1865
				tmp_coeff = 30;
1865
				tmp_coeff = 30;
1866
				nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1866
				nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1867
				level = (BYTE)min(255, max(0, (int)nlevel));
1867
				level = (BYTE)minimum(255, maximum(0, (int)nlevel));
1868
				SetPixelIndex(tmp_index_x, tmp_index_y, level);
1868
				SetPixelIndex(tmp_index_x, tmp_index_y, level);
1869
1869
1870
				tmp_index_x = x + 3;
1870
				tmp_index_x = x + 3;
1871
				tmp_coeff = 16;
1871
				tmp_coeff = 16;
1872
				nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1872
				nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1873
				level = (BYTE)min(255, max(0, (int)nlevel));
1873
				level = (BYTE)minimum(255, maximum(0, (int)nlevel));
1874
				SetPixelIndex(tmp_index_x, tmp_index_y, level);
1874
				SetPixelIndex(tmp_index_x, tmp_index_y, level);
1875
1875
1876
				tmp_index_x = x - 2;
1876
				tmp_index_x = x - 2;
1877
				tmp_index_y = y + 2;
1877
				tmp_index_y = y + 2;
1878
				tmp_coeff = 12;
1878
				tmp_coeff = 12;
1879
				nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1879
				nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1880
				level = (BYTE)min(255, max(0, (int)nlevel));
1880
				level = (BYTE)minimum(255, maximum(0, (int)nlevel));
1881
				SetPixelIndex(tmp_index_x, tmp_index_y, level);
1881
				SetPixelIndex(tmp_index_x, tmp_index_y, level);
1882
1882
1883
				tmp_index_x = x;
1883
				tmp_index_x = x;
1884
				tmp_coeff = 26;
1884
				tmp_coeff = 26;
1885
				nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1885
				nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1886
				level = (BYTE)min(255, max(0, (int)nlevel));
1886
				level = (BYTE)minimum(255, maximum(0, (int)nlevel));
1887
				SetPixelIndex(tmp_index_x, tmp_index_y, level);
1887
				SetPixelIndex(tmp_index_x, tmp_index_y, level);
1888
1888
1889
				tmp_index_x = x + 2;
1889
				tmp_index_x = x + 2;
1890
				tmp_coeff = 12;
1890
				tmp_coeff = 12;
1891
				nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1891
				nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1892
				level = (BYTE)min(255, max(0, (int)nlevel));
1892
				level = (BYTE)minimum(255, maximum(0, (int)nlevel));
1893
				SetPixelIndex(tmp_index_x, tmp_index_y, level);
1893
				SetPixelIndex(tmp_index_x, tmp_index_y, level);
1894
1894
1895
				tmp_index_x = x - 3;
1895
				tmp_index_x = x - 3;
1896
				tmp_index_y = y + 3;
1896
				tmp_index_y = y + 3;
1897
				tmp_coeff = 5;
1897
				tmp_coeff = 5;
1898
				nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1898
				nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1899
				level = (BYTE)min(255, max(0, (int)nlevel));
1899
				level = (BYTE)minimum(255, maximum(0, (int)nlevel));
1900
				SetPixelIndex(tmp_index_x, tmp_index_y, level);
1900
				SetPixelIndex(tmp_index_x, tmp_index_y, level);
1901
1901
1902
				tmp_index_x = x - 1;
1902
				tmp_index_x = x - 1;
1903
				tmp_coeff = 12;
1903
				tmp_coeff = 12;
1904
				nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1904
				nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1905
				level = (BYTE)min(255, max(0, (int)nlevel));
1905
				level = (BYTE)minimum(255, maximum(0, (int)nlevel));
1906
				SetPixelIndex(tmp_index_x, tmp_index_y, level);
1906
				SetPixelIndex(tmp_index_x, tmp_index_y, level);
1907
1907
1908
				tmp_index_x = x + 1;
1908
				tmp_index_x = x + 1;
1909
				tmp_coeff = 12;
1909
				tmp_coeff = 12;
1910
				nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1910
				nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1911
				level = (BYTE)min(255, max(0, (int)nlevel));
1911
				level = (BYTE)minimum(255, maximum(0, (int)nlevel));
1912
				SetPixelIndex(tmp_index_x, tmp_index_y, level);
1912
				SetPixelIndex(tmp_index_x, tmp_index_y, level);
1913
1913
1914
				tmp_index_x = x + 3;
1914
				tmp_index_x = x + 3;
1915
				tmp_coeff = 5;
1915
				tmp_coeff = 5;
1916
				nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1916
				nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum;
1917
				level = (BYTE)min(255, max(0, (int)nlevel));
1917
				level = (BYTE)minimum(255, maximum(0, (int)nlevel));
1918
				SetPixelIndex(tmp_index_x, tmp_index_y, level);
1918
				SetPixelIndex(tmp_index_x, tmp_index_y, level);
1919
			}
1919
			}
1920
		}
1920
		}
Lines 1941-1947 bool CxImage::Dither(long method) Link Here
1941
			Bmatrix[i] = (BYTE)(dither);
1941
			Bmatrix[i] = (BYTE)(dither);
1942
		}
1942
		}
1943
1943
1944
		int scale = max(0,(8-2*order));
1944
		int scale = maximum(0,(8-2*order));
1945
		int level;
1945
		int level;
1946
		for (long y=0;y<head.biHeight;y++){
1946
		for (long y=0;y<head.biHeight;y++){
1947
			info.nProgress = (long)(100*y/head.biHeight);
1947
			info.nProgress = (long)(100*y/head.biHeight);
Lines 1981-1987 bool CxImage::Dither(long method) Link Here
1981
				}
1981
				}
1982
1982
1983
				nlevel = GetPixelIndex(x+1,y) + (error * 7)/16;
1983
				nlevel = GetPixelIndex(x+1,y) + (error * 7)/16;
1984
				level = (BYTE)min(255,max(0,(int)nlevel));
1984
				level = (BYTE)minimum(255,maximum(0,(int)nlevel));
1985
				SetPixelIndex(x+1,y,level);
1985
				SetPixelIndex(x+1,y,level);
1986
				for(int i=-1; i<2; i++){
1986
				for(int i=-1; i<2; i++){
1987
					switch(i){
1987
					switch(i){
Lines 1993-1999 bool CxImage::Dither(long method) Link Here
1993
						coeff=1; break;
1993
						coeff=1; break;
1994
					}
1994
					}
1995
					nlevel = GetPixelIndex(x+i,y+1) + (error * coeff)/16;
1995
					nlevel = GetPixelIndex(x+i,y+1) + (error * coeff)/16;
1996
					level = (BYTE)min(255,max(0,(int)nlevel));
1996
					level = (BYTE)minimum(255,maximum(0,(int)nlevel));
1997
					SetPixelIndex(x+i,y+1,level);
1997
					SetPixelIndex(x+i,y+1,level);
1998
				}
1998
				}
1999
			}
1999
			}
Lines 2031-2037 bool CxImage::CropRotatedRectangle( long topx, long topy, long width, long heigh Link Here
2031
	if ( fabs(angle)<0.0002 )
2031
	if ( fabs(angle)<0.0002 )
2032
		return Crop( topx, topy, topx+width, topy+height, iDst);
2032
		return Crop( topx, topy, topx+width, topy+height, iDst);
2033
2033
2034
	startx = min(topx, topx - (long)(sin_angle*(double)height));
2034
	startx = minimum(topx, topx - (long)(sin_angle*(double)height));
2035
	endx   = topx + (long)(cos_angle*(double)width);
2035
	endx   = topx + (long)(cos_angle*(double)width);
2036
	endy   = topy + (long)(cos_angle*(double)height + sin_angle*(double)width);
2036
	endy   = topy + (long)(cos_angle*(double)height + sin_angle*(double)width);
2037
	// check: corners of the rectangle must be inside
2037
	// check: corners of the rectangle must be inside
Lines 2079-2088 bool CxImage::Crop(long left, long top, long right, long bottom, CxImage* iDst) Link Here
2079
{
2079
{
2080
	if (!pDib) return false;
2080
	if (!pDib) return false;
2081
2081
2082
	long startx = max(0L,min(left,head.biWidth));
2082
	long startx = maximum(0L,minimum(left,head.biWidth));
2083
	long endx = max(0L,min(right,head.biWidth));
2083
	long endx = maximum(0L,minimum(right,head.biWidth));
2084
	long starty = head.biHeight - max(0L,min(top,head.biHeight));
2084
	long starty = head.biHeight - maximum(0L,minimum(top,head.biHeight));
2085
	long endy = head.biHeight - max(0L,min(bottom,head.biHeight));
2085
	long endy = head.biHeight - maximum(0L,minimum(bottom,head.biHeight));
2086
2086
2087
	if (startx==endx || starty==endy) return false;
2087
	if (startx==endx || starty==endy) return false;
2088
2088
Lines 2443-2450 bool CxImage::CircleTransform(int type,long rmax,float Koeff) Link Here
2443
						nx=x+(x%32)-16;
2443
						nx=x+(x%32)-16;
2444
						ny=y;
2444
						ny=y;
2445
					}
2445
					}
2446
//					nx=max(xmin,min(nx,xmax));
2446
//					nx=maximum(xmin,minimum(nx,xmax));
2447
//					ny=max(ymin,min(ny,ymax));
2447
//					ny=maximum(ymin,minimum(ny,ymax));
2448
				}
2448
				}
2449
				else { nx=-1;ny=-1;}
2449
				else { nx=-1;ny=-1;}
2450
				if (head.biClrUsed==0){
2450
				if (head.biClrUsed==0){
(-)a/lib/cximage-6.0/CxImage/ximawnd.cpp (-8 / +8 lines)
Lines 682-691 long CxImage::Draw(HDC hdc, long x, long y, long cx, long cy, RECT* pClipRect, b Link Here
682
	RECT clipbox,paintbox;
682
	RECT clipbox,paintbox;
683
	GetClipBox(hdc,&clipbox);
683
	GetClipBox(hdc,&clipbox);
684
684
685
	paintbox.top = min(clipbox.bottom,max(clipbox.top,y));
685
	paintbox.top = minimum(clipbox.bottom,maximum(clipbox.top,y));
686
	paintbox.left = min(clipbox.right,max(clipbox.left,x));
686
	paintbox.left = minimum(clipbox.right,maximum(clipbox.left,x));
687
	paintbox.right = max(clipbox.left,min(clipbox.right,x+cx));
687
	paintbox.right = maximum(clipbox.left,minimum(clipbox.right,x+cx));
688
	paintbox.bottom = max(clipbox.top,min(clipbox.bottom,y+cy));
688
	paintbox.bottom = maximum(clipbox.top,minimum(clipbox.bottom,y+cy));
689
689
690
	long destw = paintbox.right - paintbox.left;
690
	long destw = paintbox.right - paintbox.left;
691
	long desth = paintbox.bottom - paintbox.top;
691
	long desth = paintbox.bottom - paintbox.top;
Lines 730-741 long CxImage::Draw(HDC hdc, long x, long y, long cx, long cy, RECT* pClipRect, b Link Here
730
730
731
				for(yy=0;yy<desth;yy++){
731
				for(yy=0;yy<desth;yy++){
732
					dy = head.biHeight-(ymax-yy-y)*fy;
732
					dy = head.biHeight-(ymax-yy-y)*fy;
733
					sy = max(0L,(long)floor(dy));
733
					sy = maximum(0L,(long)floor(dy));
734
					psrc = info.pImage+sy*info.dwEffWidth;
734
					psrc = info.pImage+sy*info.dwEffWidth;
735
					pdst = pbase+yy*ew;
735
					pdst = pbase+yy*ew;
736
					for(xx=0;xx<destw;xx++){
736
					for(xx=0;xx<destw;xx++){
737
						dx = (xx+xmin-x)*fx;
737
						dx = (xx+xmin-x)*fx;
738
						sx = max(0L,(long)floor(dx));
738
						sx = maximum(0L,(long)floor(dx));
739
#if CXIMAGE_SUPPORT_INTERPOLATION
739
#if CXIMAGE_SUPPORT_INTERPOLATION
740
						if (bSmooth){
740
						if (bSmooth){
741
							if (fx > 1 && fy > 1) { 
741
							if (fx > 1 && fy > 1) { 
Lines 813-819 long CxImage::Draw(HDC hdc, long x, long y, long cx, long cy, RECT* pClipRect, b Link Here
813
				
813
				
814
				for(yy=0;yy<desth;yy++){
814
				for(yy=0;yy<desth;yy++){
815
					dy = head.biHeight-(ymax-yy-y)*fy;
815
					dy = head.biHeight-(ymax-yy-y)*fy;
816
					sy = max(0L,(long)floor(dy));
816
					sy = maximum(0L,(long)floor(dy));
817
817
818
					alphaoffset = sy*head.biWidth;
818
					alphaoffset = sy*head.biWidth;
819
					pdst = pbase + yy*ew;
819
					pdst = pbase + yy*ew;
Lines 821-827 long CxImage::Draw(HDC hdc, long x, long y, long cx, long cy, RECT* pClipRect, b Link Here
821
821
822
					for(xx=0;xx<destw;xx++){
822
					for(xx=0;xx<destw;xx++){
823
						dx = (xx+xmin-x)*fx;
823
						dx = (xx+xmin-x)*fx;
824
						sx = max(0L,(long)floor(dx));
824
						sx = maximum(0L,(long)floor(dx));
825
825
826
						if (bAlpha) a=pAlpha[alphaoffset+sx]; else a=255;
826
						if (bAlpha) a=pAlpha[alphaoffset+sx]; else a=255;
827
						a =(BYTE)((a*(1+info.nAlphaMax))>>8);
827
						a =(BYTE)((a*(1+info.nAlphaMax))>>8);

Return to bug 592446