// Class: openfl.display.BitmapData

var $global = typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this

$global.Object.defineProperty(exports, "__esModule", {value: true});

var __map_reserved = {};

// Imports

var $hxClasses = require("./../../hxClasses_stub").default;
var $import = require("./../../import_stub").default;
function openfl_display_IBitmapDrawable() {return require("./../../openfl/display/IBitmapDrawable");}
function lime_graphics_ImageChannel() {return require("./../../lime/graphics/ImageChannel");}
function openfl_geom_Matrix() {return require("./../../openfl/geom/Matrix");}
function lime_graphics_opengl_GL() {return require("./../../lime/graphics/opengl/GL");}
function openfl__$internal_renderer_opengl_GLRenderer() {return require("./../../openfl/_internal/renderer/opengl/GLRenderer");}
function js_Boot() {return require("./../../js/Boot");}
function openfl_geom_Rectangle() {return require("./../../openfl/geom/Rectangle");}
function lime_graphics_utils_ImageCanvasUtil() {return require("./../../lime/graphics/utils/ImageCanvasUtil");}
function openfl__$internal_renderer_RenderSession() {return require("./../../openfl/_internal/renderer/RenderSession");}
function lime_graphics_RendererType() {return require("./../../lime/graphics/RendererType");}
function openfl__$internal_renderer_canvas_CanvasMaskManager() {return require("./../../openfl/_internal/renderer/canvas/CanvasMaskManager");}
function openfl__$internal_renderer_canvas_CanvasBlendModeManager() {return require("./../../openfl/_internal/renderer/canvas/CanvasBlendModeManager");}
function openfl_utils_ByteArrayData() {return require("./../../openfl/utils/ByteArrayData");}
function Std() {return require("./../../Std");}
function openfl_display_PNGEncoderOptions() {return require("./../../openfl/display/PNGEncoderOptions");}
function openfl_utils__$ByteArray_ByteArray_$Impl_$() {return require("./../../openfl/utils/_ByteArray/ByteArray_Impl_");}
function openfl_display_JPEGEncoderOptions() {return require("./../../openfl/display/JPEGEncoderOptions");}
function lime_graphics_opengl__$WebGLContext_WebGLContext_$Impl_$() {return require("./../../lime/graphics/opengl/_WebGLContext/WebGLContext_Impl_");}
function lime_utils__$DataPointer_DataPointer_$Impl_$() {return require("./../../lime/utils/_DataPointer/DataPointer_Impl_");}
function lime_graphics_cairo__$CairoImageSurface_CairoImageSurface_$Impl_$() {return require("./../../lime/graphics/cairo/_CairoImageSurface/CairoImageSurface_Impl_");}
function lime_graphics_cairo__$CairoSurface_CairoSurface_$Impl_$() {return require("./../../lime/graphics/cairo/_CairoSurface/CairoSurface_Impl_");}
function lime_graphics_opengl_GLContextType() {return require("./../../lime/graphics/opengl/GLContextType");}
function lime_graphics_ImageType() {return require("./../../lime/graphics/ImageType");}
function openfl__$Vector_Vector_$Impl_$() {return require("./../../openfl/_Vector/Vector_Impl_");}
function openfl_display_Bitmap() {return require("./../../openfl/display/Bitmap");}
function openfl_geom_Point() {return require("./../../openfl/geom/Point");}
function openfl__$internal_utils_PerlinNoise() {return require("./../../openfl/_internal/utils/PerlinNoise");}
function _$UInt_UInt_$Impl_$() {return require("./../../_UInt/UInt_Impl_");}
function js__$Boot_HaxeError() {return require("./../../js/_Boot/HaxeError");}
function openfl_errors_Error() {return require("./../../openfl/errors/Error");}
function openfl_utils__$Endian_Endian_$Impl_$() {return require("./../../openfl/utils/_Endian/Endian_Impl_");}
function lime_graphics_Image() {return require("./../../lime/graphics/Image");}
function lime_app_Future() {return require("./../../lime/app/Future");}
function openfl__$internal_renderer_opengl_GLMaskManager() {return require("./../../openfl/_internal/renderer/opengl/GLMaskManager");}
function lime_math_Vector2() {return require("./../../lime/math/Vector2");}
function openfl_geom_ColorTransform() {return require("./../../openfl/geom/ColorTransform");}

// Constructor

var BitmapData = function(width,height,transparent,fillColor) {
	if(fillColor == null) {
		fillColor = -1;
	}
	if(transparent == null) {
		transparent = true;
	}
	this.transparent = transparent;
	if(width == null) {
		width = 0;
	} else {
		width = width;
	}
	if(height == null) {
		height = 0;
	} else {
		height = height;
	}
	if(width < 0) {
		width = 0;
	} else {
		width = width;
	}
	if(height < 0) {
		height = 0;
	} else {
		height = height;
	}
	this.width = width;
	this.height = height;
	this.rect = new (openfl_geom_Rectangle().default)(0,0,width,height);
	if(width > 0 && height > 0) {
		if(transparent) {
			if((fillColor & -16777216) == 0) {
				fillColor = 0;
			}
		} else {
			fillColor = -16777216 | fillColor & 16777215;
		}
		fillColor = fillColor << 8 | fillColor >>> 24 & 255;
		this.image = new (lime_graphics_Image().default)(null,0,0,width,height,fillColor);
		this.image.set_transparent(transparent);
		this.__isValid = true;
		this.readable = true;
	}
	this.__worldTransform = new (openfl_geom_Matrix().default)();
	this.__worldColorTransform = new (openfl_geom_ColorTransform().default)();
	this.__renderable = true;
}

// Meta

