From 75af86cbcb2f0d12e39c23abde2f0b4c762d20f3 Mon Sep 17 00:00:00 2001 From: crashGG <80488411+crashGG@users.noreply.github.com> Date: Sun, 16 Nov 2025 22:05:11 +0300 Subject: [PATCH] Enhance tex_mmpx.csh bug fixes and logic optimizations --- assets/shaders/tex_mmpx.csh | 1296 ++++++++++++++++++++--------------- 1 file changed, 733 insertions(+), 563 deletions(-) diff --git a/assets/shaders/tex_mmpx.csh b/assets/shaders/tex_mmpx.csh index fd9005d8fb..5a8ca37621 100644 --- a/assets/shaders/tex_mmpx.csh +++ b/assets/shaders/tex_mmpx.csh @@ -19,23 +19,24 @@ uint src(int x, int y) { return readColoru(uvec2(clamp(x, 0, params.width - 1), clamp(y, 0, params.height - 1))); } -//RGB visual weight + alpha segmentation -uint luma(uint C) { +// RGB visual weight + alpha segmentation +int luma(uint C) { - if (C==0) return 7000000; + if (C==0) return 7340032; - uint alpha = C >> 24; - //BT.601 standard from the CRT era - uint rgbsum = ((C >> 16) & 0xFF) *299 + ((C >> 8) & 0xFF) *587 + (C & 0xFF) *114; + int alpha = int(C >> 24); + // CRT era BT.601 standard (255 × (299 + 587 + 114), output range: 0~255000) + int rgbsum = int(((C >> 16) & 0xFF) *299 + ((C >> 8) & 0xFF) *587 + (C & 0xFF) *114); // R G B average - //uint rgbsum = ((C >> 16) & 0xFF) + ((C >> 8) & 0xFF) + (C & 0xFF); + //int rgbsum = ((C >> 16) & 0xFF) + ((C >> 8) & 0xFF) + (C & 0xFF); - uint alphafactor = - (alpha == 0) ? 7000000 : // Fully transparent - (alpha > 217) ? 1000000 : // Two golden sections 0.854102 ×255≈217.8 - (alpha > 157) ? 2000000 : // 1 golden section 0.618034 ×255≈157.6 - (alpha > 97) ? 3000000 : // 1 golden section (short) 0.381966 ×255≈97.4 - (alpha > 37) ? 4000000 : 5000000; // Two golden sections (short) 0.145898 ×255≈37.2 + // 2^20 * n to facilitate subsequent removal of alpha weighting using bit shifts + int alphafactor = + (alpha == 0) ? 7340032 : // Fully transparent + (alpha > 217) ? 1048576 : // Two golden sections 0.854102 ×255≈217.8 + (alpha > 157) ? 2097152 : // 1 golden section 0.618034 ×255≈157.6 + (alpha > 97) ? 3145728 : // 1 golden section (short) 0.381966 ×255≈97.4 + (alpha > 37) ? 4194304 : 5242880; // Two golden sections (short) 0.145898 ×255≈37.2 return rgbsum + alphafactor; @@ -49,7 +50,6 @@ bool checkblack(vec4 col) { //bool checkwhite(vec4 col) { // if (col.r < 0.9 || col.g < 0.92 || col.b < 0.9) return false; - // return true; //} @@ -57,30 +57,28 @@ bool sim(vec4 rgbaC1, vec4 rgbaC2, int Lv) { vec4 diff = abs(rgbaC1 - rgbaC2); - // 1. Quick component difference check - if ( diff.r > 0.145898 || diff.g > 0.145898 || diff.b > 0.145898 || diff.a > 0.145898 ) return false; + // 1. Fast component difference check + float chDiff = Lv==1 ? 0.09652388 : Lv==2 ? 0.145898 : 0.2527; + if ( diff.r > chDiff || diff.g > chDiff || diff.b > chDiff || diff.a > 0.145898 ) return false; vec3 rgbC1 = rgbaC1.rgb; vec3 rgbC2 = rgbaC2.rgb; - - if (rgbC1 == rgbC2) return true; - - // 2.Quickly filter out identical pixels and very dark/bright pixels after clamping + + // 2. Quickly filter out identical pixels and very dark/bright pixels after clamping vec3 clampCol1 = clamp(rgbC1, vec3(0.078),vec3(0.92)); vec3 clampCol2 = clamp(rgbC2, vec3(0.078),vec3(0.92)); vec3 clampdiff = clampCol1 - clampCol2; vec3 absclampdiff = abs(clampdiff); if ( absclampdiff.r < 0.05572809 && absclampdiff.g < 0.021286 && absclampdiff.b < 0.05572809 ) return true; - float dotdist = 0.00931686; - if (Lv==2) dotdist = 0.024391856; - if (Lv==3) dotdist = 0.0638587; + // Cube of Euclidean distance between two points, 2+1, 2 short golden sections + float dotdist = Lv==1 ? 0.00931686 : Lv==2 ? 0.024391856 : 0.0638587; - // 3. Quick squared distance check + // 3. Fast squared distance check float dot_diff = dot(diff.rgb, diff.rgb); if (dot_diff > dotdist) return false; - // 4. Add opposite channels to squared distance and re-evaluate + // 4. Re-check squared distance after adding opposite channels float teamA = 0.0; float teamB = 0.0; @@ -88,11 +86,9 @@ bool sim(vec4 rgbaC1, vec4 rgbaC2, int Lv) { if (clampdiff.g > 0.0) teamA += absclampdiff.g; else teamB += absclampdiff.g; if (clampdiff.b > 0.0) teamA += absclampdiff.b; else teamB += absclampdiff.b; float team = min(teamA,teamB); - // Testing shows at least 3 times the opposite channel value is needed. (+1x ties, +2x creates an increasing trend) + // Testing shows at least 3 times the opposite channel value needs to be added. (+1x draws, +2x creates an increasing trend) if (dot_diff + team*team*3.0 > dotdist) return false; - if (Lv==3) return true; - // 5. Check for gray pixels float sum1 = rgbC1.r + rgbC1.g + rgbC1.b; float avg1 = sum1 * 0.3333333; @@ -105,31 +101,34 @@ bool sim(vec4 rgbaC1, vec4 rgbaC2, int Lv) { bool Col1isGray = all(lessThan(abs(rgbC1 - vec3(avg1)), vec3(threshold1))); bool Col2isGray = all(lessThan(abs(rgbC2 - vec3(avg2)), vec3(threshold2))); - // Return true if both or neither are gray + // Return true if both are gray or both are not gray return Col1isGray == Col2isGray; } + bool sim1(uint C1, uint C2) { if (C1 == C2) return true; vec4 rgbaC1 = unpackUnorm4x8(C1); vec4 rgbaC2 = unpackUnorm4x8(C2); return sim(rgbaC1, rgbaC2, 1); } -bool sim2(uint C1, uint C2) { - if (C1 == C2) return true; - vec4 rgbaC1 = unpackUnorm4x8(C1); - vec4 rgbaC2 = unpackUnorm4x8(C2); - return sim(rgbaC1, rgbaC2, 2); + +bool v4i_sim1(vec4 rgbaE, uint C) { + vec4 rgbaC = unpackUnorm4x8(C); + return sim(rgbaE, rgbaC, 1); } -bool vec4_sim2(vec4 C1, vec4 C2) { - return sim(C1, C2, 2); + +bool v4i_sim2(vec4 rgbaE, uint C) { + vec4 rgbaC = unpackUnorm4x8(C); + return sim(rgbaE, rgbaC, 2); } -bool vec4_sim3(vec4 C1, vec4 C2) { + +bool v4_sim3(vec4 C1, vec4 C2) { return sim(C1, C2, 3); } bool mixcheck(vec4 col1, vec4 col2) { - // Cannot mix if one is transparent + // Cannot mix if one is transparent and the other is not bool col1alpha0 = col1.a < 0.003; bool col2alpha0 = col2.a < 0.003; if (col1alpha0!=col2alpha0) return false; @@ -137,16 +136,16 @@ bool mixcheck(vec4 col1, vec4 col2) { vec4 diff = col1 - col2; vec4 absdiff = abs(diff); - // 1. Quick component difference check + // 1. Fast component difference check if ( absdiff.r > 0.618034 || absdiff.g > 0.618034 || absdiff.b > 0.618034 || absdiff.a > 0.5 ) return false; - // Quickly filter out similar pixels (0.4377 divided by 6, sqrt max can be 0.27) + // Quickly filter out similar pixels (0.4377 divided by 6, square root max can be 0.27) if ( absdiff.r < 0.27 && absdiff.g < 0.27 && absdiff.b < 0.27 ) return true; - // 3. Quick squared distance check + // 3. Fast squared distance check float dot_diff = dot(diff.rgb, diff.rgb); - if (dot_diff > 0.4377) return false; + if (dot_diff > 0.4377) return false; // One short golden section of Euclidean distance - // 4. Add opposite channels to squared distance and re-evaluate + // 4. Re-check squared distance after adding opposite channels float teamA = 0.0; float teamB = 0.0; @@ -154,28 +153,30 @@ bool mixcheck(vec4 col1, vec4 col2) { if (diff.g > 0.0) teamA += absdiff.g; else teamB += absdiff.g; if (diff.b > 0.0) teamA += absdiff.b; else teamB += absdiff.b; float team = min(teamA,teamB); - // Testing shows at least 3 times the opposite channel value is needed. (+1x ties, +2x creates a positive trend) + // Testing shows at least 3 times the opposite channel value needs to be added. (+1x draws, +2x creates a positive trend) if (dot_diff + team*team*3.0 > 0.4377) return false; return true; } -bool eq(uint B, uint A0){ - return B == A0; +bool eq(uint C1, uint C2){ + if (C1 == C2) return true; + + int rgbC1 = int(C1 & 0x00FFFFFF); + int rgbC2 = int(C2 & 0x00FFFFFF); + + if (rgbC1 != rgbC2) return false; + + int alphaC1 = int(C1 >> 24); + int alphaC2 = int(C2 >> 24); + + return abs(alphaC1-alphaC2)<38; } bool noteq(uint B, uint A0){ return B != A0; } -bool vec_eq(vec4 col1, vec4 col2) { - vec4 diff = abs(col1 - col2); - - if (diff.r > 0.004 || diff.g > 0.004 || diff.b > 0.004 || diff.a > 0.021286) return false; - - return true; -} - bool rgb_eq(vec4 col1, vec4 col2) { vec4 diff = abs(col1 - col2); @@ -184,7 +185,7 @@ bool rgb_eq(vec4 col1, vec4 col2) { return true; } -bool vec_noteq(vec4 col1, vec4 col2) { +bool v4_noteq(vec4 col1, vec4 col2) { vec4 diff = abs(col1 - col2); if (diff.r > 0.004 || diff.g > 0.004 || diff.b > 0.004 || diff.a > 0.021286) return true; @@ -196,6 +197,10 @@ bool all_eq2(uint B, uint A0, uint A1) { return (eq(B,A0) && eq(B,A1)); } +bool any_eq2(uint B, uint A0, uint A1) { + return (eq(B,A0) || eq(B,A1)); +} + bool any_eq3(uint B, uint A0, uint A1, uint A2) { return (eq(B,A0) || eq(B,A1) || eq(B,A2)); } @@ -205,50 +210,29 @@ bool none_eq2(uint B, uint A0, uint A1) { } /////////////////////// Test Colors /////////////////////// - //vec4 testcolor = vec4(1.0, 0.0, 1.0, 1.0); // Magenta (Opaque) - //vec4 testcolor2 = vec4(0.0, 1.0, 1.0, 1.0); // Cyan (Opaque) - //vec4 testcolor3 = vec4(1.0, 1.0, 0.0, 1.0); // Yellow (Opaque) - //vec4 testcolor4 = vec4(1.0, 1.0, 1.0, 1.0); // White (Opaque) +//const vec4 testcolor = vec4(1.0, 0.0, 1.0, 1.0); // Magenta (Opaque) +//const vec4 testcolor2 = vec4(0.0, 1.0, 1.0, 1.0); // Cyan (Opaque) +//const vec4 testcolor3 = vec4(1.0, 1.0, 0.0, 1.0); // Yellow (Opaque) +//const vec4 testcolor4 = vec4(1.0, 1.0, 1.0, 1.0); // White (Opaque) -// "Concave + Cross" type Weak blending (Weak mix/None) -vec4 admixC(uint X1, uint X2, vec4 rgbaE) { +// "Concave + Cross" type Weak mixing (Weak Mix / None) +vec4 admixC(uint X, vec4 rgbaE) { - // Return if center point is transparent - // if (rgbaE.a < 0.003) return rgbaE; - - // Unpack uint to RGBA float vector (range 0.0-1.0) - vec4 rgbaX1 = unpackUnorm4x8(X1); - vec4 rgbaX2 = unpackUnorm4x8(X2); - - // Return if black on both sides? Not necessary, E is also dark when mixing is possible. - //if (checkblack(rgbaX1) && checkblack(rgbaX2)) return rgbaE; - - bool mix1ok = mixcheck(rgbaX1, rgbaE); - bool mix2ok = mixcheck(rgbaX2, rgbaE); - - if (mix1ok&&!mix2ok) return mix(rgbaX1, rgbaE, 0.618034); - if (!mix1ok&&mix2ok) return mix(rgbaX2, rgbaE, 0.618034); - if (mix1ok&&mix2ok) { - float rgbDist1 = dot(rgbaX1 - rgbaE, rgbaX1 - rgbaE); - float rgbDist2 = dot(rgbaX2 - rgbaE, rgbaX2 - rgbaE); - - // Choose the closer reference color - vec4 rgbaX = rgbDist1 < rgbDist2 ? rgbaX1 : rgbaX2; - return mix(rgbaX, rgbaE, 0.618034); - } - - return rgbaE; - -} - -// K type Forced weak blending (Weak mix/Weaker) -vec4 admixK(uint X, vec4 rgbaE) { -//return testcolor; vec4 rgbaX = unpackUnorm4x8(X); - // When E is transparent, return X's rgb value and the weakest mixed alpha value (avoid mixing rgb with black) - // Checked before entry that it won't be transparent. - // if (rgbaX.a < 0.003 || rgbaE.a < 0.003) return rgbaE; + // Transparent pixels already filtered in main logic + + bool mixok = mixcheck(rgbaX, rgbaE); + + return mixok ? mix(rgbaX, rgbaE, 0.618034) : rgbaE; +} + +// K type Forced weak mixing (Weaker Mix / Even Weaker) +vec4 admixK(uint X, vec4 rgbaE) { + + vec4 rgbaX = unpackUnorm4x8(X); + + // Transparent pixels already filtered in main logic bool mixok = mixcheck(rgbaX, rgbaE); @@ -265,8 +249,8 @@ vec4 admixL(vec4 rgbaX, vec4 rgbaE, uint S) { vec4 rgbaS = unpackUnorm4x8(S); - // If target X and reference S(sample) are different, it means already mixed once, then just copy the target. - if (vec_noteq(rgbaX, rgbaS)) return rgbaX; + // If target X and reference S(sample) are different, it means it has been mixed once already, then just copy the target. + if (v4_noteq(rgbaX, rgbaS)) return rgbaX; bool mixok = mixcheck(rgbaX, rgbaE); @@ -276,47 +260,66 @@ vec4 admixL(vec4 rgbaX, vec4 rgbaE, uint S) { /******************************************************************************************************************************************** * main slope + X cross-processing mechanism * *******************************************************************************************************************************************/ -vec4 admixX(uint A, uint B, uint C, uint D, uint E, uint F, uint G, uint H, uint I, uint P, uint PA, uint PC, uint Q, uint QA, uint QG, uint R, uint RC, uint RI, uint S, uint SG, uint SI, uint AA) { +vec4 admixX(uint A, uint B, uint C, uint D, uint E, uint F, uint G, uint H, uint I, uint P, uint PA, uint PC, uint Q, uint QA, uint QG, uint R, uint RC, uint RI, uint S, uint SG, uint SI, uint AA, uint CC, uint GG, int El, int Bl, int Dl, int Fl, int Hl, vec4 rgbaE) { // Pre-define 3 types of special exits - vec4 slopeBAD = vec4(2.0); - vec4 theEXIT = vec4(8.0); - vec4 slopEND = vec4(33.0); + const vec4 slopeBAD = vec4(2.0); + const vec4 theEXIT = vec4(8.0); + const vec4 slopEND = vec4(33.0); //pre-cal bool eq_B_D = eq(B, D); bool eq_B_C = eq(B, C); bool eq_D_G = eq(D, G); - // Exit if bilateral straight line clamping - if (eq_B_D && eq_B_C && eq_D_G) return slopeBAD; - vec4 rgbaE = unpackUnorm4x8(E); vec4 rgbaB = unpackUnorm4x8(B); - vec4 rgbaD = unpackUnorm4x8(D); + vec4 rgbaD; + vec4 rgbaX; + // Remove alpha channel weighting + int rgbBl = Bl & 0xFFFFF; + int rgbDl = Dl & 0xFFFFF; + int rgbEl = El & 0xFFFFF; + int rgbFl = Fl & 0xFFFFF; + int rgbHl = Hl & 0xFFFFF; - // Although rules limit B D pixel channel differences to be small. Need to avoid mixing non-transparent black and transparent (black), generating a darker non-transparent color, causing artifacts. - // So when one is transparent, copy the rgb value of the other. - // But with the next step, this becomes redundant. After mixing, the alpha from the lesser side will be used, becoming fully transparent. - //if (rgbaB.a < 0.003) rgbaB.rgb = rgbaD.rgb; - //if (rgbaD.a < 0.003) rgbaD.rgb = rgbaB.rgb; + if (eq_B_D) { + // Exit if sandwiched by straight walls on both sides + if (eq_B_C && eq_D_G) return slopeBAD; + rgbaX = rgbaB; + if ( B != D ) { + float alphaD = float(D >> 24) * 0.0039215686; // 1/255 + rgbaX.a = min(rgbaB.a , alphaD); + } + } else { + // Exit if E-A equality does not meet preset logic + if ( E == A ) return slopeBAD; - // Merge D B into X - vec4 rgbaX = eq_B_D ? rgbaB : mix(rgbaB,rgbaD,0.5); + // If D and B are not equal, and the difference between them is greater than the difference between either one and the center point E, exit. + int diffBD = abs(rgbBl-rgbDl); + int diffEB = abs(rgbEl-rgbBl); + int diffED = abs(rgbEl-rgbDl); + if (diffBD > diffEB || diffBD > diffED) return slopeBAD; - // After mixing, use the alpha from the lesser side to reduce artifacts. - if (rgbaB.a < rgbaX.a ) rgbaX.a = rgbaB.a; - if (rgbaD.a < rgbaX.a ) rgbaX.a = rgbaD.a; - // Practice: Cases exist where both B D sides are fully transparent, and the center point is fully transparent. In such cases, follow the rules to copy. Otherwise, shape will be lost. + // Generate X using the intermediate value of B-D + rgbaD = unpackUnorm4x8(D); + rgbaX = mix(rgbaB,rgbaD,0.5); + // After mixing, use the alpha from the side with less alpha to reduce artifacts. + rgbaX.a = min(rgbaB.a,rgbaD.a); - // Avoid opposite side squeezing when E is at black edge (for fonts with contrast exceeding half) - bool Bisblack = checkblack(rgbaB); - // Cannot use average for X black when BD are not equal - bool Xisblack = eq_B_D ? Bisblack : Bisblack&&checkblack(rgbaD); - //bool Aisblack = checkblack(A); - if (Xisblack && abs((rgbaE.r + rgbaE.g + rgbaE.b) - (rgbaX.r + rgbaX.g + rgbaX.b)) >1.5 ) { + // Although the rules limit the difference between B and D pixels across 4 channels, we still need to avoid mixing non-transparent black and transparent (black) to generate a darker non-transparent color, causing artifacts. + // Alternative: When one is transparent, copy the rgb value of the other. (Not as good as the previous solution) + //if (rgbaB.a < 0.003) rgbaB.rgb = rgbaD.rgb; + //if (rgbaD.a < 0.003) rgbaD.rgb = rgbaB.rgb; + } - if ( checkblack(unpackUnorm4x8(F)) || checkblack(unpackUnorm4x8(H)) ) return theEXIT; + + // Avoid single-pixel font edges being squeezed by black background on both sides (font and background brightness difference usually exceeds 0.5) + // Note: If BD are not equal, cannot use average for judgment, both must satisfy the black condition. + bool Xisblack = eq_B_D ? checkblack(rgbaB) : checkblack(rgbaB)&&checkblack(rgbaD); + if ( Xisblack && rgbEl > 127500 ) { // 127500/255000 = 0.5/1 + // Use Fl Hl to save cost + if ( rgbFl<19890 || rgbHl<19890 ) return theEXIT; // 19890/255000 = 0.078/1 } //Pre-declare @@ -324,171 +327,198 @@ vec4 admixX(uint A, uint B, uint C, uint D, uint E, uint F, uint G, uint H, uint bool eq_B_P; bool eq_B_PA; bool eq_B_PC; bool eq_D_Q; bool eq_D_QA; bool eq_D_QG; bool eq_E_F; bool eq_E_H; bool eq_E_I; bool En3; bool En4square; - bool linkB1; bool linkB2; bool linkD1; bool linkD2; - bool BDlong; bool DBlong; + bool B_slope; bool B_tower; bool B_wall; + bool D_slope; bool D_tower; bool D_wall; bool comboA3; bool mixok; - //pre-cal - bool eq_E_A = eq(E,A); - // B != D if (!eq_B_D){ - // Exit if it doesn't meet preset logic - if (eq_E_A) return slopeBAD; - eq_A_B = eq(A,B); eq_A_D = eq(A,D); - // B D are not equal (non-black), one side is straight line, the other must be single pixel. - // Practice: Avoids mixing at corners of parallel lines where BD are each continuous. + // If B and D are not equal (and not black), and one side is a straight line, the other side must be a single pixel. + // Practice: Prevents mixing at corners of parallel lines where B and D are each continuous. if (!Xisblack){ if ( eq_A_B && (eq_D_G||eq(D,Q)) ) return slopeBAD; if ( eq_A_D && (eq_B_C||eq(B,P)) ) return slopeBAD; } - // When D B are not equal, and their rgb difference is large, greater than either side's difference with the center, exit. - vec3 rgbE = rgbaE.rgb; - vec3 rgbB = rgbaB.rgb; - vec3 rgbD = rgbaD.rgb; - vec3 diffBD = rgbB - rgbD; - vec3 diffEB = rgbE - rgbB; - vec3 diffED = rgbE - rgbD; - float distBD = dot(diffBD,diffBD); - if (distBD > dot(diffEB,diffEB) || distBD > dot(diffED,diffED)) return slopeBAD; - // B D not connected? Not applicable here (Can eliminate some faults, but also lose some shapes, especially in non-native pixel art, e.g., Double Dragon character portraits) + // B D not connected to anything? Not applicable here (Can eliminate some artifacts, but also loses some shapes, especially in non-native pixel art, e.g., character portraits in Double Dragon) - // Treat black-like the same as DB? - // Practice: Special treatment for black not applicable,Easily causes burrs in dark areas (Samurai Shodown 2 Charlotte) - //if (Xisblack) return X +slopEND; - - eq_A_P = eq(A,P); - eq_A_Q = eq(A,Q); - comboA3 = eq_A_P && eq_A_Q; - mixok = mixcheck(rgbaX, rgbaE); - - // A-side three-star alignment, high priority - if (comboA3) return mixok ? mix(rgbaX,rgbaE,0.381966) +slopEND : rgbaX +slopEND; - - // Official original rule - if ( eq(E,C) || eq(E,G) ) return mixok ? mix(rgbaX,rgbaE,0.381966) +slopEND : rgbaX +slopEND; - // Enhanced original rule Practice: Beneficial for non-native pixel art, but harmful for native pixel art (JoJo's wall and clock) - // if (sim_EC && sim_EG) return mixok ? mix(X,E,0.381966) +slopEND : X +slopEND; - - eq_E_F = eq(E, F); - eq_E_H = eq(E, H); - En3 = eq_E_F && eq_E_H; - - if (En3) return mixok ? mix(rgbaX,rgbaE,0.381966) +slopEND : rgbaX +slopEND; - // Exclude "single stick" situation, including eq_E_I bent stick situation - if ( eq_E_F || eq_E_H ) return slopeBAD; - // Exclude "three-grid single-side wall" situation - if ( eq_A_B&&eq_B_C || eq_A_D&&eq_D_G ) return slopeBAD; - // F-H inline trend, placed after the three-grid single-side wall rule as it might be blocked by it. - if ( eq(F,H) ) return mixok ? mix(rgbaX,rgbaE,0.381966) +slopEND : rgbaX +slopEND; - // Exclude "two-grid single-side wall" situation, merged with next rule - //if (eq_A_B||eq_A_D) return slopeBAD; - // The rest are single pixels within sim2 range that are similar but have no logic, so use weak mixing??? Just give up! - return slopeBAD; -} // B != D - - //pre-cal B == D - bool eq_E_C = eq(E,C); - bool eq_E_G = eq(E,G); - bool sim_EC = eq_E_C || vec4_sim2(rgbaE, unpackUnorm4x8(C)); - bool sim_EG = eq_E_G || vec4_sim2(rgbaE, unpackUnorm4x8(G)); - - bool ThickBorder; - uint X = B; -// Original main rule enhanced with sim -if ( (sim_EC || sim_EG) && !eq_E_A ){ - - eq_A_B = eq(A,B); - eq_B_P = eq(B,P); - eq_B_PC = eq(B,PC); - eq_D_Q = eq(D,Q); - eq_D_QG = eq(D,QG); - - linkB1 = eq_B_PC; - linkB2 = eq_B_P; - linkD1 = eq_D_QG; - linkD2 = eq_D_Q; - - // B + D + their respective extension forms, highest priority. Initial screening. - // Practice: Need to add the !eq_A_B case (E side is continuous step edge, opposite side is black background) - if ( (linkB1||linkB2)&&!eq_B_C && (linkD1||linkD2)&&!eq_D_G && !eq_A_B ) return rgbaX +slopEND; + // Treat near-black like DB? + // Practice: Special treatment for non-black in dark areas can easily cause artifacts (Samurai Shodown 2 Charlotte) + //if (Xisblack) return rgbaX +slopEND; eq_A_P = eq(A,P); eq_A_Q = eq(A,Q); comboA3 = eq_A_P && eq_A_Q; mixok = mixcheck(rgbaX,rgbaE); - // A-side three-star alignment, high priority - if (comboA3) { - // Copy directly if not border - if (!eq_A_B) return rgbaX + slopEND; - // Disable mixing at border - mixok=false; - } - - // When A-side is border, and A has a support on the diagonal (has thickness), copy without mixing. - // Without thickness detection, if D B A are the same and copy, it will increase thickness at the edge,It disrupts the original design aesthetic. - // Exclude black, overly thick black borders affect appearance. Keep some transition near black edges,Add scan lines later for better layering. - ThickBorder = eq_A_B && (eq_A_P||eq_A_Q|| eq(A,AA)&&(eq(B,PA)||eq(D,QA))); - if (ThickBorder && !Xisblack) mixok=false; + // A-side three in a row, high priority + if (comboA3) return mixok ? mix(rgbaX,rgbaE,0.381966) +slopEND : rgbaX +slopEND; // Official original rule + if ( eq(E,C) || eq(E,G) ) return mixok ? mix(rgbaX,rgbaE,0.381966) +slopEND : rgbaX +slopEND; + // Enhanced original rule Practice: Beneficial for non-native pixel art, but harmful for native pixel art (JoJo's wall and clock) + // if (sim_EC && sim_EG) return mixok ? mix(rgbaX,rgbaE,0.381966) +slopEND : rgbaX +slopEND; + + eq_E_F = eq(E, F); + eq_E_H = eq(E, H); + En3 = eq_E_F && eq_E_H; + + if (En3) return mixok ? mix(rgbaX,rgbaE,0.381966) +slopEND : rgbaX +slopEND; + // Exclude "single stick" situations, including eq_E_I single bent stick + if ( eq_E_F || eq_E_H ) return theEXIT; + // Exclude "three-cell single-side wall" situations + if ( eq_A_B&&eq_B_C || eq_A_D&&eq_D_G ) return slopeBAD; + // F-H inline trend, placed after the three-cell single-side wall rule as it might be blocked by it + if ( eq(F,H) ) return mixok ? mix(rgbaX,rgbaE,0.381966) +slopEND : rgbaX +slopEND; + // Exclude "two-cell single-side wall" situations, merged with next rule + //if (eq_A_B||eq_A_D) return slopeBAD; + // The rest are single pixels without logic but similar within sim2 range, so use weak mixing??? Just give up! + return slopeBAD; +} // B != D + + //pre-cal B == D + bool eq_E_A = eq(E,A); + bool eq_E_C = eq(E,C); + bool eq_E_G = eq(E,G); + bool sim_EC = eq_E_C || v4i_sim2(rgbaE,C); + bool sim_EG = eq_E_G || v4i_sim2(rgbaE,G); + + bool ThickBorder; + +// Enhanced original main rule using sim +if ( (sim_EC || sim_EG) && !eq_E_A ){ + +/* Approach: + 1. Handle continuous boundary shapes without mixing + 2. Special handling for long slopes + 3. Original rules + 4. Handle E-zone inlines like En4 En3 F-H, leaving single sticks and single pixels + 5. Handle L-shaped inward and outward single sticks + 5. Normal fallback +*/ + + eq_A_B = eq(A,B); + eq_B_P = eq(B,P); + eq_B_PC = eq(B,PC); + eq_D_Q = eq(D,Q); + eq_D_QG = eq(D,QG); + eq_B_PA = eq(B,PA); + eq_D_QA = eq(D,QA); + B_slope = eq_B_PC && !eq_B_P && !eq_B_C; + B_tower = eq_B_P && !eq_B_PC && !eq_B_C && !eq_B_PA; + D_slope = eq_D_QG && !eq_D_Q && !eq_D_G; + D_tower = eq_D_Q && !eq_D_QG && !eq_D_G && !eq_D_QA; + + // step1: + // B + D + their respective extension shapes + // Note: Only used for judging X without mixing, different from the "rule capture return" logic in the final section. + + if ( (B_slope||B_tower) && (D_slope||D_tower) && !eq_A_B) return rgbaX +slopEND; + + + eq_A_P = eq(A, P); + eq_A_Q = eq(A, Q); + comboA3 = eq_A_P && eq_A_Q; + mixok = mixcheck(rgbaX,rgbaE); + ThickBorder = eq_A_B && (eq_A_P||eq_A_Q|| eq(A,AA)&&(eq_B_PA||eq_D_QA)); + if (ThickBorder && !Xisblack) mixok=false; + + // A-side three in a row + if (comboA3) { + if (!eq_A_B) return rgbaX + slopEND; + else mixok=false; + } + + // XE_messL B-D-E L-shape highly similar with sim2 WIP + // bool XE_messL = (eq_B_C && !sim_EG || eq_D_G && !sim_EC) ; + + eq_E_F = eq(E, F); + B_wall = eq_B_C && !eq_B_PC && !eq_B_P; + + // Long slope clear long slope (Not thick solid edge. Strong trend!) + // Long slope case is slightly special, judged separately + if ( B_wall && D_tower ) { + if (eq_E_G || sim_EG&&eq(E,QG) ) { // Original rule + Original enhancement + if (eq_A_B) return mixok ? mix(rgbaX,rgbaE,0.381966): rgbaX; // Has thickness + return rgbaX; // Hollow + } + // Clear Z-shaped snake, exclude XE_messL ??? + //if (eq_A_B && !XE_messL) return slopeBAD; // WIP + if (eq_A_B) return slopeBAD; + // 2-cell with subsequent long slope + if (eq_E_F ) return rgbaX; + // 1-cell without subsequent long slope + return rgbaX +slopEND; + } + + eq_E_H = eq(E, H); + D_wall = eq_D_G && !eq_D_QG&& !eq_D_Q; + + if ( B_tower && D_wall ) { + if (eq_E_C || sim_EC&&eq(E,PC) ) { // Original rule + Original enhancement + if (eq_A_B) return mixok ? mix(rgbaX,rgbaE,0.381966): rgbaX; // Has thickness + return rgbaX; // Hollow + } + if (eq_A_B) return slopeBAD; + // 2-cell with subsequent long slope + if (eq_E_H ) return rgbaX; + // 1-cell without subsequent long slope + return rgbaX +slopEND; + } + + + // Official original rule (placed after the special shapes above, special shapes specify no mixing!) if (eq_E_C || eq_E_G) return mixok ? mix(rgbaX,rgbaE,0.381966) : rgbaX; - // Enhanced original rule - if (sim_EC && sim_EG) return mixok ? mix(rgbaX,rgbaE,0.381966) : rgbaX; - // En3 skip + // Original rule enhancement 1 + if (sim_EG&&!eq_D_G&&eq(E,QG) || sim_EC&&!eq_B_C&&eq(E,PC)) return mixok ? mix(rgbaX,rgbaE,0.381966)+slopEND : rgbaX+slopEND; - // F-H inline trend - if ( eq(F,H) ) return mixok ? mix(rgbaX,rgbaE,0.381966) : rgbaX; + // Original rule enhancement 2 + if (sim_EC && sim_EG) return mixok ? mix(rgbaX,rgbaE,0.381966)+slopEND : rgbaX+slopEND; - // When one side is a wall, besides the official rule and inline trend, the opposite side needs sim, otherwise exit (exclude cases where the wall itself is similar to center E) - if (eq_B_C && !sim_EG) return slopeBAD; - if (eq_D_G && !sim_EC) return slopeBAD; - BDlong = eq_B_C && eq_D_Q; - DBlong = eq_D_G && eq_B_P; - eq_E_F = eq(E,F); - eq_E_H = eq(E,H); - eq_E_I = eq(E,I); + // F-H inline trend (Skip En4 En3) + if ( eq(F,H) ) return mixok ? mix(rgbaX,rgbaE,0.381966)+slopEND : rgbaX+slopEND; + + // Relaxed rule finally cleans up two long slopes (non-clear shapes) + // Practice: This section handles long slopes and is different from F-H. Default is draw, unless it's a cube. + if ( eq_B_C && eq_D_Q) { + // Double cube exit + if (eq_B_P && eq_B_PC && eq_A_B && eq_D_QA && !eq_D_QG && eq_E_F && eq(H,I) ) return theEXIT; - if ( BDlong ) { - if (eq_D_QG) return mixok ? mix(rgbaX,rgbaE,0.381966)+slopEND : rgbaX+slopEND; - if (eq_E_F && !eq_E_I) return mixok ? mix(rgbaX,rgbaE,0.381966) : rgbaX; return mixok ? mix(rgbaX,rgbaE,0.381966)+slopEND : rgbaX+slopEND; - } - - if ( DBlong ) { - if (eq_B_PC) return mixok ? mix(rgbaX,rgbaE,0.381966) +slopEND : rgbaX+slopEND; - if (eq_E_H && !eq_E_I) return mixok ? mix(rgbaX,rgbaE,0.381966) : rgbaX; - return mixok ? mix(rgbaX,rgbaE,0.381966) +slopEND : rgbaX+slopEND; - } - - // Use A-side three-star alignment again to return faster. - if (comboA3) return rgbaX +slopEND; - - // Use B + D + their respective extensions again, priority higher than L + single stick below - if ( (linkB1 || linkB2) && (linkD1 || linkD2) ) return mixok ? mix(rgbaX,rgbaE,0.381966) +slopEND : rgbaX +slopEND; - - // X E Lv3 similarity can ignore the next two exit rules - if ( vec4_sim3(rgbaX,rgbaE) ) return mixok ? mix(rgbaX,rgbaE,0.381966) +slopEND : rgbaX +slopEND; - - // L-shaped corner (hollow) with an internal stick, exit - if (eq_A_B && !ThickBorder && !eq_E_I) { - if (eq_B_C && eq_E_F) return theEXIT; - if (eq_D_G && eq_E_H) return theEXIT; } - // L-shaped corner (hollow) with an external stick, exit (connect inside corner, not outside) - // Practice: Can avoid font edges being shaved (Captain Commando) - if ( (linkB2 || linkD2) && (eq_E_F||eq_E_H) && !ThickBorder && !eq_E_I) return theEXIT; + if ( eq_D_G && eq_B_P) { + // Double cube exit + if (eq_D_Q && eq_D_QG && eq_A_B && eq_B_PA && !eq_B_PC && eq_E_H && eq(F,I) ) return theEXIT; + return mixok ? mix(rgbaX,rgbaE,0.381966)+slopEND : rgbaX+slopEND; + } + + eq_E_I = eq(E, I); + + // L-shaped corner (clear) inward single stick (parallel), exit + if (eq_A_B && !ThickBorder && !eq_E_I ) { + if (B_wall && eq_E_F) return theEXIT; + if (D_wall && eq_E_H) return theEXIT; + } + + // Skip next step and return early if colors are similar + if (mixok) return mix(rgbaX,rgbaE,0.381966)+slopEND; + + // L-shaped corner (hollow) outward single stick (any direction), exit (solves font edge issues) + if ( !eq_A_B && (eq_E_F||eq_E_H) && !eq_E_I) { + if (B_tower && !eq_D_Q && !eq_D_QG) return theEXIT; + if (D_tower && !eq_B_P && !eq_B_PC) return theEXIT; + } + + // Fallback processing return mixok ? mix(rgbaX,rgbaE,0.381966)+slopEND : rgbaX+slopEND; } // sim2 base @@ -500,16 +530,13 @@ if ( (sim_EC || sim_EG) && !eq_E_A ){ if (eq_E_A) { - // When judging cross ✕, need concepts of "region" and "trend". Conditions need tightening for different regions. + // When judging crosses ✕, have a concept of "area" and "trend". Conditions need tightening for different areas. - // B D not connected exit? Not needed here!!! - // Sometimes connecting two separate pixels looks abrupt. But in many cases, shapes are lost! - //if ( !eq_B_C && !eq_B_P && !eq_B_PC && !eq_D_G && !eq_D_Q && !eq_D_QG ) return slopeBAD; + // B D not connected to anything exit? Not needed here!!! - // X fully transparent exit (Using transparent B D to cut the crossing E A doesn't make logical sense for slope) + // X fully transparent exit (slope transparent B D cutting the crossing E A doesn't make logical sense) bool X_alpha0 = rgbaX.a < 0.003; if (X_alpha0) return slopeBAD; - //if (E_alpha0) return testcolor; eq_E_F = eq(E, F); eq_E_H = eq(E, H); @@ -517,47 +544,43 @@ if (eq_E_A) { En3 = eq_E_F&&eq_E_H; En4square = En3 && eq_E_I; - // Special form: Square + // Special shape: Square if ( En4square ) { - if( noteq(G,H) && noteq(C,F) // Independent clear 4-grid square / 6-grid rectangle (both sides satisfied) + if( noteq(G,H) && noteq(C,F) // Independent clear 4-cell square / 6-cell rectangle (both sides satisfy simultaneously) && (eq(H,S) == eq(I,SI) && eq(F,R) == eq(I,RI)) ) return theEXIT; - //else return mixok ? mix(rgbaX,rgbaE,0.381966) : rgbaX; Note: Cannot return directly. Need to enter the board decision rule, because the opposite shore might also be a square forming a bubble. + //else return mixok ? mix(rgbaX,rgbaE,0.381966) : rgbaX; Note: Cannot return directly. Need to enter the chessboard decision rule because adjacent B, D areas might also form bubbles with square structures. } - // Special form: Halftone dot - // Practice 1: !eq_E_F, !eq_E_H not using !sim, because it loses some shapes. - // Practice 2: Force mixing, otherwise shapes are lost. (Gouketsuji Ichizoku Matrimelee, WWF Super WrestleMania) + // Special shape: Dithering pattern + // Practice 1: !eq_E_F, !eq_E_H Not using !sim, because it loses some shapes. + // Practice 2: Force mixing, otherwise shapes are lost. (Gouketsuji horse, WWF Super Wrestlemania 2) bool Eisblack = checkblack(rgbaE); mixok = mixcheck(rgbaX,rgbaE); - // 1. Halftone dot center + // 1. Dithering center if ( eq_E_C && eq_E_G && eq_E_I && !eq_E_F && !eq_E_H ) { // Exit if center E is black (KOF96 power gauge, Punisher's belt) Avoid mixing with too high contrast. if (Eisblack) return theEXIT; + // Example of dithering created by changing transparency against same-color background: Black Rock Shooter if ( rgb_eq(rgbaX,rgbaE) ) return slopeBAD; - // Practice 1: Cannot catch black B point, B points entering here all satisfy the form. - //if (Xisblack) return testcolor2; - // Option 1 Layered五花肉 (eq_F_H occurrence 95%) + progressive layering inside health bar, remaining 0.5 fallback mixing. - // if (eq_F_H) return mixok ? mix(rgbaX, rgbaE, 0.381966)+slopEND : mix(rgbaX, rgbaE, 0.618034)+slopEND; - // return mix(rgbaX, rgbaE, 0.5)+slopEND; - // Final decision: unify it. + return mixok ? mix(rgbaX, rgbaE, 0.381966)+slopEND : mix(rgbaX, rgbaE, 0.618034)+slopEND; } -//return testcolor; + eq_A_P = eq(A,P); eq_A_Q = eq(A,Q); eq_B_PA = eq(B,PA); - // 2. Halftone dot edge + // 2. Dithering edge if ( eq_A_P && eq_A_Q && eq(A,AA) && noteq(A,PA) && noteq(A,QA) ) { if (Eisblack) return theEXIT; - // Layered progressive edge, use strong mixing. + // Layered progressive edge, use strong mixing if ( !eq_B_PA && eq(PA,QA) ) return mixok ? mix(rgbaX, rgbaE, 0.381966)+slopEND : mix(rgbaX, rgbaE, 0.618034)+slopEND; - // Remaining 1. Perfect cross, must be halftone dot edge, use weak mixing. - // Remaining 2. Fallback weak mixing. + // Remaining 1. Perfect cross, must be dithering edge, use weak mixing. + // Remaining 2. Fallback weak mixing return mixok ? mix(rgbaX, rgbaE, 0.618034)+slopEND : mix(rgbaX, rgbaE, 0.8541)+slopEND; // Note: No need to specify health bar border separately. } @@ -566,16 +589,15 @@ if (eq_E_A) { eq_D_QG = eq(D,QG); eq_B_PC = eq(B,PC); - // 3. Half halftone Usually shadow expression on contour edges, use weak mixing. + // 3. Half dithering Usually shadow expression on contour edges, use weak mixing if ( eq_E_C && eq_E_G && eq_A_P && eq_A_Q && (eq_B_PC || eq_D_QG) && eq_D_QA && eq_B_PA) { - //if (Eisblack) return testcolor; return mixok ? mix(rgbaX, rgbaE, 0.618034)+slopEND : mix(rgbaX, rgbaE, 0.8541)+slopEND; } - // 4. Quarter halftone (ugly pinky finger effect) + // 4. Quarter dithering, prone to ugly little finger effect if ( eq_E_C && eq_E_G && eq_A_P && eq_B_PA &&eq_D_QA && eq_D_QG @@ -588,32 +610,32 @@ if (eq_E_A) { ) return mixok ? mix(rgbaX, rgbaE, 0.618034)+slopEND : mix(rgbaX, rgbaE, 0.8541)+slopEND; - // E-side three-star alignment (Must be after halftone) + // E-side three in a row (Must be after dithering) if ( eq_E_C && eq_E_G ) return rgbaX+slopEND; comboA3 = eq_A_P && eq_A_Q; - // A-side three-star alignment (Must be after halftone) Since E-A are same, prefer mixing over direct copying. + // A-side three in a row (Must be after dithering) Because E-A are the same, prefer mixing over direct copy. if (comboA3) return mixok ? mix(rgbaX, rgbaE, 0.381966)+slopEND : rgbaX+slopEND; - // B-D part of long slope + // B-D part of long slope eq_B_P = eq(B,P); eq_D_Q = eq(D,Q); - bool B_hori = eq_B_C && !eq_B_P; - bool B_vert = eq_B_P && !eq_B_C; - bool D_hori = eq_D_Q && !eq_D_G; - bool D_vert = eq_D_G && !eq_D_Q; + B_wall = eq_B_C && !eq_B_P; + B_tower = eq_B_P && !eq_B_C; + D_tower = eq_D_Q && !eq_D_G; + D_wall = eq_D_G && !eq_D_Q; int scoreE = 0; int scoreB = 0; int scoreD = 0; int scoreZ = 0; -// E B D region board scoring rule +// E B D area chessboard scoring rule -// E Zone +// E Zone if (En3) { scoreE += 1; - if (B_hori || B_vert || D_hori || D_vert) scoreZ = 1; + if (B_wall || B_tower || D_tower || D_wall) scoreZ = 1; } if (eq_E_C) { @@ -634,14 +656,14 @@ if (eq_E_A) { if ( eq(F,H) ) { scoreE += 1; - if ( scoreZ==0 && B_hori && (eq(F,R) || eq(G,H) || eq(F,I)) ) scoreZ = 1; - if ( scoreZ==0 && D_vert && (eq(C,F) || eq(H,S) || eq(F,I)) ) scoreZ = 1; + if ( scoreZ==0 && B_wall && (eq(F,R) || eq(G,H) || eq(F,I)) ) scoreZ = 1; + if ( scoreZ==0 && D_wall && (eq(C,F) || eq(H,S) || eq(F,I)) ) scoreZ = 1; } bool Bn3 = eq_B_P&&eq_B_C; bool Dn3 = eq_D_G&&eq_D_Q; -// B Zone +// B Zone scoreB -= int(Bn3); scoreB -= int(eq(C,P)); if (scoreB < 0) scoreZ = 0; @@ -651,7 +673,7 @@ if (eq_E_A) { scoreB -= int(eq(P,PA)); } -// D Zone +// D Zone scoreD -= int(Dn3); scoreD -= int(eq(G,Q)); if (scoreD < 0) scoreZ = 0; @@ -669,10 +691,10 @@ if (eq_E_A) { if (scoreFinal == 1) return mixok ? mix(rgbaX,rgbaE,0.381966) : rgbaX; - // Final addition: If total score is zero, and B, D zones have no deductions, forming a long slope shape. + // Final supplement: Total score zero, and B, D zones have no deductions, forming a long slope shape. if (scoreB >= 0 && scoreD >=0) { - if (B_hori&&D_hori) return rgbaX; - if (B_vert&&D_vert) return rgbaX; + if (B_wall&&D_tower) return rgbaX; + if (B_tower&&D_wall) return rgbaX; } return slopeBAD; @@ -683,176 +705,266 @@ if (eq_E_A) { /*========================================================= F - H / -B - D- Extension New Rules - ==================================================== zz*/ + ==================================================== zz */ -// This side is different from the sim side. Since the inner pixels mostly have high contrast with the surroundings and are not sim. -// Sometimes it's more like the opposite side of sim, with B-D as the boundary, so the judgment rules are different from the sim side. +// This section is different from the sim section. The center point and related En4square and BD logic naturally have a wall separating them. +// Judgment rules are different from the sim side. eq_B_P = eq(B, P); eq_B_PC = eq(B, PC); eq_D_Q = eq(D, Q); eq_D_QG = eq(D, QG); - // B D not connected exit (Practice: Indeed needed) + // B D not connected to anything exit (Practice: This branch section needs it) if ( !eq_B_C && !eq_B_P && !eq_B_PC && !eq_D_G && !eq_D_Q && !eq_D_QG ) return slopeBAD; + mixok = mixcheck(rgbaX,rgbaE); + eq_E_I = eq(E, I); + + // Exit if center point E is a high-contrast pixel, visually very different from surrounding pixels. + int E_lumDiff = rgbEl>234600 ? 37204 : 97401; // 234600/255000=0.92/1 37204=0.145898/1 97401=0.382/1 + bool E_ally = mixok || abs(rgbEl-rgbFl)127500) && (eq_H_S == eq(I, SI) && eq_F_R == eq(I, RI)) ) return theEXIT; + + return mixok ? mix(rgbaX,rgbaE,0.381966)+slopEND : rgbaX+slopEND; } - // Triangle + // Wall enclosed triangle if ( En3 ) { - if (sim_X_E) return mixok ? mix(rgbaX,rgbaE,0.381966) : rgbaX; - - if (eq_H_S && eq_F_R) return theEXIT; // Both sides extended simultaneously (building edge) - - if (eq_A_B) return mixok ? mix(rgbaX,rgbaE,0.381966) : rgbaX; - // Inner bend - if (eq_B_C || eq_D_G) return mixok ? mix(rgbaX,rgbaE,0.381966) : rgbaX; + if (sim_X_E) return mixok ? mix(rgbaX,rgbaE,0.381966)+slopEND : rgbaX+slopEND; + if (eq_H_S && eq_F_R) return theEXIT; // Both sides extend simultaneously (building edges) + // Inner bend + if (eq_B_C || eq_D_G) return mixok ? mix(rgbaX,rgbaE,0.381966)+slopEND : rgbaX+slopEND; + // Return directly if has thickness (Z-shaped snake can flatten the outer bend below) + if (eq_A_B) return mixok ? mix(rgbaX,rgbaE,0.381966)+slopEND : rgbaX+slopEND; // Outer bend if (eq_B_P || eq_D_Q) return theEXIT; - return mixok ? mix(rgbaX,rgbaE,0.381966) : rgbaX; - // Last two rules based on experience, principle: Connect L inner bend, not L outer bend (Double Dragon Jimmy's eyebrows) + return mixok ? mix(rgbaX,rgbaE,0.381966)+slopEND : rgbaX+slopEND; + // The last two rules are based on experience. Principle: Connect L inner bend, do not connect L outer bend (Double Dragon Jimmy's eyebrow) } // F - H - // Principle: Connect L inner bend, not L outer bend. - // Practice: E single pixel should not use subsequent long slopes. + // Principle: Connect L inner bend, do not connect L outer bend if ( eq(F,H) ) { if (sim_X_E) return mixok ? mix(rgbaX,rgbaE,0.381966)+slopEND : rgbaX+slopEND; - // Avoid bilateral symmetric full clamping squeezing single pixel. - if ( eq_B_C && eq_A_B && eq_G_H &&eq(F, I) ) return theEXIT; - if ( eq_D_G && eq_A_B && eq_C_F &&eq(F, I) ) return theEXIT; + // Solid L enclosed, avoid bilateral symmetric full enclosure squeezing single pixel + if ( eq_B_C && eq_A_B && (eq_G_H||!eq_F_R) &&eq(F, I) ) return slopeBAD; + if ( eq_D_G && eq_A_B && (eq_C_F||!eq_H_S) &&eq(F, I) ) return slopeBAD; + //Inner bend if (eq_B_C && (eq_F_R||eq_G_H||eq(F, I))) return mixok ? mix(rgbaX,rgbaE,0.381966)+slopEND : rgbaX+slopEND; if (eq_D_G && (eq_C_F||eq_H_S||eq(F, I))) return mixok ? mix(rgbaX,rgbaE,0.381966)+slopEND : rgbaX+slopEND; - // E-I F-H cross破坏趋势 + // E-I F-H cross破坏 trend if (eq_E_I) return slopeBAD; - // Z-shape outer + // Z-shaped outer if (eq_B_P && eq_A_B) return mixok ? mix(rgbaX,rgbaE,0.381966)+slopEND : rgbaX+slopEND; if (eq_D_Q && eq_A_B) return mixok ? mix(rgbaX,rgbaE,0.381966)+slopEND : rgbaX+slopEND; - // Outer bend unless the opposite side forms a long L-shape trend. + // Outer bend unless the opposite side forms a long L-shaped trend if (eq_B_P && (eq_C_F&&eq_H_S)) return mixok ? mix(rgbaX,rgbaE,0.381966)+slopEND : rgbaX+slopEND; if (eq_D_Q && (eq_F_R&&eq_G_H)) return mixok ? mix(rgbaX,rgbaE,0.381966)+slopEND : rgbaX+slopEND; return slopeBAD; } - BDlong = eq_B_C && eq_D_Q; - DBlong = eq_D_G && eq_B_P; -// Clear out two long slopes (Long slopes not caught by simE2 rule, cannot use here!) - if ( BDlong ) { - if (eq_D_QG) return mixok ? mix(rgbaX,rgbaE,0.381966)+slopEND : rgbaX+slopEND; - return theEXIT; - } - if ( DBlong ) { - if (eq_B_PC) return mixok ? mix(rgbaX,rgbaE,0.381966)+slopEND : rgbaX+slopEND; - return theEXIT; - } - // Use A-side three-star alignment again to return faster. - if (comboA3) return rgbaX+slopEND; - - // Can X E similarity override all rules below and return directly??? - if (sim_X_E) return mixok ? mix(rgbaX,rgbaE,0.381966) : rgbaX; - - // Use B + D + their respective extensions again, priority higher than L + single stick below. - if ( (linkB1 || linkB2) && (linkD1 || linkD2) ) return mixok ? mix(rgbaX,rgbaE,0.381966) +slopEND : rgbaX +slopEND; - - // L-shaped corner (hollow) with an internal stick, exit. - if (eq_A_B && !eq_E_I) { - - if (eq_B_C && eq_E_F) return theEXIT; - if (eq_D_G && eq_E_H) return theEXIT; + // Relaxed rule finally cleans up two long slopes (non-clear shapes) + // Note: This section handles long slopes differently from the sim2 section. Solid corners exit. + if ( eq_B_C && eq_D_Q || eq_D_G && eq_B_P) { + // Note: Must clear eq_A_B first, otherwise edge single pixels will be chipped away (Everlasting Secret) + if (eq_A_B) return theEXIT; + return mixok ? mix(rgbaX,rgbaE,0.381966)+slopEND : rgbaX+slopEND; } - // L-shaped corner (hollow) with an external stick, exit (connect inside corner, not outside) - // Practice: Can avoid font edges being shaved (Captain Commando) - if ( (linkB2 || linkD2) && (eq_E_F||eq_E_H) && !eq_E_I) return theEXIT; - // Finally use B or D extension rule to filter, tighten the rule. - linkB1 = eq_B_PC && !eq_B_C && (!eq_C_F||eq(F,RC)); - linkD1 = eq_D_QG && !eq_D_G && (!eq_G_H||eq(H,SG)); + // A-side three in a row, MUST NOT be used separately without !eq_A_B !!!!!!!!!!!! + // if (comboA3) return rgbaX+slopEND; - if ( (linkB1 || linkD1 )&& !eq_A_B ) return mixok ? mix(rgbaX,rgbaE,0.381966)+slopEND : rgbaX+slopEND; - return slopeBAD; + // Use B + D bidirectional extension to capture once more, priority higher than L inner/outer single stick below. + if ( (B_slope||B_tower) && (eq_D_QG&&!eq_D_G||D_tower) ) return rgbaX +slopEND; + if ( (D_slope||D_tower) && (eq_B_PC&&!eq_B_C||B_tower) ) return rgbaX +slopEND; + + + // L-shaped corner (clear) inward single stick, exit + if (eq_A_B && !ThickBorder && !eq_E_I ) { + + if (B_wall && eq_E_F) return theEXIT; + if (D_wall && eq_E_H) return theEXIT; + } + + + // L-shaped corner (hollow) outward single stick, exit (Connect inside corner, not outside corner) + // Practice: Can prevent font edges from being shaved (Captain Commando) + if ( (B_tower || D_tower) && (eq_E_F||eq_E_H) && !eq_A_B && !eq_E_I) return theEXIT; + + // Final B or D individual extension judgment + + // Farthest distance a slope can utilize + if ( B_slope && eq(PC,CC) && noteq(PC,RC) && !eq_A_B) return mixok ? mix(rgbaX,rgbaE,0.381966)+slopEND : rgbaX+slopEND; + if ( D_slope && eq(QG,GG) && noteq(QG,SG) && !eq_A_B) return mixok ? mix(rgbaX,rgbaE,0.381966)+slopEND : rgbaX+slopEND; + + // With X E being close, the slope can have one less judgment point, and some restrictions internally. + if ( mixok && !eq_A_B ) { + if ( B_slope && (!eq_C_F||eq(F,RC)) ) return mix(rgbaX,rgbaE,0.381966)+slopEND; + if ( D_slope && (!eq_G_H||eq(H,SG)) ) return mix(rgbaX,rgbaE,0.381966)+slopEND; + } + + // Tower type relax eq_A_B to form Z-shaped snake, and one side can be wall, slope. But the other side cannot be tower and wall (naturally forbidden) + if ( eq_B_P && !eq_B_PA && !eq_D_Q && eq_A_B) return mixok ? mix(rgbaX,rgbaE,0.381966)+slopEND : rgbaX+slopEND; + if ( eq_D_Q && !eq_D_QA && !eq_B_P && eq_A_B) return mixok ? mix(rgbaX,rgbaE,0.381966)+slopEND : rgbaX+slopEND; + + return theEXIT; } // admixX +vec4 admixS(uint A, uint B, uint C, uint D, uint E, uint F, uint G, uint H, uint I, uint R, uint RC, uint RI, uint S, uint SG, uint SI, uint II, bool eq_B_D, bool eq_E_D, int El, int Bl, vec4 rgbaE) { + + // A B C . + // Q D 🄴 🅵 🆁 Zone 4 + // 🅶 🅷 I + // S + int rgbBl = Bl & 0xFFFFF; + int rgbEl = El & 0xFFFFF; + + if (any_eq2(F,C,I)) return rgbaE; + + if (eq(R, RI) && !eq(R,I)) return rgbaE; + if (eq(H, S) && !eq(H,I)) return rgbaE; + + if ( eq(R, RC) || eq(G,SG) ) return rgbaE; + // 97401/255000 = 0.382/1 + if ( ( eq_B_D&&eq(B,C)&&abs(rgbEl-rgbBl)<97401 || eq_E_D&&v4i_sim2(rgbaE,C) ) && + (any_eq3(I,H,S,RI) || eq(SI,RI)&¬eq(I,II)) ) return unpackUnorm4x8(F); + + return rgbaE; +} + void applyScaling(uvec2 xy) { int srcX = int(xy.x); int srcY = int(xy.y); - uint A = src(srcX - 1, srcY - 1), B = src(srcX, srcY - 1), C = src(srcX + 1, srcY - 1); uint D = src(srcX - 1, srcY + 0), E = src(srcX, srcY + 0), F = src(srcX + 1, srcY + 0); - uint G = src(srcX - 1, srcY + 1), H = src(srcX, srcY + 1), I = src(srcX + 1, srcY + 1); - - // Predefine default output for easy conditional returns. + // Predefine default output for easy conditional return later ivec2 destXY = ivec2(xy) * 2; vec4 rgbaE = unpackUnorm4x8(E); vec4 J = rgbaE, K = rgbaE, L = rgbaE, M = rgbaE; - bool eq_E_B = eq(E,B); - bool eq_E_D = eq(E,D); - bool eq_E_F = eq(E,F); - bool eq_E_H = eq(E,H); - -// New skip acceleration, skip if three consecutive horizontal or vertical pixels are equal. -if ( !(eq_E_D && eq_E_F) && !(eq_E_B && eq_E_H) ) { + bool eq_E_D = eq(E,D); + bool eq_E_F = eq(E,F); - uint P = src(srcX, srcY - 2), S = src(srcX, srcY + 2); - uint Q = src(srcX - 2, srcY), R = src(srcX + 2, srcY); - uint Bl = luma(B), Dl = luma(D), El = luma(E), Fl = luma(F), Hl = luma(H); +// Skip same-color horizontal 3x1 block +if ( eq_E_D && eq_E_F ) { + writeColorf(destXY, J); + writeColorf(destXY + ivec2(1, 0), K); + writeColorf(destXY + ivec2(0, 1), L); + writeColorf(destXY + ivec2(1, 1), M); + return; +} -// Extend to 5x5 + uint B = src(srcX, srcY - 1), H = src(srcX, srcY + 1); + bool eq_E_B = eq(E,B); + bool eq_E_H = eq(E,H); + +// Skip same-color vertical 3x1 block +if ( eq_E_B && eq_E_H ) { + writeColorf(destXY, J); + writeColorf(destXY + ivec2(1, 0), K); + writeColorf(destXY + ivec2(0, 1), L); + writeColorf(destXY + ivec2(1, 1), M); + return; +} + + bool eq_B_H = eq(B,H); + bool eq_D_F = eq(D,F); + +// Skip mirrored block surrounding center point +if ( eq_B_H && eq_D_F ) { + writeColorf(destXY, J); + writeColorf(destXY + ivec2(1, 0), K); + writeColorf(destXY + ivec2(0, 1), L); + writeColorf(destXY + ivec2(1, 1), M); + return; +} + + uint A = src(srcX - 1, srcY - 1), C = src(srcX + 1, srcY - 1); + uint G = src(srcX - 1, srcY + 1), I = src(srcX + 1, srcY + 1); + + uint P = src(srcX, srcY - 2), S = src(srcX, srcY + 2); + uint Q = src(srcX - 2, srcY), R = src(srcX + 2, srcY); + + int Bl = luma(B), Dl = luma(D), El = luma(E), Fl = luma(F), Hl = luma(H); + +// Continue expanding to 5x5 uint PA = src(srcX-1, srcY-2); uint PC = src(srcX+1, srcY-2); uint QA = src(srcX-2, srcY-1); @@ -867,24 +979,27 @@ if ( !(eq_E_D && eq_E_F) && !(eq_E_B && eq_E_H) ) { uint II = src(srcX+2, srcY+2); // GG SG [S] SI II +// 1:1 slope rules (P95) + // main slops bool eq_B_D = eq(B,D); bool eq_B_F = eq(B,F); bool eq_D_H = eq(D,H); bool eq_F_H = eq(F,H); - // other side - bool eq_B_H = eq(B,H); - bool eq_D_F = eq(D,F); - -// 1:1 slope rules (P95) - + // Any mirrored block surrounding center point + bool oppoPix = eq_B_H || eq_D_F; + // Flag indicating entry into adminxX function if caught by 1:1 slope rule + bool slope1 = false; bool slope2 = false; bool slope3 = false; bool slope4 = false; + // Standard pixel that successfully passed the 1:1 slope rule and returned normally + bool slope1ok = false; bool slope2ok = false; bool slope3ok = false; bool slope4ok = false; + // slopeBAD entered adminxX, but (at least one of JKLM) returned E point bool slopeBAD = false; bool slopEND = false; -// .------------------- 1st ---------------------. .---- New ----. .-------- 3rd ----------. .~~~~~New Pocket Rule------ 4th ------------. .------------------------ 5th ----------------------------. + // B - D - bool slope1 = false; - if ( (!eq_E_B&&!eq_E_D) && (!eq_D_H&&!eq_D_F && !eq_B_H&&!eq_B_F) && (El>=Dl&&El>=Bl || eq(E,A)) && ( (El=Dl&&El>=Bl || eq(E,A)) && ( (El 1.0 ) { if (J.b > 30.0 ) {J=J-33.0; slopEND=true;} if (J.b == 8.0 ) { @@ -896,12 +1011,12 @@ if ( !(eq_E_D && eq_E_F) && !(eq_E_B && eq_E_H) ) { return; } if (J.b == 2.0 ) {slopeBAD=true; J=rgbaE;} - } else slope1 = true; + } else slope1ok = true; } // B - F - bool slope2 = false; - if ( (!eq_E_B&&!eq_E_F) && (!eq_B_D&&!eq_B_H && !eq_D_F&&!eq_F_H) && (El>=Bl&&El>=Fl || eq(E,C)) && ( (El=Bl&&El>=Fl || eq(E,C)) && ( (El 1.0 ) { if (K.b > 30.0 ) {K=K-33.0; slopEND=true;} if (K.b == 8.0 ) { @@ -913,12 +1028,12 @@ if ( !(eq_E_D && eq_E_F) && !(eq_E_B && eq_E_H) ) { return; } if (K.b == 2.0 ) {slopeBAD=true; K=rgbaE;} - } else {slope2 = true;slopeBAD = false;} + } else {slope2ok = true;} } // D - H - bool slope3 = slope1; - if ( !slope1 && (!eq_E_D&&!eq_E_H) && (!eq_F_H&&!eq_B_H && !eq_D_F&&!eq_B_D) && (El>=Hl&&El>=Dl || eq(E,G)) && ((El=Hl&&El>=Dl || eq(E,G)) && ((El 1.0 ) { if (L.b > 30.0 ) {L=L-33.0; slopEND=true;} if (L.b == 8.0 ) { @@ -930,12 +1045,12 @@ if ( !(eq_E_D && eq_E_F) && !(eq_E_B && eq_E_H) ) { return; } if (L.b == 2.0 ) {slopeBAD=true; L=rgbaE;} - } else {slope3 = true;slopeBAD = false;} + } else {slope3ok = true;} } // F - H - bool slope4 = slope2; - if ( !slope2 && (!eq_E_F&&!eq_E_H) && (!eq_B_F&&!eq_D_F && !eq_B_H&&!eq_D_H) && (El>=Fl&&El>=Hl || eq(E,I)) && ((El=Fl&&El>=Hl || eq(E,I)) && ((El 1.0 ) { if (M.b > 30.0 ) {M=M-33.0; slopEND=true;} if (M.b == 8.0 ) { @@ -947,9 +1062,10 @@ if ( !(eq_E_D && eq_E_F) && !(eq_E_B && eq_E_H) ) { return; } if (M.b == 2.0 ) {slopeBAD=true; M=rgbaE;} - } else {slope4 = true;slopeBAD = false;} + } else {slope4ok = true;} } + if (slopEND) { writeColorf(destXY, J); writeColorf(destXY + ivec2(1, 0), K); @@ -958,121 +1074,44 @@ if (slopEND) { return; } - bool slope = slope1 || slope2 || slope3 || slope4; -// long gentle 2:1 slope (P100) and saw-tooth slope +// long gentle 2:1 slope (P100) - bool longslope1 = false; bool longslope2 = false; bool longslope3 = false; bool longslope4 = false; bool sawslope = false; - - if (!eq_B_H) { // horizontal - - if (!eq_E_H && none_eq2(H,A,C)) { - - // A B C . - // Q D 🄴 🅵 🆁 Zone 4 - // 🅶 🅷 I - // S - // (!slope3 && !eq_D_H) This combination is better than directly !sim_D_H, can catch more shapes that are "close but different, didn't pass the main slope rule for some reason". - if ( (!slope3 && !eq_D_H) && noteq(R, RC)) { // H ≠ RC replaced because H = R - if (slope4) { // Divert based on current main slope formation marker. - // Original rule extension 1. Third parameter compares adjacent pixels to ensure no double mixing. - // Original rule extension 2. L-shape cannot appear again within the two-pixel gap on the opposite side. - if (eq_F_H && eq(G,H) && eq(F,R) && (noteq(Q,G)||eq(Q, QA))) {L=admixL(M,L,H); longslope4 = true;} - // Practice: Finally decided to replace !sim_F_H with !eq_F_H (because added any_eq3(I,H,S,SG) condition). - // Practice 2: E cannot equal I, otherwise it will form bubbles with the F branch! - } else if (!eq_F_H && !eq_B_F && !eq_E_F && noteq(E,I) && none_eq2(F,C,I) && (eq_B_D&&eq(B,C)&&sim2(E,B) || eq_E_D&&(eq(E,C)||eq(H,I)||eq(I,S)&&eq(I,RI))) && (noteq(R, RI)||eq(R,I)) && eq(R,H) && eq(F,G) && noteq(G,SG)) {M=unpackUnorm4x8(F); sawslope = true;} - } - // . A B C - // 🆀 🅳 🄴 F R Zone 3 - // G 🅷 🅸 - // S - if ( (!longslope4 && !sawslope) && (!slope4 && !eq_F_H) && noteq(Q, QA) ) { // H ≠ QA replaced because H = Q next - if (slope3) { - if (eq_D_H && eq(D,Q) && eq(H,I) && (noteq(R,I)||eq(R, RC))) {M=admixL(L,M,H); longslope3 = true;} - } else if (!eq_D_H && !eq_B_D && !eq_E_D && noteq(E,G) && none_eq2(D,A,G) && (eq_B_F&&eq(B,A)&&sim2(E,B) || eq_E_F&&(eq(E,A)||eq(H,G)||eq(G,S)&&eq(G,QG))) && (noteq(Q, QG)||eq(Q,G)) && eq(Q,H) && eq(D,I) && noteq(I,SI)) {L=unpackUnorm4x8(D); sawslope = true;} - } - } - - if ( (!sawslope) && !eq_E_B && none_eq2(B,G,I)) { - - // P - // 🅐 🅑 C - // Q D 🄴 🅵 🆁 Zone 2 - // G H I . - if ( (!longslope4) && (!slope1 && !eq_B_D) && noteq(R, RI)) { // B ≠ RI replaced because B = R next - if (slope2) { - if (eq_B_F && eq(A,B) && eq(F,R) && (noteq(A,Q)||eq(Q, QG))) {J=admixL(K,J,B); longslope2 = true;} - } else if (!eq_B_F && !eq_F_H && !eq_E_F && noteq(E,C) && none_eq2(F,C,I) && (eq_D_H&&eq(H,I)&&sim2(E,H) || eq_E_D&&(eq(E,I)||eq(B,C)||eq(I,S)&&eq(I,RI)||eq(C,P)&&eq(C,RC))) && (noteq(R, RC)||eq(R,C)) && eq(B,R) && eq(A,F) && noteq(A,PA)) {K=unpackUnorm4x8(F); sawslope = true;} - } - // P - // A 🅑 🅲 - // 🆀 🅳 🄴 F R Zone 1 - // . G H I - if ( (!longslope2 && !longslope3 && !sawslope) && (!slope2 && !eq_B_F) && noteq(Q, QG)) { // B ≠ QG replaced - if (slope1) { - if (eq_B_D && eq(B,C) && eq(D,Q) && (noteq(C,R)||eq(R, RI))) {K=admixL(J,K,B); longslope1 = true;} - } else if (!eq_B_D && !eq_D_H && !eq_E_D && noteq(E,A) && none_eq2(D,A,G) && (eq_F_H&&eq(H,G)&&sim2(E,H) || eq_E_F&&(eq(E,G)||eq(B,A)||eq(A,P)&&eq(A,QA))) && (noteq(Q, QA)||eq(Q,A)) && eq(B,Q) && eq(C,D) && noteq(C,PC)) {J=unpackUnorm4x8(D); sawslope = true;} - } - } + bool longslope = false; + if (slope4ok && eq_F_H) { //zone4 long slope + // Original rule extension 1. adminxL third parameter passes adjacent pixel for comparison, ensuring no double mixing. + // Original rule extension 2. Cannot have L shape again within the two-pixel gap on the opposite side, unless forming a wall. + if (eq(G,H) && eq(F,R) && noteq(R, RC) && (noteq(Q,G)||eq(Q, QA))) {L=admixL(M,L,H); longslope = true;} + // virtical + if (eq(C,F) && eq(H,S) && noteq(S, SG) && (noteq(P,C)||eq(P, PA))) {K=admixL(M,K,F); longslope = true;} } - bool longslope = longslope1||longslope2||longslope3||longslope4; - longslope1 = false; longslope2 = false; longslope3 = false; longslope4 = false; // reset - if ( (!longslope && !sawslope) && !eq_D_F ) { // vertical + if (slope3ok && eq_D_H) { //zone3 long slope + // horizontal + if (eq(D,Q) && eq(H,I) && noteq(Q, QA) && (noteq(R,I)||eq(R, RC))) {M=admixL(L,M,H); longslope = true;} + // virtical + if (eq(A,D) && eq(H,S) && noteq(S, SI) && (noteq(A,P)||eq(P, PC))) {J=admixL(L,J,D); longslope = true;} + } - // E point on the right - if ( !eq_E_D && none_eq2(D,C,I) ) { // left + if (slope2ok && eq_B_F) { //zone2 long slope + // horizontal + if (eq(A,B) && eq(F,R) && noteq(R, RI) && (noteq(A,Q)||eq(Q, QG))) {J=admixL(K,J,B); longslope = true;} + // virtical + if (eq(F,I) && eq(B,P) && noteq(P, PA) && (noteq(I,S)||eq(S, SG))) {M=admixL(K,M,F); longslope = true;} + } - // 🅐 B C - // Q 🅳 🄴 F R - // G 🅷 I Zone 3 - // 🆂 . - if ( (!slope1 && !eq_B_D) && noteq(S, SI) ) { // D ≠ SI replaced - if (slope3) { - if(eq_D_H && eq(A,D) && eq(H,S) && (noteq(A,P)||eq(P, PC))) {J=admixL(L,J,D); longslope3 = true;} - } else if (!eq_D_H && !eq_F_H && !eq_E_H && noteq(E,G) && none_eq2(H,G,I) && (eq_B_F&&eq(F,I)&&sim2(E,F) || eq_E_B&&(eq(E,I)||eq(D,G)||eq(G,Q)&&eq(G,SG))) && (noteq(S, SG)||eq(S,G)) && eq(D,S) && eq(A,H) && noteq(A,QA)) {L=unpackUnorm4x8(H); sawslope = true;} - } - // 🅟 . - // A 🅑 C - // Q 🅳 🄴 F R Zone 1 - // 🅶 H I - if ( (!longslope3 && !sawslope) && (!slope3 && !eq_D_H) && noteq(P, PC) ) { // D ≠ PC replaced - if (slope1) { - if (eq_B_D && eq(D,G) && eq(B,P) && (noteq(G,S)||eq(S, SI))) {L=admixL(J,L,D); longslope1 = true;} - } else if (!eq_B_D && !eq_B_F && !eq_E_B && noteq(E,A) && none_eq2(B,A,C) && (eq_F_H&&eq(F,C)&&sim2(E,H) || eq_E_H&&(eq(E,C)||eq(D,A)||eq(A,Q)&&eq(A,PA))) && (noteq(P, PA)||eq(P,A)) && eq(P,D) && eq(B,G) && noteq(G,QG)) {J=unpackUnorm4x8(B); sawslope = true;} - } + if (slope1ok && eq_B_D) { //zone1 long slope + // horizontal + if (eq(B,C) && eq(D,Q) && noteq(Q, QG) && (noteq(C,R)||eq(R, RI))) {K=admixL(J,K,B); longslope = true;} + // virtical + if (eq(D,G) && eq(B,P) && noteq(P, PC) && (noteq(G,S)||eq(S, SI))) {L=admixL(J,L,D); longslope = true;} + } - } - if ( (!sawslope) && !eq_E_F && none_eq2(F,A,G) ) { // right - - // A B 🅲 - // Q D 🄴 🅵 R - // G 🅷 I Zone 4 - // . 🆂 - if ( (!longslope3) && (!slope2 && !eq_B_F) && noteq(S, SG)) { // F ≠ SG replaced - if (slope4) { - if (eq_F_H && eq(C,F) && eq(H,S) && (noteq(P,C)||eq(P, PA))) {K=admixL(M,K,F); longslope4 = true;} - } else if (!eq_F_H && !eq_D_H && !eq_E_H && noteq(E,I) && none_eq2(H,G,I) && (eq_B_D&&eq(D,G)&&sim2(E,D) || eq_E_B&&(eq(E,G)||eq(F,I)||eq(I,R)&&eq(I,SI))) && (noteq(S, SI)||eq(S,I)) && eq(S,F) && eq(H,C) && noteq(C,RC)) {M=unpackUnorm4x8(H); sawslope = true;} - } - // . 🅟 - // A 🅑 C - // Q D 🄴 🅵 R Zone 2 - // G H 🅸 - if ( (!longslope1 && !longslope4 && !sawslope) && (!slope4 && !eq_F_H) && noteq(P, PA)) { // F ≠ PA replaced - if (slope2) { - if (eq_B_F && eq(F,I) && eq(B,P) && (noteq(I,S)||eq(S, SG))) {M=admixL(K,M,F); longslope2 = true;} - // B -> K - } else if (!eq_B_F && !eq_B_D && !eq_E_B && noteq(E,C) && none_eq2(B,A,C) && (eq_D_H&&eq(D,A)&&sim2(E,D) || eq_E_H&&(eq(E,A)||eq(F,C)||eq(C,R)&&eq(C,PC))) && (noteq(P, PC)||eq(P,C)) && eq(P,F) && eq(B,I) && noteq(I,RI)) {K=unpackUnorm4x8(B); sawslope = true;} - } - } - } // F ≠ D - -longslope = longslope||longslope1||longslope2||longslope3||longslope4; - -if (slopeBAD||longslope||sawslope||El>=7000000||Bl>=7000000||Dl>=7000000||Fl>=7000000||Hl>=7000000) { +// longslope formed can exit, basically won't form sawslope on the diagonal +if (longslope) { writeColorf(destXY, J); writeColorf(destXY + ivec2(1, 0), K); writeColorf(destXY + ivec2(0, 1), L); @@ -1080,56 +1119,189 @@ if (slopeBAD||longslope||sawslope||El>=7000000||Bl>=7000000||Dl>=7000000||Fl>=70 return; } +bool sawslope = false; + +bool slopeok = slope1ok||slope2ok||slope3ok||slope4ok; + +// Note: sawslope cannot exclude slopEND (few) and slopeBAD (very few), but can exclude slopeok (strong shape) +if (!oppoPix && !slopeok) { + + + // horizontal bottom + if (!eq_E_H && none_eq2(H,A,C)) { + + // A B C . + // Q D 🄴 🅵 🆁 Zone 4 + // 🅶 🅷 I + // S + // (!slope3 && !eq_D_H) Such consecutive use is quite well + if ( (!slope2 && !eq_B_F) && (!slope3 && !eq_D_H) && !eq_F_H && + !eq_E_F && (eq_B_D || eq_E_D) && eq(R,H) && eq(F,G) ) { + M = admixS(A,B,C,D,E,F,G,H,I,R,RC,RI,S,SG,SI,II,eq_B_D,eq_E_D,El,Bl,rgbaE); + sawslope = true;} + + // . A B C + // 🆀 🅳 🄴 F R Zone 3 + // G 🅷 🅸 + // S + if ( !sawslope && (!slope1 && !eq_B_D) && (!slope4 && !eq_F_H) && !eq_D_H && + !eq_E_D && (eq_B_F || eq_E_F) && eq(Q,H) && eq(D,I) ) { + L = admixS(C,B,A,F,E,D,I,H,G,Q,QA,QG,S,SI,SG,GG,eq_B_F,eq_E_F,El,Bl,rgbaE); + sawslope = true;} + } + + // horizontal up + if ( !sawslope && !eq_E_B && none_eq2(B,G,I)) { + + // P + // 🅐 🅑 C + // Q D 🄴 🅵 🆁 Zone 2 + // G H I . + if ( (!slope1 && !eq_B_D) && (!slope4 && !eq_F_H) && !eq_B_F && + !eq_E_F && (eq_D_H || eq_E_D) && eq(B,R) && eq(A,F) ) { + K = admixS(G,H,I,D,E,F,A,B,C,R,RI,RC,P,PA,PC,CC,eq_D_H,eq_E_D,El,Hl,rgbaE); + sawslope = true;} + + // P + // A 🅑 🅲 + // 🆀 🅳 🄴 F R Zone 1 + // . G H I + if ( !sawslope && (!slope2 && !eq_B_F) && (!slope3 && !eq_D_H) && !eq_B_D && + !eq_E_D && (eq_F_H || eq_E_F) && eq(B,Q) && eq(C,D) ) { + J = admixS(I,H,G,F,E,D,C,B,A,Q,QG,QA,P,PC,PA,AA,eq_F_H,eq_E_F,El,Hl,rgbaE); + sawslope = true;} + + } + + // vertical left + if ( !sawslope && !eq_E_D && none_eq2(D,C,I) ) { + + // 🅐 B C + // Q 🅳 🄴 F R + // G 🅷 I Zone 3 + // 🆂 . + if ( (!slope1 && !eq_B_D) && (!slope4 && !eq_F_H) && !eq_D_H && + !eq_E_H && (eq_B_F || eq_E_B) && eq(D,S) && eq(A,H) ) { + L = admixS(C,F,I,B,E,H,A,D,G,S,SI,SG,Q,QA,QG,GG,eq_B_F,eq_E_B,El,Fl,rgbaE); + sawslope = true;} + + // 🅟 . + // A 🅑 C + // Q 🅳 🄴 F R Zone 1 + // 🅶 H I + if ( !sawslope && (!slope3 && !eq_D_H) && (!slope2 && !eq_B_F) && !eq_B_D && + !eq_E_B && (eq_F_H || eq_E_H) && eq(P,D) && eq(B,G) ) { + J = admixS(I,F,C,H,E,B,G,D,A,P,PC,PA,Q,QG,QA,AA,eq_F_H,eq_E_H,El,Fl,rgbaE); + sawslope = true;} + + } + + // vertical right + if ( !sawslope && !eq_E_F && none_eq2(F,A,G) ) { // right + + // A B 🅲 + // Q D 🄴 🅵 R + // G 🅷 I Zone 4 + // . 🆂 + if ( (!slope2 && !eq_B_F) && (!slope3 && !eq_D_H) && !eq_F_H && + !eq_E_H && (eq_B_D || eq_E_B) && eq(S,F) && eq(H,C) ) { + M = admixS(A,D,G,B,E,H,C,F,I,S,SG,SI,R,RC,RI,II,eq_B_D,eq_E_B,El,Dl,rgbaE); + sawslope = true;} + + // . 🅟 + // A 🅑 C + // Q D 🄴 🅵 R Zone 2 + // G H 🅸 + if ( !sawslope && (!slope1 && !eq_B_D) && (!slope4 && !eq_F_H) && !eq_B_F && + !eq_E_B && (eq_D_H || eq_E_H) && eq(P,F) && eq(B,I) ) { + K = admixS(G,D,A,H,E,B,I,F,C,P,PA,PC,R,RI,RC,CC,eq_D_H,eq_E_H,El,Dl,rgbaE); + sawslope = true;} + + } // vertical right +} // sawslope + +// sawslope formed can exit, slopeBAD is not suitable for the CnC below +// Exit early if all 5 points (up, down, left, right, center) are fully transparent +if (sawslope||slopeBAD||El>=7340032||Bl>=7340032||Dl>=7340032||Fl>=7340032||Hl>=7340032) { + writeColorf(destXY, J); + writeColorf(destXY + ivec2(1, 0), K); + writeColorf(destXY + ivec2(0, 1), L); + writeColorf(destXY + ivec2(1, 1), M); + return; +} + + /************************************************** - * "Concave + Cross" type (P100) * + * "Concave + Cross" type (P100) * *************************************************/ -// The far end of the cross star uses similar pixels, useful for some horizontal line + sawtooth and layered gradient shapes. e.g., SFIII 2nd Impact opening glowing text, SFZ3Mix Japanese houses, Garou Mark of the Wolves opening. -bool cnc = false; +// The far end of the cross star uses similar pixels, useful for some horizontal lines + sawtooth and layered gradient shapes. E.g., glowing text in SFIII 3rd Strike intro, Japanese houses in SFZ3Mix, Garou Mark of the Wolves intro. +// Practice: CnC cannot exclude slopEND (weak shape) and slopeok (strong shape) but can exclude slopeBAD !!! + +bool cnc = false; uint X; if (!slope3 && !slope4 && - Bl