| 
									
										
										
										
											2019-05-14 03:55:35 +03:00
										 |  |  | <!DOCTYPE html> | 
					
						
							|  |  |  | <html> | 
					
						
							|  |  |  | <style> | 
					
						
							| 
									
										
										
										
											2019-11-15 17:14:55 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .graph { | 
					
						
							|  |  |  | 	position: relative; | 
					
						
							|  |  |  | 	display: inline-block; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	width: attr(image-width); | 
					
						
							|  |  |  | 	height: attr(graph-height); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | .graph canvas { | 
					
						
							|  |  |  | 	width: 100%; | 
					
						
							|  |  |  | 	height: 100%; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | .graph .controls { | 
					
						
							|  |  |  | 	display: inline-block; | 
					
						
							|  |  |  | 	position: absolute; | 
					
						
							|  |  |  | 	top: 2px; | 
					
						
							|  |  |  | 	right: 2px; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | .graph .controls button { | 
					
						
							|  |  |  | 	background: transparent; | 
					
						
							|  |  |  | 	border: none; | 
					
						
							|  |  |  | 	color: white; | 
					
						
							|  |  |  | 	opacity: 0.7; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | .graph .controls button.current { | 
					
						
							|  |  |  | 	text-decoration: underline; | 
					
						
							|  |  |  | 	opacity: 0.9; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-11-15 18:25:09 +03:00
										 |  |  | .graph .controls button.R:hover, | 
					
						
							|  |  |  | .graph .controls button.current.R { | 
					
						
							|  |  |  | 	background: red; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | .graph .controls button.G:hover, | 
					
						
							|  |  |  | .graph .controls button.current.G { | 
					
						
							|  |  |  | 	background: green; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | .graph .controls button.B:hover, | 
					
						
							|  |  |  | .graph .controls button.current.B { | 
					
						
							|  |  |  | 	background: blue; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-11-15 17:14:55 +03:00
										 |  |  | .graph .controls button:hover { | 
					
						
							|  |  |  | 	opacity: 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-14 03:55:35 +03:00
										 |  |  | </style> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <script src="../ext-lib/jquery.js"></script> | 
					
						
							|  |  |  | <script src="../ext-lib/jquery-ui.js"></script> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <script src="../lib/jli.js"></script> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-17 06:15:41 +03:00
										 |  |  | <script src="ig-image-graph.js"></script> | 
					
						
							| 
									
										
										
										
											2019-05-14 03:55:35 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-17 06:15:41 +03:00
										 |  |  | <script> | 
					
						
							| 
									
										
										
										
											2019-05-14 03:55:35 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-16 15:55:58 +03:00
										 |  |  | // XXX should we make this a web components??? | 
					
						
							|  |  |  | //		+ would make everything transparent | 
					
						
							|  |  |  | //			- add a tag | 
					
						
							|  |  |  | //			- edit props | 
					
						
							|  |  |  | //			- handle events | 
					
						
							|  |  |  | //		- not sure what is the differenence practically... | 
					
						
							|  |  |  | var makeWaveform = function(img, options){ | 
					
						
							|  |  |  | 	var color_modes = ['normalized', 'white', 'color'] | 
					
						
							| 
									
										
										
										
											2019-11-15 18:25:09 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-16 15:55:58 +03:00
										 |  |  | 	options = options || {} | 
					
						
							|  |  |  | 	options.mode = options.mode || 'color' | 
					
						
							|  |  |  | 	options.color = options.color || color_modes[0] | 
					
						
							| 
									
										
										
										
											2019-11-15 18:25:09 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// XXX configurable... | 
					
						
							| 
									
										
										
										
											2019-11-15 17:14:55 +03:00
										 |  |  | 	var type = 'waveform' | 
					
						
							|  |  |  | 	var graph = waveform | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var buttons | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 18:25:09 +03:00
										 |  |  | 	var update = function(m){ | 
					
						
							| 
									
										
										
										
											2019-11-16 15:55:58 +03:00
										 |  |  | 		m = options.mode = m || options.mode | 
					
						
							|  |  |  | 		graph(img, canvas, m, options.color) | 
					
						
							| 
									
										
										
										
											2019-11-15 17:14:55 +03:00
										 |  |  | 		;(buttons || []) | 
					
						
							|  |  |  | 			.forEach(function(b){ | 
					
						
							| 
									
										
										
										
											2019-11-15 18:25:09 +03:00
										 |  |  | 				b.classList.contains(m) ? | 
					
						
							| 
									
										
										
										
											2019-11-15 17:14:55 +03:00
										 |  |  | 					b.classList.add('current')  | 
					
						
							|  |  |  | 					: b.classList.remove('current') }) }  | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-16 01:00:07 +03:00
										 |  |  | 	// handle img urls... | 
					
						
							|  |  |  | 	if(typeof(img) == typeof('str')){ | 
					
						
							|  |  |  | 		var src = img | 
					
						
							|  |  |  | 		img = document.createElement('img') | 
					
						
							|  |  |  | 		img.onload = function(){ | 
					
						
							|  |  |  | 			container.setAttribute('image-width', img.width) | 
					
						
							|  |  |  | 			container.setAttribute('image-height', img.height) | 
					
						
							|  |  |  | 			update() } | 
					
						
							|  |  |  | 		img.src = src } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 17:14:55 +03:00
										 |  |  | 	// container... | 
					
						
							|  |  |  | 	var container = document.createElement('div') | 
					
						
							|  |  |  | 	container.classList.add('graph', type) | 
					
						
							| 
									
										
										
										
											2019-11-16 15:55:58 +03:00
										 |  |  | 	// XXX not sure why would we need shadow dom here... | 
					
						
							|  |  |  | 	//var shadow = container.attachShadow({mode: 'open'}) | 
					
						
							| 
									
										
										
										
											2019-11-15 17:14:55 +03:00
										 |  |  | 	// canvas... | 
					
						
							|  |  |  | 	var canvas = document.createElement('canvas') | 
					
						
							|  |  |  | 	container.appendChild(canvas) | 
					
						
							|  |  |  | 	// controls... | 
					
						
							|  |  |  | 	if(controls || controls === undefined){ | 
					
						
							|  |  |  | 		var controls = document.createElement('div') | 
					
						
							|  |  |  | 		controls.classList.add('controls') | 
					
						
							|  |  |  | 		// buttons... | 
					
						
							|  |  |  | 		buttons = ['luminance', 'color', 'R', 'G', 'B'] | 
					
						
							|  |  |  | 			.map(function(m){ | 
					
						
							|  |  |  | 				var button = document.createElement('button') | 
					
						
							|  |  |  | 				button.innerText = m | 
					
						
							|  |  |  | 				button.classList.add(m) | 
					
						
							| 
									
										
										
										
											2019-11-15 18:25:09 +03:00
										 |  |  | 				button.onclick = function(){  | 
					
						
							| 
									
										
										
										
											2019-11-16 15:55:58 +03:00
										 |  |  | 					update(m) } | 
					
						
							| 
									
										
										
										
											2019-11-15 17:14:55 +03:00
										 |  |  | 				controls.appendChild(button)  | 
					
						
							|  |  |  | 				return button }) | 
					
						
							| 
									
										
										
										
											2019-11-15 18:25:09 +03:00
										 |  |  | 		// color mode switch... | 
					
						
							|  |  |  | 		var button = document.createElement('button') | 
					
						
							| 
									
										
										
										
											2019-11-16 15:55:58 +03:00
										 |  |  | 		button.innerText = '('+ options.color[0] +')' | 
					
						
							| 
									
										
										
										
											2019-11-15 18:25:09 +03:00
										 |  |  | 		button.onclick = function(){  | 
					
						
							| 
									
										
										
										
											2019-11-16 15:55:58 +03:00
										 |  |  | 			options.color = color_modes[ | 
					
						
							|  |  |  | 				(color_modes.indexOf(options.color) + 1)  | 
					
						
							|  |  |  | 					% color_modes.length] | 
					
						
							|  |  |  | 			this.innerText = '('+ options.color[0] +')' | 
					
						
							| 
									
										
										
										
											2019-11-15 18:25:09 +03:00
										 |  |  | 			update() } | 
					
						
							|  |  |  | 		controls.appendChild(button)  | 
					
						
							|  |  |  | 		// add to block... | 
					
						
							| 
									
										
										
										
											2019-11-15 17:14:55 +03:00
										 |  |  | 		container.appendChild(controls) } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// meta stuff... | 
					
						
							|  |  |  | 	container.setAttribute('graph-width', canvas.width) | 
					
						
							|  |  |  | 	container.setAttribute('graph-height', canvas.height) | 
					
						
							|  |  |  | 	container.setAttribute('image-width', img.width) | 
					
						
							|  |  |  | 	container.setAttribute('image-height', img.height) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 18:25:09 +03:00
										 |  |  | 	// init... | 
					
						
							| 
									
										
										
										
											2019-11-16 01:00:07 +03:00
										 |  |  | 	update() | 
					
						
							| 
									
										
										
										
											2019-11-15 17:14:55 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return container | 
					
						
							| 
									
										
										
										
											2019-05-14 03:55:35 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 17:14:55 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | var start = function(){ | 
					
						
							|  |  |  | 	//waveform(document.getElementById('input'), document.getElementById('waveform'), 'color') | 
					
						
							|  |  |  | 	//histogram(document.getElementById('input'), document.getElementById('histogram'), 'color') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 18:25:09 +03:00
										 |  |  | 	//document.body.appendChild(makeWaveform(document.getElementById('input'), 'color', 'normalized')) | 
					
						
							| 
									
										
										
										
											2019-11-15 17:14:55 +03:00
										 |  |  | 	document.body.appendChild(makeWaveform(document.getElementById('input'))) | 
					
						
							| 
									
										
										
										
											2019-11-16 01:00:07 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	document.body.appendChild(makeWaveform('../images/splash-800x500.jpg')) | 
					
						
							| 
									
										
										
										
											2019-11-15 17:14:55 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-16 15:55:58 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-14 03:55:35 +03:00
										 |  |  | </script> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-16 15:55:58 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-14 03:55:35 +03:00
										 |  |  | <body> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <img id="input" src="../images/splash-800x500.jpg" onload="start()"/> | 
					
						
							| 
									
										
										
										
											2019-11-15 17:14:55 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-16 15:55:58 +03:00
										 |  |  | <br> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <ig-image-graph  | 
					
						
							| 
									
										
										
										
											2019-11-17 01:50:23 +03:00
										 |  |  | 	graph="histogram" | 
					
						
							| 
									
										
										
										
											2019-11-16 15:55:58 +03:00
										 |  |  | 	src="../images/splash-800x500.jpg" | 
					
						
							|  |  |  | 	mode="color" | 
					
						
							|  |  |  | 	color="normalized"  | 
					
						
							| 
									
										
										
										
											2019-11-17 06:15:41 +03:00
										 |  |  | 	style="width: 600px; height: 300px"></ig-image-graph> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <ig-image-graph  | 
					
						
							|  |  |  | 	graph="waveform" | 
					
						
							|  |  |  | 	src="../images/splash-800x500.jpg" | 
					
						
							|  |  |  | 	mode="color" | 
					
						
							|  |  |  | 	color="normalized" ></ig-image-graph> | 
					
						
							| 
									
										
										
										
											2019-11-16 15:55:58 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 17:14:55 +03:00
										 |  |  | <!--
 | 
					
						
							| 
									
										
										
										
											2019-05-14 03:55:35 +03:00
										 |  |  | <br> | 
					
						
							|  |  |  | <canvas id="waveform"></canvas> | 
					
						
							|  |  |  | <br> | 
					
						
							|  |  |  | <button onclick="waveform(getElementById('input'), getElementById('waveform'), 'luminance')">Luminance</button> | 
					
						
							|  |  |  | <button onclick="waveform(getElementById('input'), getElementById('waveform'), 'color')">Color</button> | 
					
						
							|  |  |  | <button onclick="waveform(getElementById('input'), getElementById('waveform'), 'R')">R</button> | 
					
						
							|  |  |  | <button onclick="waveform(getElementById('input'), getElementById('waveform'), 'G')">G</button> | 
					
						
							|  |  |  | <button onclick="waveform(getElementById('input'), getElementById('waveform'), 'B')">B</button> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <br> | 
					
						
							|  |  |  | <canvas id="histogram"></canvas> | 
					
						
							|  |  |  | <br> | 
					
						
							|  |  |  | <button onclick="histogram(getElementById('input'), getElementById('histogram'), 'luminance')">Luminance</button> | 
					
						
							|  |  |  | <button onclick="histogram(getElementById('input'), getElementById('histogram'), 'color')">Color</button> | 
					
						
							|  |  |  | <button onclick="histogram(getElementById('input'), getElementById('histogram'), 'R')">R</button> | 
					
						
							|  |  |  | <button onclick="histogram(getElementById('input'), getElementById('histogram'), 'G')">G</button> | 
					
						
							|  |  |  | <button onclick="histogram(getElementById('input'), getElementById('histogram'), 'B')">B</button> | 
					
						
							| 
									
										
										
										
											2019-11-15 17:14:55 +03:00
										 |  |  | --> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <br> | 
					
						
							|  |  |  | <br> | 
					
						
							|  |  |  | <br> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-14 03:55:35 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | </body> | 
					
						
							|  |  |  | </html> | 
					
						
							| 
									
										
										
										
											2019-11-16 15:55:58 +03:00
										 |  |  | <!-- vim:set ts=4 sw=4 : --> |