Best JavaScript code snippet using devicefarmer-stf
PixelFormat.js
Source:PixelFormat.js
1import PixelDatatype from "../Renderer/PixelDatatype.js";2import WebGLConstants from "./WebGLConstants.js";3/**4 * The format of a pixel, i.e., the number of components it has and what they represent.5 *6 * @enum {Number}7 */8var PixelFormat = {9 /**10 * A pixel format containing a depth value.11 *12 * @type {Number}13 * @constant14 */15 DEPTH_COMPONENT: WebGLConstants.DEPTH_COMPONENT,16 /**17 * A pixel format containing a depth and stencil value, most often used with {@link PixelDatatype.UNSIGNED_INT_24_8}.18 *19 * @type {Number}20 * @constant21 */22 DEPTH_STENCIL: WebGLConstants.DEPTH_STENCIL,23 /**24 * A pixel format containing an alpha channel.25 *26 * @type {Number}27 * @constant28 */29 ALPHA: WebGLConstants.ALPHA,30 /**31 * A pixel format containing red, green, and blue channels.32 *33 * @type {Number}34 * @constant35 */36 RGB: WebGLConstants.RGB,37 /**38 * A pixel format containing red, green, blue, and alpha channels.39 *40 * @type {Number}41 * @constant42 */43 RGBA: WebGLConstants.RGBA,44 /**45 * A pixel format containing a luminance (intensity) channel.46 *47 * @type {Number}48 * @constant49 */50 LUMINANCE: WebGLConstants.LUMINANCE,51 /**52 * A pixel format containing luminance (intensity) and alpha channels.53 *54 * @type {Number}55 * @constant56 */57 LUMINANCE_ALPHA: WebGLConstants.LUMINANCE_ALPHA,58 /**59 * A pixel format containing red, green, and blue channels that is DXT1 compressed.60 *61 * @type {Number}62 * @constant63 */64 RGB_DXT1: WebGLConstants.COMPRESSED_RGB_S3TC_DXT1_EXT,65 /**66 * A pixel format containing red, green, blue, and alpha channels that is DXT1 compressed.67 *68 * @type {Number}69 * @constant70 */71 RGBA_DXT1: WebGLConstants.COMPRESSED_RGBA_S3TC_DXT1_EXT,72 /**73 * A pixel format containing red, green, blue, and alpha channels that is DXT3 compressed.74 *75 * @type {Number}76 * @constant77 */78 RGBA_DXT3: WebGLConstants.COMPRESSED_RGBA_S3TC_DXT3_EXT,79 /**80 * A pixel format containing red, green, blue, and alpha channels that is DXT5 compressed.81 *82 * @type {Number}83 * @constant84 */85 RGBA_DXT5: WebGLConstants.COMPRESSED_RGBA_S3TC_DXT5_EXT,86 /**87 * A pixel format containing red, green, and blue channels that is PVR 4bpp compressed.88 *89 * @type {Number}90 * @constant91 */92 RGB_PVRTC_4BPPV1: WebGLConstants.COMPRESSED_RGB_PVRTC_4BPPV1_IMG,93 /**94 * A pixel format containing red, green, and blue channels that is PVR 2bpp compressed.95 *96 * @type {Number}97 * @constant98 */99 RGB_PVRTC_2BPPV1: WebGLConstants.COMPRESSED_RGB_PVRTC_2BPPV1_IMG,100 /**101 * A pixel format containing red, green, blue, and alpha channels that is PVR 4bpp compressed.102 *103 * @type {Number}104 * @constant105 */106 RGBA_PVRTC_4BPPV1: WebGLConstants.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,107 /**108 * A pixel format containing red, green, blue, and alpha channels that is PVR 2bpp compressed.109 *110 * @type {Number}111 * @constant112 */113 RGBA_PVRTC_2BPPV1: WebGLConstants.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG,114 /**115 * A pixel format containing red, green, and blue channels that is ETC1 compressed.116 *117 * @type {Number}118 * @constant119 */120 RGB_ETC1: WebGLConstants.COMPRESSED_RGB_ETC1_WEBGL,121};122/**123 * @private124 */125PixelFormat.componentsLength = function (pixelFormat) {126 switch (pixelFormat) {127 case PixelFormat.RGB:128 return 3;129 case PixelFormat.RGBA:130 return 4;131 case PixelFormat.LUMINANCE_ALPHA:132 return 2;133 case PixelFormat.ALPHA:134 case PixelFormat.LUMINANCE:135 return 1;136 default:137 return 1;138 }139};140/**141 * @private142 */143PixelFormat.validate = function (pixelFormat) {144 return (145 pixelFormat === PixelFormat.DEPTH_COMPONENT ||146 pixelFormat === PixelFormat.DEPTH_STENCIL ||147 pixelFormat === PixelFormat.ALPHA ||148 pixelFormat === PixelFormat.RGB ||149 pixelFormat === PixelFormat.RGBA ||150 pixelFormat === PixelFormat.LUMINANCE ||151 pixelFormat === PixelFormat.LUMINANCE_ALPHA ||152 pixelFormat === PixelFormat.RGB_DXT1 ||153 pixelFormat === PixelFormat.RGBA_DXT1 ||154 pixelFormat === PixelFormat.RGBA_DXT3 ||155 pixelFormat === PixelFormat.RGBA_DXT5 ||156 pixelFormat === PixelFormat.RGB_PVRTC_4BPPV1 ||157 pixelFormat === PixelFormat.RGB_PVRTC_2BPPV1 ||158 pixelFormat === PixelFormat.RGBA_PVRTC_4BPPV1 ||159 pixelFormat === PixelFormat.RGBA_PVRTC_2BPPV1 ||160 pixelFormat === PixelFormat.RGB_ETC1161 );162};163/**164 * @private165 */166PixelFormat.isColorFormat = function (pixelFormat) {167 return (168 pixelFormat === PixelFormat.ALPHA ||169 pixelFormat === PixelFormat.RGB ||170 pixelFormat === PixelFormat.RGBA ||171 pixelFormat === PixelFormat.LUMINANCE ||172 pixelFormat === PixelFormat.LUMINANCE_ALPHA173 );174};175/**176 * @private177 */178PixelFormat.isDepthFormat = function (pixelFormat) {179 return (180 pixelFormat === PixelFormat.DEPTH_COMPONENT ||181 pixelFormat === PixelFormat.DEPTH_STENCIL182 );183};184/**185 * @private186 */187PixelFormat.isCompressedFormat = function (pixelFormat) {188 return (189 pixelFormat === PixelFormat.RGB_DXT1 ||190 pixelFormat === PixelFormat.RGBA_DXT1 ||191 pixelFormat === PixelFormat.RGBA_DXT3 ||192 pixelFormat === PixelFormat.RGBA_DXT5 ||193 pixelFormat === PixelFormat.RGB_PVRTC_4BPPV1 ||194 pixelFormat === PixelFormat.RGB_PVRTC_2BPPV1 ||195 pixelFormat === PixelFormat.RGBA_PVRTC_4BPPV1 ||196 pixelFormat === PixelFormat.RGBA_PVRTC_2BPPV1 ||197 pixelFormat === PixelFormat.RGB_ETC1198 );199};200/**201 * @private202 */203PixelFormat.isDXTFormat = function (pixelFormat) {204 return (205 pixelFormat === PixelFormat.RGB_DXT1 ||206 pixelFormat === PixelFormat.RGBA_DXT1 ||207 pixelFormat === PixelFormat.RGBA_DXT3 ||208 pixelFormat === PixelFormat.RGBA_DXT5209 );210};211/**212 * @private213 */214PixelFormat.isPVRTCFormat = function (pixelFormat) {215 return (216 pixelFormat === PixelFormat.RGB_PVRTC_4BPPV1 ||217 pixelFormat === PixelFormat.RGB_PVRTC_2BPPV1 ||218 pixelFormat === PixelFormat.RGBA_PVRTC_4BPPV1 ||219 pixelFormat === PixelFormat.RGBA_PVRTC_2BPPV1220 );221};222/**223 * @private224 */225PixelFormat.isETC1Format = function (pixelFormat) {226 return pixelFormat === PixelFormat.RGB_ETC1;227};228/**229 * @private230 */231PixelFormat.compressedTextureSizeInBytes = function (232 pixelFormat,233 width,234 height235) {236 switch (pixelFormat) {237 case PixelFormat.RGB_DXT1:238 case PixelFormat.RGBA_DXT1:239 case PixelFormat.RGB_ETC1:240 return Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4) * 8;241 case PixelFormat.RGBA_DXT3:242 case PixelFormat.RGBA_DXT5:243 return Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4) * 16;244 case PixelFormat.RGB_PVRTC_4BPPV1:245 case PixelFormat.RGBA_PVRTC_4BPPV1:246 return Math.floor((Math.max(width, 8) * Math.max(height, 8) * 4 + 7) / 8);247 case PixelFormat.RGB_PVRTC_2BPPV1:248 case PixelFormat.RGBA_PVRTC_2BPPV1:249 return Math.floor(250 (Math.max(width, 16) * Math.max(height, 8) * 2 + 7) / 8251 );252 default:253 return 0;254 }255};256/**257 * @private258 */259PixelFormat.textureSizeInBytes = function (260 pixelFormat,261 pixelDatatype,262 width,263 height264) {265 var componentsLength = PixelFormat.componentsLength(pixelFormat);266 if (PixelDatatype.isPacked(pixelDatatype)) {267 componentsLength = 1;268 }269 return (270 componentsLength * PixelDatatype.sizeInBytes(pixelDatatype) * width * height271 );272};273/**274 * @private275 */276PixelFormat.alignmentInBytes = function (pixelFormat, pixelDatatype, width) {277 var mod =278 PixelFormat.textureSizeInBytes(pixelFormat, pixelDatatype, width, 1) % 4;279 return mod === 0 ? 4 : mod === 2 ? 2 : 1;280};281/**282 * @private283 */284PixelFormat.createTypedArray = function (285 pixelFormat,286 pixelDatatype,287 width,288 height289) {290 var constructor;291 var sizeInBytes = PixelDatatype.sizeInBytes(pixelDatatype);292 if (sizeInBytes === Uint8Array.BYTES_PER_ELEMENT) {293 constructor = Uint8Array;294 } else if (sizeInBytes === Uint16Array.BYTES_PER_ELEMENT) {295 constructor = Uint16Array;296 } else if (297 sizeInBytes === Float32Array.BYTES_PER_ELEMENT &&298 pixelDatatype === PixelDatatype.FLOAT299 ) {300 constructor = Float32Array;301 } else {302 constructor = Uint32Array;303 }304 var size = PixelFormat.componentsLength(pixelFormat) * width * height;305 return new constructor(size);306};307/**308 * @private309 */310PixelFormat.flipY = function (311 bufferView,312 pixelFormat,313 pixelDatatype,314 width,315 height316) {317 if (height === 1) {318 return bufferView;319 }320 var flipped = PixelFormat.createTypedArray(321 pixelFormat,322 pixelDatatype,323 width,324 height325 );326 var numberOfComponents = PixelFormat.componentsLength(pixelFormat);327 var textureWidth = width * numberOfComponents;328 for (var i = 0; i < height; ++i) {329 var row = i * width * numberOfComponents;330 var flippedRow = (height - i - 1) * width * numberOfComponents;331 for (var j = 0; j < textureWidth; ++j) {332 flipped[flippedRow + j] = bufferView[row + j];333 }334 }335 return flipped;336};337/**338 * @private339 */340PixelFormat.toInternalFormat = function (pixelFormat, pixelDatatype, context) {341 // WebGL 1 require internalFormat to be the same as PixelFormat342 if (!context.webgl2) {343 return pixelFormat;344 }345 // Convert pixelFormat to correct internalFormat for WebGL 2346 if (pixelFormat === PixelFormat.DEPTH_STENCIL) {347 return WebGLConstants.DEPTH24_STENCIL8;348 }349 if (pixelFormat === PixelFormat.DEPTH_COMPONENT) {350 if (pixelDatatype === PixelDatatype.UNSIGNED_SHORT) {351 return WebGLConstants.DEPTH_COMPONENT16;352 } else if (pixelDatatype === PixelDatatype.UNSIGNED_INT) {353 return WebGLConstants.DEPTH_COMPONENT24;354 }355 }356 if (pixelDatatype === PixelDatatype.FLOAT) {357 switch (pixelFormat) {358 case PixelFormat.RGBA:359 return WebGLConstants.RGBA32F;360 case PixelFormat.RGB:361 return WebGLConstants.RGB32F;362 case PixelFormat.RG:363 return WebGLConstants.RG32F;364 case PixelFormat.R:365 return WebGLConstants.R32F;366 }367 }368 if (pixelDatatype === PixelDatatype.HALF_FLOAT) {369 switch (pixelFormat) {370 case PixelFormat.RGBA:371 return WebGLConstants.RGBA16F;372 case PixelFormat.RGB:373 return WebGLConstants.RGB16F;374 case PixelFormat.RG:375 return WebGLConstants.RG16F;376 case PixelFormat.R:377 return WebGLConstants.R16F;378 }379 }380 return pixelFormat;381};...
Using AI Code Generation
1var adb = require('adbkit');2var client = adb.createClient();3var os = require('os');4var util = require('util');5client.listDevices()6.then(function(devices) {7 return Promise.all(devices.map(function(device) {8 return client.getProperties(device.id)9 .then(function(properties) {10 return client.pixelFormat(device.id)11 .then(adb.util.readAll)12 .then(function(output) {13 console.log('Device ID: ' + device.id);14 console.log('Device Name: ' + properties['ro.product.model']);15 console.log('Device Pixel Format: ' + output.toString());16 });17 });18 }));19})20.then(function() {21 console.log('Done.');22})23.catch(function(err) {24 console.error('Something went wrong:', err.stack);25});
Using AI Code Generation
1var stf = require('devicefarmer-stf');2var pixelFormat = new stf.PixelFormat();3pixelFormat.getPixelFormat(function(err, pixelFormat){4 if(err){5 console.log(err);6 }7 else{8 console.log(pixelFormat);9 }10});11 at Object. (/home/ankur/Desktop/test.js:6:9)12 at Module._compile (module.js:571:32)13 at Object.Module._extensions..js (module.js:580:10)14 at Module.load (module.js:503:32)15 at tryModuleLoad (module.js:466:12)16 at Function.Module._load (module.js:458:3)17 at Function.Module.runMain (module.js:605:10)18 at startup (bootstrap_node.js:158:16)
Using AI Code Generation
1var client = require('devicefarmer-stf-client');2var pixelFormat = client.PixelFormat;3var pixelFormatEnum = pixelFormat.PixelFormatEnum;4var pixelFormat = new pixelFormat.PixelFormat(pixelFormatEnum.RGBA_8888);5console.log(pixelFormat.getPixelFormat());6console.log(pixelFormat.getPixelFormatEnum());7console.log(pixelFormat.getPixelFormatName());8console.log(pixelFormat.getPixelFormatValue());9console.log(pixelFormat.isPixelFormatValid());10console.log(pixelFormat.isPixelFormatSupported());11console.log(pixelFormat.isPixelFormatSupported(pixelFormatEnum.RGBA_8888));12console.log(pixelFormat.isPixelFormatSupported(pixelFormatEnum.RGBX_8888));13console.log(pixelFormat.isPixelFormatSupported(pixelFormatEnum.RGB_888));14console.log(pixelFormat.isPixelFormatSupported(pixelFormatEnum.RGB_565));15console.log(pixelFormat.isPixelFormatSupported(pixelFormatEnum.RGB_555));16console.log(pixelFormat.isPixelFormatSupported(pixelFormatEnum.RGB_444));17console.log(pixelFormat.isPixelFormatSupported(pixelFormatEnum.BGR_565));18console.log(pixelFormat.isPixelFormatSupported(pixelFormatEnum.BGR_555));19console.log(pixelFormat.isPixelFormatSupported(pixelFormatEnum.BGR_444));20console.log(pixelFormat.isPixelFormatSupported(pixelFormatEnum.GRAY_8));21console.log(pixelFormat.isPixelFormatSupported(pixelFormatEnum.GRAY_4));22console.log(pixelFormat.isPixelFormatSupported(pixelFormatEnum.GRAY_2));23console.log(pixelFormat.isPixelFormatSupported(pixelFormatEnum.GRAY_1));24console.log(pixelFormat.isPixelFormatSupported(pixelFormatEnum.YUV_420_888));25console.log(pixelFormat.isPixelFormatSupported(pixelFormatEnum.YUV_422_888));26console.log(pixelFormat.isPixelFormatSupported(pixelFormatEnum.YUV_444_888));27console.log(pixelFormat.isPixelFormatSupported(pixelFormatEnum.YUV_420_888_NV21));28console.log(pixelFormat.isPixelFormatSupported(pixelFormatEnum.YUV_420_888_NV12));29console.log(pixelFormat.isPixelFormatSupported(pixelFormatEnum.YUV_422_888_NV16));30console.log(pixelFormat.isPixelFormatSupported(pixelFormatEnum.YUV_422_888_NV61));31console.log(pixelFormat.isPixelFormatSupported(pixelFormatEnum.YUV_422_888_NV21));32console.log(pixelFormat.isPixelFormatSupported(pixelFormatEnum.YUV_422_888_NV12));33console.log(pixelFormat.isPixelFormatSupported(pixelFormatEnum.YUV_444_888_NV24));34console.log(pixelFormat.isPixelFormatSupported(pixelFormatEnum.YUV_444_888_NV42));35console.log(pixelFormat.is
Using AI Code Generation
1var stf = require('devicefarmer-stf');2var pixelFormat = stf.pixelFormat;3var pixelFormatObj = new pixelFormat();4var pixelFormat = pixelFormatObj.getPixelFormat(1);5console.log(pixelFormat);6var stf = require('devicefarmer-stf');7var pixelFormat = stf.pixelFormat;8var pixelFormatObj = new pixelFormat();9var pixelFormat = pixelFormatObj.getPixelFormat(1);10console.log(pixelFormat);11var stf = require('devicefarmer-stf');12var pixelFormat = stf.pixelFormat;13var pixelFormatObj = new pixelFormat();14var pixelFormat = pixelFormatObj.getPixelFormat(1);15console.log(pixelFormat);16var stf = require('devicefarmer-stf');17var pixelFormat = stf.pixelFormat;18var pixelFormatObj = new pixelFormat();19var pixelFormat = pixelFormatObj.getPixelFormat(1);20console.log(pixelFormat);21var stf = require('devicefarmer-stf');22var pixelFormat = stf.pixelFormat;23var pixelFormatObj = new pixelFormat();24var pixelFormat = pixelFormatObj.getPixelFormat(1);25console.log(pixelFormat);26var stf = require('devicefarmer-stf');27var pixelFormat = stf.pixelFormat;28var pixelFormatObj = new pixelFormat();29var pixelFormat = pixelFormatObj.getPixelFormat(1);30console.log(pixelFormat);31var stf = require('devicefarmer-stf');32var pixelFormat = stf.pixelFormat;33var pixelFormatObj = new pixelFormat();34var pixelFormat = pixelFormatObj.getPixelFormat(1);35console.log(pixelFormat);36var stf = require('devicefarmer-stf');37var pixelFormat = stf.pixelFormat;
Using AI Code Generation
1var pixelFormat = require('devicefarmer-stf').PixelFormat;2var pixelFormatObj = new pixelFormat();3var pixelFormatValue = pixelFormatObj.getPixelFormat('rgb565');4console.log(pixelFormatValue);5var pixelFormat = require('devicefarmer-stf').PixelFormat;6var pixelFormatObj = new pixelFormat();7var pixelFormatValue = pixelFormatObj.getPixelFormat('rgb888');8console.log(pixelFormatValue);9var pixelFormat = require('devicefarmer-stf').PixelFormat;10var pixelFormatObj = new pixelFormat();11var pixelFormatValue = pixelFormatObj.getPixelFormat('bgr565');12console.log(pixelFormatValue);13var pixelFormat = require('devicefarmer-stf').PixelFormat;14var pixelFormatObj = new pixelFormat();15var pixelFormatValue = pixelFormatObj.getPixelFormat('bgr888');16console.log(pixelFormatValue);17var pixelFormat = require('devicefarmer-stf').PixelFormat;18var pixelFormatObj = new pixelFormat();19var pixelFormatValue = pixelFormatObj.getPixelFormat('rgba8888');20console.log(pixelFormatValue);21var pixelFormat = require('devicefarmer-stf').PixelFormat;22var pixelFormatObj = new pixelFormat();23var pixelFormatValue = pixelFormatObj.getPixelFormat('bgra8888');24console.log(pixelFormatValue);25var pixelFormat = require('devicefarmer-stf').PixelFormat;26var pixelFormatObj = new pixelFormat();27var pixelFormatValue = pixelFormatObj.getPixelFormat('rgbx8888');28console.log(pixelFormatValue);29var pixelFormat = require('devicefarmer-stf').PixelFormat;30var pixelFormatObj = new pixelFormat();31var pixelFormatValue = pixelFormatObj.getPixelFormat('bgrx8888');
Using AI Code Generation
1var deviceInterface = require('devicefarmer-stf-device-interface');2var device = new deviceInterface.Device();3var pixelFormat = device.getPixelFormat();4var deviceDb = require('stf-device-db');5var db = new deviceDb();6var pixelFormat = db.getPixelFormat();7var deviceControl = require('stf-device-control');8var control = new deviceControl();9var pixelFormat = control.getPixelFormat();10var device = require('stf-device');11var pixelFormat = device.getPixelFormat();12var triproxy = require('stf-triproxy');13var pixelFormat = triproxy.getPixelFormat();14var provider = require('stf-provider');15var pixelFormat = provider.getPixelFormat();16var pixelFormat = require('stf').getPixelFormat();17var cli = require('stf-cli');18var pixelFormat = cli.getPixelFormat();19var app = require('stf-app');20var pixelFormat = app.getPixelFormat();21var api = require('stf-api');22var pixelFormat = api.getPixelFormat();23var processor = require('stf-processor');24var pixelFormat = processor.getPixelFormat();25var util = require('stf-util');26var pixelFormat = util.getPixelFormat();27var vendor = require('stf-vendor');28var pixelFormat = vendor.getPixelFormat();29var socket = require('stf-socket');30var pixelFormat = socket.getPixelFormat();31var protocol = require('stf-socket-protocol');32var pixelFormat = protocol.getPixelFormat();33var wire = require('stf-socket-protocol
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!!