ragephoto_default_header = { str: "PHOTO - 02/01/17 08:42:44", sum: 1099956068 }
ragephoto_default_json = '{"area":"SANAND","creat":0,"crewid":0,"drctr":false,"loc":{"x":0,"y":0,"z":0},"meme":false,"mid":"","mode":"FREEMODE","mug":false,"nm":"","onislandx":false,"plyrs":[],"rds":"","rsedtr":false,"scr":1,"sid":"0x0","slf":true,"street":0,"time":{"day":11,"hour":12,"minute":6,"month":7,"second":11,"year":2013},"uid":0}'
ragephoto_default_jsonbuf = 3072
ragephoto_default_titlbuf = 256
function setup_libragephoto(module) {
    ragephoto_module = module
    ragephoto_defpbuf_gta5 = module.cwrap("ragephoto_defpbuf_gta5", "number")
    ragephoto_defpbuf_rdr2 = module.cwrap("ragephoto_defpbuf_rdr2", "number")
    ragephoto_format_gta5 = module.cwrap("ragephoto_format_gta5", "number")
    ragephoto_format_rdr2 = module.cwrap("ragephoto_format_rdr2", "number")
    ragephoto_error = module.cwrap("ragephoto_error", "number", ["number"])
    ragephoto_load = module.cwrap("ragephoto_load", "number", ["number", "number", "number"])
    ragephoto_getphotoformat = module.cwrap("ragephoto_getphotoformat", "number", ["number"])
    ragephoto_getphotoheader = module.cwrap("ragephoto_getphotoheader", "string", ["number"])
    ragephoto_getphotojpeg = module.cwrap("ragephoto_getphotojpeg", "number", ["number"])
    ragephoto_getphotojson = module.cwrap("ragephoto_getphotojson", "string", ["number"])
    ragephoto_getphotosign = module.cwrap("ragephoto_getphotosign", "number", ["number"])
    ragephoto_getphotosigns = module.cwrap("ragephoto_getphotosigns", null, ["number", "number", "number"])
    ragephoto_getphotosize = module.cwrap("ragephoto_getphotosize", "number", ["number"])
    ragephoto_getphototitle = module.cwrap("ragephoto_getphototitle", "string", ["number"])
    ragephoto_getsavesize = module.cwrap("ragephoto_getsavesize", "number", ["number"])
    ragephoto_getsavesizef = module.cwrap("ragephoto_getsavesizef", "number", ["number", "number"])
    ragephoto_setphotoformat = module.cwrap("ragephoto_setphotoformat", null, ["number", "number"])
    ragephoto_setphotoheader = module.cwrap("ragephoto_setphotoheader", null, ["number", "string", "number"])
    ragephoto_setphotoheader2 = module.cwrap("ragephoto_setphotoheader2", null, ["number", "string", "number", "number"])
    ragephoto_setphotojpeg = module.cwrap("ragephoto_setphotojpeg", "number", ["number", "number", "number", "number"])
    ragephoto_setphotojson = module.cwrap("ragephoto_setphotojson", null, ["number", "string", "number"])
    ragephoto_setphototitle = module.cwrap("ragephoto_setphototitle", null, ["number", "string", "number"])
    ragephoto_save = module.cwrap("ragephoto_save", "number", ["number", "number"])
    ragephoto_savef = module.cwrap("ragephoto_savef", "number", ["number", "number", "number"])
    ragephoto_version = module.cwrap("ragephoto_version", "string")
    RagePhoto = class RagePhoto {
        constructor() {
            this.instance = module._ragephoto_open()
        }
        clear() {
            module._ragephoto_clear(this.instance)
        }
        load(data) {
            const uint8a_data = new Uint8Array(data)
            const data_buffer = module._malloc(uint8a_data.length)
            module.HEAPU8.set(uint8a_data, data_buffer)
            const result = ragephoto_load(this.instance, data_buffer, uint8a_data.length)
            module._free(data_buffer)
            return result
        }
        get error() {
            return ragephoto_error(this.instance)
        }
        get format() {
            return ragephoto_getphotoformat(this.instance)
        }
        set format(f) {
            ragephoto_setphotoformat(this.instance, f)
        }
        get header() {
            return { str: ragephoto_getphotoheader(this.instance), sum: 0, sum2: 0 }
        }
        set header(h) {
			if (h.sum2 != null) ragephoto_setphotoheader2(this.instance, h.str, h.sum, h.sum2)
			else ragephoto_setphotoheader2(this.instance, h.str, h.sum, 0)
        }
        get jpeg() {
            const psz = this.jpegSize
            if (psz == 0) return null
            const photo_buffer = ragephoto_getphotojpeg(this.instance)
            return module.HEAPU8.subarray(photo_buffer, photo_buffer + psz)
        }
        set jpeg(data) {
            const uint8a_data = new Uint8Array(data)
            let bufsz = RagePhoto.DefaultBuffer.GTA5
            if (this.format == RagePhoto.Format.RDR2) bufsz = RagePhoto.DefaultBuffer.RDR2
            if (uint8a_data.length > bufsz) bufsz = uint8a_data.length
            const data_buffer = module._malloc(uint8a_data.length)
            module.HEAPU8.set(uint8a_data, data_buffer)
            const result = ragephoto_setphotojpeg(this.instance, data_buffer, uint8a_data.length, bufsz)
            module._free(data_buffer)
            return result
        }
        get jpegSign() {
            return ragephoto_getphotosign(this.instance)
        }
        get jpegSize() {
            return ragephoto_getphotosize(this.instance)
        }
        get json() {
            return ragephoto_getphotojson(this.instance)
        }
        set json(j) {
            ragephoto_setphotojson(this.instance, j, ragephoto_default_jsonbuf)
        }
        save() {
            const save_size = this.saveSize
            const save_buffer = module._malloc(save_size)
            ragephoto_save(this.instance, save_buffer)
            const save_array = Uint8Array.from(module.HEAPU8.subarray(save_buffer, save_buffer + save_size))
            module._free(save_buffer)
            return save_array
        }
        get saveSize() {
            return ragephoto_getsavesize(this.instance)
        }
        get title() {
            return ragephoto_getphototitle(this.instance)
        }
        set title(t) {
            ragephoto_setphototitle(this.instance, t, ragephoto_default_titlbuf)
        }
        static get DefaultBuffer() {
            return { GTA5: ragephoto_defpbuf_gta5(), RDR2: ragephoto_defpbuf_rdr2() }
        }
        static get Format() {
            return { GTA5: ragephoto_format_gta5(), RDR2: ragephoto_format_rdr2() }
        }
        static destroy(object) {
            module._ragephoto_close(object.instance)
            delete object.instance
        }
        static get version() {
            return ragephoto_version()
        }
    }
}
function areaWrapper(text) {
    if (text == "AIRP") return "Los Santos International Airport"
    if (text == "ALAMO") return "Alamo Sea"
    if (text == "ALTA") return "Alta"
    if (text == "ARMYB") return "Fort Zancudo"
    if (text == "BANNING") return "Banning"
    if (text == "BAYTRE") return "Baytree Canyon"
    if (text == "BEACH") return "Vespucci Beach"
    if (text == "BHAMCA") return "Banham Canyon"
    if (text == "BRADP") return "Braddock Pass"
    if (text == "BRADT") return "Braddock Tunnel"
    if (text == "BURTON") return "Burton"
    if (text == "CALAFB") return "Calafia Bridge"
    if (text == "CANNY") return "Raton Canyon"
    if (text == "CCREAK") return "Cassidy Creek"
    if (text == "CHAMH") return "Chamberlain Hills"
    if (text == "CHIL") return "Vinewood Hills"
    if (text == "CHU") return "Chumash"
    if (text == "CMSW") return "Chiliad Mountain State Wilderness"
    if (text == "COSI") return "Countryside"
    if (text == "CYPRE") return "Cypress Flats"
    if (text == "DAVIS") return "Davis"
    if (text == "DELBE") return "Del Perro Beach"
    if (text == "DELPE") return "Del Perro"
    if (text == "DELSOL") return "La Puerta"
    if (text == "DESRT") return "Grand Senora Desert"
    if (text == "DOWNT") return "Downtown"
    if (text == "DTVINE") return "Downtown Vinewood"
    if (text == "EAST_V") return "East Vinewood"
    if (text == "EBURO") return "El Burro Heights"
    if (text == "ECLIPS") return "Eclipse"
    if (text == "ELGORL") return "El Gordo Lighthouse"
    if (text == "ELSANT") return "East Los Santos"
    if (text == "ELYSIAN") return "Elysian Island"
    if (text == "GALFISH") return "Galilee"
    if (text == "GALLI") return "Galileo Park"
    if (text == "GOLF") return "GWC and Golfing Society"
    if (text == "GRAPES") return "Grapeseed"
    if (text == "GREATC") return "Great Chaparral"
    if (text == "HARMO") return "Harmony"
    if (text == "HAWICK") return "Hawick"
    if (text == "HEART") return "Heart Attacks Beach"
    if (text == "HORS") return "Vinewood Racetrack"
    if (text == "HUMLAB") return "Humane Labs and Research"
    if (text == "ISHEIST") return "Cayo Perico"
    if (text == "JAIL") return "Bolingbroke Penitentiary"
    if (text == "KOREAT") return "Little Seoul"
    if (text == "LACT") return "Land Act Reservoir"
    if (text == "LAGO") return "Lago Zancudo"
    if (text == "LDAM") return "Land Act Dam"
    if (text == "LMESA") return "La Mesa"
    if (text == "LOSPUER") return "La Puerta"
    if (text == "LOSSF") return "Los Santos Freeway"
    if (text == "MIRR") return "Mirror Park"
    if (text == "MORN") return "Morningwood"
    if (text == "MOVIE") return "Richards Majestic"
    if (text == "MTCHIL") return "Mount Chiliad"
    if (text == "MTGORDO") return "Mount Gordo"
    if (text == "MTJOSE") return "Mount Josiah"
    if (text == "MURRI") return "Murrieta Heights"
    if (text == "NCHU") return "North Chumash"
    if (text == "OBSERV") return "Galileo Observatory"
    if (text == "OCEANA") return "Pacific Ocean"
    if (text == "PALCOV") return "Paleto Cove"
    if (text == "PALETO") return "Paleto Bay"
    if (text == "PALFOR") return "Paleto Forest"
    if (text == "PALHIGH") return "Palomino Highlands"
    if (text == "PALMPOW") return "Palmer-Taylor Power Station"
    if (text == "PBLUFF") return "Pacific Bluffs"
    if (text == "PBOX") return "Pillbox Hill"
    if (text == "PROCOB") return "Procopio Beach"
    if (text == "PROL") return "North Yankton"
    if (text == "RANCHO") return "Rancho"
    if (text == "RGLEN") return "Richman Glen"
    if (text == "RICHM") return "Richman"
    if (text == "ROCKF") return "Rockford Hills"
    if (text == "RTRAK") return "Redwood Lights Track"
    if (text == "SANAND") return "San Andreas"
    if (text == "SANCHIA") return "San Chianski Mountain Range"
    if (text == "SANDY") return "Sandy Shores"
    if (text == "SKID") return "Mission Row"
    if (text == "SLAB") return "Stab City"
    if (text == "SLSANT") return "South Los Santos"
    if (text == "STAD") return "Maze Bank Arena"
    if (text == "STRAW") return "Strawberry"
    if (text == "TATAMO") return "Tataviam Mountains"
    if (text == "TERMINA") return "Terminal"
    if (text == "TEXTI") return "Textile City"
    if (text == "TONGVAH") return "Tongva Hills"
    if (text == "TONGVAV") return "Tongva Valley"
    if (text == "UTOPIAG") return "Utopia Gardens"
    if (text == "VCANA") return "Vespucci Canals"
    if (text == "VESP") return "Vespucci"
    if (text == "VINE") return "Vinewood"
    if (text == "WINDF") return "Ron Alternates Wind Farm"
    if (text == "WMIRROR") return "West Mirror Drive"
    if (text == "WVINE") return "West Vinewood"
    if (text == "ZANCUDO") return "Zancudo River"
    if (text == "ZENORA") return "Senora Freeway"
    return text
}
function generateCreat() {
    return Math.floor(Date.now() / 1000)
}
function generateSign(object) {
    try {
        return object.jpegSign.toString()
    }
    catch {
        const sign_buffer = ragephoto_module._malloc(18)
        ragephoto_getphotosigns(object.instance, sign_buffer, 18)
        let sign_array = ragephoto_module.HEAPU8.subarray(sign_buffer, sign_buffer + 18)
        sign_array = sign_array.filter(element => element)
        let sign = (new TextDecoder()).decode(sign_array)
        ragephoto_module._free(sign_buffer)
        return sign
    }
}
function generateUid() {
    return Math.floor(Math.random() * 2147483647)
}
function exportFileName(title, date, uid) {
    let new_title = title.replaceAll('"', "''")
    new_title = new_title.replaceAll(" ", "_")
    new_title = new_title.replaceAll(":", "-")
    new_title = new_title.replaceAll("\\", "")
    new_title = new_title.replaceAll("{", "")
    new_title = new_title.replaceAll("}", "")
    new_title = new_title.replaceAll("/", "")
    new_title = new_title.replaceAll("<", "")
    new_title = new_title.replaceAll(">", "")
    new_title = new_title.replaceAll("*", "")
    new_title = new_title.replaceAll("?", "")
    new_title = new_title.replaceAll(".", "")
    let date_year = date.getFullYear()
    let date_month = date.getMonth() + 1
    if (date_month < 10) {
        date_month = "0" + date_month
    }
    let date_day = date.getDate()
    if (date_day < 10) {
        date_day = "0" + date_day
    }
    return (date_year + date_month + date_day + "-" + uid + "_" + new_title)
}
function escapeHtml(text) {
    const map = {
        '&': '&amp;',
        '<': '&lt;',
        '>': '&gt;',
        '"': '&quot;',
        "'": '&#039;'
    };
    return text.replace(/[&<>"']/g, function (m) {
        return map[m]
    })
}