How to use DeviceGrayCS method in wpt

Best JavaScript code snippet using wpt

colorspace.js

Source:colorspace.js Github

copy

Full Screen

...27 ColorSpace.fromIR = function ColorSpace_fromIR(IR) {28 var name = isArray(IR) ? IR[0] : IR;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) {...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var DeviceGrayCS = wptools.DeviceGrayCS;3var DeviceRGBCS = wptools.DeviceRGBCS;4var DeviceCMYKCS = wptools.DeviceCMYKCS;5var ICCBasedCS = wptools.ICCBasedCS;6var IndexedCS = wptools.IndexedCS;7var PatternCS = wptools.PatternCS;8var SeparationCS = wptools.SeparationCS;9var LabCS = wptools.LabCS;10var ICCBasedCS = wptools.ICCBasedCS;11var DeviceNCS = wptools.DeviceNCS;12var CalGrayCS = wptools.CalGrayCS;13var CalRGBCS = wptools.CalRGBCS;14var LabCS = wptools.LabCS;15var ICCBasedCS = wptools.ICCBasedCS;16var PatternCS = wptools.PatternCS;17var cs = new DeviceGrayCS();18var cs = new DeviceRGBCS();19var cs = new DeviceCMYKCS();20var cs = new ICCBasedCS();21var cs = new IndexedCS();22var cs = new PatternCS();23var cs = new SeparationCS();24var cs = new LabCS();25var cs = new ICCBasedCS();26var cs = new DeviceNCS();27var cs = new CalGrayCS();28var cs = new CalRGBCS();29var cs = new LabCS();30var cs = new ICCBasedCS();31var cs = new PatternCS();32##### new DeviceGrayCS()33##### DeviceGrayCS.prototype.getMode()34##### DeviceGrayCS.prototype.getDefColor()35##### DeviceGrayCS.prototype.getGray(color)36##### DeviceGrayCS.prototype.getRGB(color)37##### DeviceGrayCS.prototype.getCMYK(color)38##### DeviceGrayCS.prototype.getHSL(color)

Full Screen

Using AI Code Generation

copy

Full Screen

1wpt.DeviceGrayCS(0.5);2wpt.DeviceGrayCS(0.5, 0.5);3wpt.DeviceGrayCS(0.5, 0.5, 0.5);4wpt.DeviceGrayCS(0.5, 0.5, 0.5, 0.5);5wpt.DeviceRGBCS(0.5, 0.5, 0.5);6wpt.DeviceRGBCS(0.5, 0.5, 0.5, 0.5);7wpt.DeviceCMYKCS(0.5, 0.5, 0.5, 0.5);8wpt.DeviceCMYKCS(0.5, 0.5, 0.5, 0.5, 0.5);9wpt.PatternCS();10wpt.IndexedCS(0, 0, 0, 0, 0, 0);11wpt.IndexedCS(0, 0, 0, 0, 0, 0, 0);12wpt.SeparationCS(0, 0, 0, 0, 0, 0);13wpt.SeparationCS(0, 0, 0, 0, 0, 0, 0);14wpt.DeviceNCS(0, 0, 0, 0, 0, 0);15wpt.DeviceNCS(0, 0, 0, 0, 0, 0, 0);16wpt.ICCBasedCS(0, 0, 0, 0, 0, 0);17wpt.ICCBasedCS(0, 0, 0, 0, 0, 0, 0);18wpt.CalGrayCS(0, 0, 0, 0, 0, 0

Full Screen

Using AI Code Generation

copy

Full Screen

1var DeviceGrayCS = require('wptoolkit').DeviceGrayCS;2var c = new DeviceGrayCS();3console.log(c);4var DeviceRGBCS = require('wptoolkit').DeviceRGBCS;5var c = new DeviceRGBCS();6console.log(c);7var DeviceCMYKCS = require('wptoolkit').DeviceCMYKCS;8var c = new DeviceCMYKCS();9console.log(c);10var DeviceNCS = require('wptoolkit').DeviceNCS;11var c = new DeviceNCS();12console.log(c);13var PatternCS = require('wptoolkit').PatternCS;14var c = new PatternCS();15console.log(c);16var IndexedCS = require('wptoolkit').IndexedCS;17var c = new IndexedCS();18console.log(c);19var SeparationCS = require('wptoolkit').SeparationCS;20var c = new SeparationCS();21console.log(c);22var ICCBasedCS = require('wptoolkit').ICCBasedCS;23var c = new ICCBasedCS();24console.log(c);25var LabCS = require('wptoolkit').LabCS;26var c = new LabCS();27console.log(c);28var CalGrayCS = require('wptoolkit').CalGrayCS;29var c = new CalGrayCS();30console.log(c);31var CalRGBCS = require('wptoolkit').CalRGBCS;32var c = new CalRGBCS();33console.log(c);34var DeviceNCS = require('wptoolkit').DeviceNCS;35var c = new DeviceNCS();36console.log(c);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var doc = app.activeDocument;3var myPath = doc.pathItems.add();4myPath.setEntirePath([[100,100],[100,300],[300,300],[300,100]]);5var myGray = wpt.DeviceGrayCS();6myPath.fillColor = myGray;7myPath.strokeColor = myGray;8myPath.filled = true;9myPath.stroked = true;10var wpt = {};11wpt.DeviceGrayCS = function () {12 var desc = new ActionDescriptor();13 var ref = new ActionReference();14 ref.putClass(charIDToTypeID("Grsc"));15 desc.putReference(charIDToTypeID("null"), ref);16 executeAction(charIDToTypeID("Mk "), desc, DialogModes.NO);17 return app.foregroundColor;18}19wpt;20var wpt = {};21var wpt = wpt || {};22var doc = app.activeDocument;23var myPath = doc.pathItems.add();24myPath.setEntirePath([[100,100],[100,300],[300,300],[300,100]]);25var myCMYK = new CMYKColor();26myCMYK.cyan = 100;27myCMYK.magenta = 100;28myCMYK.yellow = 100;29myCMYK.black = 100;30myPath.fillColor = myCMYK;31myPath.strokeColor = myCMYK;32myPath.filled = true;33myPath.stroked = true;

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require("wptools");2var pdf = new wptools.Pdf("test.pdf");3var page = pdf.getPage(1);4var pageContents = page.getContents();5var newPageContents = pageContents.DeviceGrayCS();6page.setContents(newPageContents);7pdf.save("test.pdf");8var wptools = require("wptools");9var pdf = new wptools.Pdf("test.pdf");10var page = pdf.getPage(1);11var pageContents = page.getContents();12var newPageContents = pageContents.DeviceRGBCS();13page.setContents(newPageContents);14pdf.save("test.pdf");15var wptools = require("wptools");16var pdf = new wptools.Pdf("test.pdf");17var page = pdf.getPage(1);18var pageContents = page.getContents();19var newPageContents = pageContents.DeviceCMYKCS();20page.setContents(newPageContents);21pdf.save("test.pdf");22var wptools = require("wptools");23var pdf = new wptools.Pdf("test.pdf");24var page = pdf.getPage(1);25var pageContents = page.getContents();26var newPageContents = pageContents.CalGrayCS();27page.setContents(newPageContents);28pdf.save("test.pdf");29var wptools = require("wptools");30var pdf = new wptools.Pdf("test.pdf");31var page = pdf.getPage(1);32var pageContents = page.getContents();33var newPageContents = pageContents.CalRGBCS();34page.setContents(newPageContents);35pdf.save("test.pdf");36var wptools = require("wptools");37var pdf = new wptools.Pdf("test.pdf");38var page = pdf.getPage(1);39var pageContents = page.getContents();40var newPageContents = pageContents.LabCS();41page.setContents(newPageContents);42pdf.save("test.pdf");

Full Screen

Using AI Code Generation

copy

Full Screen

1var cs = wptb.DeviceGrayCS();2var cs = wptb.DeviceRGBCS();3var cs = wptb.DeviceCMYKCS();4var cs = wptb.CalGrayCS(0.3127, 0.329, 1.0, 0.0, 1.0);5var cs = wptb.CalRGBCS(0.3127, 0.329, 1.0, 0.0, 1.0, 0.64, 0.33, 0.3, 0.6, 0.15, 0.06);6var cs = wptb.LabCS(0.3127, 0.329, 1.0, 0.0, 1.0, 0.0, 100.0, -128.0, 127.0);7var cs = wptb.ICCBasedCS("test.icc");8var cs = wptb.IndexedCS(0, 255, wptb.DeviceRGBCS(), "test.icc");

Full Screen

Using AI Code Generation

copy

Full Screen

1var gState = wpt.getGraphicsState();2gState.setColorSpace(wpt.DeviceGrayCS);3wpt.setGraphicsState(gState);4wpt.drawRect(0,0,50,50);5var gState = wpt.getGraphicsState();6gState.setColorSpace(wpt.DeviceRGBCS);7wpt.setGraphicsState(gState);8wpt.drawRect(0,0,50,50);9var gState = wpt.getGraphicsState();10gState.setColorSpace(wpt.DeviceCMYKCS);11wpt.setGraphicsState(gState);12wpt.drawRect(0,0,50,50);13var gState = wpt.getGraphicsState();14gState.setColorSpace(wpt.DeviceNCS);15wpt.setGraphicsState(gState);16wpt.drawRect(0,0,50,50);17var gState = wpt.getGraphicsState();18gState.setColorSpace(wpt.CalGrayCS);19wpt.setGraphicsState(gState);20wpt.drawRect(0,0,50,50);21var gState = wpt.getGraphicsState();22gState.setColorSpace(wpt.CalRGBCS);23wpt.setGraphicsState(gState);24wpt.drawRect(0,0,50,50);25var gState = wpt.getGraphicsState();26gState.setColorSpace(wpt.Lab

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