Explorar o código

added png16 hl support

Nicolas Cannasse %!s(int64=5) %!d(string=hai) anos
pai
achega
23f2c72012
Modificáronse 3 ficheiros con 36 adicións e 9 borrados
  1. 3 0
      hxd/PixelFormat.hx
  2. 6 6
      hxd/Pixels.hx
  3. 27 3
      hxd/res/Image.hx

+ 3 - 0
hxd/PixelFormat.hx

@@ -19,5 +19,8 @@ enum PixelFormat {
 	SRGB_ALPHA;
 	RGB10A2;
 	RG11B10UF; // unsigned float
+	R16U;
+	RGB16U;
+	RGBA16U;
 	S3TC( v : Int );
 }

+ 6 - 6
hxd/Pixels.hx

@@ -483,16 +483,16 @@ class Pixels {
 	public static function calcStride( width : Int, format : PixelFormat ) {
 		return width * switch( format ) {
 		case ARGB, BGRA, RGBA, SRGB, SRGB_ALPHA: 4;
-		case RGBA16F: 8;
+		case RGBA16U, RGBA16F: 8;
 		case RGBA32F: 16;
 		case R8: 1;
-		case R16F: 2;
+		case R16U, R16F: 2;
 		case R32F: 4;
 		case RG8: 2;
 		case RG16F: 4;
 		case RG32F: 8;
 		case RGB8: 3;
-		case RGB16F: 6;
+		case RGB16U, RGB16F: 6;
 		case RGB32F: 12;
 		case RGB10A2: 4;
 		case RG11B10UF: 4;
@@ -511,12 +511,12 @@ class Pixels {
 	**/
 	public static function getChannelOffset( format : PixelFormat, channel : Channel ) {
 		return switch( format ) {
-		case R8, R16F, R32F:
+		case R8, R16F, R32F, R16U:
 			if( channel == R ) 0 else -1;
 		case RG8, RG16F, RG32F:
 			var p = calcStride(1,format);
 			[0, p, -1, -1][channel.toInt()];
-		case RGB8, RGB16F, RGB32F:
+		case RGB8, RGB16F, RGB32F, RGB16U:
 			var p = calcStride(1,format);
 			[0, p, p<<1, -1][channel.toInt()];
 		case ARGB:
@@ -525,7 +525,7 @@ class Pixels {
 			[2, 1, 0, 3][channel.toInt()];
 		case RGBA, SRGB, SRGB_ALPHA:
 			channel.toInt();
-		case RGBA16F:
+		case RGBA16F, RGBA16U:
 			channel.toInt() * 2;
 		case RGBA32F:
 			channel.toInt() * 4;

+ 27 - 3
hxd/res/Image.hx

@@ -81,6 +81,7 @@ class Image extends Resource {
 				if( f.readInt32() == ('I'.code << 24) | ('H'.code << 16) | ('D'.code << 8) | 'R'.code ) {
 					width = f.readInt32();
 					height = f.readInt32();
+					bc = f.readByte(); // colbits
 					break;
 				}
 				f.skip(dataLen + 4); // CRC
@@ -158,7 +159,13 @@ class Image extends Resource {
 			var bytes = entry.getBytes(); // using getTmpBytes cause bug in E2
 
 			#if hl
-			if( fmt == null ) fmt = BGRA;
+			if( fmt == null )
+				fmt = switch( inf.bc ) {
+				case 16: R16U;
+				case 48: RGB16U;
+				case 64: RGBA16U;
+				default: BGRA;
+				}
 			pixels = decodePNG(bytes, inf.width, inf.height, fmt, flipY);
 			if( pixels == null ) throw "Failed to decode PNG " + entry.path;
 			#else
@@ -242,12 +249,29 @@ class Image extends Resource {
 		case RGBA: RGBA;
 		case BGRA: BGRA;
 		case ARGB: ARGB;
+		case R16U: cast 12;
+		case RGB16U: cast 13;
+		case RGBA16U: cast 14;
 		default:
 			fmt = BGRA;
 			BGRA;
 		};
-		var dst = haxe.io.Bytes.alloc(width * height * 4);
-		if( !hl.Format.decodePNG(src.getData(), src.length, dst.getData(), width, height, width * 4, ifmt, (flipY?1:0)) )
+		var stride = 4; // row_stride is the step, in png_byte or png_uint_16 units	as appropriate, between adjacent rows
+		var pxsize = 4;
+		switch( fmt ) {
+			case R16U:
+				stride = 1;
+				pxsize = 2;
+			case RGB16U:
+				stride = 3;
+				pxsize = 6;
+			case RGBA16U:
+				stride = 4;
+				pxsize = 8;
+			default:
+		}
+		var dst = haxe.io.Bytes.alloc(width * height * pxsize);
+		if( !hl.Format.decodePNG(src.getData(), src.length, dst.getData(), width, height, width * stride, ifmt, (flipY?1:0)) )
 			return null;
 		var pix = new hxd.Pixels(width, height, dst, fmt);
 		if( flipY ) pix.flags.set(FlipY);