@vibrant/image
Advanced tools
Comparing version 3.0.0 to 3.1.0-0
@@ -1,2 +0,2 @@ | ||
import { Pixels } from "./index"; | ||
import { Pixels } from './index'; | ||
export interface HistogramOptions { | ||
@@ -3,0 +3,0 @@ sigBits: number; |
/// <reference types="node" /> | ||
/// <reference types="bluebird" /> | ||
import * as Bluebird from 'bluebird'; | ||
import { Callback } from '@vibrant/types'; | ||
@@ -19,3 +17,3 @@ import { Filter } from '@vibrant/color'; | ||
export interface Image { | ||
load(image: ImageSource): Bluebird<Image>; | ||
load(image: ImageSource): Promise<Image>; | ||
clear(): void; | ||
@@ -35,3 +33,3 @@ update(imageData: ImageData): void; | ||
export declare abstract class ImageBase implements Image { | ||
abstract load(image: ImageSource): Bluebird<ImageBase>; | ||
abstract load(image: ImageSource): Promise<ImageBase>; | ||
abstract clear(): void; | ||
@@ -38,0 +36,0 @@ abstract update(imageData: ImageData): void; |
@@ -28,3 +28,7 @@ "use strict"; | ||
var n = pixels.length / 4; | ||
var offset = void 0, r = void 0, g = void 0, b = void 0, a = void 0; | ||
var offset = void 0; | ||
var r = void 0; | ||
var g = void 0; | ||
var b = void 0; | ||
var a = void 0; | ||
for (var i = 0; i < n; i++) { | ||
@@ -36,3 +40,3 @@ offset = i * 4; | ||
a = pixels[offset + 3]; | ||
// Mark ignored colorj | ||
// Mark ignored color | ||
for (var j = 0; j < filters.length; j++) { | ||
@@ -39,0 +43,0 @@ if (!filters[j](r, g, b, a)) { |
{ | ||
"name": "@vibrant/image", | ||
"version": "3.0.0", | ||
"version": "3.1.0-0", | ||
"description": "Helpers and typings for writing a vibrant ImageClass", | ||
"scripts": { | ||
"build:module": "tsc", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
@@ -11,13 +10,18 @@ }, | ||
"types": "lib/index.d.ts", | ||
"author": "", | ||
"license": "ISC", | ||
"author": { | ||
"name": "akfish", | ||
"email": "akfish@gmail.com" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/akfish/node-vibrant/issues" | ||
}, | ||
"homepage": "https://github.com/akfish/node-vibrant", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@vibrant/types": "^3.0.0", | ||
"@vibrant/color": "^3.0.0", | ||
"bluebird": "^3.5.1" | ||
"@vibrant/color": "^3.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/bluebird": "^3.5.18", | ||
"@types/node": "^8.0.53", | ||
"typescript": "latest" | ||
"@types/node": "^10.12.18", | ||
"typescript": "^3.2.2" | ||
}, | ||
@@ -24,0 +28,0 @@ "publishConfig": { |
@@ -1,79 +0,78 @@ | ||
import { Pixels } from "./index" | ||
import { Pixels } from './index' | ||
export interface HistogramOptions { | ||
sigBits: number | ||
sigBits: number | ||
} | ||
export default class Histogram { | ||
bmin: number | ||
bmax: number | ||
gmin: number | ||
gmax: number | ||
rmin: number | ||
rmax: number | ||
hist: Uint32Array | ||
private _colorCount: number | ||
get colorCount() { return this._colorCount } | ||
getColorIndex: (r: number, g: number, b: number) => number | ||
constructor(public pixels: Pixels, public opts: HistogramOptions) { | ||
const { sigBits } = opts | ||
const getColorIndex = (r: number, g: number, b: number) => | ||
(r << (2 * sigBits)) + (g << sigBits) + b | ||
bmin: number | ||
bmax: number | ||
gmin: number | ||
gmax: number | ||
rmin: number | ||
rmax: number | ||
hist: Uint32Array | ||
private _colorCount: number | ||
get colorCount () { return this._colorCount } | ||
getColorIndex: (r: number, g: number, b: number) => number | ||
constructor (public pixels: Pixels, public opts: HistogramOptions) { | ||
const { sigBits } = opts | ||
const getColorIndex = (r: number, g: number, b: number) => | ||
(r << (2 * sigBits)) + (g << sigBits) + b | ||
this.getColorIndex = getColorIndex | ||
this.getColorIndex = getColorIndex | ||
const rshift = 8 - sigBits | ||
const hn = 1 << (3 * sigBits) | ||
let hist = new Uint32Array(hn) | ||
let rmax: number | ||
let rmin: number | ||
let gmax: number | ||
let gmin: number | ||
let bmax: number | ||
let bmin: number | ||
let r: number | ||
let g: number | ||
let b: number | ||
let a: number | ||
rmax = gmax = bmax = 0 | ||
rmin = gmin = bmin = Number.MAX_VALUE | ||
let n = pixels.length / 4 | ||
let i = 0 | ||
const rshift = 8 - sigBits | ||
const hn = 1 << (3 * sigBits) | ||
let hist = new Uint32Array(hn) | ||
let rmax: number | ||
let rmin: number | ||
let gmax: number | ||
let gmin: number | ||
let bmax: number | ||
let bmin: number | ||
let r: number | ||
let g: number | ||
let b: number | ||
let a: number | ||
rmax = gmax = bmax = 0 | ||
rmin = gmin = bmin = Number.MAX_VALUE | ||
let n = pixels.length / 4 | ||
let i = 0 | ||
while (i < n) { | ||
while (i < n) { | ||
let offset = i * 4 | ||
i++ | ||
r = pixels[offset + 0] | ||
g = pixels[offset + 1] | ||
b = pixels[offset + 2] | ||
a = pixels[offset + 3] | ||
let offset = i * 4 | ||
i++ | ||
r = pixels[offset + 0] | ||
g = pixels[offset + 1] | ||
b = pixels[offset + 2] | ||
a = pixels[offset + 3] | ||
// Ignored pixels' alpha is marked as 0 in filtering stage | ||
if (a === 0) continue | ||
// Ignored pixels' alpha is marked as 0 in filtering stage | ||
if (a === 0) continue | ||
r = r >> rshift | ||
g = g >> rshift | ||
b = b >> rshift | ||
r = r >> rshift | ||
g = g >> rshift | ||
b = b >> rshift | ||
let index = getColorIndex(r, g, b) | ||
hist[index] += 1 | ||
let index = getColorIndex(r, g, b) | ||
hist[index] += 1 | ||
if (r > rmax) rmax = r | ||
if (r < rmin) rmin = r | ||
if (g > gmax) gmax = g | ||
if (g < gmin) gmin = g | ||
if (b > bmax) bmax = b | ||
if (b < bmin) bmin = b | ||
} | ||
this._colorCount = hist.reduce((total, c) => c > 0 ? total + 1 : total, 0) | ||
this.hist = hist | ||
this.rmax = rmax | ||
this.rmin = rmin | ||
this.gmax = gmax | ||
this.gmin = gmin | ||
this.bmax = bmax | ||
this.bmin = bmin | ||
if (r > rmax) rmax = r | ||
if (r < rmin) rmin = r | ||
if (g > gmax) gmax = g | ||
if (g < gmin) gmin = g | ||
if (b > bmax) bmax = b | ||
if (b < bmin) bmin = b | ||
} | ||
} | ||
this._colorCount = hist.reduce((total, c) => c > 0 ? total + 1 : total, 0) | ||
this.hist = hist | ||
this.rmax = rmax | ||
this.rmin = rmin | ||
this.gmax = gmax | ||
this.gmin = gmin | ||
this.bmax = bmax | ||
this.bmin = bmin | ||
} | ||
} |
124
src/index.ts
@@ -1,3 +0,1 @@ | ||
import * as Bluebird from 'bluebird' | ||
import { Callback } from '@vibrant/types' | ||
@@ -12,79 +10,83 @@ import { Filter } from '@vibrant/color' | ||
export interface ImageData { | ||
data: Pixels, | ||
width: number, | ||
height: number | ||
data: Pixels, | ||
width: number, | ||
height: number | ||
} | ||
export interface ImageOptions { | ||
quality: number | ||
maxDimension: number | ||
quality: number | ||
maxDimension: number | ||
} | ||
export interface Image { | ||
load(image: ImageSource): Bluebird<Image> | ||
clear(): void | ||
update(imageData: ImageData): void | ||
getWidth(): number | ||
getHeight(): number | ||
resize(targetWidth: number, targetHeight: number, ratio: number): void | ||
getPixelCount(): number | ||
getImageData(): ImageData | ||
remove(): void | ||
scaleDown(opts: ImageOptions): void | ||
load (image: ImageSource): Promise<Image> | ||
clear (): void | ||
update (imageData: ImageData): void | ||
getWidth (): number | ||
getHeight (): number | ||
resize (targetWidth: number, targetHeight: number, ratio: number): void | ||
getPixelCount (): number | ||
getImageData (): ImageData | ||
remove (): void | ||
scaleDown (opts: ImageOptions): void | ||
} | ||
export interface ImageClass { | ||
new (): Image | ||
new(): Image | ||
} | ||
export abstract class ImageBase implements Image { | ||
abstract load(image: ImageSource): Bluebird<ImageBase> | ||
abstract clear(): void | ||
abstract update(imageData: ImageData): void | ||
abstract getWidth(): number | ||
abstract getHeight(): number | ||
abstract resize(targetWidth: number, targetHeight: number, ratio: number): void | ||
abstract getPixelCount(): number | ||
abstract getImageData(): ImageData | ||
abstract remove(): void | ||
abstract load (image: ImageSource): Promise<ImageBase> | ||
abstract clear (): void | ||
abstract update (imageData: ImageData): void | ||
abstract getWidth (): number | ||
abstract getHeight (): number | ||
abstract resize (targetWidth: number, targetHeight: number, ratio: number): void | ||
abstract getPixelCount (): number | ||
abstract getImageData (): ImageData | ||
abstract remove (): void | ||
scaleDown(opts: ImageOptions): void { | ||
let width: number = this.getWidth() | ||
let height: number = this.getHeight() | ||
scaleDown (opts: ImageOptions): void { | ||
let width: number = this.getWidth() | ||
let height: number = this.getHeight() | ||
let ratio: number = 1 | ||
let ratio: number = 1 | ||
if (opts.maxDimension > 0) { | ||
let maxSide: number = Math.max(width, height) | ||
if (maxSide > opts.maxDimension) ratio = opts.maxDimension / maxSide | ||
} else { | ||
ratio = 1 / opts.quality | ||
} | ||
if (ratio < 1) this.resize(width * ratio, height * ratio, ratio) | ||
if (opts.maxDimension > 0) { | ||
let maxSide: number = Math.max(width, height) | ||
if (maxSide > opts.maxDimension) ratio = opts.maxDimension / maxSide | ||
} else { | ||
ratio = 1 / opts.quality | ||
} | ||
} | ||
export function applyFilters(imageData: ImageData, filters: Filter[]) { | ||
if (filters.length > 0) { | ||
let pixels = imageData.data | ||
let n = pixels.length / 4 | ||
let offset, r, g, b, a | ||
for (let i = 0; i < n; i++) { | ||
offset = i * 4 | ||
r = pixels[offset + 0] | ||
g = pixels[offset + 1] | ||
b = pixels[offset + 2] | ||
a = pixels[offset + 3] | ||
// Mark ignored colorj | ||
for (let j = 0; j < filters.length; j++) { | ||
if (!filters[j](r, g, b, a)) { | ||
pixels[offset + 3] = 0 | ||
break | ||
} | ||
} | ||
if (ratio < 1) this.resize(width * ratio, height * ratio, ratio) | ||
} | ||
} | ||
export function applyFilters (imageData: ImageData, filters: Filter[]) { | ||
if (filters.length > 0) { | ||
let pixels = imageData.data | ||
let n = pixels.length / 4 | ||
let offset | ||
let r | ||
let g | ||
let b | ||
let a | ||
for (let i = 0; i < n; i++) { | ||
offset = i * 4 | ||
r = pixels[offset + 0] | ||
g = pixels[offset + 1] | ||
b = pixels[offset + 2] | ||
a = pixels[offset + 3] | ||
// Mark ignored color | ||
for (let j = 0; j < filters.length; j++) { | ||
if (!filters[j](r, g, b, a)) { | ||
pixels[offset + 3] = 0 | ||
break | ||
} | ||
} | ||
} | ||
return imageData | ||
} | ||
} | ||
return imageData | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
2
2
0
16134
11
331
- Removedbluebird@^3.5.1