BitmapData.__name__ = ["openfl","display","BitmapData"];
BitmapData.__interfaces__ = [(openfl_display_IBitmapDrawable().default)];
BitmapData.prototype = {
	applyFilter: function(sourceBitmapData,sourceRect,destPoint,filter) {
		if(!this.readable || sourceBitmapData == null || !sourceBitmapData.readable) {
			return;
		}
		filter.__applyFilter(this,sourceBitmapData,sourceRect,destPoint);
	},
	clone: function() {
		if(!this.__isValid) {
			return new BitmapData(this.width,this.height,this.transparent,0);
		} else if(!this.readable && this.image == null) {
			var bitmapData = new BitmapData(0,0,this.transparent,0);
			bitmapData.width = this.width;
			bitmapData.height = this.height;
			bitmapData.rect.copyFrom(this.rect);
			bitmapData.__framebuffer = this.__framebuffer;
			bitmapData.__framebufferContext = this.__framebufferContext;
			bitmapData.__texture = this.__texture;
			bitmapData.__textureContext = this.__textureContext;
			bitmapData.__isValid = true;
			return bitmapData;
		} else {
			return BitmapData.fromImage(this.image.clone(),this.transparent);
		}
	},
	colorTransform: function(rect,colorTransform) {
		if(!this.readable) {
			return;
		}
		this.image.colorTransform(rect.__toLimeRectangle(),colorTransform.__toLimeColorMatrix());
	},
	compare: function(otherBitmapData) {
		if(otherBitmapData == this) {
			return 0;
		} else if(otherBitmapData == null) {
			return -1;
		} else if(this.readable == false || otherBitmapData.readable == false) {
			return -2;
		} else if(this.width != otherBitmapData.width) {
			return -3;
		} else if(this.height != otherBitmapData.height) {
			return -4;
		}
		if(this.image != null && otherBitmapData.image != null && this.image.get_format() == otherBitmapData.image.get_format()) {
			var bytes = this.image.get_data();
			var otherBytes = otherBitmapData.image.get_data();
			var equal = true;
			var _g1 = 0;
			var _g = bytes.length;
			while(_g1 < _g) {
				var i = _g1++;
				if(bytes[i] != otherBytes[i]) {
					equal = false;
					break;
				}
			}
			if(equal) {
				return 0;
			}
		}
		var bitmapData = null;
		var foundDifference;
		var pixel;
		var otherPixel;
		var comparePixel;
		var r;
		var g;
		var b;
		var a;
		var _g11 = 0;
		var _g2 = this.height;
		while(_g11 < _g2) {
			var y = _g11++;
			var _g3 = 0;
			var _g21 = this.width;
			while(_g3 < _g21) {
				var x = _g3++;
				foundDifference = false;
				pixel = this.getPixel32(x,y);
				otherPixel = otherBitmapData.getPixel32(x,y);
				comparePixel = 0;
				if(pixel != otherPixel) {
					r = (pixel >>> 16 & 255) - (otherPixel >>> 16 & 255);
					g = (pixel >>> 8 & 255) - (otherPixel >>> 8 & 255);
					b = (pixel & 255) - (otherPixel & 255);
					if(r < 0) {
						r *= -1;
					}
					if(g < 0) {
						g *= -1;
					}
					if(b < 0) {
						b *= -1;
					}
					if(r == 0 && g == 0 && b == 0) {
						a = (pixel >>> 24 & 255) - (otherPixel >>> 24 & 255);
						if(a != 0) {
							comparePixel = (comparePixel >>> 24 & 255 & 255) << 24 | 16711680 | (comparePixel >>> 8 & 255 & 255) << 8 | comparePixel & 255 & 255;
							comparePixel = (comparePixel >>> 24 & 255 & 255) << 24 | (comparePixel >>> 16 & 255 & 255) << 16 | 65280 | comparePixel & 255 & 255;
							comparePixel = (comparePixel >>> 24 & 255 & 255) << 24 | (comparePixel >>> 16 & 255 & 255) << 16 | (comparePixel >>> 8 & 255 & 255) << 8 | 255;
							comparePixel = (a & 255) << 24 | (comparePixel >>> 16 & 255 & 255) << 16 | (comparePixel >>> 8 & 255 & 255) << 8 | comparePixel & 255 & 255;
							foundDifference = true;
						}
					} else {
						comparePixel = (comparePixel >>> 24 & 255 & 255) << 24 | (r & 255) << 16 | (comparePixel >>> 8 & 255 & 255) << 8 | comparePixel & 255 & 255;
						comparePixel = (comparePixel >>> 24 & 255 & 255) << 24 | (comparePixel >>> 16 & 255 & 255) << 16 | (g & 255) << 8 | comparePixel & 255 & 255;
						comparePixel = (comparePixel >>> 24 & 255 & 255) << 24 | (comparePixel >>> 16 & 255 & 255) << 16 | (comparePixel >>> 8 & 255 & 255) << 8 | b & 255;
						comparePixel = -16777216 | (comparePixel >>> 16 & 255 & 255) << 16 | (comparePixel >>> 8 & 255 & 255) << 8 | comparePixel & 255 & 255;
						foundDifference = true;
					}
				}
				if(foundDifference) {
					if(bitmapData == null) {
						bitmapData = new BitmapData(this.width,this.height,this.transparent || otherBitmapData.transparent,0);
					}
					bitmapData.setPixel32(x,y,comparePixel);
				}
			}
		}
		if(bitmapData == null) {
			return 0;
		}
		return bitmapData;
	},
	copyChannel: function(sourceBitmapData,sourceRect,destPoint,sourceChannel,destChannel) {
		if(!this.readable) {
			return;
		}
		var sourceChannel1;
		switch(sourceChannel) {
		case 1:
			sourceChannel1 = (lime_graphics_ImageChannel().default).RED;
			break;
		case 2:
			sourceChannel1 = (lime_graphics_ImageChannel().default).GREEN;
			break;
		case 4:
			sourceChannel1 = (lime_graphics_ImageChannel().default).BLUE;
			break;
		case 8:
			sourceChannel1 = (lime_graphics_ImageChannel().default).ALPHA;
			break;
		default:
			return;
		}
		var destChannel1;
		switch(destChannel) {
		case 1:
			destChannel1 = (lime_graphics_ImageChannel().default).RED;
			break;
		case 2:
			destChannel1 = (lime_graphics_ImageChannel().default).GREEN;
			break;
		case 4:
			destChannel1 = (lime_graphics_ImageChannel().default).BLUE;
			break;
		case 8:
			destChannel1 = (lime_graphics_ImageChannel().default).ALPHA;
			break;
		default:
			return;
		}
		this.image.copyChannel(sourceBitmapData.image,sourceRect.__toLimeRectangle(),destPoint.__toLimeVector2(),sourceChannel1,destChannel1);
	},
	copyPixels: function(sourceBitmapData,sourceRect,destPoint,alphaBitmapData,alphaPoint,mergeAlpha) {
		if(mergeAlpha == null) {
			mergeAlpha = false;
		}
		if(!this.readable || sourceBitmapData == null) {
			return;
		}
		if(alphaPoint != null) {
			BitmapData.__tempVector.x = alphaPoint.x;
			BitmapData.__tempVector.y = alphaPoint.y;
		}
		this.image.copyPixels(sourceBitmapData.image,sourceRect.__toLimeRectangle(),destPoint.__toLimeVector2(),alphaBitmapData != null ? alphaBitmapData.image : null,alphaPoint != null ? BitmapData.__tempVector : null,mergeAlpha);
	},
	dispose: function() {
		this.image = null;
		this.width = 0;
		this.height = 0;
		this.rect = null;
		this.__isValid = false;
		this.readable = false;
		this.__surface = null;
		this.__buffer = null;
		this.__framebuffer = null;
		this.__framebufferContext = null;
		this.__texture = null;
		this.__textureContext = null;
	},
	disposeImage: function() {
		this.readable = false;
	},
	draw: function(source,matrix,colorTransform,blendMode,clipRect,smoothing) {
		if(smoothing == null) {
			smoothing = false;
		}
		if(matrix == null) {
			matrix = new (openfl_geom_Matrix().default)();
			if(source.__transform != null) {
				matrix.copyFrom(source.__transform);
				matrix.tx = 0;
				matrix.ty = 0;
			}
		}
		if(!this.readable) {
			if((lime_graphics_opengl_GL().default).context != null) {
				var gl = (lime_graphics_opengl_GL().default).context;
				gl.bindFramebuffer(gl.FRAMEBUFFER,this.__getFramebuffer(gl));
				gl.viewport(0,0,this.width,this.height);
				var renderer = new (openfl__$internal_renderer_opengl_GLRenderer().default)(null,gl,this);
				var renderSession = renderer.renderSession;
				renderSession.clearRenderDirty = false;
				renderSession.shaderManager = ((js_Boot().default).__cast(null , (openfl__$internal_renderer_opengl_GLRenderer().default))).renderSession.shaderManager;
				var matrixCache = source.__worldTransform;
				source.__updateTransforms(matrix);
				source.__updateChildren(false);
				source.__renderGL(renderer.renderSession);
				source.__updateTransforms(matrixCache);
				source.__updateChildren(true);
				gl.bindFramebuffer(gl.FRAMEBUFFER,null);
			}
		} else {
			if(colorTransform != null) {
				var bounds = (openfl_geom_Rectangle().default).__pool.get();
				var boundsMatrix = (openfl_geom_Matrix().default).__pool.get();
				source.__getBounds(bounds,boundsMatrix);
				var width = Math.ceil(bounds.width);
				var height = Math.ceil(bounds.height);
				var copy = new BitmapData(width,height,true,0);
				copy.draw(source);
				copy.colorTransform(copy.rect,colorTransform);
				source = copy;
				(openfl_geom_Rectangle().default).__pool.release(bounds);
				(openfl_geom_Matrix().default).__pool.release(boundsMatrix);
			}
			(lime_graphics_utils_ImageCanvasUtil().default).convertToCanvas(this.image);
			var buffer = this.image.buffer;
			var renderSession1 = new (openfl__$internal_renderer_RenderSession().default)();
			renderSession1.renderType = (lime_graphics_RendererType().default).CANVAS;
			renderSession1.clearRenderDirty = false;
			renderSession1.context = buffer.__srcContext;
			renderSession1.allowSmoothing = smoothing;
			renderSession1.maskManager = new (openfl__$internal_renderer_canvas_CanvasMaskManager().default)(renderSession1);
			renderSession1.blendModeManager = new (openfl__$internal_renderer_canvas_CanvasBlendModeManager().default)(renderSession1);
			renderSession1.blendModeManager.setBlendMode(blendMode);
			if(!smoothing) {
				buffer.__srcContext.mozImageSmoothingEnabled = false;
				buffer.__srcContext.msImageSmoothingEnabled = false;
				buffer.__srcContext.imageSmoothingEnabled = false;
			}
			if(clipRect != null) {
				renderSession1.maskManager.pushRect(clipRect,new (openfl_geom_Matrix().default)());
			}
			var matrixCache1 = source.__worldTransform;
			source.__updateTransforms(matrix);
			source.__updateChildren(false);
			source.__renderCanvas(renderSession1);
			source.__updateTransforms(matrixCache1);
			source.__updateChildren(true);
			if(!smoothing) {
				buffer.__srcContext.mozImageSmoothingEnabled = true;
				buffer.__srcContext.msImageSmoothingEnabled = true;
				buffer.__srcContext.imageSmoothingEnabled = true;
			}
			if(clipRect != null) {
				renderSession1.maskManager.popRect();
			}
			buffer.__srcContext.setTransform(1,0,0,1,0,0);
			buffer.__srcImageData = null;
			buffer.data = null;
			this.image.dirty = true;
			this.image.version++;
		}
	},
	drawWithQuality: function(source,matrix,colorTransform,blendMode,clipRect,smoothing,quality) {
		if(smoothing == null) {
			smoothing = false;
		}
		this.draw(source,matrix,colorTransform,blendMode,clipRect,quality != "low" && smoothing);
	},
	encode: function(rect,compressor,byteArray) {
		if(!this.readable || rect == null) {
			byteArray = null;
			return byteArray;
		}
		if(byteArray == null) {
			var this1 = new (openfl_utils_ByteArrayData().default)(0);
			byteArray = this1;
		}
		var image = this.image;
		if(!rect.equals(this.rect)) {
			var matrix = (openfl_geom_Matrix().default).__pool.get();
			matrix.tx = Math.round(-rect.x);
			matrix.ty = Math.round(-rect.y);
			var bitmapData = new BitmapData(Math.ceil(rect.width),Math.ceil(rect.height),true,0);
			bitmapData.draw(this,matrix);
			image = bitmapData.image;
			(openfl_geom_Matrix().default).__pool.release(matrix);
		}
		if((Std().default)["is"](compressor,(openfl_display_PNGEncoderOptions().default))) {
			byteArray.writeBytes((openfl_utils__$ByteArray_ByteArray_$Impl_$().default).fromBytes(image.encode("png")));
			return byteArray;
		} else if((Std().default)["is"](compressor,(openfl_display_JPEGEncoderOptions().default))) {
			byteArray.writeBytes((openfl_utils__$ByteArray_ByteArray_$Impl_$().default).fromBytes(image.encode("jpg",((js_Boot().default).__cast(compressor , (openfl_display_JPEGEncoderOptions().default))).quality)));
			return byteArray;
		}
		byteArray = null;
		return byteArray;
	},
	fillRect: function(rect,color) {
		if(rect == null) {
			return;
		}
		if(this.transparent && (color & -16777216) == 0) {
			color = 0;
		}
		if(this.readable) {
			this.image.fillRect(rect.__toLimeRectangle(),color,1);
		} else if(this.__framebuffer != null) {
			var gl = (lime_graphics_opengl_GL().default).context;
			var color1 = color;
			var useScissor = !this.rect.equals(rect);
			gl.bindFramebuffer(gl.FRAMEBUFFER,this.__framebuffer);
			if(useScissor) {
				gl.enable(gl.SCISSOR_TEST);
				gl.scissor(Math.round(rect.x),Math.round(rect.y),Math.round(rect.width),Math.round(rect.height));
			}
			gl.clearColor((color1 >>> 16 & 255) / 255,(color1 >>> 8 & 255) / 255,(color1 & 255) / 255,(color1 >>> 24 & 255) / 255);
			gl.clear(gl.COLOR_BUFFER_BIT);
			if(useScissor) {
				gl.disable(gl.SCISSOR_TEST);
			}
			gl.bindFramebuffer(gl.FRAMEBUFFER,null);
		}
	},
	floodFill: function(x,y,color) {
		if(!this.readable) {
			return;
		}
		this.image.floodFill(x,y,color,1);
	},
	generateFilterRect: function(sourceRect,filter) {
		return sourceRect.clone();
	},
	getBuffer: function(gl,alpha,colorTransform) {
		if(this.__buffer == null || this.__bufferContext != gl) {
			var uvWidth = 1;
			var uvHeight = 1;
			var this1 = new Float32Array(104);
			this.__bufferData = this1;
			this.__bufferData[0] = this.width;
			this.__bufferData[1] = this.height;
			this.__bufferData[3] = uvWidth;
			this.__bufferData[4] = uvHeight;
			this.__bufferData[27] = this.height;
			this.__bufferData[30] = uvHeight;
			this.__bufferData[52] = this.width;
			this.__bufferData[55] = uvWidth;
			var _g = 0;
			while(_g < 4) {
				var i = _g++;
				this.__bufferData[26 * i + 5] = alpha;
				if(colorTransform != null) {
					this.__bufferData[26 * i + 6] = colorTransform.redMultiplier;
					this.__bufferData[26 * i + 11] = colorTransform.greenMultiplier;
					this.__bufferData[26 * i + 16] = colorTransform.blueMultiplier;
					this.__bufferData[26 * i + 21] = colorTransform.alphaMultiplier;
					this.__bufferData[26 * i + 22] = colorTransform.redOffset / 255;
					this.__bufferData[26 * i + 23] = colorTransform.greenOffset / 255;
					this.__bufferData[26 * i + 24] = colorTransform.blueOffset / 255;
					this.__bufferData[26 * i + 25] = colorTransform.alphaOffset / 255;
				} else {
					this.__bufferData[26 * i + 6] = 1;
					this.__bufferData[26 * i + 11] = 1;
					this.__bufferData[26 * i + 16] = 1;
					this.__bufferData[26 * i + 21] = 1;
				}
			}
			this.__bufferAlpha = alpha;
			this.__bufferColorTransform = colorTransform != null ? colorTransform.__clone() : null;
			this.__bufferContext = gl;
			this.__buffer = gl.createBuffer();
			gl.bindBuffer(gl.ARRAY_BUFFER,this.__buffer);
			(lime_graphics_opengl__$WebGLContext_WebGLContext_$Impl_$().default).bufferData(gl,gl.ARRAY_BUFFER,this.__bufferData,gl.STATIC_DRAW);
		} else {
			var dirty = false;
			if(this.__bufferAlpha != alpha) {
				dirty = true;
				var _g1 = 0;
				while(_g1 < 4) {
					var i1 = _g1++;
					this.__bufferData[26 * i1 + 5] = alpha;
				}
				this.__bufferAlpha = alpha;
			}
			if(this.__bufferColorTransform == null && colorTransform != null || this.__bufferColorTransform != null && !this.__bufferColorTransform.__equals(colorTransform)) {
				dirty = true;
				if(colorTransform != null) {
					if(this.__bufferColorTransform == null) {
						this.__bufferColorTransform = colorTransform.__clone();
					} else {
						this.__bufferColorTransform.__copyFrom(colorTransform);
					}
					var _g2 = 0;
					while(_g2 < 4) {
						var i2 = _g2++;
						this.__bufferData[26 * i2 + 6] = colorTransform.redMultiplier;
						this.__bufferData[26 * i2 + 11] = colorTransform.greenMultiplier;
						this.__bufferData[26 * i2 + 16] = colorTransform.blueMultiplier;
						this.__bufferData[26 * i2 + 21] = colorTransform.alphaMultiplier;
						this.__bufferData[26 * i2 + 22] = colorTransform.redOffset / 255;
						this.__bufferData[26 * i2 + 23] = colorTransform.greenOffset / 255;
						this.__bufferData[26 * i2 + 24] = colorTransform.blueOffset / 255;
						this.__bufferData[26 * i2 + 25] = colorTransform.alphaOffset / 255;
					}
				} else {
					var _g3 = 0;
					while(_g3 < 4) {
						var i3 = _g3++;
						this.__bufferData[26 * i3 + 6] = 1;
						this.__bufferData[26 * i3 + 11] = 1;
						this.__bufferData[26 * i3 + 16] = 1;
						this.__bufferData[26 * i3 + 21] = 1;
						this.__bufferData[26 * i3 + 22] = 0;
						this.__bufferData[26 * i3 + 23] = 0;
						this.__bufferData[26 * i3 + 24] = 0;
						this.__bufferData[26 * i3 + 25] = 0;
					}
				}
			}
			gl.bindBuffer(gl.ARRAY_BUFFER,this.__buffer);
			if(dirty) {
				gl.bufferData(gl.ARRAY_BUFFER,this.__bufferData.byteLength,(lime_utils__$DataPointer_DataPointer_$Impl_$().default).fromArrayBufferView(this.__bufferData),gl.STATIC_DRAW);
			}
		}
		return this.__buffer;
	},
	getColorBoundsRect: function(mask,color,findColor) {
		if(findColor == null) {
			findColor = true;
		}
		if(!this.readable) {
			return new (openfl_geom_Rectangle().default)(0,0,this.width,this.height);
		}
		if(!this.transparent || (mask >> 24 & 255) > 0) {
			var color1 = color;
			if((color1 >>> 24 & 255) == 0) {
				color1 = 0;
			}
		}
		var rect = this.image.getColorBoundsRect(mask,color,findColor,1);
		return new (openfl_geom_Rectangle().default)(rect.x,rect.y,rect.width,rect.height);
	},
	getPixel: function(x,y) {
		if(!this.readable) {
			return 0;
		}
		return this.image.getPixel(x,y,1);
	},
	getPixel32: function(x,y) {
		if(!this.readable) {
			return 0;
		}
		return this.image.getPixel32(x,y,1);
	},
	getPixels: function(rect) {
		if(!this.readable) {
			return null;
		}
		if(rect == null) {
			rect = this.rect;
		}
		var byteArray = (openfl_utils__$ByteArray_ByteArray_$Impl_$().default).fromBytes(this.image.getPixels(rect.__toLimeRectangle(),1));
		byteArray.set_endian("bigEndian");
		return byteArray;
	},
	getSurface: function() {
		if(!this.readable) {
			return null;
		}
		if(this.__surface == null) {
			this.__surface = (lime_graphics_cairo__$CairoImageSurface_CairoImageSurface_$Impl_$().default).fromImage(this.image);
		}
		return this.__surface;
	},
	getTexture: function(gl) {
		if(!this.__isValid) {
			return null;
		}
		if(this.__texture == null || this.__textureContext != gl) {
			this.__textureContext = gl;
			this.__texture = gl.createTexture();
			gl.bindTexture(gl.TEXTURE_2D,this.__texture);
			gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE);
			gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE);
			gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.NEAREST);
			gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.NEAREST);
			this.__textureVersion = -1;
		}
		(lime_graphics_utils_ImageCanvasUtil().default).sync(this.image,false);
		if(this.image != null && this.image.version != this.__textureVersion) {
			var internalFormat;
			var format;
			if(this.__surface != null) {
				(lime_graphics_cairo__$CairoSurface_CairoSurface_$Impl_$().default).flush(this.__surface);
			}
			if(this.image.buffer.bitsPerPixel == 1) {
				internalFormat = gl.ALPHA;
				format = gl.ALPHA;
			} else {
				if(BitmapData.__supportsBGRA == null) {
					BitmapData.__textureInternalFormat = gl.RGBA;
					var bgraExtension = null;
					if(bgraExtension != null) {
						BitmapData.__supportsBGRA = true;
						BitmapData.__textureFormat = bgraExtension.BGRA_EXT;
						if(gl.type == (lime_graphics_opengl_GLContextType().default).GLES) {
							BitmapData.__textureInternalFormat = bgraExtension.BGRA_EXT;
						}
					} else {
						BitmapData.__supportsBGRA = false;
						BitmapData.__textureFormat = gl.RGBA;
					}
				}
				internalFormat = BitmapData.__textureInternalFormat;
				format = BitmapData.__textureFormat;
			}
			gl.bindTexture(gl.TEXTURE_2D,this.__texture);
			var textureImage = this.image;
			if(textureImage.type != (lime_graphics_ImageType().default).DATA && !textureImage.get_premultiplied()) {
				gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL,1);
			} else if(!textureImage.get_premultiplied() && textureImage.get_transparent()) {
				gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL,1);
			}
			if(!BitmapData.__supportsBGRA && textureImage.get_format() != 0) {
				textureImage = textureImage.clone();
				textureImage.set_format(0);
			}
			if(textureImage.type == (lime_graphics_ImageType().default).DATA) {
				gl.texImage2D(gl.TEXTURE_2D,0,internalFormat,textureImage.buffer.width,textureImage.buffer.height,0,format,gl.UNSIGNED_BYTE,(lime_utils__$DataPointer_DataPointer_$Impl_$().default).fromArrayBufferView(textureImage.get_data()));
			} else {
				(lime_graphics_opengl__$WebGLContext_WebGLContext_$Impl_$().default).texImage2D(gl,gl.TEXTURE_2D,0,internalFormat,format,gl.UNSIGNED_BYTE,textureImage.get_src());
			}
			gl.bindTexture(gl.TEXTURE_2D,null);
			this.__textureVersion = this.image.version;
		}
		if(!this.readable && this.image != null) {
			this.__surface = null;
			this.image = null;
		}
		return this.__texture;
	},
	getVector: function(rect) {
		var pixels = this.getPixels(rect);
		var length = (Std().default)["int"]((openfl_utils__$ByteArray_ByteArray_$Impl_$().default).get_length(pixels) / 4);
		var result = (openfl__$Vector_Vector_$Impl_$().default)._new(length,true);
		var _g1 = 0;
		var _g = length;
		while(_g1 < _g) {
			var i = _g1++;
			result.set(i,pixels.readUnsignedInt());
		}
		return result;
	},
	histogram: function(hRect) {
		var rect = hRect != null ? hRect : new (openfl_geom_Rectangle().default)(0,0,this.width,this.height);
		var pixels = this.getPixels(rect);
		var _g = [];
		var _g1 = 0;
		while(_g1 < 4) {
			var i = _g1++;
			var _g2 = [];
			var _g3 = 0;
			while(_g3 < 256) {
				var j = _g3++;
				_g2.push(0);
			}
			_g.push(_g2);
		}
		var result = _g;
		var _g21 = 0;
		var _g11 = (openfl_utils__$ByteArray_ByteArray_$Impl_$().default).get_length(pixels);
		while(_g21 < _g11) {
			var i1 = _g21++;
			++result[i1 % 4][pixels.readUnsignedByte()];
		}
		return result;
	},
	hitTest: function(firstPoint,firstAlphaThreshold,secondObject,secondBitmapDataPoint,secondAlphaThreshold) {
		if(secondAlphaThreshold == null) {
			secondAlphaThreshold = 1;
		}
		if(!this.readable) {
			return false;
		}
		if((Std().default)["is"](secondObject,(openfl_display_Bitmap().default))) {
			secondObject = ((js_Boot().default).__cast(secondObject , (openfl_display_Bitmap().default))).__bitmapData;
		}
		if((Std().default)["is"](secondObject,(openfl_geom_Point().default))) {
			var secondPoint = secondObject;
			var x = (Std().default)["int"](secondPoint.x - firstPoint.x);
			var y = (Std().default)["int"](secondPoint.y - firstPoint.y);
			if(this.rect.contains(x,y)) {
				var pixel = this.getPixel32(x,y);
				if((pixel >> 24 & 255) > firstAlphaThreshold) {
					return true;
				}
			}
		} else if((Std().default)["is"](secondObject,BitmapData)) {
			var secondBitmapData = secondObject;
			var x1;
			var y1;
			if(secondBitmapDataPoint == null) {
				x1 = 0;
				y1 = 0;
			} else {
				x1 = (Std().default)["int"](secondBitmapDataPoint.x - firstPoint.x);
				y1 = (Std().default)["int"](secondBitmapDataPoint.y - firstPoint.y);
			}
			if(this.rect.contains(x1,y1)) {
				var hitRect = (openfl_geom_Rectangle().default).__pool.get();
				hitRect.setTo(x1,y1,Math.min(secondBitmapData.width,this.width - x1),Math.min(secondBitmapData.height,this.height - y1));
				var pixels = this.getPixels(hitRect);
				hitRect.offset(-x1,-y1);
				var testPixels = secondBitmapData.getPixels(hitRect);
				var length = (Std().default)["int"](hitRect.width * hitRect.height);
				var pixel1;
				var testPixel;
				(openfl_geom_Rectangle().default).__pool.release(hitRect);
				var _g1 = 0;
				var _g = length;
				while(_g1 < _g) {
					var i = _g1++;
					pixel1 = pixels.readUnsignedInt();
					testPixel = testPixels.readUnsignedInt();
					if((pixel1 >> 24 & 255) > firstAlphaThreshold && (testPixel >> 24 & 255) > secondAlphaThreshold) {
						return true;
					}
				}
				return false;
			}
		} else if((Std().default)["is"](secondObject,(openfl_geom_Rectangle().default))) {
			var secondRectangle = (openfl_geom_Rectangle().default).__pool.get();
			secondRectangle.copyFrom(secondObject);
			secondRectangle.offset(-firstPoint.x,-firstPoint.y);
			secondRectangle.__contract(0,0,this.width,this.height);
			if(secondRectangle.width > 0 && secondRectangle.height > 0) {
				var pixels1 = this.getPixels(secondRectangle);
				var length1 = (Std().default)["int"]((openfl_utils__$ByteArray_ByteArray_$Impl_$().default).get_length(pixels1) / 4);
				var pixel2;
				var _g11 = 0;
				var _g2 = length1;
				while(_g11 < _g2) {
					var i1 = _g11++;
					pixel2 = pixels1.readUnsignedInt();
					if((pixel2 >> 24 & 255) > firstAlphaThreshold) {
						(openfl_geom_Rectangle().default).__pool.release(secondRectangle);
						return true;
					}
				}
			}
			(openfl_geom_Rectangle().default).__pool.release(secondRectangle);
		}
		return false;
	},
	lock: function() {
	},
	merge: function(sourceBitmapData,sourceRect,destPoint,redMultiplier,greenMultiplier,blueMultiplier,alphaMultiplier) {
		if(!this.readable || sourceBitmapData == null || !sourceBitmapData.readable || sourceRect == null || destPoint == null) {
			return;
		}
		this.image.merge(sourceBitmapData.image,sourceRect.__toLimeRectangle(),destPoint.__toLimeVector2(),redMultiplier,greenMultiplier,blueMultiplier,alphaMultiplier);
	},
	noise: function(randomSeed,low,high,channelOptions,grayScale) {
		if(grayScale == null) {
			grayScale = false;
		}
		if(channelOptions == null) {
			channelOptions = 7;
		}
		if(high == null) {
			high = 255;
		}
		if(low == null) {
			low = 0;
		}
		if(!this.readable) {
			return;
		}
		var func = function() {
			randomSeed = randomSeed * 1103515245 + 12345;
			return (Std().default)["int"](Math.abs(randomSeed / 65536)) % 32768;
		};
		var rand = func;
		rand();
		var range = high - low;
		var this1 = new (openfl_utils_ByteArrayData().default)(0);
		var data = this1;
		var redChannel = (channelOptions & 1) == 1;
		var greenChannel = (channelOptions & 2) >> 1 == 1;
		var blueChannel = (channelOptions & 4) >> 2 == 1;
		var alphaChannel = (channelOptions & 8) >> 3 == 1;
		var _g1 = 0;
		var _g = this.height;
		while(_g1 < _g) {
			var y = _g1++;
			var _g3 = 0;
			var _g2 = this.width;
			while(_g3 < _g2) {
				var x = _g3++;
				var red = 0;
				var blue = 0;
				var green = 0;
				var alpha = 255;
				if(grayScale) {
					blue = low + rand() % range;
					green = blue;
					red = green;
					alpha = 255;
				} else {
					if(redChannel) {
						red = low + rand() % range;
					}
					if(greenChannel) {
						green = low + rand() % range;
					}
					if(blueChannel) {
						blue = low + rand() % range;
					}
					if(alphaChannel) {
						alpha = low + rand() % range;
					}
				}
				var rgb = alpha;
				rgb = (rgb << 8) + red;
				rgb = (rgb << 8) + green;
				rgb = (rgb << 8) + blue;
				this.setPixel32(x,y,rgb);
			}
		}
	},
	paletteMap: function(sourceBitmapData,sourceRect,destPoint,redArray,greenArray,blueArray,alphaArray) {
		var sw = (Std().default)["int"](sourceRect.width);
		var sh = (Std().default)["int"](sourceRect.height);
		var pixels = sourceBitmapData.getPixels(sourceRect);
		var pixelValue;
		var r;
		var g;
		var b;
		var a;
		var color;
		var _g1 = 0;
		var _g = sh * sw;
		while(_g1 < _g) {
			var i = _g1++;
			pixelValue = pixels.readUnsignedInt();
			if(alphaArray == null) {
				a = pixelValue & -16777216;
			} else {
				a = alphaArray[pixelValue >> 24 & 255];
			}
			if(redArray == null) {
				r = pixelValue & 16711680;
			} else {
				r = redArray[pixelValue >> 16 & 255];
			}
			if(greenArray == null) {
				g = pixelValue & 65280;
			} else {
				g = greenArray[pixelValue >> 8 & 255];
			}
			if(blueArray == null) {
				b = pixelValue & 255;
			} else {
				b = blueArray[pixelValue & 255];
			}
			color = a + r + g + b;
			pixels.position = i * 4;
			pixels.writeUnsignedInt(color);
		}
		pixels.position = 0;
		var destRect = (openfl_geom_Rectangle().default).__pool.get();
		destRect.setTo(destPoint.x,destPoint.y,sw,sh);
		this.setPixels(destRect,pixels);
		(openfl_geom_Rectangle().default).__pool.release(destRect);
	},
	perlinNoise: function(baseX,baseY,numOctaves,randomSeed,stitch,fractalNoise,channelOptions,grayScale,offsets) {
		if(grayScale == null) {
			grayScale = false;
		}
		if(channelOptions == null) {
			channelOptions = 7;
		}
		if(!this.readable) {
			return;
		}
		var noise = new (openfl__$internal_utils_PerlinNoise().default)(randomSeed,numOctaves,0.01);
		noise.fill(this,baseX,baseY,0);
	},
	scroll: function(x,y) {
		if(!this.readable) {
			return;
		}
		this.image.scroll(x,y);
	},
	setPixel: function(x,y,color) {
		if(!this.readable) {
			return;
		}
		this.image.setPixel(x,y,color,1);
	},
	setPixel32: function(x,y,color) {
		if(!this.readable) {
			return;
		}
		this.image.setPixel32(x,y,color,1);
	},
	setPixels: function(rect,byteArray) {
		if(!this.readable || rect == null) {
			return;
		}
		var length = rect.width * rect.height * 4;
		if((_$UInt_UInt_$Impl_$().default).toFloat(byteArray.get_bytesAvailable()) < length) {
			throw new (js__$Boot_HaxeError().default)(new (openfl_errors_Error().default)("End of file was encountered.",2030));
		}
		this.image.setPixels(rect.__toLimeRectangle(),(openfl_utils__$ByteArray_ByteArray_$Impl_$().default).toBytePointer(byteArray),1,(openfl_utils__$Endian_Endian_$Impl_$().default).toLimeEndian(byteArray.get_endian()));
	},
	setVector: function(rect,inputVector) {
		var this1 = new (openfl_utils_ByteArrayData().default)(0);
		var byteArray = this1;
		(openfl_utils__$ByteArray_ByteArray_$Impl_$().default).set_length(byteArray,inputVector.get_length() * 4);
		var _g = 0;
		while(_g < inputVector.get_length()) {
			var color = inputVector.get(_g);
			++_g;
			byteArray.writeUnsignedInt(color);
		}
		byteArray.position = 0;
		this.setPixels(rect,byteArray);
	},
	threshold: function(sourceBitmapData,sourceRect,destPoint,operation,threshold,color,mask,copySource) {
		if(copySource == null) {
			copySource = false;
		}
		if(mask == null) {
			mask = -1;
		}
		if(color == null) {
			color = 0;
		}
		if(sourceBitmapData == null || sourceRect == null || destPoint == null || sourceRect.x > sourceBitmapData.width || sourceRect.y > sourceBitmapData.height || destPoint.x > this.width || destPoint.y > this.height) {
			return 0;
		}
		return this.image.threshold(sourceBitmapData.image,sourceRect.__toLimeRectangle(),destPoint.__toLimeVector2(),operation,threshold,color,mask,copySource,1);
	},
	unlock: function(changeRect) {
	},
	__applyAlpha: function(alpha) {
		(lime_graphics_utils_ImageCanvasUtil().default).convertToCanvas(this.image);
		(lime_graphics_utils_ImageCanvasUtil().default).createImageData(this.image);
		var data = this.image.buffer.data;
		var _g1 = 0;
		var _g = (openfl_utils__$ByteArray_ByteArray_$Impl_$().default).get_length(alpha);
		while(_g1 < _g) {
			var i = _g1++;
			data[i * 4 + 3] = alpha.readUnsignedByte();
		}
		this.image.version++;
	},
	__draw: function(source,matrix,colorTransform,blendMode,clipRect,smoothing) {
		if(smoothing == null) {
			smoothing = false;
		}
		if(matrix == null) {
			matrix = new (openfl_geom_Matrix().default)();
			if(source.__transform != null) {
				matrix.copyFrom(source.__transform);
				matrix.tx = 0;
				matrix.ty = 0;
			}
		}
		if(!this.readable) {
			if((lime_graphics_opengl_GL().default).context != null) {
				var gl = (lime_graphics_opengl_GL().default).context;
				gl.bindFramebuffer(gl.FRAMEBUFFER,this.__getFramebuffer(gl));
				gl.viewport(0,0,this.width,this.height);
				var renderer = new (openfl__$internal_renderer_opengl_GLRenderer().default)(null,gl,this);
				var renderSession = renderer.renderSession;
				renderSession.clearRenderDirty = true;
				renderSession.shaderManager = ((js_Boot().default).__cast(null , (openfl__$internal_renderer_opengl_GLRenderer().default))).renderSession.shaderManager;
				var matrixCache = source.__worldTransform;
				source.__updateTransforms(matrix);
				source.__updateChildren(false);
				source.__renderGL(renderer.renderSession);
				source.__updateTransforms(matrixCache);
				source.__updateChildren(true);
				gl.bindFramebuffer(gl.FRAMEBUFFER,null);
			}
		} else {
			if(colorTransform != null) {
				var bounds = (openfl_geom_Rectangle().default).__pool.get();
				var boundsMatrix = (openfl_geom_Matrix().default).__pool.get();
				source.__getBounds(bounds,boundsMatrix);
				var width = Math.ceil(bounds.width);
				var height = Math.ceil(bounds.height);
				var copy = new BitmapData(width,height,true,0);
				copy.draw(source);
				copy.colorTransform(copy.rect,colorTransform);
				source = copy;
				(openfl_geom_Rectangle().default).__pool.release(bounds);
				(openfl_geom_Matrix().default).__pool.release(boundsMatrix);
			}
			(lime_graphics_utils_ImageCanvasUtil().default).convertToCanvas(this.image);
			var buffer = this.image.buffer;
			var renderSession1 = new (openfl__$internal_renderer_RenderSession().default)();
			renderSession1.renderType = (lime_graphics_RendererType().default).CANVAS;
			renderSession1.clearRenderDirty = true;
			renderSession1.context = buffer.__srcContext;
			renderSession1.allowSmoothing = smoothing;
			renderSession1.maskManager = new (openfl__$internal_renderer_canvas_CanvasMaskManager().default)(renderSession1);
			renderSession1.blendModeManager = new (openfl__$internal_renderer_canvas_CanvasBlendModeManager().default)(renderSession1);
			if(!smoothing) {
				buffer.__srcContext.mozImageSmoothingEnabled = false;
				buffer.__srcContext.msImageSmoothingEnabled = false;
				buffer.__srcContext.imageSmoothingEnabled = false;
			}
			if(clipRect != null) {
				renderSession1.maskManager.pushRect(clipRect,new (openfl_geom_Matrix().default)());
			}
			var matrixCache1 = source.__worldTransform;
			source.__updateTransforms(matrix);
			source.__updateChildren(false);
			var cacheRenderable = source.__renderable;
			if(source.__isMask) {
				source.__renderable = true;
			}
			var cacheAlpha = source.__worldAlpha;
			source.__worldAlpha = 1;
			source.__renderCanvas(renderSession1);
			source.__renderable = cacheRenderable;
			source.__worldAlpha = cacheAlpha;
			source.__updateTransforms(matrixCache1);
			source.__updateChildren(true);
			if(!smoothing) {
				buffer.__srcContext.mozImageSmoothingEnabled = true;
				buffer.__srcContext.msImageSmoothingEnabled = true;
				buffer.__srcContext.imageSmoothingEnabled = true;
			}
			if(clipRect != null) {
				renderSession1.maskManager.popRect();
			}
			buffer.__srcContext.setTransform(1,0,0,1,0,0);
			buffer.__srcImageData = null;
			buffer.data = null;
			this.image.dirty = true;
			this.image.version++;
		}
	},
	__fromBase64: function(base64,type) {
		var image = (lime_graphics_Image().default).fromBase64(base64,type);
		this.__fromImage(image);
	},
	__fromBytes: function(bytes,rawAlpha) {
		var image = (lime_graphics_Image().default).fromBytes((openfl_utils__$ByteArray_ByteArray_$Impl_$().default).toBytes(bytes));
		this.__fromImage(image);
		if(rawAlpha != null) {
			this.__applyAlpha(rawAlpha);
		}
	},
	__fromFile: function(path) {
		var image = (lime_graphics_Image().default).fromFile(path);
		this.__fromImage(image);
	},
	__fromImage: function(image) {
		if(image != null && image.buffer != null) {
			this.image = image;
			this.width = image.width;
			this.height = image.height;
			this.rect = new (openfl_geom_Rectangle().default)(0,0,image.width,image.height);
			this.readable = true;
			this.__isValid = true;
		}
	},
	__getBounds: function(rect,matrix) {
		var bounds = (openfl_geom_Rectangle().default).__pool.get();
		this.rect.__transform(bounds,matrix);
		rect.__expand(bounds.x,bounds.y,bounds.width,bounds.height);
		(openfl_geom_Rectangle().default).__pool.release(bounds);
	},
	__getFramebuffer: function(gl) {
		if(this.__framebuffer == null || this.__framebufferContext != gl) {
			this.getTexture(gl);
			this.__framebufferContext = gl;
			this.__framebuffer = gl.createFramebuffer();
			gl.bindFramebuffer(gl.FRAMEBUFFER,this.__framebuffer);
			gl.framebufferTexture2D(gl.FRAMEBUFFER,gl.COLOR_ATTACHMENT0,gl.TEXTURE_2D,this.__texture,0);
		}
		return this.__framebuffer;
	},
	__loadFromBase64: function(base64,type) {
		var _gthis = this;
		return (lime_graphics_Image().default).loadFromBase64(base64,type).then(function(image) {
			_gthis.__fromImage(image);
			return (lime_app_Future().default).withValue(_gthis);
		});
	},
	__loadFromBytes: function(bytes,rawAlpha) {
		var _gthis = this;
		return (lime_graphics_Image().default).loadFromBytes((openfl_utils__$ByteArray_ByteArray_$Impl_$().default).toBytes(bytes)).then(function(image) {
			_gthis.__fromImage(image);
			if(rawAlpha != null) {
				_gthis.__applyAlpha(rawAlpha);
			}
			return (lime_app_Future().default).withValue(_gthis);
		});
	},
	__loadFromFile: function(path) {
		var _gthis = this;
		return (lime_graphics_Image().default).loadFromFile(path).then(function(image) {
			_gthis.__fromImage(image);
			return (lime_app_Future().default).withValue(_gthis);
		});
	},
	__renderCairo: function(renderSession) {
	},
	__renderCairoMask: function(renderSession) {
	},
	__renderCanvas: function(renderSession) {
		if(!this.readable) {
			return;
		}
		if(this.image.type == (lime_graphics_ImageType().default).DATA) {
			(lime_graphics_utils_ImageCanvasUtil().default).convertToCanvas(this.image);
		}
		var context = renderSession.context;
		if(this.__worldTransform == null) {
			this.__worldTransform = new (openfl_geom_Matrix().default)();
		}
		context.globalAlpha = 1;
		var transform = this.__worldTransform;
		if(renderSession.roundPixels) {
			context.setTransform(transform.a,transform.b,transform.c,transform.d,(Std().default)["int"](transform.tx),(Std().default)["int"](transform.ty));
		} else {
			context.setTransform(transform.a,transform.b,transform.c,transform.d,transform.tx,transform.ty);
		}
		context.drawImage(this.image.get_src(),0,0);
	},
	__renderCanvasMask: function(renderSession) {
	},
	__renderGL: function(renderSession) {
		var renderer = renderSession.renderer;
		var gl = renderSession.gl;
		renderSession.blendModeManager.setBlendMode("normal");
		var shader = renderSession.shaderManager.defaultShader;
		shader.get_data().uImage0.input = this;
		var tmp = renderSession.allowSmoothing && renderSession.upscaled;
		shader.get_data().uImage0.smoothing = tmp;
		shader.get_data().uMatrix.value = renderer.getMatrix(this.__worldTransform);
		renderSession.shaderManager.setShader(shader);
		gl.bindBuffer(gl.ARRAY_BUFFER,this.getBuffer(gl,1,this.__worldColorTransform));
		gl.vertexAttribPointer(shader.get_data().aPosition.index,3,gl.FLOAT,false,24,(lime_utils__$DataPointer_DataPointer_$Impl_$().default).fromInt(0));
		gl.vertexAttribPointer(shader.get_data().aTexCoord.index,2,gl.FLOAT,false,24,(lime_utils__$DataPointer_DataPointer_$Impl_$().default).fromInt(12));
		gl.vertexAttribPointer(shader.get_data().aAlpha.index,1,gl.FLOAT,false,24,(lime_utils__$DataPointer_DataPointer_$Impl_$().default).fromInt(20));
		gl.drawArrays(gl.TRIANGLE_STRIP,0,4);
	},
	__renderGLMask: function(renderSession) {
		var renderer = renderSession.renderer;
		var gl = renderSession.gl;
		var shader = (openfl__$internal_renderer_opengl_GLMaskManager().default).maskShader;
		shader.get_data().uImage0.input = this;
		var tmp = renderSession.allowSmoothing && renderSession.upscaled;
		shader.get_data().uImage0.smoothing = tmp;
		shader.get_data().uMatrix.value = renderer.getMatrix(this.__worldTransform);
		renderSession.shaderManager.setShader(shader);
		gl.bindBuffer(gl.ARRAY_BUFFER,this.getBuffer(gl,1,this.__worldColorTransform));
		gl.vertexAttribPointer(shader.get_data().aPosition.index,3,gl.FLOAT,false,24,(lime_utils__$DataPointer_DataPointer_$Impl_$().default).fromInt(0));
		gl.vertexAttribPointer(shader.get_data().aTexCoord.index,2,gl.FLOAT,false,24,(lime_utils__$DataPointer_DataPointer_$Impl_$().default).fromInt(12));
		gl.drawArrays(gl.TRIANGLE_STRIP,0,4);
	},
	__resize: function(width,height) {
		this.width = width;
		this.height = height;
		this.rect.width = width;
		this.rect.height = height;
	},
	__sync: function() {
		(lime_graphics_utils_ImageCanvasUtil().default).sync(this.image,false);
	},
	__updateChildren: function(transformOnly) {
	},
	__updateMask: function(maskGraphics) {
	},
	__updateTransforms: function(overrideTransform) {
		if(overrideTransform == null) {
			this.__worldTransform.identity();
		} else {
			this.__worldTransform = overrideTransform;
		}
	}
};
BitmapData.prototype.__class__ = $hxClasses["openfl.display.BitmapData"] = BitmapData;

