Returns the WebGL Context object of the given Canvas
@name getContextGL
@memberOf me.WebGLRenderer.prototype
@function
@param {Canvas} canvas
@param {Boolean} [transparent=true] use false to disable transparency
@return {WebGLRenderingContext}
779152
function getContextGL(canvas, transparent) {
         if (typeof canvas === "undefined" || canvas === null) {
           throw new Error("You must pass a canvas element in order to create " + "a GL context");
         }

         if (typeof transparent !== "boolean") {
           transparent = true;
         }

         var attr = {
           alpha: transparent,
           antialias: this.settings.antiAlias,
           depth: false,
           stencil: true,
           premultipliedAlpha: transparent,
           failIfMajorPerformanceCaveat: this.settings.failIfMajorPerformanceCaveat
         };
         var gl = canvas.getContext("webgl", attr) || canvas.getContext("experimental-webgl", attr);

         if (!gl) {
           throw new Error("A WebGL context could not be created.");
         }

         return gl;
       }
500609
function LGraphTextureGlow() {
            this.addInput("in", "Texture");
            this.addInput("dirt", "Texture");
            this.addOutput("out", "Texture");
            this.addOutput("glow", "Texture");
            this.properties = {
                enabled: true,
                intensity: 1,
                persistence: 0.99,
                iterations: 16,
                threshold: 0,
                scale: 1,
                dirt_factor: 0.5,
                precision: LGraphTexture.DEFAULT
            };
            this._textures = [];
            this._uniforms = {
                u_intensity: 1,
                u_texture: 0,
                u_glow_texture: 1,
                u_threshold: 0,
                u_texel_size: vec2.create()
            };
        }
64738
function() {

      // create a canvas element
      var canvas = document.createElement('canvas');

      // define a context var that will be used for browsers with canvas support
      var ctx;

      // try/catch for older browsers that don't support the canvas element
      try {

        // attempt to give ctx a 2d canvas context value
        ctx = canvas.getContext('2d');

      } catch (e) {

        // return empty string if canvas element not supported
        return "";
      }

      // https://www.browserleaks.com/canvas#how-does-it-work
      // Text with lowercase/uppercase/punctuation symbols
      var txt = 'ClientJS,org <canvas> 1.0';
      ctx.textBaseline = "top";
      // The most common type
      ctx.font = "14px 'Arial'";
      ctx.textBaseline = "alphabetic";
      ctx.fillStyle = "#f60";
      ctx.fillRect(125, 1, 62, 20);
      // Some tricks for color mixing to increase the difference in rendering
      ctx.fillStyle = "#069";
      ctx.fillText(txt, 2, 15);
      ctx.fillStyle = "rgba(102, 204, 0, 0.7)";
      ctx.fillText(txt, 4, 17);
      return canvas.toDataURL();
    }
308107
function() {
        var c = this._canvas;
        c.width = Crafty.viewport.width;
        c.height = Crafty.viewport.height;

        var gl = this.context;
        gl.viewportWidth = c.width;
        gl.viewportHeight = c.height;
    }
