<commit_before>package openfl.display;


import lime.app.Future;
import lime.app.Promise;
import lime.graphics.cairo.CairoExtend;
import lime.graphics.cairo.CairoFilter;
import lime.graphics.cairo.CairoImageSurface;
import lime.graphics.cairo.CairoPattern;
import lime.graphics.cairo.CairoSurface;
import lime.graphics.cairo.Cairo;
import lime.graphics.opengl.GLBuffer;
import lime.graphics.opengl.GLFramebuffer;
import lime.graphics.opengl.GLTexture;
import lime.graphics.opengl.GL;
import lime.graphics.opengl.WebGLContext;
import lime.graphics.GLRenderContext;
import lime.graphics.Image;
import lime.graphics.ImageChannel;
import lime.graphics.ImageBuffer;
import lime.graphics.utils.ImageCanvasUtil;
import lime.math.color.ARGB;
import lime.math.ColorMatrix;
import lime.math.Rectangle in LimeRectangle;
import lime.math.Vector2;
import lime.utils.Float32Array;
import lime.utils.UInt8Array;
import openfl.Lib;
import openfl._internal.renderer.canvas.CanvasMaskManager;
import openfl._internal.renderer.RenderSession;
import openfl._internal.renderer.opengl.GLRenderer;
import openfl._internal.utils.PerlinNoise;
import openfl.display3D.textures.TextureBase;
import openfl.errors.IOError;
import openfl.errors.TypeError;
import openfl.filters.BitmapFilter;
import openfl.geom.ColorTransform;
import openfl.geom.Matrix;
import openfl.geom.Point;
import openfl.geom.Rectangle;
import openfl.utils.ByteArray;
import openfl.Vector;

#if (js && html5)
import js.html.CanvasElement;
import js.html.CanvasRenderingContext2D;
import js.html.ImageData;
import js.html.ImageElement;
import js.html.Uint8ClampedArray;
import js.Browser;
#end

#if lime_cairo
import openfl._internal.renderer.cairo.CairoBlendModeManager;
import openfl._internal.renderer.cairo.CairoRenderer;
import openfl._internal.renderer.cairo.CairoMaskManager;
#end

@:access(lime.graphics.opengl.GL)
@:access(lime.graphics.Image)
@:access(lime.graphics.ImageBuffer)
@:access(lime.math.Rectangle)
@:access(openfl._internal.renderer.opengl.GLRenderer)
@:access(openfl.display3D.textures.TextureBase)
@:access(openfl.display.DisplayObject)
@:access(openfl.display.Graphics)
@:access(openfl.filters.BitmapFilter)
@:access(openfl.geom.ColorTransform)
@:access(openfl.geom.Matrix)
@:access(openfl.geom.Point)
@:access(openfl.geom.Rectangle)

#if !openfl_debug
@:fileXml('tags="haxe,release"')
@:noDebug
#end

@:autoBuild(openfl._internal.macros.AssetsMacro.embedBitmap())


class BitmapData implements IBitmapDrawable {
	
	
	private static var __supportsBGRA:Null<Bool> = null;
	private static var __textureFormat:Int;
	private static var __textureInternalFormat:Int;
	
	public var height (default, null):Int;
	public var image (default, null):Image;
	public var readable (default, null):Bool;
	public var rect (default, null):Rectangle;
	public var transparent (default, null):Bool;
	public var width (default, null):Int;
	
