|
@@ -43,7 +43,7 @@ abstract PixelsFloat(Pixels) to Pixels {
|
|
}
|
|
}
|
|
|
|
|
|
@:from public static function fromPixels(p:Pixels) : PixelsFloat {
|
|
@:from public static function fromPixels(p:Pixels) : PixelsFloat {
|
|
- p.convert(RGBA16F);
|
|
|
|
|
|
+ p.convert(RGBA32F);
|
|
p.setFlip(false);
|
|
p.setFlip(false);
|
|
return cast p;
|
|
return cast p;
|
|
}
|
|
}
|
|
@@ -66,7 +66,7 @@ class Pixels {
|
|
public var height : Int;
|
|
public var height : Int;
|
|
public var offset : Int;
|
|
public var offset : Int;
|
|
public var flags: haxe.EnumFlags<Flags>;
|
|
public var flags: haxe.EnumFlags<Flags>;
|
|
- var bpp : Int;
|
|
|
|
|
|
+ public var bytesPerPixel(default,null) : Int;
|
|
var innerFormat(default, set) : PixelFormat;
|
|
var innerFormat(default, set) : PixelFormat;
|
|
|
|
|
|
public function new(width : Int, height : Int, bytes : haxe.io.Bytes, format : hxd.PixelFormat, offset = 0) {
|
|
public function new(width : Int, height : Int, bytes : haxe.io.Bytes, format : hxd.PixelFormat, offset = 0) {
|
|
@@ -89,7 +89,7 @@ class Pixels {
|
|
|
|
|
|
function set_innerFormat(fmt) {
|
|
function set_innerFormat(fmt) {
|
|
this.innerFormat = fmt;
|
|
this.innerFormat = fmt;
|
|
- bpp = bytesPerPixel(fmt);
|
|
|
|
|
|
+ bytesPerPixel = getBytesPerPixel(fmt);
|
|
return fmt;
|
|
return fmt;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -100,11 +100,11 @@ class Pixels {
|
|
public function sub( x : Int, y : Int, width : Int, height : Int ) {
|
|
public function sub( x : Int, y : Int, width : Int, height : Int ) {
|
|
if( x < 0 || y < 0 || x + width > this.width || y + height > this.height )
|
|
if( x < 0 || y < 0 || x + width > this.width || y + height > this.height )
|
|
throw "Pixels.sub() outside bounds";
|
|
throw "Pixels.sub() outside bounds";
|
|
- var out = haxe.io.Bytes.alloc(width * height * bpp);
|
|
|
|
- var stride = width * bpp;
|
|
|
|
|
|
+ var out = haxe.io.Bytes.alloc(width * height * bytesPerPixel);
|
|
|
|
+ var stride = width * bytesPerPixel;
|
|
var outP = 0;
|
|
var outP = 0;
|
|
for( dy in 0...height ) {
|
|
for( dy in 0...height ) {
|
|
- var p = (x + yflip(y + dy) * this.width) * bpp + offset;
|
|
|
|
|
|
+ var p = (x + yflip(y + dy) * this.width) * bytesPerPixel + offset;
|
|
out.blit(outP, this.bytes, p, stride);
|
|
out.blit(outP, this.bytes, p, stride);
|
|
outP += stride;
|
|
outP += stride;
|
|
}
|
|
}
|
|
@@ -122,6 +122,7 @@ class Pixels {
|
|
throw "Pixels.blit() outside src bounds";
|
|
throw "Pixels.blit() outside src bounds";
|
|
willChange();
|
|
willChange();
|
|
src.convert(format);
|
|
src.convert(format);
|
|
|
|
+ var bpp = bytesPerPixel;
|
|
var stride = width * bpp;
|
|
var stride = width * bpp;
|
|
for( dy in 0...height ) {
|
|
for( dy in 0...height ) {
|
|
var srcP = (srcX + src.yflip(dy + srcY) * src.width) * bpp + src.offset;
|
|
var srcP = (srcX + src.yflip(dy + srcY) * src.width) * bpp + src.offset;
|
|
@@ -134,7 +135,7 @@ class Pixels {
|
|
var mask = preserveMask;
|
|
var mask = preserveMask;
|
|
willChange();
|
|
willChange();
|
|
if( color == 0 && mask == 0 ) {
|
|
if( color == 0 && mask == 0 ) {
|
|
- bytes.fill(offset, width * height * bpp, 0);
|
|
|
|
|
|
+ bytes.fill(offset, width * height * bytesPerPixel, 0);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
switch( format ) {
|
|
switch( format ) {
|
|
@@ -168,8 +169,8 @@ class Pixels {
|
|
var p = offset;
|
|
var p = offset;
|
|
var dl = 0;
|
|
var dl = 0;
|
|
if( flags.has(FlipY) ) {
|
|
if( flags.has(FlipY) ) {
|
|
- p += ((height - 1) * width) * bpp;
|
|
|
|
- dl = -width * 2 * bpp;
|
|
|
|
|
|
+ p += ((height - 1) * width) * bytesPerPixel;
|
|
|
|
+ dl = -width * 2 * bytesPerPixel;
|
|
}
|
|
}
|
|
switch(format) {
|
|
switch(format) {
|
|
case BGRA:
|
|
case BGRA:
|
|
@@ -210,6 +211,7 @@ class Pixels {
|
|
while( tw < w ) tw <<= 1;
|
|
while( tw < w ) tw <<= 1;
|
|
while( th < h ) th <<= 1;
|
|
while( th < h ) th <<= 1;
|
|
if( w == tw && h == th ) return this;
|
|
if( w == tw && h == th ) return this;
|
|
|
|
+ var bpp = bytesPerPixel;
|
|
var out = haxe.io.Bytes.alloc(tw * th * bpp);
|
|
var out = haxe.io.Bytes.alloc(tw * th * bpp);
|
|
var p = 0, b = offset;
|
|
var p = 0, b = offset;
|
|
for( y in 0...h ) {
|
|
for( y in 0...h ) {
|
|
@@ -235,8 +237,8 @@ class Pixels {
|
|
|
|
|
|
function copyInner() {
|
|
function copyInner() {
|
|
var old = bytes;
|
|
var old = bytes;
|
|
- bytes = haxe.io.Bytes.alloc(width * height * bpp);
|
|
|
|
- bytes.blit(0, old, offset, width * height * bpp);
|
|
|
|
|
|
+ bytes = haxe.io.Bytes.alloc(width * height * bytesPerPixel);
|
|
|
|
+ bytes.blit(0, old, offset, width * height * bytesPerPixel);
|
|
offset = 0;
|
|
offset = 0;
|
|
flags.unset(ReadOnly);
|
|
flags.unset(ReadOnly);
|
|
}
|
|
}
|
|
@@ -248,10 +250,10 @@ class Pixels {
|
|
public function setFlip( b : Bool ) {
|
|
public function setFlip( b : Bool ) {
|
|
#if js if( b == null ) b = false; #end
|
|
#if js if( b == null ) b = false; #end
|
|
if( flags.has(FlipY) == b ) return;
|
|
if( flags.has(FlipY) == b ) return;
|
|
- if( this.bpp != 4 ) throw "TODO";
|
|
|
|
willChange();
|
|
willChange();
|
|
if( b ) flags.set(FlipY) else flags.unset(FlipY);
|
|
if( b ) flags.set(FlipY) else flags.unset(FlipY);
|
|
- var stride = width * bpp;
|
|
|
|
|
|
+ var stride = width * bytesPerPixel;
|
|
|
|
+ if( stride%4 != 0 ) invalidFormat();
|
|
for( y in 0...height >> 1 ) {
|
|
for( y in 0...height >> 1 ) {
|
|
var p1 = y * stride + offset;
|
|
var p1 = y * stride + offset;
|
|
var p2 = (height - 1 - y) * stride + offset;
|
|
var p2 = (height - 1 - y) * stride + offset;
|
|
@@ -322,7 +324,7 @@ class Pixels {
|
|
}
|
|
}
|
|
|
|
|
|
public function getPixel(x, y) : Int {
|
|
public function getPixel(x, y) : Int {
|
|
- var p = ((x + yflip(y) * width) * bpp) + offset;
|
|
|
|
|
|
+ var p = ((x + yflip(y) * width) * bytesPerPixel) + offset;
|
|
switch(format) {
|
|
switch(format) {
|
|
case BGRA:
|
|
case BGRA:
|
|
return bytes.getInt32(p);
|
|
return bytes.getInt32(p);
|
|
@@ -337,7 +339,7 @@ class Pixels {
|
|
}
|
|
}
|
|
|
|
|
|
public function setPixel(x, y, color) : Void {
|
|
public function setPixel(x, y, color) : Void {
|
|
- var p = ((x + yflip(y) * width) * bpp) + offset;
|
|
|
|
|
|
+ var p = ((x + yflip(y) * width) * bytesPerPixel) + offset;
|
|
willChange();
|
|
willChange();
|
|
switch(format) {
|
|
switch(format) {
|
|
case BGRA:
|
|
case BGRA:
|
|
@@ -375,14 +377,14 @@ class Pixels {
|
|
p.flags = flags;
|
|
p.flags = flags;
|
|
p.flags.unset(ReadOnly);
|
|
p.flags.unset(ReadOnly);
|
|
if( bytes != null ) {
|
|
if( bytes != null ) {
|
|
- var size = width * height * bpp;
|
|
|
|
|
|
+ var size = width * height * bytesPerPixel;
|
|
p.bytes = haxe.io.Bytes.alloc(size);
|
|
p.bytes = haxe.io.Bytes.alloc(size);
|
|
p.bytes.blit(0, bytes, offset, size);
|
|
p.bytes.blit(0, bytes, offset, size);
|
|
}
|
|
}
|
|
return p;
|
|
return p;
|
|
}
|
|
}
|
|
|
|
|
|
- public static function bytesPerPixel( format : PixelFormat ) {
|
|
|
|
|
|
+ public static function getBytesPerPixel( format : PixelFormat ) {
|
|
return switch( format ) {
|
|
return switch( format ) {
|
|
case ALPHA8: 1;
|
|
case ALPHA8: 1;
|
|
case ARGB, BGRA, RGBA, SRGB, SRGB_ALPHA: 4;
|
|
case ARGB, BGRA, RGBA, SRGB, SRGB_ALPHA: 4;
|
|
@@ -415,7 +417,7 @@ class Pixels {
|
|
}
|
|
}
|
|
|
|
|
|
public static function alloc( width, height, format : PixelFormat ) {
|
|
public static function alloc( width, height, format : PixelFormat ) {
|
|
- return new Pixels(width, height, haxe.io.Bytes.alloc(width * height * bytesPerPixel(format)), format);
|
|
|
|
|
|
+ return new Pixels(width, height, haxe.io.Bytes.alloc(width * height * getBytesPerPixel(format)), format);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|