Revision: 2515
http://sourceforge.net/p/swingme/code/2515
Author: yuranet
Date: 2021-07-07 09:51:40 +0000 (Wed, 07 Jul 2021)
Log Message:
-----------
draw with color matrix works fully
Modified Paths:
--------------
iOSME/src/android/graphics/ColorMatrix.java
iOSME/src/javax/microedition/lcdui/Graphics.java
iOSME/src/javax/microedition/lcdui/Image.java
iOSME/src/javax/microedition/m3g/Graphics3D.java
iOSME/src/net/yura/ios/plaf/IOSBorder.java
Modified: iOSME/src/android/graphics/ColorMatrix.java
===================================================================
--- iOSME/src/android/graphics/ColorMatrix.java 2021-07-06 14:40:40 UTC (rev 2514)
+++ iOSME/src/android/graphics/ColorMatrix.java 2021-07-07 09:51:40 UTC (rev 2515)
@@ -1,8 +1,12 @@
package android.graphics;
+import java.util.Arrays;
import apple.coreimage.CIFilter;
import apple.coreimage.CIVector;
+/**
+ * class "borrowed" from AOSP
+ */
public class ColorMatrix {
private final float[] mArray = new float[20];
@@ -23,13 +27,9 @@
}
public void reset() {
- float[] a = this.mArray;
-
- for(int i = 19; i > 0; --i) {
- a[i] = 0.0F;
- }
-
- a[0] = a[6] = a[12] = a[18] = 1.0F;
+ final float[] a = mArray;
+ Arrays.fill(a, 0);
+ a[0] = a[6] = a[12] = a[18] = 1;
}
public void set(ColorMatrix src) {
@@ -159,29 +159,23 @@
m[12] = 0.0F;
}
- public int filterRGB(int x, int y, int rgb) {
- int R = rgb >> 16 & 255;
- int G = rgb >> 8 & 255;
- int B = rgb >> 0 & 255;
- int A = rgb >> 24 & 255;
- int r = clamp(this.mArray[0] * (float)R + this.mArray[1] * (float)G + this.mArray[2] * (float)B + this.mArray[3] * (float)A + this.mArray[4]);
- int g = clamp(this.mArray[5] * (float)R + this.mArray[6] * (float)G + this.mArray[7] * (float)B + this.mArray[8] * (float)A + this.mArray[9]);
- int b = clamp(this.mArray[10] * (float)R + this.mArray[11] * (float)G + this.mArray[12] * (float)B + this.mArray[13] * (float)A + this.mArray[14]);
- int a = clamp(this.mArray[15] * (float)R + this.mArray[16] * (float)G + this.mArray[17] * (float)B + this.mArray[18] * (float)A + this.mArray[19]);
- return (a & 255) << 24 | (r & 255) << 16 | (g & 255) << 8 | (b & 255) << 0;
- }
+ @Override
+ public boolean equals(Object obj) {
+ // if (obj == this) return true; -- NaN value would mean matrix != itself
+ if (!(obj instanceof ColorMatrix)) {
+ return false;
+ }
- private static int clamp(float value) {
- if(value < 0.0F) {
- value = 0.0F;
- } else if(value > 255.0F) {
- value = 255.0F;
+ // we don't use Arrays.equals(), since that considers NaN == NaN
+ final float[] other = ((ColorMatrix) obj).mArray;
+ for (int i = 0; i < 20; i++) {
+ if (other[i] != mArray[i]) {
+ return false;
+ }
}
-
- return (int)value;
+ return true;
}
-
public CIFilter toCIFilter() {
CIFilter filter = CIFilter.filterWithName("CIColorMatrix");
@@ -199,5 +193,4 @@
return filter;
}
-
}
Modified: iOSME/src/javax/microedition/lcdui/Graphics.java
===================================================================
--- iOSME/src/javax/microedition/lcdui/Graphics.java 2021-07-06 14:40:40 UTC (rev 2514)
+++ iOSME/src/javax/microedition/lcdui/Graphics.java 2021-07-07 09:51:40 UTC (rev 2515)
@@ -8,9 +8,13 @@
import apple.coregraphics.struct.CGPoint;
import apple.coregraphics.struct.CGRect;
import apple.coregraphics.struct.CGSize;
+import apple.coreimage.CIContext;
import apple.coreimage.CIFilter;
+import apple.coreimage.CIImage;
+import apple.coreimage.c.CoreImage;
import apple.foundation.NSMutableDictionary;
import apple.foundation.NSString;
+import apple.imageio.enums.CGImagePropertyOrientation;
import apple.uikit.UIBezierPath;
import apple.uikit.UIColor;
import apple.uikit.UIImage;
@@ -379,22 +383,60 @@
// we get the image first, this may close a current bitmap context
UIImage uiImageToDraw = image.getUIImage();
- drawImage(uiImageToDraw, ax, ay, image.getWidth(), image.getHeight());
+ drawInRect(uiImageToDraw, ax, ay, image.getWidth(), image.getHeight());
}
- public void drawImage(UIImage image, int x, int y, int width, int height) {
- CGRect imageRect = getDestRect(x, y, width, height);
- boolean same = isCurrentContext();
-
- if (!same) UIKit.UIGraphicsPushContext(context);
-
+ public void drawInRect(UIImage image, int x, int y, int width, int height) {
if (filter != null) {
- Image.drawInRect(context, image, imageRect, filter);
+ drawInRect(image, x, y, width, height, filter);
}
else {
- image.drawInRect(imageRect);
+ boolean same = isCurrentContext();
+ if (!same) UIKit.UIGraphicsPushContext(context);
+ image.drawInRect(getDestRect(x, y, width, height));
+ if (!same) UIKit.UIGraphicsPopContext();
}
+ }
+ public void drawInRect(UIImage uiImageToDraw, int x, int y, int width, int height, CIFilter filter) {
+ CGRect inRect = getDestRect(x, y, width, height);
+
+ // uiImageToDraw.CIImage() does not seem to work here
+ filter.setValueForKey(CIImage.imageWithCGImage(uiImageToDraw.CGImage()), CoreImage.kCIInputImageKey());
+
+ CIImage output = filter.outputImage();
+ if (output == null) {
+ throw new IllegalStateException("outputImage is null");
+ }
+
+ // drawImageInRectFromRect defaults to drawing upside down, to avoid this we flip the image
+ // not sure whats difference between imageByApplyingOrientation and imageByApplyingCGOrientation
+ output = output.imageByApplyingOrientation(CGImagePropertyOrientation.DownMirrored);
+
+ //CGImageRef cgImage = CIContext.alloc().init().createCGImageFromRect(output, output.extent());
+ //CoreGraphics.CGContextDrawImage(context, inRect, cgImage);
+
+ CIContext c = CIContext.contextWithCGContextOptions(context, null);
+ c.drawImageInRectFromRect(output, inRect, output.extent());
+
+ // TODO remove the image from the filter, this does not work
+ //filter.setNilValueForKey(CoreImage.kCIInputImageKey());
+ }
+
+ public void drawInRect(UIImage uiImageToDraw, int x, int y, int width, int height, CGAffineTransform affineTransform) {
+ CGRect rect = new CGRect(new CGPoint(x, y), new CGSize(width, height));
+ boolean same = isCurrentContext();
+
+ if (!same) UIKit.UIGraphicsPushContext(context);
+
+ CoreGraphics.CGContextTranslateCTM(context, tx, ty);
+ CoreGraphics.CGContextConcatCTM(context, affineTransform);
+
+ uiImageToDraw.drawInRect(rect);
+
+ CoreGraphics.CGContextConcatCTM(context, CoreGraphics.CGAffineTransformInvert(affineTransform));
+ CoreGraphics.CGContextTranslateCTM(context, -tx, -ty);
+
if (!same) UIKit.UIGraphicsPopContext();
}
@@ -497,7 +539,7 @@
UIImage transformed = src.getUIImage(xSrc, ySrc, width, height, transform);
- drawImage(transformed, anchorX, anchorY, destWidth, destHeight);
+ drawInRect(transformed, anchorX, anchorY, destWidth, destHeight);
}
/**
Modified: iOSME/src/javax/microedition/lcdui/Image.java
===================================================================
--- iOSME/src/javax/microedition/lcdui/Image.java 2021-07-06 14:40:40 UTC (rev 2514)
+++ iOSME/src/javax/microedition/lcdui/Image.java 2021-07-07 09:51:40 UTC (rev 2515)
@@ -7,24 +7,14 @@
import javax.microedition.lcdui.game.Sprite;
import android.graphics.ColorMatrix;
import org.moe.natj.general.ptr.BytePtr;
-import org.moe.natj.general.ptr.ConstIntPtr;
import org.moe.natj.general.ptr.IntPtr;
-import org.moe.natj.general.ptr.VoidPtr;
import org.moe.natj.general.ptr.impl.PtrFactory;
-import apple.corefoundation.opaque.CFDataRef;
import apple.coregraphics.opaque.CGContextRef;
-import apple.coregraphics.opaque.CGDataProviderRef;
import apple.coregraphics.opaque.CGImageRef;
import apple.coregraphics.struct.CGPoint;
import apple.coregraphics.struct.CGRect;
import apple.coregraphics.struct.CGSize;
-import apple.coreimage.CIContext;
-import apple.coreimage.CIFilter;
-import apple.coreimage.CIImage;
-import apple.coreimage.CIVector;
-import apple.coreimage.c.CoreImage;
import apple.foundation.NSData;
-import apple.foundation.NSDictionary;
import apple.uikit.UIImage;
import apple.uikit.c.UIKit;
import apple.coregraphics.c.CoreGraphics;
@@ -319,29 +309,6 @@
}
public static void filter(Image source, Image bm, ColorMatrix cm) {
- Graphics dist = bm.getGraphics();
- UIImage src = source.getUIImage();
- drawInRect(dist.getContext(), src, new CGRect(CoreGraphics.CGPointZero(), src.size()), cm.toCIFilter());
+ bm.getGraphics().drawInRect(source.getUIImage(), 0, 0, source.getWidth(), source.getHeight(), cm.toCIFilter());
}
-
- public static void drawInRect(CGContextRef context, UIImage uiImageToDraw, CGRect inRect, CIFilter filter) {
- filter.setValueForKey(CIImage.imageWithCGImage(uiImageToDraw.CGImage()), CoreImage.kCIInputImageKey());
-
- CIImage output = filter.outputImage();
- if (output == null) {
- //uiImageToDraw.drawInRect(inRect);
- //if (true) return;
-
- throw new IllegalStateException("outputImage is null");
- }
-
- //CGImageRef cgImage = CIContext.alloc().init().createCGImageFromRect(output, output.extent());
- //CoreGraphics.CGContextDrawImage(context, inRect, cgImage);
-
- CIContext c = CIContext.contextWithCGContextOptions(context, null);
- c.drawImageInRectFromRect(output, inRect, output.extent());
-
- // remove the image from the filter
- //filter.setNilValueForKey(CoreImage.kCIInputImageKey());
- }
}
Modified: iOSME/src/javax/microedition/m3g/Graphics3D.java
===================================================================
--- iOSME/src/javax/microedition/m3g/Graphics3D.java 2021-07-06 14:40:40 UTC (rev 2514)
+++ iOSME/src/javax/microedition/m3g/Graphics3D.java 2021-07-07 09:51:40 UTC (rev 2515)
@@ -3,12 +3,6 @@
import java.util.Hashtable;
import javax.microedition.lcdui.Graphics;
-import apple.coregraphics.opaque.CGContextRef;
-import apple.coregraphics.struct.CGPoint;
-import apple.coregraphics.struct.CGRect;
-import apple.coregraphics.struct.CGSize;
-import apple.uikit.UIImage;
-import apple.uikit.c.UIKit;
public final class Graphics3D {
@@ -52,7 +46,7 @@
targetGraphics.fillRect(vpX, vpY, vpW, vpH);
}
else {
- targetGraphics.drawImage(background.getImage().getImage().getUIImage(), vpX, vpY,vpW, vpH);
+ targetGraphics.drawInRect(background.getImage().getImage().getUIImage(), vpX, vpY, vpW, vpH);
}
}
Modified: iOSME/src/net/yura/ios/plaf/IOSBorder.java
===================================================================
--- iOSME/src/net/yura/ios/plaf/IOSBorder.java 2021-07-06 14:40:40 UTC (rev 2514)
+++ iOSME/src/net/yura/ios/plaf/IOSBorder.java 2021-07-07 09:51:40 UTC (rev 2515)
@@ -5,14 +5,7 @@
import net.yura.mobile.gui.components.Component;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.game.Sprite;
-import apple.coregraphics.c.CoreGraphics;
-import apple.coregraphics.opaque.CGContextRef;
-import apple.coregraphics.struct.CGAffineTransform;
-import apple.coregraphics.struct.CGPoint;
-import apple.coregraphics.struct.CGRect;
-import apple.coregraphics.struct.CGSize;
import apple.uikit.UIImage;
-import apple.uikit.c.UIKit;
public class IOSBorder extends EmptyBorder {
@@ -28,29 +21,10 @@
int transform = g.getTransform();
if (transform == Sprite.TRANS_NONE) {
- g.getGraphics().drawImage(resizableImage, - left, - top, width + left + right, height + top + bottom);
+ g.getGraphics().drawInRect(resizableImage, - left, - top, width + left + right, height + top + bottom);
}
else {
- int tx = g.getGraphics().getTranslateX();
- int ty = g.getGraphics().getTranslateY();
-
- boolean same = g.getGraphics().isCurrentContext();
- CGContextRef context = g.getGraphics().getContext();
-
- if (!same) UIKit.UIGraphicsPushContext(context);
-
- CGRect rect = new CGRect(new CGPoint( - left, - top), new CGSize(width + left + right, height + top + bottom));
- CGAffineTransform affineTransform = Graphics.getAffineTransform(transform);
-
- CoreGraphics.CGContextTranslateCTM(context, tx, ty);
- CoreGraphics.CGContextConcatCTM(context, affineTransform);
-
- resizableImage.drawInRect(rect);
-
- CoreGraphics.CGContextConcatCTM(context, CoreGraphics.CGAffineTransformInvert(affineTransform));
- CoreGraphics.CGContextTranslateCTM(context, -tx, -ty);
-
- if (!same) UIKit.UIGraphicsPopContext();
+ g.getGraphics().drawInRect(resizableImage, - left, - top, width + left + right, height + top + bottom, Graphics.getAffineTransform(transform));
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|