浏览代码

use Bytes for BitmapData pixels in HL, add drawScaled support

Nicolas Cannasse 9 年之前
父节点
当前提交
0a713bc4a9
共有 2 个文件被更改,包括 31 次插入1 次删除
  1. 27 1
      hxd/BitmapData.hx
  2. 4 0
      hxd/impl/FmtSupport.hx

+ 27 - 1
hxd/BitmapData.hx

@@ -11,7 +11,11 @@ typedef BitmapInnerData =
 	BitmapInnerDataImpl;
 
 class BitmapInnerDataImpl {
+	#if hl
+	public var pixels : hl.types.BytesAccess<Int>;
+	#else
 	public var pixels : haxe.ds.Vector<Int>;
+	#end
 	public var width : Int;
 	public var height : Int;
 	public function new() {
@@ -55,7 +59,11 @@ class BitmapData {
 			data = new lime.graphics.Image( null, 0, 0, width, height );
 			#else
 			data = new BitmapInnerData();
+			#if hl
+			data.pixels = new hl.types.Bytes(width * height * 4);
+			#else
 			data.pixels = new haxe.ds.Vector(width * height);
+			#end
 			data.width = width;
 			data.height = height;
 			#end
@@ -203,6 +211,18 @@ class BitmapData {
 		m.a = 1;
 		m.d = 1;
 
+		#elseif hl
+
+		if( blendMode != None ) throw "BitmapData.drawScaled blendMode no supported : " + blendMode;
+		if( x < 0 || y < 0 || width < 0 || height < 0 || srcX < 0 || srcY < 0 || srcWidth < 0 || srcHeight < 0 ||
+			x + width > this.width || y + height > this.height || srcX + srcWidth > src.width || srcY + srcHeight > src.height )
+			throw "Outside bounds";
+		hxd.impl.FmtSupport.scaleImage(
+			data.pixels, (x + y * this.width) << 2, this.width<<2, width, height,
+			src.data.pixels, (srcX + srcY * src.width)<<2, src.width<<2, srcWidth, srcHeight,
+			smooth?1:0
+		);
+
 		#else
 		notImplemented();
 		#end
@@ -260,9 +280,15 @@ class BitmapData {
 		var b = new BitmapInnerData();
 		b.width = w;
 		b.height = h;
+		#if hl
+		b.pixels = new hl.types.Bytes(w * h * 4);
+		for( dy in 0...h )
+			b.pixels.blit(dy * w, data.pixels, x + (y + dy) * width, w);
+		#else
 		b.pixels = new haxe.ds.Vector(w * h);
 		for( dy in 0...h )
-			haxe.ds.Vector.blit(data.pixels, x + (y + dy) * width * 4, b.pixels, dy * w * 4, w * 4);
+			haxe.ds.Vector.blit(data.pixels, x + (y + dy) * width, b.pixels, dy * w, w);
+		#end
 		return fromNative(b);
 		#end
 	}

+ 4 - 0
hxd/impl/FmtSupport.hx

@@ -44,5 +44,9 @@ class FmtSupport {
 		return false;
 	}
 
+	@:hlNative("fmt","img_scale")
+	public static function scaleImage( out : hl.types.Bytes, outPos : Int,  outStride : Int, outWidth : Int, outHeight : Int, _in : hl.types.Bytes, inPos : Int,  inStride : Int, inWidth : Int, inHeight : Int, flags : Int ) {
+	}
+
 }
 #end