-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
okni.html
1162 lines (881 loc) · 27.7 KB
/
okni.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>OkniEtchAI</title>
<link href="style5.css" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Roboto:400,500,700,900|Satisfy" rel="stylesheet">
<!-- Integrating JQuery-->
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<!-- <link rel="stylesheet" href="/resources/demos/style.css"> -->
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$( function() {
$( "#menu" ).menu();
} );
</script>
<style>
.ui-menu { width: 150px; }
</style>
<!-- End JQuery -->
<script src="script.js" type="text/javascript" async></script>
<style rel="stylesheet" type="text/css">
.filll {
position: absolute;
width:1px;
height:1px;
color:black;
left:auto;
top:65px;
background-color: black;
}
#result {
/* object-fit: cover;
width:230px;
height:230px; position: relative;
*/
position: relative;
left:58px;
width: 864px;
height: 832px;
overflow: hidden; /**/
}
.fillr {
width:77px;
height:600px;
color:magenta;
right:621px;
/* top:65px; */
background-color:black;
}
/* Override JQuery menu */
.ui-menu {
width: 70px;
}
.ui-menu-etch-ul
{
width: 170px;
text-align: left;
}
.ui-menu-icon{
min-width: 10px;
max-width: 15px;
}
</style>
<script type="text/javascript">
var currentSizeNumber = -1;
var moved = true;
//@STCGoal Refresh only if we moved
function probablyDrawing()
{
moved = true;
}
</script>
</head>
<body>
<table><tr><td valign=top>
<div id="maincontainer">
<div id="top">
<button id="hover">
<!-- <img src="./img/drag.png"> -->
Hover</button>
<button id="header"><h1>OkniEtchAI Sketcher</h1></button>
<button id="drag"><img src="./img/click.png">
Drag
</button>
</div>
<div id="canvaswrapper" onmousemove="probablyDrawing()">
<div id="gridcontainer">
</div>
</div>
<div id="bottombuttons">
<!-- <button id="restartAutoRefresh" onclick="restartAutoRefresh()"><img src="./img/timer.jpg" class="buttonicon" title="Restart Auto Refresh"></button> -->
<!-- <button id="clear"><img src="./img/channel-mode-off.ico"
title="Clear the canvas"></button> -->
<button id="default" style="color: gray;background-color: white;max-width: 55px;"><img src="./img/paint-52.png" title="Paint with Black"
></button>
<button id="transparent" style="color: gray;background-color: gray;max-width: 53px;"><img src="./img/paint-gray-52.png" title="Paint with Gray"></button>
<button id="colorized" style="min-width: 73px;"> <input type="color" id="coloring" name="coloring"
value="#e66465" onchange="setColoring()" onclick="refreshColoring()"
style="min-height: 55px;min-width:61px;"></button>
<button id="resize" style="max-width: 54px;"><img src="./img/resize.png" class="buttonicon"></button>
<button id="renderimg" onclick="renderimg()" style="max-width: 65px;min-width: 50px;">
<img src="./img/render.jpg" class="buttonicon2" width="65" height="45" ></button>
<!-- -->
<!-- JQuery Menu -->
<div class="buttonicon">
<ul id="menu" >
<li><div style="max-width: 55px;"><img src="./img/menu.png"></div>
<ul class="ui-menu-etch-ul">
<li class="ui-state-disabled"><div>---ETCH-AI---</div></li>
<li><div id="clear"><img src="./img/channel-mode-off.ico"
class="ui-menu-icon"> Clear canvas</div></li>
<!-- <li><div onclick="refreshRender">Refresh Render</div></li> -->
<li class="ui-state-disabled"><div>--------</div></li>
<li><div onclick="restartAutoRefresh()"><img src="./img/timer.jpg" class="ui-menu-icon"> Restart Refresh</div></li>
<li class="ui-state-disabled"><div>--------</div></li>
<li><div onclick="toogleRefreshOnMouseMoved()"><img src="./img/timer.jpg" class="ui-menu-icon"> Toogle Refresh Mouse Moved</div></li>
</ul>
</ul>
</div>
<!-- End menu -->
</div>
</div>
</td>
<td>
<div class="filll"> </div>
<div id="maincontainer2">
<div id="top2">
<button id="hover2"> </button>
<button id="header2" class="b2">
<h2 id="resultlabel" class="inferencelabel">Inferencing</h2></button>
<button id="cpainter" class="b2"> CHOOSE A MODEL </button>
<button id="header2" class="b2">
<h2 id="resultlabel" class="inferencelabel">Style</h2></button>
</div>
<div id="bottombuttons2" class="b2">
<br>
<div>
<nobr>
<button onclick="setPainter(9060)" class="b2"> Okni </button> <button onclick="setPainter(9060)" class="b2 b3"> Okni </button>
<button onclick="setPainter(9061)" class="b2"> 61 </button> <button onclick="setPainter(9061)" class="b2 b3"> 61 </button>
<button onclick="setPainter(9062)" class="b2"> 62 </button> <button onclick="setPainter(9062)" class="b2 b3"> 62 </button>
<button onclick="setPainter(9070)" class="b2"> 70 </button> <button onclick="setPainter(9070)" class="b2 b3"> 70 </button>
<button onclick="setPainter(9071)" class="b2"> 71 </button> <button onclick="setPainter(9071)" class="b2 b3"> 71 </button>
<br>
<!--
<button onclick="setPainter(9000)" class="b2"> Picasso </button> <button onclick="setPainter(9010)" class="b2 b3"> Vo </button>
<button onclick="setPainter(9003)" class="b2 b3"> 3.030</button>/
<button onclick="setPainter(9006)" class="b2 b3"> 3.075 </button> /
<button onclick="setPainter(9031)" class="b2 b3"> 3.120 </button> /
<button onclick="setPainter(9002)" class="b2 b3"> 3.165 </button>
<button onclick="setPainter(9009)" class="b2 b3"> 3.180 </button> /
<button onclick="setPainter(9005)" class="b2 b3"> 3.225 </button> /
<button onclick="setPainter(9008)" class="b2 b3"> 4.120 </button> /
<button onclick="setPainter(9030)" class="b2 b3"> 5.150 </button>
</nobr>
<br> -->
---COMPO:
<button onclick="setPainter(9051)" class="b2 b3">51 </button> -
<button onclick="setPainter(9052)" class="b2 b3">52 </button> -
<button onclick="setPainter(9053)" class="b2 b3">53 </button> -
<button onclick="setPainter(9054)" class="b2 b3">54 </button> -
<button onclick="setPainter(9055)" class="b2 b3">55 </button> -
<button onclick="setPainter(9056)" class="b2 b3">56 </button>
</div>
<div>
<nobr>
<button onclick="setPainter(9001)" class="b2"> Kandinsky </button>
<button onclick="setPainter(9004)" class="b2"> Dali </button>
<button onclick="setPainter(9011)" class="b2">Van-Gogh </button>
<button onclick="setPainter(9041)" class="b2"> El-Greco </button>
<button onclick="setPainter(9042)" class="b2"> Gauguin </button>
<button onclick="setPainter(9043)" class="b2"> Kirchner </button>
</nobr>
<br>
<nobr>
<button onclick="setPainter(9014)" class="b2"> Monet </button>
<button onclick="setPainter(9007)" class="b2"> Cezanne</button>
<button onclick="setPainter(9012)" class="b2 b3"> vo.165</button>
<button onclick="setPainter(9013)" class="b2 b3"> vo.180</button>
<button onclick="setPainter(9044)" class="b2"> Morisot </button>
<button onclick="setPainter(9045)" class="b2"> Munch </button>
<button onclick="setPainter(9046)" class="b2"> Peploe </button>
<button onclick="setPainter(9047)" class="b2"> Pollock </button>
<button onclick="setPainter(9048)" class="b2"> Roerich </button>
</nobr>
</div>
</div>
<div id="canvaswrapper2">
<div id="result"></div>
</div>
</div>
<!-- <div class="fillr"> </div> -->
</td>
</tr></table>
<!--
<br>
<button id="doubleInferenceModeButton" class="b3" onclick="doubleInferenceModeToogle()">Double Inference Mode Innactive</button>
-- DISABLED -->
<hr>
<br>
<br>
<br>
<!-- <br>
<button class="b2" onclick="grabresultpresentationgrid()">Grab Result Grid as Image</button>
<br> -->
<hr>
<br>
<br>
<div id="resultpresentationgrid">
<table id="resultpresentationgridtable">
<tr>
<td>
<font size=+2>
<h1 id="currentPainterLabelText">CURRENT PAINTER LABEL</h1></td>
</font>
<td></td>
</tr>
<tr>
<th><h2>Content</h2></th>
<th><h2>Stylized</h2></th>
</tr>
<tr>
<td>
<div id="presentationContentDiv"></div>
</td>
<td>
<div id="presentationResultDiv"></div>
</td>
</tr>
</table>
<!-- </canvas> -->
<br>
<br>
<br>
<hr>
<!-- @STCGoal Capture Canvas from an HTML Elements -->
<script type="text/javascript" src="./node_modules/html2canvas/dist/html2canvas.js"></script>
<!-- @STCGoal So we dont publish on the web our config like pika_token -->
<script type="text/javascript" src="./config.js"></script>
<!-- @STCGoal Render Stylistic inferences via hosted AI model -->
<!-- <script type="text/javascript" src="/node_modules/html2canvas/dist/html2canvas.js"></script>
-->
<!-- @STCGoal Logic doing all the work -->
<script type="text/javascript">
//----------------------------------------------------------------------------------
//--------------------------------------------Inference Starts after that timeout
//Being Deprecated
var infereAfterTimeOut = 19000;
//----------------------------------------------------------FEATURE ON/OFF --------------------
//----------------- Toogle This for processing Style or Not (Cost 0.01$ USD per inference -----
var doProcess = true;
var featCompoRendering = false; //feature altering behaviour to compose image with two model (NOT WORKING SO GREATLY)
var featCompoPort1 = 9061 //default 1: 3.165
var featCompoPort2 = 9062; //default 2: 3.03
var showCurrentImageInBody = true;//false bug the process
var debug = false;
var countLoop = 0;
var initialWaitBeforeStartingLoop = 2111;
var _cnf_defaultPainterPort = 9060;
setTimeout(function() {
//Override the default port
setPainter(_cnf_defaultPainterPort);
looping();
},initialWaitBeforeStartingLoop);
function looping()
{
(function myLoop(i) {
setTimeout(function() {
console.log('looping:' + countLoop); // your code here
if (moved)
{
if (!initialMouseOverDone) //required to run first so we can draw right away
{
//activateDefaultDrawOptions();
initialMouseOverDone = true;
}
console.log("Movement detected");
//Rendering Type ?
if (!featCompoRendering) {
if (refreshOnMouseMoved || refreshButtonPressed) //we refresh if refresh on mouse move is active or the render button was pressed
renderimg(); //normal (1 model)
loopingWaitFactor = 1;
}
else {
loopingWaitFactor = 4;
compoRenderingWF();}
}
moved = false;
countLoop++;
if (--i) myLoop(i); // decrement i and call myLoop again if i > 0
else console.log("Loop auto refresh TimedOut");
}, getRefreshRateRelativeToSize() * loopingWaitFactor )
})(autorefreshingIterations ); // pass the number of iterations as an argument
}
autorefreshing=false;
var refreshOnMouseMoved = false;
var refreshButtonPressed = false;
var loopingWaitFactor = 1;
etchLoadWhenStarting();
function etchLoadWhenStarting()
{
activateDefaultDrawOptions();
etchLoaded();
}
var initialMouseOverDone = false;
function activateDefaultDrawOptions()
{
setTimeout(() => {
// mouseHoverDefault(this);
// changeDefaultButton();
var hoverHandler = document.getElementById("hover");
hoverHandler.click();
var defaultHandler = document.getElementById("default");
defaultHandler.click();
try {
hoverHandler.click();
hoverHandler.releasePointerCapture();
} catch (error) {}
try {
defaultHandler.click();
defaultHandler.releasePointerCapture();
} catch (error) {}
},222);
}
//@TODO DELETE
setTimeout(() => {
console.log("Starting the whole thing BYPASSED in this by the button RENDER!");
}, infereAfterTimeOut);
//----------------------------------------------
function imgToBase64(img) {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
canvas.width = img.width;
canvas.height = img.height;
// I think this won't work inside the function from the console
img.crossOrigin = 'anonymous';
ctx.drawImage(img, 0, 0);
return canvas.toDataURL();
}
//Ititial auto refresh if we do not auto refresh
if (!autorefreshing) renderimg();
var currentResultBase64;
var doubleInferenceMode = false;
function doubleInferenceModeToogle()
{
doubleInferenceMode = !doubleInferenceMode;
var b = document.getElementById("doubleInferenceModeButton");
if (doubleInferenceMode)
b.innerText = "Double Inference Mode Active";
else
b.innerText = "Double Inference Mode Innactive";
}
var previousResult = new Image();
var previousPresentationResult = new Image();
var previousContent = new Image();
var presentationContentDiv = document.getElementById("presentationContentDiv");
var presentationResultDiv = document.getElementById("presentationResultDiv");
//
//<canvas id="canvas"></canvas>
function renderimg()
{
console.log("Started rendering...");
var htmlIdSource = "canvaswrapper";// the html id that we capture, convert as image and send to the Pika agent which will send us back our stylized image.
var frame = document.getElementById(htmlIdSource);
// SnapShotCroped(htmlIdSource,"",function(canvas){
// document.body.appendChild(canvas);
// });
var rect = frame.getBoundingClientRect();
var options = {
scrollX: 0,
scrollY: 100,
x: 55,
width:rect.width -99
};
//options = {};
html2canvas(frame,options).then(function(canvas) {
if (showCurrentImageInBody)
{
}
//console.log("The canvas lib has a toDataURL method to encode in base64");
//console.log(canvas.toDataURL());
// resultDiv.appendChild(canvas);
var enc64 =
imgToBase64(canvas);
var currentContent = new Image();
currentContent.src = enc64;
try {
presentationContentDiv.removeChild(previousContent);
} catch (error) { }
presentationContentDiv.appendChild(currentContent);
//document.body.appendChild(canvas);
previousContent = currentContent;
//Tring to do double inference if the mode was activated
if (doubleInferenceMode) {
enc64 = currentResultBase64;
setPainter(9003);
autorefreshingIterations =5050;
}
//we reuse the last result
// canvas.toDataURL();
if (debug) console.log("Fetching " + pika_url + " starting");
var o = new Object();
o.contentImage = enc64;
var jsonString = JSON.stringify(o);
if (debug) console.log("Sending stringified :" + jsonString);
(async () => {
const rawResponse = await fetch(pika_url, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(o)
});
const content = await rawResponse.json();
if (debug) console.log(content.stylizedImage);
var resultImage = new Image();
var resultPresentationImage = new Image();
resultImage.src= content.stylizedImage;
resultPresentationImage.src= content.stylizedImage;
currentResultBase64 = content.stylizedImage;
var resultDiv = document.getElementById("result");
// var separator = new Image();
// separator.src = separatorBase64;
//@STCGoal Keeps clean the area of previews
try {
resultDiv.removeChild(previousResult);
} catch (error) {}
resultDiv.appendChild(resultImage);
previousResult = resultImage;
//-------------------------------------
try {
presentationResultDiv.removeChild(previousPresentationResult);
} catch (error) { }
presentationResultDiv.appendChild(resultPresentationImage);
previousPresentationResult = resultPresentationImage;
currentPainterLabelText.innerText = currentPainterLabel;
//resultDiv.prepend(separator);
// document.body.replaceChild(image);
})();
});
console.log("...Rendering done");
}
//runs when we just loaded (few ms)
function etchLoaded(){
etchResized();
}
function etchResized()
{
try {
currentSizeNumber = resizeNumber;
} catch (error) { }
}
function restartAutoRefresh()
{
//@STCGoal Startup of the refresh sequence again
countLoop= 0;
// activateDefaultDrawOptions();
looping();
alert("Auto refresh restarted");
}
var currentPainterLabel ;
var currentPainterLabelText = document.getElementById("currentPainterLabelText");
function setUI(painterLabel)
{
var cpainter = document.getElementById("cpainter");
cpainter.innerText = painterLabel;
console.log("Current Size: " + currentSizeNumber);
currentPainterLabel = painterLabel;
}
var startingApp = true;
/** */
function setPainter(port)
{
featCompoRendering = false;
var oldPort = pika_port;
this.pika_port = port;
console.log("Port changed from : " + oldPort + " to: " + pika_port);
updatedContext();
setCurrentlyInferingLabel(port);
if (!startingApp)
renderimg();
startingApp = false;
}
var jgwillPicassoModelName = "Picawill";
function setCurrentlyInferingLabel(port)
{
switch (port) {
case 90029003:
setUI("Compo3165030");
break;
case 9000:
setUI("Picasso");
break;
case 9002:
setUI(jgwillPicassoModelName + " var 3.165");
break;
case 9003:
setUI(jgwillPicassoModelName + " var 3.030");
break;
case 9031:
setUI(jgwillPicassoModelName + " var 3.120");
break;
case 9005:
setUI(jgwillPicassoModelName + " var 3.225");
break;
case 9009:
setUI(jgwillPicassoModelName + " var 3.180");
case 9010:
setUI("Picasso Vo");
break;
case 9006:
setUI(jgwillPicassoModelName + " var 3.075");
break;
case 9008:
setUI(jgwillPicassoModelName + " var 4.120");
break;
case 9030:
setUI(jgwillPicassoModelName + " var 5.150");
break;
//VAN GOGH
case 9011:
setUI("Van-Gogh Vo");
break;
//CEZANNE
case 9007:
setUI("Cezanne Vo");
break;
case 9012:
setUI("Cezanne Vo.165ik");
break;
case 9013:
setUI("Cezanne Vo.180ik");
break;
case 9014:
setUI("Monet Vd");
break;
case 9001:
setUI("Kandinsky var 1.210");
break;
case 9004:
setUI("Dali var 1.300");
break;
case 9041:
setUI("El-Greco");
break;
case 9042:
setUI("Gauguin");
break;
case 9043:
setUI("Kirchner");
break;
case 9044:
setUI("Morisot");
break;
case 9045:
setUI("Munch");
break;
case 9046:
setUI("Peploe");
break;
case 9047:
setUI("Pollock");
break;
case 9048:
setUI("Roerich");
break;
case 9060:
setUI("Okni");
break;
case 9061:
setUI("Okni");
break;
case 9062:
setUI("Okni");
break;
case 9063:
setUI("Okni");
break;
case 9070:
setUI("Okni");
break;
case 9071:
setUI("Okni");
break;
default:
setUI("---" + port + "---");
break;
}
}
function updatedContext()
{
pika_url=getstylizeCallUrl(pika_port);
console.log("Service URL now:" + pika_url);
}
function getstylizeCallUrl(port)
{
return "http://" + pika_host + ":"+port+"/stylize";
}
function getRefreshRateRelativeToSize()
{
if (currentSizeNumber == -1) return autorefreshingTimeout;
else
{
if (currentSizeNumber > 50)
return autorefreshingTimeout + (currentSizeNumber * 85);
if (currentSizeNumber > 45)
return autorefreshingTimeout + (currentSizeNumber * 69);
if (currentSizeNumber > 40)
return autorefreshingTimeout + (currentSizeNumber * 58);
if (currentSizeNumber > 35)
return autorefreshingTimeout + (currentSizeNumber * 47);
if (currentSizeNumber > 30)
return autorefreshingTimeout + (currentSizeNumber * 41);
if (currentSizeNumber > 25)
return autorefreshingTimeout + (currentSizeNumber * 26);
if (currentSizeNumber > 20)
return autorefreshingTimeout + (currentSizeNumber * 14);
if (currentSizeNumber > 17)
return autorefreshingTimeout + (currentSizeNumber * 8);
if (currentSizeNumber > 12)
return autorefreshingTimeout ;
if (currentSizeNumber > 10)
return autorefreshingTimeout* 0.9;
if (currentSizeNumber > 8)
return autorefreshingTimeout* 0.8;
if (currentSizeNumber > 7)
return autorefreshingTimeout* 0.75;
}
return autorefreshingTimeout;
//Example if we
}
/** */
function setCompoPainter(port1,port2)
{
featCompoPort1 = port1;
featCompoPort2 = port2;
featCompoRendering = true;
console.log("Port compo from : " + port1 + " to: " + port2);
setCurrentlyInferingLabel(port1 + "" + port2);
console.log("Compo rendering activated");
}
function compoRenderingWF()
{
//executed by the loop
console.log("Composite Rendering WF Processing...")
// renderASTCompo(featCompoPort1,featCompoPort2);
renderimgComposite();
}
function renderASTCompo(port1,port2)
{
var imgIteration1 = new Image();
this.pika_port = port;
updatedContext();
// code call for iteration 1
var content1Request = getCurrentCanvasAsContentImageRequest();
//@STCGoal Desired end Result: a result we call back
var imgIteration2 = new Image();
}
//SHOULD BE CALLABLE AND GET SAME RESULT AS renderimg()
function renderimgV2()
{
var contentImageRequest = getCurrentCanvasAsContentImageRequest();
updatedContext();
astGetInference(contentImageRequest,)
}
//
function getCurrentCanvasAsContentImageRequest()
{
var htmlIdSource = "canvaswrapper";// the html id that we capture, convert as image and send to the Pika agent which will send us back our stylized image.
var frame = document.getElementById(htmlIdSource);
// var rect = frame.getBoundingClientRect();
// var WHFixOffset = 140;
// var fixWidth = rect.width +WHFixOffset;
// var fixHeight = rect.height +WHFixOffset;
// var options = {
// scrollX: 0,
// scrollY: 100,
// width: fixWidth + 25-100,
// height: fixHeight -70
// };
var options = {
scrollX: 0,
scrollY: 100
};
//options = {};
html2canvas(frame,options).then(function(canvas) {
if (showCurrentImageInBody)
{
//if (debug)
try {
document.body.removeChild(previousContent);
} catch (error) { }
document.body.appendChild(canvas);
previousContent = canvas;
}
//console.log("The canvas lib has a toDataURL method to encode in base64");
//console.log(canvas.toDataURL());
// resultDiv.appendChild(canvas);
var enc64 =
imgToBase64(canvas);
// canvas.toDataURL();
if (debug) console.log("Fetching " + pika_url + " starting");
var o = new Object();
o.contentImage = enc64;
return o;
});
}
function astGetInference(contentImageRequest,serviceURL,targetHTMLID,previousResultToCLean)
{
//@TODO
(async () => {
const rawResponse = await fetch(serviceURL, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(contentImageRequest)
});
const content = await rawResponse.json();
if (debug) console.log(content.stylizedImage);
var resultImage = new Image();
resultImage.src= content.stylizedImage;
//--------WHAT WILL IT RETURNS ??
var resultDiv = document.getElementById(targetHTMLID);
// var separator = new Image();
// separator.src = separatorBase64;
//@STCGoal Keeps clean the area of previews
try {
resultDiv.removeChild(previousResultToCLean);
} catch (error) {}
resultDiv.appendChild(resultImage);
previousResultToCLean = resultImage;
//resultDiv.prepend(separator);
// document.body.replaceChild(image);
})();
console.log("...Rendering done");
}
//A copy of the rendertmp for composite (PREVIOUS Function require more reflections)
function renderimgComposite()
{
console.log("Composite rendering started...");
var htmlIdSource = "canvaswrapper";// the html id that we capture, convert as image and send to the Pika agent which will send us back our stylized image.
var frame = document.getElementById(htmlIdSource);
// var rect = frame.getBoundingClientRect();
// var WHFixOffset = 140;
// var fixWidth = rect.width +WHFixOffset;
// var fixHeight = rect.height +WHFixOffset;
// var options = {
// scrollX: 0,
// scrollY: 100,
// width: fixWidth + 25-100,
// height: fixHeight -70
// };
var options = {
scrollX: 0,
scrollY: 100
};
//options = {};
html2canvas(frame,options).then(function(canvas) {
if (showCurrentImageInBody)
{
//if (debug)
try {
document.body.removeChild(previousContent);
} catch (error) { }
document.body.appendChild(canvas);
previousContent = canvas;