import{t as u}from"./index-CWvpOmY5.js";const d={quality:50,qualityAlpha:-1,denoiseLevel:0,tileColsLog2:0,tileRowsLog2:0,speed:6,subsample:1,chromaDeltaQ:!1,sharpness:0,tune:0,enableSharpYUV:!1,bitDepth:8,lossless:!1};function o(t,s,e={}){let n;return s&&(n=(a,l)=>{const r=new WebAssembly.Instance(s,a);return l(r),r.exports}),t({noInitialRun:!0,instantiateWasm:n,...e})}let i;const f=()=>typeof process<"u"&&process.release&&process.release.name==="node",c=()=>{var t;return((t=globalThis.caches)===null||t===void 0?void 0:t.default)!==void 0};async function p(t,s){let e=t,n=s;if(arguments.length===1&&!(t instanceof WebAssembly.Module)&&(e=void 0,n=t),!f()&&!c()&&await u()){const l=await import("./avif_enc_mt-DL2yi-mK.js");return i=o(l.default,e,n),i}const a=await import("./avif_enc-GHSQWwbh.js");return i=o(a.default,e,n),i}async function b(t,s={}){i||(i=p());const e={...d,...s};if(e.bitDepth!==8&&e.bitDepth!==10&&e.bitDepth!==12)throw new Error("Invalid bit depth. Supported values are 8, 10, or 12.");if(!(t.data instanceof Uint16Array)&&e.bitDepth!==8)throw new Error("Invalid image data for bit depth. Must use Uint16Array for bit depths greater than 8.");e.lossless&&(s.quality!==void 0&&s.quality!==100&&console.warn("AVIF lossless: Quality setting is ignored when lossless is enabled (quality must be 100)."),s.qualityAlpha!==void 0&&s.qualityAlpha!==100&&s.qualityAlpha!==-1&&console.warn("AVIF lossless: QualityAlpha setting is ignored when lossless is enabled (qualityAlpha must be 100 or -1)."),s.subsample!==void 0&&s.subsample!==3&&console.warn("AVIF lossless: Subsample setting is ignored when lossless is enabled (subsample must be 3 for YUV444)."),e.quality=100,e.qualityAlpha=-1,e.subsample=3);const a=(await i).encode(new Uint8Array(t.data.buffer),t.width,t.height,e);if(!a)throw new Error("Encoding error.");return a.buffer}export{b as encode};
