@@ -1390,7 +1390,7 @@ private Bitmap ScaleBAContrastGrayAuto(Bitmap img, int x, int ac)
13901390 {
13911391 accelerator.Dispose();
13921392 context.Dispose();
1393- if (img.Height < 25 || (ulong)accelerator.Device.MemorySize < (ulong)img.Width * (ulong)img.Height * (ulong)x * (ulong)x * 12)
1393+ if (img.Width < 144 || 147.37f-0.3289f*img.Width>ac || (ulong)accelerator.Device.MemorySize < (ulong)img.Width * (ulong)img.Height * (ulong)x * (ulong)x * 12)
13941394 {
13951395 return ScaleBAContrastGray(img, x, ac);
13961396 }
@@ -1414,8 +1414,8 @@ private Bitmap Scale255BAGrayAuto(Bitmap img, int x, int ac)
14141414 else
14151415 {
14161416 accelerator.Dispose();
1417- context.Dispose();//after new methods, review
1418- if (img.Height < 25 || (ulong)accelerator.Device.MemorySize < (ulong)img.Width * (ulong)img.Height * (ulong)x * (ulong)x * (ulong)(4 + ac * 51 / 10))
1417+ context.Dispose();
1418+ if ((ulong)accelerator.Device.MemorySize < (ulong)img.Width * (ulong)img.Height * (ulong)x * (ulong)x * (ulong)(4 + ac * 51 / 10))
14191419 {
14201420 return Scale255BAGray(img, x, ac);
14211421 }
@@ -1440,7 +1440,7 @@ private Bitmap ScaleBAExtremumGrayAuto(Bitmap img, int x, int ac)
14401440 {
14411441 accelerator.Dispose();
14421442 context.Dispose();
1443- if (img.Height < 25 || (ulong)accelerator.Device.MemorySize < (ulong)img.Width * (ulong)img.Height * (ulong)x * (ulong)x * 12 )
1443+ if (112.07f-0.078f* img.Width*x >ac || (ulong)accelerator.Device.MemorySize < (( ulong)img.Width * (ulong)img.Height + 2) * (ulong)img.Width * (ulong)img.Height * (ulong) x * (ulong)x / 10000 )
14441444 {
14451445 return ScaleBAExtremumGray(img, x, ac);
14461446 }
@@ -1465,8 +1465,8 @@ private Bitmap ScaleBASmoothContrastGrayAuto(Bitmap img, int x, int ac)
14651465 {
14661466 accelerator.Dispose();
14671467 context.Dispose();
1468- if (( img.Height < 448 && ac * 5 + 508 > img.Height && ac * 34.667f + 32 > img.Height) || (ulong)accelerator.Device.MemorySize < (ulong)img.Width * (ulong)img.Height * (ulong)x * (ulong)x * 12)
1469- {//check if
1468+ if (img.Width < 144 || 147.37f - 0.3289f * img.Width > ac || (ulong)accelerator.Device.MemorySize < (ulong)img.Width * (ulong)img.Height * (ulong)x * (ulong)x * 12)
1469+ {
14701470 return ScaleBASmoothContrastGray(img, x, ac);
14711471 }
14721472 else
@@ -1491,7 +1491,7 @@ private Bitmap ScaleBilinearApproximationColorAuto(Bitmap img, int x, int ac)
14911491 {
14921492 accelerator.Dispose();
14931493 context.Dispose();
1494- if ((ac < 27 && img.Width < 448 && ac * 9.1429f + 201.14f > img.Width) || (ulong)accelerator.Device.MemorySize < (ulong)img.Width * (ulong)img.Height * (ulong)x * (ulong)x * 11)
1494+ if ((ulong)accelerator.Device.MemorySize < (ulong)img.Width * (ulong)img.Height * (ulong)x * (ulong)x * 11 || ac < 27 && img.Width < 448 && ac * 9.1429f + 201.14f < img.Width) //отполировать BA по сравнению с v3.1.3 by TimeMethods только Pareto
14951495 {
14961496 return ScaleBilinearApproximationColor(img, x, ac);
14971497 }
@@ -1516,7 +1516,7 @@ private Bitmap ScaleDerivativeBAColorAuto(Bitmap img, int x, int ac)
15161516 {
15171517 accelerator.Dispose();
15181518 context.Dispose();
1519- if (ac < 22 || (ulong)accelerator.Device.MemorySize < (ulong)img.Width * (ulong)img.Height * (ulong)x * (ulong)x * 11)
1519+ if (ac < 108.87f-0.074f*img.Width*x || (ulong)accelerator.Device.MemorySize < (ulong)img.Width * (ulong)img.Height * (ulong)x * (ulong)x * 11)
15201520 {
15211521 return ScaleDerivativeBAColor(img, x, ac);
15221522 }
@@ -1542,7 +1542,7 @@ private Bitmap ScaleBAContrastColorAuto(Bitmap img, int x, int ac)
15421542 {
15431543 accelerator.Dispose();
15441544 context.Dispose();
1545- if (ac < 22 || (ulong)accelerator.Device.MemorySize < (ulong)img.Width * (ulong)img.Height * (ulong)x * (ulong)x * 20)
1545+ if (img.Width < 24 || 120-0.8333f*img.Width>ac || (ulong)accelerator.Device.MemorySize < (ulong)img.Width * (ulong)img.Height * (ulong)x * (ulong)x * 20)
15461546 {
15471547 return ScaleBAContrastColor(img, x, ac);
15481548 }
@@ -1567,7 +1567,7 @@ private Bitmap ScaleThin255BAColorAuto(Bitmap img, int x, int ac)
15671567 {
15681568 accelerator.Dispose();
15691569 context.Dispose();
1570- if (ac < 22 || (ulong)accelerator.Device.MemorySize < (ulong)img.Width * (ulong)img.Height * (ulong)x * (ulong)x * (ulong)(4 + ac * 153 / 10))
1570+ if (ac < 0.8393f*img.Width-20.857f || (ulong)accelerator.Device.MemorySize < (ulong)img.Width * (ulong)img.Height * (ulong)x * (ulong)x * (ulong)(4 + ac * 153 / 10))
15711571 {
15721572 return ScaleThin255BAColor(img, x, ac);
15731573 }
@@ -1592,7 +1592,7 @@ private Bitmap Scale255BAColorAuto(Bitmap img, int x, int ac)
15921592 {
15931593 accelerator.Dispose();
15941594 context.Dispose();//after new methods, review
1595- if (ac < 22 || (ulong)accelerator.Device.MemorySize < (ulong)img.Width * (ulong)img.Height * (ulong)x * (ulong)x * (ulong)(4 + ac * 153 / 10))
1595+ if ((ulong)accelerator.Device.MemorySize < (ulong)img.Width * (ulong)img.Height * (ulong)x * (ulong)x * (ulong)(4 + ac * 153 / 10))
15961596 {
15971597 return Scale255BAColor(img, x, ac);
15981598 }
@@ -1616,8 +1616,8 @@ private Bitmap ScaleThin255BAGrayAuto(Bitmap img, int x, int ac)
16161616 else
16171617 {
16181618 accelerator.Dispose();
1619- context.Dispose();//after new methods, review
1620- if (img.Height < 25 || (ulong)accelerator.Device.MemorySize < (ulong)img.Width * (ulong)img.Height * (ulong)x * (ulong)x * (ulong)(4 + ac * 51 / 10))
1619+ context.Dispose();
1620+ if (ac < 90.722f-0.0616*img.Width*x || (ulong)accelerator.Device.MemorySize < (ulong)img.Width * (ulong)img.Height * (ulong)x * (ulong)x * (ulong)(4 + ac * 51 / 10))
16211621 {
16221622 return ScaleThin255BAGray(img, x, ac);
16231623 }
@@ -1642,7 +1642,7 @@ private Bitmap ScaleDerivativeBAGrayAuto(Bitmap img, int x, int ac)
16421642 {
16431643 accelerator.Dispose();
16441644 context.Dispose();//after new methods, review
1645- if (img.Height < 25 || (ulong)accelerator.Device.MemorySize < (ulong)img.Width * (ulong)img.Height * (ulong)x * (ulong)x * 11)
1645+ if (img.Width*x < 1472 || (ulong)accelerator.Device.MemorySize < (ulong)img.Width * (ulong)img.Height * (ulong)x * (ulong)x * 11)
16461646 {
16471647 return ScaleDerivativeBAGray(img, x, ac);
16481648 }
@@ -1668,7 +1668,7 @@ private Bitmap ScaleBAMonochromeGrayAuto(Bitmap img, int x, int ac)
16681668 {
16691669 accelerator.Dispose();
16701670 context.Dispose();
1671- if (ac < 22 || (ulong)accelerator.Device.MemorySize < (ulong)img.Width * (ulong)img.Height * (ulong)x * (ulong)x * 12)
1671+ if (ac < 27 || (ulong)accelerator.Device.MemorySize < (ulong)img.Width * (ulong)img.Height * (ulong)x * (ulong)x * 12)
16721672 {
16731673 return ScaleBAMonochromeGray(img, x, ac);
16741674 }
@@ -1693,7 +1693,7 @@ private Bitmap ScaleBAMonochrome2GrayAuto(Bitmap img, int x, int ac)
16931693 {
16941694 accelerator.Dispose();
16951695 context.Dispose();
1696- if (ac < 22 || (ulong)accelerator.Device.MemorySize < (ulong)img.Width * (ulong)img.Height * (ulong)x * (ulong)x * 12)
1696+ if (80.333f-img.Width*x*0.0495f > ac || (ulong)accelerator.Device.MemorySize < (ulong)img.Width * (ulong)img.Height * (ulong)x * (ulong)x * 12)
16971697 {
16981698 return ScaleBAMonochrome2Gray(img, x, ac);
16991699 }
@@ -1718,7 +1718,7 @@ private Bitmap ScaleBAMonochromeColorAuto(Bitmap img, int x, int ac)
17181718 {
17191719 accelerator.Dispose();
17201720 context.Dispose();
1721- if (ac < 22 || (ulong)accelerator.Device.MemorySize < (ulong)img.Width * (ulong)img.Height * (ulong)x * (ulong)x * 20)
1721+ if (62-img.Width*x*0.1094f>ac || (ulong)accelerator.Device.MemorySize < (ulong)img.Width * (ulong)img.Height * (ulong)x * (ulong)x * 20)
17221722 {
17231723 return ScaleBAMonochromeColor(img, x, ac);
17241724 }
@@ -1743,7 +1743,7 @@ private Bitmap ScaleBAExtremumColorAuto(Bitmap img, int x, int ac)
17431743 {
17441744 accelerator.Dispose();
17451745 context.Dispose();
1746- if (ac < 22) //after new methods, review
1746+ if (157.26f-0.1068f*img.Width*x> ac || (ulong)accelerator.Device.MemorySize < ((ulong)img.Width * (ulong)img.Height+4) *(ulong)img.Width * (ulong)img.Height * (ulong)x * (ulong)x/ 10000)
17471747 {
17481748 return ScaleBAExtremumColor(img, x, ac);
17491749 }
@@ -1768,7 +1768,7 @@ private Bitmap ScaleBAMonochrome2ColorAuto(Bitmap img, int x, int ac)
17681768 {
17691769 accelerator.Dispose();
17701770 context.Dispose();
1771- if (ac < 22 || (ulong)accelerator.Device.MemorySize < (ulong)img.Width * (ulong)img.Height * (ulong)x * (ulong)x * 20)
1771+ if (ac < 76.659f-0.0541f*img.Width*x || (ulong)accelerator.Device.MemorySize < (ulong)img.Width * (ulong)img.Height * (ulong)x * (ulong)x * 20)
17721772 {//after new methods, review
17731773 return ScaleBAMonochrome2Color(img, x, ac);
17741774 }
@@ -1794,7 +1794,7 @@ private Bitmap ScaleBASmoothContrastColorAuto(Bitmap img, int x, int ac)
17941794 {
17951795 accelerator.Dispose();
17961796 context.Dispose();
1797- if (ac < 22 || (ulong)accelerator.Device.MemorySize < (ulong)img.Width * (ulong)img.Height * (ulong)x * (ulong)x * 20)
1797+ if (img.Width < 144 || 103.9f - 0.1623f * img.Width > ac || (ulong)accelerator.Device.MemorySize < (ulong)img.Width * (ulong)img.Height * (ulong)x * (ulong)x * 20)
17981798 { //after new methods, review
17991799 return ScaleBASmoothContrastColor(img, x, ac);
18001800 }
@@ -1819,7 +1819,7 @@ private Bitmap ScaleBilinearApproximationGrayAuto(Bitmap img, int x, int ac)
18191819 {
18201820 accelerator.Dispose();
18211821 context.Dispose();
1822- if ((img.Height < 448 && ac * 5 + 508 > img.Height && ac * 34.667f + 32 > img.Height) || (ulong)accelerator.Device.MemorySize < (ulong)img.Width * (ulong)img.Height * (ulong)x * (ulong)x * 12)
1822+ if ((img.Height < 448 && ac * 5 + 508 > img.Height && ac * 34.667f + 32 < img.Height) || (ulong)accelerator.Device.MemorySize < (ulong)img.Width * (ulong)img.Height * (ulong)x * (ulong)x * 12)
18231823 {
18241824 return ScaleBilinearApproximationGray(img, x, ac);
18251825 }
@@ -4792,7 +4792,7 @@ private Bitmap ScaleBAMonochrome2ColorGPU(Bitmap img, int x, int ac)
47924792 private byte[,,] BilinearApproximationExtremumColorGPU(Bitmap img, int x, int ac)
47934793 {
47944794 Context context = Context.Create(b => b.AllAccelerators().EnableAlgorithms().Optimize(OptimizationLevel.O2).PageLocking(PageLockingMode.Aggressive));
4795- #if DEBUG
4795+ #if ! DEBUG
47964796 Accelerator accelerator = context.GetPreferredDevice(true).CreateAccelerator(context);
47974797 ulong mem = 4 * (ulong)MathF.Pow(2, 30);//4GB VRAM for debug
47984798#else
@@ -23223,7 +23223,7 @@ public Bitmap SmoothCAScolor(Bitmap lowResImage, int scale, int iterations) //т
2322323223 }
2322423224 }
2322523225
23226- float[,] edgeMap = DetectEdgesColor(lowResLuminance);
23226+
2322723227
2322823228 float[,,] gradient = new float[highWidth, highHeight, 3];
2322923229 int yMaxM = highHeight - 1;
@@ -23295,6 +23295,7 @@ public Bitmap SmoothCAScolor(Bitmap lowResImage, int scale, int iterations) //т
2329523295 EnforceAverageConstraintColor(highResLuminance, lowResLuminance, scale);
2329623296 }
2329723297
23298+ float[,] edgeMap = DetectEdgesColor(lowResLuminance);
2329823299 float[,] edgeEnhancement = new float[highWidth, highHeight];
2329923300 byte[,,] output = new byte[highWidth, highHeight, 3];
2330023301 int scaleHalf = scale / 2;
0 commit comments