Texture LUT *****************************************
181548
function LGraphTextureLUT() {
            this.addInput("Texture", "Texture");
            this.addInput("LUT", "Texture");
            this.addInput("Intensity", "number");
            this.addOutput("", "Texture");
            this.properties = {
                intensity: 1,
                precision: LGraphTexture.DEFAULT,
                texture: null
            };

            if (!LGraphTextureLUT._shader) {
                LGraphTextureLUT._shader = new GL.Shader(
                    Shader.SCREEN_VERTEX_SHADER,
                    LGraphTextureLUT.pixel_shader
                );
            }
        }
112909
function resizeTexture(texture, width, height) {
  const oldWidth = texture.width;
  const oldHeight = texture.height;
  const oldPixels = readPixelsToBuffer(texture, {});

  texture.resize({width, height});

  texture.setSubImageData({
    data: oldPixels,
    x: 0,
    y: height - oldHeight,
    width: oldWidth,
    height: oldHeight,
    parameters: DEFAULT_TEXTURE_PARAMETERS
  });

  texture.generateMipmap();

  oldPixels.delete();
  return texture;
}
1034319
def draw_texture(tex):
    
    from .program import Program
    program = Program(vert_draw, frag_draw)
    program['u_texture'] = tex
    program['a_position'] = [[-1., -1.], [-1., 1.], [1., -1.], [1., 1.]]
    program['a_texcoord'] = [[0., 1.], [0., 0.], [1., 1.], [1., 0.]]
    program.draw('triangle_strip')
1062811
function LGraphTextureOperation() {
            this.addInput("Texture", "Texture");
            this.addInput("TextureB", "Texture");
            this.addInput("value", "number");
            this.addOutput("Texture", "Texture");
            this.help =
                "<p>pixelcode must be vec3</p>\
			<p>uvcode must be vec2, is optional</p>\
			<p><strong>uv:</strong> tex. coords</p><p><strong>color:</strong> texture</p><p><strong>colorB:</strong> textureB</p><p><strong>time:</strong> scene time</p><p><strong>value:</strong> input value</p><p>For multiline you must type: result = ...</p>";

            this.properties = {
                value: 1,
                uvcode: "",
                pixelcode: "color + colorB * value",
                precision: LGraphTexture.DEFAULT
            };

			this.has_error = false;
        }
303615
function addCap (coord, v, normal, type, isBeginning, context) {
    var neg_normal = Vector.neg(normal);
    var has_texcoord = (context.texcoord_index != null);

    switch (type){
    case CAP_TYPE.square:
        var tangent;
        // first vertex on the lineString
        if (isBeginning){
            tangent = [normal[1], -normal[0]];

            addVertex(coord, Vector.add(normal, tangent), normal, 1, v, context, 1);
            addVertex(coord, Vector.add(neg_normal, tangent), normal, 0, v, context, 1);

            if (has_texcoord) {
                // Add length of square cap to texture coordinate
                v += 0.5 * context.texcoord_width * context.v_scale;
            }

            addVertex(coord, normal, normal, 1, v, context, 1);
            addVertex(coord, neg_normal, normal, 0, v, context, 1);

        }
        // last vertex on the lineString
        else {
            tangent = [-normal[1], normal[0]];

            addVertex(coord, normal, normal, 1, v, context, 1);
            addVertex(coord, neg_normal, normal, 0, v, context, 1);

            if (has_texcoord) {
                // Add length of square cap to texture coordinate
                v += 0.5 * context.texcoord_width * context.v_scale;
            }

            addVertex(coord, Vector.add(normal, tangent), normal, 1, v, context, 1);
            addVertex(coord, Vector.add(neg_normal, tangent), normal, 0, v, context, 1);
        }

        indexPairs(1, context);
        break;
    case CAP_TYPE.round:
        // default for end cap, beginning cap will overwrite below (this way we're always passing a non-null value,
        // even if texture coords are disabled)
        var uvA = zero_v, uvB = one_v, uvC = mid_v;
        var nA, nB;

        // first vertex on the lineString
        if (isBeginning) {
            nA = normal;
            nB = neg_normal;

            if (has_texcoord){
                v += 0.5 * context.texcoord_width * context.v_scale;
                uvA = one_v, uvB = zero_v, uvC = mid_v; // update cap UV order
            }
        }
        // last vertex on the lineString - flip the direction of the cap
        else {
            nA = neg_normal;
            nB = normal;
        }

        if (has_texcoord) {
            zero_v[1] = v, one_v[1] = v, mid_v[1] = v; // update cap UV values
        }

        addFan(coord,
            nA, zero_vec2, nB,  // extrusion normal
            normal,             // line normal, for offsets
            uvA, uvC, uvB,      // texture coords (ignored if disabled)
            true, false, context
        );

        break;
    case CAP_TYPE.butt:
        return;
    }
}
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()
            };
        }
