UNPKG

@cloudinary/url-gen

Version:

You are invited to influence our new SDK [Click here to view github discussion](https://github.com/cloudinary/js-url-gen/discussions/602) =========================

32 lines (28 loc) 1.4 kB
'use strict'; var Action = require('./Action-0ed405c1.cjs'); var QualifierValue = require('./QualifierValue-e770d619.cjs'); var Qualifier = require('./Qualifier-6633a22f.cjs'); /** * @extends SDK.Action * @description Converts the colors of every pixel in an image based on the supplied color matrix, in which the value of each color channel is calculated based on the values from all other channels (e.g. a 3x3 matrix for RGB, a 4x4 matrix for RGBA or CMYK, etc).<br/> * For every pixel in the image, take each color channel and adjust its value by the specified values of the matrix to get a new value. * @memberOf Actions.Adjust */ class RecolorAction extends Action.Action { constructor(recolorMatrix) { super(); this.matrix = recolorMatrix; // Turn the matrix into a flat array of values // the values are ordered by row // [...row1, ...row2, ...row3, ..., row(n) ] const flat = []; for (let row = 0; row < recolorMatrix.length; row++) { for (let col = 0; col < recolorMatrix[row].length; col++) { flat.push(recolorMatrix[row][col].toString()); } } const qualifierValue = new QualifierValue.QualifierValue(['recolor', ...flat]).setDelimiter(':'); this.addQualifier(new Qualifier.Qualifier('e', qualifierValue)); } } exports.RecolorAction = RecolorAction;