// Init



// Statics

BitmapData.fromBase64 = function(base64,type) {
	var bitmapData = new BitmapData(0,0,true,0);
	bitmapData.__fromBase64(base64,type);
	return bitmapData;
}
BitmapData.fromBytes = function(bytes,rawAlpha) {
	var bitmapData = new BitmapData(0,0,true,0);
	bitmapData.__fromBytes(bytes,rawAlpha);
	return bitmapData;
}
BitmapData.fromCanvas = function(canvas,transparent) {
	if(transparent == null) {
		transparent = true;
	}
	if(canvas == null) {
		return null;
	}
	var bitmapData = new BitmapData(0,0,transparent,0);
	bitmapData.__fromImage((lime_graphics_Image().default).fromCanvas(canvas));
	bitmapData.image.set_transparent(transparent);
	return bitmapData;
}
BitmapData.fromFile = function(path) {
	var bitmapData = new BitmapData(0,0,true,0);
	bitmapData.__fromFile(path);
	return bitmapData;
}
BitmapData.fromImage = function(image,transparent) {
	if(transparent == null) {
		transparent = true;
	}
	if(image == null || image.buffer == null) {
		return null;
	}
	var bitmapData = new BitmapData(0,0,transparent,0);
	bitmapData.__fromImage(image);
	bitmapData.image.set_transparent(transparent);
	return bitmapData;
}
BitmapData.fromTexture = function(texture) {
	if(texture == null) {
		return null;
	}
	var bitmapData = new BitmapData(texture.__width,texture.__height,true,0);
	bitmapData.readable = false;
	bitmapData.__texture = texture.__textureID;
	bitmapData.__textureContext = texture.__textureContext;
	bitmapData.image = null;
	return bitmapData;
}
BitmapData.loadFromBase64 = function(base64,type) {
	return (lime_graphics_Image().default).loadFromBase64(base64,type).then(function(image) {
		return (lime_app_Future().default).withValue(BitmapData.fromImage(image));
	});
}
BitmapData.loadFromBytes = function(bytes,rawAlpha) {
	return (lime_graphics_Image().default).loadFromBytes((openfl_utils__$ByteArray_ByteArray_$Impl_$().default).toBytes(bytes)).then(function(image) {
		var bitmapData = BitmapData.fromImage(image);
		if(rawAlpha != null) {
			bitmapData.__applyAlpha(rawAlpha);
		}
		return (lime_app_Future().default).withValue(bitmapData);
	});
}
BitmapData.loadFromFile = function(path) {
	return (lime_graphics_Image().default).loadFromFile(path).then(function(image) {
		return (lime_app_Future().default).withValue(BitmapData.fromImage(image));
	});
}
BitmapData.__bufferStride = 26
BitmapData.__supportsBGRA = null
BitmapData.__tempVector = new (lime_math_Vector2().default)()

// Export

exports.default = BitmapData;