Best JavaScript code snippet using wpt
colorspace.js
Source:colorspace.js
...29 switch (name) {30 case 'DeviceGrayCS':31 return new DeviceGrayCS();32 case 'DeviceRgbCS':33 return new DeviceRgbCS();34 case 'DeviceCmykCS':35 return new DeviceCmykCS();36 case 'PatternCS':37 var basePatternCS = IR[1];38 if (basePatternCS)39 basePatternCS = ColorSpace.fromIR(basePatternCS);40 return new PatternCS(basePatternCS);41 case 'IndexedCS':42 var baseIndexedCS = IR[1];43 var hiVal = IR[2];44 var lookup = IR[3];45 return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);46 case 'AlternateCS':47 var numComps = IR[1];48 var alt = IR[2];49 var tintFnIR = IR[3];50 return new AlternateCS(numComps, ColorSpace.fromIR(alt),51 PDFFunction.fromIR(tintFnIR));52 case 'LabCS':53 var whitePoint = IR[1].WhitePoint;54 var blackPoint = IR[1].BlackPoint;55 var range = IR[1].Range;56 return new LabCS(whitePoint, blackPoint, range);57 default:58 error('Unkown name ' + name);59 }60 return null;61 };62 ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {63 if (isName(cs)) {64 var colorSpaces = res.get('ColorSpace');65 if (isDict(colorSpaces)) {66 var refcs = colorSpaces.get(cs.name);67 if (refcs)68 cs = refcs;69 }70 }71 cs = xref.fetchIfRef(cs);72 var mode;73 if (isName(cs)) {74 mode = cs.name;75 this.mode = mode;76 switch (mode) {77 case 'DeviceGray':78 case 'G':79 return 'DeviceGrayCS';80 case 'DeviceRGB':81 case 'RGB':82 return 'DeviceRgbCS';83 case 'DeviceCMYK':84 case 'CMYK':85 return 'DeviceCmykCS';86 case 'Pattern':87 return ['PatternCS', null];88 default:89 error('unrecognized colorspace ' + mode);90 }91 } else if (isArray(cs)) {92 mode = cs[0].name;93 this.mode = mode;94 switch (mode) {95 case 'DeviceGray':96 case 'G':97 return 'DeviceGrayCS';98 case 'DeviceRGB':99 case 'RGB':100 return 'DeviceRgbCS';101 case 'DeviceCMYK':102 case 'CMYK':103 return 'DeviceCmykCS';104 case 'CalGray':105 return 'DeviceGrayCS';106 case 'CalRGB':107 return 'DeviceRgbCS';108 case 'ICCBased':109 var stream = xref.fetchIfRef(cs[1]);110 var dict = stream.dict;111 var numComps = dict.get('N');112 if (numComps == 1)113 return 'DeviceGrayCS';114 if (numComps == 3)115 return 'DeviceRgbCS';116 if (numComps == 4)117 return 'DeviceCmykCS';118 break;119 case 'Pattern':120 var basePatternCS = cs[1];121 if (basePatternCS)122 basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);123 return ['PatternCS', basePatternCS];124 case 'Indexed':125 case 'I':126 var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);127 var hiVal = cs[2] + 1;128 var lookup = xref.fetchIfRef(cs[3]);129 if (isStream(lookup)) {130 lookup = lookup.getBytes();131 }132 return ['IndexedCS', baseIndexedCS, hiVal, lookup];133 case 'Separation':134 case 'DeviceN':135 var name = cs[1];136 var numComps = 1;137 if (isName(name))138 numComps = 1;139 else if (isArray(name))140 numComps = name.length;141 var alt = ColorSpace.parseToIR(cs[2], xref, res);142 var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));143 return ['AlternateCS', numComps, alt, tintFnIR];144 case 'Lab':145 var params = cs[1].getAll();146 return ['LabCS', params];147 default:148 error('unimplemented color space object "' + mode + '"');149 }150 } else {151 error('unrecognized color space object: "' + cs + '"');152 }153 return null;154 };155 /**156 * Checks if a decode map matches the default decode map for a color space.157 * This handles the general decode maps where there are two values per158 * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.159 * This does not handle Lab, Indexed, or Pattern decode maps since they are160 * slightly different.161 * @param {Array} decode Decode map (usually from an image).162 * @param {Number} n Number of components the color space has.163 */164 ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {165 if (!decode)166 return true;167 if (n * 2 !== decode.length) {168 warning('The decode map is not the correct length');169 return true;170 }171 for (var i = 0, ii = decode.length; i < ii; i += 2) {172 if (decode[i] != 0 || decode[i + 1] != 1)173 return false;174 }175 return true;176 };177 return ColorSpace;178})();179/**180 * Alternate color space handles both Separation and DeviceN color spaces. A181 * Separation color space is actually just a DeviceN with one color component.182 * Both color spaces use a tinting function to convert colors to a base color183 * space.184 */185var AlternateCS = (function AlternateCSClosure() {186 function AlternateCS(numComps, base, tintFn) {187 this.name = 'Alternate';188 this.numComps = numComps;189 this.defaultColor = [];190 for (var i = 0; i < numComps; ++i)191 this.defaultColor.push(1);192 this.base = base;193 this.tintFn = tintFn;194 }195 AlternateCS.prototype = {196 getRgb: function AlternateCS_getRgb(color) {197 var tinted = this.tintFn(color);198 return this.base.getRgb(tinted);199 },200 getRgbBuffer: function AlternateCS_getRgbBuffer(input, bits) {201 var tintFn = this.tintFn;202 var base = this.base;203 var scale = 1 / ((1 << bits) - 1);204 var length = input.length;205 var pos = 0;206 var baseNumComps = base.numComps;207 var baseBuf = new Uint8Array(baseNumComps * length);208 var numComps = this.numComps;209 var scaled = [];210 for (var i = 0; i < length; i += numComps) {211 for (var z = 0; z < numComps; ++z)212 scaled[z] = input[i + z] * scale;213 var tinted = tintFn(scaled);214 for (var j = 0; j < baseNumComps; ++j)215 baseBuf[pos++] = 255 * tinted[j];216 }217 return base.getRgbBuffer(baseBuf, 8);218 },219 isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {220 return ColorSpace.isDefaultDecode(decodeMap, this.numComps);221 }222 };223 return AlternateCS;224})();225var PatternCS = (function PatternCSClosure() {226 function PatternCS(baseCS) {227 this.name = 'Pattern';228 this.base = baseCS;229 }230 PatternCS.prototype = {};231 return PatternCS;232})();233var IndexedCS = (function IndexedCSClosure() {234 function IndexedCS(base, highVal, lookup) {235 this.name = 'Indexed';236 this.numComps = 1;237 this.defaultColor = [0];238 this.base = base;239 this.highVal = highVal;240 var baseNumComps = base.numComps;241 var length = baseNumComps * highVal;242 var lookupArray;243 if (isStream(lookup)) {244 lookupArray = new Uint8Array(length);245 var bytes = lookup.getBytes(length);246 lookupArray.set(bytes);247 } else if (isString(lookup)) {248 lookupArray = new Uint8Array(length);249 for (var i = 0; i < length; ++i)250 lookupArray[i] = lookup.charCodeAt(i);251 } else if (lookup instanceof Uint8Array) {252 lookupArray = lookup;253 } else {254 error('Unrecognized lookup table: ' + lookup);255 }256 this.lookup = lookupArray;257 }258 IndexedCS.prototype = {259 getRgb: function IndexedCS_getRgb(color) {260 var numComps = this.base.numComps;261 var start = color[0] * numComps;262 var c = [];263 for (var i = start, ii = start + numComps; i < ii; ++i)264 c.push(this.lookup[i]);265 return this.base.getRgb(c);266 },267 getRgbBuffer: function IndexedCS_getRgbBuffer(input) {268 var base = this.base;269 var numComps = base.numComps;270 var lookup = this.lookup;271 var length = input.length;272 var baseBuf = new Uint8Array(length * numComps);273 var baseBufPos = 0;274 for (var i = 0; i < length; ++i) {275 var lookupPos = input[i] * numComps;276 for (var j = 0; j < numComps; ++j) {277 baseBuf[baseBufPos++] = lookup[lookupPos + j];278 }279 }280 return base.getRgbBuffer(baseBuf, 8);281 },282 isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {283 // indexed color maps shouldn't be changed284 return true;285 }286 };287 return IndexedCS;288})();289var DeviceGrayCS = (function DeviceGrayCSClosure() {290 function DeviceGrayCS() {291 this.name = 'DeviceGray';292 this.numComps = 1;293 this.defaultColor = [0];294 }295 DeviceGrayCS.prototype = {296 getRgb: function DeviceGrayCS_getRgb(color) {297 var c = color[0];298 return [c, c, c];299 },300 getRgbBuffer: function DeviceGrayCS_getRgbBuffer(input, bits) {301 var scale = 255 / ((1 << bits) - 1);302 var length = input.length;303 var rgbBuf = new Uint8Array(length * 3);304 for (var i = 0, j = 0; i < length; ++i) {305 var c = (scale * input[i]) | 0;306 rgbBuf[j++] = c;307 rgbBuf[j++] = c;308 rgbBuf[j++] = c;309 }310 return rgbBuf;311 },312 isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {313 return ColorSpace.isDefaultDecode(decodeMap, this.numComps);314 }315 };316 return DeviceGrayCS;317})();318var DeviceRgbCS = (function DeviceRgbCSClosure() {319 function DeviceRgbCS() {320 this.name = 'DeviceRGB';321 this.numComps = 3;322 this.defaultColor = [0, 0, 0];323 }324 DeviceRgbCS.prototype = {325 getRgb: function DeviceRgbCS_getRgb(color) {326 return color;327 },328 getRgbBuffer: function DeviceRgbCS_getRgbBuffer(input, bits) {329 if (bits == 8)330 return input;331 var scale = 255 / ((1 << bits) - 1);332 var i, length = input.length;333 var rgbBuf = new Uint8Array(length);...
Using AI Code Generation
1var wptb = require('wptb').wptb;2var deviceRgbCS = wptb.DeviceRgbCS();3var wptb = require('wptb').wptb;4var deviceGrayCS = wptb.DeviceGrayCS();5var wptb = require('wptb').wptb;6var deviceCmykCS = wptb.DeviceCmykCS();7var wptb = require('wptb').wptb;8var deviceNCS = wptb.DeviceNCS();9var wptb = require('wptb').wptb;10var indexedCS = wptb.IndexedCS();11var wptb = require('wptb').wptb;12var separationCS = wptb.SeparationCS();13var wptb = require('wptb').wptb;14var iccBasedCS = wptb.ICCBasedCS();15var wptb = require('wptb').wptb;16var patternCS = wptb.PatternCS();17var wptb = require('wptb').wptb;18var calGrayCS = wptb.CalGrayCS();19var wptb = require('wptb').wptb;20var calRGBCS = wptb.CalRGBCS();21var wptb = require('wptb').wptb;22var labCS = wptb.LabCS();23var wptb = require('wptb').wptb;24var deviceNCS = wptb.DeviceNCS();
Using AI Code Generation
1var wptools = require('wptools');2var fs = require('fs');3var path = require('path');4var DeviceRgbCS = wptools.DeviceRgbCS;5var deviceRgb = new DeviceRgbCS();6var rgb = deviceRgb.fromCmyk(0.5, 0.5, 0.5, 0.5);7console.log(rgb);8var rgb2 = deviceRgb.fromCmyk(0.5, 0.5, 0.5, 0.5, 0.5);9console.log(rgb2);10var rgb3 = deviceRgb.fromCmyk(0.5, 0.5, 0.5, 0.5, 0.5, 0.5);11console.log(rgb3);
Using AI Code Generation
1var DeviceRgbCS = wpt.DeviceRgbCS;2var rgb = new DeviceRgbCS(255, 0, 0);3var DeviceGrayCS = wpt.DeviceGrayCS;4var gray = new DeviceGrayCS(0.5);5var DeviceCmykCS = wpt.DeviceCmykCS;6var cmyk = new DeviceCmykCS(0, 1, 0, 0);7var PatternCS = wpt.PatternCS;8var pattern = new PatternCS();9var IndexedCS = wpt.IndexedCS;10var indexed = new IndexedCS(1, 1, [1, 1, 1]);11var SeparationCS = wpt.SeparationCS;12var separation = new SeparationCS("name", 1, 1, [1, 1, 1]);13var DeviceNCS = wpt.DeviceNCS;14var deviceN = new DeviceNCS("name", 1, 1, [1, 1, 1]);15var ICCBasedCS = wpt.ICCBasedCS;16var iccBased = new ICCBasedCS(1, 1, [1, 1, 1]);17var Shading = wpt.Shading;18var shading = new Shading();
Using AI Code Generation
1var wptools = require('wptools');2var deviceRgb = wptools.deviceRgbCS(0, 0, 0);3console.log(deviceRgb);4var wptools = require('wptools');5var deviceGray = wptools.deviceGrayCS();6console.log(deviceGray);7var wptools = require('wptools');8var deviceCmyk = wptools.deviceCmykCS(0, 0, 0, 0);9console.log(deviceCmyk);10var wptools = require('wptools');11var pattern = wptools.patternCS();12console.log(pattern);13var wptools = require('wptools');14var indexed = wptools.indexedCS(0, 0, 0);15console.log(indexed);16var wptools = require('wptools');17var separation = wptools.separationCS(0, 0, 0);18console.log(separation);19var wptools = require('wptools');20var deviceN = wptools.deviceNCS(0, 0, 0);21console.log(deviceN);22var wptools = require('wptools');23var iccBased = wptools.iccBasedCS(0, 0, 0);24console.log(iccBased);25var wptools = require('wptools');26var lab = wptools.labCS(0, 0, 0);27console.log(lab);28var wptools = require('wptools');29var calGray = wptools.calGrayCS(0,
Using AI Code Generation
1var cs = new DeviceRgbCS();2var rgb = cs.getRGB(0.5, 0.5, 0.5);3console.log(rgb);4var cs = new DeviceRgbCS();5var rgb = cs.getRGB(0.5, 0.5, 0.5);6console.log(rgb);7var cs = new DeviceRgbCS();8var rgb = cs.getRGB(0.5, 0.5, 0.5);9console.log(rgb);10var cs = new DeviceRgbCS();11var rgb = cs.getRGB(0.5, 0.5, 0.5);12console.log(rgb);13var cs = new DeviceRgbCS();14var rgb = cs.getRGB(0.5, 0.5, 0.5);15console.log(rgb);16var cs = new DeviceRgbCS();17var rgb = cs.getRGB(0.5, 0.5, 0.5);18console.log(rgb);19var cs = new DeviceRgbCS();20var rgb = cs.getRGB(0.5, 0.5, 0.5);21console.log(rgb);22var cs = new DeviceRgbCS();23var rgb = cs.getRGB(0.5, 0.5, 0.5);24console.log(rgb);25var cs = new DeviceRgbCS();26var rgb = cs.getRGB(0.5, 0.5, 0.5);27console.log(rgb);28var cs = new DeviceRgbCS();29var rgb = cs.getRGB(0.5, 0.5, 0.5);30console.log(rgb);
Using AI Code Generation
1var page = require('webpage').create(),2 system = require('system'),3 address, output, size;4var wpt = require('./wpt.js');5var test = wpt.DeviceRgbCS(page);6console.log('test: ' + test);7phantom.exit();
Using AI Code Generation
1var wptools = require('wptools');2var wp = new wptools('Wikipedia:WikiProject Color/Color articles by color');3wp.get(function(err, resp) {4 if (err) {5 console.log(err);6 } else {7 console.log(resp);8 }9});10### .get([opts], callback)11### .parse([opts], callback)12### .getSections([opts], callback)
Using AI Code Generation
1const wptools = require('wptools');2const fs = require('fs');3var options = {4}5var wpt = new wptools(options);6var rgb = wpt.DeviceRgbCS(0, 0, 0);7console.log(rgb);8var date = new Date();9var timestamp = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();10var date = new Date();11var timestamp = date.toISOString();12var date = new Date();13var timestamp = date.toUTCString();14var date = new Date();15var timestamp = date.toLocaleString();
Using AI Code Generation
1var driver = WptDriver();2var cs = DeviceRgbCS();3var device = Device(cs);4driver.setDevice(device);5driver.setPageSize(8.5, 11);6driver.setPageMargins(0.5, 0.5, 0.5, 0.5);7driver.setPageRotation(0);8driver.setPageUnits('inches');9driver.setPageMode('default');10driver.setPageLayout('default');11driver.setPageScaling(100);12driver.setPageFitWindow(false);13driver.setPageCenterWindow(false);14driver.setPageDisplayDocTitle(false);15driver.setPagePrintArea(false);16driver.setPagePrintClip(false);17driver.setPagePrintScaling(false);18driver.setPageDuplex(false);19driver.setPagePickTrayByPdfSize(false);20driver.setPageFirstPage(1);21driver.setPageLastPage(1);22driver.setPageCopies(1);23driver.setPageCollate(false);24driver.setPageReverse(false);25driver.setPageRotate(0);26driver.setPageScale(100);27driver.setPageZoom(100);28driver.setPageView('normal');29driver.setPageDisplayDocTitle(false);30driver.setPageDisplayBookmarks(false);
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!