Beatmup
java_factory.cpp
Go to the documentation of this file.
1 /*
2  Beatmup image and signal processing library
3  Copyright (C) 2019, lnstadrum
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #include "java_factory.h"
20 #include <core/geometry.h>
21 
22 JavaFactory::JavaFactory() : usedEnv(NULL) {}
23 
25  if (usedEnv == jenv)
26  return;
27  usedEnv = jenv;
28  // AffineMapping
29  jclass cls = jenv->FindClass("Beatmup/Geometry/AffineMapping");
30  affineMapping.constructor = jenv->GetMethodID(cls, "<init>", "()V");
31  affineMapping.ida11 = jenv->GetFieldID(cls, "a11", "F");
32  affineMapping.ida12 = jenv->GetFieldID(cls, "a12", "F");
33  affineMapping.ida21 = jenv->GetFieldID(cls, "a21", "F");
34  affineMapping.ida22 = jenv->GetFieldID(cls, "a22", "F");
35  affineMapping.idx = jenv->GetFieldID(cls, "x", "F");
36  affineMapping.idy = jenv->GetFieldID(cls, "y", "F");
37  jenv->DeleteLocalRef(cls);
38  // IntRectangle
39  cls = jenv->FindClass("Beatmup/Geometry/IntRectangle");
40  intRectangle.constructor = jenv->GetMethodID(cls, "<init>", "(IIII)V");
41  intRectangle.ix1 = jenv->GetFieldID(cls, "x1", "I");
42  intRectangle.iy1 = jenv->GetFieldID(cls, "y1", "I");
43  intRectangle.ix2 = jenv->GetFieldID(cls, "x2", "I");
44  intRectangle.iy2 = jenv->GetFieldID(cls, "y2", "I");
45  jenv->DeleteLocalRef(cls);
46  // IntPoint
47  cls = jenv->FindClass("Beatmup/Geometry/IntPoint");
48  intPoint.constructor = jenv->GetMethodID(cls, "<init>", "(II)V");
49  intPoint.ix = jenv->GetFieldID(cls, "x", "I");
50  intPoint.iy = jenv->GetFieldID(cls, "y", "I");
51  jenv->DeleteLocalRef(cls);
52  // Color
53  cls = jenv->FindClass("Beatmup/Imaging/Color");
54  color.constructor = jenv->GetMethodID(cls, "<init>", "(IIII)V");
55  color.idr = jenv->GetFieldID(cls, "r", "I");
56  color.idg = jenv->GetFieldID(cls, "g", "I");
57  color.idb = jenv->GetFieldID(cls, "b", "I");
58  color.ida = jenv->GetFieldID(cls, "a", "I");
59  jenv->DeleteLocalRef(cls);
60 }
61 
62 
65  jclass cls = jenv->FindClass("Beatmup/Geometry/AffineMapping");
66  jobject result = jenv->NewObject(cls, affineMapping.constructor);
67  jenv->DeleteLocalRef(cls);
69  return result;
70 }
71 
72 
75  float a11, a12, a21, a22;
77  jenv->SetFloatField(jMapping, affineMapping.ida11, a11);
78  jenv->SetFloatField(jMapping, affineMapping.ida12, a12);
79  jenv->SetFloatField(jMapping, affineMapping.ida21, a21);
80  jenv->SetFloatField(jMapping, affineMapping.ida22, a22);
81  jenv->SetFloatField(jMapping, affineMapping.idx, mapping.position.x);
82  jenv->SetFloatField(jMapping, affineMapping.idy, mapping.position.y);
83 }
84 
87  jclass cls = jenv->FindClass("Beatmup/Geometry/IntRectangle");
88  jobject result = jenv->NewObject(cls, intRectangle.constructor, r.a.x, r.a.y, r.b.x, r.b.y);
89  jenv->DeleteLocalRef(cls);
90  return result;
91 }
92 
93 
96  jclass cls = jenv->FindClass("Beatmup/Geometry/IntPoint");
97  jobject result = jenv->NewObject(cls, intPoint.constructor, p.x, p.y);
98  jenv->DeleteLocalRef(cls);
99  return result;
100 }
101 
102 
103 void JavaFactory::setIntPoint(JNIEnv *jenv, const Beatmup::IntPoint &point, jobject jPoint) {
104  initialize(jenv);
105  jenv->SetIntField(jPoint, intPoint.ix, point.x);
106  jenv->SetIntField(jPoint, intPoint.iy, point.y);
107 }
108 
109 
110 void JavaFactory::setIntPoint(JNIEnv *jenv, int x, int y, jobject jPoint) {
111  initialize(jenv);
112  jenv->SetIntField(jPoint, intPoint.ix, x);
113  jenv->SetIntField(jPoint, intPoint.iy, y);
114 }
115 
116 
118  initialize(jenv);
119  jclass cls = jenv->FindClass("Beatmup/Imaging/Color");
120  jobject result = jenv->NewObject(cls, color.constructor, c.r, c.g, c.b, c.a);
121  jenv->DeleteLocalRef(cls);
122  return result;
123 }
124 
125 
127  initialize(jenv);
128  jenv->SetIntField(jColor, color.idr, c.r);
129  jenv->SetIntField(jColor, color.idg, c.g);
130  jenv->SetIntField(jColor, color.idb, c.b);
131  jenv->SetIntField(jColor, color.ida, c.a);
132 }
2x3 affine mapping containing a 2x2 matrix and a 2D point
Definition: geometry.h:639
void getElements(float &a11, float &a12, float &a21, float &a22) const
Retrieves matrix element values.
Definition: geometry.h:572
struct JavaFactory::@19 color
void setIntPoint(JNIEnv *jenv, const Beatmup::IntPoint &point, jobject jPoint)
jobject makeIntRectangle(JNIEnv *jenv, const Beatmup::IntRectangle)
Creates Java's IntRectangle object from Beatmup IntRectangle.
void setAffineMapping(JNIEnv *jenv, const Beatmup::AffineMapping &mapping, jobject jMapping)
JNIEnv * usedEnv
last used JNIEnv
Definition: java_factory.h:29
void setColor(JNIEnv *jenv, const Beatmup::color4i &c, jobject jColor)
struct JavaFactory::@16 affineMapping
jobject makeAffineMapping(JNIEnv *jenv, const Beatmup::AffineMapping &mapping)
Creates Java's AffineMapping object from Beatmup AffineMapping.
jobject makeIntPoint(JNIEnv *jenv, const Beatmup::IntPoint)
struct JavaFactory::@17 intRectangle
void initialize(JNIEnv *jenv)
struct JavaFactory::@18 intPoint
jobject makeColor(JNIEnv *jenv, const Beatmup::color4i &color)
Creates Java's Color object from Beatmup's color.
JNIEnv jclass
JNIEnv * jenv
JNIEnv jobject
jobject jlong jint jint y
jobject jlong jint jint jint r
Beatmup::IntPoint result
jobject jlong jint x
return layer isPhantom() ? JNI_TRUE jlong jfloat jfloat jfloat a11
return layer isPhantom() ? JNI_TRUE jlong jfloat jfloat jfloat jfloat jfloat jfloat a22
Beatmup::IntPoint p((int) x,(int) y)
return layer isPhantom() ? JNI_TRUE jlong jfloat jfloat jfloat jfloat jfloat a21
Beatmup::AffineMapping & mapping
return layer isPhantom() ? JNI_TRUE jlong jfloat jfloat jfloat jfloat a12
jlong jobject jColor