How to use CalGrayCS method in wpt

Best JavaScript code snippet using wpt

colorspace.js

Source:colorspace.js Github

copy

Full Screen

...175 case 'CalGrayCS':176 whitePoint = IR[1];177 blackPoint = IR[2];178 gamma = IR[3];179 return new CalGrayCS(whitePoint, blackPoint, gamma);180 case 'CalRGBCS':181 whitePoint = IR[1];182 blackPoint = IR[2];183 gamma = IR[3];184 var matrix = IR[4];185 return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);186 case 'PatternCS':187 var basePatternCS = IR[1];188 if (basePatternCS) {189 basePatternCS = this.fromIR(basePatternCS);190 }191 return new PatternCS(basePatternCS);192 case 'IndexedCS':193 var baseIndexedCS = IR[1];194 var hiVal = IR[2];195 var lookup = IR[3];196 return new IndexedCS(this.fromIR(baseIndexedCS), hiVal, lookup);197 case 'AlternateCS':198 var numComps = IR[1];199 var alt = IR[2];200 var tintFn = IR[3];201 return new AlternateCS(numComps, this.fromIR(alt), tintFn);202 case 'LabCS':203 whitePoint = IR[1];204 blackPoint = IR[2];205 var range = IR[3];206 return new LabCS(whitePoint, blackPoint, range);207 default:208 throw new _util.FormatError('Unknown colorspace name: ' + name);209 }210 }211 }, {212 key: 'parseToIR',213 value: function parseToIR(cs, xref) {214 var res = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;215 var pdfFunctionFactory = arguments[3];216 cs = xref.fetchIfRef(cs);217 if ((0, _primitives.isName)(cs)) {218 switch (cs.name) {219 case 'DeviceGray':220 case 'G':221 return 'DeviceGrayCS';222 case 'DeviceRGB':223 case 'RGB':224 return 'DeviceRgbCS';225 case 'DeviceCMYK':226 case 'CMYK':227 return 'DeviceCmykCS';228 case 'Pattern':229 return ['PatternCS', null];230 default:231 if ((0, _primitives.isDict)(res)) {232 var colorSpaces = res.get('ColorSpace');233 if ((0, _primitives.isDict)(colorSpaces)) {234 var resCS = colorSpaces.get(cs.name);235 if (resCS) {236 if ((0, _primitives.isName)(resCS)) {237 return this.parseToIR(resCS, xref, res, pdfFunctionFactory);238 }239 cs = resCS;240 break;241 }242 }243 }244 throw new _util.FormatError('unrecognized colorspace ' + cs.name);245 }246 }247 if (Array.isArray(cs)) {248 var mode = xref.fetchIfRef(cs[0]).name;249 var numComps = void 0,250 params = void 0,251 alt = void 0,252 whitePoint = void 0,253 blackPoint = void 0,254 gamma = void 0;255 switch (mode) {256 case 'DeviceGray':257 case 'G':258 return 'DeviceGrayCS';259 case 'DeviceRGB':260 case 'RGB':261 return 'DeviceRgbCS';262 case 'DeviceCMYK':263 case 'CMYK':264 return 'DeviceCmykCS';265 case 'CalGray':266 params = xref.fetchIfRef(cs[1]);267 whitePoint = params.getArray('WhitePoint');268 blackPoint = params.getArray('BlackPoint');269 gamma = params.get('Gamma');270 return ['CalGrayCS', whitePoint, blackPoint, gamma];271 case 'CalRGB':272 params = xref.fetchIfRef(cs[1]);273 whitePoint = params.getArray('WhitePoint');274 blackPoint = params.getArray('BlackPoint');275 gamma = params.getArray('Gamma');276 var matrix = params.getArray('Matrix');277 return ['CalRGBCS', whitePoint, blackPoint, gamma, matrix];278 case 'ICCBased':279 var stream = xref.fetchIfRef(cs[1]);280 var dict = stream.dict;281 numComps = dict.get('N');282 alt = dict.get('Alternate');283 if (alt) {284 var altIR = this.parseToIR(alt, xref, res, pdfFunctionFactory);285 var altCS = this.fromIR(altIR, pdfFunctionFactory);286 if (altCS.numComps === numComps) {287 return altIR;288 }289 (0, _util.warn)('ICCBased color space: Ignoring incorrect /Alternate entry.');290 }291 if (numComps === 1) {292 return 'DeviceGrayCS';293 } else if (numComps === 3) {294 return 'DeviceRgbCS';295 } else if (numComps === 4) {296 return 'DeviceCmykCS';297 }298 break;299 case 'Pattern':300 var basePatternCS = cs[1] || null;301 if (basePatternCS) {302 basePatternCS = this.parseToIR(basePatternCS, xref, res, pdfFunctionFactory);303 }304 return ['PatternCS', basePatternCS];305 case 'Indexed':306 case 'I':307 var baseIndexedCS = this.parseToIR(cs[1], xref, res, pdfFunctionFactory);308 var hiVal = xref.fetchIfRef(cs[2]) + 1;309 var lookup = xref.fetchIfRef(cs[3]);310 if ((0, _primitives.isStream)(lookup)) {311 lookup = lookup.getBytes();312 }313 return ['IndexedCS', baseIndexedCS, hiVal, lookup];314 case 'Separation':315 case 'DeviceN':316 var name = xref.fetchIfRef(cs[1]);317 numComps = Array.isArray(name) ? name.length : 1;318 alt = this.parseToIR(cs[2], xref, res, pdfFunctionFactory);319 var tintFn = pdfFunctionFactory.create(xref.fetchIfRef(cs[3]));320 return ['AlternateCS', numComps, alt, tintFn];321 case 'Lab':322 params = xref.fetchIfRef(cs[1]);323 whitePoint = params.getArray('WhitePoint');324 blackPoint = params.getArray('BlackPoint');325 var range = params.getArray('Range');326 return ['LabCS', whitePoint, blackPoint, range];327 default:328 throw new _util.FormatError('unimplemented color space object "' + mode + '"');329 }330 }331 throw new _util.FormatError('unrecognized color space object: "' + cs + '"');332 }333 }, {334 key: 'isDefaultDecode',335 value: function isDefaultDecode(decode, n) {336 if (!Array.isArray(decode)) {337 return true;338 }339 if (n * 2 !== decode.length) {340 (0, _util.warn)('The decode map is not the correct length');341 return true;342 }343 for (var i = 0, ii = decode.length; i < ii; i += 2) {344 if (decode[i] !== 0 || decode[i + 1] !== 1) {345 return false;346 }347 }348 return true;349 }350 }, {351 key: 'singletons',352 get: function get() {353 return (0, _util.shadow)(this, 'singletons', {354 get gray() {355 return (0, _util.shadow)(this, 'gray', new DeviceGrayCS());356 },357 get rgb() {358 return (0, _util.shadow)(this, 'rgb', new DeviceRgbCS());359 },360 get cmyk() {361 return (0, _util.shadow)(this, 'cmyk', new DeviceCmykCS());362 }363 });364 }365 }]);366 return ColorSpace;367}();368var AlternateCS = function (_ColorSpace) {369 _inherits(AlternateCS, _ColorSpace);370 function AlternateCS(numComps, base, tintFn) {371 _classCallCheck(this, AlternateCS);372 var _this = _possibleConstructorReturn(this, (AlternateCS.__proto__ || Object.getPrototypeOf(AlternateCS)).call(this, 'Alternate', numComps));373 _this.base = base;374 _this.tintFn = tintFn;375 _this.tmpBuf = new Float32Array(base.numComps);376 return _this;377 }378 _createClass(AlternateCS, [{379 key: 'getRgbItem',380 value: function getRgbItem(src, srcOffset, dest, destOffset) {381 var tmpBuf = this.tmpBuf;382 this.tintFn(src, srcOffset, tmpBuf, 0);383 this.base.getRgbItem(tmpBuf, 0, dest, destOffset);384 }385 }, {386 key: 'getRgbBuffer',387 value: function getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {388 var tintFn = this.tintFn;389 var base = this.base;390 var scale = 1 / ((1 << bits) - 1);391 var baseNumComps = base.numComps;392 var usesZeroToOneRange = base.usesZeroToOneRange;393 var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) && alpha01 === 0;394 var pos = isPassthrough ? destOffset : 0;395 var baseBuf = isPassthrough ? dest : new Uint8ClampedArray(baseNumComps * count);396 var numComps = this.numComps;397 var scaled = new Float32Array(numComps);398 var tinted = new Float32Array(baseNumComps);399 var i = void 0,400 j = void 0;401 for (i = 0; i < count; i++) {402 for (j = 0; j < numComps; j++) {403 scaled[j] = src[srcOffset++] * scale;404 }405 tintFn(scaled, 0, tinted, 0);406 if (usesZeroToOneRange) {407 for (j = 0; j < baseNumComps; j++) {408 baseBuf[pos++] = tinted[j] * 255;409 }410 } else {411 base.getRgbItem(tinted, 0, baseBuf, pos);412 pos += baseNumComps;413 }414 }415 if (!isPassthrough) {416 base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);417 }418 }419 }, {420 key: 'getOutputLength',421 value: function getOutputLength(inputLength, alpha01) {422 return this.base.getOutputLength(inputLength * this.base.numComps / this.numComps, alpha01);423 }424 }, {425 key: 'isDefaultDecode',426 value: function isDefaultDecode(decodeMap) {427 return ColorSpace.isDefaultDecode(decodeMap, this.numComps);428 }429 }]);430 return AlternateCS;431}(ColorSpace);432var PatternCS = function (_ColorSpace2) {433 _inherits(PatternCS, _ColorSpace2);434 function PatternCS(baseCS) {435 _classCallCheck(this, PatternCS);436 var _this2 = _possibleConstructorReturn(this, (PatternCS.__proto__ || Object.getPrototypeOf(PatternCS)).call(this, 'Pattern', null));437 _this2.base = baseCS;438 return _this2;439 }440 return PatternCS;441}(ColorSpace);442var IndexedCS = function (_ColorSpace3) {443 _inherits(IndexedCS, _ColorSpace3);444 function IndexedCS(base, highVal, lookup) {445 _classCallCheck(this, IndexedCS);446 var _this3 = _possibleConstructorReturn(this, (IndexedCS.__proto__ || Object.getPrototypeOf(IndexedCS)).call(this, 'Indexed', 1));447 _this3.base = base;448 _this3.highVal = highVal;449 var baseNumComps = base.numComps;450 var length = baseNumComps * highVal;451 if ((0, _primitives.isStream)(lookup)) {452 _this3.lookup = new Uint8Array(length);453 var bytes = lookup.getBytes(length);454 _this3.lookup.set(bytes);455 } else if ((0, _util.isString)(lookup)) {456 _this3.lookup = new Uint8Array(length);457 for (var i = 0; i < length; ++i) {458 _this3.lookup[i] = lookup.charCodeAt(i);459 }460 } else if (lookup instanceof Uint8Array) {461 _this3.lookup = lookup;462 } else {463 throw new _util.FormatError('Unrecognized lookup table: ' + lookup);464 }465 return _this3;466 }467 _createClass(IndexedCS, [{468 key: 'getRgbItem',469 value: function getRgbItem(src, srcOffset, dest, destOffset) {470 var numComps = this.base.numComps;471 var start = src[srcOffset] * numComps;472 this.base.getRgbBuffer(this.lookup, start, 1, dest, destOffset, 8, 0);473 }474 }, {475 key: 'getRgbBuffer',476 value: function getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {477 var base = this.base;478 var numComps = base.numComps;479 var outputDelta = base.getOutputLength(numComps, alpha01);480 var lookup = this.lookup;481 for (var i = 0; i < count; ++i) {482 var lookupPos = src[srcOffset++] * numComps;483 base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);484 destOffset += outputDelta;485 }486 }487 }, {488 key: 'getOutputLength',489 value: function getOutputLength(inputLength, alpha01) {490 return this.base.getOutputLength(inputLength * this.base.numComps, alpha01);491 }492 }, {493 key: 'isDefaultDecode',494 value: function isDefaultDecode(decodeMap) {495 return true;496 }497 }]);498 return IndexedCS;499}(ColorSpace);500var DeviceGrayCS = function (_ColorSpace4) {501 _inherits(DeviceGrayCS, _ColorSpace4);502 function DeviceGrayCS() {503 _classCallCheck(this, DeviceGrayCS);504 return _possibleConstructorReturn(this, (DeviceGrayCS.__proto__ || Object.getPrototypeOf(DeviceGrayCS)).call(this, 'DeviceGray', 1));505 }506 _createClass(DeviceGrayCS, [{507 key: 'getRgbItem',508 value: function getRgbItem(src, srcOffset, dest, destOffset) {509 var c = src[srcOffset] * 255;510 dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;511 }512 }, {513 key: 'getRgbBuffer',514 value: function getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {515 var scale = 255 / ((1 << bits) - 1);516 var j = srcOffset,517 q = destOffset;518 for (var i = 0; i < count; ++i) {519 var c = scale * src[j++];520 dest[q++] = c;521 dest[q++] = c;522 dest[q++] = c;523 q += alpha01;524 }525 }526 }, {527 key: 'getOutputLength',528 value: function getOutputLength(inputLength, alpha01) {529 return inputLength * (3 + alpha01);530 }531 }, {532 key: 'isDefaultDecode',533 value: function isDefaultDecode(decodeMap) {534 return ColorSpace.isDefaultDecode(decodeMap, this.numComps);535 }536 }]);537 return DeviceGrayCS;538}(ColorSpace);539var DeviceRgbCS = function (_ColorSpace5) {540 _inherits(DeviceRgbCS, _ColorSpace5);541 function DeviceRgbCS() {542 _classCallCheck(this, DeviceRgbCS);543 return _possibleConstructorReturn(this, (DeviceRgbCS.__proto__ || Object.getPrototypeOf(DeviceRgbCS)).call(this, 'DeviceRGB', 3));544 }545 _createClass(DeviceRgbCS, [{546 key: 'getRgbItem',547 value: function getRgbItem(src, srcOffset, dest, destOffset) {548 dest[destOffset] = src[srcOffset] * 255;549 dest[destOffset + 1] = src[srcOffset + 1] * 255;550 dest[destOffset + 2] = src[srcOffset + 2] * 255;551 }552 }, {553 key: 'getRgbBuffer',554 value: function getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {555 if (bits === 8 && alpha01 === 0) {556 dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);557 return;558 }559 var scale = 255 / ((1 << bits) - 1);560 var j = srcOffset,561 q = destOffset;562 for (var i = 0; i < count; ++i) {563 dest[q++] = scale * src[j++];564 dest[q++] = scale * src[j++];565 dest[q++] = scale * src[j++];566 q += alpha01;567 }568 }569 }, {570 key: 'getOutputLength',571 value: function getOutputLength(inputLength, alpha01) {572 return inputLength * (3 + alpha01) / 3 | 0;573 }574 }, {575 key: 'isPassthrough',576 value: function isPassthrough(bits) {577 return bits === 8;578 }579 }, {580 key: 'isDefaultDecode',581 value: function isDefaultDecode(decodeMap) {582 return ColorSpace.isDefaultDecode(decodeMap, this.numComps);583 }584 }]);585 return DeviceRgbCS;586}(ColorSpace);587var DeviceCmykCS = function DeviceCmykCSClosure() {588 function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {589 var c = src[srcOffset] * srcScale;590 var m = src[srcOffset + 1] * srcScale;591 var y = src[srcOffset + 2] * srcScale;592 var k = src[srcOffset + 3] * srcScale;593 dest[destOffset] = 255 + c * (-4.387332384609988 * c + 54.48615194189176 * m + 18.82290502165302 * y + 212.25662451639585 * k + -285.2331026137004) + m * (1.7149763477362134 * m - 5.6096736904047315 * y + -17.873870861415444 * k - 5.497006427196366) + y * (-2.5217340131683033 * y - 21.248923337353073 * k + 17.5119270841813) + k * (-21.86122147463605 * k - 189.48180835922747);594 dest[destOffset + 1] = 255 + c * (8.841041422036149 * c + 60.118027045597366 * m + 6.871425592049007 * y + 31.159100130055922 * k + -79.2970844816548) + m * (-15.310361306967817 * m + 17.575251261109482 * y + 131.35250912493976 * k - 190.9453302588951) + y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) + k * (-20.737325471181034 * k - 187.80453709719578);595 dest[destOffset + 2] = 255 + c * (0.8842522430003296 * c + 8.078677503112928 * m + 30.89978309703729 * y - 0.23883238689178934 * k + -14.183576799673286) + m * (10.49593273432072 * m + 63.02378494754052 * y + 50.606957656360734 * k - 112.23884253719248) + y * (0.03296041114873217 * y + 115.60384449646641 * k + -193.58209356861505) + k * (-22.33816807309886 * k - 180.12613974708367);596 }597 var DeviceCmykCS = function (_ColorSpace6) {598 _inherits(DeviceCmykCS, _ColorSpace6);599 function DeviceCmykCS() {600 _classCallCheck(this, DeviceCmykCS);601 return _possibleConstructorReturn(this, (DeviceCmykCS.__proto__ || Object.getPrototypeOf(DeviceCmykCS)).call(this, 'DeviceCMYK', 4));602 }603 _createClass(DeviceCmykCS, [{604 key: 'getRgbItem',605 value: function getRgbItem(src, srcOffset, dest, destOffset) {606 convertToRgb(src, srcOffset, 1, dest, destOffset);607 }608 }, {609 key: 'getRgbBuffer',610 value: function getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {611 var scale = 1 / ((1 << bits) - 1);612 for (var i = 0; i < count; i++) {613 convertToRgb(src, srcOffset, scale, dest, destOffset);614 srcOffset += 4;615 destOffset += 3 + alpha01;616 }617 }618 }, {619 key: 'getOutputLength',620 value: function getOutputLength(inputLength, alpha01) {621 return inputLength / 4 * (3 + alpha01) | 0;622 }623 }, {624 key: 'isDefaultDecode',625 value: function isDefaultDecode(decodeMap) {626 return ColorSpace.isDefaultDecode(decodeMap, this.numComps);627 }628 }]);629 return DeviceCmykCS;630 }(ColorSpace);631 return DeviceCmykCS;632}();633var CalGrayCS = function CalGrayCSClosure() {634 function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {635 var A = src[srcOffset] * scale;636 var AG = Math.pow(A, cs.G);637 var L = cs.YW * AG;638 var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0);639 dest[destOffset] = val;640 dest[destOffset + 1] = val;641 dest[destOffset + 2] = val;642 }643 var CalGrayCS = function (_ColorSpace7) {644 _inherits(CalGrayCS, _ColorSpace7);645 function CalGrayCS(whitePoint, blackPoint, gamma) {646 _classCallCheck(this, CalGrayCS);647 var _this7 = _possibleConstructorReturn(this, (CalGrayCS.__proto__ || Object.getPrototypeOf(CalGrayCS)).call(this, 'CalGray', 1));648 if (!whitePoint) {649 throw new _util.FormatError('WhitePoint missing - required for color space CalGray');650 }651 blackPoint = blackPoint || [0, 0, 0];652 gamma = gamma || 1;653 _this7.XW = whitePoint[0];654 _this7.YW = whitePoint[1];655 _this7.ZW = whitePoint[2];656 _this7.XB = blackPoint[0];657 _this7.YB = blackPoint[1];658 _this7.ZB = blackPoint[2];659 _this7.G = gamma;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) return console.error(err);4 console.log('Test status:', data.statusText);5 console.log('Test ID:', data.data.testId);6 console.log('Test URL:', data.data.summary);7 console.log('View results:', data.data.userUrl);8});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3var options = {video: true};4 if (err) return console.error(err);5 console.log('Test submitted. Polling for results...');6 wpt.getTestResults(data.data.testId, function(err, data) {7 if (err) return console.error(err);8 console.log('First View: ' + data.data.average.firstView);9 console.log('Repeat View: ' + data.data.average.repeatView);10 });11});12var wpt = require('webpagetest');13var wpt = new WebPageTest('www.webpagetest.org');14var options = {location: 'Dulles:Chrome'};15 if (err) return console.error(err);16 console.log('Test submitted. Polling for results...');17 wpt.getTestResults(data.data.testId, function(err, data) {18 if (err) return console.error(err);19 console.log('First View: ' + data.data.average.firstView);20 console.log('Repeat View: ' + data.data.average.repeatView);21 });22});23var wpt = require('webpagetest');24var wpt = new WebPageTest('www.webpagetest.org');25var options = {connectivity: '3G'};26 if (err) return console.error(err);27 console.log('Test submitted. Polling for results...');28 wpt.getTestResults(data.data.testId, function(err, data) {29 if (err) return console.error(err);30 console.log('First View: ' + data.data.average.firstView);31 console.log('Repeat View: ' + data.data.average.repeatView);32 });33});34var wpt = require('webpagetest');35var wpt = new WebPageTest('www.webpagetest.org');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var WebPageTest = new wpt('www.webpagetest.org');3var options = {4};5 if (err) return console.error(err);6 console.log('Test ID: ' + data.data.testId);7});

Full Screen

Using AI Code Generation

copy

Full Screen

1var myDoc = new PDFDoc();2var myPage = myDoc.addPage();3myPage.setMediaBox(0,0,612,792);4var myContent = myPage.addContent();5var myCS = myContent.getColorSpace("CalGrayCS");6myContent.setColorSpace(myCS);7myContent.setColor(0,0,0);8myContent.drawRectangle(0,0,612,792);9myContent.fillPath();10myDoc.saveAs("test.pdf");11myDoc.close();

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful