| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 2× 2× 1× 3× 3× 3× 3× 3× 3× 3× 3× 3× 3× 3× 3× 3× 3× 3× 1× 1× 1× 1× 1× 1× 1× 1× 3× 3× 9× 9× 3× 1× 3× 3× 3× 3× 3× 1× 3× 3× 3× 3× 3× 1× 1× 3× 3× 6× 6× 6× 6× 6× 3× 1× 1× 6× 6× 6× 6× 6× 6× 6× 6× 6× 6× 1× 6× 6× 6× 6× 9× 9× 6× 6× 6× 3× 3× 3× 6× 1× 3× 3× 3× 3× 3× 1× 1× 1× | /* istanbul ignore next */ var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); define(["require", "exports", "./../enum", "./../../general/functions/pdf-sampled-function", "./pdf-blend"], function (require, exports, enum_1, pdf_sampled_function_1, pdf_blend_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var PdfColorBlend = (function (_super) { __extends(PdfColorBlend, _super); function PdfColorBlend(count) { var _this = _super.call(this) || this; Eif (typeof count === 'number') { _this = _super.call(this, count) || this; } return _this; } Object.defineProperty(PdfColorBlend.prototype, "colors", { get: function () { return this.mcolors; }, set: function (value) { Iif ((value == null)) { throw new Error('ArgumentNullException : Colors'); } this.mcolors = value; }, enumerable: true, configurable: true }); PdfColorBlend.prototype.getFunction = function (colorSpace) { var domain = [0, 1]; var colourComponents = this.getColorComponentsCount(colorSpace); var maxComponentValue = this.getMaxComponentValue(colorSpace); var range = this.setRange(colourComponents, maxComponentValue); var func = null; Eif ((this.mbrush == null && typeof this.mbrush === 'undefined')) { var sizes = [1]; var samplesCount = void 0; var step = 1; Eif (this.positions.length === 2) { samplesCount = 2; } else { var positions = this.positions; var intervals = this.getIntervals(positions); var gcd = this.gcd(intervals); step = gcd; samplesCount = (((1 / gcd)) + 1); } sizes[0] = samplesCount; var samples = this.getSamplesValues(colorSpace, samplesCount, maxComponentValue, step); func = new pdf_sampled_function_1.PdfSampledFunction(domain, range, sizes, samples); return func; } return func; }; PdfColorBlend.prototype.cloneColorBlend = function () { var cBlend = this; Eif ((this.mcolors != null && typeof this.mcolors !== 'undefined')) { cBlend.colors = (this.mcolors); } Eif ((this.positions != null && typeof this.positions !== 'undefined')) { cBlend.positions = (this.positions); } return cBlend; }; PdfColorBlend.prototype.setRange = function (colourComponents, maxValue) { var range = [(colourComponents * 2)]; for (var i = 0; (i < colourComponents); ++i) { range[(i * 2)] = 0; range[((i * 2) + 1)] = 1; } return range; }; PdfColorBlend.prototype.getColorComponentsCount = function (colorSpace) { var count = 0; switch (colorSpace) { case enum_1.PdfColorSpace.Rgb: count = 3; break; case enum_1.PdfColorSpace.Cmyk: count = 4; break; case enum_1.PdfColorSpace.GrayScale: count = 1; break; default: throw new Error('ArgumentException - Unsupported color space: ' + colorSpace + ' colorSpace'); } return count; }; PdfColorBlend.prototype.getSamplesValues = function (colorSpace, sampleCount, maxComponentValue, step) { var values; switch (colorSpace) { case enum_1.PdfColorSpace.GrayScale: values = this.getGrayscaleSamples(sampleCount, maxComponentValue, step); break; case enum_1.PdfColorSpace.Cmyk: values = this.getCmykSamples(sampleCount, maxComponentValue, step); break; case enum_1.PdfColorSpace.Rgb: values = this.getRgbSamples(sampleCount, maxComponentValue, step); break; default: throw new Error('ArgumentException - Unsupported color space: ' + colorSpace + ' colorSpace'); } return values; }; PdfColorBlend.prototype.getGrayscaleSamples = function (sampleCount, maxComponentValue, step) { var values = [(sampleCount * 2)]; for (var i = 0; (i < sampleCount); ++i) { var color = this.getNextColor(i, step, enum_1.PdfColorSpace.GrayScale); var index = (i * 2); } return values; }; PdfColorBlend.prototype.getRgbSamples = function (sampleCount, maxComponentValue, step) { var values = [(sampleCount * 3)]; for (var i = 0; (i < sampleCount); ++i) { var color = this.getNextColor(i, step, enum_1.PdfColorSpace.Rgb); var index = (i * 3); values[index] = color.r; values[(index + 1)] = color.g; values[(index + 2)] = color.b; } return values; }; PdfColorBlend.prototype.getCmykSamples = function (sampleCount, maxComponentValue, step) { var values = [(sampleCount * 4)]; for (var i = 0; (i < sampleCount); i++) { var color = this.getNextColor(i, step, enum_1.PdfColorSpace.Cmyk); var index = (i * 4); values[index] = ((color.c * maxComponentValue)); values[(index + 1)] = ((color.m * maxComponentValue)); values[(index + 2)] = ((color.y * maxComponentValue)); values[(index + 3)] = ((color.k * maxComponentValue)); } return values; }; PdfColorBlend.prototype.getNextColor = function (index, step, colorSpace) { var position = (step * index); var indexHi; var indexLow; var result = this.getIndices(position, indexLow, indexHi); indexLow = result.indexLow; indexHi = result.indexHi; var color; Eif (indexLow === indexHi) { color = this.mcolors[indexLow]; } else { var positionLow = this.positions[indexLow]; var positionHi = this.positions[indexHi]; var colorLow = this.mcolors[indexLow]; var colorHi = this.mcolors[indexHi]; var t = ((position - positionLow) / (positionHi - positionLow)); color = this.interpolate(t, colorLow, colorHi, colorSpace); } return color; }; PdfColorBlend.prototype.getIndices = function (position, indexLow, indexHi) { var positions = this.positions; indexLow = 0; indexHi = 0; for (var i = 0; (i < this.mcolors.length); ++i) { var currPos = positions[i]; if ((currPos === position)) { indexHi = i; indexLow = i; break; } else Iif ((currPos > position)) { indexHi = i; break; } indexLow = i; indexHi = i; } return { indexLow: indexLow, indexHi: indexHi }; }; PdfColorBlend.prototype.getMaxComponentValue = function (colorSpace) { var result = 0; switch (colorSpace) { case enum_1.PdfColorSpace.Cmyk: case enum_1.PdfColorSpace.Rgb: result = 255; break; case enum_1.PdfColorSpace.GrayScale: result = 65535; break; default: throw new Error('ArgumentException - Unsupported color space: ' + colorSpace + 'colorSpace'); } return result; }; PdfColorBlend.prototype.getIntervals = function (positions) { var count = positions.length; var intervals = [(count - 1)]; var prev = positions[0]; for (var i = 1; (i < count); ++i) { var v = positions[i]; intervals[(i - 1)] = (v - prev); prev = v; } return intervals; }; return PdfColorBlend; }(pdf_blend_1.PdfBlend)); exports.PdfColorBlend = PdfColorBlend; }); |