tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

tcuPixelFormat.js (2345B)


      1 /*-------------------------------------------------------------------------
      2 * drawElements Quality Program OpenGL ES Utilities
      3 * ------------------------------------------------
      4 *
      5 * Copyright 2014 The Android Open Source Project
      6 *
      7 * Licensed under the Apache License, Version 2.0 (the "License");
      8 * you may not use this file except in compliance with the License.
      9 * You may obtain a copy of the License at
     10 *
     11 *      http://www.apache.org/licenses/LICENSE-2.0
     12 *
     13 * Unless required by applicable law or agreed to in writing, software
     14 * distributed under the License is distributed on an "AS IS" BASIS,
     15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16 * See the License for the specific language governing permissions and
     17 * limitations under the License.
     18 *
     19 */
     20 
     21 'use strict';
     22 goog.provide('framework.common.tcuPixelFormat');
     23 
     24 goog.scope(function() {
     25 
     26 var tcuPixelFormat = framework.common.tcuPixelFormat;
     27 
     28 /**
     29 * @constructor
     30 * @param {number=} r
     31 * @param {number=} g
     32 * @param {number=} b
     33 * @param {number=} a
     34 */
     35 tcuPixelFormat.PixelFormat = function(r, g, b, a) {
     36    this.redBits = r || 0;
     37    this.greenBits = g || 0;
     38    this.blueBits = b || 0;
     39    this.alphaBits = a || 0;
     40 };
     41 
     42 /**
     43 * @param {WebGL2RenderingContext} context
     44 * @return {tcuPixelFormat.PixelFormat}
     45 */
     46 tcuPixelFormat.PixelFormatFromContext = function(context) {
     47    var r = /** @type {number} */ (context.getParameter(gl.RED_BITS));
     48    var g = /** @type {number} */ (context.getParameter(gl.GREEN_BITS));
     49    var b = /** @type {number} */ (context.getParameter(gl.BLUE_BITS));
     50    var a = /** @type {number} */ (context.getParameter(gl.ALPHA_BITS));
     51 
     52    return new tcuPixelFormat.PixelFormat(r, g, b, a);
     53 };
     54 
     55 /**
     56 * @param {number} r
     57 * @param {number} g
     58 * @param {number} b
     59 * @param {number} a
     60 * @return {boolean}
     61 */
     62 tcuPixelFormat.PixelFormat.prototype.equals = function(r, g, b, a) {
     63    return this.redBits === r &&
     64            this.greenBits === g &&
     65            this.blueBits === b &&
     66            this.alphaBits === a;
     67 };
     68 
     69 /**
     70 * @return {Array<number>}
     71 */
     72 tcuPixelFormat.PixelFormat.prototype.getColorThreshold = function() {
     73    return [1 << (8 - this.redBits),
     74            1 << (8 - this.greenBits),
     75            1 << (8 - this.blueBits),
     76            (this.alphaBits > 0) ? (1 << (8 - this.alphaBits)) : 0];
     77 };
     78 
     79 });