1079355
function() {
        var heightSegments = this.heightSegments;
        var widthSegments = this.widthSegments;

        var positionAttr = this.attributes.position;
        var texcoordAttr = this.attributes.texcoord0;
        var normalAttr = this.attributes.normal;

        var vertexCount = (widthSegments + 1) * (heightSegments + 1);
        positionAttr.init(vertexCount);
        texcoordAttr.init(vertexCount);
        normalAttr.init(vertexCount);

        var IndicesCtor = vertexCount > 0xffff ? Uint32Array : Uint16Array;
        var indices = this.indices = new IndicesCtor(widthSegments * heightSegments * 6);

        var x, y, z,
            u, v,
            i, j;

        var radius = this.radius;
        var phiStart = this.phiStart;
        var phiLength = this.phiLength;
        var thetaStart = this.thetaStart;
        var thetaLength = this.thetaLength;
        var radius = this.radius;

        var pos = [];
        var uv = [];
        var offset = 0;
        var divider = 1 / radius;
        for (j = 0; j <= heightSegments; j ++) {
            for (i = 0; i <= widthSegments; i ++) {
                u = i / widthSegments;
                v = j / heightSegments;

                // X axis is inverted so texture can be mapped from left to right
                x = -radius * Math.cos(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
                y = radius * Math.cos(thetaStart + v * thetaLength);
                z = radius * Math.sin(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);

                pos[0] = x; pos[1] = y; pos[2] = z;
                uv[0] = u; uv[1] = v;
                positionAttr.set(offset, pos);
                texcoordAttr.set(offset, uv);
                pos[0] *= divider;
                pos[1] *= divider;
                pos[2] *= divider;
                normalAttr.set(offset, pos);
                offset++;
            }
        }

        var i1, i2, i3, i4;

        var len = widthSegments + 1;

        var n = 0;
        for (j = 0; j < heightSegments; j ++) {
            for (i = 0; i < widthSegments; i ++) {
                i2 = j * len + i;
                i1 = (j * len + i + 1);
                i4 = (j + 1) * len + i + 1;
                i3 = (j + 1) * len + i;

                indices[n++] = i1;
                indices[n++] = i2;
                indices[n++] = i4;

                indices[n++] = i2;
                indices[n++] = i3;
                indices[n++] = i4;
            }
        }

        this.boundingBox = new BoundingBox();
        this.boundingBox.max.set(radius, radius, radius);
        this.boundingBox.min.set(-radius, -radius, -radius);
    }
855283
def fit_texture(layer):
    
    x, y = layer
    x = (x - np.nanmin(x)) / (np.nanmax(x) - np.nanmin(x))
    y = (y - np.nanmin(y)) / (np.nanmax(y) - np.nanmin(y))
    return x, y
1044047
function LGraphTextureWarp() {
            this.addInput("in", "Texture");
            this.addInput("warp", "Texture");
            this.addInput("factor", "number");
            this.addOutput("out", "Texture");
            this.properties = {
                factor: 0.01,
                precision: LGraphTexture.DEFAULT
            };
        }
1032557
public Color getColor(int x, int y) {
	    
		if (pixelData == null) {
			pixelData = texture.getTextureData();
		}
		
		
		int xo = (int) (textureOffsetX * texture.getTextureWidth());
		int yo = (int) (textureOffsetY * texture.getTextureHeight());
		
		if (textureWidth < 0) {
			x = xo - x;
		} else {
			x = xo + x;
		} 
		
		if (textureHeight < 0) {
			y = yo - y;
		} else {
			y = yo + y;
		}
		
		// Clamp to texture dimensions
		x %= texture.getTextureWidth();
		y %= texture.getTextureHeight();

		int offset = x + (y * texture.getTextureWidth());
		offset *= texture.hasAlpha() ? 4 : 3;
		
		if (texture.hasAlpha()) {
			return new Color(translate(pixelData[offset]),translate(pixelData[offset+1]),
							 translate(pixelData[offset+2]),translate(pixelData[offset+3]));
		} else {
			return new Color(translate(pixelData[offset]),translate(pixelData[offset+1]),
					 	     translate(pixelData[offset+2]));
		}
	}
1366570
function() {
		var gl = this.gl;

		var fragmentShaderSource = [
			"precision mediump float;",
			"uniform sampler2D bgTexture;",
			"uniform sampler2D spriteTexture;",
			"uniform sampler2D prioTexture;",
			"uniform sampler2D paletteTexture;",
			"uniform vec4 bgColor;",
			"varying vec2 texCoord;",

			"void main(void) {",
				"float bgIndex = texture2D(bgTexture, texCoord).r;",
				"float spriteIndex = texture2D(spriteTexture, texCoord).r;",
				"float prioIndex = texture2D(prioTexture, texCoord).r;",
				"float colorIndex = ((spriteIndex > 0.0 && (prioIndex == 0.0 || bgIndex == 0.0)) ? spriteIndex : bgIndex);",
				"vec4 color = texture2D(paletteTexture, vec2( colorIndex * 4.0 + 0.0078, 0.5));", // 0.0078 == ( 0.5 * 3 / 192 ) === ( 0.5 * [RGB colors] / [palette width] )
				"if ( colorIndex > 0.0 ) {",
					"gl_FragColor = color;",
				"} else {",
					"gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);",
					"gl_FragColor = bgColor;",
				"}",
			"}"
		].join("\n");

		var vertexShaderSource = [
			"attribute vec2 vertCoord;",
			"varying vec2 texCoord;",

			"void main() {",
				"gl_Position = vec4(vertCoord, 0, 1);",
				"texCoord = vec2( 0.5 * ( vertCoord.x + 1.0 ), 0.5 * (1.0 - vertCoord.y));",
			"}"
		].join("");

		this.fragmentShader = compileShader( gl.FRAGMENT_SHADER, fragmentShaderSource );
		this.vertexShader = compileShader( gl.VERTEX_SHADER, vertexShaderSource );

		function compileShader( shaderType, shaderSource ) {
			var shader = gl.createShader( shaderType );
			gl.shaderSource( shader, shaderSource );
			gl.compileShader( shader );

			if ( !gl.getShaderParameter( shader, gl.COMPILE_STATUS ) ) {  
				throw ( "An error occurred compiling the shaders: " + gl.getShaderInfoLog( shader ) );
			}

			return shader;
		}
	}
1128938
function findTexture(item, queue)
{
    if (item._texture && item._texture instanceof Texture)
    {
        const texture = item._texture.baseTexture;

        if (queue.indexOf(texture) === -1)
        {
            queue.push(texture);
        }

        return true;
    }

    return false;
}
301745
public void fillRect(float x1, float y1, float width, float height) {
		predraw();
		TextureImpl.bindNone();
		currentColor.bind();

		GL.glBegin(SGL.GL_QUADS);
		GL.glVertex2f(x1, y1);
		GL.glVertex2f(x1 + width, y1);
		GL.glVertex2f(x1 + width, y1 + height);
		GL.glVertex2f(x1, y1 + height);
		GL.glEnd();
		postdraw();
	}
1366827
function( format, type, internal ){
    var t = new Texture( this.gl, format, type, internal );
    return this.attach( 0x8CE0, t );
  }
910855
@Override
	public void initSprite(int width, int height, int x, int y, boolean rotated)
	{
		if (width == 0 || height == 0)
		{
			//assume block atlas
			width = BLOCK_TEXTURE_WIDTH;
			height = BLOCK_TEXTURE_HEIGHT;
		}
		this.sheetWidth = width;
		this.sheetHeight = height;
		super.initSprite(width, height, x, y, rotated);
		for (TextureAtlasSprite dep : dependants)
		{
			if (dep instanceof Icon)
				((Icon) dep).initIcon(this, width, height, x, y, rotated);
			else
				dep.copyFrom(this);
		}
	}
1281658
public void texture(Shape shape, Image image, float scaleX, float scaleY) {
		texture(shape, image, scaleX, scaleY, false);
	}
439141
function() {
        var gl = this.context;
        gl.useProgram(this.shader);
        gl.bindBuffer(gl.ARRAY_BUFFER, this._attributeBuffer);
        var a,
            attributes = this.attributes;
        // Process every attribute
        for (var i = 0; i < attributes.length; i++) {
            a = attributes[i];
            gl.vertexAttribPointer(
                a.location,
                a.width,
                a.type,
                false,
                this.stride * a.bytes,
                a.offset * a.bytes
            );
        }

        // For now, special case the need for texture objects
        var t = this.texture_obj;
        if (t && t.unit === null) {
            this.layer.texture_manager.bindTexture(t);
        }

        this.index_pointer = 0;
    }