Skip to content

Commit

Permalink
Color Examinition. New Color Test - Lab Color Test.
Browse files Browse the repository at this point in the history
  • Loading branch information
ErmacMKIII committed Sep 17, 2023
1 parent c85cc54 commit 1a0f51f
Show file tree
Hide file tree
Showing 15 changed files with 4,325 additions and 4,190 deletions.
74 changes: 14 additions & 60 deletions Algorithm/HqxFamily/Hqx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/> */
using FOnlineScalex.Examination;
using FOnlineScalex.FRMFile;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -48,74 +49,27 @@ public abstract class Hqx : IAlgorithm
public const uint Vmask = 0x000000FF;

/// <summary>
/// Compares two ARGB colors according to the provided Y, U, V and A thresholds.
/// Compares two ARGB colors according, are they equal against corresponding difference.
/// </summary>
/// <param name="c1">ARGB Color</param>
/// <param name="c2">ARGB Color</param>
/// <param name="trY">U (chrominance) threshold</param>
/// <param name="trU"></param>
/// <param name="trV">V (chrominance) threshold</param>
/// <param name="trA">A (transparency) threshold</param>
/// <returns></returns>
public static bool Diff(uint c1, uint c2, uint trY, uint trU, uint trV, uint trA)
{
uint YUV1 = RgbYuv.RGBToYuv(c1);
uint YUV2 = RgbYuv.RGBToYuv(c2);

return (
(Math.Abs((YUV1 & Ymask) - (YUV2 & Ymask)) > trY) ||
(Math.Abs((YUV1 & Umask) - (YUV2 & Umask)) > trU) ||
(Math.Abs((YUV1 & Vmask) - (YUV2 & Vmask)) > trV) ||
(Math.Abs(((c1 >> 24) - (c2 >> 24))) > trA)
);
}

/// <summary>
/// Compares two ARGB colors according to the provided Y, U, V and A thresholds.
/// </summary>
/// <param name="c1">ARGB Color</param>
/// <param name="c2">ARGB Color</param>
/// <returns>nequal test</returns>
public static bool PixelRGBNotEqual(uint c1, uint c2, double eqDiff)
{
return !PixelRGBEqual(c1, c2, eqDiff);
}

/// <summary>
/// Compares two ARGB colors according to the provided Y, U, V and A thresholds.
/// </summary>
/// <param name="c1">ARGB Color</param>
/// <param name="c2">ARGB Color</param>
/// <returns>nequal test</returns>
public static bool PixelRGBANotEqual(uint c1, uint c2, double eqDiff)
{
return !PixelRGBAEqual(c1, c2, eqDiff);
}

/// <summary>
/// Comparing if two pixel colors satisfy RGB color equality against eqDiff.
/// </summary>
/// <param name="c1">color</param>
/// <param name="c2">other color</param>
/// <param name="eqDiff">equal difference</param>
/// <param name="c1">ARGB Color 1</param>
/// <param name="c2">ARGB Color 2</param>
/// <returns>equal test</returns>
public static bool PixelRGBEqual(uint c1, uint c2, double eqDiff)
{
return Palette.RGBDeviation(Color.FromArgb((int)c1), Color.FromArgb((int)c2)) <= eqDiff;
public static bool PixelEqual(uint c1, uint c2, double eqDiff)
{
return ColorTest.PixelRGBEqual(c1, c2, eqDiff);
}

/// <summary>
/// Comparing if two pixel colors satisfy RGBA color equality against eqDiff.
/// Compares two ARGB colors according, are they equal against corresponding difference.
/// </summary>
/// <param name="c1">color</param>
/// <param name="c2">other color</param>
/// <param name="eqDiff">equal difference</param>
/// <returns>equal test</returns>
public static bool PixelRGBAEqual(uint c1, uint c2, double eqDiff)
/// <param name="c1">ARGB Color 1</param>
/// <param name="c2">ARGB Color 2</param>
/// <returns>nequal test</returns>
public static bool PixelNotEqual(uint c1, uint c2, double eqDiff)
{
return Palette.RGBADeviation(Color.FromArgb((int)c1), Color.FromArgb((int)c2)) <= eqDiff;
return ColorTest.PixelRGBNotEqual(c1, c2, eqDiff);
}

/// <summary>
/// Get Pixel Color (ARGB) from the image from color (ARGB) array at index pos.
/// </summary>
Expand Down
708 changes: 354 additions & 354 deletions Algorithm/HqxFamily/Hqx2x.cs

Large diffs are not rendered by default.

708 changes: 354 additions & 354 deletions Algorithm/HqxFamily/Hqx3x.cs

Large diffs are not rendered by default.

6,618 changes: 3,309 additions & 3,309 deletions Algorithm/HqxFamily/Hqx4x.cs

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion Algorithm/HqxFamily/RgbYuv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ public static uint YuvToRGB(uint yuv)
uint g = (uint)(y - 0.395 * u - 0.581 * v);
uint b = (uint)(y + 2.033 * v);

return (uint)Color.FromArgb((int)r, (int)g, (int)b).ToArgb();
uint argb = (uint)((0xFF << 24) | (r << 16) | (g << 8) | b);

return argb;
}

