minitel-mosaic
Advanced tools
Comparing version 2.0.4 to 2.0.5
@@ -1,4 +0,4 @@ | ||
import { MinitelObject } from "minitel-standalone/dist/abstract/minitelobject"; | ||
import { RichCharGrid } from "minitel-standalone/dist/richchargrid"; | ||
import { MinitelObjectAttributes } from "minitel-standalone/dist/types"; | ||
import { MinitelObject } from "minitel-standalone/dist/abstract/minitelobject.js"; | ||
import { RichCharGrid } from "minitel-standalone/dist/richchargrid.js"; | ||
import { MinitelObjectAttributes } from "minitel-standalone/dist/types.js"; | ||
export interface ImageAttributes extends MinitelObjectAttributes { | ||
@@ -5,0 +5,0 @@ imageData: number[][][] | null; |
@@ -1,10 +0,7 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Image = void 0; | ||
const minitelobject_1 = require("minitel-standalone/dist/abstract/minitelobject"); | ||
const richchargrid_1 = require("minitel-standalone/dist/richchargrid"); | ||
const get_fg_bg_1 = require("../utils/get_fg_bg"); | ||
const sg_to_ascii_1 = require("../utils/sg_to_ascii"); | ||
const richchar_1 = require("minitel-standalone/dist/richchar"); | ||
class Image extends minitelobject_1.MinitelObject { | ||
import { MinitelObject } from "minitel-standalone/dist/abstract/minitelobject.js"; | ||
import { RichCharGrid } from "minitel-standalone/dist/richchargrid.js"; | ||
import { getFgBg } from "../utils/get_fg_bg.js"; | ||
import { sgToAscii } from "../utils/sg_to_ascii.js"; | ||
import { RichChar } from "minitel-standalone/dist/richchar.js"; | ||
export class Image extends MinitelObject { | ||
constructor() { | ||
@@ -20,3 +17,3 @@ super(...arguments); | ||
if (img == null) { | ||
return new richchargrid_1.RichCharGrid(); | ||
return new RichCharGrid(); | ||
} | ||
@@ -37,3 +34,3 @@ const clusters = []; | ||
// Step 2. Collect the best fg/bg pairs | ||
const fgBgPairs = clusters.map((cluster) => (0, get_fg_bg_1.getFgBg)(this.minitel.colors, cluster)); | ||
const fgBgPairs = clusters.map((cluster) => getFgBg(this.minitel.colors, cluster)); | ||
const lookupMap = {}; | ||
@@ -43,11 +40,11 @@ for (let idx in this.minitel.colors) { | ||
} | ||
const result = new richchargrid_1.RichCharGrid(); | ||
const result = new RichCharGrid(); | ||
let weAt = 0; | ||
for (let y = 0; y < img.length; y += 3) { | ||
let currLine = new richchargrid_1.RichCharGrid(); | ||
let currLine = new RichCharGrid(); | ||
for (let x = 0; x < img[0].length; x += 2) { | ||
const { pixelsAsSg, bgFg: [bg, fg] } = fgBgPairs[weAt]; | ||
const chr = (0, sg_to_ascii_1.sgToAscii)(pixelsAsSg); | ||
const richChar = new richchar_1.RichChar(chr, { charset: 1, fg: lookupMap[fg.join()], bg: lookupMap[bg.join()] }); | ||
currLine.mergeX(new richchargrid_1.RichCharGrid([[richChar]]), 'end'); | ||
const chr = sgToAscii(pixelsAsSg); | ||
const richChar = new RichChar(chr, { charset: 1, fg: lookupMap[fg.join()], bg: lookupMap[bg.join()] }); | ||
currLine.mergeX(new RichCharGrid([[richChar]]), 'end'); | ||
weAt += 1; | ||
@@ -60,6 +57,5 @@ } | ||
} | ||
exports.Image = Image; | ||
Image.defaultAttributes = { | ||
...(minitelobject_1.MinitelObject.defaultAttributes), | ||
...(MinitelObject.defaultAttributes), | ||
imageData: null, | ||
}; |
@@ -1,3 +0,3 @@ | ||
/// <reference types="node" /> | ||
import { ColorTriplet } from "../types"; | ||
/// <reference types="node" resolution-mode="require"/> | ||
import { ColorTriplet } from "../types.js"; | ||
export declare function anyHandler(inputImage: Buffer): Promise<ColorTriplet[][]>; |
@@ -1,12 +0,5 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.anyHandler = void 0; | ||
const sharp_1 = __importDefault(require("sharp")); | ||
const sharp_2 = require("./sharp"); | ||
async function anyHandler(inputImage) { | ||
return (0, sharp_2.sharpHandler)((0, sharp_1.default)(inputImage)); | ||
import sharp from "sharp"; | ||
import { sharpHandler } from "./sharp.js"; | ||
export async function anyHandler(inputImage) { | ||
return sharpHandler(sharp(inputImage)); | ||
} | ||
exports.anyHandler = anyHandler; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
// export function defaultImg() { | ||
@@ -13,5 +12,3 @@ // const w = () => [255, 255, 255]; | ||
// } | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defaultImg = void 0; | ||
function defaultImg() { | ||
export function defaultImg() { | ||
return [ | ||
@@ -26,2 +23,1 @@ [[255, 255, 255], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [255, 255, 255], [0, 0, 0], [0, 0, 0], [0, 0, 0], [255, 255, 255], [0, 0, 0], [0, 0, 0], [255, 255, 255], [255, 255, 255], [0, 0, 0], [0, 0, 0], [255, 255, 255], [0, 0, 0], [255, 255, 255], [0, 0, 0], [0, 0, 0], [255, 255, 255], [0, 0, 0], [0, 0, 0], [255, 255, 255], [255, 255, 255]], | ||
} | ||
exports.defaultImg = defaultImg; |
import type { Sharp } from "sharp"; | ||
import { ColorTriplet } from "../types"; | ||
import { ColorTriplet } from "../types.js"; | ||
export declare function sharpHandler(sharpInstance: Sharp): Promise<ColorTriplet[][]>; |
@@ -1,5 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.sharpHandler = void 0; | ||
async function sharpHandler(sharpInstance) { | ||
export async function sharpHandler(sharpInstance) { | ||
const { data, info } = await sharpInstance | ||
@@ -24,2 +21,1 @@ .raw() | ||
} | ||
exports.sharpHandler = sharpHandler; |
@@ -1,6 +0,6 @@ | ||
import { Image, ImageAttributes } from './components/image'; | ||
import { anyHandler } from './converters/any'; | ||
import { sharpHandler } from './converters/sharp'; | ||
import { defaultImg } from './converters/default'; | ||
import { Image, ImageAttributes } from './components/image.js'; | ||
import { anyHandler } from './converters/any.js'; | ||
import { sharpHandler } from './converters/sharp.js'; | ||
import { defaultImg } from './converters/default.js'; | ||
export { Image, anyHandler, sharpHandler, defaultImg }; | ||
export { ImageAttributes }; |
@@ -1,11 +0,5 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defaultImg = exports.sharpHandler = exports.anyHandler = exports.Image = void 0; | ||
const image_1 = require("./components/image"); | ||
Object.defineProperty(exports, "Image", { enumerable: true, get: function () { return image_1.Image; } }); | ||
const any_1 = require("./converters/any"); | ||
Object.defineProperty(exports, "anyHandler", { enumerable: true, get: function () { return any_1.anyHandler; } }); | ||
const sharp_1 = require("./converters/sharp"); | ||
Object.defineProperty(exports, "sharpHandler", { enumerable: true, get: function () { return sharp_1.sharpHandler; } }); | ||
const default_1 = require("./converters/default"); | ||
Object.defineProperty(exports, "defaultImg", { enumerable: true, get: function () { return default_1.defaultImg; } }); | ||
import { Image } from './components/image.js'; | ||
import { anyHandler } from './converters/any.js'; | ||
import { sharpHandler } from './converters/sharp.js'; | ||
import { defaultImg } from './converters/default.js'; | ||
export { Image, anyHandler, sharpHandler, defaultImg }; |
@@ -1,14 +0,9 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const ws_1 = require("ws"); | ||
const stream_1 = require("stream"); | ||
const minitel_standalone_1 = require("minitel-standalone"); | ||
const image_1 = require("../components/image"); | ||
const sharp_1 = require("../converters/sharp"); | ||
const sharp_2 = __importDefault(require("sharp")); | ||
const wss = new ws_1.WebSocketServer({ port: 8080 }); | ||
class DuplexBridge extends stream_1.Duplex { | ||
import { WebSocketServer, createWebSocketStream } from 'ws'; | ||
import { Duplex } from 'stream'; | ||
import { Minitel } from 'minitel-standalone'; | ||
import { Image } from '../components/image.js'; | ||
import { sharpHandler } from '../converters/sharp.js'; | ||
import sharp from 'sharp'; | ||
const wss = new WebSocketServer({ port: 8080 }); | ||
class DuplexBridge extends Duplex { | ||
constructor(destinationStream, ws, opts) { | ||
@@ -33,6 +28,6 @@ super(opts); | ||
wss.on('connection', async function connection(ws) { | ||
const bridge = new DuplexBridge((0, ws_1.createWebSocketStream)(ws, { decodeStrings: false }), ws, { decodeStrings: false }); | ||
const minitel = new minitel_standalone_1.Minitel(bridge, { statusBar: true }); | ||
const bridge = new DuplexBridge(createWebSocketStream(ws, { decodeStrings: false }), ws, { decodeStrings: false }); | ||
const minitel = new Minitel(bridge, { statusBar: true }); | ||
await minitel.readyAsync(); | ||
minitel.appendChild(new image_1.Image([], { imageData: await (0, sharp_1.sharpHandler)((0, sharp_2.default)('./test.png').resize(80, 75)) }, minitel)); | ||
minitel.appendChild(new Image([], { imageData: await sharpHandler(sharp('./test.png').resize(80, 75)) }, minitel)); | ||
// minitel.appendChild(new Image([], { imageData: defaultImg() }, minitel)); | ||
@@ -39,0 +34,0 @@ minitel.on('frame', () => console.log('render done!')); |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
export {}; |
@@ -1,2 +0,2 @@ | ||
import { ColorTriplet } from "../types"; | ||
import { ColorTriplet } from "../types.js"; | ||
export declare function getFgBg(colors: ColorTriplet[], pixels: ColorTriplet[]): { | ||
@@ -3,0 +3,0 @@ bgFg: [ColorTriplet, ColorTriplet]; |
@@ -1,6 +0,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getFgBg = void 0; | ||
const utils_1 = require("./utils"); | ||
function getFgBg(colors, pixels) { | ||
import { computeEuclidianDistance } from "./utils.js"; | ||
export function getFgBg(colors, pixels) { | ||
let leastSum = Infinity; | ||
@@ -15,3 +12,3 @@ let mostEfficient = null; | ||
for (let pixel of pixels) { | ||
const pixelCloseness = bf.map((v) => (0, utils_1.computeEuclidianDistance)(pixel, v)); | ||
const pixelCloseness = bf.map((v) => computeEuclidianDistance(pixel, v)); | ||
const closest = Math.min(...pixelCloseness); | ||
@@ -31,2 +28,1 @@ sum += closest; | ||
} | ||
exports.getFgBg = getFgBg; |
@@ -1,5 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.sgToAscii = void 0; | ||
function sgToAscii(sg) { | ||
export function sgToAscii(sg) { | ||
let result = 32; | ||
@@ -17,2 +14,1 @@ result += +sg[0]; | ||
} | ||
exports.sgToAscii = sgToAscii; |
@@ -1,2 +0,2 @@ | ||
import { ColorTriplet } from "../types"; | ||
import { ColorTriplet } from "../types.js"; | ||
export declare function computeEuclidianDistance([x1, y1, z1]: ColorTriplet, [x2, y2, z2]: ColorTriplet): number; |
@@ -1,7 +0,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.computeEuclidianDistance = void 0; | ||
function computeEuclidianDistance([x1, y1, z1], [x2, y2, z2]) { | ||
export function computeEuclidianDistance([x1, y1, z1], [x2, y2, z2]) { | ||
return Math.hypot(x1 - x2, y1 - y2, z1 - z2); | ||
} | ||
exports.computeEuclidianDistance = computeEuclidianDistance; |
{ | ||
"name": "minitel-mosaic", | ||
"version": "2.0.4", | ||
"version": "2.0.5", | ||
"description": "A mosaic adaptor for immjs's minitel npm ecoystem", | ||
"main": "dist/index.js", | ||
"type": "module", | ||
"scripts": { | ||
@@ -7,0 +8,0 @@ "test": "echo \"Error: no test specified\" && exit 1", |
@@ -1,8 +0,8 @@ | ||
import { MinitelObject } from "minitel-standalone/dist/abstract/minitelobject"; | ||
import { RichCharGrid } from "minitel-standalone/dist/richchargrid"; | ||
import { MinitelObjectAttributes } from "minitel-standalone/dist/types"; | ||
import { getFgBg } from "../utils/get_fg_bg"; | ||
import { ColorTriplet } from "../types"; | ||
import { sgToAscii } from "../utils/sg_to_ascii"; | ||
import { RichChar } from "minitel-standalone/dist/richchar"; | ||
import { MinitelObject } from "minitel-standalone/dist/abstract/minitelobject.js"; | ||
import { RichCharGrid } from "minitel-standalone/dist/richchargrid.js"; | ||
import { MinitelObjectAttributes } from "minitel-standalone/dist/types.js"; | ||
import { getFgBg } from "../utils/get_fg_bg.js"; | ||
import { ColorTriplet } from "../types.js"; | ||
import { sgToAscii } from "../utils/sg_to_ascii.js"; | ||
import { RichChar } from "minitel-standalone/dist/richchar.js"; | ||
@@ -9,0 +9,0 @@ export interface ImageAttributes extends MinitelObjectAttributes { |
import sharp from "sharp"; | ||
import { ColorTriplet } from "../types"; | ||
import { sharpHandler } from "./sharp"; | ||
import { ColorTriplet } from "../types.js"; | ||
import { sharpHandler } from "./sharp.js"; | ||
@@ -5,0 +5,0 @@ export async function anyHandler(inputImage: Buffer): Promise<ColorTriplet[][]> { |
import type { Sharp } from "sharp"; | ||
import { ColorTriplet } from "../types"; | ||
import { ColorTriplet } from "../types.js"; | ||
@@ -4,0 +4,0 @@ export async function sharpHandler(sharpInstance: Sharp): Promise<ColorTriplet[][]> { |
@@ -1,6 +0,6 @@ | ||
import { Image, ImageAttributes } from './components/image'; | ||
import { Image, ImageAttributes } from './components/image.js'; | ||
import { anyHandler } from './converters/any'; | ||
import { sharpHandler } from './converters/sharp'; | ||
import { defaultImg } from './converters/default'; | ||
import { anyHandler } from './converters/any.js'; | ||
import { sharpHandler } from './converters/sharp.js'; | ||
import { defaultImg } from './converters/default.js'; | ||
@@ -7,0 +7,0 @@ export { Image, anyHandler, sharpHandler, defaultImg }; |
@@ -5,5 +5,4 @@ import { WebSocket, WebSocketServer, createWebSocketStream } from 'ws'; | ||
import { Minitel, Paragraph, Scrollable } from 'minitel-standalone'; | ||
import { Image } from '../components/image'; | ||
import { defaultImg } from '../converters/default'; | ||
import { sharpHandler } from '../converters/sharp'; | ||
import { Image } from '../components/image.js'; | ||
import { sharpHandler } from '../converters/sharp.js'; | ||
import sharp from 'sharp'; | ||
@@ -10,0 +9,0 @@ |
@@ -1,3 +0,3 @@ | ||
import { ColorTriplet } from "../types"; | ||
import { computeEuclidianDistance } from "./utils"; | ||
import { ColorTriplet } from "../types.js"; | ||
import { computeEuclidianDistance } from "./utils.js"; | ||
@@ -4,0 +4,0 @@ export function getFgBg(colors: ColorTriplet[], pixels: ColorTriplet[]) { |
@@ -1,2 +0,2 @@ | ||
import { ColorTriplet } from "../types"; | ||
import { ColorTriplet } from "../types.js"; | ||
@@ -3,0 +3,0 @@ export function computeEuclidianDistance([x1, y1, z1]: ColorTriplet, [x2, y2, z2]: ColorTriplet) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Yes
37386
575