From c4f856c11e6984fda2bec22fb66296d1388ae512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Bruy=C3=A8re?= Date: Fri, 2 Feb 2024 10:35:59 +0100 Subject: [PATCH] fix(CssFilters): Rename filters, use "create" instead of "get" --- .../ColorTransferFunction/CssFilters.d.ts | 14 ++++---- .../Core/ColorTransferFunction/CssFilters.js | 33 +++++++++++-------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/Sources/Rendering/Core/ColorTransferFunction/CssFilters.d.ts b/Sources/Rendering/Core/ColorTransferFunction/CssFilters.d.ts index 540c8a89a20..3a6d959db06 100644 --- a/Sources/Rendering/Core/ColorTransferFunction/CssFilters.d.ts +++ b/Sources/Rendering/Core/ColorTransferFunction/CssFilters.d.ts @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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; diff --git a/Sources/Rendering/Core/ColorTransferFunction/CssFilters.js b/Sources/Rendering/Core/ColorTransferFunction/CssFilters.js index 5d3fbe1e83b..37c9821f238 100644 --- a/Sources/Rendering/Core/ColorTransferFunction/CssFilters.js +++ b/Sources/Rendering/Core/ColorTransferFunction/CssFilters.js @@ -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; @@ -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; @@ -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; @@ -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); }