about summary refs log tree commit diff stats
path: root/js/lut-cam
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2024-08-15 06:06:17 -0400
committerelioat <elioat@tilde.institute>2024-08-15 06:06:17 -0400
commit9f6bfa0fc299615b2676bfaa2b6b3a7ee8063531 (patch)
tree5b8012bdc22235fa2ee0aa4e461c46ea19a3054c /js/lut-cam
parent800d420eab70942506f2c96ab63f3d845592e7d2 (diff)
downloadtour-9f6bfa0fc299615b2676bfaa2b6b3a7ee8063531.tar.gz
*
Diffstat (limited to 'js/lut-cam')
-rw-r--r--js/lut-cam/index.html29
-rw-r--r--js/lut-cam/lut.js38
2 files changed, 61 insertions, 6 deletions
diff --git a/js/lut-cam/index.html b/js/lut-cam/index.html
index 28d9b0d..02186c6 100644
--- a/js/lut-cam/index.html
+++ b/js/lut-cam/index.html
@@ -13,7 +13,7 @@
             display: flex;
             justify-content: center;
             align-items: center;
-            background-color: #000;
+            background-color: beige;
         }
         #canvas {
             width: 100%;
@@ -40,6 +40,27 @@
             font-size: 18px;
             cursor: pointer;
         }
+
+        button, select {
+            border: none;
+            cursor: pointer;
+            transition: background-color 0.3s ease;
+        }
+
+        button:hover, button:focus {
+            outline: none; 
+        }
+
+        button.capture {
+            background-color: teal;
+            color: #FFFFFF;
+        }
+
+        button.capture:disabled {
+            background-color: #ccc;
+            color: #5c5c5c;
+        }
+
     </style>
 </head>
 <body>
@@ -66,10 +87,14 @@
 </div>
 
 <div id="controls">
+    <div id="focus-container">
+        <input style="display: none;" type="range" id="focus-slider" min="0" max="100" step="1" value="50" disabled>
+    </div>
     <button id="toggle-camera">Turn Camera On</button>
-    <button id="capture" disabled>Capture Frame</button>
+    <button id="capture" disabled class="capture">Capture Image</button>
 </div>
 
+
 <script src="lut.js"></script>
 </body>
 </html>
diff --git a/js/lut-cam/lut.js b/js/lut-cam/lut.js
index 1c298e3..0bd7dae 100644
--- a/js/lut-cam/lut.js
+++ b/js/lut-cam/lut.js
@@ -31,6 +31,9 @@ const LUTs = {
 
 let currentLUT = null;
 
+const focusSlider = document.getElementById('focus-slider');
+let track = null;
+
 function startCamera() {
     navigator.mediaDevices.getUserMedia({ video: { facingMode: { ideal: 'environment' } } })
         .then(s => {
@@ -40,11 +43,35 @@ function startCamera() {
             canvas.style.display = 'block'; // Show the canvas
             lutSelect.disabled = false;
             captureButton.disabled = false;
-
-            // Display the video feed on the canvas
+            captureButton.active = true;
+            focusSlider.disabled = false;
+
+            track = stream.getVideoTracks()[0];
+            const settings = track.getSettings();
+
+            // So, I don't seem to have a device where this is supported
+            // Check if focus control is supported with this browser and device combo
+            if ('focusDistance' in settings) {
+                // If it is available, enable the slider for focus control
+                focusSlider.style.display = 'block';
+
+                // Set initial focus value, and a fallback
+                focusSlider.value = settings.focusDistance || focusSlider.min;
+
+                focusSlider.addEventListener('input', () => {
+                    track.applyConstraints({
+                        advanced: [{ focusDistance: focusSlider.value }]
+                    });
+                });
+            } else {
+                console.warn('Focus control is not supported on this device.');
+                focusSlider.style.display = 'none';
+            }
+
+            // Draw the video feed to the canvas
             video.addEventListener('play', function() {
                 function step() {
-                    if (!cameraOn) return; // Don't show the video feed if there isn't a video feed to show
+                    if (!cameraOn) return;
                     drawVideoProportional();
                     applyLUT();
                     requestAnimationFrame(step);
@@ -61,13 +88,16 @@ function stopCamera() {
     if (stream) {
         stream.getTracks().forEach(track => track.stop());
         video.pause();
-        canvas.style.display = 'none';
+        canvas.style.display = 'none'; // hide the canvas
         lutSelect.disabled = true;
         captureButton.disabled = true;
+        captureButton.active = false;
+        focusSlider.disabled = true;
         stream = null;
     }
 }
 
+
 function drawVideoProportional() {
     const videoAspectRatio = video.videoWidth / video.videoHeight;
     const canvasAspectRatio = canvas.width / canvas.height;
'n353' href='#n353'>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