[MORTSCRIPT] Indent.mscr - A Simple Script Beautifier - Windows Mobile Apps and Games

Thought I should share this code snippet, because I am sure it does not exist a comparable one.
You simply copy and paste the code listet.
Code:
//
// indent.mscr
//
// © 2014 jwoegerbauer
// GPL v2
//
//
// This indent script changes the appearance of a MSCR script by inserting or deleting whitespace.
// One issue in the formatting of MortScript code is how far each line should be indented from the
// left margin. When the beginning of a statement such as IF or FOR is encountered, the indentation
// level is increased by 1 (one). Consequently when the beginning of a statement such as ENDIF or
// NEXT is encountered, the indentation level is decreased by 1 (one). The indentation (whitespace)
// is calculated as indentation level * TAB
//
// Get script file to be processed: if it's not passed as argument, a dialog will
// be shown you select the file from
fileIN = "" & argv[1]
If( fileIN EQ "" )
fileIN = SelectFile("Select script file",0,"*.mscr", ("Please select script file that should get indented"))
EndIf
If( fileIN EQ "" )
// Quit
Exit
EndIf
fileOUT = fileIN & ".indented"
fileWrites = 0
indentLevel = 0
indentExtra = 0 // only set if SWITCH ... ENDSWITCH detected
lineIN = ReadLine(fileIn)
While(NOT IsEmpty(lineIN))
fileWrites += 1
// Left trim line
idx = 1
While((SubStr(lineIN, idx, 1) EQ " ") || (SubStr(lineIN, idx, 1) EQ "^TAB^"))
idx += 1
EndWhile
lineOUT = SubStr(lineIN, idx)
// Create a copy of trimmed line and convert it to upper case
lineTMP = ToUpper(lineOUT)
// Build indentation string
indentationString = ""
If (indentLevel >= 1)
For idx = 1 To indentLevel
indentationString &= "^TAB^"
Next
EndIf
// Flags
opening = 0
closing = 0
// Ignore if it's a comment line
If((SubStr(lineIn, 1, 1) NE "#") && (SubStr(lineIn, 1, 1) NE "/"))
// Check whether to indent/unindent
opening = ((SubStr(lineTMP, 1, 2) EQ "IF") ? 1 : 0)
If(NOT opening)
opening = ((SubStr(lineTMP, 1, 4) EQ "ELSE") ? 1 : 0)
EndIf
If(NOT opening)
opening = ((SubStr(lineTMP, 1, 6) EQ "ELSEIF") ? 1 : 0)
EndIf
If(NOT opening)
opening = ((SubStr(lineTMP,1, 3) EQ "FOR") ? 1 : 0)
EndIf
If(NOT opening)
opening = ((SubStr(lineTMP, 1, 7) EQ "FOREACH") ? 1 : 0)
EndIf
If(NOT opening)
opening = ((SubStr(lineTMP, 1, 5) EQ "WHILE") ? 1 : 0)
EndIf
If(NOT opening)
opening = ((SubStr(lineTMP, 1, 6) EQ "SWITCH") ? 1 : 0)
EndIf
If(NOT opening)
opening = ((SubStr(lineTMP, 1, 4) EQ "CASE") ? 1 : 0)
indentExtra = (opening ? 1 : 0)
EndIf
If(NOT opening)
opening = ((SubStr(lineTMP, 1, 7) EQ "DEFAULT") ? 1 : 0)
indentExtra = (opening ? 1 : 0)
EndIf
If(NOT opening)
opening = ((SubStr(lineTMP, 1, 6) EQ "REPEAT") ? 1 : 0)
EndIf
If(NOT opening)
opening = ((SubStr(lineTMP, 1, 6) EQ "CHOICE") ? 1 : 0)
EndIf
If(NOT opening)
opening = ((SubStr(lineTMP, 1, 13) EQ "CHOICEDEFAULT") ? 1 : 0)
EndIf
If(NOT opening)
closing = ((SubStr(lineTMP, 1, 5) EQ "ENDIF") ? 1 : 0)
If(NOT closing)
closing = ((SubStr(lineTMP, 1, 4) EQ "NEXT") ? 1 : 0)
EndIf
If(NOT closing)
closing = ((SubStr(lineTMP, 1, 10) EQ "ENDFOREACH") ? 1 : 0)
EndIf
If(NOT closing)
closing = ((SubStr(lineTMP, 1, 8) EQ "ENDWHILE") ? 1 : 0)
EndIf
If(NOT closing)
closing = ((SubStr(lineTMP, 1, 9) EQ "ENDSWITCH") ? 1 : 0)
indentExtra = (closing ? -2 : 0)
EndIf
If(NOT closing)
closing = ((SubStr(lineTMP, 1, 9) EQ "ENDREPEAT") ? 1 : 0)
EndIf
If(NOT closing)
closing = ((SubStr(lineTMP, 1, 9) EQ "ENDCHOICE") ? 1 : 0)
EndIf
EndIf
EndIf
If( closing )
// Rebuild identation string
indentLevel -= 1
// Handle SWITCH ... ENDSWITCH compound statements
If (indentExtra <> 0)
indentLevel += indentExtra
indentExtra = 0
EndIf
indentationString = ""
If (indentLevel >= 1)
For idx = 1 To indentLevel
indentationString &= "^TAB^"
Next
EndIf
EndIf
// Create line to be output
lineOUT = (indentationString & lineOUT & "^NL^")
fileAppend = ((fileWrites > 1) ? 1 : 0)
WriteFile(fileOUT, lineOUT, fileAppend)
// Force re-calculate indentation
If(opening)
// Handle SWITCH ... ENDSWITCH compound statements
If (indentExtra > 0)
indentLevel += indentExtra
indentExtra = 0
EndIf
indentLevel += 1
EndIf
lineIN = ReadLine(fileIn)
EndWhile
// Done
Exit
HTH