19959
function Graphics()
{
    Container.call(this);

    /**
     * The alpha value used when filling the Graphics object.
     *
     * @member {number}
     * @default 1
     */
    this.fillAlpha = 1;

    /**
     * The width (thickness) of any lines drawn.
     *
     * @member {number}
     * @default 0
     */
    this.lineWidth = 0;

    /**
     * The color of any lines drawn.
     *
     * @member {string}
     * @default 0
     */
    this.lineColor = 0;

    /**
     * Graphics data
     *
     * @member {GraphicsData[]}
     * @private
     */
    this.graphicsData = [];

    /**
     * The tint applied to the graphic shape. This is a hex value. Apply a value of 0xFFFFFF to reset the tint.
     *
     * @member {number}
     * @default 0xFFFFFF
     */
    this.tint = 0xFFFFFF;

    /**
     * The previous tint applied to the graphic shape. Used to compare to the current tint and check if theres change.
     *
     * @member {number}
     * @private
     * @default 0xFFFFFF
     */
    this._prevTint = 0xFFFFFF;

    /**
     * The blend mode to be applied to the graphic shape. Apply a value of blendModes.NORMAL to reset the blend mode.
     *
     * @member {number}
     * @default CONST.BLEND_MODES.NORMAL;
     */
    this.blendMode = CONST.BLEND_MODES.NORMAL;

    /**
     * Current path
     *
     * @member {GraphicsData}
     * @private
     */
    this.currentPath = null;

    /**
     * Array containing some WebGL-related properties used by the WebGL renderer.
     *
     * @member {object<number, object>}
     * @private
     */
    // TODO - _webgl should use a prototype object, not a random undocumented object...
    this._webGL = {};

    /**
     * Whether this shape is being used as a mask.
     *
     * @member {boolean}
     */
    this.isMask = false;

    /**
     * The bounds' padding used for bounds calculation.
     *
     * @member {number}
     */
    this.boundsPadding = 0;

    /**
     * A cache of the local bounds to prevent recalculation.
     *
     * @member {Rectangle}
     * @private
     */
    this._localBounds = new math.Rectangle(0,0,1,1);

    /**
     * Used to detect if the graphics object has changed. If this is set to true then the graphics
     * object will be recalculated.
     *
     * @member {boolean}
     * @private
     */
    this.dirty = true;

    /**
     * Used to detect if the WebGL graphics object has changed. If this is set to true then the
     * graphics object will be recalculated.
     *
     * @member {boolean}
     * @private
     */
    this.glDirty = false;

    this.boundsDirty = true;

    /**
     * Used to detect if the cached sprite object needs to be updated.
     *
     * @member {boolean}
     * @private
     */
    this.cachedSpriteDirty = false;
}
748451
function setAntiAlias(context, enable) {
         var canvas = context.canvas; // enable/disable antialis on the given Context2d object

         me.agent.setPrefixed("imageSmoothingEnabled", enable === true, context); // set antialias CSS property on the main canvas

         if (enable !== true) {
           // https://developer.mozilla.org/en-US/docs/Web/CSS/image-rendering
           canvas.style["image-rendering"] = "pixelated";
           canvas.style["image-rendering"] = "crisp-edges";
           canvas.style["image-rendering"] = "-moz-crisp-edges";
           canvas.style["image-rendering"] = "-o-crisp-edges";
           canvas.style["image-rendering"] = "-webkit-optimize-contrast";
           canvas.style.msInterpolationMode = "nearest-neighbor";
         } else {
           canvas.style["image-rendering"] = "auto";
         }
       }
353015
function getUniformBufferSetFunction( index, gl, context ){
  var unit = context.ublockIndex++;
  return function(){
    if( arguments.length === 1 ) {
      if( arguments[0] instanceof WebGLBuffer ){ // is buffer
        gl.uniformBlockBinding(this.program, index, unit);
        gl.bindBufferBase(gl.UNIFORM_BUFFER, unit, arguments[0] );
      } else {
        gl.uniformBlockBinding(this.program, index, arguments[0]);
      }
    }
    return index;
  };
}
1116220
function checkWebGlSupported() {
  var canvas = document.createElement('canvas');
  var gl = canvas.getContext && (canvas.getContext('webgl') ||
                                 canvas.getContext('experimental-webgl'));
  return !!gl;
}
673736
def selected_canvas_explayer(self):
        
        if self.lstCanvasExpLayers.selectedItems():
            item = self.lstCanvasExpLayers.currentItem()
        else:
            return None
        try:
            layer_id = item.data(Qt.UserRole)
        except (AttributeError, NameError):
            layer_id = None

        # noinspection PyArgumentList
        layer = QgsProject.instance().mapLayer(layer_id)
        return layer
1032938
function(width, height){
    var canvas = document.createElement("canvas");
    canvas.width = width;
    canvas.height = height;
    var context = canvas.getContext("2d");
    var imageData = context.getImageData(0, 0, width, height);
    var buffer = new ArrayBuffer(width*height*4);
    var buffer8 = new Uint8ClampedArray(buffer);
    var buffer32 = new Uint32Array(buffer);
    return {
      canvas: canvas,
      context: context,
      width: width,
      height: height,
      imageData: imageData,
      buffer8: buffer8,
      buffer32: buffer32};
  }
