mirror of
https://github.com/xdsopl/robot36.git
synced 2026-01-06 16:29:56 +01:00
Fixed indents to tabs
This commit is contained in:
parent
02018686b6
commit
5aa3be6cc9
|
|
@ -3,8 +3,8 @@ package xdsopl.robot36;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
|
||||||
public abstract class BaseMode implements Mode {
|
public abstract class BaseMode implements Mode {
|
||||||
@Override
|
@Override
|
||||||
public Bitmap postProcessScopeImage(Bitmap bmp) {
|
public Bitmap postProcessScopeImage(Bitmap bmp) {
|
||||||
return Bitmap.createScaledBitmap(bmp, bmp.getWidth() / 3, bmp.getHeight() / 3, true);
|
return Bitmap.createScaledBitmap(bmp, bmp.getWidth() / 3, bmp.getHeight() / 3, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,123 +9,123 @@ import android.graphics.Rect;
|
||||||
* HF Fax, IOC 576, 120 lines per minute
|
* HF Fax, IOC 576, 120 lines per minute
|
||||||
*/
|
*/
|
||||||
public class HFFax extends BaseMode {
|
public class HFFax extends BaseMode {
|
||||||
private final ExponentialMovingAverage lowPassFilter;
|
private final ExponentialMovingAverage lowPassFilter;
|
||||||
private final String name;
|
private final String name;
|
||||||
private final int sampleRate;
|
private final int sampleRate;
|
||||||
private final float[] cumulated;
|
private final float[] cumulated;
|
||||||
private int horizontalShift = 0;
|
private int horizontalShift = 0;
|
||||||
|
|
||||||
HFFax(String name, int sampleRate) {
|
HFFax(String name, int sampleRate) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
lowPassFilter = new ExponentialMovingAverage();
|
lowPassFilter = new ExponentialMovingAverage();
|
||||||
this.sampleRate = sampleRate;
|
this.sampleRate = sampleRate;
|
||||||
cumulated = new float[getWidth()];
|
cumulated = new float[getWidth()];
|
||||||
}
|
}
|
||||||
|
|
||||||
private float freqToLevel(float frequency, float offset) {
|
private float freqToLevel(float frequency, float offset) {
|
||||||
return 0.5f * (frequency - offset + 1.f);
|
return 0.5f * (frequency - offset + 1.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCode() {
|
public int getCode() {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getWidth() {
|
public int getWidth() {
|
||||||
return 1808;
|
return 1808;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getHeight() {
|
public int getHeight() {
|
||||||
return 1200;
|
return 1200;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getBegin() {
|
public int getBegin() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getFirstSyncPulseIndex() {
|
public int getFirstSyncPulseIndex() {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getScanLineSamples() {
|
public int getScanLineSamples() {
|
||||||
return sampleRate / 2;
|
return sampleRate / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reset() {
|
public void reset() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Bitmap postProcessScopeImage(Bitmap bmp) {
|
public Bitmap postProcessScopeImage(Bitmap bmp) {
|
||||||
if (horizontalShift > 0) {
|
if (horizontalShift > 0) {
|
||||||
Bitmap bmpMutable = Bitmap.createBitmap(getWidth(), bmp.getHeight(), Bitmap.Config.ARGB_8888);
|
Bitmap bmpMutable = Bitmap.createBitmap(getWidth(), bmp.getHeight(), Bitmap.Config.ARGB_8888);
|
||||||
Canvas canvas = new Canvas(bmpMutable);
|
Canvas canvas = new Canvas(bmpMutable);
|
||||||
canvas.drawBitmap(
|
canvas.drawBitmap(
|
||||||
bmp,
|
bmp,
|
||||||
new Rect(0, 0, horizontalShift, bmp.getHeight()),
|
new Rect(0, 0, horizontalShift, bmp.getHeight()),
|
||||||
new Rect(getWidth() - horizontalShift, 0, getWidth(), bmp.getHeight()),
|
new Rect(getWidth() - horizontalShift, 0, getWidth(), bmp.getHeight()),
|
||||||
null);
|
null);
|
||||||
canvas.drawBitmap(
|
canvas.drawBitmap(
|
||||||
bmp,
|
bmp,
|
||||||
new Rect(horizontalShift, 0, getWidth(), bmp.getHeight()),
|
new Rect(horizontalShift, 0, getWidth(), bmp.getHeight()),
|
||||||
new Rect(0, 1, getWidth() - horizontalShift, bmp.getHeight() + 1),
|
new Rect(0, 1, getWidth() - horizontalShift, bmp.getHeight() + 1),
|
||||||
null);
|
null);
|
||||||
|
|
||||||
return bmpMutable;
|
return bmpMutable;
|
||||||
}
|
}
|
||||||
|
|
||||||
return bmp;
|
return bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean decodeScanLine(PixelBuffer pixelBuffer, float[] scratchBuffer, float[] scanLineBuffer, int scopeBufferWidth, int syncPulseIndex, int scanLineSamples, float frequencyOffset) {
|
public boolean decodeScanLine(PixelBuffer pixelBuffer, float[] scratchBuffer, float[] scanLineBuffer, int scopeBufferWidth, int syncPulseIndex, int scanLineSamples, float frequencyOffset) {
|
||||||
if (syncPulseIndex < 0 || syncPulseIndex + scanLineSamples > scanLineBuffer.length)
|
if (syncPulseIndex < 0 || syncPulseIndex + scanLineSamples > scanLineBuffer.length)
|
||||||
return false;
|
return false;
|
||||||
int horizontalPixels = getWidth();
|
int horizontalPixels = getWidth();
|
||||||
lowPassFilter.cutoff(horizontalPixels, 2 * scanLineSamples, 2);
|
lowPassFilter.cutoff(horizontalPixels, 2 * scanLineSamples, 2);
|
||||||
lowPassFilter.reset();
|
lowPassFilter.reset();
|
||||||
for (int i = 0; i < scanLineSamples; ++i)
|
for (int i = 0; i < scanLineSamples; ++i)
|
||||||
scratchBuffer[i] = lowPassFilter.avg(scanLineBuffer[i]);
|
scratchBuffer[i] = lowPassFilter.avg(scanLineBuffer[i]);
|
||||||
lowPassFilter.reset();
|
lowPassFilter.reset();
|
||||||
for (int i = scanLineSamples - 1; i >= 0; --i)
|
for (int i = scanLineSamples - 1; i >= 0; --i)
|
||||||
scratchBuffer[i] = freqToLevel(lowPassFilter.avg(scratchBuffer[i]), frequencyOffset);
|
scratchBuffer[i] = freqToLevel(lowPassFilter.avg(scratchBuffer[i]), frequencyOffset);
|
||||||
for (int i = 0; i < horizontalPixels; ++i) {
|
for (int i = 0; i < horizontalPixels; ++i) {
|
||||||
int position = (i * scanLineSamples) / horizontalPixels;
|
int position = (i * scanLineSamples) / horizontalPixels;
|
||||||
int color = ColorConverter.GRAY(scratchBuffer[position]);
|
int color = ColorConverter.GRAY(scratchBuffer[position]);
|
||||||
pixelBuffer.pixels[i] = color;
|
pixelBuffer.pixels[i] = color;
|
||||||
|
|
||||||
//accumulate recent values, forget old
|
//accumulate recent values, forget old
|
||||||
float decay = 0.99f;
|
float decay = 0.99f;
|
||||||
cumulated[i] = cumulated[i] * decay + Color.luminance(color) * (1 - decay);
|
cumulated[i] = cumulated[i] * decay + Color.luminance(color) * (1 - decay);
|
||||||
}
|
}
|
||||||
|
|
||||||
//try to detect "sync": thick white margin
|
//try to detect "sync": thick white margin
|
||||||
int bestIndex = 0;
|
int bestIndex = 0;
|
||||||
float bestValue = 0;
|
float bestValue = 0;
|
||||||
for (int x = 0; x < getWidth(); ++x)
|
for (int x = 0; x < getWidth(); ++x)
|
||||||
{
|
{
|
||||||
float val = cumulated[x];
|
float val = cumulated[x];
|
||||||
if (val > bestValue)
|
if (val > bestValue)
|
||||||
{
|
{
|
||||||
bestIndex = x;
|
bestIndex = x;
|
||||||
bestValue = val;
|
bestValue = val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
horizontalShift = bestIndex;
|
horizontalShift = bestIndex;
|
||||||
|
|
||||||
pixelBuffer.width = horizontalPixels;
|
pixelBuffer.width = horizontalPixels;
|
||||||
pixelBuffer.height = 1;
|
pixelBuffer.height = 1;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue