Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.

Commit 9548d13

Browse files
committed
Revert "Remove Marvinj", make Seriously.js optional available
This reverts commit 21f4575. Change-Id: I0d620f96a26f08336470c74fdd4f68d1fcccb854
1 parent 21f4575 commit 9548d13

File tree

8 files changed

+135
-32
lines changed

8 files changed

+135
-32
lines changed

chromakeying.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,12 @@
9494
<script src="node_modules/whatwg-fetch/dist/fetch.umd.js"></script>
9595
<script type="text/javascript" src="api/config.php"></script>
9696
<script type="text/javascript" src="node_modules/jquery/dist/jquery.min.js"></script>
97+
<?php if ($config['chroma_keying_variant'] === 'marvinj'): ?>
98+
<script type="text/javascript" src="node_modules/marvinj/marvinj/release/marvinj-1.0.js"></script>
99+
<?php else:?>
97100
<script type="text/javascript" src="vendor/Seriously/seriously.js"></script>
98101
<script type="text/javascript" src="vendor/Seriously/effects/seriously.chroma.js"></script>
102+
<?php endif; ?>
99103
<script type="text/javascript" src="resources/js/chromakeying.js"></script>
100104
<script type="text/javascript" src="resources/js/theme.js"></script>
101105
<script src="node_modules/@andreasremdt/simple-translator/dist/umd/translator.min.js"></script>

config/config.inc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
$config['collage_layout'] = '2x2'; // possible values are '2x2' or '2x4'
5151
$config['collage_background'] = '../resources/img/frames/DefaultCollageBackground.png';
5252
$config['chroma_keying'] = false;
53+
$config['chroma_keying_variant'] = 'marvinj'; // possible values: 'marvinj', 'seriouslyjs'
5354
$config['use_collage'] = true;
5455
$config['continuous_collage'] = true;
5556
$config['background_image'] = null;

