How to use ColorSpace method in wpt

Best JavaScript code snippet using wpt

image-data.test.js

Source:image-data.test.js Github

copy

Full Screen

1const {Colorspace} = require('../dist/types')2const ImageData = require('../dist/image-data').ImageData3const {expect, fixtureDecode, compareToFixture, enableWASM, disableWASM} = require('./utils')4describe('ImageData', () => {5 const pixel = value => [value, value, value, 255]6 describe('#mapPixels', () => {7 it('should evaluate the function', () => {8 const imageData = {9 width: 1,10 height: 1,11 channels: 3,12 colorspace: 'rgb',13 data: [1, 2, 3],14 }15 const result = ImageData.mapPixels(imageData, ({values}) => values.map(x => x + 1))16 expect(result).toEqual({17 width: 1,18 height: 1,19 channels: 3,20 colorspace: 'rgb',21 data: new Uint8Array([2, 3, 4]),22 })23 })24 it('should evaluate the functions in order', () => {25 const imageData = {26 width: 1,27 height: 1,28 channels: 1,29 colorspace: 'k',30 data: [10],31 }32 const result = ImageData.mapPixels(imageData, [33 ({values}) => [values[0] / 2],34 ({values}) => [values[0] + 2],35 ])36 expect(result).toEqual({37 width: 1,38 height: 1,39 channels: 1,40 colorspace: 'k',41 data: new Uint8Array([7]),42 })43 })44 })45 describe('#proximityTransform', () => {46 const hslImageData = (h, s, l) => ({colorspace: 'hsl', data: [h, s, l], channels: 3, width: 1, height: 1})47 it('should evaluate based on proximity', () => {48 const transform = data => ImageData.proximityTransform(49 data,50 [{filterChannels: ['h', 's', 'l'],51 filterChannelCenters: [180, 1, 0.5],52 filterChannelRanges: [180, 1, 0.5],53 targetChannel: 'l',54 targetIntensity: 0.5}]55 )56 const fn = imageData => Math.round(100 * transform(imageData).data[2]) / 10057 expect(fn(hslImageData(180, 1, 0.5))).toBe(1)58 expect(fn(hslImageData(180, 0.5, 0.5))).toBe(0.75)59 expect(fn(hslImageData(0, 0, 0))).toBe(0)60 })61 it('should handle wrap around hue', () => {62 const transform = data => ImageData.proximityTransform(63 data,64 [{filterChannels: ['h', 's', 'l'],65 filterChannelCenters: [355, 1, 0.5],66 filterChannelRanges: [355, 1, 0.5],67 targetChannel: 'l',68 targetIntensity: 0.5}]69 )70 const fn = imageData => Math.round(100 * transform(imageData).data[2]) / 10071 expect(fn(hslImageData(355, 1, 0.5))).toBe(1)72 expect(fn(hslImageData(0, 1, 0.5))).toBe(0.99)73 })74 })75 describe('#probablyIs', () => {76 it('should identify invalid values', () => {77 expect(ImageData.probablyIs()).toBe(false)78 expect(ImageData.probablyIs(null)).toBe(false)79 expect(ImageData.probablyIs(Buffer.from([]))).toBe(false)80 expect(ImageData.probablyIs(false)).toBe(false)81 expect(ImageData.probablyIs(2)).toBe(false)82 expect(ImageData.probablyIs({data: undefined})).toBe(false)83 expect(ImageData.probablyIs({width: '2', height: 1, data: []})).toBe(false)84 })85 it('should identify Array-based', () => {86 const pixels = [...pixel(128), ...pixel(255), ...pixel(0), ...pixel(0)]87 expect(ImageData.probablyIs({width: 2, height: 2, data: pixels})).toBe(true)88 })89 it('should identify Uint8Array-based', () => {90 expect(ImageData.probablyIs({width: 10, height: 10, data: new Uint8Array(400)})).toBe(true)91 })92 it('should identify Buffer-based', () => {93 const pixels = Buffer.from([...pixel(128), ...pixel(255), ...pixel(0), ...pixel(0)])94 expect(ImageData.probablyIs({width: 2, height: 2, data: pixels})).toBe(true)95 })96 it('should enforce pixel length', () => {97 expect(ImageData.probablyIs({width: 10, height: 10, data: new Uint8Array(87)})).toBe(false)98 })99 })100 describe('#is', () => {101 it('should identify invalid values', () => {102 expect(ImageData.is()).toBe(false)103 expect(ImageData.is(null)).toBe(false)104 expect(ImageData.is(Buffer.from([]))).toBe(false)105 expect(ImageData.is(false)).toBe(false)106 expect(ImageData.is(2)).toBe(false)107 expect(ImageData.is({data: undefined})).toBe(false)108 expect(ImageData.is({width: '2', height: 1, data: []})).toBe(false)109 expect(ImageData.is({width: 1, height: 1, data: [0]})).toBe(false)110 expect(ImageData.is({width: 1, height: 1, data: [0], channels: 1})).toBe(false)111 })112 it('should enforce format', () => {113 const imageData = {114 width: 10,115 height: 10,116 channels: 3,117 colorspace: 'what?',118 data: new Uint8Array(300),119 }120 expect(ImageData.is(imageData)).toBe(false)121 expect(ImageData.is(Object.assign(imageData, {colorspace: Colorspace.RGB}))).toBe(true)122 })123 it('should enforce pixel length', () => {124 const imageData = {125 width: 10,126 height: 10,127 channels: 3,128 colorspace: 'rgb',129 data: new Uint8Array(100),130 }131 expect(ImageData.is(imageData)).toBe(false)132 expect(ImageData.is(Object.assign(imageData, {channels: 1}))).toBe(true)133 })134 })135 describe('#rotate', () => {136 const simpleLineOdd = {137 width: 3,138 height: 3,139 channels: 1,140 colorspace: Colorspace.Greyscale,141 data: [142 0, 0, 0,143 1, 1, 1,144 0, 0, 0,145 ],146 }147 const simpleLineEven = {148 width: 4,149 height: 4,150 channels: 1,151 colorspace: Colorspace.Greyscale,152 data: [153 0, 0, 0, 0,154 0, 0, 0, 0,155 1, 1, 1, 1,156 0, 0, 0, 0,157 ],158 }159 const simpleRectangle = {160 width: 6,161 height: 3,162 channels: 1,163 colorspace: Colorspace.Greyscale,164 data: [165 1, 0, 0, 0, 0, 0,166 1, 1, 1, 1, 1, 1,167 1, 0, 0, 0, 0, 0,168 ],169 }170 it('should rotate an odd-size image 45 degrees', () => {171 const result = ImageData.rotate(simpleLineOdd, 45)172 expect(result).toEqual({173 width: 3,174 height: 3,175 channels: 1,176 colorspace: Colorspace.Greyscale,177 data: new Uint8Array([178 0, 0, 1,179 0, 1, 0,180 1, 0, 0,181 ]),182 })183 })184 it('should rotate an odd-size image 90 degrees', () => {185 const result = ImageData.rotate(simpleLineOdd, 90)186 expect(result).toEqual({187 width: 3,188 height: 3,189 channels: 1,190 colorspace: Colorspace.Greyscale,191 data: new Uint8Array([192 0, 1, 0,193 0, 1, 0,194 0, 1, 0,195 ]),196 })197 })198 it('should rotate an odd-size image 135 degrees', () => {199 const result = ImageData.rotate(simpleLineOdd, 135)200 expect(result).toEqual({201 width: 3,202 height: 3,203 channels: 1,204 colorspace: Colorspace.Greyscale,205 data: new Uint8Array([206 1, 0, 0,207 0, 1, 0,208 0, 0, 1,209 ]),210 })211 })212 it('should rotate an even-size image 90 degrees', () => {213 const result = ImageData.rotate(simpleLineEven, 90)214 expect(result).toEqual({215 width: 4,216 height: 4,217 channels: 1,218 colorspace: Colorspace.Greyscale,219 data: new Uint8Array([220 0, 0, 1, 0,221 0, 0, 1, 0,222 0, 0, 1, 0,223 0, 0, 1, 0,224 ]),225 })226 })227 it('should rotate an even-size image 270 degrees', () => {228 const result = ImageData.rotate(simpleLineEven, 270)229 expect(result).toEqual({230 width: 4,231 height: 4,232 channels: 1,233 colorspace: Colorspace.Greyscale,234 data: new Uint8Array([235 0, 1, 0, 0,236 0, 1, 0, 0,237 0, 1, 0, 0,238 0, 1, 0, 0,239 ]),240 })241 })242 it('should rotate a rectangular image 90 degrees', () => {243 const result = ImageData.rotate(simpleRectangle, 90)244 expect(result).toEqual({245 width: 3,246 height: 6,247 channels: 1,248 colorspace: Colorspace.Greyscale,249 data: new Uint8Array([250 0, 1, 0,251 0, 1, 0,252 0, 1, 0,253 0, 1, 0,254 0, 1, 0,255 1, 1, 1,256 ]),257 })258 })259 it('should rotate a rectangular image 180 degrees', () => {260 const result = ImageData.rotate(simpleRectangle, 180)261 expect(result).toEqual({262 width: 6,263 height: 3,264 channels: 1,265 colorspace: Colorspace.Greyscale,266 data: new Uint8Array([267 0, 0, 0, 0, 0, 1,268 1, 1, 1, 1, 1, 1,269 0, 0, 0, 0, 0, 1,270 ]),271 })272 })273 it('should rotate a rectangular image 270 degrees', () => {274 const result = ImageData.rotate(simpleRectangle, 270)275 expect(result).toEqual({276 width: 3,277 height: 6,278 channels: 1,279 colorspace: Colorspace.Greyscale,280 data: new Uint8Array([281 1, 1, 1,282 0, 1, 0,283 0, 1, 0,284 0, 1, 0,285 0, 1, 0,286 0, 1, 0,287 ]),288 })289 })290 })291 describe('#toGreyscale', () => {292 it('should be no-op for greyscale images', () => {293 const imageData = {294 width: 10,295 height: 10,296 channels: 1,297 colorspace: Colorspace.Greyscale,298 data: new Uint8Array(100),299 }300 expect(ImageData.toGreyscale(imageData)).toBe(imageData)301 })302 it('should use luminance for RGB images', () => {303 const imageData = {304 width: 2,305 height: 2,306 channels: 3,307 colorspace: Colorspace.RGB,308 data: [309 100, 100, 100,310 0, 100, 0,311 100, 0, 0,312 0, 0, 100,313 ],314 }315 expect(ImageData.toGreyscale(imageData)).toEqual({316 width: 2,317 height: 2,318 channels: 1,319 colorspace: Colorspace.Greyscale,320 data: new Uint8Array([100, 59, 30, 11]),321 })322 })323 it('should cycle with non-rgb images', () => {324 const imageData = {325 width: 2,326 height: 2,327 channels: 3,328 colorspace: Colorspace.YCbCr,329 data: new Uint8Array([330 100, 128, 128,331 0, 128, 128,332 50, 128, 128,333 192, 128, 128,334 ]),335 }336 const greyscale = ImageData.toGreyscale(imageData)337 expect(ImageData.toYCbCr(greyscale)).toEqual(imageData)338 })339 it('should cycle through back to RGBA', async () => {340 const skaterData = await fixtureDecode('source-skater.jpg')341 const imageData = ImageData.normalize(skaterData)342 const greyscale = ImageData.toGreyscale(imageData)343 const rgba = ImageData.toRGBA(greyscale)344 await compareToFixture(ImageData.toBuffer(rgba), 'skater-greyscale.jpg')345 })346 })347 describe('#toHSL', () => {348 it('should convert greyscale images', () => {349 const imageData = {350 width: 2,351 height: 2,352 channels: 1,353 colorspace: Colorspace.Greyscale,354 data: new Uint8Array([100, 50, 200, 30]),355 }356 expect(ImageData.toHSL(imageData)).toEqual({357 width: 2,358 height: 2,359 channels: 3,360 colorspace: Colorspace.HSL,361 data: new Float32Array([362 0, 0, 0.3921568691730499,363 0, 0, 0.19607843458652496,364 0, 0, 0.7843137383460999,365 0, 0, 0.11764705926179886,366 ]),367 })368 })369 it('should convert RGBA images', () => {370 const imageData = {371 width: 2,372 height: 2,373 channels: 4,374 colorspace: Colorspace.RGBA,375 data: new Uint8Array([376 255, 0, 0, 255,377 0, 255, 0, 255,378 255, 0, 255, 255,379 255, 255, 255, 255,380 ]),381 }382 expect(ImageData.toHSL(imageData)).toEqual({383 width: 2,384 height: 2,385 channels: 3,386 colorspace: Colorspace.HSL,387 data: new Float32Array([388 0, 1, 0.5,389 120, 1, 0.5,390 300, 1, 0.5,391 0, 0, 1,392 ]),393 })394 })395 it('should convert back to rgb', () => {396 const imageData = {397 width: 2,398 height: 2,399 channels: 3,400 colorspace: Colorspace.HSL,401 data: [402 0, 1, 0.5,403 60, 1, 0.5,404 0, 1, 1,405 300, 1, 0.5,406 ],407 }408 expect(ImageData.toRGB(imageData)).toEqual({409 width: 2,410 height: 2,411 channels: 3,412 colorspace: Colorspace.RGB,413 data: new Uint8Array([414 255, 0, 0,415 255, 255, 0,416 255, 255, 255,417 255, 0, 255,418 ]),419 })420 })421 it('should handle the rainbow', async () => {422 const rainbowData = await fixtureDecode('source-rainbow.jpg')423 const imageData = ImageData.normalize(rainbowData)424 const hsl = ImageData.toHSL(imageData)425 const rgba = ImageData.toRGBA(hsl)426 await compareToFixture(ImageData.toBuffer(rgba), 'rainbow.jpg', {strict: false})427 })428 })429 describe('#toHCL', () => {430 it('should convert to HCL', () => {431 const imageData = {432 width: 2,433 height: 2,434 channels: 3,435 colorspace: Colorspace.RGB,436 data: new Uint8Array([437 255, 255, 255,438 255, 0, 0,439 0, 255, 0,440 0, 0, 255,441 ]),442 }443 const converted = ImageData.toHCL(imageData)444 converted.data = converted.data.map(445 (x, idx) => idx % 3 === 0 ? Math.round(x) : Math.round(x * 100) / 100446 )447 expect(converted).toEqual({448 width: 2,449 height: 2,450 channels: 3,451 colorspace: Colorspace.HCL,452 data: [453 5, 0, 1,454 0, 0.33, 0.21,455 93, 0.27, 0.72,456 239, 0.31, .07,457 ],458 })459 })460 it('should cycle through back to RGBA', async () => {461 const rainbowData = await fixtureDecode('source-rainbow.jpg')462 const imageData = ImageData.normalize(rainbowData)463 const ycbcr = ImageData.toHCL(imageData)464 const rgba = ImageData.toRGBA(ycbcr)465 await compareToFixture(ImageData.toBuffer(rgba), 'rainbow.jpg', {strict: false})466 })467 })468 describe('#toXYZ', () => {469 it('should convert to XYZ', () => {470 const imageData = {471 width: 2,472 height: 2,473 channels: 3,474 colorspace: Colorspace.RGB,475 data: new Uint8Array([476 255, 255, 255,477 255, 0, 0,478 0, 255, 0,479 0, 0, 255,480 ]),481 }482 const converted = ImageData.toXYZ(imageData)483 converted.data = converted.data.map(x => Math.round(x * 1000))484 expect(converted).toEqual({485 width: 2,486 height: 2,487 channels: 3,488 colorspace: Colorspace.XYZ,489 data: [490 951, 1000, 1089,491 412, 213, 19,492 358, 715, 119,493 181, 72, 951,494 ],495 })496 })497 it('should handle calibration profiles', () => {498 const imageData = {499 width: 2,500 height: 2,501 channels: 3,502 colorspace: Colorspace.RGB,503 data: new Uint8Array([504 255, 255, 255,505 255, 0, 0,506 0, 255, 0,507 0, 0, 255,508 ]),509 }510 const converted = ImageData.toXYZ(imageData, {511 xRed: 0.25,512 yRed: 0.5,513 zRed: 0.25,514 xGreen: 0.25,515 yGreen: 0.5,516 zGreen: 0.25,517 xBlue: 0.75,518 yBlue: 0.5,519 zBlue: 0.25,520 })521 converted.data = converted.data.map(x => Math.round(x * 1000))522 expect(converted).toEqual({523 width: 2,524 height: 2,525 channels: 3,526 colorspace: Colorspace.XYZ,527 data: [528 1250, 1500, 750,529 250, 500, 250,530 250, 500, 250,531 750, 500, 250,532 ],533 })534 })535 it('should handle the rainbow', async () => {536 const rainbowData = await fixtureDecode('source-rainbow.jpg')537 const imageData = ImageData.normalize(rainbowData)538 const xyz = ImageData.toXYZ(imageData)539 const rgba = ImageData.toRGBA(xyz)540 await compareToFixture(ImageData.toBuffer(rgba), 'rainbow.jpg', {strict: false})541 })542 })543 describe('#toYCbCr', () => {544 // describe.skip('with WASM', () => {545 // beforeAll(async () => {546 // await enableWASM()547 // })548 // it('should use wasm', async () => {549 // ImageData.toYCbCr(await fixtureDecode('source-yosemite.jpg').then(ImageData.normalize))550 // })551 // afterAll(() => {552 // disableWASM()553 // })554 // })555 it('should convert RGB images', () => {556 const imageData = {557 width: 2,558 height: 2,559 channels: 3,560 colorspace: Colorspace.RGB,561 data: new Uint8Array([562 255, 255, 255,563 255, 0, 0,564 0, 0, 255,565 128, 128, 128,566 ]),567 }568 expect(ImageData.toYCbCr(imageData)).toEqual({569 width: 2,570 height: 2,571 channels: 3,572 colorspace: Colorspace.YCbCr,573 data: new Uint8Array([574 255, 128, 128,575 76, 85, 255,576 29, 255, 107,577 128, 128, 128,578 ]),579 })580 })581 it('should cycle through back to RGBA', async () => {582 const rainbowData = await fixtureDecode('source-rainbow.jpg')583 const imageData = ImageData.normalize(rainbowData)584 const ycbcr = ImageData.toYCbCr(imageData)585 const rgba = ImageData.toRGBA(ycbcr)586 await compareToFixture(ImageData.toBuffer(rgba), 'rainbow.jpg', {strict: false})587 })588 })589 describe('#toRGB', () => {590 it('should inflate greyscale images', () => {591 const imageData = {592 width: 2,593 height: 2,594 channels: 1,595 colorspace: Colorspace.Greyscale,596 data: new Uint8Array([100, 50, 200, 30]),597 }598 expect(ImageData.toRGB(imageData)).toEqual({599 width: 2,600 height: 2,601 channels: 3,602 colorspace: Colorspace.RGB,603 data: new Uint8Array([604 100, 100, 100,605 50, 50, 50,606 200, 200, 200,607 30, 30, 30,608 ]),609 })610 })611 it('should inflate YCbCr images', () => {612 const imageData = {613 width: 2,614 height: 2,615 channels: 3,616 colorspace: Colorspace.YCbCr,617 data: new Uint8Array([618 255, 128, 128,619 76, 85, 255,620 29, 255, 107,621 128, 128, 128,622 ]),623 }624 expect(ImageData.toRGB(imageData)).toEqual({625 width: 2,626 height: 2,627 channels: 3,628 colorspace: Colorspace.RGB,629 data: new Uint8Array([630 255, 255, 255,631 254, 0, 0,632 0, 0, 254,633 128, 128, 128,634 ]),635 })636 })637 })638 describe('#toRGBA', () => {639 it('should be no-op on rgba images', () => {640 return fixtureDecode('source-skater.jpg').then(skaterData => {641 const imageData = ImageData.normalize(skaterData)642 expect(ImageData.toRGBA(imageData)).toBe(imageData)643 });644 })645 it('should add full alpha channel to RGB', () => {646 const imageData = {647 width: 2,648 height: 2,649 channels: 3,650 colorspace: Colorspace.RGB,651 data: [652 100, 100, 100,653 0, 100, 0,654 100, 0, 0,655 0, 0, 100,656 ],657 }658 expect(ImageData.toRGBA(imageData)).toEqual({659 width: 2,660 height: 2,661 channels: 4,662 colorspace: Colorspace.RGBA,663 data: new Uint8Array([664 100, 100, 100, 255,665 0, 100, 0, 255,666 100, 0, 0, 255,667 0, 0, 100, 255,668 ]),669 })670 })671 })672 describe('#removeAlphaChannel', () => {673 it('should convert RGBA to RGB', () => {674 const imageData = {675 width: 2,676 height: 2,677 channels: 4,678 colorspace: Colorspace.RGBA,679 data: [680 100, 100, 100, 255,681 0, 100, 0, 255,682 100, 0, 0, 255,683 0, 0, 100, 255,684 ],685 }686 expect(ImageData.removeAlphaChannel(imageData)).toEqual({687 width: 2,688 height: 2,689 channels: 3,690 colorspace: Colorspace.RGB,691 data: new Uint8Array([692 100, 100, 100,693 0, 100, 0,694 100, 0, 0,695 0, 0, 100,696 ]),697 })698 })699 })700 describe('#toBrowserImageData', () => {701 it('should throw in node', () => {702 expect(() => {703 ImageData.toBrowserImageData({data: []})704 }).toThrowError(/must be called in browser/)705 })706 })707 describe('WASM', () => {708 if (!process.env.ENABLE_WASM) {709 it.skip('should enable WASM for these tests', () => undefined)710 return711 }712 beforeAll(async () => {713 await enableWASM()714 })715 afterAll(async () => {716 await disableWASM()717 })718 describe('#toXYZ', () => {719 it('should handle simple cases', () => {720 const imageData = {721 width: 2,722 height: 2,723 channels: 3,724 colorspace: Colorspace.RGB,725 data: new Uint8Array([726 255, 255, 255,727 255, 0, 0,728 0, 255, 0,729 0, 0, 255,730 ]),731 }732 const xyz = ImageData.toXYZ(imageData)733 const rgb = ImageData.toRGB(xyz)734 xyz.data = xyz.data.map(x => Math.round(x * 1000))735 expect(xyz).toEqual({736 width: 2,737 height: 2,738 channels: 3,739 colorspace: Colorspace.XYZ,740 data: [741 951, 1000, 1089,742 412, 213, 19,743 358, 715, 119,744 181, 72, 951,745 ],746 })747 expect(rgb).toEqual({748 width: 2,749 height: 2,750 channels: 3,751 colorspace: Colorspace.RGB,752 data: new Uint8Array([753 255, 255, 255,754 255, 1, 0,755 0, 255, 1,756 1, 0, 255,757 ]),758 })759 })760 it('should handle images', async () => {761 const rainbowData = await fixtureDecode('source-rainbow.jpg')762 const imageData = ImageData.normalize(rainbowData)763 const xyz = ImageData.toXYZ(imageData)764 const rgba = ImageData.toRGBA(xyz)765 await compareToFixture(ImageData.toBuffer(rgba), 'rainbow.jpg', {strict: false})766 })767 })768 })...

Full Screen

Full Screen

colorspace_spec.js

Source:colorspace_spec.js Github

copy

Full Screen

1/* Copyright 2017 Mozilla Foundation2 *3 * Licensed under the Apache License, Version 2.0 (the "License");4 * you may not use this file except in compliance with the License.5 * You may obtain a copy of the License at6 *7 * http://www.apache.org/licenses/LICENSE-2.08 *9 * Unless required by applicable law or agreed to in writing, software10 * distributed under the License is distributed on an "AS IS" BASIS,11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12 * See the License for the specific language governing permissions and13 * limitations under the License.14 */15'use strict';16var _primitives = require('../../core/primitives');17var _stream = require('../../core/stream');18var _colorspace = require('../../core/colorspace');19var _function = require('../../core/function');20var _test_utils = require('./test_utils');21describe('colorspace', function () {22 describe('ColorSpace', function () {23 it('should be true if decode is not an array', function () {24 expect(_colorspace.ColorSpace.isDefaultDecode('string', 0)).toBeTruthy();25 });26 it('should be true if length of decode array is not correct', function () {27 expect(_colorspace.ColorSpace.isDefaultDecode([0], 1)).toBeTruthy();28 expect(_colorspace.ColorSpace.isDefaultDecode([0, 1, 0], 1)).toBeTruthy();29 });30 it('should be true if decode map matches the default decode map', function () {31 expect(_colorspace.ColorSpace.isDefaultDecode([], 0)).toBeTruthy();32 expect(_colorspace.ColorSpace.isDefaultDecode([0, 0], 1)).toBeFalsy();33 expect(_colorspace.ColorSpace.isDefaultDecode([0, 1], 1)).toBeTruthy();34 expect(_colorspace.ColorSpace.isDefaultDecode([0, 1, 0, 1, 0, 1], 3)).toBeTruthy();35 expect(_colorspace.ColorSpace.isDefaultDecode([0, 1, 0, 1, 1, 1], 3)).toBeFalsy();36 expect(_colorspace.ColorSpace.isDefaultDecode([0, 1, 0, 1, 0, 1, 0, 1], 4)).toBeTruthy();37 expect(_colorspace.ColorSpace.isDefaultDecode([1, 0, 0, 1, 0, 1, 0, 1], 4)).toBeFalsy();38 });39 });40 describe('DeviceGrayCS', function () {41 it('should handle the case when cs is a Name object', function () {42 var cs = _primitives.Name.get('DeviceGray');43 var xref = new _test_utils.XRefMock([{44 ref: new _primitives.Ref(10, 0),45 data: new _primitives.Dict()46 }]);47 var res = new _primitives.Dict();48 var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });49 var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);50 var testSrc = new Uint8Array([27, 125, 250, 131]);51 var testDest = new Uint8Array(4 * 4 * 3);52 var expectedDest = new Uint8Array([27, 27, 27, 27, 27, 27, 125, 125, 125, 125, 125, 125, 27, 27, 27, 27, 27, 27, 125, 125, 125, 125, 125, 125, 250, 250, 250, 250, 250, 250, 131, 131, 131, 131, 131, 131, 250, 250, 250, 250, 250, 250, 131, 131, 131, 131, 131, 131]);53 colorSpace.fillRgb(testDest, 2, 2, 4, 4, 4, 8, testSrc, 0);54 expect(colorSpace.getRgb(new Float32Array([0.1]), 0)).toEqual(new Uint8Array([25, 25, 25]));55 expect(colorSpace.getOutputLength(2, 0)).toEqual(6);56 expect(colorSpace.isPassthrough(8)).toBeFalsy();57 expect(testDest).toEqual(expectedDest);58 });59 it('should handle the case when cs is an indirect object', function () {60 var cs = new _primitives.Ref(10, 0);61 var xref = new _test_utils.XRefMock([{62 ref: cs,63 data: _primitives.Name.get('DeviceGray')64 }]);65 var res = new _primitives.Dict();66 var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });67 var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);68 var testSrc = new Uint8Array([27, 125, 250, 131]);69 var testDest = new Uint8Array(3 * 3 * 3);70 var expectedDest = new Uint8Array([27, 27, 27, 27, 27, 27, 125, 125, 125, 27, 27, 27, 27, 27, 27, 125, 125, 125, 250, 250, 250, 250, 250, 250, 131, 131, 131]);71 colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);72 expect(colorSpace.getRgb(new Float32Array([0.2]), 0)).toEqual(new Uint8Array([51, 51, 51]));73 expect(colorSpace.getOutputLength(3, 1)).toEqual(12);74 expect(colorSpace.isPassthrough(8)).toBeFalsy();75 expect(testDest).toEqual(expectedDest);76 });77 });78 describe('DeviceRgbCS', function () {79 it('should handle the case when cs is a Name object', function () {80 var cs = _primitives.Name.get('DeviceRGB');81 var xref = new _test_utils.XRefMock([{82 ref: new _primitives.Ref(10, 0),83 data: new _primitives.Dict()84 }]);85 var res = new _primitives.Dict();86 var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });87 var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);88 var testSrc = new Uint8Array([27, 125, 250, 131, 139, 140, 111, 25, 198, 21, 147, 255]);89 var testDest = new Uint8Array(4 * 4 * 3);90 var expectedDest = new Uint8Array([27, 125, 250, 27, 125, 250, 131, 139, 140, 131, 139, 140, 27, 125, 250, 27, 125, 250, 131, 139, 140, 131, 139, 140, 111, 25, 198, 111, 25, 198, 21, 147, 255, 21, 147, 255, 111, 25, 198, 111, 25, 198, 21, 147, 255, 21, 147, 255]);91 colorSpace.fillRgb(testDest, 2, 2, 4, 4, 4, 8, testSrc, 0);92 expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3]), 0)).toEqual(new Uint8Array([25, 51, 76]));93 expect(colorSpace.getOutputLength(4, 0)).toEqual(4);94 expect(colorSpace.isPassthrough(8)).toBeTruthy();95 expect(testDest).toEqual(expectedDest);96 });97 it('should handle the case when cs is an indirect object', function () {98 var cs = new _primitives.Ref(10, 0);99 var xref = new _test_utils.XRefMock([{100 ref: cs,101 data: _primitives.Name.get('DeviceRGB')102 }]);103 var res = new _primitives.Dict();104 var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });105 var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);106 var testSrc = new Uint8Array([27, 125, 250, 131, 139, 140, 111, 25, 198, 21, 147, 255]);107 var testDest = new Uint8Array(3 * 3 * 3);108 var expectedDest = new Uint8Array([27, 125, 250, 27, 125, 250, 131, 139, 140, 27, 125, 250, 27, 125, 250, 131, 139, 140, 111, 25, 198, 111, 25, 198, 21, 147, 255]);109 colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);110 expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3]), 0)).toEqual(new Uint8Array([25, 51, 76]));111 expect(colorSpace.getOutputLength(4, 1)).toEqual(5);112 expect(colorSpace.isPassthrough(8)).toBeTruthy();113 expect(testDest).toEqual(expectedDest);114 });115 });116 describe('DeviceCmykCS', function () {117 it('should handle the case when cs is a Name object', function () {118 var cs = _primitives.Name.get('DeviceCMYK');119 var xref = new _test_utils.XRefMock([{120 ref: new _primitives.Ref(10, 0),121 data: new _primitives.Dict()122 }]);123 var res = new _primitives.Dict();124 var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });125 var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);126 var testSrc = new Uint8Array([27, 125, 250, 128, 131, 139, 140, 45, 111, 25, 198, 78, 21, 147, 255, 69]);127 var testDest = new Uint8Array(4 * 4 * 3);128 var expectedDest = new Uint8Array([135, 80, 18, 135, 80, 18, 113, 102, 97, 113, 102, 97, 135, 80, 18, 135, 80, 18, 113, 102, 97, 113, 102, 97, 112, 143, 75, 112, 143, 75, 188, 98, 27, 188, 98, 27, 112, 143, 75, 112, 143, 75, 188, 98, 27, 188, 98, 27]);129 colorSpace.fillRgb(testDest, 2, 2, 4, 4, 4, 8, testSrc, 0);130 expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3, 1]), 0)).toEqual(new Uint8Array([31, 27, 20]));131 expect(colorSpace.getOutputLength(4, 0)).toEqual(3);132 expect(colorSpace.isPassthrough(8)).toBeFalsy();133 expect(testDest).toEqual(expectedDest);134 });135 it('should handle the case when cs is an indirect object', function () {136 var cs = new _primitives.Ref(10, 0);137 var xref = new _test_utils.XRefMock([{138 ref: cs,139 data: _primitives.Name.get('DeviceCMYK')140 }]);141 var res = new _primitives.Dict();142 var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });143 var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);144 var testSrc = new Uint8Array([27, 125, 250, 128, 131, 139, 140, 45, 111, 25, 198, 78, 21, 147, 255, 69]);145 var testDest = new Uint8Array(3 * 3 * 3);146 var expectedDest = new Uint8Array([135, 80, 18, 135, 80, 18, 113, 102, 97, 135, 80, 18, 135, 80, 18, 113, 102, 97, 112, 143, 75, 112, 143, 75, 188, 98, 27]);147 colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);148 expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3, 1]), 0)).toEqual(new Uint8Array([31, 27, 20]));149 expect(colorSpace.getOutputLength(4, 1)).toEqual(4);150 expect(colorSpace.isPassthrough(8)).toBeFalsy();151 expect(testDest).toEqual(expectedDest);152 });153 });154 describe('CalGrayCS', function () {155 it('should handle the case when cs is an array', function () {156 var params = new _primitives.Dict();157 params.set('WhitePoint', [1, 1, 1]);158 params.set('BlackPoint', [0, 0, 0]);159 params.set('Gamma', 2.0);160 var cs = [_primitives.Name.get('CalGray'), params];161 var xref = new _test_utils.XRefMock([{162 ref: new _primitives.Ref(10, 0),163 data: new _primitives.Dict()164 }]);165 var res = new _primitives.Dict();166 var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });167 var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);168 var testSrc = new Uint8Array([27, 125, 250, 131]);169 var testDest = new Uint8Array(4 * 4 * 3);170 var expectedDest = new Uint8Array([25, 25, 25, 25, 25, 25, 143, 143, 143, 143, 143, 143, 25, 25, 25, 25, 25, 25, 143, 143, 143, 143, 143, 143, 251, 251, 251, 251, 251, 251, 148, 148, 148, 148, 148, 148, 251, 251, 251, 251, 251, 251, 148, 148, 148, 148, 148, 148]);171 colorSpace.fillRgb(testDest, 2, 2, 4, 4, 4, 8, testSrc, 0);172 expect(colorSpace.getRgb(new Float32Array([1.0]), 0)).toEqual(new Uint8Array([255, 255, 255]));173 expect(colorSpace.getOutputLength(4, 0)).toEqual(12);174 expect(colorSpace.isPassthrough(8)).toBeFalsy();175 expect(testDest).toEqual(expectedDest);176 });177 });178 describe('CalRGBCS', function () {179 it('should handle the case when cs is an array', function () {180 var params = new _primitives.Dict();181 params.set('WhitePoint', [1, 1, 1]);182 params.set('BlackPoint', [0, 0, 0]);183 params.set('Gamma', [1, 1, 1]);184 params.set('Matrix', [1, 0, 0, 0, 1, 0, 0, 0, 1]);185 var cs = [_primitives.Name.get('CalRGB'), params];186 var xref = new _test_utils.XRefMock([{187 ref: new _primitives.Ref(10, 0),188 data: new _primitives.Dict()189 }]);190 var res = new _primitives.Dict();191 var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });192 var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);193 var testSrc = new Uint8Array([27, 125, 250, 131, 139, 140, 111, 25, 198, 21, 147, 255]);194 var testDest = new Uint8Array(3 * 3 * 3);195 var expectedDest = new Uint8Array([0, 238, 255, 0, 238, 255, 185, 196, 195, 0, 238, 255, 0, 238, 255, 185, 196, 195, 235, 0, 243, 235, 0, 243, 0, 255, 255]);196 colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);197 expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3]), 0)).toEqual(new Uint8Array([0, 147, 151]));198 expect(colorSpace.getOutputLength(4, 0)).toEqual(4);199 expect(colorSpace.isPassthrough(8)).toBeFalsy();200 expect(testDest).toEqual(expectedDest);201 });202 });203 describe('LabCS', function () {204 it('should handle the case when cs is an array', function () {205 var params = new _primitives.Dict();206 params.set('WhitePoint', [1, 1, 1]);207 params.set('BlackPoint', [0, 0, 0]);208 params.set('Range', [-100, 100, -100, 100]);209 var cs = [_primitives.Name.get('Lab'), params];210 var xref = new _test_utils.XRefMock([{211 ref: new _primitives.Ref(10, 0),212 data: new _primitives.Dict()213 }]);214 var res = new _primitives.Dict();215 var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });216 var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);217 var testSrc = new Uint8Array([27, 25, 50, 31, 19, 40, 11, 25, 98, 21, 47, 55]);218 var testDest = new Uint8Array(3 * 3 * 3);219 var expectedDest = new Uint8Array([0, 49, 101, 0, 49, 101, 0, 53, 116, 0, 49, 101, 0, 49, 101, 0, 53, 116, 0, 40, 39, 0, 40, 39, 0, 43, 90]);220 colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);221 expect(colorSpace.getRgb([55, 25, 35], 0)).toEqual(new Uint8Array([188, 99, 61]));222 expect(colorSpace.getOutputLength(4, 0)).toEqual(4);223 expect(colorSpace.isPassthrough(8)).toBeFalsy();224 expect(colorSpace.isDefaultDecode([0, 1])).toBeTruthy();225 expect(testDest).toEqual(expectedDest);226 });227 });228 describe('IndexedCS', function () {229 it('should handle the case when cs is an array', function () {230 var lookup = new Uint8Array([23, 155, 35, 147, 69, 93, 255, 109, 70]);231 var cs = [_primitives.Name.get('Indexed'), _primitives.Name.get('DeviceRGB'), 2, lookup];232 var xref = new _test_utils.XRefMock([{233 ref: new _primitives.Ref(10, 0),234 data: new _primitives.Dict()235 }]);236 var res = new _primitives.Dict();237 var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });238 var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);239 var testSrc = new Uint8Array([2, 2, 0, 1]);240 var testDest = new Uint8Array(3 * 3 * 3);241 var expectedDest = new Uint8Array([255, 109, 70, 255, 109, 70, 255, 109, 70, 255, 109, 70, 255, 109, 70, 255, 109, 70, 23, 155, 35, 23, 155, 35, 147, 69, 93]);242 colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);243 expect(colorSpace.getRgb([2], 0)).toEqual(new Uint8Array([255, 109, 70]));244 expect(colorSpace.isPassthrough(8)).toBeFalsy();245 expect(colorSpace.isDefaultDecode([0, 1])).toBeTruthy();246 expect(testDest).toEqual(expectedDest);247 });248 });249 describe('AlternateCS', function () {250 it('should handle the case when cs is an array', function () {251 var fnDict = new _primitives.Dict();252 fnDict.set('FunctionType', 4);253 fnDict.set('Domain', [0.0, 1.0]);254 fnDict.set('Range', [0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0]);255 fnDict.set('Length', 58);256 var fn = new _stream.StringStream('{ dup 0.84 mul ' + 'exch 0.00 exch ' + 'dup 0.44 mul ' + 'exch 0.21 mul }');257 fn = new _stream.Stream(fn.bytes, 0, 58, fnDict);258 var fnRef = new _primitives.Ref(10, 0);259 var cs = [_primitives.Name.get('Separation'), _primitives.Name.get('LogoGreen'), _primitives.Name.get('DeviceCMYK'), fnRef];260 var xref = new _test_utils.XRefMock([{261 ref: fnRef,262 data: fn263 }]);264 var res = new _primitives.Dict();265 var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });266 var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);267 var testSrc = new Uint8Array([27, 25, 50, 31]);268 var testDest = new Uint8Array(3 * 3 * 3);269 var expectedDest = new Uint8Array([227, 243, 242, 227, 243, 242, 228, 243, 242, 227, 243, 242, 227, 243, 242, 228, 243, 242, 203, 233, 229, 203, 233, 229, 222, 241, 239]);270 colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);271 expect(colorSpace.getRgb([0.1], 0)).toEqual(new Uint8Array([228, 243, 241]));272 expect(colorSpace.isPassthrough(8)).toBeFalsy();273 expect(colorSpace.isDefaultDecode([0, 1])).toBeTruthy();274 expect(testDest).toEqual(expectedDest);275 });276 });...