/// <summary>
Expand Down
95 changes: 6 additions & 89 deletions Algorithm/ScalexFamily/Scalex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/> */
using FOnlineScalex.Algorithm;
using FOnlineScalex.Examination;
using FOnlineScalex.FRMFile;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -123,106 +124,22 @@ protected static bool PixelEqual(Frame src, uint px, uint py, uint tx, uint ty,
return true;
}

if (Palette.RGBDeviation(src.GetPixel(px, py), src.GetPixel(tx, ty)) > deviation)
if (ColorTest.PixelRGBNotEqual(src.GetPixel(px, py), src.GetPixel(tx, ty), deviation))
{
return false;
}

return true;
}

/// <summary>
/// Check if two pixels are equal
/// </summary>
/// <param name="src">Source Frame (where comparison is being performed)</param>
/// <param name="px">first pixel px</param>
/// <param name="py">first pixel py</param>
/// <param name="tx">other (target) pixel px</param>
/// <param name="ty">other (target) pixel py</param>
/// <returns></returns>
protected static bool PixelEqual(Frame src, uint px, uint py, uint tx, uint ty)
{
if (px == tx && py == ty)
{
return true;
}

if (src.GetPixel(px, py) != src.GetPixel(tx, ty))
{
return false;
}

return true;
}


/// <summary>
/// Check if two pixels are equal (safely)
/// </summary>
/// <param name="src">Source Frame (where comparison is being performed)</param>
/// <param name="px">first pixel px</param>
/// <param name="py">first pixel py</param>
/// <param name="tx">other (target) pixel px</param>
/// <param name="ty">other (target) pixel py</param>
/// <returns></returns>
protected static bool PixelEqualSafe(Frame src, uint px, uint py, uint tx, uint ty)
{
if (px == tx && py == ty)
{
return true;
}

if (src.GetPixelSafe(px, py) != src.GetPixelSafe(tx, ty))
{
return false;
}

return true;
}

/// <summary>
/// Check if two pixels are equal (safely)
/// </summary>
/// <param name="src">Source Frame (where comparison is being performed)</param>
/// <param name="px">first pixel px</param>
/// <param name="py">first pixel py</param>
/// <param name="tx">other (target) pixel px</param>
/// <param name="ty">other (target) pixel py</param>
/// <returns></returns>
protected static bool PixelEqualSafe(Frame src, uint px, uint py, uint tx, uint ty, double deviation)
{
if (px == tx && py == ty)
{
return true;
}

if (Palette.RGBDeviation(src.GetPixel(px, py), src.GetPixel(tx, ty)) > deviation)
{
return false;
}

return true;
}


/// <summary>
/// Check if two pixels are equal (RGBA) with some eqDiff [0..1]
/// </summary>
/// <param name="src">Source Bitmap (where comparison is being performed)</param>
/// <param name="px">first pixel px</param>
/// <param name="py">first pixel py</param>
/// <param name="tx">other (target) pixel px</param>
/// <param name="ty">other (target) pixel py</param>
/// <param name="deviation">eqDiff tolerance (pixel difference), in range [0,1]</param>
/// <returns></returns>
protected static bool PixelRGBAEqual(Bitmap src, int px, int py, int tx, int ty, double deviation)

