"use strict"; import {Common} from "http://localhost:18000/Public/ecma/Utils/Common.ecma.js"; import {Tools} from "../Utils/Tools.ecma.js"; export const SFFPCXModel = (function(){ const SFFPCXModel = function(pcx, palette_size = 0){ const self = this; this.id = null; this.version = null; this.encoding = null; this.bit = null; this.x = null; this.y = null; this.width = null; this.height = null; this.horizontal = null; this.vertical = null; this.color_map = null; this.reserved = null; this.planes = null; this.bytes_per_line = null; this.information = null; this.filler = null; this.data = null; this.ok = null; this.palette = null; const constructor = () => { Object.entries(Tools.load_binary(pcx, [ ["id", "integer", 1], ["version", "integer", 1], ["encoding", "integer", 1], ["bit", "integer", 1], ["x", "integer", 2], ["y", "integer", 2], ["width", "integer", 2], ["height", "integer", 2], ["horizontal", "integer", 2], ["vertical", "integer", 2], ["color_map", (bytes, _) => bytes.reduce((map, byte, j) => { const k = j / 3 >> 0; (map[k] || (map[k] = []))[j % 3] = byte; return map; }), 48], ["reserved", "integer", 1], ["planes", "integer", 1], ["bytes_per_line", "integer", 2], ["information", "integer", 2], ["filler", "bytes", 58], ["data", "bytes", object => pcx.length - 128 - palette_size - (palette_size ? 1 : 0)], ["ok", (bytes, _) => !bytes.length || bytes[0] == 12, palette_size ? 1 : 0], ["palette", "bytes", palette_size] ])).forEach(([key, value]) => { self[key] = value; }); }; constructor(); }; return SFFPCXModel; })(); export const SFFv1ImageModel = (function(){ const SFFv1ImageModel = function(version, data){ const self = this; this.next = null; this.length = null; this.x = null; this.y = null; this.group = null; this.i = null; this.shared_flag = null; this.comments = null; this.image = null; const constructor = () => { Object.entries(Tools.load_binary(data, [ ["next", "integer", 4], ["length", "integer", 4], ["x", "integer", 2], ["y", "integer", 2], ["group", "integer", 2], ["i", "integer", 2], ["shared_flag", "boolean", 1], ["comments", "string", 15], ["image", "bytes", object => object.length] ])).forEach(([key, value]) => { if(key == "image"){ self[key] = new SFFPCXModel(value, self.shared_flag ? 0 : 768); }else self[key] = value; }); }; constructor(); }; return SFFv1ImageModel; })(); export const SFFv1Model = (function(){ const SFFv1Model = function(sff, callback = null){ const self = this; this.signature = ""; this.version = []; this.groups = {}; this.images = []; this.next = null; this.offset_palette = null; this.shared_palette = null; this.comments = ""; const constructor = () => { let images_l, groups_l, offset; Object.entries(Tools.load_binary(sff, [ ["signature", "string", 12], ["version", "bytes", 4], ["groups", "integer", 4], ["images", "integer", 4], ["next", "integer", 4], ["offset_palette", "integer", 4], ["shared_palette", "boolean", 4], ["comments", "string", object => object.next - 36] ])).forEach(([key, value]) => { if(key == "images") images_l = value; else if(key == "groups") groups_l = value; else self[key] = value; }); offset = self.next; while(self.images.length < images_l){ const image = new SFFImageModel(self.version, sff.slice(offset)); self.images.push(image); offset = image.next; }; Common.execute(callback, self); }; constructor(); }; return SFFv1Model; })();