	private var __blendMode:BlendMode;
	private var __buffer:GLBuffer;
	private var __bufferContext:GLRenderContext;
	private var __bufferAlpha:Float;
	private var __bufferData:Float32Array;
	private var __framebuffer:GLFramebuffer;
	private var __framebufferContext:GLRenderContext;
	private var __isValid:Bool;
	private var __surface:CairoSurface;
	private var __texture:GLTexture;
	private var __textureContext:GLRenderContext;
	private var __textureVersion:Int;
	private var __transform:Matrix;
	private var __worldColorTransform:ColorTransform;
	private var __worldTransform:Matrix;
	
	
	public function new (width:Int, height:Int, transparent:Bool = true, fillColor:UInt = 0xFFFFFFFF) {
		
		this.transparent = transparent;
		
		#if (neko || (js && html5))
		width = width == null ? 0 : width;
		height = height == null ? 0 : height;
		#end
		
		width = width < 0 ? 0 : width;
		height = height < 0 ? 0 : height;
		
		this.width = width;
		this.height = height;
		rect = new Rectangle (0, 0, width, height);
		
		if (width > 0 && height > 0) {
			
			if (transparent) {
				
				if ((fillColor & 0xFF000000) == 0) {
					
					fillColor = 0;
					
				}
				
			} else {
				
				fillColor = (0xFF << 24) | (fillColor & 0xFFFFFF);
				
			}
			
			fillColor = (fillColor << 8) | ((fillColor >> 24) & 0xFF);
			
			#if sys
			var buffer = new ImageBuffer (new UInt8Array (width * height * 4), width, height);
			buffer.format = BGRA32;
			buffer.premultiplied = true;
			
			image = new Image (buffer, 0, 0, width, height);
			
			if (fillColor != 0) {
				
				image.fillRect (image.rect, fillColor);
				
			}
			#else
			image = new Image (null, 0, 0, width, height, fillColor);
			#end
			
			image.transparent = transparent;
			
			__isValid = true;
			readable = true;
			
		}
		
		__worldTransform = new Matrix ();
		__worldColorTransform = new ColorTransform ();
		
	}<commit_msg>Add commented code for canvas-based BitmapData rather than pixel array<commit_after>package openfl.display;


import lime.app.Future;
import lime.app.Promise;
import lime.graphics.cairo.CairoExtend;
import lime.graphics.cairo.CairoFilter;
import lime.graphics.cairo.CairoImageSurface;
import lime.graphics.cairo.CairoPattern;
import lime.graphics.cairo.CairoSurface;
import lime.graphics.cairo.Cairo;
import lime.graphics.opengl.GLBuffer;
import lime.graphics.opengl.GLFramebuffer;
import lime.graphics.opengl.GLTexture;
import lime.graphics.opengl.GL;
import lime.graphics.opengl.WebGLContext;
import lime.graphics.GLRenderContext;
import lime.graphics.Image;
import lime.graphics.ImageChannel;
import lime.graphics.ImageBuffer;
import lime.graphics.utils.ImageCanvasUtil;
import lime.math.color.ARGB;
import lime.math.ColorMatrix;
import lime.math.Rectangle in LimeRectangle;
import lime.math.Vector2;
import lime.utils.Float32Array;
import lime.utils.UInt8Array;
import openfl.Lib;
import openfl._internal.renderer.canvas.CanvasMaskManager;
import openfl._internal.renderer.RenderSession;
import openfl._internal.renderer.opengl.GLRenderer;
import openfl._internal.utils.PerlinNoise;
import openfl.display3D.textures.TextureBase;
import openfl.errors.IOError;
import openfl.errors.TypeError;
import openfl.filters.BitmapFilter;
import openfl.geom.ColorTransform;
import openfl.geom.Matrix;
import openfl.geom.Point;
import openfl.geom.Rectangle;
import openfl.utils.ByteArray;
import openfl.Vector;

#if (js && html5)
import js.html.CanvasElement;
import js.html.CanvasRenderingContext2D;
import js.html.ImageData;
import js.html.ImageElement;
import js.html.Uint8ClampedArray;
import js.Browser;
#end

#if lime_cairo
import openfl._internal.renderer.cairo.CairoBlendModeManager;
import openfl._internal.renderer.cairo.CairoRenderer;
import openfl._internal.renderer.cairo.CairoMaskManager;
#end

@:access(lime.graphics.opengl.GL)
@:access(lime.graphics.Image)
@:access(lime.graphics.ImageBuffer)
@:access(lime.math.Rectangle)
@:access(openfl._internal.renderer.opengl.GLRenderer)
@:access(openfl.display3D.textures.TextureBase)
@:access(openfl.display.DisplayObject)
@:access(openfl.display.Graphics)
@:access(openfl.filters.BitmapFilter)
@:access(openfl.geom.ColorTransform)
@:access(openfl.geom.Matrix)
@:access(openfl.geom.Point)
@:access(openfl.geom.Rectangle)

#if !openfl_debug
@:fileXml('tags="haxe,release"')
@:noDebug
#end

@:autoBuild(openfl._internal.macros.AssetsMacro.embedBitmap())


class BitmapData implements IBitmapDrawable {
	
	
	private static var __supportsBGRA:Null<Bool> = null;
	private static var __textureFormat:Int;
	private static var __textureInternalFormat:Int;
	