920249
function RenderContext() {
		this._aBuffer = [];
		var that = this;
		this.add = function() {
			that._aBuffer.push.apply(that._aBuffer, arguments);
		};
		this.addWithParam = function(s, o) {
			for (var n in o) {
				var reg = new RegExp("\{" + n + "\}","g");
				s = s.replace(reg,o[n]);
			}
			that.add(s);
		};
		this.toString = function() {
			return that._aBuffer.join("");
		};
	}
679000
function canvasFilters(canvas, settings) {
    settings = Object.assign({}, {
        smoothing   : false,  // Smoothing [true|fale]
        brightness  : 0,      // Image brightness [-255 to +255]
        contrast    : 0,      // Image contrast [-255 to +255]
        gamma       : 0,      // Image gamma correction [0.01 to 7.99]
        grayscale   : 'none', // Graysale algorithm [average, luma, luma-601, luma-709, luma-240, desaturation, decomposition-[min|max], [red|green|blue]-chanel]
        shadesOfGray: 256,    // Number of shades of gray [2-256]
        invertColor : false   // Invert color...
    }, settings || {})

    // Get canvas 2d context
    let context = canvas.getContext('2d')

    // Smoothing
    if (context.imageSmoothingEnabled !== undefined) {
        context.imageSmoothingEnabled = settings.smoothing
    }
    else {
        context.mozImageSmoothingEnabled    = settings.smoothing
        context.webkitImageSmoothingEnabled = settings.smoothing
        context.msImageSmoothingEnabled     = settings.smoothing
        context.oImageSmoothingEnabled      = settings.smoothing
    }

    // Get image data
    let imageData = context.getImageData(0, 0, canvas.width, canvas.height)
    let data      = imageData.data

    let contrastFactor, brightnessOffset, gammaCorrection, shadesOfGrayFactor

    if (settings.contrast !== 0) {
        contrastFactor = (259 * (settings.contrast + 255)) / (255 * (259 - settings.contrast))
    }

    if (settings.brightness !== 0) {
        brightnessOffset = settings.brightness
    }

    if (settings.gamma !== 0) {
        gammaCorrection = 1 / settings.gamma
    }

    // Shades of gray
    if (settings.shadesOfGray > 1 && settings.shadesOfGray < 256) {
        shadesOfGrayFactor = 255 / (settings.shadesOfGray - 1)
    }

    // For each pixel
    for (let i = 0, il = data.length; i < il; i += 4) {
        // Apply filters
        invertColor(data, i, settings.invertColor)
        brightness(data, i, brightnessOffset)
        contrast(data, i, contrastFactor)
        gamma(data, i, gammaCorrection)
        grayscale(data, i, settings.grayscale, shadesOfGrayFactor)
    }

    // Write new image data on the context
    context.putImageData(imageData, 0, 0)
}
632272
function getPixels(texture, opts) {
    var gl = texture.gl
    if (!gl)
        throw new Error("must provide gl-texture2d object with a valid 'gl' context")
    
    if (!fbo) {
        var handle = gl.createFramebuffer()
        fbo = {
            handle: handle,
            dispose: dispose,
            gl: gl
        }
    } 

    // make this the current frame buffer
    gl.bindFramebuffer(gl.FRAMEBUFFER, fbo.handle)

    // attach the texture to the framebuffer.
    gl.framebufferTexture2D(
        gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0,
        gl.TEXTURE_2D, texture.handle, 0)

    // check if you can read from this type of texture.
    var status = gl.checkFramebufferStatus(gl.FRAMEBUFFER)
    if (status !== gl.FRAMEBUFFER_COMPLETE) 
        throw new Error("cannot read GL framebuffer: " + status)
    
    opts = opts||{}
    opts.x = opts.x|0
    opts.y = opts.y|0
    opts.width = typeof opts.width === 'number' ? opts.width : (texture.shape[0]|0)
    opts.height = typeof opts.height === 'number' ? opts.height : (texture.shape[1]|0)

    var array = new Uint8Array(opts.width * opts.height * 4)
    gl.readPixels(opts.x, opts.y, opts.width, opts.height, gl.RGBA, gl.UNSIGNED_BYTE, array)
    gl.bindFramebuffer(gl.FRAMEBUFFER, null)
    return array
}
1294108
function drawRenderLayer (ctx, layer) {
  var customDrawFunc;

  // Performance: avoid drawing hidden layers.
  if (typeof layer.alpha === 'number' && layer.alpha <= 0) {
    return;
  }

  switch (layer.type) {
    case 'image':
      customDrawFunc = drawImageRenderLayer;
      break;

    case 'text':
      customDrawFunc = drawTextRenderLayer;
      break;

    case 'gradient':
      customDrawFunc = drawGradientRenderLayer;
      break;
  }

  // Establish drawing context for certain properties:
  // - alpha
  // - translate
  var saveContext = (layer.alpha !== null && layer.alpha < 1) ||
                    (layer.translateX || layer.translateY);

  if (saveContext) {
    ctx.save();

    // Alpha:
    if (layer.alpha !== null && layer.alpha < 1) {
      ctx.globalAlpha = layer.alpha;
    }

    // Translation:
    if (layer.translateX || layer.translateY) {
      ctx.translate(layer.translateX || 0, layer.translateY || 0);
    }
  }

  // If the layer is bitmap-cacheable, draw in a pooled off-screen canvas.
  // We disable backing stores on pad since we flip there.
  if (layer.backingStoreId) {
    drawCacheableRenderLayer(ctx, layer, customDrawFunc);
  } else {
    // Draw default properties, such as background color.
    ctx.save();
    drawBaseRenderLayer(ctx, layer);

    // Draw custom properties if needed.
    customDrawFunc && customDrawFunc(ctx, layer);
    ctx.restore();

    // Draw child layers, sorted by their z-index.
    if (layer.children) {
      layer.children.slice().sort(sortByZIndexAscending).forEach(function (childLayer) {
        drawRenderLayer(ctx, childLayer);
      });
    }
  }

  // Pop the context state if we established a new drawing context.
  if (saveContext) {
    ctx.restore();
  }
}
1023941
function(context) {
    var maskedContext = this._maskContext(context);
    if ("production" !== process.env.NODE_ENV) {
      var Component = ReactNativeComponent.getComponentClassForElement(
        this._currentElement
      );
      if (Component.contextTypes) {
        this._checkPropTypes(
          Component.contextTypes,
          maskedContext,
          ReactPropTypeLocations.context
        );
      }
    }
    return maskedContext;
  }
