mirror of
https://github.com/xdsopl/robot36.git
synced 2026-01-04 07:29:55 +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;
|
||||
|
||||
public abstract class BaseMode implements Mode {
|
||||
@Override
|
||||
public Bitmap postProcessScopeImage(Bitmap bmp) {
|
||||
return Bitmap.createScaledBitmap(bmp, bmp.getWidth() / 3, bmp.getHeight() / 3, true);
|
||||
}
|
||||
@Override
|
||||
public Bitmap postProcessScopeImage(Bitmap bmp) {
|
||||
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
|
||||
*/
|
||||
public class HFFax extends BaseMode {
|
||||
private final ExponentialMovingAverage lowPassFilter;
|
||||
private final String name;
|
||||
private final int sampleRate;
|
||||
private final float[] cumulated;
|
||||
private int horizontalShift = 0;
|
||||
private final ExponentialMovingAverage lowPassFilter;
|
||||
private final String name;
|
||||
private final int sampleRate;
|
||||
private final float[] cumulated;
|
||||
private int horizontalShift = 0;
|
||||
|
||||
HFFax(String name, int sampleRate) {
|
||||
this.name = name;
|
||||
lowPassFilter = new ExponentialMovingAverage();
|
||||
this.sampleRate = sampleRate;
|
||||
cumulated = new float[getWidth()];
|
||||
}
|
||||
HFFax(String name, int sampleRate) {
|
||||
this.name = name;
|
||||
lowPassFilter = new ExponentialMovingAverage();
|
||||
this.sampleRate = sampleRate;
|
||||
cumulated = new float[getWidth()];
|
||||
}
|
||||
|
||||
private float freqToLevel(float frequency, float offset) {
|
||||
return 0.5f * (frequency - offset + 1.f);
|
||||
}
|
||||
private float freqToLevel(float frequency, float offset) {
|
||||
return 0.5f * (frequency - offset + 1.f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCode() {
|
||||
return -1;
|
||||
}
|
||||
@Override
|
||||
public int getCode() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return 1808;
|
||||
}
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return 1808;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return 1200;
|
||||
}
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return 1200;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBegin() {
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public int getBegin() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFirstSyncPulseIndex() {
|
||||
return -1;
|
||||
}
|
||||
@Override
|
||||
public int getFirstSyncPulseIndex() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getScanLineSamples() {
|
||||
return sampleRate / 2;
|
||||
}
|
||||
@Override
|
||||
public int getScanLineSamples() {
|
||||
return sampleRate / 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
}
|
||||
@Override
|
||||
public void reset() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bitmap postProcessScopeImage(Bitmap bmp) {
|
||||
if (horizontalShift > 0) {
|
||||
Bitmap bmpMutable = Bitmap.createBitmap(getWidth(), bmp.getHeight(), Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(bmpMutable);
|
||||
canvas.drawBitmap(
|
||||
bmp,
|
||||
new Rect(0, 0, horizontalShift, bmp.getHeight()),
|
||||
new Rect(getWidth() - horizontalShift, 0, getWidth(), bmp.getHeight()),
|
||||
null);
|
||||
canvas.drawBitmap(
|
||||
bmp,
|
||||
new Rect(horizontalShift, 0, getWidth(), bmp.getHeight()),
|
||||
new Rect(0, 1, getWidth() - horizontalShift, bmp.getHeight() + 1),
|
||||
null);
|
||||
@Override
|
||||
public Bitmap postProcessScopeImage(Bitmap bmp) {
|
||||
if (horizontalShift > 0) {
|
||||
Bitmap bmpMutable = Bitmap.createBitmap(getWidth(), bmp.getHeight(), Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(bmpMutable);
|
||||
canvas.drawBitmap(
|
||||
bmp,
|
||||
new Rect(0, 0, horizontalShift, bmp.getHeight()),
|
||||
new Rect(getWidth() - horizontalShift, 0, getWidth(), bmp.getHeight()),
|
||||
null);
|
||||
canvas.drawBitmap(
|
||||
bmp,
|
||||
new Rect(horizontalShift, 0, getWidth(), bmp.getHeight()),
|
||||
new Rect(0, 1, getWidth() - horizontalShift, bmp.getHeight() + 1),
|
||||
null);
|
||||
|
||||
return bmpMutable;
|
||||
}
|
||||
return bmpMutable;
|
||||
}
|
||||
|
||||
return bmp;
|
||||
}
|
||||
return bmp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean decodeScanLine(PixelBuffer pixelBuffer, float[] scratchBuffer, float[] scanLineBuffer, int scopeBufferWidth, int syncPulseIndex, int scanLineSamples, float frequencyOffset) {
|
||||
if (syncPulseIndex < 0 || syncPulseIndex + scanLineSamples > scanLineBuffer.length)
|
||||
return false;
|
||||
int horizontalPixels = getWidth();
|
||||
lowPassFilter.cutoff(horizontalPixels, 2 * scanLineSamples, 2);
|
||||
lowPassFilter.reset();
|
||||
for (int i = 0; i < scanLineSamples; ++i)
|
||||
scratchBuffer[i] = lowPassFilter.avg(scanLineBuffer[i]);
|
||||
lowPassFilter.reset();
|
||||
for (int i = scanLineSamples - 1; i >= 0; --i)
|
||||
scratchBuffer[i] = freqToLevel(lowPassFilter.avg(scratchBuffer[i]), frequencyOffset);
|
||||
for (int i = 0; i < horizontalPixels; ++i) {
|
||||
int position = (i * scanLineSamples) / horizontalPixels;
|
||||
int color = ColorConverter.GRAY(scratchBuffer[position]);
|
||||
pixelBuffer.pixels[i] = color;
|
||||
@Override
|
||||
public boolean decodeScanLine(PixelBuffer pixelBuffer, float[] scratchBuffer, float[] scanLineBuffer, int scopeBufferWidth, int syncPulseIndex, int scanLineSamples, float frequencyOffset) {
|
||||
if (syncPulseIndex < 0 || syncPulseIndex + scanLineSamples > scanLineBuffer.length)
|
||||
return false;
|
||||
int horizontalPixels = getWidth();
|
||||
lowPassFilter.cutoff(horizontalPixels, 2 * scanLineSamples, 2);
|
||||
lowPassFilter.reset();
|
||||
for (int i = 0; i < scanLineSamples; ++i)
|
||||
scratchBuffer[i] = lowPassFilter.avg(scanLineBuffer[i]);
|
||||
lowPassFilter.reset();
|
||||
for (int i = scanLineSamples - 1; i >= 0; --i)
|
||||
scratchBuffer[i] = freqToLevel(lowPassFilter.avg(scratchBuffer[i]), frequencyOffset);
|
||||
for (int i = 0; i < horizontalPixels; ++i) {
|
||||
int position = (i * scanLineSamples) / horizontalPixels;
|
||||
int color = ColorConverter.GRAY(scratchBuffer[position]);
|
||||
pixelBuffer.pixels[i] = color;
|
||||
|
||||
//accumulate recent values, forget old
|
||||
float decay = 0.99f;
|
||||
cumulated[i] = cumulated[i] * decay + Color.luminance(color) * (1 - decay);
|
||||
}
|
||||
//accumulate recent values, forget old
|
||||
float decay = 0.99f;
|
||||
cumulated[i] = cumulated[i] * decay + Color.luminance(color) * (1 - decay);
|
||||
}
|
||||
|
||||
//try to detect "sync": thick white margin
|
||||
int bestIndex = 0;
|
||||
float bestValue = 0;
|
||||
for (int x = 0; x < getWidth(); ++x)
|
||||
{
|
||||
float val = cumulated[x];
|
||||
if (val > bestValue)
|
||||
{
|
||||
bestIndex = x;
|
||||
bestValue = val;
|
||||
}
|
||||
}
|
||||
//try to detect "sync": thick white margin
|
||||
int bestIndex = 0;
|
||||
float bestValue = 0;
|
||||
for (int x = 0; x < getWidth(); ++x)
|
||||
{
|
||||
float val = cumulated[x];
|
||||
if (val > bestValue)
|
||||
{
|
||||
bestIndex = x;
|
||||
bestValue = val;
|
||||
}
|
||||
}
|
||||
|
||||
horizontalShift = bestIndex;
|
||||
horizontalShift = bestIndex;
|
||||
|
||||
pixelBuffer.width = horizontalPixels;
|
||||
pixelBuffer.height = 1;
|
||||
return true;
|
||||
}
|
||||
pixelBuffer.width = horizontalPixels;
|
||||
pixelBuffer.height = 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue