Skip to content

Commit 22981cc

Browse files
authored
Merge branch 'master' into ding/mark-region-in-source-2
2 parents b1ef2be + 9d31b3f commit 22981cc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2549
-9
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ or
117117

118118
where only the part that starts from `Error:` will be compared. Line number is be ignored as it varies. If line number is needed for a particular reason, it can be appended to the back.
119119

120-
> **Note**: for virtual machine tests, you will have to make a function that outputs a single line output without the help of any `displays()`, as the test currently only supports 1 line comparison. Help to make this generic is appreciated.
121-
122120
> Integration of the `test` script with `src/test/framework/` is pending a fix to the `--variant` parameter; any help appreciated.
123121
124122
# License

scripts/test.sh

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#! /usr/bin/env bash
22

3-
JS_SLANG="node --stack-size=2000 node_modules/js-slang/dist/repl/repl.js"
3+
JS_SLANG="node --stack-size=4000 node_modules/js-slang/dist/repl/repl.js"
44

55
# must use BSD awk
66
AWK="awk"
@@ -24,16 +24,31 @@ failed=0
2424
# $4 is the variant
2525

2626
test_source() {
27+
# read in test file to find the number of comment lines
28+
IFS=$'\n' read -d '' -r -a lines < $2
29+
NUM_VALID_COMMENT=0
30+
31+
for ((i=${#lines[@]}-1;i >= 0; i--))
32+
do
33+
COMMENT=$(echo "${lines[i]}" | grep ^//)
34+
if [ -z "$COMMENT" ]
35+
then
36+
break
37+
else
38+
((NUM_VALID_COMMENT++))
39+
fi
40+
done
41+
2742

2843
# if program throws error, ignore the output and compare the error message only
2944
# NOTE: error output line is striped of line number as it is machine dependent
3045
ERROR=$( { $JS_SLANG -e --chapter=$3 "$(cat $1 $2)">$DIR/__tests__/output; } 2>&1 )
3146
if [ ! -z "$ERROR" ]
3247
then
33-
DIFF=$(diff <(echo $ERROR | grep -o 'Error:.*') <(cat $2 | tail -1 | grep -o 'Error:.*'))
48+
DIFF=$(diff <(echo $ERROR | grep -o 'Error:.*') <(cat $2 | tail -$NUM_VALID_COMMENT | grep -o 'Error:.*'))
3449
else
3550
DIFF=$(diff <(cat $DIR/__tests__/output) \
36-
<(cat $2 | tail -1 | cut -c4-))
51+
<(cat $2 | tail -$NUM_VALID_COMMENT | cut -c4-))
3752
fi
3853

3954
if [ "$DIFF" = "" ]
@@ -43,7 +58,6 @@ $DIFF"
4358
fi
4459
# clean up temp file
4560
rm $DIR/__tests__/output
46-
4761
}
4862

4963
test_source_framework() {

src/evaluators/__tests__/source-2-non-det.test5.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require(! (baker === 5)); \
1010
require(! (cooper === 1)); \
1111
require(! (fletcher === 5)); \
1212
require(! (fletcher === 1)); \
13-
require(! (miller > cooper)); \
13+
require( miller > cooper ); \
1414
require(! ((math_abs(smith - fletcher)) === 1)); \
1515
require(! ((math_abs(fletcher - cooper)) === 1)); \
1616
return list(list('baker', baker), \
@@ -28,4 +28,4 @@ function print_one_line_list(li) {
2828
return result;
2929
}
3030
print_one_line_list(result);
31-
// 'baker1,cooper4,fletcher2,miller3,smith5,'
31+
// 'baker3,cooper2,fletcher4,miller5,smith1,'

src/evaluators/source-2-non-det.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ function parse_and_run(str) {
869869
// require(! (cooper === 1)); \
870870
// require(! (fletcher === 5)); \
871871
// require(! (fletcher === 1)); \
872-
// require(! (miller > cooper)); \
872+
// require(miller > cooper); \
873873
// require(! ((math_abs(smith - fletcher)) === 1)); \
874874
// require(! ((math_abs(fletcher - cooper)) === 1)); \
875875
// return list(list('baker', baker), \
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Here 13 filters that you can use in your codes and other video and multimedia.
2+
Brief descriptions for them :-
3+
4+
1. Blur3x3 :- Blurs using a 3*3 mask
5+
2. Blur5x5 :- Blurs using a 5*5 mask, (277.78%) more effective than 3*3 mask.
6+
3. Cos_distortion :- Blurs by modifying pixels according to a cosine wave.
7+
[Various parameters like wave-length and distortion constant, can be varied to see various types of effects.]
8+
4. Sine_distortion :- Same as above, except it uses sine properties. (*2)
9+
5. Invert :- Inverts the colors, ie, shows the multimedia in the contrast color
10+
6. Upside down :- Inverts the multimedia upside down.
11+
7. Motion Detector:- Detects motion in videos and highlights the areas where the motion is happening
12+
8. Green Background :- Marks sharp contrasts in the background to green them, so that the face and other-contrast-parity objects can be brought to focus
13+
9. Frame Rate (Continuous) :- Continuously prints the video's Frame Rate
14+
10. Frame_Rate (Single) :- Prints Frame rate for a video for the initial frame, and then stops.
15+
11. Ping (Continous) :- Ping is the time between two consecutive frames. Continuously prints the ping for a video. [Has extensive applications in games, etc].
16+
12. Ping (Single) :- Prints the initial value of ping and then stops.
17+
18+
Other filters that I have researched can can be added to this collection :-
19+
1. Converting the video to black and white
20+
2. Coloring the video (B&W to Color)
21+
3. Segmentation
22+
4. Edge detection
23+
and so on
24+
25+
As per the knowledege I could gain from the Source $4 GPU document(*1), I have tried to bring as many of these filters to Source $4 GPU, however, since I could not find ways to convert all forms of code into this format, some codes are yet on their way to this destination.
26+
27+
I am sure, with code improvisations, this can be extended to a library of faster filters catering to all types of requirements.
28+
29+
Further scope of improvement:-
30+
Undoubtedly, this branch of Source Academy has room for tremendous improvement with various new filters. Apart from that, we can improve the error-handling portion. It's not a big deal to report these errors from console to REPL for the user's consideration, but also to minimum their occurence.
31+
32+
Credits :-
33+
I would love to thank my professor, batchmates and friends who helped me in this Project, especially who spent the nights together with me to make it work.
34+
35+
(*1) I have added the document along for further consideration by other people.
36+
(*2) It might feel that the sine and cosine filters are similar, but the images they impact have a significant difference. Feel free to play with them to know the difference.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
function blur3x3(src, dest)
2+
{
3+
const WIDTH = get_video_width();
4+
const HEIGHT = get_video_height();
5+
6+
for(let y=0; y<HEIGHT; y = y + 1)
7+
{
8+
9+
dest[0][y] = src[0][y];
10+
dest[WIDTH-1][y] = src[WIDTH-1][y];
11+
12+
}
13+
14+
for(let x=0; x<WIDTH; x = x + 1)
15+
{
16+
let r1=src[x][0][0];
17+
let g1=src[x][0][1];
18+
let b1=src[x][0][2];
19+
20+
let new_height = HEIGHT-1;
21+
22+
let r2=src[x][new_height][0];
23+
let g2=src[x][new_height][1];
24+
let b2=src[x][new_height][2];
25+
26+
dest[x][0] = [r1,g1,b1];
27+
dest[x][new_height] = [r2,b2,g2];
28+
29+
}
30+
31+
32+
const WIDTH1= WIDTH -2;
33+
const HEIGHT1= HEIGHT-2;
34+
for(let x=0; x<WIDTH1; x = x + 1)
35+
{
36+
for (let y=0; y<HEIGHT1; y = y + 1)
37+
{
38+
39+
let r=src[x][y][0]+
40+
src[x][y+1][0]+
41+
src[x][y+2][0]+
42+
src[x+1][y][0]+
43+
src[x+1][y+1][0]+
44+
src[x+1][y+2][0]+
45+
src[x+2][y][0]+
46+
src[x+2][y+1][0]+
47+
src[x+2][y+2][0];
48+
let g=src[x][y][1]+
49+
src[x][y+1][1]+
50+
src[x][y+2][1]+
51+
src[x+1][y][1]+
52+
src[x+1][y+1][1]+
53+
src[x+1][y+2][1]+
54+
src[x+2][y][1]+
55+
src[x+2][y+1][1]+
56+
src[x+2][y+2][1];
57+
let b=src[x][y][2]+
58+
src[x][y+1][2]+
59+
src[x][y+2][2]+
60+
src[x+1][y][2]+
61+
src[x+1][y+1][2]+
62+
src[x+1][y+2][2]+
63+
src[x+2][y][2]+
64+
src[x+2][y+1][2]+
65+
src[x+2][y+2][2];
66+
67+
r = r/9;
68+
b = b/9;
69+
g = g/9;
70+
71+
dest[x][y] = [r,g,b];
72+
}
73+
}
74+
}
75+
76+
// apply_filter(blur3x3);
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
function blur5x5(src, dest)
2+
{
3+
const WIDTH = get_video_width();
4+
const HEIGHT = get_video_height();
5+
6+
for(let y=0; y<HEIGHT; y = y + 1)
7+
{
8+
dest[0][y] = src[0][y];
9+
dest[1][y] = src[1][y];
10+
dest[WIDTH-1][y] = src[WIDTH-1][y];
11+
dest[WIDTH-2][y] = src[WIDTH-2][y];
12+
13+
}
14+
15+
for(let x=0; x<WIDTH; x = x + 1)
16+
{
17+
dest[x][0] = src[x][0];
18+
dest[x][1] = src[x][1];
19+
dest[x][HEIGHT-1] = src[x][HEIGHT-1];
20+
dest[x][HEIGHT-2] = src[x][HEIGHT-2];
21+
22+
}
23+
const WIDTH4=WIDTH-4;
24+
const HEIGHT4=HEIGHT-4;
25+
for(let x=0; x<WIDTH4; x = x + 1)
26+
{
27+
for (let y=0; y<HEIGHT4; y = y + 1)
28+
{
29+
let sum1 = 0;
30+
let sum2 = 0;
31+
let sum3 = 0;
32+
33+
for(let i=0; i < 5; i=i+1)
34+
{
35+
36+
for(let j=0; j < 5; j=j+1)
37+
{
38+
sum1 = sum1 + (src[x+i][y+j][0]);
39+
sum2 = sum2 + (src[x+i][y+j][1]);
40+
sum3 = sum3 + (src[x+i][y+j][2]);
41+
}
42+
}
43+
sum1 = sum1 / 9;
44+
sum2 = sum2 / 9;
45+
sum3 = sum3 / 9;
46+
// dest[x][y]=dest[x][y];
47+
48+
dest[x][y] = [sum1, sum2, sum3];
49+
}
50+
}
51+
}
52+
// apply_filter(blur5x5);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
function cos_distortion(src, dest)
2+
{
3+
let wave_length = 5 * (2 * math_PI);
4+
let distortion = 10;
5+
6+
let WIDTH = get_video_width();
7+
let HEIGHT = get_video_height();
8+
9+
let mid_x = WIDTH/2;
10+
let mid_y = HEIGHT/2;
11+
for(let x=0; x<WIDTH; x = x + 1)
12+
{
13+
for(let y=0; y<HEIGHT; y = y + 1)
14+
{
15+
let d_x = math_abs(mid_x - x);
16+
let d_y = math_abs(mid_y - y);
17+
let d = d_x + d_y;
18+
let s = math_round(distortion * math_cos( d / wave_length));
19+
let x_raw = x + s;
20+
let y_raw = y + s;
21+
let x_src = math_max(0,math_min(WIDTH - 1, x_raw));
22+
let y_src = math_max(0,math_min(HEIGHT - 1, y_raw));
23+
dest[x][y] = src[x_src][y_src];
24+
}
25+
}
26+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
let x=0;
2+
let ini= runtime();
3+
4+
function framerate_cont(src,dest)
5+
{
6+
let today= runtime();
7+
let z=1000.0/(today-ini);
8+
display(z);
9+
ini=today;
10+
x=x+1;
11+
12+
13+
}
14+
15+
// apply_filter(framerate_cont);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
let x=0;
2+
let ini= runtime();
3+
4+
function framerate_single(src,dest)
5+
{
6+
let today= runtime();
7+
let z=1000.0/(today-ini);
8+
if(x===1)
9+
{
10+
display(z);
11+
}
12+
else
13+
{
14+
x=x;
15+
}
16+
ini=today;
17+
x=x+1;
18+
}
19+
20+
// apply_filter(framerate_single);

0 commit comments

Comments
 (0)