I'm working on a concept, that I'll hopefully have time to complete. But for today I'd like to throw out the idea of allowing Pixel scaling methods.
My thought is that these are in the spirit of the contest and would make playing the entries more fun. But if allowed would need to follow the rule:
The scaling method must be under end user control and should default to point sampling. Also, to be fair to everyone, the method source should be made available.
Below I have my implementations of Scale2X & Scale3X. These can be chained to create 4x & 6x. I also have Hq{2,3,4}x, but are not really ready for realtime usage. If TPTB decided that these methods are OK for usage, I'll try to complete them along with an 2xSai version.
Scale2X:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| public static final void convert(int[] dst, int[] src, int sw, int sh) { int dw = sw+sw; int r0 = 0; int r1 = dw;
int x, y; int pr = 0; int nr; int i = 0; int c01; int c10,c11,c12; int c21;
for (y=0; y<sh; y++) { if (y < sh-1) nr = sw; else nr = 0; c11 = src[i]; c12 = src[i+1];
for (x=0; x<sw; x++) { c10 = c11; c11 = c12; c01 = src[i + pr]; c21 = src[i + nr];
if (x < sw-1) c12 = src[i+1];
if (c01 != c21 && c10 != c12) { dst[r0 ] = c10 == c01 ? c10 : c11; dst[r0+1] = c01 == c12 ? c12 : c11; dst[r1 ] = c10 == c21 ? c10 : c11; dst[r1+1] = c21 == c12 ? c12 : c11; } else dst[r0] = dst[r0+1] = dst[r1] = dst[r1+1] = c11;
r0 += 2; r1 += 2; i++; } pr = -sw; r0 = r1; r1 += dw; } } |
Scale3X:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
| public static final void convert(int[] dst, int[] src, int sw, int sh) { int i = 0; int x, y; int pr = 0; int nr; int dx = sw * 3; int r0 = 0; int r1 = dx; int r2 = r1 + dx;
int c00,c01,c02; int c10,c11,c12; int c20,c21,c22;
for (y = 0; y < sh; y++) { if (y < sh - 1) nr = sw; else nr = 0;
for (x = 0; x < sw; x++) { c01 = src[i + pr]; c11 = src[i]; c21 = src[i + nr];
if (x > 0) { c00 = src[i + pr - 1]; c10 = src[i - 1]; c20 = src[i + nr - 1]; } else { c00 = c01; c10 = c11; c20 = c21; }
if (x < sw - 1) { c02 = src[i + pr + 1]; c12 = src[i + 1]; c22 = src[i + nr + 1]; } else { c02 = c01; c12 = c11; c22 = c21; }
i++; if ((c01 != c21) && (c10 != c12)) { boolean t0 = c01 == c12; boolean t1 = c10 == c21; boolean t2 = c11 != c02; boolean t3 = c11 != c20; if (c11 != c00) { if (c10 == c01) { dst[r0 ] = c10; dst[r0+1] = t0 || t2 ? c01 : c11; dst[r1 ] = t1 || t3 ? c10 : c11; } else { dst[r0 ] = c11; dst[r0+1] = t0 ? c01 : c11; dst[r1 ] = t1 ? c10 : c11; } } else { if (c10 == c01) { dst[r0 ] = c10; dst[r0+1] = t2 ? c01 : c11; dst[r1 ] = t3 ? c10 : c11; } else { dst[r0 ] = c11; dst[r0+1] = c11; dst[r1 ] = c11; } }
if (c11 != c22) { if (c21 == c12) { dst[r2+2] = c12; dst[r1+2] = t0 || t2 ? c12 : c11; dst[r2+1] = t1 || t3 ? c21 : c11; } else { dst[r2+2] = c11; dst[r1+2] = t0 ? c12 : c11; dst[r2+1] = t1 ? c21 : c11; } } else { if (c21 == c12) { dst[r2+2] = c12; dst[r1+2] = t2 ? c12 : c11; dst[r2+1] = t3 ? c21 : c11; } else { dst[r2+2] = c11; dst[r1+2] = c11; dst[r2+1] = c11; } }
dst[r0+2] = t0 ? c12 : c11; dst[r2 ] = t1 ? c10 : c11; } else { dst[r0 ] = dst[r0+1] = dst[r0+2] = dst[r1 ] = dst[r1+2] = dst[r2 ] = dst[r2+1] = dst[r2+2] = c11; }
dst[r1+1] = c11;
r0 += 3; r1 += 3; r2 += 3; } pr = -sw; r0 = r2; r1 = r0+dx; r2 = r1+dx; } } |