protected static bool PixelEqual(Bitmap src, int px, int py, int tx, int ty, double deviation)
{
if (px == tx && py == ty)
{
return true;
}

if (Palette.RGBADeviation(src.GetPixel(px, py), src.GetPixel(tx, ty)) > deviation)
if (ColorTest.PixelRGBNotEqual(src.GetPixel(px, py), src.GetPixel(tx, ty), deviation))
{
return false;
}
Expand All @@ -247,7 +164,7 @@ protected static bool PixelRGBEqual(Bitmap src, int px, int py, int tx, int ty,
return true;
}

if (Palette.RGBDeviation(src.GetPixel(px, py), src.GetPixel(tx, ty)) > deviation)
if (ColorTest.PixelRGBEqual(src.GetPixel(px, py), src.GetPixel(tx, ty), deviation))
{
return false;
}
Expand Down
10 changes: 5 additions & 5 deletions Algorithm/ScalexFamily/Scalex2x.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ protected static ExpandorBitmap Scalex2xHelper(Bitmap src, int px, int py, doubl
E2[xL,yB] E3[xR,yB]
*/

if (!PixelRGBAEqual(src, Bx, By, Hx, Hy, eqDiff) && !PixelRGBAEqual(src, Dx, Dy, Fx, Fy, eqDiff))
if (!PixelEqual(src, Bx, By, Hx, Hy, eqDiff) && !PixelEqual(src, Dx, Dy, Fx, Fy, eqDiff))
{
if (PixelRGBAEqual(src, Dx, Dy, Bx, By, eqDiff))
if (PixelEqual(src, Dx, Dy, Bx, By, eqDiff))
{
result.E0 = src.GetPixel(Dx, Dy);
}
Expand All @@ -202,7 +202,7 @@ protected static ExpandorBitmap Scalex2xHelper(Bitmap src, int px, int py, doubl
result.E0 = src.GetPixel(Ex, Ey);
}

if (PixelRGBAEqual(src, Bx, By, Fx, Fy, eqDiff))
if (PixelEqual(src, Bx, By, Fx, Fy, eqDiff))
{
result.E1 = src.GetPixel(Fx, Fy);
}
Expand All @@ -211,7 +211,7 @@ protected static ExpandorBitmap Scalex2xHelper(Bitmap src, int px, int py, doubl
result.E1 = src.GetPixel(Ex, Ey);
}

if (PixelRGBAEqual(src, Dx, Dy, Hx, Hy, eqDiff))
if (PixelEqual(src, Dx, Dy, Hx, Hy, eqDiff))
{
result.E2 = src.GetPixel(Dx, Dy);
}
Expand All @@ -220,7 +220,7 @@ protected static ExpandorBitmap Scalex2xHelper(Bitmap src, int px, int py, doubl
result.E2 = src.GetPixel(Ex, Ey);
}

if (PixelRGBAEqual(src, Hx, Hy, Fx, Fy, eqDiff))
if (PixelEqual(src, Hx, Hy, Fx, Fy, eqDiff))
{
result.E2 = src.GetPixel(Fx, Fy);
}
Expand Down
26 changes: 13 additions & 13 deletions Algorithm/ScalexFamily/Scalex3x.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,10 @@ private static ExpandorBitmap Scalex3xHelper(Bitmap src, int px, int py, double
// E3[xL,y ] E4[x,y ] E5[xR, y ]
// E6[xL,yB] E7[x,yB] E8[xR, yB]

if (!PixelRGBAEqual(src, Bx, By, Hx, Hy, eqDiff) && !PixelRGBAEqual(src, Dx, Dy, Fx, Fy, eqDiff))
if (!PixelEqual(src, Bx, By, Hx, Hy, eqDiff) && !PixelEqual(src, Dx, Dy, Fx, Fy, eqDiff))
{
// E0 = D == B ? D : E;
if (PixelRGBAEqual(src, Dx, Dy, Bx, By, eqDiff))
if (PixelEqual(src, Dx, Dy, Bx, By, eqDiff))
{
result.E0 = src.GetPixel(Dx, Dy);
}
Expand All @@ -334,9 +334,9 @@ private static ExpandorBitmap Scalex3xHelper(Bitmap src, int px, int py, double
}

// E1 = (D == B && E != C) || (B == F && E != A) ? B : E;
if ((PixelRGBAEqual(src, Dx, Dy, Bx, By, eqDiff) && !PixelRGBAEqual(src, Ex, Ey, Cx, Cy, eqDiff))
if ((PixelEqual(src, Dx, Dy, Bx, By, eqDiff) && !PixelEqual(src, Ex, Ey, Cx, Cy, eqDiff))
||
(PixelRGBAEqual(src, Bx, By, Fx, Fy, eqDiff) && !PixelRGBAEqual(src, Ex, Ey, Ax, Ay, eqDiff)))
(PixelEqual(src, Bx, By, Fx, Fy, eqDiff) && !PixelEqual(src, Ex, Ey, Ax, Ay, eqDiff)))
{
result.E1 = src.GetPixel(Bx, By);
}
Expand All @@ -346,7 +346,7 @@ private static ExpandorBitmap Scalex3xHelper(Bitmap src, int px, int py, double
}

// E2 = B == F ? F : E;
if (PixelRGBAEqual(src, Bx, By, Fx, Fy, eqDiff))
if (PixelEqual(src, Bx, By, Fx, Fy, eqDiff))
{
result.E2 = src.GetPixel(Fx, Fy);
}
Expand All @@ -356,9 +356,9 @@ private static ExpandorBitmap Scalex3xHelper(Bitmap src, int px, int py, double
}

// E3 = (D == B && E != G) || (D == H && E != A) ? D : E;
if ((PixelRGBAEqual(src, Dx, Dy, Bx, By, eqDiff) && !PixelRGBAEqual(src, Ex, Ey, Gx, Gy, eqDiff))
if ((PixelEqual(src, Dx, Dy, Bx, By, eqDiff) && !PixelEqual(src, Ex, Ey, Gx, Gy, eqDiff))
||
(PixelRGBAEqual(src, Dx, Dy, Hx, Hy, eqDiff) && !PixelRGBAEqual(src, Ex, Ey, Ax, Ay, eqDiff)))
(PixelEqual(src, Dx, Dy, Hx, Hy, eqDiff) && !PixelEqual(src, Ex, Ey, Ax, Ay, eqDiff)))
{
result.E3 = src.GetPixel(Dx, Dy);
}
Expand All @@ -371,9 +371,9 @@ private static ExpandorBitmap Scalex3xHelper(Bitmap src, int px, int py, double
result.E4 = src.GetPixel(Ex, Ey);

// E5 = (B == F && E != I) || (H == F && E != C) ? F : E;
if ((PixelRGBAEqual(src, Bx, By, Fx, Fy, eqDiff) && !PixelRGBAEqual(src, Ex, Ey, Ix, Iy, eqDiff))
if ((PixelEqual(src, Bx, By, Fx, Fy, eqDiff) && !PixelEqual(src, Ex, Ey, Ix, Iy, eqDiff))
||
(PixelRGBAEqual(src, Hx, Hy, Fx, Fy, eqDiff) && !PixelRGBAEqual(src, Ex, Ey, Cx, Cy, eqDiff)))
(PixelEqual(src, Hx, Hy, Fx, Fy, eqDiff) && !PixelEqual(src, Ex, Ey, Cx, Cy, eqDiff)))
{
result.E5 = src.GetPixel(Fx, Fy);
}
Expand All @@ -383,7 +383,7 @@ private static ExpandorBitmap Scalex3xHelper(Bitmap src, int px, int py, double
}

// E6 = D == H ? D : E;
if (PixelRGBAEqual(src, Dx, Dy, Hx, Hy, eqDiff))
if (PixelEqual(src, Dx, Dy, Hx, Hy, eqDiff))
{
result.E6 = src.GetPixel(Dx, Dy);
}
Expand All @@ -393,9 +393,9 @@ private static ExpandorBitmap Scalex3xHelper(Bitmap src, int px, int py, double
}

// E7 = (D == H && E != I) || (H == F && E != G) ? H : E;
if ((PixelRGBAEqual(src, Dx, Dy, Hx, Hy, eqDiff) && !PixelRGBAEqual(src, Ex, Ey, Ix, Iy, eqDiff))
if ((PixelEqual(src, Dx, Dy, Hx, Hy, eqDiff) && !PixelEqual(src, Ex, Ey, Ix, Iy, eqDiff))
||
(PixelRGBAEqual(src, Hx, Hy, Fx, Fy, eqDiff) && !PixelRGBAEqual(src, Ex, Ey, Gx, Gy, eqDiff)))
(PixelEqual(src, Hx, Hy, Fx, Fy, eqDiff) && !PixelEqual(src, Ex, Ey, Gx, Gy, eqDiff)))
{
result.E7 = src.GetPixel(Hx, Hy);
}
Expand All @@ -405,7 +405,7 @@ private static ExpandorBitmap Scalex3xHelper(Bitmap src, int px, int py, double
}

// E8 = H == F ? F : E;
if (PixelRGBAEqual(src, Hx, Hy, Fx, Fy, eqDiff))
if (PixelEqual(src, Hx, Hy, Fx, Fy, eqDiff))
{
result.E8 = src.GetPixel(Fx, Fy);
}
Expand Down
Loading

0 comments on commit 1a0f51f

Please sign in to comment.