@psdk/frame-imageb
Advanced tools
Comparing version 0.3.4 to 0.4.0
@@ -1,1 +0,17 @@ | ||
export * from './process'; | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./process"), exports); |
@@ -1,24 +0,32 @@ | ||
import { ImagebProcesser } from "../process"; | ||
import { ProcessedImage, ProcessedResult, ThresholdValueMode } from "../../types"; | ||
import { ImagebTool } from "../../tools"; | ||
export class AbstractThreshold extends ImagebProcesser { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PinedThresholdValue = exports.ThresholdValue = exports.AbstractThreshold = void 0; | ||
const process_1 = require("../process"); | ||
const types_1 = require("../../types"); | ||
const tools_1 = require("../../tools"); | ||
class AbstractThreshold extends process_1.ImagebProcesser { | ||
threshold; | ||
mode; | ||
constructor(threshold) { | ||
super(); | ||
this.mode = ThresholdValueMode.avg; | ||
this.threshold = threshold !== null && threshold !== void 0 ? threshold : new PinedThresholdValue(); | ||
this.mode = types_1.ThresholdValueMode.avg; | ||
this.threshold = threshold ?? new PinedThresholdValue(); | ||
} | ||
process(input) { | ||
let result = ImagebTool.zeroAndOne(input); | ||
return new ProcessedResult({ | ||
let result = tools_1.ImagebTool.zeroAndOne(input); | ||
return new types_1.ProcessedResult({ | ||
origin: input, | ||
result: new ProcessedImage({ data: result, width: result.width, height: result.height }) | ||
result: new types_1.ProcessedImage({ data: result, width: result.width, height: result.height }) | ||
}); | ||
} | ||
} | ||
export class ThresholdValue { | ||
exports.AbstractThreshold = AbstractThreshold; | ||
class ThresholdValue { | ||
} | ||
export class PinedThresholdValue extends ThresholdValue { | ||
exports.ThresholdValue = ThresholdValue; | ||
class PinedThresholdValue extends ThresholdValue { | ||
_value; | ||
constructor(value) { | ||
super(); | ||
this._value = value !== null && value !== void 0 ? value : 190; | ||
this._value = value ?? 190; | ||
} | ||
@@ -29,1 +37,2 @@ threshold() { | ||
} | ||
exports.PinedThresholdValue = PinedThresholdValue; |
@@ -1,15 +0,19 @@ | ||
import { ImagebProcesser } from "../process"; | ||
import { ProcessedImage, ProcessedResult } from "../../types"; | ||
import { ImagebTool } from "../../tools"; | ||
export class GrayscaleImage extends ImagebProcesser { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.GrayscaleImage = void 0; | ||
const process_1 = require("../process"); | ||
const types_1 = require("../../types"); | ||
const tools_1 = require("../../tools"); | ||
class GrayscaleImage extends process_1.ImagebProcesser { | ||
_processer; | ||
constructor(options) { | ||
super(); | ||
this._processer = options === null || options === void 0 ? void 0 : options._processer; | ||
this._processer = options?._processer; | ||
} | ||
process(input) { | ||
let result = ImagebTool.convertGreyImg(input); | ||
let result = tools_1.ImagebTool.convertGreyImg(input); | ||
if (this._processer == null) { | ||
return new ProcessedResult({ | ||
return new types_1.ProcessedResult({ | ||
origin: input, | ||
result: new ProcessedImage({ data: result, width: result.width, height: result.height }) | ||
result: new types_1.ProcessedImage({ data: result, width: result.width, height: result.height }) | ||
}); | ||
@@ -20,1 +24,2 @@ } | ||
} | ||
exports.GrayscaleImage = GrayscaleImage; |
@@ -1,15 +0,19 @@ | ||
import { ImagebProcesser } from "../process"; | ||
import { ProcessedImage, ProcessedResult } from "../../types"; | ||
import { ImagebTool } from "../../tools"; | ||
export class ReverseColorImage extends ImagebProcesser { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ReverseColorImage = void 0; | ||
const process_1 = require("../process"); | ||
const types_1 = require("../../types"); | ||
const tools_1 = require("../../tools"); | ||
class ReverseColorImage extends process_1.ImagebProcesser { | ||
_processer; | ||
constructor(options) { | ||
super(); | ||
this._processer = options === null || options === void 0 ? void 0 : options._processer; | ||
this._processer = options?._processer; | ||
} | ||
process(input) { | ||
let result = ImagebTool.invertBitmap(input); | ||
let result = tools_1.ImagebTool.invertBitmap(input); | ||
if (this._processer == null) { | ||
return new ProcessedResult({ | ||
return new types_1.ProcessedResult({ | ||
origin: input, | ||
result: new ProcessedImage({ data: result, width: result.width, height: result.height }) | ||
result: new types_1.ProcessedImage({ data: result, width: result.width, height: result.height }) | ||
}); | ||
@@ -20,1 +24,2 @@ } | ||
} | ||
exports.ReverseColorImage = ReverseColorImage; |
@@ -1,6 +0,10 @@ | ||
import { AbstractThreshold, PinedThresholdValue } from "../basic/threshold"; | ||
export class ThresholdImage extends AbstractThreshold { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ThresholdImage = void 0; | ||
const threshold_1 = require("../basic/threshold"); | ||
class ThresholdImage extends threshold_1.AbstractThreshold { | ||
constructor(options) { | ||
super(new PinedThresholdValue(options === null || options === void 0 ? void 0 : options.threshold)); | ||
super(new threshold_1.PinedThresholdValue(options?.threshold)); | ||
} | ||
} | ||
exports.ThresholdImage = ThresholdImage; |
@@ -1,6 +0,22 @@ | ||
export * from './process'; | ||
export * from './impls/gray'; | ||
export * from './impls/reverse'; | ||
export * from './impls/threshold'; | ||
export * from './pbit/pbita'; | ||
export * from './basic/threshold'; | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./process"), exports); | ||
__exportStar(require("./impls/gray"), exports); | ||
__exportStar(require("./impls/reverse"), exports); | ||
__exportStar(require("./impls/threshold"), exports); | ||
__exportStar(require("./pbit/pbita"), exports); | ||
__exportStar(require("./basic/threshold"), exports); |
@@ -1,7 +0,37 @@ | ||
import { ImagebProcesser } from "../process"; | ||
import { ProcessedImage, ProcessedResult } from "../../types"; | ||
import * as pako from 'pako'; | ||
import { GrayscaleImage } from "../impls/gray"; | ||
import { ReverseColorImage } from "../impls/reverse"; | ||
export class Pbita extends ImagebProcesser { | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Pbita = void 0; | ||
const process_1 = require("../process"); | ||
const types_1 = require("../../types"); | ||
const pako = __importStar(require("pako")); | ||
const gray_1 = require("../impls/gray"); | ||
const reverse_1 = require("../impls/reverse"); | ||
class Pbita extends process_1.ImagebProcesser { | ||
command; | ||
threshold; | ||
compress; | ||
reverse; | ||
constructor(options) { | ||
@@ -17,6 +47,6 @@ super(); | ||
const height = input.height; | ||
const grayScaleImage = new GrayscaleImage(); | ||
const grayScaleImage = new gray_1.GrayscaleImage(); | ||
const grayResult = grayScaleImage.process(input); | ||
if (grayResult.result == null) { | ||
return new ProcessedResult({ | ||
return new types_1.ProcessedResult({ | ||
origin: input, | ||
@@ -28,6 +58,6 @@ message: 'Failed to process gray scale: ' + grayResult.message | ||
if (this.reverse) { | ||
const reverseColorImage = new ReverseColorImage(); | ||
const reverseColorImage = new reverse_1.ReverseColorImage(); | ||
const reverseResult = reverseColorImage.process(grayResult.result.data); | ||
if (reverseResult.result == null) { | ||
return new ProcessedResult({ | ||
return new types_1.ProcessedResult({ | ||
origin: input, | ||
@@ -44,3 +74,3 @@ message: 'Failed to process reverse: ' + reverseResult.message | ||
if (outputBytes == null) { | ||
return new ProcessedResult({ | ||
return new types_1.ProcessedResult({ | ||
origin: input, | ||
@@ -53,5 +83,5 @@ message: 'Failed to process bitimg' | ||
} | ||
return new ProcessedResult({ | ||
return new types_1.ProcessedResult({ | ||
origin: input, | ||
result: new ProcessedImage({ | ||
result: new types_1.ProcessedImage({ | ||
data: preprocessCanvas, | ||
@@ -73,3 +103,2 @@ width: width, | ||
_topbitimgRaw(canvas, width, height) { | ||
var _a; | ||
const ctx = canvas.getContext('2d'); | ||
@@ -102,3 +131,3 @@ let eWidth = Math.floor((width % 8 === 0) ? (width / 8) : (width / 8 + 1)); | ||
const blue = pixel[2]; | ||
if ((red + green + blue) / 3 < ((_a = this.threshold) !== null && _a !== void 0 ? _a : 190)) { | ||
if ((red + green + blue) / 3 < (this.threshold ?? 190)) { | ||
bytes[index] = (bytes[index] | n); | ||
@@ -141,1 +170,2 @@ } | ||
} | ||
exports.Pbita = Pbita; |
@@ -1,2 +0,6 @@ | ||
export class ImagebProcesser { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ImagebProcesser = void 0; | ||
class ImagebProcesser { | ||
} | ||
exports.ImagebProcesser = ImagebProcesser; |
@@ -1,2 +0,5 @@ | ||
export class ImagebTool { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ImagebTool = void 0; | ||
class ImagebTool { | ||
static invertBitmap(canvas) { | ||
@@ -54,1 +57,2 @@ const ctx = canvas.getContext('2d'); | ||
} | ||
exports.ImagebTool = ImagebTool; |
@@ -1,2 +0,8 @@ | ||
export class ProcessedResult { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ThresholdValueMode = exports.ProcessedImage = exports.ProcessedResult = void 0; | ||
class ProcessedResult { | ||
origin; | ||
result; | ||
message; | ||
constructor(options) { | ||
@@ -8,3 +14,8 @@ this.origin = options.origin; | ||
} | ||
export class ProcessedImage { | ||
exports.ProcessedResult = ProcessedResult; | ||
class ProcessedImage { | ||
data; | ||
width; | ||
height; | ||
bytes; | ||
constructor(options) { | ||
@@ -17,3 +28,4 @@ this.data = options.data; | ||
} | ||
export var ThresholdValueMode; | ||
exports.ProcessedImage = ProcessedImage; | ||
var ThresholdValueMode; | ||
(function (ThresholdValueMode) { | ||
@@ -27,2 +39,2 @@ ThresholdValueMode[ThresholdValueMode["sum"] = 0] = "sum"; | ||
ThresholdValueMode[ThresholdValueMode["min"] = 6] = "min"; | ||
})(ThresholdValueMode || (ThresholdValueMode = {})); | ||
})(ThresholdValueMode || (exports.ThresholdValueMode = ThresholdValueMode = {})); |
{ | ||
"name": "@psdk/frame-imageb", | ||
"version": "0.3.4", | ||
"version": "0.4.0", | ||
"description": "psdk", | ||
@@ -18,12 +18,10 @@ "main": "build/index.js", | ||
"devDependencies": { | ||
"@babel/core": "^7.24.5", | ||
"@babel/preset-env": "^7.24.5", | ||
"@babel/preset-typescript": "^7.24.1", | ||
"@types/jest": "^29.5.12", | ||
"@vercel/ncc": "^0.38.1", | ||
"babel-jest": "^29.7.0", | ||
"canvas": "^2.11.2", | ||
"jest": "^29.7.0", | ||
"typedoc": "^0.25.13", | ||
"typescript": "^5.4.5" | ||
"ts-jest": "^29.1.5", | ||
"ts-node": "^10.9.2", | ||
"typedoc": "^0.26.4", | ||
"typescript": "^5.5.3" | ||
}, | ||
@@ -36,3 +34,3 @@ "dependencies": { | ||
], | ||
"gitHead": "b8c2fdcb52f1bd3e9d75d004d37d717bd465b4c9" | ||
"gitHead": "13fa8cc6aacbf8f6bacb5f485da11a7610001f61" | ||
} |
23362
8
504