3dlut-base-cube-maker.html 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <!doctype html>
  2. <html>
  3. <meta charset="utf-8">
  4. <head>
  5. <title>3DLUT Base Cube Maker</title>
  6. <style>
  7. canvas {
  8. min-width: 512px;
  9. min-height: 64px;
  10. image-rendering: pixelated;
  11. }
  12. #cube {
  13. max-width: calc(100vw - 20px);
  14. overflow: auto;
  15. }
  16. </style>
  17. </head>
  18. <body>
  19. <h1>Color Cube Image Maker</h1>
  20. <div>size:<input id="size" type="number" value="8" min="2" max="64"/></div>
  21. <p><button type="button">Save...</button></p>
  22. <div id="cube"><canvas></canvas></div>
  23. <div>( note: actual image size is
  24. <span id="width"></span>x<span id="height"></span> )</div>
  25. </p>
  26. </body>
  27. <script>
  28. 'use strict';
  29. const ctx = document.querySelector('canvas').getContext('2d');
  30. function drawColorCubeImage(ctx, size) {
  31. const canvas = ctx.canvas;
  32. canvas.width = size * size;
  33. canvas.height = size;
  34. for (let zz = 0; zz < size; ++zz) {
  35. for (let yy = 0; yy < size; ++yy) {
  36. for (let xx = 0; xx < size; ++xx) {
  37. const r = Math.floor(xx / (size - 1) * 255);
  38. const g = Math.floor(yy / (size - 1) * 255);
  39. const b = Math.floor(zz / (size - 1) * 255);
  40. ctx.fillStyle = `rgb(${r},${g},${b})`;
  41. ctx.fillRect(zz * size + xx, yy, 1, 1);
  42. }
  43. }
  44. }
  45. document.querySelector('#width').textContent = canvas.width;
  46. document.querySelector('#height').textContent = canvas.height;
  47. }
  48. drawColorCubeImage(ctx, 8);
  49. function handleSizeChange(event) {
  50. const elem = event.target;
  51. elem.style.background = '';
  52. try {
  53. const size = parseInt(elem.value);
  54. if (size >= 2 && size <= 64) {
  55. drawColorCubeImage(ctx, size);
  56. }
  57. } catch (e) {
  58. elem.style.background = 'red';
  59. }
  60. }
  61. const sizeElem = document.querySelector('#size');
  62. sizeElem.addEventListener('change', handleSizeChange, true);
  63. const saveData = (function() {
  64. const a = document.createElement('a');
  65. document.body.appendChild(a);
  66. a.style.display = 'none';
  67. return function saveData(blob, fileName) {
  68. const url = window.URL.createObjectURL(blob);
  69. a.href = url;
  70. a.download = fileName;
  71. a.click();
  72. };
  73. }());
  74. document.querySelector('button').addEventListener('click', () => {
  75. ctx.canvas.toBlob((blob) => {
  76. saveData(blob, `identity-lut-s${ctx.canvas.height}.png`);
  77. });
  78. });
  79. </script>
  80. </html>