mirror of
https://github.com/xdsopl/robot36.git
synced 2026-01-02 06:29:56 +01:00
WIP: save image when finished
This commit is contained in:
parent
308874b131
commit
88a13d9a9b
|
|
@ -49,12 +49,18 @@ public class ImageView extends SurfaceView implements SurfaceHolder.Callback {
|
|||
private final short[] audioBuffer;
|
||||
private final int[] pixelBuffer;
|
||||
private final int[] currentMode;
|
||||
private final int[] savedBuffer;
|
||||
private final int[] savedWidth;
|
||||
private final int[] savedHeight;
|
||||
|
||||
private final RenderScript rs;
|
||||
private final Allocation rsDecoderAudioBuffer;
|
||||
private final Allocation rsDecoderPixelBuffer;
|
||||
private final Allocation rsDecoderValueBuffer;
|
||||
private final Allocation rsDecoderCurrentMode;
|
||||
private final Allocation rsDecoderSavedBuffer;
|
||||
private final Allocation rsDecoderSavedWidth;
|
||||
private final Allocation rsDecoderSavedHeight;
|
||||
private final ScriptC_decoder rsDecoder;
|
||||
|
||||
private final int mode_debug = 0;
|
||||
|
|
@ -110,16 +116,26 @@ public class ImageView extends SurfaceView implements SurfaceHolder.Callback {
|
|||
int maxHorizontalLength = 2 * sampleRate;
|
||||
currentMode = new int[1];
|
||||
|
||||
savedWidth = new int[1];
|
||||
savedHeight = new int[1];
|
||||
savedBuffer = new int[pixelBuffer.length];
|
||||
|
||||
rs = RenderScript.create(context);
|
||||
rsDecoderAudioBuffer = Allocation.createSized(rs, Element.I16(rs), audioBuffer.length, Allocation.USAGE_SHARED | Allocation.USAGE_SCRIPT);
|
||||
rsDecoderValueBuffer = Allocation.createSized(rs, Element.U8(rs), maxHorizontalLength, Allocation.USAGE_SCRIPT);
|
||||
rsDecoderPixelBuffer = Allocation.createSized(rs, Element.I32(rs), pixelBuffer.length, Allocation.USAGE_SHARED | Allocation.USAGE_SCRIPT);
|
||||
rsDecoderCurrentMode = Allocation.createSized(rs, Element.I32(rs), 1, Allocation.USAGE_SHARED | Allocation.USAGE_SCRIPT);
|
||||
rsDecoderSavedWidth = Allocation.createSized(rs, Element.I32(rs), 1, Allocation.USAGE_SHARED | Allocation.USAGE_SCRIPT);
|
||||
rsDecoderSavedHeight = Allocation.createSized(rs, Element.I32(rs), 1, Allocation.USAGE_SHARED | Allocation.USAGE_SCRIPT);
|
||||
rsDecoderSavedBuffer = Allocation.createSized(rs, Element.I32(rs), savedBuffer.length, Allocation.USAGE_SHARED | Allocation.USAGE_SCRIPT);
|
||||
rsDecoder = new ScriptC_decoder(rs);
|
||||
rsDecoder.bind_audio_buffer(rsDecoderAudioBuffer);
|
||||
rsDecoder.bind_value_buffer(rsDecoderValueBuffer);
|
||||
rsDecoder.bind_pixel_buffer(rsDecoderPixelBuffer);
|
||||
rsDecoder.bind_current_mode(rsDecoderCurrentMode);
|
||||
rsDecoder.bind_saved_width(rsDecoderSavedWidth);
|
||||
rsDecoder.bind_saved_height(rsDecoderSavedHeight);
|
||||
rsDecoder.bind_saved_buffer(rsDecoderSavedBuffer);
|
||||
rsDecoder.invoke_initialize(sampleRate, maxHorizontalLength, bitmap.getWidth(), bitmap.getHeight());
|
||||
|
||||
thread.start();
|
||||
|
|
@ -314,5 +330,12 @@ public class ImageView extends SurfaceView implements SurfaceHolder.Callback {
|
|||
|
||||
rsDecoderCurrentMode.copyTo(currentMode);
|
||||
switch_mode(currentMode[0]);
|
||||
|
||||
rsDecoderSavedHeight.copyTo(savedHeight);
|
||||
if (savedHeight[0] > 0) {
|
||||
rsDecoderSavedWidth.copyTo(savedWidth);
|
||||
rsDecoderSavedBuffer.copyTo(savedBuffer);
|
||||
Bitmap savedBitmap = Bitmap.createBitmap(savedBuffer, savedWidth[0], savedHeight[0], Bitmap.Config.ARGB_8888);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,17 +37,29 @@ static inline uchar4 yuv(uchar y, uchar u, uchar v)
|
|||
return rgb(bgra[0], bgra[1], bgra[2]);
|
||||
}
|
||||
|
||||
static void reset()
|
||||
static void reset_buffer()
|
||||
{
|
||||
vpos = 0;
|
||||
hpos = 0;
|
||||
even_hpos = 0;
|
||||
seperator_counter = 0;
|
||||
sync_counter = sync_length;
|
||||
for (int i = 0; i < bitmap_width * bitmap_height; ++i)
|
||||
buffer_cleared = 1;
|
||||
for (int i = 0; i < maximum_width * maximum_height; ++i)
|
||||
pixel_buffer[i] = rgb(0, 0, 0);
|
||||
}
|
||||
|
||||
static void save_buffer()
|
||||
{
|
||||
if (!buffer_cleared)
|
||||
return;
|
||||
buffer_cleared = 0;
|
||||
*saved_height = bitmap_height;
|
||||
*saved_width = bitmap_width;
|
||||
for (int i = 0; i < bitmap_width * bitmap_height; ++i)
|
||||
saved_buffer[i] = pixel_buffer[i];
|
||||
}
|
||||
|
||||
static void robot36_decoder()
|
||||
{
|
||||
static prev_timeout;
|
||||
|
|
@ -119,6 +131,8 @@ static void raw_decoder()
|
|||
}
|
||||
|
||||
void decode(int samples) {
|
||||
*saved_width = 0;
|
||||
*saved_height = 0;
|
||||
for (int sample = 0; sample < samples; ++sample) {
|
||||
float amp = audio_buffer[sample] / 32768.0f;
|
||||
float power = amp * amp;
|
||||
|
|
@ -147,11 +161,11 @@ void decode(int samples) {
|
|||
if (*current_mode != mode_debug) {
|
||||
int detected_mode = calibration_detector(dat_value, dat_active, cnt_active, cnt_quantized);
|
||||
if (detected_mode >= 0)
|
||||
reset();
|
||||
reset_buffer();
|
||||
switch_mode(detected_mode);
|
||||
int estimated_mode = scanline_estimator(sync_level);
|
||||
if (estimated_mode >= 0 && estimated_mode != *current_mode)
|
||||
reset();
|
||||
reset_buffer();
|
||||
switch_mode(estimated_mode);
|
||||
}
|
||||
|
||||
|
|
@ -179,7 +193,9 @@ void decode(int samples) {
|
|||
default:
|
||||
raw_decoder();
|
||||
}
|
||||
if (++vpos >= bitmap_height)
|
||||
if (++vpos == bitmap_height)
|
||||
save_buffer();
|
||||
if (vpos >= maximum_height)
|
||||
vpos = 0;
|
||||
seperator_counter = 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,9 @@ limitations under the License.
|
|||
short *audio_buffer;
|
||||
uchar *value_buffer;
|
||||
uchar4 *pixel_buffer;
|
||||
uchar4 *saved_buffer;
|
||||
int *saved_width;
|
||||
int *saved_height;
|
||||
int *current_mode;
|
||||
|
||||
#endif
|
||||
|
|
@ -25,14 +25,15 @@ void initialize(float rate, int length, int width, int height)
|
|||
{
|
||||
sample_rate = rate;
|
||||
buffer_length = length;
|
||||
bitmap_width = width;
|
||||
bitmap_height = height;
|
||||
maximum_width = width;
|
||||
maximum_height = height;
|
||||
|
||||
vpos = 0;
|
||||
even_hpos = hpos = 0;
|
||||
even_hpos = 0;
|
||||
sync_counter = 0;
|
||||
seperator_counter = 0;
|
||||
buffer_cleared = 0;
|
||||
minimum_length = 0.05f * sample_rate;
|
||||
minimum_sync_length = 0.002f * sample_rate;
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ void debug_sync()
|
|||
blur_power = -1;
|
||||
*current_mode = mode_debug;
|
||||
current_decoder = decoder_raw;
|
||||
bitmap_width = maximum_width;
|
||||
bitmap_height = maximum_height;
|
||||
sync_length = minimum_sync_length;
|
||||
maximum_length = buffer_length;
|
||||
scanline_length = maximum_length;
|
||||
|
|
@ -39,6 +41,8 @@ void debug_image()
|
|||
blur_power = -1;
|
||||
*current_mode = mode_debug;
|
||||
current_decoder = decoder_raw;
|
||||
bitmap_width = maximum_width;
|
||||
bitmap_height = maximum_height;
|
||||
sync_length = minimum_sync_length;
|
||||
maximum_length = buffer_length;
|
||||
scanline_length = maximum_length;
|
||||
|
|
@ -50,6 +54,8 @@ void debug_both()
|
|||
blur_power = -1;
|
||||
*current_mode = mode_debug;
|
||||
current_decoder = decoder_raw;
|
||||
bitmap_width = maximum_width;
|
||||
bitmap_height = maximum_height;
|
||||
sync_length = minimum_sync_length;
|
||||
maximum_length = buffer_length;
|
||||
scanline_length = maximum_length;
|
||||
|
|
@ -61,6 +67,8 @@ void robot36_mode()
|
|||
blur_power = 2;
|
||||
*current_mode = mode_robot36;
|
||||
current_decoder = decoder_robot36;
|
||||
bitmap_width = 320;
|
||||
bitmap_height = 240;
|
||||
const float tolerance = 0.8f;
|
||||
const float settling_time = 0.0011f;
|
||||
const float sync_seconds = 0.009f;
|
||||
|
|
@ -87,6 +95,8 @@ void robot72_mode()
|
|||
blur_power = 3;
|
||||
*current_mode = mode_robot72;
|
||||
current_decoder = decoder_yuv;
|
||||
bitmap_width = 320;
|
||||
bitmap_height = 240;
|
||||
const float tolerance = 0.8f;
|
||||
const float settling_time = 0.0011f;
|
||||
const float sync_seconds = 0.009f;
|
||||
|
|
@ -117,6 +127,8 @@ void martin1_mode()
|
|||
blur_power = 3;
|
||||
*current_mode = mode_martin1;
|
||||
current_decoder = decoder_rgb;
|
||||
bitmap_width = 320;
|
||||
bitmap_height = 256;
|
||||
const float tolerance = 0.5f;
|
||||
const float sync_seconds = 0.004862f;
|
||||
const float sync_porch_seconds = 0.000572f;
|
||||
|
|
@ -142,6 +154,8 @@ void martin2_mode()
|
|||
blur_power = 2;
|
||||
*current_mode = mode_martin2;
|
||||
current_decoder = decoder_rgb;
|
||||
bitmap_width = 320;
|
||||
bitmap_height = 256;
|
||||
const float tolerance = 0.5f;
|
||||
const float sync_seconds = 0.004862f;
|
||||
const float sync_porch_seconds = 0.000572f;
|
||||
|
|
@ -167,6 +181,8 @@ void scottie1_mode()
|
|||
blur_power = 3;
|
||||
*current_mode = mode_scottie1;
|
||||
current_decoder = decoder_rgb;
|
||||
bitmap_width = 320;
|
||||
bitmap_height = 256;
|
||||
const float tolerance = 0.8f;
|
||||
const float settling_time = 0.0011f;
|
||||
const float sync_seconds = 0.009f;
|
||||
|
|
@ -193,6 +209,8 @@ void scottie2_mode()
|
|||
blur_power = 2;
|
||||
*current_mode = mode_scottie2;
|
||||
current_decoder = decoder_rgb;
|
||||
bitmap_width = 320;
|
||||
bitmap_height = 256;
|
||||
const float tolerance = 0.8f;
|
||||
const float settling_time = 0.0011f;
|
||||
const float sync_seconds = 0.009f;
|
||||
|
|
@ -219,6 +237,8 @@ void scottieDX_mode()
|
|||
blur_power = 5;
|
||||
*current_mode = mode_scottieDX;
|
||||
current_decoder = decoder_rgb;
|
||||
bitmap_width = 320;
|
||||
bitmap_height = 256;
|
||||
const float tolerance = 0.8f;
|
||||
const float settling_time = 0.0011f;
|
||||
const float sync_seconds = 0.009f;
|
||||
|
|
@ -245,6 +265,8 @@ void wrasseSC2_180_mode()
|
|||
blur_power = 4;
|
||||
*current_mode = mode_wrasseSC2_180;
|
||||
current_decoder = decoder_rgb;
|
||||
bitmap_width = 320;
|
||||
bitmap_height = 256;
|
||||
const float tolerance = 0.5f;
|
||||
const float sync_seconds = 0.0055225f;
|
||||
const float sync_porch_seconds = 0.0005f;
|
||||
|
|
|
|||
|
|
@ -29,7 +29,9 @@ static int vis_timeout, vis_length, bit_length;
|
|||
static int break_timeout, break_length;
|
||||
static int leader_timeout, leader_length;
|
||||
static int first_leader_length, second_leader_length;
|
||||
static int buffer_length, bitmap_width, bitmap_height;
|
||||
static int buffer_length, buffer_cleared;
|
||||
static int bitmap_width, bitmap_height;
|
||||
static int maximum_width, maximum_height;
|
||||
static int sync_length, sync_counter, vpos, hpos;
|
||||
static int save_cnt, save_dat, seperator_counter, seperator_length;
|
||||
static int u_sep_begin, u_sep_end, v_sep_begin, v_sep_end;
|
||||
|
|
|
|||
Loading…
Reference in a new issue