-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
GitHub Actions
committed
Sep 8, 2024
0 parents
commit 358cf85
Showing
2 changed files
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="./vite.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite + TS</title> | ||
<script type="module" crossorigin>(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const t of document.querySelectorAll('link[rel="modulepreload"]'))n(t);new MutationObserver(t=>{for(const r of t)if(r.type==="childList")for(const s of r.addedNodes)s.tagName==="LINK"&&s.rel==="modulepreload"&&n(s)}).observe(document,{childList:!0,subtree:!0});function i(t){const r={};return t.integrity&&(r.integrity=t.integrity),t.referrerPolicy&&(r.referrerPolicy=t.referrerPolicy),t.crossOrigin==="use-credentials"?r.credentials="include":t.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function n(t){if(t.ep)return;t.ep=!0;const r=i(t);fetch(t.href,r)}})();class w{constructor(e){document.addEventListener("paste",i=>{var r;const n=(r=i.clipboardData)==null?void 0:r.items;let t=0;if(console.log("items",n),!n)throw new Error("Error: no items found");for(let s=0;s<n.length;s++){const l=n[s];if(console.log("item",l),l.kind==="file"){console.log("item",l);const m=l.getAsFile(),u=new FileReader;if(u.onload=d=>{var g,p;if(!((g=d.target)!=null&&g.result))throw new Error("Error: file format not supported");e((p=d.target)==null?void 0:p.result)},u.onerror=d=>{throw new Error(`${d}`)},!m)throw new Error("Error: blob was null");u.readAsDataURL(m)}else t++}if(t===n.length)throw new Error("No image/file found")})}}const c=document.createElement("canvas"),f=c.getContext("2d");if(!f)throw new Error("ERROR: 2d context not supported!");new w(o=>{if(typeof o!="string")throw new Error("Error: arraybuffer not supported!");const e=document.createElement("img");e.src=o,e.onload=()=>{console.log("loaded"),c.width=e.width,c.height=e.height,h(f,e,()=>{}),h(f,e,E)}});function h(o,e,i){var s;o.drawImage(e,0,0);const n=o.getImageData(0,0,c.width,c.height);i(n.data),o.putImageData(n,0,0);const t=document.createElement("img"),r=document.createElement("div");t.src=c.toDataURL(),r.classList.add("img-container"),r.append(t),(s=document.getElementById("content"))==null||s.prepend(r)}function E(o){for(let e=0;e<o.length;e+=4){const i=o[e]/255,n=o[e+1]/255,t=o[e+2]/255,r=a.YtoLstar(a.rgbToY(i,n,t));o[e]=r*255/100,o[e+1]=r*255/100,o[e+2]=r*255/100}}class a{static rgbToY(e,i,n){return .2126*a.sRGBtoLin(e)+.7152*a.sRGBtoLin(i)+.0722*a.sRGBtoLin(n)}static YtoLstar(e){return e<=.008856?e*903.3:Math.pow(e,1/3)*116-16}static sRGBtoLin(e){return e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4)}} | ||
</script> | ||
<style rel="stylesheet" crossorigin>*,html{font-family:Arial,Helvetica,sans-serif;padding:0;margin:0;box-sizing:border-box;--app-color: #ffffff;--pattern-color: rgb(165, 165, 165);--border-color: black}html{display:grid;text-align:center}h1{margin:2rem}#content{display:grid;gap:1rem;padding-bottom:5rem}.img-container{display:flex;justify-content:center;border-top:.25rem solid var(--border-color);border-bottom:.25rem solid var(--border-color);background:linear-gradient(45deg,transparent 49%,var(--pattern-color) 49.99% 50.01%,transparent 51%);background-size:2.5em 2.5em;background-color:var(--app-color);opacity:1} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<h1><b><i>CTRL+V</i></b> <span style="font-weight: 300;">to convert image to perceived lightness (L*)</span></h1> | ||
|
||
<div id="content"></div> | ||
</body> | ||
|
||
</html> |