mirror of
https://github.com/xdsopl/robot36.git
synced 2026-01-25 09:00:17 +01:00
Refactoring, added postProcessScopeImage
This commit is contained in:
parent
055d62b625
commit
34d34f435c
|
|
@ -1,8 +1,15 @@
|
|||
package xdsopl.robot36;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
public abstract class BaseMode implements Mode {
|
||||
@Override
|
||||
public int getEstimatedHorizontalShift() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bitmap postProcessScopeImage(Bitmap bmp) {
|
||||
return Bitmap.createScaledBitmap(bmp, bmp.getWidth() / 3, bmp.getHeight() / 3, true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
package xdsopl.robot36;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Rect;
|
||||
|
||||
/**
|
||||
* HF Fax, IOC 576, 120 lines per minute
|
||||
|
|
@ -67,6 +70,29 @@ public class HFFax extends BaseMode {
|
|||
public void reset() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bitmap postProcessScopeImage(Bitmap bmp) {
|
||||
int shift = getEstimatedHorizontalShift();
|
||||
if (shift > 0) {
|
||||
Bitmap bmpMutable = Bitmap.createBitmap(getWidth(), bmp.getHeight(), Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(bmpMutable);
|
||||
canvas.drawBitmap(
|
||||
bmp,
|
||||
new Rect(0, 0, shift, bmp.getHeight()),
|
||||
new Rect(getWidth() - shift, 0, getWidth(), bmp.getHeight()),
|
||||
null);
|
||||
canvas.drawBitmap(
|
||||
bmp,
|
||||
new Rect(shift, 0, getWidth(), bmp.getHeight()),
|
||||
new Rect(0, 1, getWidth() - shift, bmp.getHeight() + 1),
|
||||
null);
|
||||
|
||||
return bmpMutable;
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -15,9 +15,7 @@ import android.content.SharedPreferences;
|
|||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Rect;
|
||||
import android.media.AudioFormat;
|
||||
import android.media.AudioRecord;
|
||||
import android.media.MediaRecorder;
|
||||
|
|
@ -846,27 +844,10 @@ public class MainActivity extends AppCompatActivity {
|
|||
int stride = scopeBuffer.width;
|
||||
int offset = stride * scopeBuffer.line;
|
||||
Bitmap bmp = Bitmap.createBitmap(scopeBuffer.pixels, offset, stride, width, height, Bitmap.Config.ARGB_8888);
|
||||
if (decoder != null && decoder.currentMode.getName().equals("HF Fax")) {
|
||||
Mode mode = decoder.currentMode;
|
||||
int shift = mode.getEstimatedHorizontalShift();
|
||||
if (shift > 0) {
|
||||
Bitmap bmpMutable = Bitmap.createBitmap(mode.getWidth(), bmp.getHeight(), Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(bmpMutable);
|
||||
canvas.drawBitmap(
|
||||
bmp,
|
||||
new Rect(0, 0, shift, bmp.getHeight()),
|
||||
new Rect(mode.getWidth() - shift, 0, mode.getWidth(), bmp.getHeight()),
|
||||
null);
|
||||
canvas.drawBitmap(
|
||||
bmp,
|
||||
new Rect(shift, 0, mode.getWidth(), bmp.getHeight()),
|
||||
new Rect(0, 1, mode.getWidth() - shift, bmp.getHeight() + 1),
|
||||
null);
|
||||
|
||||
bmp = bmpMutable;
|
||||
}
|
||||
} else {
|
||||
bmp = Bitmap.createScaledBitmap(bmp, width / 3, height / 3, true);
|
||||
if (decoder != null)
|
||||
{
|
||||
bmp = decoder.currentMode.postProcessScopeImage(bmp);
|
||||
}
|
||||
|
||||
storeBitmap(bmp);
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ Copyright 2024 Ahmet Inan <xdsopl@gmail.com>
|
|||
|
||||
package xdsopl.robot36;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
public interface Mode {
|
||||
/**
|
||||
* @return mode name
|
||||
|
|
@ -47,6 +49,11 @@ public interface Mode {
|
|||
*/
|
||||
int getEstimatedHorizontalShift();
|
||||
|
||||
/**
|
||||
* Adjust scope image before saving
|
||||
*/
|
||||
Bitmap postProcessScopeImage(Bitmap bmp);
|
||||
|
||||
/**
|
||||
* Reset internal state.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in a new issue