diff --git a/lime/graphics/Image.hx b/lime/graphics/Image.hx index 3542011af..022a3d2aa 100644 --- a/lime/graphics/Image.hx +++ b/lime/graphics/Image.hx @@ -39,31 +39,53 @@ class Image { public var rect (get, null):Rectangle; public var src (get, set):Dynamic; public var transparent (get, set):Bool; + public var type:ImageType; public var width:Int; - private var __type:DataStoreType; - - public function new (buffer:ImageBuffer, context:RenderContext = null) { + public function new (buffer:ImageBuffer = null, offsetX:Int = 0, offsetY:Int = 0, width:Int = 0, height:Int = 0, color:Null = null, type:ImageType = null) { - this.buffer = buffer; + this.offsetX = offsetX; + this.offsetY = offsetY; + this.width = width; + this.height = height; - if (context == null) { + if (type == null) { - context = Application.__instance.window.currentRenderer.context; + this.type = switch (Application.__instance.window.currentRenderer.context) { + + case DOM (_), CANVAS (_): CANVAS; + case FLASH (_): FLASH; + default: DATA; + + } + + } else { + + this.type = type; } - width = buffer.width; - height = buffer.height; - offsetX = 0; - offsetY = 0; - - __type = switch (context) { + if (buffer == null) { - case DOM (_), CANVAS (_): CANVAS; - case FLASH (_): FLASH; - default: DATA; + if (width > 0 && height > 0) { + + this.buffer = new ImageBuffer (new UInt8Array (width * height * 4), width, height); + + if (color != null) { + + fillRect (new Rectangle (0, 0, width, height), color); + + } + + } + + } else { + + this.buffer = buffer; + + if (width == 0) this.width = buffer.width; + if (height == 0) this.height = buffer.height; } @@ -76,14 +98,7 @@ class Image { ImageCanvasUtil.sync (this); #end - var image = new Image (buffer.clone (), null); - image.__type = __type; - - image.width = width; - image.height = height; - image.offsetX = offsetX; - image.offsetY = offsetY; - + var image = new Image (buffer.clone (), offsetX, offsetY, width, height, null, type); return image; } @@ -94,7 +109,7 @@ class Image { rect = __clipRect (rect); if (buffer == null || rect == null) return; - switch (__type) { + switch (type) { case CANVAS: @@ -113,6 +128,8 @@ class Image { rect.offset (offsetX, offsetY); buffer.__srcBitmapData.colorTransform (rect.__toFlashRectangle (), colorMatrix.__toFlashColorTransform ()); + default: + } } @@ -128,7 +145,7 @@ class Image { 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; - switch (__type) { + switch (type) { case CANVAS: @@ -162,6 +179,8 @@ class Image { destPoint.offset (offsetX, offsetY); buffer.__srcBitmapData.copyChannel (sourceImage.buffer.src, sourceRect.__toFlashRectangle (), destPoint.__toFlashPoint (), srcChannel, dstChannel); + + default: } @@ -176,7 +195,7 @@ class Image { if (sourceRect.y + sourceRect.height > sourceImage.height) sourceRect.height = sourceImage.height - sourceRect.y; if (sourceRect.width <= 0 || sourceRect.height <= 0) return; - switch (__type) { + switch (type) { case CANVAS: @@ -203,6 +222,8 @@ class Image { buffer.__srcBitmapData.copyPixels (sourceImage.buffer.__srcBitmapData, sourceRect.__toFlashRectangle (), destPoint.__toFlashPoint (), alphaImage != null ? alphaImage.buffer.src : null, alphaPoint != null ? alphaPoint.__toFlashPoint () : null, mergeAlpha); + default: + } } @@ -213,7 +234,7 @@ class Image { rect = __clipRect (rect); if (buffer == null || rect == null) return; - switch (__type) { + switch (type) { case CANVAS: @@ -231,6 +252,8 @@ class Image { rect.offset (offsetX, offsetY); buffer.__srcBitmapData.fillRect (rect.__toFlashRectangle (), color); + + default: } @@ -241,7 +264,7 @@ class Image { if (buffer == null) return; - switch (__type) { + switch (type) { case CANVAS: @@ -259,6 +282,8 @@ class Image { buffer.__srcBitmapData.floodFill (x + offsetX, y + offsetY, color); + default: + } } @@ -342,7 +367,7 @@ class Image { if (buffer == null || x < 0 || y < 0 || x >= width || y >= height) return 0; - switch (__type) { + switch (type) { case CANVAS: @@ -360,6 +385,10 @@ class Image { return buffer.__srcBitmapData.getPixel (x + offsetX, y + offsetY); + default: + + return 0; + } } @@ -369,7 +398,7 @@ class Image { if (buffer == null || x < 0 || y < 0 || x >= width || y >= height) return 0; - switch (__type) { + switch (type) { case CANVAS: @@ -387,6 +416,10 @@ class Image { return buffer.__srcBitmapData.getPixel32 (x + offsetX, y + offsetY); + default: + + return 0; + } } @@ -396,7 +429,7 @@ class Image { if (buffer == null || x < 0 || y < 0 || x >= width || y >= height) return; - switch (__type) { + switch (type) { case CANVAS: @@ -414,6 +447,8 @@ class Image { buffer.__srcBitmapData.setPixel (x + offsetX, y + offsetX, color); + default: + } } @@ -423,7 +458,7 @@ class Image { if (buffer == null || x < 0 || y < 0 || x >= width || y >= height) return; - switch (__type) { + switch (type) { case CANVAS: @@ -441,6 +476,8 @@ class Image { buffer.__srcBitmapData.setPixel32 (x + offsetX, y + offsetY, color); + default: + } } @@ -548,7 +585,7 @@ class Image { } - switch (__type) { + switch (type) { case CANVAS: @@ -569,6 +606,7 @@ class Image { buffer.height = newHeight; #end + default: } } @@ -589,7 +627,7 @@ class Image { if (value && !buffer.premultiplied) { - switch (__type) { + switch (type) { case DATA: @@ -603,7 +641,7 @@ class Image { } else if (!value && buffer.premultiplied) { - switch (__type) { + switch (type) { case DATA: @@ -674,15 +712,6 @@ class Image { } -private enum DataStoreType { - - CANVAS; - DATA; - FLASH; - -} - - enum ImageChannel { RED; diff --git a/lime/graphics/ImageType.hx b/lime/graphics/ImageType.hx new file mode 100644 index 000000000..72f868cbf --- /dev/null +++ b/lime/graphics/ImageType.hx @@ -0,0 +1,11 @@ +package lime.graphics; + + +enum ImageType { + + CANVAS; + DATA; + FLASH; + CUSTOM; + +} \ No newline at end of file diff --git a/lime/math/ColorMatrix.hx b/lime/math/ColorMatrix.hx index 664626d5f..b8916658d 100644 --- a/lime/math/ColorMatrix.hx +++ b/lime/math/ColorMatrix.hx @@ -116,7 +116,8 @@ abstract ColorMatrix(Float32Array) from Float32Array to Float32Array { private inline function set_alphaMultiplier (value:Float):Float { - return this[18] = value; + this[18] = value; + return value; } @@ -145,7 +146,8 @@ abstract ColorMatrix(Float32Array) from Float32Array to Float32Array { private inline function set_blueMultiplier (value:Float):Float { - return this[12] = value; + this[12] = value; + return value; } @@ -196,7 +198,8 @@ abstract ColorMatrix(Float32Array) from Float32Array to Float32Array { private inline function set_greenMultiplier (value:Float):Float { - return this[6] = value; + this[6] = value; + return value; } @@ -225,7 +228,8 @@ abstract ColorMatrix(Float32Array) from Float32Array to Float32Array { private inline function set_redMultiplier (value:Float):Float { - return this[0] = value; + this[0] = value; + return value; }