-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
223 lines (222 loc) · 8.21 KB
/
index.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
<!--
/*getColorSection
* index.html
*===================================================================
* Copyright (c) 2019 Yuji SODE <yuji.sode@gmail.com>
*
* This software is released under the MIT License.
* See LICENSE or http://opensource.org/licenses/mit-license.php
*===================================================================
*/
-->
<!-- This program is web version of getColorSection. -->
<!-- Tool that draws a columnar color section by given RGB values of the canvas. -->
<!DOCTYPE html><html lang='en'>
<head>
<meta charset='utf-8'>
<meta name='description' content="Tool that draws a columnar color section by given RGB values of the canvas. This program is web version of getColorSection.">
<title>getColorSection</title>
<style type='text/css'>
canvas{
border:1px solid #000f;
}
#outputCvs{
border:1px dashed #f00f;
}
#formDiv{
position:fixed;
right:0;
top:5vh;
width:40vw;
height:38vh;
resize:both;
background:#ddd;
overflow:scroll;
}
.divRight{
right:0;
}
.divLeft{
left:0;
}
</style>
<script type='text/javascript' src='./getColorSection.js'></script>
<script type='text/javascript' src='./colorScale.js'></script>
</head>
<body>
<div>
<h1>getColorSection</h1>
<p>Tool that draws a columnar color section by given RGB values of the canvas.
<br>This is web version of<a href='https://github.com/YujiSODE/getColorSection'>getColorSection</a>.</p>
</div>
<canvas id='cvs_getColorSection' width=100 height=100></canvas>
<div id='outputDiv'>
<h2>Output</h2>
<canvas id='outputCvs' width=100 height=100></canvas>
</div>
<img id='imgForCvs' src='' style="display:none;">
<div id='formDiv' class='divRight'>
<div id='buttonsDiv'>
<!-- buttons to change form position -->
<button id='leftB'>Left</button>
<button id='rightB'>Right</button>
<!-- buttons to scan image -->
<button id='scanB'>Scan</button>
<button id='fixedScanB'>Fixed Scan</button>
<!-- buttons to show color scale -->
<button id='scaleB'>Color Scale</button>
<!-- buttons to show log -->
<button id='logB'>Log</button>
</div>
<form id='control'>
<!-- source image and size of canvas -->
<fieldset id='CANVAS'>
<legend><b>Canvas</b></legend>
<ol>
<li><label>image file<input type='file' id='inputImg' accept='image/*'></label></li>
<p>Canvas size</p>
<li><label>width<input type='number' id='inputWidth' value=100 min=100 step=1 required></label></li>
<li><label>height<input type='number' id='inputHeight' value=100 min=100 step=1 required></label></li>
</ol>
<!-- size of source image -->
<p id='imgInfo'>Image size = <i>width</i> x <i>height</i> pixels</p>
</fieldset>
<!-- image scan -->
<fieldset id='scan'>
<legend><b>Scan area</b></legend>
<p>Top left corner is <code>(x,y)=(0,0)</code> in pixels</p>
<ol>
<div id='scanArea'>
<li><label>horizontal coordinate in pixels<input type='number' id='scanX' value=0 min=0 step=1 required></label></li>
<li><label>width to scan<input type='number' id='scanWidth' value=1 min=1 step=1 required></label></li>
</div>
<!-- rgb coefficient -->
<li>
<div id='rgbCoefficient'>
<p>RGB color coefficients to scan: <code>rgb(R,G,B)=r*R+g*G+b*B</code></p>
<ul>
<li><label>r<input type='number' id='scanRValue' value=1 min=0 step=0.02 required></label></li>
<li><label>g<input type='number' id='scanGValue' value=1 min=0 step=0.02 required></label></li>
<li><label>b<input type='number' id='scanBValue' value=1 min=0 step=0.02 required></label></li>
</ul>
</div>
</li>
</ol>
</fieldset>
</form>
</div>
<footer>
<p>Copyright (c) 2019 Yuji SODE</p>
<a href='https://github.com/YujiSODE/getColorSection'>GitHub</a>
</footer>
<script type='text/javascript'>
(function(){
var slf=window,
C=slf.document.getElementById('cvs_getColorSection'),
cOut=slf.document.getElementById('outputCvs'),
reader=new FileReader(),
__LOG='',
/*buttons*/
LeftB=slf.document.getElementById('leftB'),
RightB=slf.document.getElementById('rightB'),
ScanB=slf.document.getElementById('scanB'),
FixedScanB=slf.document.getElementById('fixedScanB'),
ScaleB=slf.document.getElementById('scaleB'),
LogB=slf.document.getElementById('logB'),
/*form inputs: Canvas*/
img=slf.document.getElementById('inputImg'),
imgLength=0,
_IMG=slf.document.getElementById('imgForCvs'),
_IMGInfo=slf.document.getElementById('imgInfo'),
Width=slf.document.getElementById('inputWidth'),
Height=slf.document.getElementById('inputHeight'),
/*form inputs: scan area*/
xScan=slf.document.getElementById('scanX'),
wScan=slf.document.getElementById('scanWidth'),
rScan=slf.document.getElementById('scanRValue'),
gScan=slf.document.getElementById('scanGValue'),
bScan=slf.document.getElementById('scanBValue'),
/*initial value*/
scan=getColorSection(C,[+rScan.value,+gScan.value,+bScan.value]);
//### file reader event ###
_IMG.addEventListener('load',function(){
var ctx=C.getContext('2d');
ctx.drawImage(_IMG,0,0);
ctx=null;
_IMGInfo.textContent='Image\u0020size\u0020=\u0020'+_IMG.width+'\u0020x\u0020'+_IMG.height+'\u0020pixels';
},false);
reader.addEventListener('load',function(){
C.width=Width.value;
C.height=Height.value;
_IMG.src=reader.result;
},false);
//### form change event ###
slf.document.getElementById('control').addEventListener('change',function(){
imgLength=img.files.length;
scan=getColorSection(C,[+rScan.value,+gScan.value,+bScan.value]);
if(imgLength>0){
reader.readAsDataURL(img.files[0]);
}else{
C.width=Width.value,C.height=Height.value;
}
},false);
//### button event ###
LeftB.addEventListener('click',()=>{
slf.document.getElementById('formDiv').className='divLeft';
},false);
RightB.addEventListener('click',()=>{
slf.document.getElementById('formDiv').className='divRight';
},false);
ScanB.addEventListener('click',()=>{
//new value for width of canvas to output [cf. "getColorSection.js"]: w0*(1+data)*1.1=100*(1+1.0)*1.1
cOut.width=220;
cOut.height=Height.value;
cOut.getContext('2d').clearRect(0,0,cOut.width,cOut.height);
scan(cOut,xScan.value,wScan.value,false);
},false);
FixedScanB.addEventListener('click',()=>{
//new value for width and height of canvas to output
cOut.width=Width.value;
cOut.height=Height.value;
cOut.getContext('2d').drawImage(_IMG,0,0);
scan(cOut,xScan.value,wScan.value,true);
},false);
ScaleB.addEventListener('click',()=>{
colorScale(cOut);
},false);
LogB.addEventListener('click',()=>{
__LOG=`\"getColorSection\"
Filename:${imgLength>0?img.files[0].name:'no data'}
Horizontal coordinate in pixels:${xScan.value}
Width to scan:${wScan.value}
RGB color coefficients:\[r,g,b\]=\[${rScan.value},${gScan.value},${bScan.value}\]`;
slf.alert(__LOG);
slf.console.log(__LOG);
},false);
}());
</script>
</body>
</html>
<!-- getColorSection/index.html -->
<!--/*
* MIT License
*
* Copyright (c) 2019 Yuji Sode
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/-->