From 8bd5bb91a3950885966628136d84f5899fb383e6 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Tue, 21 Apr 2015 12:41:52 -0700 Subject: [PATCH 01/31] Update to 2.3.3 --- haxelib.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/haxelib.json b/haxelib.json index cb15392f7..dd81bb5d8 100644 --- a/haxelib.json +++ b/haxelib.json @@ -4,7 +4,7 @@ "license": "MIT", "tags": [], "description": "A flexible lightweight layer for Haxe cross-platform developers", - "version": "2.3.2", - "releasenote": "Improved Image performance, improved Windows 10 support, fixes", + "version": "2.3.3", + "releasenote": "AudioSource improvements, other fixes", "contributors": [ "singmajesty" ] } From f3030bb9c4860667ca8a3051b7b3178e2d981f19 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Tue, 21 Apr 2015 12:42:00 -0700 Subject: [PATCH 02/31] Update CHANGELOG --- CHANGELOG.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dfe39f482..35f387c7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +2.3.3 (04/21/2015) +------------------ + +* Added audioSource.loops, audioSource.offset, audioSource.length +* Renamed audioSource.timeOffset to audioSource.currentTime +* Fixed onComplete for AudioSource instances +* Fixed support for embedded bytes on HTML5 +* Fixed support for hardware anti-aliasing on SDL2 targets +* Fixed a possible crash in copyPixels +* Improved accuracy of URLLoader progress + + 2.3.2 (04/15/2015) ------------------ From d7ade5b2f83d5e5394c0de07f26b1347113dcf5b Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Tue, 21 Apr 2015 13:31:38 -0700 Subject: [PATCH 03/31] Better OGG cleanup --- project/src/audio/format/OGG.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/project/src/audio/format/OGG.cpp b/project/src/audio/format/OGG.cpp index ecedc639a..53c91368b 100644 --- a/project/src/audio/format/OGG.cpp +++ b/project/src/audio/format/OGG.cpp @@ -124,6 +124,7 @@ namespace lime { } else { + lime::fclose (file); ByteArray data = ByteArray (resource->path); OAL_OggMemoryFile fakeFile = { data.Bytes (), data.Size (), 0 }; @@ -166,6 +167,7 @@ namespace lime { if (pInfo == NULL) { //LOG_SOUND("FAILED TO READ OGG SOUND INFO, IS THIS EVEN AN OGG FILE?\n"); + ov_clear (&oggFile); return false; } From 7e9f71c1c0b8fd1be5d9fa39f55fd0239ff02dcf Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Tue, 21 Apr 2015 13:35:46 -0700 Subject: [PATCH 04/31] Better cleanup in WAV code --- project/src/audio/format/WAV.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/project/src/audio/format/WAV.cpp b/project/src/audio/format/WAV.cpp index 71c3c068b..5e91c8fbe 100644 --- a/project/src/audio/format/WAV.cpp +++ b/project/src/audio/format/WAV.cpp @@ -73,6 +73,7 @@ namespace lime { if ((riff_header.chunkID[0] != 'R' || riff_header.chunkID[1] != 'I' || riff_header.chunkID[2] != 'F' || riff_header.chunkID[3] != 'F') || (riff_header.format[0] != 'W' || riff_header.format[1] != 'A' || riff_header.format[2] != 'V' || riff_header.format[3] != 'E')) { //LOG_SOUND ("Invalid RIFF or WAVE Header!\n"); + lime::fclose (file); return false; } @@ -88,6 +89,7 @@ namespace lime { if (result != 1) { LOG_SOUND ("Invalid Wave Format!\n"); + lime::fclose (file); return false; } @@ -120,6 +122,7 @@ namespace lime { if (result != 1) { LOG_SOUND ("Invalid Wav Data Header!\n"); + lime::fclose (file); return false; } @@ -141,6 +144,7 @@ namespace lime { if (!lime::fread (audioBuffer->data->Bytes (), wave_data.subChunkSize, 1, file)) { LOG_SOUND ("error loading WAVE data into struct!\n"); + lime::fclose (file); return false; } From e3c4c0d57ba102523ab96f83b5829515b0f59c4c Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Tue, 21 Apr 2015 13:38:48 -0700 Subject: [PATCH 05/31] Minor fix --- project/src/audio/format/WAV.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/project/src/audio/format/WAV.cpp b/project/src/audio/format/WAV.cpp index 5e91c8fbe..2afe61877 100644 --- a/project/src/audio/format/WAV.cpp +++ b/project/src/audio/format/WAV.cpp @@ -96,7 +96,7 @@ namespace lime { if (wave_format.subChunkID[0] != 'f' || wave_format.subChunkID[1] != 'm' || wave_format.subChunkID[2] != 't' || wave_format.subChunkID[3] != ' ') { - lime::fseek (file, wave_data.subChunkSize, SEEK_CUR); + lime::fseek (file, wave_format.subChunkSize, SEEK_CUR); } else { @@ -106,11 +106,11 @@ namespace lime { } - if (wave_format.subChunkSize > 16) { - - lime::fseek (file, sizeof (short), SEEK_CUR); - - } + //if (wave_format.subChunkSize > 16) { + // + //lime::fseek (file, sizeof (short), SEEK_CUR); + // + //} bool foundData = false; From 5ff82be019356ea60d34c504ddf64a8eabe09233 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Tue, 21 Apr 2015 13:42:50 -0700 Subject: [PATCH 06/31] Close a few more handles --- project/src/graphics/format/PNG.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/project/src/graphics/format/PNG.cpp b/project/src/graphics/format/PNG.cpp index 1dd707f38..503f5e2a8 100644 --- a/project/src/graphics/format/PNG.cpp +++ b/project/src/graphics/format/PNG.cpp @@ -201,6 +201,8 @@ namespace lime { png_read_end (png_ptr, NULL); png_destroy_read_struct (&png_ptr, &info_ptr, (png_infopp)NULL); + if (file) lime::fclose (file); + return true; } From 3e2291fb5459ed530c21e098d9b6bd626a541254 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Tue, 21 Apr 2015 14:00:56 -0700 Subject: [PATCH 07/31] Return immediately if ov_open fails --- project/src/audio/format/OGG.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/project/src/audio/format/OGG.cpp b/project/src/audio/format/OGG.cpp index 53c91368b..756e7c2af 100644 --- a/project/src/audio/format/OGG.cpp +++ b/project/src/audio/format/OGG.cpp @@ -120,7 +120,12 @@ namespace lime { if (file->isFile ()) { - ov_open (file->getFile (), &oggFile, NULL, file->getLength ()); + if (ov_open (file->getFile (), &oggFile, NULL, file->getLength ()) != 0) { + + lime::fclose (file); + return false; + + } } else { From 7c0023d622f2bc1a0a14f67190395d9edf51b96c Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Tue, 21 Apr 2015 14:15:20 -0700 Subject: [PATCH 08/31] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 35f387c7a..308bab168 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * Fixed onComplete for AudioSource instances * Fixed support for embedded bytes on HTML5 * Fixed support for hardware anti-aliasing on SDL2 targets +* Fixed some loose file handles in the format decoders * Fixed a possible crash in copyPixels * Improved accuracy of URLLoader progress From 02c545a8f170b97e75ab7577fbd7c4ffe99a879f Mon Sep 17 00:00:00 2001 From: "Lars A. Doucet" Date: Tue, 21 Apr 2015 16:20:45 -0500 Subject: [PATCH 09/31] null checks on lime/graphics/Image.hx --- lime/graphics/Image.hx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lime/graphics/Image.hx b/lime/graphics/Image.hx index d275d549d..0883cb4c4 100644 --- a/lime/graphics/Image.hx +++ b/lime/graphics/Image.hx @@ -1244,6 +1244,7 @@ class Image { private function get_transparent ():Bool { + if (buffer == null) return false; return buffer.transparent; } @@ -1252,7 +1253,7 @@ class Image { private function set_transparent (value:Bool):Bool { // TODO, modify data to set transparency - + if (buffer == null) return false; return buffer.transparent = value; } From c445feecd0ef60e0181429d714448f755a5aeb50 Mon Sep 17 00:00:00 2001 From: "Lars A. Doucet" Date: Tue, 21 Apr 2015 16:56:00 -0500 Subject: [PATCH 10/31] Image.hx copyPixels: more robust bounds checks prior to system-specific calls, this trims the rects to known legal values to prevent both buffer overflows and underflows --- lime/graphics/Image.hx | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/lime/graphics/Image.hx b/lime/graphics/Image.hx index 0883cb4c4..b054da9d2 100644 --- a/lime/graphics/Image.hx +++ b/lime/graphics/Image.hx @@ -245,15 +245,41 @@ class Image { public function copyPixels (sourceImage:Image, sourceRect:Rectangle, destPoint:Vector2, alphaImage:Image = null, alphaPoint:Vector2 = null, mergeAlpha:Bool = false):Void { + //fast fails -- if source or destination is null or of 0 dimensions, do nothing if (buffer == null || sourceImage == null) return; + if (sourceRect.width <= 0 || sourceRect.height <= 0) return; + if (width <= 0 || height <= 0) return; + //source rect expands too far right or too far below source image boundaries if (sourceRect.x + sourceRect.width > sourceImage.width) sourceRect.width = sourceImage.width - sourceRect.x; if (sourceRect.y + sourceRect.height > sourceImage.height) sourceRect.height = sourceImage.height - sourceRect.y; - if (sourceRect.width <= 0 || sourceRect.height <= 0) return; + //source rect starts too far left or too far above source image boundaries + if (sourceRect.x < 0) { + sourceRect.width += sourceRect.x; //shrink width by amount off canvas + sourceRect.x = 0; //clamp rect to 0 + } + if (sourceRect.y < 0) { + sourceRect.height += sourceRect.y; //shrink height by amount off canvas + sourceRect.y = 0; //clamp rect to 0 + } + + //draw area expands too far right or too far below destination image boundaries if (destPoint.x + sourceRect.width > width) sourceRect.width = width - destPoint.x; if (destPoint.y + sourceRect.height > height) sourceRect.height = height - destPoint.y; + //draw area starts too far left or too far above destination image boundaries + if (destPoint.x < 0) { + sourceRect.width += destPoint.x; //shrink width by amount off canvas + sourceRect.x = -destPoint.x; //adjust source rect to effective starting point + destPoint.x = 0; //clamp destination point to 0 + } + if (destPoint.y < 0) { + sourceRect.height += destPoint.y; //shrink height by amount off canvas + sourceRect.y = -destPoint.y; //adjust source rect to effective starting point + destPoint.y = 0; //clamp destination point to 0 + } + switch (type) { case CANVAS: From fc74f1c4edf529fc99cf8f3204a3a6e279e806f2 Mon Sep 17 00:00:00 2001 From: vroad Date: Wed, 22 Apr 2015 16:04:54 +0900 Subject: [PATCH 11/31] Fix compilation on nodejs --- lime/audio/AudioSource.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lime/audio/AudioSource.hx b/lime/audio/AudioSource.hx index fa8a03a80..b0c27fdb1 100644 --- a/lime/audio/AudioSource.hx +++ b/lime/audio/AudioSource.hx @@ -31,7 +31,7 @@ class AudioSource { private var channel:SoundChannel; #end - #if (cpp || neko) + #if (cpp || neko || nodejs) private var timer:Timer; #end From 594d1e30a1f6cd497934f953da2f5630139eb6d1 Mon Sep 17 00:00:00 2001 From: "Lars A. Doucet" Date: Wed, 22 Apr 2015 14:37:57 -0500 Subject: [PATCH 12/31] BitmapData: added getColorBoundsRect implementation for next --- lime/graphics/Image.hx | 25 ++++++ lime/graphics/utils/ImageDataUtil.hx | 130 +++++++++++++++++++++++++++ 2 files changed, 155 insertions(+) diff --git a/lime/graphics/Image.hx b/lime/graphics/Image.hx index b054da9d2..0029a3527 100644 --- a/lime/graphics/Image.hx +++ b/lime/graphics/Image.hx @@ -460,6 +460,31 @@ class Image { } + public function getColorBoundsRect(mask:Int, color:Int, findColor:Bool = true, format:PixelFormat = null):Rectangle { + + if (buffer == null) return null; + + //TODO: add all the other cases + + switch (type) { + + case CANVAS: + + return null; + + case DATA: + + return ImageDataUtil.getColorBoundsRect(this, mask, color, findColor, format); + + case FLASH: + + return buffer.__srcBitmapData.getColorBoundsRect(mask, color, findColor); + + default: + + return null; + } + } public function getPixel (x:Int, y:Int, format:PixelFormat = null):Int { diff --git a/lime/graphics/utils/ImageDataUtil.hx b/lime/graphics/utils/ImageDataUtil.hx index 71cb6e777..7427cb469 100644 --- a/lime/graphics/utils/ImageDataUtil.hx +++ b/lime/graphics/utils/ImageDataUtil.hx @@ -423,6 +423,136 @@ class ImageDataUtil { } + public static function getColorBoundsRect(image:Image, mask:Int, color:Int, findColor:Bool = true, format:PixelFormat):Rectangle { + + var left:Int = image.width+1; + var right:Int = 0; + var top:Int = image.height+1; + var bottom:Int = 0; + + var r, g, b, a; + var mr, mg, mb, ma; + + if (format == ARGB) { + + a = (image.transparent) ? (color >> 24) & 0xFF : 0xFF; + r = (color >> 16) & 0xFF; + g = (color >> 8) & 0xFF; + b = color & 0xFF; + + ma = (image.transparent) ? (mask >> 24) & 0xFF : 0xFF; + mr = (mask >> 16) & 0xFF; + mg = (mask >> 8) & 0xFF; + mb = mask & 0xFF; + + } else { + + r = (color >> 24) & 0xFF; + g = (color >> 16) & 0xFF; + b = (color >> 8) & 0xFF; + a = (image.transparent) ? color & 0xFF : 0xFF; + + mr = (mask >> 24) & 0xFF; + mg = (mask >> 16) & 0xFF; + mb = (mask >> 8) & 0xFF; + ma = (image.transparent) ? mask & 0xFF : 0xFF; + + } + + color = (r | (g << 8) | (b << 16) | (a << 24)); + mask = (mr | (mg << 8) | (mb << 16) | (mask << 24)); + + var pix:Int; + + //Sweep from the left + for (ix in 0...image.width) { + + var hit:Bool = false; + for (iy in 0...image.height) { + + pix = image.getPixel32(ix, iy); + hit = findColor ? (pix & mask) == color : (pix & mask) != color; + if (hit) { + if (ix < left) left = ix; + break; + } + } + if (hit) { + break; + } + } + + //Sweep from the right + for (_ix in 0...image.width) { + + var ix = (image.width - 1) - _ix; + var hit:Bool = false; + for (iy in 0...image.height) { + + pix = image.getPixel32(ix, iy); + hit = findColor ? (pix & mask) == color : (pix & mask) != color; + if (hit) { + if (ix > right) right = ix; + break; + } + } + if (hit) { + break; + } + } + + //Sweep from the top + for (iy in 0...image.height) { + + var hit:Bool = false; + for (ix in 0...image.width) { + pix = image.getPixel32(ix, iy); + hit = findColor ? (pix & mask) == color : (pix & mask) != color; + if (hit) { + if (iy < top) top = iy; + break; + } + } + if (hit) { + break; + } + } + + //Sweep from the bottom + for (_iy in 0...image.height) { + + var iy = (image.height - 1) - _iy; + var hit:Bool = false; + for (ix in 0...image.width) { + pix = image.getPixel32(ix, iy); + hit = findColor ? (pix & mask) == color : (pix & mask) != color; + if (hit) { + if (iy > bottom) bottom = iy; + break; + } + } + if (hit) { + break; + } + } + + var w = right - left; + var h = bottom - top; + + if (w > 0) w++; + if (h > 0) h++; + + if (w < 0) w = 0; + if (h < 0) h = 0; + + if (left == right) w = 1; + if (top == bottom) h = 1; + + if (left > image.width) left = 0; + if (top > image.height) top = 0; + + return new Rectangle(left, top, w, h); + } public static function getPixel (image:Image, x:Int, y:Int, format:PixelFormat):Int { From 72b906cea6f64513c28e8175fd30ad73f7284177 Mon Sep 17 00:00:00 2001 From: "Lars A. Doucet" Date: Wed, 22 Apr 2015 14:46:45 -0500 Subject: [PATCH 13/31] Image.hx: compile fix for flash --- lime/graphics/Image.hx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lime/graphics/Image.hx b/lime/graphics/Image.hx index 0029a3527..6ad9cc6b3 100644 --- a/lime/graphics/Image.hx +++ b/lime/graphics/Image.hx @@ -460,12 +460,18 @@ class Image { } - public function getColorBoundsRect(mask:Int, color:Int, findColor:Bool = true, format:PixelFormat = null):Rectangle { + public function getColorBoundsRect(mask:Int, color:Int, findColor:Bool = true, format:PixelFormat = null):#if (flash) flash.geom.Rectangle #else Rectangle #end { if (buffer == null) return null; //TODO: add all the other cases + #if flash + + return buffer.__srcBitmapData.getColorBoundsRect(mask, color, findColor); + + #else + switch (type) { case CANVAS: @@ -476,14 +482,12 @@ class Image { return ImageDataUtil.getColorBoundsRect(this, mask, color, findColor, format); - case FLASH: - - return buffer.__srcBitmapData.getColorBoundsRect(mask, color, findColor); - default: return null; } + + #end } public function getPixel (x:Int, y:Int, format:PixelFormat = null):Int { From c6ec535ee88d2b6b2dc4685e3991adc22c106ac3 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Wed, 22 Apr 2015 13:36:27 -0700 Subject: [PATCH 14/31] Image improvements --- lime/graphics/Image.hx | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/lime/graphics/Image.hx b/lime/graphics/Image.hx index 6ad9cc6b3..ee06410a4 100644 --- a/lime/graphics/Image.hx +++ b/lime/graphics/Image.hx @@ -409,6 +409,7 @@ class Image { public static function fromBase64 (base64:String, type:String, onload:Image -> Void):Image { + if (base64 == null) return null; var image = new Image (); image.__fromBase64 (base64, type, onload); return image; @@ -418,6 +419,7 @@ class Image { public static function fromBitmapData (bitmapData:#if flash BitmapData #else Dynamic #end):Image { + if (bitmapData == null) return null; var buffer = new ImageBuffer (null, bitmapData.width, bitmapData.height); buffer.__srcBitmapData = bitmapData; return new Image (buffer); @@ -427,6 +429,7 @@ class Image { public static function fromBytes (bytes:ByteArray, onload:Image -> Void = null):Image { + if (bytes == null) return null; var image = new Image (); image.__fromBytes (bytes, onload); return image; @@ -436,6 +439,7 @@ class Image { public static function fromCanvas (canvas:#if (js && html5) CanvasElement #else Dynamic #end):Image { + if (canvas == null) return null; var buffer = new ImageBuffer (null, canvas.width, canvas.height); buffer.src = canvas; return new Image (buffer); @@ -454,34 +458,36 @@ class Image { public static function fromImageElement (image:#if (js && html5) ImageElement #else Dynamic #end):Image { + if (image == null) return null; var buffer = new ImageBuffer (null, image.width, image.height); buffer.src = image; return new Image (buffer); } - public function getColorBoundsRect(mask:Int, color:Int, findColor:Bool = true, format:PixelFormat = null):#if (flash) flash.geom.Rectangle #else Rectangle #end { + public function getColorBoundsRect (mask:Int, color:Int, findColor:Bool = true, format:PixelFormat = null):Rectangle { if (buffer == null) return null; - //TODO: add all the other cases - - #if flash - - return buffer.__srcBitmapData.getColorBoundsRect(mask, color, findColor); - - #else - switch (type) { case CANVAS: - return null; + #if (js && html5) + ImageCanvasUtil.convertToData (this); + #end + + return ImageDataUtil.getColorBoundsRect (this, mask, color, findColor, format); case DATA: - return ImageDataUtil.getColorBoundsRect(this, mask, color, findColor, format); + return ImageDataUtil.getColorBoundsRect (this, mask, color, findColor, format); + + case FLASH: + var rect = buffer.__srcBitmapData.getColorBoundsRect (mask, color, findColor); + return new Rectangle (rect.x, rect.y, rect.width, rect.height); + default: return null; From 40b24706184ab272b35fa384885d8527ed6b0b31 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Wed, 22 Apr 2015 13:41:58 -0700 Subject: [PATCH 15/31] Compile fix --- lime/graphics/Image.hx | 1 - 1 file changed, 1 deletion(-) diff --git a/lime/graphics/Image.hx b/lime/graphics/Image.hx index ee06410a4..86fb29bd6 100644 --- a/lime/graphics/Image.hx +++ b/lime/graphics/Image.hx @@ -493,7 +493,6 @@ class Image { return null; } - #end } public function getPixel (x:Int, y:Int, format:PixelFormat = null):Int { From 89c3c382d787627e6b7b64dab54e8bc698a32831 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Wed, 22 Apr 2015 13:42:03 -0700 Subject: [PATCH 16/31] Tweak style a little --- lime/graphics/utils/ImageDataUtil.hx | 69 +++++++++++++++++++++------- 1 file changed, 53 insertions(+), 16 deletions(-) diff --git a/lime/graphics/utils/ImageDataUtil.hx b/lime/graphics/utils/ImageDataUtil.hx index 7427cb469..15cd0e5dc 100644 --- a/lime/graphics/utils/ImageDataUtil.hx +++ b/lime/graphics/utils/ImageDataUtil.hx @@ -423,11 +423,12 @@ class ImageDataUtil { } - public static function getColorBoundsRect(image:Image, mask:Int, color:Int, findColor:Bool = true, format:PixelFormat):Rectangle { + + public static function getColorBoundsRect (image:Image, mask:Int, color:Int, findColor:Bool = true, format:PixelFormat):Rectangle { - var left:Int = image.width+1; + var left:Int = image.width + 1; var right:Int = 0; - var top:Int = image.height+1; + var top:Int = image.height + 1; var bottom:Int = 0; var r, g, b, a; @@ -464,76 +465,110 @@ class ImageDataUtil { var pix:Int; - //Sweep from the left for (ix in 0...image.width) { - var hit:Bool = false; + var hit = false; + for (iy in 0...image.height) { - pix = image.getPixel32(ix, iy); + pix = image.getPixel32 (ix, iy); hit = findColor ? (pix & mask) == color : (pix & mask) != color; + if (hit) { + if (ix < left) left = ix; break; + } + } + if (hit) { + break; + } + } - //Sweep from the right for (_ix in 0...image.width) { var ix = (image.width - 1) - _ix; - var hit:Bool = false; + var hit = false; + for (iy in 0...image.height) { - pix = image.getPixel32(ix, iy); + pix = image.getPixel32 (ix, iy); hit = findColor ? (pix & mask) == color : (pix & mask) != color; + if (hit) { + if (ix > right) right = ix; break; + } + } + if (hit) { + break; + } + } - //Sweep from the top for (iy in 0...image.height) { - var hit:Bool = false; + var hit = false; + for (ix in 0...image.width) { - pix = image.getPixel32(ix, iy); + + pix = image.getPixel32 (ix, iy); hit = findColor ? (pix & mask) == color : (pix & mask) != color; + if (hit) { + if (iy < top) top = iy; break; + } + } + if (hit) { + break; + } + } - //Sweep from the bottom for (_iy in 0...image.height) { var iy = (image.height - 1) - _iy; - var hit:Bool = false; + var hit = false; + for (ix in 0...image.width) { - pix = image.getPixel32(ix, iy); + + pix = image.getPixel32 (ix, iy); hit = findColor ? (pix & mask) == color : (pix & mask) != color; + if (hit) { + if (iy > bottom) bottom = iy; break; + } + } + if (hit) { + break; + } + } var w = right - left; @@ -551,9 +586,11 @@ class ImageDataUtil { if (left > image.width) left = 0; if (top > image.height) top = 0; - return new Rectangle(left, top, w, h); + return new Rectangle (left, top, w, h); + } + public static function getPixel (image:Image, x:Int, y:Int, format:PixelFormat):Int { var data = image.buffer.data; From be0012948db5d2066df4e20ea1a8f464443d034c Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Thu, 23 Apr 2015 09:29:21 -0700 Subject: [PATCH 17/31] Ubuntu setup fix --- tools/utils/PlatformSetup.hx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/utils/PlatformSetup.hx b/tools/utils/PlatformSetup.hx index eb7b9d675..e58fca915 100644 --- a/tools/utils/PlatformSetup.hx +++ b/tools/utils/PlatformSetup.hx @@ -153,8 +153,8 @@ class PlatformSetup { if (extension != "zip") { - var arguments = "xvzf"; - + var arguments = "xvzf"; + if (extension == "bz2" || extension == "tbz2") { arguments = "xvjf"; @@ -178,7 +178,7 @@ class PlatformSetup { } ProcessHelper.runCommand ("", "tar", [ arguments, sourceZIP ], false); - ProcessHelper.runCommand ("", "cp", [ "-R", ignoreRootFolder + "/*", targetPath ], false); + ProcessHelper.runCommand ("", "cp", [ "-R", ignoreRootFolder + "/.", targetPath ], false); Sys.command ("rm", [ "-r", ignoreRootFolder ]); } else { @@ -668,7 +668,7 @@ class PlatformSetup { defaultInstallPath = "/opt/air-sdk"; } - + downloadFile (downloadPath); var path = unescapePath (CLIHelper.param ("Output directory [" + defaultInstallPath + "]")); From 02916119ca841f6e80aaf4610de2dab4de2845b9 Mon Sep 17 00:00:00 2001 From: MrCdK Date: Thu, 23 Apr 2015 23:35:26 +0200 Subject: [PATCH 18/31] Fixes copyPixels mergeAlpha Fixes issue https://github.com/openfl/openfl/issues/618 --- lime/graphics/utils/ImageDataUtil.hx | 8 ++++---- project/src/graphics/utils/ImageDataUtil.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lime/graphics/utils/ImageDataUtil.hx b/lime/graphics/utils/ImageDataUtil.hx index 15cd0e5dc..ae85b5f8b 100644 --- a/lime/graphics/utils/ImageDataUtil.hx +++ b/lime/graphics/utils/ImageDataUtil.hx @@ -240,10 +240,10 @@ class ImageDataUtil { sourceAlpha = sourceData[sourceOffset + 3] / 255; oneMinusSourceAlpha = (1 - sourceAlpha); - data[offset] = __clamp[Std.int (sourceData[sourceOffset] + (data[offset] * oneMinusSourceAlpha))]; - data[offset + 1] = __clamp[Std.int (sourceData[sourceOffset + 1] + (data[offset + 1] * oneMinusSourceAlpha))]; - data[offset + 2] = __clamp[Std.int (sourceData[sourceOffset + 2] + (data[offset + 2] * oneMinusSourceAlpha))]; - data[offset + 3] = __clamp[Std.int (sourceData[sourceOffset + 3] + (data[offset + 3] * oneMinusSourceAlpha))]; + data[offset] = __clamp[Std.int (sourceData[sourceOffset] * sourceAlpha)] + __clamp[Std.int(data[offset] * oneMinusSourceAlpha)]; + data[offset + 1] = __clamp[Std.int (sourceData[sourceOffset + 1] * sourceAlpha)] + __clamp[Std.int(data[offset + 1] * oneMinusSourceAlpha)]; + data[offset + 2] = __clamp[Std.int (sourceData[sourceOffset + 2] * sourceAlpha)] + __clamp[Std.int(data[offset + 2] * oneMinusSourceAlpha)]; + data[offset + 3] = __clamp[Std.int (sourceData[sourceOffset + 3] * sourceAlpha)] + __clamp[Std.int(data[offset + 3] * oneMinusSourceAlpha)]; } diff --git a/project/src/graphics/utils/ImageDataUtil.cpp b/project/src/graphics/utils/ImageDataUtil.cpp index 3a663ea82..d956ad641 100644 --- a/project/src/graphics/utils/ImageDataUtil.cpp +++ b/project/src/graphics/utils/ImageDataUtil.cpp @@ -174,10 +174,10 @@ namespace lime { sourceAlpha = sourceData[sourceOffset + 3] / 255; oneMinusSourceAlpha = (1 - sourceAlpha); - data[offset] = __clamp[int (sourceData[sourceOffset] + (data[offset] * oneMinusSourceAlpha))]; - data[offset + 1] = __clamp[int (sourceData[sourceOffset + 1] + (data[offset + 1] * oneMinusSourceAlpha))]; - data[offset + 2] = __clamp[int (sourceData[sourceOffset + 2] + (data[offset + 2] * oneMinusSourceAlpha))]; - data[offset + 3] = __clamp[int (sourceData[sourceOffset + 3] + (data[offset + 3] * oneMinusSourceAlpha))]; + data[offset] = __clamp[int (sourceData[sourceOffset] * sourceAlpha)] + __clamp[int(data[offset] * oneMinusSourceAlpha)]; + data[offset + 1] = __clamp[int (sourceData[sourceOffset + 1] * sourceAlpha)] + __clamp[int(data[offset + 1] * oneMinusSourceAlpha)]; + data[offset + 2] = __clamp[int (sourceData[sourceOffset + 2] * sourceAlpha)] + __clamp[int(data[offset + 2] * oneMinusSourceAlpha)]; + data[offset + 3] = __clamp[int (sourceData[sourceOffset + 3] * sourceAlpha)] + __clamp[int(data[offset + 3] * oneMinusSourceAlpha)]; } From 7703a8e2c020d1c475147cfca8b83c27a54f7696 Mon Sep 17 00:00:00 2001 From: MrCdK Date: Fri, 24 Apr 2015 00:33:19 +0200 Subject: [PATCH 19/31] Fix windows imageBuffer transparent value --- project/include/graphics/ImageBuffer.h | 1 + project/src/graphics/Image.cpp | 2 +- project/src/graphics/ImageBuffer.cpp | 6 ++++++ project/src/graphics/utils/ImageDataUtil.cpp | 2 +- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/project/include/graphics/ImageBuffer.h b/project/include/graphics/ImageBuffer.h index d6ddf291f..6e6e0ecfd 100644 --- a/project/include/graphics/ImageBuffer.h +++ b/project/include/graphics/ImageBuffer.h @@ -26,6 +26,7 @@ namespace lime { ByteArray *data; int height; int width; + bool transparent; private: diff --git a/project/src/graphics/Image.cpp b/project/src/graphics/Image.cpp index 4a84bffb4..3ad8692db 100644 --- a/project/src/graphics/Image.cpp +++ b/project/src/graphics/Image.cpp @@ -44,7 +44,7 @@ namespace lime { buffer = new ImageBuffer (val_field (image, id_buffer)); offsetX = val_int (val_field (image, id_offsetX)); offsetY = val_int (val_field (image, id_offsetY)); - transparent = val_int (val_field (image, id_transparent)); + transparent = val_bool (val_field (image, id_transparent)); } diff --git a/project/src/graphics/ImageBuffer.cpp b/project/src/graphics/ImageBuffer.cpp index 2f95b52b2..4f6c179ce 100644 --- a/project/src/graphics/ImageBuffer.cpp +++ b/project/src/graphics/ImageBuffer.cpp @@ -10,6 +10,7 @@ namespace lime { static int id_data; static int id_height; static int id_width; + static int id_transparent; static bool init = false; @@ -19,6 +20,7 @@ namespace lime { height = 0; bpp = 4; data = 0; + transparent = false; } @@ -29,6 +31,7 @@ namespace lime { id_bpp = val_id ("bpp"); id_bitsPerPixel = val_id ("bitsPerPixel"); + id_transparent = val_id ("transparent"); id_buffer = val_id ("buffer"); id_width = val_id ("width"); id_height = val_id ("height"); @@ -40,6 +43,7 @@ namespace lime { width = val_int (val_field (imageBuffer, id_width)); height = val_int (val_field (imageBuffer, id_height)); bpp = val_int (val_field (imageBuffer, id_bitsPerPixel)); + transparent = val_bool (val_field (imageBuffer, id_transparent)); value data_value = val_field (imageBuffer, id_data); value buffer_value = val_field (data_value, id_buffer); @@ -94,6 +98,7 @@ namespace lime { id_bpp = val_id ("bpp"); id_bitsPerPixel = val_id ("bitsPerPixel"); + id_transparent = val_id ("transparent"); id_buffer = val_id ("buffer"); id_width = val_id ("width"); id_height = val_id ("height"); @@ -106,6 +111,7 @@ namespace lime { alloc_field (mValue, id_width, alloc_int (width)); alloc_field (mValue, id_height, alloc_int (height)); alloc_field (mValue, id_bpp, alloc_int (bpp)); + alloc_field (mValue, id_transparent, alloc_bool (transparent)); alloc_field (mValue, id_data, data->mValue); return mValue; diff --git a/project/src/graphics/utils/ImageDataUtil.cpp b/project/src/graphics/utils/ImageDataUtil.cpp index d956ad641..649e11b1b 100644 --- a/project/src/graphics/utils/ImageDataUtil.cpp +++ b/project/src/graphics/utils/ImageDataUtil.cpp @@ -141,7 +141,7 @@ namespace lime { int rows = sourceRect->y + sourceRect->height + sourceImage->offsetY; int columns = sourceRect->x + sourceRect->width + sourceImage->offsetX; - if (!mergeAlpha || !sourceImage->transparent) { + if (!mergeAlpha || !sourceImage->buffer->transparent) { for (int row = sourceRect->y + sourceImage->offsetY; row < rows; row++) { From 632f0e695dbc5d8957113d4a14357b1033b501fc Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Fri, 24 Apr 2015 02:18:06 -0700 Subject: [PATCH 20/31] Add window enter and leave events (mouse focus) --- lime/_backend/flash/FlashApplication.hx | 14 +++++++++++++ lime/_backend/html5/HTML5Window.hx | 10 ++++++++- lime/_backend/native/NativeApplication.hx | 22 ++++++++++++++------ lime/app/Application.hx | 24 ++++++++++++++++++++++ lime/app/IModule.hx | 12 +++++++++++ lime/app/Module.hx | 20 ++++++++++++++++++ lime/ui/Window.hx | 2 ++ project/include/ui/WindowEvent.h | 4 +++- project/src/backend/sdl/SDLApplication.cpp | 4 ++++ 9 files changed, 104 insertions(+), 8 deletions(-) diff --git a/lime/_backend/flash/FlashApplication.hx b/lime/_backend/flash/FlashApplication.hx index c407442e6..7488b6795 100644 --- a/lime/_backend/flash/FlashApplication.hx +++ b/lime/_backend/flash/FlashApplication.hx @@ -25,6 +25,7 @@ class FlashApplication { private var cacheTime:Int; + private var mouseLeft:Bool; private var parent:Application; @@ -138,6 +139,7 @@ class FlashApplication { Lib.current.stage.addEventListener (Event.DEACTIVATE, handleWindowEvent); Lib.current.stage.addEventListener (FocusEvent.FOCUS_IN, handleWindowEvent); Lib.current.stage.addEventListener (FocusEvent.FOCUS_OUT, handleWindowEvent); + Lib.current.stage.addEventListener (Event.MOUSE_LEAVE, handleWindowEvent); Lib.current.stage.addEventListener (Event.RESIZE, handleWindowEvent); cacheTime = Lib.getTimer (); @@ -192,6 +194,13 @@ class FlashApplication { case "mouseMove": + if (mouseLeft) { + + mouseLeft = false; + parent.window.onWindowEnter.dispatch (); + + } + parent.window.onMouseMove.dispatch (event.stageX, event.stageY); case "mouseUp", "middleMouseUp", "rightMouseUp": @@ -280,6 +289,11 @@ class FlashApplication { parent.window.onWindowFocusOut.dispatch (); + case Event.MOUSE_LEAVE: + + mouseLeft = true; + parent.window.onWindowLeave.dispatch (); + default: parent.window.width = Lib.current.stage.stageWidth; diff --git a/lime/_backend/html5/HTML5Window.hx b/lime/_backend/html5/HTML5Window.hx index 101bea46f..6cae8c737 100644 --- a/lime/_backend/html5/HTML5Window.hx +++ b/lime/_backend/html5/HTML5Window.hx @@ -140,7 +140,7 @@ class HTML5Window { } - var events = [ "mousedown", "mousemove", "mouseup", "wheel" ]; + var events = [ "mousedown", "mouseenter", "mouseleave", "mousemove", "mouseup", "wheel" ]; for (event in events) { @@ -210,6 +210,14 @@ class HTML5Window { parent.onMouseDown.dispatch (x, y, event.button); + case "mouseenter": + + parent.onWindowEnter.dispatch (); + + case "mouseleave": + + parent.onWindowLeave.dispatch (); + case "mouseup": parent.onMouseUp.dispatch (x, y, event.button); diff --git a/lime/_backend/native/NativeApplication.hx b/lime/_backend/native/NativeApplication.hx index 4ab68db87..1b86c4f1e 100644 --- a/lime/_backend/native/NativeApplication.hx +++ b/lime/_backend/native/NativeApplication.hx @@ -287,6 +287,10 @@ class NativeApplication { parent.window.onWindowDeactivate.dispatch (); + case WINDOW_ENTER: + + parent.window.onWindowEnter.dispatch (); + case WINDOW_FOCUS_IN: parent.window.onWindowFocusIn.dispatch (); @@ -295,6 +299,10 @@ class NativeApplication { parent.window.onWindowFocusOut.dispatch (); + case WINDOW_LEAVE: + + parent.window.onWindowLeave.dispatch (); + case WINDOW_MINIMIZE: parent.window.__minimized = true; @@ -650,11 +658,13 @@ private class WindowEventInfo { var WINDOW_ACTIVATE = 0; var WINDOW_CLOSE = 1; var WINDOW_DEACTIVATE = 2; - var WINDOW_FOCUS_IN = 3; - var WINDOW_FOCUS_OUT = 4; - var WINDOW_MINIMIZE = 5; - var WINDOW_MOVE = 6; - var WINDOW_RESIZE = 7; - var WINDOW_RESTORE = 8; + var WINDOW_ENTER = 3; + var WINDOW_FOCUS_IN = 4; + var WINDOW_FOCUS_OUT = 5; + var WINDOW_LEAVE = 6; + var WINDOW_MINIMIZE = 7; + var WINDOW_MOVE = 8; + var WINDOW_RESIZE = 9; + var WINDOW_RESTORE = 10; } \ No newline at end of file diff --git a/lime/app/Application.hx b/lime/app/Application.hx index 90d455be0..9fa4dad85 100644 --- a/lime/app/Application.hx +++ b/lime/app/Application.hx @@ -119,9 +119,11 @@ class Application extends Module { window.onWindowActivate.add (onWindowActivate); window.onWindowClose.add (onWindowClose); window.onWindowDeactivate.add (onWindowDeactivate); + window.onWindowEnter.add (onWindowEnter); window.onWindowFocusIn.add (onWindowFocusIn); window.onWindowFocusOut.add (onWindowFocusOut); window.onWindowFullscreen.add (onWindowFullscreen); + window.onWindowLeave.add (onWindowLeave); window.onWindowMinimize.add (onWindowMinimize); window.onWindowMove.add (onWindowMove); window.onWindowResize.add (onWindowResize); @@ -393,6 +395,17 @@ class Application extends Module { } + public override function onWindowEnter ():Void { + + for (module in modules) { + + module.onWindowEnter (); + + } + + } + + public override function onWindowFocusIn ():Void { for (module in modules) { @@ -426,6 +439,17 @@ class Application extends Module { } + public override function onWindowLeave ():Void { + + for (module in modules) { + + module.onWindowLeave (); + + } + + } + + public override function onWindowMinimize ():Void { for (module in modules) { diff --git a/lime/app/IModule.hx b/lime/app/IModule.hx index 5b26d41f2..4627999ae 100644 --- a/lime/app/IModule.hx +++ b/lime/app/IModule.hx @@ -178,6 +178,12 @@ interface IModule { public function onWindowDeactivate ():Void; + /** + * Called when a window enter event is fired + */ + public function onWindowEnter ():Void; + + /** * Called when a window focus in event is fired */ @@ -196,6 +202,12 @@ interface IModule { public function onWindowFullscreen ():Void; + /** + * Called when a window leave event is fired + */ + public function onWindowLeave ():Void; + + /** * Called when a window move event is fired * @param x The x position of the window diff --git a/lime/app/Module.hx b/lime/app/Module.hx index 05573667c..88b469fad 100644 --- a/lime/app/Module.hx +++ b/lime/app/Module.hx @@ -153,6 +153,12 @@ class Module implements IModule { public function onWindowDeactivate ():Void { } + /** + * Called when a window enter event is fired + */ + public function onWindowEnter ():Void { } + + /** * Called when a window focus in event is fired */ @@ -165,7 +171,21 @@ class Module implements IModule { public function onWindowFocusOut ():Void { } + /** + * Called when a window fullscreen event is fired + */ public function onWindowFullscreen ():Void { } + + + /** + * Called when a mouse leave event is fired + */ + public function onWindowLeave ():Void { } + + + /** + * Called when a window minimize event is fired + */ public function onWindowMinimize ():Void { } diff --git a/lime/ui/Window.hx b/lime/ui/Window.hx index efb4b3dd0..637d01871 100644 --- a/lime/ui/Window.hx +++ b/lime/ui/Window.hx @@ -34,9 +34,11 @@ class Window { public var onWindowActivate = new EventVoid> (); public var onWindowClose = new EventVoid> (); public var onWindowDeactivate = new EventVoid> (); + public var onWindowEnter = new EventVoid> (); public var onWindowFocusIn = new EventVoid> (); public var onWindowFocusOut = new EventVoid> (); public var onWindowFullscreen = new EventVoid> (); + public var onWindowLeave = new EventVoid> (); public var onWindowMinimize = new EventVoid> (); public var onWindowMove = new EventFloat->Void> (); public var onWindowResize = new EventInt->Void> (); diff --git a/project/include/ui/WindowEvent.h b/project/include/ui/WindowEvent.h index 34ee8db1d..a96b33fcc 100644 --- a/project/include/ui/WindowEvent.h +++ b/project/include/ui/WindowEvent.h @@ -13,12 +13,14 @@ namespace lime { WINDOW_ACTIVATE, WINDOW_CLOSE, WINDOW_DEACTIVATE, + WINDOW_ENTER, WINDOW_FOCUS_IN, WINDOW_FOCUS_OUT, + WINDOW_LEAVE, WINDOW_MINIMIZE, WINDOW_MOVE, WINDOW_RESIZE, - WINDOW_RESTORE + WINDOW_RESTORE, }; diff --git a/project/src/backend/sdl/SDLApplication.cpp b/project/src/backend/sdl/SDLApplication.cpp index 3f55c091a..25a153bb7 100644 --- a/project/src/backend/sdl/SDLApplication.cpp +++ b/project/src/backend/sdl/SDLApplication.cpp @@ -149,6 +149,8 @@ namespace lime { switch (event->window.event) { + case SDL_WINDOWEVENT_ENTER: + case SDL_WINDOWEVENT_LEAVE: case SDL_WINDOWEVENT_SHOWN: case SDL_WINDOWEVENT_HIDDEN: case SDL_WINDOWEVENT_FOCUS_GAINED: @@ -351,8 +353,10 @@ namespace lime { case SDL_WINDOWEVENT_SHOWN: windowEvent.type = WINDOW_ACTIVATE; break; case SDL_WINDOWEVENT_CLOSE: windowEvent.type = WINDOW_CLOSE; break; case SDL_WINDOWEVENT_HIDDEN: windowEvent.type = WINDOW_DEACTIVATE; break; + case SDL_WINDOWEVENT_ENTER: windowEvent.type = WINDOW_ENTER; break; case SDL_WINDOWEVENT_FOCUS_GAINED: windowEvent.type = WINDOW_FOCUS_IN; break; case SDL_WINDOWEVENT_FOCUS_LOST: windowEvent.type = WINDOW_FOCUS_OUT; break; + case SDL_WINDOWEVENT_LEAVE: windowEvent.type = WINDOW_LEAVE; break; case SDL_WINDOWEVENT_MINIMIZED: windowEvent.type = WINDOW_MINIMIZE; break; case SDL_WINDOWEVENT_MOVED: From ca89748dc91ce07e8a7811cc05a68f27e5290346 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Fri, 24 Apr 2015 09:29:05 -0700 Subject: [PATCH 21/31] Minor tweak --- project/src/ui/WindowEvent.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/project/src/ui/WindowEvent.cpp b/project/src/ui/WindowEvent.cpp index fae1090b6..e67960ca9 100644 --- a/project/src/ui/WindowEvent.cpp +++ b/project/src/ui/WindowEvent.cpp @@ -19,6 +19,7 @@ namespace lime { WindowEvent::WindowEvent () { type = WINDOW_ACTIVATE; + width = 0; height = 0; x = 0; From ba97f1e1c597a24d1bca000c8f1cab4b67ecf648 Mon Sep 17 00:00:00 2001 From: Ben Morris Date: Fri, 24 Apr 2015 23:09:53 -0700 Subject: [PATCH 22/31] Font embedding file not found fix. --- lime/Assets.hx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lime/Assets.hx b/lime/Assets.hx index f5e3a0ad0..971fda881 100644 --- a/lime/Assets.hx +++ b/lime/Assets.hx @@ -1390,7 +1390,10 @@ class Assets { case EConst(CString(filePath)): - var path = Context.resolvePath (filePath); + var path = filePath; + if (!sys.FileSystem.exists(filePath)) { + path = Context.resolvePath (filePath); + } var bytes = File.getBytes (path); var resourceName = "__ASSET__" + metaName + "_" + (classType.pack.length > 0 ? classType.pack.join ("_") + "_" : "") + classType.name; @@ -1490,7 +1493,10 @@ class Assets { case EConst(CString(filePath)): - path = Context.resolvePath (filePath); + path = filePath; + if (!sys.FileSystem.exists(filePath)) { + path = Context.resolvePath (filePath); + } default: From 2d3576743d5d7b8c8e6272a92a022488a9be76be Mon Sep 17 00:00:00 2001 From: MrCdK Date: Mon, 27 Apr 2015 21:17:35 +0200 Subject: [PATCH 23/31] Let's make a float division and not an integer one --- project/src/graphics/utils/ImageDataUtil.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/src/graphics/utils/ImageDataUtil.cpp b/project/src/graphics/utils/ImageDataUtil.cpp index 649e11b1b..eb60eb75a 100644 --- a/project/src/graphics/utils/ImageDataUtil.cpp +++ b/project/src/graphics/utils/ImageDataUtil.cpp @@ -171,7 +171,7 @@ namespace lime { sourceOffset = (row * sourceStride) + (column * 4); offset = ((row + rowOffset) * stride) + ((column + columnOffset) * 4); - sourceAlpha = sourceData[sourceOffset + 3] / 255; + sourceAlpha = sourceData[sourceOffset + 3] / 255.0; oneMinusSourceAlpha = (1 - sourceAlpha); data[offset] = __clamp[int (sourceData[sourceOffset] * sourceAlpha)] + __clamp[int(data[offset] * oneMinusSourceAlpha)]; From 2f902dd07251ba6228200042801bd9dfe182d050 Mon Sep 17 00:00:00 2001 From: MrCdK Date: Tue, 28 Apr 2015 00:51:49 +0200 Subject: [PATCH 24/31] Fix haxe part of issue https://github.com/openfl/openfl/issues/635 --- lime/graphics/utils/ImageDataUtil.hx | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lime/graphics/utils/ImageDataUtil.hx b/lime/graphics/utils/ImageDataUtil.hx index ae85b5f8b..a77b3d3bb 100644 --- a/lime/graphics/utils/ImageDataUtil.hx +++ b/lime/graphics/utils/ImageDataUtil.hx @@ -182,9 +182,9 @@ class ImageDataUtil { } - #if ((cpp || neko) && !disable_cffi) - if (!System.disableCFFI) lime_image_data_util_copy_pixels (image, sourceImage, sourceRect, destPoint, mergeAlpha); else - #end + //#if ((cpp || neko) && !disable_cffi) + //if (!System.disableCFFI) lime_image_data_util_copy_pixels (image, sourceImage, sourceRect, destPoint, mergeAlpha); else + //#end { var rowOffset = Std.int (destPoint.y + image.offsetY - sourceRect.y - sourceImage.offsetY); @@ -228,6 +228,8 @@ class ImageDataUtil { } else { var sourceAlpha:Float; + var destAlpha:Float; + var outA:Float; var oneMinusSourceAlpha:Float; for (row in Std.int (sourceRect.top + sourceImage.offsetY)...Std.int (sourceRect.bottom + sourceImage.offsetY)) { @@ -237,13 +239,16 @@ class ImageDataUtil { sourceOffset = (row * sourceStride) + (column * 4); offset = ((row + rowOffset) * stride) + ((column + columnOffset) * 4); - sourceAlpha = sourceData[sourceOffset + 3] / 255; + sourceAlpha = sourceData[sourceOffset + 3] / 255.0; + destAlpha = data[offset + 3] / 255.0; oneMinusSourceAlpha = (1 - sourceAlpha); - data[offset] = __clamp[Std.int (sourceData[sourceOffset] * sourceAlpha)] + __clamp[Std.int(data[offset] * oneMinusSourceAlpha)]; - data[offset + 1] = __clamp[Std.int (sourceData[sourceOffset + 1] * sourceAlpha)] + __clamp[Std.int(data[offset + 1] * oneMinusSourceAlpha)]; - data[offset + 2] = __clamp[Std.int (sourceData[sourceOffset + 2] * sourceAlpha)] + __clamp[Std.int(data[offset + 2] * oneMinusSourceAlpha)]; - data[offset + 3] = __clamp[Std.int (sourceData[sourceOffset + 3] * sourceAlpha)] + __clamp[Std.int(data[offset + 3] * oneMinusSourceAlpha)]; + outA = sourceAlpha + destAlpha * oneMinusSourceAlpha; + data[offset + 0] = __clamp[Math.round ((sourceData[sourceOffset + 0] * sourceAlpha + data[offset + 0] * destAlpha * oneMinusSourceAlpha) / outA)]; + data[offset + 1] = __clamp[Math.round ((sourceData[sourceOffset + 1] * sourceAlpha + data[offset + 1] * destAlpha * oneMinusSourceAlpha) / outA)]; + data[offset + 2] = __clamp[Math.round ((sourceData[sourceOffset + 2] * sourceAlpha + data[offset + 2] * destAlpha * oneMinusSourceAlpha) / outA)]; + data[offset + 3] = __clamp[Math.round (outA * 255.0)]; + } From a7bfb9936be89ef7952f44d7837bf6bd5625b628 Mon Sep 17 00:00:00 2001 From: MrCdK Date: Tue, 28 Apr 2015 01:34:25 +0200 Subject: [PATCH 25/31] Implemented the cpp part --- lime/graphics/utils/ImageDataUtil.hx | 6 +++--- project/src/graphics/utils/ImageDataUtil.cpp | 12 ++++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lime/graphics/utils/ImageDataUtil.hx b/lime/graphics/utils/ImageDataUtil.hx index a77b3d3bb..94fffae68 100644 --- a/lime/graphics/utils/ImageDataUtil.hx +++ b/lime/graphics/utils/ImageDataUtil.hx @@ -182,9 +182,9 @@ class ImageDataUtil { } - //#if ((cpp || neko) && !disable_cffi) - //if (!System.disableCFFI) lime_image_data_util_copy_pixels (image, sourceImage, sourceRect, destPoint, mergeAlpha); else - //#end + #if ((cpp || neko) && !disable_cffi) + if (!System.disableCFFI) lime_image_data_util_copy_pixels (image, sourceImage, sourceRect, destPoint, mergeAlpha); else + #end { var rowOffset = Std.int (destPoint.y + image.offsetY - sourceRect.y - sourceImage.offsetY); diff --git a/project/src/graphics/utils/ImageDataUtil.cpp b/project/src/graphics/utils/ImageDataUtil.cpp index eb60eb75a..025225d9e 100644 --- a/project/src/graphics/utils/ImageDataUtil.cpp +++ b/project/src/graphics/utils/ImageDataUtil.cpp @@ -162,6 +162,8 @@ namespace lime { } else { float sourceAlpha; + float destAlpha; + float outA; float oneMinusSourceAlpha; for (int row = sourceRect->y + sourceImage->offsetY; row < rows; row++) { @@ -172,12 +174,14 @@ namespace lime { offset = ((row + rowOffset) * stride) + ((column + columnOffset) * 4); sourceAlpha = sourceData[sourceOffset + 3] / 255.0; + destAlpha = data[offset + 3] / 255.0; oneMinusSourceAlpha = (1 - sourceAlpha); - data[offset] = __clamp[int (sourceData[sourceOffset] * sourceAlpha)] + __clamp[int(data[offset] * oneMinusSourceAlpha)]; - data[offset + 1] = __clamp[int (sourceData[sourceOffset + 1] * sourceAlpha)] + __clamp[int(data[offset + 1] * oneMinusSourceAlpha)]; - data[offset + 2] = __clamp[int (sourceData[sourceOffset + 2] * sourceAlpha)] + __clamp[int(data[offset + 2] * oneMinusSourceAlpha)]; - data[offset + 3] = __clamp[int (sourceData[sourceOffset + 3] * sourceAlpha)] + __clamp[int(data[offset + 3] * oneMinusSourceAlpha)]; + outA = sourceAlpha + destAlpha * oneMinusSourceAlpha; + data[offset + 0] = __clamp[(int) round ((sourceData[sourceOffset + 0] * sourceAlpha + data[offset + 0] * destAlpha * oneMinusSourceAlpha) / outA)]; + data[offset + 1] = __clamp[(int) round ((sourceData[sourceOffset + 1] * sourceAlpha + data[offset + 1] * destAlpha * oneMinusSourceAlpha) / outA)]; + data[offset + 2] = __clamp[(int) round ((sourceData[sourceOffset + 2] * sourceAlpha + data[offset + 2] * destAlpha * oneMinusSourceAlpha) / outA)]; + data[offset + 3] = __clamp[(int) round (outA * 255.0)]; } From 8439a6898ac0189efb868c6218e80e508c844add Mon Sep 17 00:00:00 2001 From: MrCdK Date: Tue, 28 Apr 2015 02:29:51 +0200 Subject: [PATCH 26/31] Add math.h for round --- project/src/graphics/utils/ImageDataUtil.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/project/src/graphics/utils/ImageDataUtil.cpp b/project/src/graphics/utils/ImageDataUtil.cpp index 025225d9e..a639e3740 100644 --- a/project/src/graphics/utils/ImageDataUtil.cpp +++ b/project/src/graphics/utils/ImageDataUtil.cpp @@ -1,6 +1,7 @@ #include #include #include +#include namespace lime { From f588dcdf091911f321d5ee5c54a15a49e2ecc3f3 Mon Sep 17 00:00:00 2001 From: MrCdK Date: Tue, 28 Apr 2015 02:54:01 +0200 Subject: [PATCH 27/31] Dunno why round isn't working, so second another workaround --- project/src/graphics/utils/ImageDataUtil.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/project/src/graphics/utils/ImageDataUtil.cpp b/project/src/graphics/utils/ImageDataUtil.cpp index a639e3740..70863675a 100644 --- a/project/src/graphics/utils/ImageDataUtil.cpp +++ b/project/src/graphics/utils/ImageDataUtil.cpp @@ -1,7 +1,6 @@ #include #include #include -#include namespace lime { @@ -179,10 +178,10 @@ namespace lime { oneMinusSourceAlpha = (1 - sourceAlpha); outA = sourceAlpha + destAlpha * oneMinusSourceAlpha; - data[offset + 0] = __clamp[(int) round ((sourceData[sourceOffset + 0] * sourceAlpha + data[offset + 0] * destAlpha * oneMinusSourceAlpha) / outA)]; - data[offset + 1] = __clamp[(int) round ((sourceData[sourceOffset + 1] * sourceAlpha + data[offset + 1] * destAlpha * oneMinusSourceAlpha) / outA)]; - data[offset + 2] = __clamp[(int) round ((sourceData[sourceOffset + 2] * sourceAlpha + data[offset + 2] * destAlpha * oneMinusSourceAlpha) / outA)]; - data[offset + 3] = __clamp[(int) round (outA * 255.0)]; + data[offset + 0] = __clamp[int (0.5 + ((sourceData[sourceOffset + 0] * sourceAlpha + data[offset + 0] * destAlpha * oneMinusSourceAlpha) / outA))]; + data[offset + 1] = __clamp[int (0.5 + ((sourceData[sourceOffset + 1] * sourceAlpha + data[offset + 1] * destAlpha * oneMinusSourceAlpha) / outA))]; + data[offset + 2] = __clamp[int (0.5 + ((sourceData[sourceOffset + 2] * sourceAlpha + data[offset + 2] * destAlpha * oneMinusSourceAlpha) / outA))]; + data[offset + 3] = __clamp[int (0.5 + (outA * 255.0))]; } From 2ba1fcb5b1eff8141364e4a331fa36fc46072881 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Wed, 29 Apr 2015 15:41:00 -0700 Subject: [PATCH 28/31] Don't prevent default on space and arrow keys --- lime/_backend/html5/HTML5Application.hx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lime/_backend/html5/HTML5Application.hx b/lime/_backend/html5/HTML5Application.hx index 20acf56fc..0af060c6e 100644 --- a/lime/_backend/html5/HTML5Application.hx +++ b/lime/_backend/html5/HTML5Application.hx @@ -156,11 +156,11 @@ class HTML5Application { // space and arrow keys - switch (event.keyCode) { - - case 32, 37, 38, 39, 40: event.preventDefault (); - - } + //switch (event.keyCode) { + // + //case 32, 37, 38, 39, 40: event.preventDefault (); + // + //} var keyCode = cast convertKeyCode (event.keyCode != null ? event.keyCode : event.which); var modifier = (event.shiftKey ? (KeyModifier.SHIFT) : 0) | (event.ctrlKey ? (KeyModifier.CTRL) : 0) | (event.altKey ? (KeyModifier.ALT) : 0) | (event.metaKey ? (KeyModifier.META) : 0); From b5129ed8a677b6ed0135112b4f7803a449e91b50 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Thu, 30 Apr 2015 10:25:17 -0700 Subject: [PATCH 29/31] Update SDL commit version for ANGLE config support --- project/lib/sdl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/lib/sdl b/project/lib/sdl index 47e23f265..839888c9f 160000 --- a/project/lib/sdl +++ b/project/lib/sdl @@ -1 +1 @@ -Subproject commit 47e23f2659d729c16af96b91f6fe733e6f917ca0 +Subproject commit 839888c9ffe7aa684e6b5d888d1ae89055b6c79d From 41a2c292dd3c3158f56ed3a4b9526f89ae4c8a5a Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Thu, 30 Apr 2015 10:43:09 -0700 Subject: [PATCH 30/31] Prepare for ANGLE support --- project/Build.xml | 2 +- project/src/backend/sdl/SDLWindow.cpp | 9 +++++++++ project/src/graphics/opengl/OpenGL.h | 1 + project/src/graphics/opengl/OpenGLExtensions.h | 13 ++++++++++++- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/project/Build.xml b/project/Build.xml index 01a5864c5..f37c2bb3e 100644 --- a/project/Build.xml +++ b/project/Build.xml @@ -30,7 +30,6 @@ - @@ -141,6 +140,7 @@ + diff --git a/project/src/backend/sdl/SDLWindow.cpp b/project/src/backend/sdl/SDLWindow.cpp index 81baefb13..068d6d47c 100644 --- a/project/src/backend/sdl/SDLWindow.cpp +++ b/project/src/backend/sdl/SDLWindow.cpp @@ -22,6 +22,15 @@ namespace lime { if (flags & WINDOW_FLAG_RESIZABLE) sdlFlags |= SDL_WINDOW_RESIZABLE; if (flags & WINDOW_FLAG_BORDERLESS) sdlFlags |= SDL_WINDOW_BORDERLESS; + #if defined (HX_WINDOWS) && defined (NATIVE_TOOLKIT_SDL_ANGLE) + + SDL_GL_SetAttribute (SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); + SDL_GL_SetAttribute (SDL_GL_CONTEXT_MAJOR_VERSION, 2); + SDL_GL_SetAttribute (SDL_GL_CONTEXT_MINOR_VERSION, 0); + SDL_SetHint (SDL_HINT_VIDEO_WIN_D3DCOMPILER, "d3dcompiler_47.dll"); + + #endif + if (flags & WINDOW_FLAG_DEPTH_BUFFER) { SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 32 - (flags & WINDOW_FLAG_STENCIL_BUFFER) ? 8 : 0); diff --git a/project/src/graphics/opengl/OpenGL.h b/project/src/graphics/opengl/OpenGL.h index 95a830f95..cbc5c1395 100644 --- a/project/src/graphics/opengl/OpenGL.h +++ b/project/src/graphics/opengl/OpenGL.h @@ -60,6 +60,7 @@ #include typedef ptrdiff_t GLsizeiptrARB; #define NEED_EXTENSIONS +#define DYNAMIC_OGL #include #include diff --git a/project/src/graphics/opengl/OpenGLExtensions.h b/project/src/graphics/opengl/OpenGLExtensions.h index 7f78a5d24..3dbb07a75 100644 --- a/project/src/graphics/opengl/OpenGLExtensions.h +++ b/project/src/graphics/opengl/OpenGLExtensions.h @@ -12,6 +12,10 @@ #include "OpenGLBindings.h" +#ifdef LIME_SDL +#include +#endif + #ifdef DECLARE_EXTENSION @@ -27,7 +31,14 @@ #elif defined(GET_EXTENSION) -#ifdef HX_WINDOWS +#ifdef LIME_SDL + #define OGL_EXT(func,ret,args) \ + {\ + *(void **)&lime::func = (void *)SDL_GL_GetProcAddress(#func);\ + if (!func) \ + *(void **)&lime::func = (void *)SDL_GL_GetProcAddress(#func "ARB");\ + } +#elif HX_WINDOWS #define OGL_EXT(func,ret,args) \ {\ *(void **)&lime::func = (void *)wglGetProcAddress(#func);\ From 9866048fa1ffb4a9f44ebe4db5e90b041ee84b32 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Thu, 30 Apr 2015 11:18:17 -0700 Subject: [PATCH 31/31] Fix define for LIME_SDL_ANGLE --- project/Build.xml | 5 ++++- project/lib/sdl | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/project/Build.xml b/project/Build.xml index f37c2bb3e..34d3135a5 100644 --- a/project/Build.xml +++ b/project/Build.xml @@ -28,6 +28,9 @@ + + + @@ -140,7 +143,7 @@ - + diff --git a/project/lib/sdl b/project/lib/sdl index 839888c9f..c40b7c2e0 160000 --- a/project/lib/sdl +++ b/project/lib/sdl @@ -1 +1 @@ -Subproject commit 839888c9ffe7aa684e6b5d888d1ae89055b6c79d +Subproject commit c40b7c2e076a2e74e0c3c3d754ac4b9343988b98