Skip to content

Commit

Permalink
fix(CssFilters): Rename filters, use "create" instead of "get"
Browse files Browse the repository at this point in the history
  • Loading branch information
bruyeret committed Feb 8, 2024
1 parent 18063bb commit c4f856c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
14 changes: 7 additions & 7 deletions Sources/Rendering/Core/ColorTransferFunction/CssFilters.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ export type FilterMatrix = Matrix;
* Use applyFilter() function to use it
* It is NOT the identity
*/
export function getNewFilter(): FilterMatrix;
export function createCSSFilter(): FilterMatrix;

/**
* Convert a filter to an identity matrix or create a new identity filter
* @param outFilter If specified, the outFilter is converted to identity filter
*/
export function getIdentityFilter(outFilter?: FilterMatrix): FilterMatrix;
export function createIdentityFilter(outFilter?: FilterMatrix): FilterMatrix;

/**
* Combine two filters into a single filter
Expand Down Expand Up @@ -62,7 +62,7 @@ export function applyFilter(filter: FilterMatrix, r: number, g: number, b: numbe
* @param intercept
* @param outFilter Optional output, a new filter is created if not specified
*/
export function getLinearFilter(slope: number, intercept: number, outFilter?: FilterMatrix): FilterMatrix;
export function createLinearFilter(slope: number, intercept: number, outFilter?: FilterMatrix): FilterMatrix;

/**
* A contrast filter
Expand All @@ -72,7 +72,7 @@ export function getLinearFilter(slope: number, intercept: number, outFilter?: Fi
* @param contrast
* @param outFilter Optional output, a new filter is created if not specified
*/
export function getContrastFilter(contrast: number, outFilter?: FilterMatrix): FilterMatrix;
export function createContrastFilter(contrast: number, outFilter?: FilterMatrix): FilterMatrix;

/**
* A saturate filter
Expand All @@ -82,7 +82,7 @@ export function getContrastFilter(contrast: number, outFilter?: FilterMatrix): F
* @param saturate
* @param outFilter Optional output, a new filter is created if not specified
*/
export function getSaturateFilter(saturate: number, outFilter?: FilterMatrix): FilterMatrix;
export function createSaturateFilter(saturate: number, outFilter?: FilterMatrix): FilterMatrix;

/**
* A brightness filter
Expand All @@ -92,7 +92,7 @@ export function getSaturateFilter(saturate: number, outFilter?: FilterMatrix): F
* @param brightness
* @param outFilter Optional output, a new filter is created if not specified
*/
export function getBrightnessFilter(brightness: number, outFilter?: FilterMatrix): FilterMatrix;
export function createBrightnessFilter(brightness: number, outFilter?: FilterMatrix): FilterMatrix;

/**
* An invert filter
Expand All @@ -102,4 +102,4 @@ export function getBrightnessFilter(brightness: number, outFilter?: FilterMatrix
* @param invert
* @param outFilter Optional output, a new filter is created if not specified
*/
export function getInvertFilter(invert: number, outFilter?: FilterMatrix): FilterMatrix;
export function createInvertFilter(invert: number, outFilter?: FilterMatrix): FilterMatrix;
33 changes: 20 additions & 13 deletions Sources/Rendering/Core/ColorTransferFunction/CssFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ import { identity, multiplyMatrix } from 'vtk.js/Sources/Common/Core/Math';

export const luminanceWeights = [0.213, 0.715, 0.072];

export function getNewFilter() {
export function createCSSFilter() {
return new Array(25);
}

export function getIdentityFilter(outFilter = getNewFilter()) {
export function createIdentityFilter(outFilter = createCSSFilter()) {
return identity(5, outFilter);
}

export function combineFilters(
baseFilter,
newFilter,
outFilter = getNewFilter()
outFilter = createCSSFilter()
) {
multiplyMatrix(newFilter, baseFilter, 5, 5, 5, 5, outFilter);
return outFilter;
Expand All @@ -42,8 +42,12 @@ export function applyFilter(filter, r, g, b, a = 1) {
return vec.slice(0, 4);
}

export function getLinearFilter(slope, intercept, outFilter = getNewFilter()) {
getIdentityFilter(outFilter);
export function createLinearFilter(
slope,
intercept,
outFilter = createCSSFilter()
) {
createIdentityFilter(outFilter);
for (let row = 0; row < 3; ++row) {
outFilter[row * 5 + row] = slope;
outFilter[row * 5 + 4] = intercept;
Expand All @@ -53,16 +57,16 @@ export function getLinearFilter(slope, intercept, outFilter = getNewFilter()) {

// https://www.w3.org/TR/filter-effects-1/#contrastEquivalent
// https://www.w3.org/TR/filter-effects-1/#attr-valuedef-type-linear
export function getContrastFilter(contrast, outFilter = getNewFilter()) {
export function createContrastFilter(contrast, outFilter = createCSSFilter()) {
const slope = contrast;
const intercept = -(0.5 * contrast) + 0.5;
return getLinearFilter(slope, intercept, outFilter);
return createLinearFilter(slope, intercept, outFilter);
}

// https://www.w3.org/TR/filter-effects-1/#saturateEquivalent
// https://www.w3.org/TR/filter-effects-1/#ref-for-attr-valuedef-type-saturate
export function getSaturateFilter(saturate, outFilter = getNewFilter()) {
getIdentityFilter(outFilter);
export function createSaturateFilter(saturate, outFilter = createCSSFilter()) {
createIdentityFilter(outFilter);
for (let col = 0; col < 3; ++col) {
const columnLuminance = luminanceWeights[col];
const diagonalValue = columnLuminance + (1 - columnLuminance) * saturate;
Expand All @@ -76,16 +80,19 @@ export function getSaturateFilter(saturate, outFilter = getNewFilter()) {

// https://www.w3.org/TR/filter-effects-1/#brightnessEquivalent
// https://www.w3.org/TR/filter-effects-1/#attr-valuedef-type-linear
export function getBrightnessFilter(brightness, outFilter = getNewFilter()) {
export function createBrightnessFilter(
brightness,
outFilter = createCSSFilter()
) {
const slope = brightness;
const intercept = 0;
return getLinearFilter(slope, intercept, outFilter);
return createLinearFilter(slope, intercept, outFilter);
}

// https://www.w3.org/TR/filter-effects-1/#invertEquivalent
// https://www.w3.org/TR/filter-effects-1/#attr-valuedef-type-table
export function getInvertFilter(invert, outFilter = getNewFilter()) {
export function createInvertFilter(invert, outFilter = createCSSFilter()) {
const slope = 1 - 2 * invert;
const intercept = invert;
return getLinearFilter(slope, intercept, outFilter);
return createLinearFilter(slope, intercept, outFilter);
}

0 comments on commit c4f856c

Please sign in to comment.