Related

[REQ] to565 program

Can someone give me link for working to565 program which helps convert raw image files to rle ?
1. Need linux.
2. Script. Name Do.sh
Code:
#!/bin/sh
convert -depth 8 logo.png rgb:logo.raw
./to565 -rle < logo.raw > initlogo.rle
And source. Name to565.c
Code:
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#define to565(r,g,b) \
((((r) >> 3) << 11) | (((g) >> 2) << 5) | ((b) >> 3))
#define from565_r(x) ((((x) >> 11) & 0x1f) * 255 / 31)
#define from565_g(x) ((((x) >> 5) & 0x3f) * 255 / 63)
#define from565_b(x) (((x) & 0x1f) * 255 / 31)
void to_565_raw(void)
{
unsigned char in[3];
unsigned short out;
while(read(0, in, 3) == 3) {
out = to565(in[0],in[1],in[2]);
write(1, &out, 2);
}
return;
}
void to_565_raw_dither(int width)
{
unsigned char in[3];
unsigned short out;
int i = 0;
int e;
int* error = malloc((width+2) * 3 * sizeof(int));
int* next_error = malloc((width+2) * 3 * sizeof(int));
memset(error, 0, (width+2) * 3 * sizeof(int));
memset(next_error, 0, (width+2) * 3 * sizeof(int));
error += 3; // array goes from [-3..((width+1)*3+2)]
next_error += 3;
while(read(0, in, 3) == 3) {
int r = in[0] + error[i*3+0];
int rb = (r < 0) ? 0 : ((r > 255) ? 255 : r);
int g = in[1] + error[i*3+1];
int gb = (g < 0) ? 0 : ((g > 255) ? 255 : g);
int b = in[2] + error[i*3+2];
int bb = (b < 0) ? 0 : ((b > 255) ? 255 : b);
out = to565(rb, gb, bb);
write(1, &out, 2);
#define apply_error(ch) { \
next_error[(i-1)*3+ch] += e * 3 / 16; \
next_error[(i)*3+ch] += e * 5 / 16; \
next_error[(i+1)*3+ch] += e * 1 / 16; \
error[(i+1)*3+ch] += e - ((e*1/16) + (e*3/16) + (e*5/16)); \
}
e = r - from565_r(out);
apply_error(0);
e = g - from565_g(out);
apply_error(1);
e = b - from565_b(out);
apply_error(2);
#undef apply_error
++i;
if (i == width) {
// error <- next_error; next_error <- 0
int* temp = error; error = next_error; next_error = temp;
memset(next_error, 0, (width+1) * 3 * sizeof(int));
i = 0;
}
}
free(error-3);
free(next_error-3);
return;
}
void to_565_rle(void)
{
unsigned char in[3];
unsigned short last, color, count;
unsigned total = 0;
count = 0;
while(read(0, in, 3) == 3) {
color = to565(in[0],in[1],in[2]);
if (count) {
if ((color == last) && (count != 65535)) {
count++;
continue;
} else {
write(1, &count, 2);
write(1, &last, 2);
total += count;
}
}
last = color;
count = 1;
}
if (count) {
write(1, &count, 2);
write(1, &last, 2);
total += count;
}
fprintf(stderr,"%d pixels\n",total);
}
int main(int argc, char **argv)
{
if ((argc == 2) && (!strcmp(argv[1],"-rle"))) {
to_565_rle();
} else {
if (argc > 2 && (!strcmp(argv[1], "-w"))) {
to_565_raw_dither(atoi(argv[2]));
} else {
to_565_raw();
}
}
return 0;
}
Then build.
Code:
gcc -o to565 to565.c
Can you put the to565 program in $PATH?
Will the to565 program work if you put it in the $PATH?

