kopia lustrzana https://github.com/xdsopl/robot36
reduced code duplication
rodzic
0649ac48d5
commit
e843719923
|
@ -12,7 +12,21 @@ public final class ColorConverter {
|
|||
return Math.min(Math.max(value, 0), 255);
|
||||
}
|
||||
|
||||
public static int YUV2RGB(int Y, int U, int V) {
|
||||
private static float clamp(float value) {
|
||||
return Math.min(Math.max(value, 0), 1);
|
||||
}
|
||||
|
||||
private static int float2int(float level) {
|
||||
int intensity = Math.round(255 * level);
|
||||
return clamp(intensity);
|
||||
}
|
||||
|
||||
private static int compress(float level) {
|
||||
float compressed = (float) Math.sqrt(clamp(level));
|
||||
return float2int(compressed);
|
||||
}
|
||||
|
||||
private static int YUV2RGB(int Y, int U, int V) {
|
||||
Y -= 16;
|
||||
U -= 128;
|
||||
V -= 128;
|
||||
|
@ -21,4 +35,16 @@ public final class ColorConverter {
|
|||
int B = clamp((298 * Y + 516 * U + 128) >> 8);
|
||||
return 0xff000000 | (R << 16) | (G << 8) | B;
|
||||
}
|
||||
|
||||
public static int GRAY(float level) {
|
||||
return 0xff000000 | 0x00010101 * compress(level);
|
||||
}
|
||||
|
||||
public static int RGB(float red, float green, float blue) {
|
||||
return 0xff000000 | (float2int(red) << 16) | (float2int(green) << 8) | float2int(blue);
|
||||
}
|
||||
|
||||
public static int YUV2RGB(float Y, float U, float V) {
|
||||
return YUV2RGB(float2int(Y), float2int(U), float2int(V));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,7 +108,7 @@ public class Demodulator {
|
|||
float syncPulse9msValue = syncPulse9msDelay.push(syncPulse9ms.norm()) / averagePower;
|
||||
float syncPulse20msValue = syncPulse20msDelay.push(syncPulse20ms.norm()) / averagePower;
|
||||
float scanLineValue = scanLineDemod.demod(scanLine);
|
||||
float scanLineLevel = Math.min(Math.max(0.5f * (scanLineValue + 1), 0), 1);
|
||||
float scanLineLevel = 0.5f * (scanLineValue + 1);
|
||||
if (syncPulseTrigger.latch(syncPulse5msValue)) {
|
||||
if (syncPulse5msMaxValue < syncPulse5msValue) {
|
||||
syncPulse5msMaxValue = syncPulse5msValue;
|
||||
|
|
|
@ -50,13 +50,10 @@ public class Martin implements Mode {
|
|||
return 0;
|
||||
for (int i = 0; i < evenBuffer.length; ++i) {
|
||||
int position = (i * channelSamples) / evenBuffer.length + prevPulseIndex;
|
||||
int redPos = position + redBeginSamples;
|
||||
int greenPos = position + greenBeginSamples;
|
||||
int bluePos = position + blueBeginSamples;
|
||||
int redPos = position + redBeginSamples;
|
||||
int green = Math.round(255 * scanLineBuffer[greenPos]);
|
||||
int blue = Math.round(255 * scanLineBuffer[bluePos]);
|
||||
int red = Math.round(255 * scanLineBuffer[redPos]);
|
||||
evenBuffer[i] = 0xff000000 | (red << 16) | (green << 8) | blue;
|
||||
evenBuffer[i] = ColorConverter.RGB(scanLineBuffer[redPos], scanLineBuffer[greenPos], scanLineBuffer[bluePos]);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -55,12 +55,8 @@ public class PaulDon implements Mode {
|
|||
int vAvgPos = position + vAvgBeginSamples;
|
||||
int uAvgPos = position + uAvgBeginSamples;
|
||||
int yOddPos = position + yOddBeginSamples;
|
||||
int yEven = Math.round(255 * scanLineBuffer[yEvenPos]);
|
||||
int vAvg = Math.round(255 * scanLineBuffer[vAvgPos]);
|
||||
int uAvg = Math.round(255 * scanLineBuffer[uAvgPos]);
|
||||
int yOdd = Math.round(255 * scanLineBuffer[yOddPos]);
|
||||
evenBuffer[i] = ColorConverter.YUV2RGB(yEven, uAvg, vAvg);
|
||||
oddBuffer[i] = ColorConverter.YUV2RGB(yOdd, uAvg, vAvg);
|
||||
evenBuffer[i] = ColorConverter.YUV2RGB(scanLineBuffer[yEvenPos], scanLineBuffer[uAvgPos], scanLineBuffer[vAvgPos]);
|
||||
oddBuffer[i] = ColorConverter.YUV2RGB(scanLineBuffer[yOddPos], scanLineBuffer[uAvgPos], scanLineBuffer[vAvgPos]);
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
|
|
@ -27,8 +27,7 @@ public class Raw implements Mode {
|
|||
return 0;
|
||||
for (int i = 0; i < evenBuffer.length; ++i) {
|
||||
int position = (i * scanLineSamples) / evenBuffer.length + prevPulseIndex;
|
||||
int intensity = (int) Math.round(255 * Math.sqrt(scanLineBuffer[position]));
|
||||
evenBuffer[i] = 0xff000000 | 0x00010101 * intensity;
|
||||
evenBuffer[i] = ColorConverter.GRAY(scanLineBuffer[position]);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -36,8 +36,7 @@ public class Robot_36_Color implements Mode {
|
|||
return 0;
|
||||
for (int i = 0; i < evenBuffer.length; ++i) {
|
||||
int position = (i * scanLineSamples) / evenBuffer.length + prevPulseIndex;
|
||||
int intensity = (int) Math.round(255 * Math.sqrt(scanLineBuffer[position]));
|
||||
evenBuffer[i] = 0xff000000 | 0x00010101 * intensity;
|
||||
evenBuffer[i] = ColorConverter.GRAY(scanLineBuffer[position]);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -36,8 +36,7 @@ public class Robot_72_Color implements Mode {
|
|||
return 0;
|
||||
for (int i = 0; i < evenBuffer.length; ++i) {
|
||||
int position = (i * scanLineSamples) / evenBuffer.length + prevPulseIndex;
|
||||
int intensity = (int) Math.round(255 * Math.sqrt(scanLineBuffer[position]));
|
||||
evenBuffer[i] = 0xff000000 | 0x00010101 * intensity;
|
||||
evenBuffer[i] = ColorConverter.GRAY(scanLineBuffer[position]);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -34,8 +34,7 @@ public class Scottie implements Mode {
|
|||
return 0;
|
||||
for (int i = 0; i < evenBuffer.length; ++i) {
|
||||
int position = (i * scanLineSamples) / evenBuffer.length + prevPulseIndex;
|
||||
int intensity = (int) Math.round(255 * Math.sqrt(scanLineBuffer[position]));
|
||||
evenBuffer[i] = 0xff000000 | 0x00010101 * intensity;
|
||||
evenBuffer[i] = ColorConverter.GRAY(scanLineBuffer[position]);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -50,10 +50,7 @@ public class Wraase_SC2_180 implements Mode {
|
|||
int redPos = position + redBeginSamples;
|
||||
int greenPos = position + greenBeginSamples;
|
||||
int bluePos = position + blueBeginSamples;
|
||||
int red = Math.round(255 * scanLineBuffer[redPos]);
|
||||
int green = Math.round(255 * scanLineBuffer[greenPos]);
|
||||
int blue = Math.round(255 * scanLineBuffer[bluePos]);
|
||||
evenBuffer[i] = 0xff000000 | (red << 16) | (green << 8) | blue;
|
||||
evenBuffer[i] = ColorConverter.RGB(scanLineBuffer[redPos], scanLineBuffer[greenPos], scanLineBuffer[bluePos]);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue