{"version":3,"file":"image_resizer.mjs","names":[],"sources":["../../../../src/client/external/browser/image_resizer.ts"],"sourcesContent":["import { isSameSize } from '../../../shared/is_same_size.ts'\n\nexport const createImageResizer =\n\t({ width, height }: { width: number; height: number }) =>\n\t(image: ImageData) => {\n\t\tif (isSameSize(image, { width, height })) return image\n\n\t\tconst inArea = (x: number, y: number) => y <= image.height && x <= image.width\n\n\t\tconst data = new Uint8ClampedArray(width * height * 4)\n\t\tconst result = new ImageData(data, width, height, { colorSpace: image.colorSpace })\n\n\t\tfor (let y = 0; y < height; y++) {\n\t\t\tfor (let x = 0; x < width; x++) {\n\t\t\t\tconst idx = (width * y + x) << 2\n\t\t\t\tif (inArea(x, y)) {\n\t\t\t\t\tconst old = (image.width * y + x) << 2\n\t\t\t\t\tresult.data[idx] = image.data[old]!\n\t\t\t\t\tresult.data[idx + 1] = image.data[old + 1]!\n\t\t\t\t\tresult.data[idx + 2] = image.data[old + 2]!\n\t\t\t\t\tresult.data[idx + 3] = image.data[old + 3]!\n\t\t\t\t} else {\n\t\t\t\t\tresult.data[idx] = 0\n\t\t\t\t\tresult.data[idx + 1] = 0\n\t\t\t\t\tresult.data[idx + 2] = 0\n\t\t\t\t\tresult.data[idx + 3] = 64\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn result\n\t}\n\n// slower\nexport const createImageResizer2 =\n\t({ width, height }: { width: number; height: number }) =>\n\t(image: ImageData) => {\n\t\tif (isSameSize(image, { width, height })) return image\n\n\t\tconst inArea = (x: number, y: number) => y <= image.height && x <= image.width\n\n\t\tconst data = new Uint8ClampedArray(width * height * 4)\n\t\tconst result = new ImageData(data, width, height, { colorSpace: image.colorSpace })\n\n\t\tconst copyBytes = image.width * 4\n\t\tfor (let y = 0; y < height; y++) {\n\t\t\tresult.data.set(image.data.slice(y * image.width, copyBytes), y * width * 4)\n\t\t\tfor (let x = image.width; x < width; x++) {\n\t\t\t\tconst idx = (width * y + x) << 2\n\t\t\t\tif (!inArea(x, y)) {\n\t\t\t\t\tresult.data[idx] = 0\n\t\t\t\t\tresult.data[idx + 1] = 0\n\t\t\t\t\tresult.data[idx + 2] = 0\n\t\t\t\t\tresult.data[idx + 3] = 64\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result\n\t}\n"],"mappings":";;;AAEA,MAAa,sBACX,EAAE,OAAO,cACT,UAAqB;AACrB,KAAI,WAAW,OAAO;EAAE;EAAO;EAAQ,CAAC,CAAE,QAAO;CAEjD,MAAM,UAAU,GAAW,MAAc,KAAK,MAAM,UAAU,KAAK,MAAM;CAEzE,MAAM,OAAO,IAAI,kBAAkB,QAAQ,SAAS,EAAE;CACtD,MAAM,SAAS,IAAI,UAAU,MAAM,OAAO,QAAQ,EAAE,YAAY,MAAM,YAAY,CAAC;AAEnF,MAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,IAC3B,MAAK,IAAI,IAAI,GAAG,IAAI,OAAO,KAAK;EAC/B,MAAM,MAAO,QAAQ,IAAI,KAAM;AAC/B,MAAI,OAAO,GAAG,EAAE,EAAE;GACjB,MAAM,MAAO,MAAM,QAAQ,IAAI,KAAM;AACrC,UAAO,KAAK,OAAO,MAAM,KAAK;AAC9B,UAAO,KAAK,MAAM,KAAK,MAAM,KAAK,MAAM;AACxC,UAAO,KAAK,MAAM,KAAK,MAAM,KAAK,MAAM;AACxC,UAAO,KAAK,MAAM,KAAK,MAAM,KAAK,MAAM;SAClC;AACN,UAAO,KAAK,OAAO;AACnB,UAAO,KAAK,MAAM,KAAK;AACvB,UAAO,KAAK,MAAM,KAAK;AACvB,UAAO,KAAK,MAAM,KAAK;;;AAK1B,QAAO"}