[Q] how to restore a deleted application without the usb debug ?

My question is very simple and hopefully the great teachers in this forum can answer.
how to go and change the file in system / build.prop without activating usb debuging?
how to restore all my apps in / system / which have been erased without activating usb debuging?
<< ycusoy | http://admin-belajar.blogspot.com >>
Bonus: text mouse rotate
Code:
<style type="text/css">
/* Circle Text Styles */
#outerCircleText {
/* Optional - DO NOT SET FONT-SIZE HERE, SET IT IN THE SCRIPT */
font-style: italic;font-weight: bold;font-family: 'comic sans ms', verdana, arial;color: #000;
/* End Optional *//* Start Required - Do Not Edit*/
position: absolute;top: 0;left: 0;z-index: 3000;cursor: default;}#outerCircleText div {position: relative;}#outerCircleText div div {position: absolute;top: 0;left: 0;text-align: center;}
/* End Required *//* End Circle Text Styles */
</style>
<script type="text/javascript">
;(function(){ // Your message here (QUOTED STRING)
var msg = "http://forum.xda-developers.com/editpost.php?do=editpost&postid=26043694";
/* THE REST OF THE EDITABLE VALUES BELOW ARE ALL UNQUOTED NUMBERS */// Set font's style size for calculating dimensions// Set to number of desired pixels font size (decimal and negative numbers not allowed)
var size = 14;
// Set both to 1 for plain circle, set one of them to 2 for oval// Other numbers & decimals canhave interesting effects, keep these low (0 to 3)
var circleY = 0.75; var circleX = 2;
// The larger this divisor, the smaller the spaces between letters// (decimals allowed, not negative numbers)
var letter_spacing = 5;
// The larger this multiplier, the bigger the circle/oval// (decimals allowed, not negative numbers, some rounding is applied)
var diameter = 10; // Rotation speed, set it negative if you want it to spin clockwise (decimals allowed)
var rotation = 0.4; // This is not the rotation speed,its the reaction speed, keep low!// Set this to 1 or a decimal less than one (decimals allowed, not negative numbers)
var speed = 0.3;
////////////////////// Stop Editing //////////////////////
if (!window.addEventListener &&!window.attachEvent ||!document.createElement) return;msg = msg.split('');var n = msg.length - 1, a = Math.round(size * diameter * 0.208333), currStep = 20,ymouse = a * circleY + 20, xmouse = a * circleX + 20, y = [], x = [], Y = [], X = [],o = document.createElement('div'), oi= document.createElement('div'),b = document.compatMode && document.compatMode !="BackCompat"? document.documentElement : document.body,mouse = function(e){e = e || window.event;ymouse = !isNaN(e.pageY)? e.pageY : e.clientY;
//
y-positionxmouse = !isNaN(e.pageX)? e.pageX : e.clientX;
//
x-position},makecircle = function(){
// rotation/positioning
if(init.nopy){ o.style.top = (b || document.body).scrollTop + 'px'; o.style.left = (b || document.body).scrollLeft + 'px';};currStep -= rotation;for (var d, i = n; i > -1; --i){
// makes the circle
d = document.getElementById('iemsg'+ i).style; d.top = Math.round(y[i] + a * Math.sin((currStep + i) / letter_spacing) * circleY - 15) + 'px'; d.left = Math.round(x[i] + a * Math.cos((currStep + i) / letter_spacing) * circleX) + 'px';};},drag = function(){
// makes the resistancey
[0] = Y[0] += (ymouse - Y[0]) * speed;x[0] = X[0] += (xmouse - 20 - X[0]) * speed;for (var i = n; i > 0; --i){ y[i] = Y[i] += (y[i-1] - Y[i]) * speed; x[i] = X[i] += (x[i-1] - X[i]) * speed;};makecircle();},init = function(){
// appends message divs, & sets initial values for positioning arrays
if(!isNaN(window.pageYOffset)){ ymouse += window.pageYOffset; xmouse += window.pageXOffset;} else init.nopy = true;for (var d, i = n; i > -1; --i){ d = document.createElement('div'); d.id = 'iemsg' + i; d.style.height = d.style.width = a+ 'px'; d.appendChild(document.createTextNode(msg[i])); oi.appendChild(d); y[i] = x[i] = Y[i]= X[i] = 0;};o.appendChild(oi); document.body.appendChild(o);setInterval(drag, 25);},ascroll = function(){ymouse += window.pageYOffset;xmouse += window.pageXOffset;window.removeEventListener('scroll', ascroll, false);};o.id = 'outerCircleText'; o.style.fontSize = size + 'px';if (window.addEventListener){window.addEventListener('load', init, false);document.addEventListener('mouseover', mouse, false);document.addEventListener('mousemove', mouse, false); if (/Apple/.test(navigator.vendor)) window.addEventListener('scroll', ascroll, false);}else if (window.attachEvent){window.attachEvent('onload', init);document.attachEvent('onmousemove', mouse);};})();</script>
paste before closing tag </head>

