void applyTexture(CPBrushDab dab, float textureAmount) {
		int amount = (int) (textureAmount * 255f);
		int offset = 0;
		for (int j = 0; j < dab.height; j++) {

			for (int i = 0; i < dab.width; i++) {
				int brushValue = (dab.brush[offset]) & 0xff;
				int textureX = (i + dab.x) % texture.width;
				if (textureX < 0) {
					textureX += texture.width;
				}

				int textureY = (j + dab.y) % texture.height;
				if (textureY < 0) {
					textureY += texture.height;
				}

				int textureValue = (texture.data[textureX + textureY * texture.width]) & 0xff;
				dab.brush[offset] = (byte) (brushValue * ((textureValue * amount / 255) ^ 0xff) / 255);
				offset++;
			}
		}
	}