Full Screen

Full Screen

converters.ts

Source:converters.ts Github

copy

Full Screen

1import { Color } from './colors'2import { ColorSpace, getSpaceScales } from './spaces'3const { min, max } = Math4export type ColorConverter = (color: Color) => Color5export type ColorConverterMap = {6 [FromSpace in ColorSpace]: { [ToSpace in ColorSpace]: ColorConverter }7}8export const colorConverters: ColorConverterMap = {9 // RGB10 [ColorSpace.RGB]: {11 // RGB -> RGB12 [ColorSpace.RGB]: color => new Color(ColorSpace.RGB, [...color.data]),13 // RGB -> RGBA14 [ColorSpace.RGBA]: color => new Color(ColorSpace.RGBA, [...color.data, 1]),15 // RGB -> HSL16 [ColorSpace.HSL]: color => {17 const [rScale, gScale, bScale] = getSpaceScales(color.space)18 let [r, g, b] = color.data19 r /= rScale20 g /= gScale21 b /= bScale22 const maxValue = max(r, g, b)23 const minValue = min(r, g, b)24 let h = 025 let s = 026 const l = (maxValue + minValue) / 227 if (maxValue !== minValue) {28 const d = maxValue - minValue29 s = l > 0.5 ? d / (2 - maxValue - minValue) : d / (maxValue + minValue)30 switch (maxValue) {31 case r:32 h = (g - b) / d + (g < b ? 6 : 0)33 break34 case g:35 h = (b - r) / d + 236 break37 case b:38 h = (r - g) / d + 439 break40 }41 h /= 642 }43 const [hScale, sScale, lScale] = getSpaceScales(ColorSpace.HSL)44 return Color.hsl(h * hScale, s * sScale, l * lScale)45 },46 // RGB -> HSLA47 [ColorSpace.HSLA]: color =>48 new Color(ColorSpace.HSLA, [...toSpace(color, ColorSpace.HSL).data, 1]),49 },50 // RGBA51 [ColorSpace.RGBA]: {52 // RGBA -> RGB53 [ColorSpace.RGB]: color => new Color(ColorSpace.RGB, [...color.data.slice(0, 3)]),54 // RGBA -> RGBA55 [ColorSpace.RGBA]: color => new Color(ColorSpace.RGBA, [...color.data]),56 // RGBA -> HSL57 [ColorSpace.HSL]: color => toSpace(toSpace(color, ColorSpace.RGB), ColorSpace.HSL),58 // RGBA -> HSLA59 [ColorSpace.HSLA]: color =>60 new Color(ColorSpace.HSLA, [...toSpace(color, ColorSpace.HSL).data, color.data[3]]),61 },62 [ColorSpace.HSL]: {63 // HSL -> RGB64 [ColorSpace.RGB]: color => {65 const [hScale, sScale, lScale] = getSpaceScales(color.space)66 let [h, s, l] = color.data67 let r = 068 let g = 069 let b = 070 h /= hScale71 s /= sScale72 l /= lScale73 if (s === 0.0) {74 r = l75 g = l76 b = l77 } else {78 const q = l < 0.5 ? l * (1 + s) : l + s - l * s79 const p = 2 * l - q80 r = getRgbFromHue(p, q, h + 1 / 3)81 g = getRgbFromHue(p, q, h)82 b = getRgbFromHue(p, q, h - 1 / 3)83 }84 const [rScale, gScale, bScale] = getSpaceScales(ColorSpace.RGB)85 return Color.rgb(r * rScale, g * gScale, b * bScale)86 },87 // HSL -> RGBA88 [ColorSpace.RGBA]: color =>89 new Color(ColorSpace.RGBA, [...toSpace(color, ColorSpace.RGB).data, 1]),90 // HSL -> HSL91 [ColorSpace.HSL]: color => new Color(ColorSpace.HSL, [...color.data]),92 // HSL -> HSLA93 [ColorSpace.HSLA]: color => new Color(ColorSpace.HSLA, [...color.data, 1]),94 },95 // HSLA96 [ColorSpace.HSLA]: {97 // HSLA -> RGB98 [ColorSpace.RGB]: color => toSpace(toSpace(color, ColorSpace.HSL), ColorSpace.RGB),99 // HSLA -> RGBA100 [ColorSpace.RGBA]: color =>101 new Color(ColorSpace.RGBA, [...toSpace(color, ColorSpace.RGB).data, color.data[3]]),102 // HSLA -> HSL103 [ColorSpace.HSL]: color => new Color(ColorSpace.HSL, [...color.data.slice(0, 3)]),104 // HSLA -> HSLA105 [ColorSpace.HSLA]: color => new Color(ColorSpace.HSLA, [...color.data]),106 },107}108export const toSpace = (color: Color, targetSpace: ColorSpace): Color => {109 if (color.space === targetSpace) {110 return color111 }112 return colorConverters[color.space][targetSpace](color)113}114const getRgbFromHue = (p: number, q: number, t: number): number => {115 let nt = t116 // Normalize117 if (nt < 0) {118 nt += 1119 } else if (nt > 1) {120 nt -= 1121 }122 if (nt < 1 / 6) {123 return p + (q - p) * 6 * nt124 }125 if (nt < 1 / 2) {126 return q127 }128 if (nt < 2 / 3) {129 return p + (q - p) * (2 / 3 - nt) * 6130 }131 return p...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2page.get(function(err, resp) {3 if (err) {4 console.log(err);5 } else {6 console.log(resp);7 }8});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var page = wptools.page('Albert Einstein');3page.get(function(err, resp) {4 console.log(resp.colorspace);5});6var wptools = require('wptools');7var page = wptools.page('Albert Einstein');8page.get(function(err, resp) {9 console.log(resp.coordinates);10});11var wptools = require('wptools');12var page = wptools.page('Albert Einstein');13page.get(function(err, resp) {14 console.log(resp.created);15});16var wptools = require('wptools');17var page = wptools.page('Albert Einstein');18page.get(function(err, resp) {19 console.log(resp.creator);20});21var wptools = require('wptools');22var page = wptools.page('Albert Einstein');23page.get(function(err, resp) {24 console.log(resp.date);25});26var wptools = require('wptools');27var page = wptools.page('Albert Einstein');28page.get(function(err, resp) {29 console.log(resp.description);30});31var wptools = require('wptools');32var page = wptools.page('Albert Einstein');33page.get(function(err, resp) {34 console.log(resp.disambiguation);35});36var wptools = require('wptools');37var page = wptools.page('Albert Einstein');38page.get(function(err, resp) {39 console.log(resp.disambiguation_source);40});41var wptools = require('wptools');42var page = wptools.page('Albert Einstein');43page.get(function(err, resp) {44 console.log(resp.disambiguation_text);45});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2wptools.colorspace('New York City', function(err, result) {3 if (err) {4 console.log('error:', err);5 } else {6 console.log(result);7 }8});9{10 "colorspace": {11 {12 "rgb": {13 },14 "hsl": {15 },16 "cmyk": {17 },18 "lab": {19 },20 "yiq": {21 },22 "xyz": {23 },24 },25 {26 "rgb": {27 },28 "hsl": {29 },30 "cmyk": {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var colorspace = require('colorspace');3var colors = require('colors');4var options = {5};6wptools.page(url, options).then(function(page) {7 return page.colorspace();8}).then(function(colorspace) {9 var colors = colorspace.colors;10 for (var i = 0; i < colors.length; i++) {11 var color = colors[i];12 console.log(color.hex);13 console.log(colorspace.hex(color.hex).rgb().string());14 console.log(colorspace.hex(color.hex).hsl().string());15 console.log(colorspace.hex(color.hex).hsv().string());16 console.log(colorspace.hex(color.hex).hwb().string());17 console.log(colorspace.hex(color.hex).cmyk().string());18 console.log(colorspace.hex(color.hex).xyz().string());19 console.log(colorspace.hex(color.hex).lab().string());20 console.log(colorspace.hex(color.hex).lch().string());21 console.log(colorspace.hex(color.hex).lch().string());22 console.log(colorspace.hex(color.hex).lms().string());23 console.log(colorspace.hex(color.hex).luv().string());24 console.log(colorspace.hex(color.hex).hcg().string());25 console.log(colorspace.hex(color.hex).hsi().string());26 console.log(colorspace.hex(color.hex).hsp().string());27 console.log(colorspace.hex(color.hex).hsluv().string());28 console.log(colorspace.hex(color.hex).hpluv().string());29 console.log(colorspace.hex(color.hex).lab().string());30 console.log("\n");31 }32}).catch(function(error) {33 console.log(error);34});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var fs = require('fs');3var colors = require('colors');4var async = require('async');5var jsonfile = require('jsonfile');6var request = require('request');7var cheerio = require('cheerio');8var file = 'wikipedia.json';9var file2 = 'wikipedia2.json';10var file3 = 'wikipedia3.json';11var file4 = 'wikipedia4.json';12var file5 = 'wikipedia5.json';13var file6 = 'wikipedia6.json';14var file7 = 'wikipedia7.json';15var file8 = 'wikipedia8.json';16var file9 = 'wikipedia9.json';17var file10 = 'wikipedia10.json';18var file11 = 'wikipedia11.json';19var file12 = 'wikipedia12.json';20var file13 = 'wikipedia13.json';21var file14 = 'wikipedia14.json';22var file15 = 'wikipedia15.json';23var file16 = 'wikipedia16.json';24var file17 = 'wikipedia17.json';25var file18 = 'wikipedia18.json';26var file19 = 'wikipedia19.json';27var file20 = 'wikipedia20.json';28var file21 = 'wikipedia21.json';29var file22 = 'wikipedia22.json';30var file23 = 'wikipedia23.json';31var file24 = 'wikipedia24.json';32var file25 = 'wikipedia25.json';33var file26 = 'wikipedia26.json';34var file27 = 'wikipedia27.json';35var file28 = 'wikipedia28.json';36var file29 = 'wikipedia29.json';37var file30 = 'wikipedia30.json';38var file31 = 'wikipedia31.json';39var file32 = 'wikipedia32.json';40var file33 = 'wikipedia33.json';41var file34 = 'wikipedia34.json';42var file35 = 'wikipedia35.json';43var file36 = 'wikipedia36.json';44var file37 = 'wikipedia37.json';45var file38 = 'wikipedia38.json';46var file39 = 'wikipedia39.json';47var file40 = 'wikipedia40.json';48var file41 = 'wikipedia41.json';49var file42 = 'wikipedia42.json';

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var colorspace = require('colorspace');3wptools.page('Barack Obama').then(function(page) {4 page.imageinfo().then(function(imageinfo) {5 var url = imageinfo[0].url;6 colorspace(url, function(err, colors) {7 console.log(colors);8 });9 });10});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var fs = require('fs');3var test = wptools.page('Nelson_Mandela');4test.get(function(err, resp) {5 if(err) {6 console.log(err);7 } else {8 console.log(resp);9 }10});11test.colorSpace(function(err, resp) {12 if(err) {13 console.log(err);14 } else {15 console.log(resp);16 }17});18test.dominantColor(function(err, resp) {19 if(err) {20 console.log(err);21 } else {22 console.log(resp);23 }24});25test.fullInfo(function(err, resp) {26 if(err) {27 console.log(err);28 } else {29 console.log(resp);30 }31});32test.getImages(function(err, resp) {33 if(err) {34 console.log(err);35 } else {36 console.log(resp);37 }38});39test.getImageInfo(function(err, resp) {40 if(err) {41 console.log(err);42 } else {43 console.log(resp);44 }45});46test.getImageUsage(function(err, resp) {47 if(err) {48 console.log(err);49 } else {50 console.log(resp);51 }52});53test.getCoordinates(function(err, resp) {54 if(err) {55 console.log(err);56 } else {57 console.log(resp);58 }59});60test.getExtract(function(err, resp) {61 if(err) {62 console.log(err);63 } else {64 console.log(resp);65 }66});67test.getLangLinks(function(err, resp) {68 if(err) {69 console.log(err);70 } else {71 console.log(resp);72 }73});74test.getLinks(function(err, resp) {75 if(err) {76 console.log(err);77 } else {78 console.log(resp);79 }80});81test.getNearby(function(err, resp) {82 if(err) {83 console.log(err);84 } else {85 console.log(resp);86 }87});88test.getRedirects(function(err, resp) {89 if(err) {90 console.log(err);91 } else {92 console.log(resp);93 }94});95test.getRevisions(function(err, resp) {96 if(err) {97 console.log(err);98 } else {99 console.log(resp);100 }101});102test.getTemplates(function(err, resp

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