[Q]How can I merege two *.wav files?

I looked all over the net and I couldn't find something that works.
First there is this:
Code:
File wave1 = new File(wavFile1);
if(!wave1.exists())
throw new Exception(wave1.getPath() + " - File Not Found");
AudioInputStream clip1 = AudioSystem.getAudioInputStream(wave1);
AudioInputStream clip2 = AudioSystem.getAudioInputStream(new File(wavFile2));
AudioInputStream emptyClip =
AudioSystem.getAudioInputStream(new File(emptyWavPath));
AudioInputStream appendedFiles =
new AudioInputStream(
new SequenceInputStream(clip1, emptyClip),
clip1.getFormat(),
clip1.getFrameLength() + 100
);
clip1 = appendedFiles;
appendedFiles =
new AudioInputStream(
new SequenceInputStream(clip1, clip2),
clip1.getFormat(),
clip1.getFrameLength() + clip2.getFrameLength()
);
but android dosen't support java.sound.sampled
there is also this:
Code:
private void merge2WavFiles(String wavFile1, String wavFile2, String newWavFilePath) {
long RECORDER_SAMPLERATE = 44100;
long RECORDER_BPP = 16;
FileInputStream in1 = null, in2 = null;
FileOutputStream out = null;
long totalAudioLen = 0;
long totalDataLen = totalAudioLen + 36;
long longSampleRate = RECORDER_SAMPLERATE;
int channels = 2;
long byteRate = RECORDER_BPP * RECORDER_SAMPLERATE * channels / 8;
byte[] data = new byte[100];
try {
in1 = new FileInputStream(wavFile1);
in2 = new FileInputStream(wavFile2);
out = new FileOutputStream(newWavFilePath);
totalAudioLen = in1.getChannel().size() + in2.getChannel().size();
totalDataLen = totalAudioLen + 36;
WriteWaveFileHeader(out, totalAudioLen, totalDataLen, longSampleRate, channels, byteRate);
while (in1.read(data) != -1) {
out.write(data);
}
while (in2.read(data) != -1) {
out.write(data);
}
out.close();
in1.close();
in2.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
private void WriteWaveFileHeader(FileOutputStream out, long totalAudioLen,
long totalDataLen, long longSampleRate, int channels, long byteRate)
throws IOException {
byte[] header = new byte[44];
header[0] = 'R';
header[1] = 'I';
header[2] = 'F';
header[3] = 'F';
header[4] = (byte)(totalDataLen & 0xff);
header[5] = (byte)((totalDataLen >> 8) & 0xff);
header[6] = (byte)((totalDataLen >> 16) & 0xff);
header[7] = (byte)((totalDataLen >> 24) & 0xff);
header[8] = 'W';
header[9] = 'A';
header[10] = 'V';
header[11] = 'E';
header[12] = 'f';
header[13] = 'm';
header[14] = 't';
header[15] = ' ';
header[16] = 16;
header[17] = 0;
header[18] = 0;
header[19] = 0;
header[20] = 1;
header[21] = 0;
header[22] = (byte) channels;
header[23] = 0;
header[24] = (byte)(longSampleRate & 0xff);
header[25] = (byte)((longSampleRate >> 8) & 0xff);
header[26] = (byte)((longSampleRate >> 16) & 0xff);
header[27] = (byte)((longSampleRate >> 24) & 0xff);
header[28] = (byte)(byteRate & 0xff);
header[29] = (byte)((byteRate >> 8) & 0xff);
header[30] = (byte)((byteRate >> 16) & 0xff);
header[31] = (byte)((byteRate >> 24) & 0xff);
header[32] = (byte)(2 * 16 / 8);
header[33] = 0;
header[34] = 16;
header[35] = 0;
header[36] = 'd';
header[37] = 'a';
header[38] = 't';
header[39] = 'a';
header[40] = (byte)(totalAudioLen & 0xff);
header[41] = (byte)((totalAudioLen >> 8) & 0xff);
header[42] = (byte)((totalAudioLen >> 16) & 0xff);
header[43] = (byte)((totalAudioLen >> 24) & 0xff);
out.write(header, 0, 44);
}
but is also dosen't work.
In all cases the result sound file is empty without sound.
How can I merge two *.wav files?
I m also searching for months like MP3 EDITOR LIKE software..which can combine two or more sound file and make one..
But all apps i found is just mp3 cutter..
There is one app in symbian os my friend have in his c6
Which do editing i forgot the name but for sure in android i have not found one since six months
we all should be polite enough to press thanks for anyone who helped US.

Allwinner A23 Tablet: Launching Camera App freezes Tablet.

Hello i changed the Rom on my Tablet to :
PH_A76h_android4.4_v2.0_800x480-auto-gc2035-gc0308-wifi5990p-20141211a.img
Everything works okay, but not the Camera.
The Tablet has 2 Cameras Front and Back with 0,3 Mpixels each.
The are on the same Cable going from the Mainboard to the FrontCam and then to the Back Camera.
When i launch the App the Tablet freezes.. Sometimes it resets itself after an Minute or so (not always)
BTW:
I have saved the Data of the Nand-Partitions with the old Firmware (if you need some infos/settings/config from them)
I also have changed the script0.bin from the old Firmware to fex and changed everything in DragonFaces SystemConfiguration like it was in the Script0.bin from the original Firmware.
Here is the Block i Changed in System-Editor:
Code:
;--------------------------------------------------------------------------------
;vip (video input port) configuration
;vip_used: 0:disable 1:enable
;vip_mode: 0:sample one interface to one buffer 1:sample two interface to one buffer
;vip_dev_qty: The quantity of devices linked to capture bus
;vip_dev(x)_isp_used 0: not use isp 1:use isp
;vip_dev(x)_fmt: 0:yuv 1:bayer raw rgb
;vip_dev(x)_stby_mode: 0:not shut down power at standby 1:shut down power at standby
;vip_dev(x)_vflip: flip in vertical direction 0:disable 1:enable
;vip_dev(x)_hflip: flip in horizontal direction 0:disable 1:enable
;vip_dev(x)_iovdd: camera module io power handle string, pmu power supply
;vip_dev(x)_iovdd_vol: camera module io power voltage, pmu power supply
;vip_dev(x)_avdd: camera module analog power handle string, pmu power supply
;vip_dev(x)_avdd_vol: camera module analog power voltage, pmu power supply
;vip_dev(x)_dvdd: camera module core power handle string, pmu power supply
;vip_dev(x)_dvdd_vol: camera module core power voltage, pmu power supply
;vip_dev(x)_afvdd: camera module vcm power handle string, pmu power supply
;vip_dev(x)_afvdd_vol: camera module vcm power voltage, pmu power supply
;x indicates the index of the devices which are linked to the same capture bus
;fill voltage in uV, e.g. iovdd = 2.8V, vip_devx_iovdd_vol = 2800000
;fill handle string as below:
;axp22_eldo3
;axp22_dldo4
;axp22_eldo2
;fill handle string "" when not using any pmu power supply
;--------------------------------------------------------------------------------
[csi0]
vip_used = 1
vip_mode = 0
vip_dev_qty = 2
vip_csi_pck = port:PE00<2><default><default><default>
vip_csi_mck = port:PE01<2><default><default><default>
vip_csi_hsync = port:PE02<2><default><default><default>
vip_csi_vsync = port:PE03<2><default><default><default>
vip_csi_d0 = port:PE04<2><default><default><default>
vip_csi_d1 = port:PE05<2><default><default><default>
vip_csi_d2 = port:PE06<2><default><default><default>
vip_csi_d3 = port:PE07<2><default><default><default>
vip_csi_d4 = port:PE08<2><default><default><default>
vip_csi_d5 = port:PE09<2><default><default><default>
vip_csi_d6 = port:PE10<2><default><default><default>
vip_csi_d7 = port:PE11<2><default><default><default>
vip_dev0_mname = "siv121d"
vip_dev0_lane = 1
vip_dev0_twi_id = 2
vip_dev0_twi_addr = 102
vip_dev0_isp_used = 0
vip_dev0_fmt = 0
vip_dev0_stby_mode = 0
vip_dev0_vflip = 0
vip_dev0_hflip = 0
vip_dev0_iovdd = "axp22_dldo3"
vip_dev0_iovdd_vol = 2800000
vip_dev0_avdd = "axp22_ldoio0" vip_dev0_avdd_vol = 2800000
vip_dev0_dvdd = "axp22_eldo2" vip_dev0_dvdd_vol = 1800000
vip_dev0_afvdd = ""
vip_dev0_afvdd_vol = 2800000
vip_dev0_power_en =
vip_dev0_reset = port:PE14<1><default><default><0>
vip_dev0_pwdn = port:PE15<1><default><default><1>
vip_dev0_flash_en = port:PB00<1><default><default><0>
vip_dev0_flash_mode =
vip_dev0_af_pwdn =
vip_dev1_mname = "siv121d"
vip_dev1_lane = 1
vip_dev1_twi_id = 2
vip_dev1_twi_addr = 102
vip_dev1_isp_used = 0
vip_dev1_fmt = 0
vip_dev1_stby_mode = 0
vip_dev1_vflip = 0
vip_dev1_hflip = 0
vip_dev1_iovdd = "axp22_dldo3"
vip_dev1_iovdd_vol = 2800000
vip_dev1_avdd = "axp22_ldoio0"
vip_dev1_avdd_vol = 2800000
vip_dev1_dvdd = "axp22_eldo2"
vip_dev1_dvdd_vol = 1800000
vip_dev1_afvdd = ""
vip_dev1_afvdd_vol = 2800000
vip_dev1_power_en =
vip_dev1_reset = port:PE16<1><default><default><0>
vip_dev1_pwdn = port:PE17<1><default><default><1>
vip_dev1_flash_en = port:PB00<1><default><default><0>
vip_dev1_flash_mode =
vip_dev1_af_pwdn =
[camera_list_para]
camera_list_para_used = 0
ov7670 = 0
gc0308 = 1
gt2005 = 0
hi704 = 0
sp0838 = 0
mt9m112 = 0
mt9m113 = 0
gc2035 = 1
ov2655 = 0
hi253 = 1
gc0307 = 0
mt9d112 = 0
ov5640 = 0
ov5647 = 0
gc2015 = 0
ov2643 = 0
gc0329 = 0
gc0309 = 0
s5k4ec = 0
siv121d = 0
siv120d = 0
I also copied camera.cfg from the old /system/etc to the new installation.
But still freezes don't know what to do now.
Please help.

What Should I Do If a HUAWEI Quick App Freezes When the canvas Component Draws an Image Using setInterval?

Symptom: In a quick app, the setInterval function is used to cyclically execute the code for using canvas. However, the quick app freezes when rendering an image on a Huawei phone.
The code where the exception occurs is as follows:
JavaScript:
click0() {
this.speed = 0.3
let ctx = this.$element('canvas').getContext('2d')
setInterval(() => {
this.num0 += 2
this.noise = Math.min(0.5, 1) * this.MAX
this._draw(ctx)
this.MAX <= 200 && (this.MAX += 4)
}, 20)
},
_draw(ctx) {
this.phase = (this.phase + this.speed) % (Math.PI * 64)
ctx.clearRect(0, 0, this.width, this.height)
this._drawLine(ctx, -2, 'rgba(0, 194, 255, 0.2)')
this._drawLine(ctx, -6, 'rgba(0, 194, 255, 0.4)')
this._drawLine(ctx, 4, 'rgba(0, 194, 255, 0.6)')
this._drawLine(ctx, 2, 'rgba(0, 194, 255, 0.8)')
this._drawLine(ctx, 1, 'rgba(0, 194, 255, 1)', 4)
},
Cause Analysis:
The canvas drawing in the this._draw() method takes a long time, at least 100 ms. However, the time interval is only 20 ms. Huawei Quick App Loader will execute the code again after 20 ms, which is much shorter than 100 ms, causing the drawing to stutter.
Solution:
You can first obtain the service provider by calling the API for querying device information to determine whether the quick app is supported by Huawei Quick App Loader. If so, set the time interval to longer than 100 ms. The sample code is as follows (please refer to the red portions):
JavaScript:
onShow: function () {
var that = this
device.getInfo({
success: function (ret) {
console.log("handling success:", JSON.stringify(ret));
that.engineProvider = ret.engineProvider;
},
fail: function (erromsg, errocode) {
console.log("message:", erromsg, errocode);
}
})
},
click0() {
var that = this
this.speed = 0.3
console.log(that.engineProvider)
let ctx = this.$element('canvas').getContext('2d')
if (that.engineProvider === "huawei") {
setInterval(() => {
this.num0 += 2
this.noise = Math.min(0.5, 1) * this.MAX
this._draw(ctx)
this.MAX <= 200 && (this.MAX += 4)
}, 120)
} else {
setInterval(() => {
this.num0 += 2
this.noise = Math.min(0.5, 1) * this.MAX
this._draw(ctx)
this.MAX <= 200 && (this.MAX += 4)
}, 20)
}
},
_draw(ctx) {
this.phase = (this.phase + this.speed) % (Math.PI * 64)
ctx.clearRect(0, 0, this.width, this.height)
this._drawLine(ctx, -2, 'rgba(0, 194, 255, 0.2)')
this._drawLine(ctx, -6, 'rgba(0, 194, 255, 0.4)')
this._drawLine(ctx, 4, 'rgba(0, 194, 255, 0.6)')
this._drawLine(ctx, 2, 'rgba(0, 194, 255, 0.8)')
this._drawLine(ctx, 1, 'rgba(0, 194, 255, 1)', 4)
},
_drawLine(ctx, attenuation, color, width) {
ctx.save()
ctx.moveTo(0, 0);
ctx.beginPath();
ctx.strokeStyle = color;
ctx.lineWidth = width || 1;
var x, y;
for (var i = -this.K; i <= this.K; i += 0.01) {
x = this.width * ((i + this.K) / (this.K * 2))
y = this.height / 2 + this.noise * this._globalAttenuationFn(i) * (1 / attenuation) * Math.sin(this.F * i - this.phase)
ctx.lineTo(x, y)
}
ctx.stroke()
ctx.restore()
},
References:
Introduction to the canvas API:
https://developer.huawei.com/consumer/en/doc/development/quickApp-References/quickapp-api-canvas
Quick app materials: https://developer.huawei.com/consumer/en/doc/development/quickApp-Guides/quickapp-whitepaper

Categories

Resources