	public var height (default, null):Int;
	public var image (default, null):Image;
	public var readable (default, null):Bool;
	public var rect (default, null):Rectangle;
	public var transparent (default, null):Bool;
	public var width (default, null):Int;
	
	private var __blendMode:BlendMode;
	private var __buffer:GLBuffer;
	private var __bufferContext:GLRenderContext;
	private var __bufferAlpha:Float;
	private var __bufferData:Float32Array;
	private var __framebuffer:GLFramebuffer;
	private var __framebufferContext:GLRenderContext;
	private var __isValid:Bool;
	private var __surface:CairoSurface;
	private var __texture:GLTexture;
	private var __textureContext:GLRenderContext;
	private var __textureVersion:Int;
	private var __transform:Matrix;
	private var __worldColorTransform:ColorTransform;
	private var __worldTransform:Matrix;
	
	
	public function new (width:Int, height:Int, transparent:Bool = true, fillColor:UInt = 0xFFFFFFFF) {
		
		this.transparent = transparent;
		
		#if (neko || (js && html5))
		width = width == null ? 0 : width;
		height = height == null ? 0 : height;
		#end
		
		width = width < 0 ? 0 : width;
		height = height < 0 ? 0 : height;
		
		this.width = width;
		this.height = height;
		rect = new Rectangle (0, 0, width, height);
		
		if (width > 0 && height > 0) {
			
			if (transparent) {
				
				if ((fillColor & 0xFF000000) == 0) {
					
					fillColor = 0;
					
				}
				
			} else {
				
				fillColor = (0xFF << 24) | (fillColor & 0xFFFFFF);
				
			}
			
			fillColor = (fillColor << 8) | ((fillColor >> 24) & 0xFF);
			
			#if sys
			var buffer = new ImageBuffer (new UInt8Array (width * height * 4), width, height);
			buffer.format = BGRA32;
			buffer.premultiplied = true;
			
			image = new Image (buffer, 0, 0, width, height);
			
			if (fillColor != 0) {
				
				image.fillRect (image.rect, fillColor);
				
			}
			//#elseif (js && html5)
			//var buffer = new ImageBuffer (null, width, height);
			//var canvas:CanvasElement = cast Browser.document.createElement ("canvas");
			//buffer.__srcCanvas = canvas;
			//buffer.__srcContext = canvas.getContext ("2d");
			//
			//image = new Image (buffer, 0, 0, width, height);
			//image.type = CANVAS;
			//
			//if (fillColor != 0) {
				//
				//image.fillRect (image.rect, fillColor);
				//
			//}
			//#else
			image = new Image (null, 0, 0, width, height, fillColor);
			#end
			
			image.transparent = transparent;
			
			__isValid = true;
			readable = true;
			
		}
		
		__worldTransform = new Matrix ();
		__worldColorTransform = new ColorTransform ();
		
	}
{'fraction_non_alphanumeric': 0.1139984070091597, 'fraction_numerical': 0.010254878534448427, 'mean_word_length': 4.655968468468468, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7631908', 'n_tokens_mistral': 3707, 'n_tokens_neox': 3257, 'n_words': 733}