785793
function() {
        var gl = this.context;
        gl.bindBuffer(gl.ARRAY_BUFFER, this._attributeBuffer);
        gl.bufferData(gl.ARRAY_BUFFER, this._attributeArray, gl.STATIC_DRAW);
        gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer);
        gl.bufferData(
            gl.ELEMENT_ARRAY_BUFFER,
            this._indexArray,
            gl.STATIC_DRAW
        );
        gl.drawElements(gl.TRIANGLES, this.index_pointer, gl.UNSIGNED_SHORT, 0);
    }
968992
function initWebGL() {

  var NAMES = ['webgl2', 'webgl', 'experimental-webgl2', 'experimental-webgl', 'webkit-3d', 'moz-webgl'];
  for (let i = 0; i < NAMES.length; i++) {
    try {
      let ctx = currCanvas.getContext(NAMES[i], {
        alpha: true,
        antialias: true,
        premultipliedAlpha: true,
        failIfMajorPerformanceCaveat: false,
      });
      if (ctx) currWebGL = ctx;
    } catch (e) { }
  }
  if (!currWebGL) {
    console.error('Live2D widgets: Failed to create WebGL context.');
    if (!window.WebGLRenderingContext) {
      console.error('Your browser may not support WebGL, check https://get.webgl.org/ for futher information.');
    }
    return;
  }
}