lib/configsetup.inc.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,16 @@
235235
'name' => 'chroma_keying',
236236
'value' => $config['chroma_keying']
237237
],
238+
'chroma_keying_variant' => [
239+
'type' => 'select',
240+
'name' => 'chroma_keying_variant',
241+
'placeholder' => $defaultConfig['chroma_keying_variant'],
242+
'options' => [
243+
'marvinj' => 'MarvinJ',
244+
'seriouslyjs' => 'Seriously.js'
245+
],
246+
'value' => $config['chroma_keying_variant']
247+
],
238248
'use_collage' => [
239249
'type' => 'checkbox',
240250
'name' => 'use_collage',

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"gulp": "4.0.2",
4646
"gulp-sass": "4.1.0",
4747
"jquery": "^3.5.1",
48+
"marvinj": "^1.0.0",
4849
"normalize.css": "^8.0.1",
4950
"npm-run-all": "^4.1.5",
5051
"rpio": "^2.1.1",

resources/lang/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"general": "General",
6060
"general_camera_mode": "Camera facing mode",
6161
"general_cheese_time": "Cheeeeeeeese!-Timer:",
62+
"general_chroma_keying_variant": "Keying algorithm",
6263
"general_cntdwn_time": "Countdown timer:",
6364
"general_collage_background": "Path to the background for \"2x4 + background image\" collage",
6465
"general_collage_cntdwn_time": "Collage-countdown timer:",
@@ -152,6 +153,7 @@
152153
"manual_gallery_pswp_bgOpacity": "Background opacity, low values make the background more transparent.",
153154
"manual_general_camera_mode": "Choose between front- or back facing camera mode of your device cam.",
154155
"manual_general_cheese_time": "Set a time to display \"Cheeeeeeeese!\" after the countdown.",
156+
"manual_general_chroma_keying_variant": "Choose between different chromakeying algorithms. <b>Please note:</b> Seriously.js requires a browser that supports WebGL.",
155157
"manual_general_cntdwn_time": "Set your countdown time.",
156158
"manual_general_collage_background": "Enter the path of the background which is applied to your collage on \"2x4 + background image\" collage layout.",
157159
"manual_general_collage_cntdwn_time": "Set your countdown time between pictures while taking a collage.",

scripts/pack-build.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ function createArchive(fileName, archive) {
7575
archive.file('node_modules/github-markdown-css/license');
7676
archive.file('node_modules/jquery/LICENSE.txt');
7777
archive.directory('node_modules/jquery/dist/');
78+
archive.file('node_modules/marvinj/LICENSE');
79+
archive.directory('node_modules/marvinj/marvinj/release/');
7880
archive.file('node_modules/normalize.css/LICENSE.md');
7981
archive.file('node_modules/normalize.css/normalize.css');
8082
archive.file('node_modules/whatwg-fetch/LICENSE');

src/js/chromakeying.js

Lines changed: 110 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* globals Seriously i18n */
1+
/* globals MarvinColorModelConverter AlphaBoundary MarvinImage i18n Seriously */
22
/* exported setBackgroundImage */
33
let mainImage;
44
let mainImageWidth;
@@ -10,36 +10,110 @@ let target;
1010
let chroma;
1111
let seriouslyimage;
1212

13+
function greenToTransparency(imageIn, imageOut) {
14+
for (let y = 0; y < imageIn.getHeight(); y++) {
15+
for (let x = 0; x < imageIn.getWidth(); x++) {
16+
const color = imageIn.getIntColor(x, y);
17+
const hsv = MarvinColorModelConverter.rgbToHsv([color]);
18+
19+
if (hsv[0] >= 60 && hsv[0] <= 200 && hsv[1] >= 0.2 && hsv[2] >= 0.2) {
20+
imageOut.setIntColor(x, y, 0, 127, 127, 127);
21+
} else {
22+
imageOut.setIntColor(x, y, color);
23+
}
24+
}
25+
}
26+
}
27+
28+
function reduceGreen(image) {
29+
for (let y = 0; y < image.getHeight(); y++) {
30+
for (let x = 0; x < image.getWidth(); x++) {
31+
const r = image.getIntComponent0(x, y);
32+
const g = image.getIntComponent1(x, y);
33+
const b = image.getIntComponent2(x, y);
34+
const color = image.getIntColor(x, y);
35+
const hsv = MarvinColorModelConverter.rgbToHsv([color]);
36+
37+
if (hsv[0] >= 60 && hsv[0] <= 130 && hsv[1] >= 0.15 && hsv[2] >= 0.15) {
38+
if (r * b != 0 && (g * g) / (r * b) > 1.5) {
39+
image.setIntColor(x, y, 255, r * 1.4, g, b * 1.4);
40+
} else {
41+
image.setIntColor(x, y, 255, r * 1.2, g, b * 1.2);
42+
}
43+
}
44+
}
45+
}
46+
}
47+
48+
function alphaBoundary(imageOut, radius) {
49+
const ab = new AlphaBoundary();
50+
for (let y = 0; y < imageOut.getHeight(); y++) {
51+
for (let x = 0; x < imageOut.getWidth(); x++) {
52+
ab.alphaRadius(imageOut, x, y, radius);
53+
}
54+
}
55+
}
56+
1357
function setMainImage(imgSrc) {
14-
const image = new Image();
15-
image.src = imgSrc;
16-
mainImageWidth = image.width;
17-
mainImageHeight = image.height;
18-
19-
// create tmpcanvas and size it to image size
20-
const tmpCanvas = document.createElement('canvas');
21-
tmpCanvas.width = mainImageWidth;
22-
tmpCanvas.height = mainImageHeight;
23-
tmpCanvas.id = 'tmpimageout';
24-
25-
// append Canvas for Seriously to chromakey the image
26-
// eslint-disable-next-line no-unused-vars
27-
const body = document.getElementsByTagName('body')[0];
28-
document.body.appendChild(tmpCanvas);
29-
30-
seriously = new Seriously();
31-
target = seriously.target('#tmpimageout');
32-
seriouslyimage = seriously.source(image);
33-
chroma = seriously.effect('chroma');
34-
chroma.source = seriouslyimage;
35-
target.source = chroma;
36-
seriously.go();
37-
mainImage = new Image();
38-
mainImage.src = tmpCanvas.toDataURL('image/png');
39-
40-
mainImage.onload = function () {
41-
drawCanvas();
42-
};
58+
if (config.chroma_keying_variant === 'marvinj') {
59+
const image = new MarvinImage();
60+
image.load(imgSrc, function () {
61+
mainImageWidth = image.getWidth();
62+
mainImageHeight = image.getHeight();
63+
64+
const imageOut = new MarvinImage(image.getWidth(), image.getHeight());
65+
66+
//1. Convert green to transparency
67+
greenToTransparency(image, imageOut);
68+
69+
// 2. Reduce remaining green pixels
70+
reduceGreen(imageOut);
71+
72+
// 3. Apply alpha to the boundary
73+
alphaBoundary(imageOut, 6);
74+
75+
const tmpCanvas = document.createElement('canvas');
76+
tmpCanvas.width = mainImageWidth;
77+
tmpCanvas.height = mainImageHeight;
78+
imageOut.draw(tmpCanvas);
79+
80+
mainImage = new Image();
81+
mainImage.src = tmpCanvas.toDataURL('image/png');
82+
mainImage.onload = function () {
83+
drawCanvas();
84+
};
85+
});
86+
} else {
87+
const image = new Image();
88+
image.src = imgSrc;
89+
mainImageWidth = image.width;
90+
mainImageHeight = image.height;
91+
92+
// create tmpcanvas and size it to image size
93+
const tmpCanvas = document.createElement('canvas');
94+
tmpCanvas.width = mainImageWidth;
95+
tmpCanvas.height = mainImageHeight;
96+
tmpCanvas.id = 'tmpimageout';
97+
98+
// append Canvas for Seriously to chromakey the image
99+
// eslint-disable-next-line no-unused-vars
100+
const body = document.getElementsByTagName('body')[0];
101+
document.body.appendChild(tmpCanvas);
102+
103+
seriously = new Seriously();
104+
target = seriously.target('#tmpimageout');
105+
seriouslyimage = seriously.source(image);
106+
chroma = seriously.effect('chroma');
107+
chroma.source = seriouslyimage;
108+
target.source = chroma;
109+
seriously.go();
110+
mainImage = new Image();
111+
mainImage.src = tmpCanvas.toDataURL('image/png');
112+
113+
mainImage.onload = function () {
114+
drawCanvas();
115+
};
116+
}
43117
}
44118

45119
// eslint-disable-next-line no-unused-vars
@@ -79,8 +153,12 @@ function drawCanvas() {
79153
}
80154

81155
if (typeof mainImage !== 'undefined' && mainImage !== null) {
82-
//important to fetch tmpimageout
83-
ctx.drawImage(document.getElementById('tmpimageout'), 0, 0);
156+
if (config.chroma_keying_variant === 'marvinj') {
157+
ctx.drawImage(mainImage, 0, 0);
158+
} else {
159+
//important to fetch tmpimageout
160+
ctx.drawImage(document.getElementById('tmpimageout'), 0, 0);
161+
}
84162
}
85163
}
86164

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3333,6 +3333,11 @@ map-visit@^1.0.0:
33333333
dependencies:
33343334
object-visit "^1.0.0"
33353335

3336+
marvinj@^1.0.0:
3337+
version "1.0.0"
3338+
resolved "https://registry.yarnpkg.com/marvinj/-/marvinj-1.0.0.tgz#5e1e0663f4e605a5966d3537c1a41fd22589c8b5"
3339+
integrity sha512-+afDa86Pml2BlDt2lEn+xZUZ6r4q+aQvxSmWq37M4lQ4SraBJcKlbm+wDamzXTvW7OmeK0mkWdjRB4R3PAPFjA==
3340+
33363341
matchdep@^2.0.0:
33373342
version "2.0.0"
33383343
resolved "https://registry.yarnpkg.com/matchdep/-/matchdep-2.0.0.tgz#c6f34834a0d8dbc3b37c27ee8bbcb27c7775582e"

0 commit comments

Comments
 (0)