|
@@ -25,7 +25,8 @@ abstract PixelsARGB(Pixels) to Pixels {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-@:forward(bytes, format, width, height, offset, flags, clear, dispose, toPNG, clone, toVector, sub, blit)
|
|
|
+@:forward(bytes, format, width, height, offset, flags, clear, dispose, toPNG, clone, toVector, sub, blit, invalidFormat, willChange)
|
|
|
+@:access(hxd.Pixels)
|
|
|
abstract PixelsFloat(Pixels) to Pixels {
|
|
|
|
|
|
public inline function getPixelF(x, y) {
|
|
@@ -37,7 +38,7 @@ abstract PixelsFloat(Pixels) to Pixels {
|
|
|
var pix = ((x + y * this.width) << 4) + this.offset;
|
|
|
return new h3d.Vector(this.bytes.getFloat(pix),this.bytes.getFloat(pix+4),this.bytes.getFloat(pix+8),this.bytes.getFloat(pix+12));
|
|
|
default:
|
|
|
- invalidFormat();
|
|
|
+ this.invalidFormat();
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
@@ -54,7 +55,7 @@ abstract PixelsFloat(Pixels) to Pixels {
|
|
|
this.bytes.setFloat(pix + 8, v.z);
|
|
|
this.bytes.setFloat(pix + 12, v.w);
|
|
|
default:
|
|
|
- invalidFormat();
|
|
|
+ this.invalidFormat();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -63,8 +64,25 @@ abstract PixelsFloat(Pixels) to Pixels {
|
|
|
return cast p;
|
|
|
}
|
|
|
|
|
|
- function invalidFormat() {
|
|
|
- throw "Unsupported format for this operation : " + this.format;
|
|
|
+ public function convert( target : PixelFormat ) {
|
|
|
+ if( this.format == target )
|
|
|
+ return;
|
|
|
+ this.willChange();
|
|
|
+ var bytes : hxd.impl.UncheckedBytes = this.bytes;
|
|
|
+ switch( [this.format, target] ) {
|
|
|
+
|
|
|
+ case [RGBA32F, R32F]:
|
|
|
+ var nbytes = haxe.io.Bytes.alloc(this.height * this.width * 4);
|
|
|
+ var out : hxd.impl.UncheckedBytes = nbytes;
|
|
|
+ for( i in 0 ... this.width * this.height )
|
|
|
+ nbytes.setFloat(i << 2, this.bytes.getFloat(i << 4));
|
|
|
+ this.bytes = nbytes;
|
|
|
+
|
|
|
+ default:
|
|
|
+ throw "Cannot convert from " + this.format + " to " + target;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.innerFormat = target;
|
|
|
}
|
|
|
}
|
|
|
|