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EAAM,IAAO,IACpC,GAAQ,EAAM,OAAO,QAAU,EAAM,OAAO,QAAU,EAAM,KAAQ,GAErE,aAAa,EAAO,GAGpB,eAAe,EAAO,EAAK,GAExB,CACX","file":"/npm/@jimp/plugin-rotate@1.6.0/dist/commonjs/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.19.2.\n * Original file: /npm/@jimp/plugin-rotate@1.6.0/dist/commonjs/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.methods = void 0;\nconst plugin_resize_1 = require(\"@jimp/plugin-resize\");\nconst utils_1 = require(\"@jimp/utils\");\nconst core_1 = require(\"@jimp/core\");\nconst plugin_crop_1 = require(\"@jimp/plugin-crop\");\nconst zod_1 = require(\"zod\");\nconst RotateOptionsSchema = zod_1.z.union([\n    zod_1.z.number(),\n    zod_1.z.object({\n        /** the number of degrees to rotate the image by */\n        deg: zod_1.z.number(),\n        /** resize mode or a boolean, if false then the width and height of the image will not be changed */\n        mode: zod_1.z.union([zod_1.z.boolean(), zod_1.z.nativeEnum(plugin_resize_1.ResizeStrategy)]).optional(),\n    }),\n]);\n/** function to translate the x, y coordinate to the index of the pixel in the buffer */\nfunction createIdxTranslationFunction(w) {\n    return function (x, y) {\n        return (y * w + x) << 2;\n    };\n}\n/**\n * Rotates an image counter-clockwise by multiple of 90 degrees. NB: 'this' must be a Jimp object.\n *\n * This function is based on matrix rotation. Check this to get an initial idea how it works: https://stackoverflow.com/a/8664879/10561909\n *\n * @param deg the number of degrees to rotate the image by, it should be a multiple of 90\n */\nfunction matrixRotate(image, deg) {\n    if (Math.abs(deg) % 90 !== 0) {\n        throw new Error(\"Unsupported matrix rotation degree\");\n    }\n    const w = image.bitmap.width;\n    const h = image.bitmap.height;\n    // decide which rotation angle to use\n    let angle;\n    switch (deg) {\n        // 90 degree & -270 degree are same\n        case 90:\n        case -270:\n            angle = 90;\n            break;\n        case 180:\n        case -180:\n            angle = 180;\n            break;\n        case 270:\n        case -90:\n            angle = -90;\n            break;\n        default:\n            throw new Error(\"Unsupported matrix rotation degree\");\n    }\n    // After this switch block, angle will be 90, 180 or -90\n    // calculate the new width and height\n    const nW = angle === 180 ? w : h;\n    const nH = angle === 180 ? h : w;\n    const dstBuffer = Buffer.alloc(image.bitmap.data.length);\n    const srcIdxFunction = createIdxTranslationFunction(w);\n    const dstIdxFunction = createIdxTranslationFunction(nW);\n    for (let x = 0; x < w; x++) {\n        for (let y = 0; y < h; y++) {\n            const srcIdx = srcIdxFunction(x, y);\n            const pixelRGBA = image.bitmap.data.readUInt32BE(srcIdx);\n            let dstIdx;\n            switch (angle) {\n                case 90:\n                    dstIdx = dstIdxFunction(y, w - x - 1);\n                    break;\n                case -90:\n                    dstIdx = dstIdxFunction(h - y - 1, x);\n                    break;\n                case 180:\n                    dstIdx = dstIdxFunction(w - x - 1, h - y - 1);\n                    break;\n                default:\n                    throw new Error(\"Unsupported matrix rotation angle\");\n            }\n            dstBuffer.writeUInt32BE(pixelRGBA, dstIdx);\n        }\n    }\n    image.bitmap.data = dstBuffer;\n    image.bitmap.width = nW;\n    image.bitmap.height = nH;\n}\nfunction createTranslationFunction(deltaX, deltaY) {\n    return function (x, y) {\n        return {\n            x: x + deltaX,\n            y: y + deltaY,\n        };\n    };\n}\n/**\n * Rotates an image counter-clockwise by an arbitrary number of degrees. NB: 'this' must be a Jimp object.\n * @param {number} deg the number of degrees to rotate the image by\n */\nfunction advancedRotate(image, deg, mode) {\n    const rad = (deg * Math.PI) / 180;\n    const cosine = Math.cos(rad);\n    const sine = Math.sin(rad);\n    // the final width and height will change if resize == true\n    let w = image.bitmap.width;\n    let h = image.bitmap.height;\n    if (mode === true || typeof mode === \"string\") {\n        // resize the image to it maximum dimension and blit the existing image\n        // onto the center so that when it is rotated the image is kept in bounds\n        // http://stackoverflow.com/questions/3231176/how-to-get-size-of-a-rotated-rectangle\n        // Plus 1 border pixel to ensure to show all rotated result for some cases.\n        w =\n            Math.ceil(Math.abs(image.bitmap.width * cosine) +\n                Math.abs(image.bitmap.height * sine)) + 1;\n        h =\n            Math.ceil(Math.abs(image.bitmap.width * sine) +\n                Math.abs(image.bitmap.height * cosine)) + 1;\n        // Ensure destination to have even size to a better result.\n        if (w % 2 !== 0) {\n            w++;\n        }\n        if (h % 2 !== 0) {\n            h++;\n        }\n        const c = (0, utils_1.clone)(image);\n        image.scan((_, __, idx) => {\n            image.bitmap.data.writeUInt32BE(image.background, idx);\n        });\n        const max = Math.max(w, h, image.bitmap.width, image.bitmap.height);\n        image = plugin_resize_1.methods.resize(image, {\n            h: max,\n            w: max,\n            mode: mode === true ? undefined : mode,\n        });\n        image = (0, core_1.composite)(image, c, image.bitmap.width / 2 - c.bitmap.width / 2, image.bitmap.height / 2 - c.bitmap.height / 2);\n    }\n    const bW = image.bitmap.width;\n    const bH = image.bitmap.height;\n    const dstBuffer = Buffer.alloc(image.bitmap.data.length);\n    const translate2Cartesian = createTranslationFunction(-(bW / 2), -(bH / 2));\n    const translate2Screen = createTranslationFunction(bW / 2 + 0.5, bH / 2 + 0.5);\n    for (let y = 1; y <= bH; y++) {\n        for (let x = 1; x <= bW; x++) {\n            const cartesian = translate2Cartesian(x, y);\n            const source = translate2Screen(cosine * cartesian.x - sine * cartesian.y, cosine * cartesian.y + sine * cartesian.x);\n            const dstIdx = (bW * (y - 1) + x - 1) << 2;\n            if (source.x >= 0 && source.x < bW && source.y >= 0 && source.y < bH) {\n                const srcIdx = ((bW * (source.y | 0) + source.x) | 0) << 2;\n                const pixelRGBA = image.bitmap.data.readUInt32BE(srcIdx);\n                dstBuffer.writeUInt32BE(pixelRGBA, dstIdx);\n            }\n            else {\n                // reset off-image pixels\n                dstBuffer.writeUInt32BE(image.background, dstIdx);\n            }\n        }\n    }\n    image.bitmap.data = dstBuffer;\n    if (mode === true || typeof mode === \"string\") {\n        // now crop the image to the final size\n        const x = Math.max(bW / 2 - w / 2, 0);\n        const y = Math.max(bH / 2 - h / 2, 0);\n        image = plugin_crop_1.methods.crop(image, { x, y, w, h });\n    }\n}\nexports.methods = {\n    /**\n     * Rotates the image counter-clockwise by a number of degrees. By default the width and height of the image will be resized appropriately.\n     * @example\n     * ```ts\n     * import { Jimp } from \"jimp\";\n     *\n     * const image = await Jimp.read(\"test/image.png\");\n     *\n     * image.rotate(90);\n     * ```\n     */\n    rotate(image, options) {\n        const parsed = RotateOptionsSchema.parse(options);\n        const actualOptions = typeof parsed === \"number\" ? { deg: parsed } : parsed;\n        const { mode = true } = actualOptions;\n        let { deg } = actualOptions;\n        // No need to do extra rotation\n        deg %= 360;\n        // no rotation for 0, 360, -360, 720, -720, ...\n        if (deg % 360 === 0) {\n            return image;\n        }\n        // use matrixRotate if the angle is a multiple of 90 degrees (eg: 180 or -90) and resize is allowed or not needed.\n        const matrixRotateAllowed = deg % 90 === 0 &&\n            (mode || image.bitmap.width === image.bitmap.height || deg % 180 === 0);\n        if (matrixRotateAllowed) {\n            matrixRotate(image, deg);\n        }\n        else {\n            advancedRotate(image, deg, mode);\n        }\n        return image;\n    },\n};\n"]}