1/*
2 * Copyright (C) 2011-2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 * This file is auto-generated. DO NOT MODIFY!
19 * The source Renderscript file: reduce_general_examples.rs
20 */
21
22package examples;
23
24import android.renderscript.*;
25import examples.reduce_general_examplesBitCode;
26
27/**
28 * @hide
29 */
30public class ScriptC_reduce_general_examples extends ScriptC {
31    private static final String __rs_resource_name = "reduce_general_examples";
32    // Constructor
33    public  ScriptC_reduce_general_examples(RenderScript rs) {
34        super(rs,
35              __rs_resource_name,
36              reduce_general_examplesBitCode.getBitCode32(),
37              reduce_general_examplesBitCode.getBitCode64());
38        mRSLocal = rs;
39        __I32 = Element.I32(rs);
40        __F32 = Element.F32(rs);
41        __I32_2 = Element.I32_2(rs);
42        __U32 = Element.U32(rs);
43        __U8 = Element.U8(rs);
44    }
45
46    private Element __F32;
47    private Element __I32;
48    private Element __I32_2;
49    private Element __U32;
50    private Element __U8;
51    private RenderScript mRSLocal;
52    // To obtain the result, invoke get(), which blocks
53    // until the asynchronously-launched operation has completed.
54    public static class resultArray256_uint {
55        public long[] get() {
56            if (!mGotResult) {
57                int[] outArray = new int[256];
58                mOut.copyTo(outArray);
59                long[] result = new long[256];
60                for (int Idx = 0; Idx < 256; ++Idx) {
61                    result[Idx] = ((long) ((outArray[Idx]) & 0xffffffffL));
62                }
63
64                mResult = result;
65                mOut.destroy();
66                mOut = null;  // make Java object eligible for garbage collection
67                if (mTempIns != null) {
68                    for (Allocation tempIn : mTempIns) {
69                        tempIn.destroy();
70                    }
71
72                    mTempIns = null;  // make Java objects eligible for garbage collection
73                }
74
75                mGotResult = true;
76            }
77
78            return mResult;
79        }
80
81        private  resultArray256_uint(Allocation out) {
82            mTempIns = null;
83            mOut = out;
84            mGotResult = false;
85        }
86
87        private Allocation[] mTempIns;
88        private Allocation mOut;
89        private boolean mGotResult;
90        private long[] mResult;
91    }
92
93    // To obtain the result, invoke get(), which blocks
94    // until the asynchronously-launched operation has completed.
95    public static class result_float {
96        public float get() {
97            if (!mGotResult) {
98                float[] outArray = new float[1];
99                mOut.copyTo(outArray);
100                mResult = outArray[0];
101                mOut.destroy();
102                mOut = null;  // make Java object eligible for garbage collection
103                if (mTempIns != null) {
104                    for (Allocation tempIn : mTempIns) {
105                        tempIn.destroy();
106                    }
107
108                    mTempIns = null;  // make Java objects eligible for garbage collection
109                }
110
111                mGotResult = true;
112            }
113
114            return mResult;
115        }
116
117        private  result_float(Allocation out) {
118            mTempIns = null;
119            mOut = out;
120            mGotResult = false;
121        }
122
123        private Allocation[] mTempIns;
124        private Allocation mOut;
125        private boolean mGotResult;
126        private float mResult;
127    }
128
129    // To obtain the result, invoke get(), which blocks
130    // until the asynchronously-launched operation has completed.
131    public static class result_int {
132        public int get() {
133            if (!mGotResult) {
134                int[] outArray = new int[1];
135                mOut.copyTo(outArray);
136                mResult = outArray[0];
137                mOut.destroy();
138                mOut = null;  // make Java object eligible for garbage collection
139                if (mTempIns != null) {
140                    for (Allocation tempIn : mTempIns) {
141                        tempIn.destroy();
142                    }
143
144                    mTempIns = null;  // make Java objects eligible for garbage collection
145                }
146
147                mGotResult = true;
148            }
149
150            return mResult;
151        }
152
153        private  result_int(Allocation out) {
154            mTempIns = null;
155            mOut = out;
156            mGotResult = false;
157        }
158
159        private Allocation[] mTempIns;
160        private Allocation mOut;
161        private boolean mGotResult;
162        private int mResult;
163    }
164
165    // To obtain the result, invoke get(), which blocks
166    // until the asynchronously-launched operation has completed.
167    public static class result_int2 {
168        public Int2 get() {
169            if (!mGotResult) {
170                int[] outArray = new int[2];
171                mOut.copyTo(outArray);
172                mResult = new Int2(outArray[0], outArray[1]);
173                mOut.destroy();
174                mOut = null;  // make Java object eligible for garbage collection
175                if (mTempIns != null) {
176                    for (Allocation tempIn : mTempIns) {
177                        tempIn.destroy();
178                    }
179
180                    mTempIns = null;  // make Java objects eligible for garbage collection
181                }
182
183                mGotResult = true;
184            }
185
186            return mResult;
187        }
188
189        private  result_int2(Allocation out) {
190            mTempIns = null;
191            mOut = out;
192            mGotResult = false;
193        }
194
195        private Allocation[] mTempIns;
196        private Allocation mOut;
197        private boolean mGotResult;
198        private Int2 mResult;
199    }
200
201    private final static int mExportReduceIdx_addint = 0;
202    // in1 = "val"
203    public result_int reduce_addint(int[] in1) {
204        // Verify that "in1" is non-null.
205        if (in1 == null) {
206            throw new RSIllegalArgumentException("Array \"in1\" is null!");
207        }
208        Allocation ain1 = Allocation.createSized(mRSLocal, __I32, in1.length);
209        ain1.setAutoPadding(true);
210        ain1.copyFrom(in1);
211
212        result_int result = reduce_addint(ain1, null);
213        result.mTempIns = new Allocation[]{ain1};
214        return result;
215    }
216
217    // ain1 = "int val"
218    public result_int reduce_addint(Allocation ain1) {
219        return reduce_addint(ain1, null);
220    }
221
222    // ain1 = "int val"
223    public result_int reduce_addint(Allocation ain1, Script.LaunchOptions sc) {
224        // check ain1
225        if (!ain1.getType().getElement().isCompatible(__I32)) {
226            throw new RSRuntimeException("Type mismatch with I32!");
227        }
228        Allocation aout = Allocation.createSized(mRSLocal, __I32, 1);
229        aout.setAutoPadding(true);
230        reduce(mExportReduceIdx_addint, new Allocation[]{ain1}, aout, sc);
231        return new result_int(aout);
232    }
233
234    private final static int mExportReduceIdx_mpyint = 1;
235    // in1 = "val"
236    public result_int reduce_mpyint(int[] in1) {
237        // Verify that "in1" is non-null.
238        if (in1 == null) {
239            throw new RSIllegalArgumentException("Array \"in1\" is null!");
240        }
241        Allocation ain1 = Allocation.createSized(mRSLocal, __I32, in1.length);
242        ain1.setAutoPadding(true);
243        ain1.copyFrom(in1);
244
245        result_int result = reduce_mpyint(ain1, null);
246        result.mTempIns = new Allocation[]{ain1};
247        return result;
248    }
249
250    // ain1 = "int val"
251    public result_int reduce_mpyint(Allocation ain1) {
252        return reduce_mpyint(ain1, null);
253    }
254
255    // ain1 = "int val"
256    public result_int reduce_mpyint(Allocation ain1, Script.LaunchOptions sc) {
257        // check ain1
258        if (!ain1.getType().getElement().isCompatible(__I32)) {
259            throw new RSRuntimeException("Type mismatch with I32!");
260        }
261        Allocation aout = Allocation.createSized(mRSLocal, __I32, 1);
262        aout.setAutoPadding(true);
263        reduce(mExportReduceIdx_mpyint, new Allocation[]{ain1}, aout, sc);
264        return new result_int(aout);
265    }
266
267    private final static int mExportReduceIdx_dp = 2;
268    // in1 = "in1"
269    // in2 = "in2"
270    public result_float reduce_dp(float[] in1, float[] in2) {
271        // Verify that "in1" is non-null.
272        if (in1 == null) {
273            throw new RSIllegalArgumentException("Array \"in1\" is null!");
274        }
275        Allocation ain1 = Allocation.createSized(mRSLocal, __F32, in1.length);
276        ain1.setAutoPadding(true);
277        ain1.copyFrom(in1);
278        // Verify that "in2" is non-null.
279        if (in2 == null) {
280            throw new RSIllegalArgumentException("Array \"in2\" is null!");
281        }
282        // Verify that input array lengths are the same.
283        if (in1.length != in2.length) {
284            throw new RSRuntimeException("Array length mismatch between parameters \"in1\" and \"in2\"!");
285        }
286        Allocation ain2 = Allocation.createSized(mRSLocal, __F32, in2.length);
287        ain2.setAutoPadding(true);
288        ain2.copyFrom(in2);
289
290        result_float result = reduce_dp(ain1, ain2, null);
291        result.mTempIns = new Allocation[]{ain1, ain2};
292        return result;
293    }
294
295    // ain1 = "float in1"
296    // ain2 = "float in2"
297    public result_float reduce_dp(Allocation ain1, Allocation ain2) {
298        return reduce_dp(ain1, ain2, null);
299    }
300
301    // ain1 = "float in1"
302    // ain2 = "float in2"
303    public result_float reduce_dp(Allocation ain1, Allocation ain2, Script.LaunchOptions sc) {
304        Type t0, t1;
305        // check ain1
306        if (!ain1.getType().getElement().isCompatible(__F32)) {
307            throw new RSRuntimeException("Type mismatch with F32!");
308        }
309        // check ain2
310        if (!ain2.getType().getElement().isCompatible(__F32)) {
311            throw new RSRuntimeException("Type mismatch with F32!");
312        }
313        // Verify dimensions
314        t0 = ain1.getType();
315        t1 = ain2.getType();
316        if ((t0.getCount() != t1.getCount()) ||
317            (t0.getX() != t1.getX()) ||
318            (t0.getY() != t1.getY()) ||
319            (t0.getZ() != t1.getZ()) ||
320            (t0.hasFaces()   != t1.hasFaces()) ||
321            (t0.hasMipmaps() != t1.hasMipmaps())) {
322            throw new RSRuntimeException("Dimension mismatch between parameters ain1 and ain2!");
323        }
324
325        Allocation aout = Allocation.createSized(mRSLocal, __F32, 1);
326        aout.setAutoPadding(true);
327        reduce(mExportReduceIdx_dp, new Allocation[]{ain1, ain2}, aout, sc);
328        return new result_float(aout);
329    }
330
331    private final static int mExportReduceIdx_findMinAndMax = 3;
332    // in1 = "in"
333    public result_int2 reduce_findMinAndMax(float[] in1) {
334        // Verify that "in1" is non-null.
335        if (in1 == null) {
336            throw new RSIllegalArgumentException("Array \"in1\" is null!");
337        }
338        Allocation ain1 = Allocation.createSized(mRSLocal, __F32, in1.length);
339        ain1.setAutoPadding(true);
340        ain1.copyFrom(in1);
341
342        result_int2 result = reduce_findMinAndMax(ain1, null);
343        result.mTempIns = new Allocation[]{ain1};
344        return result;
345    }
346
347    // ain1 = "float in"
348    public result_int2 reduce_findMinAndMax(Allocation ain1) {
349        return reduce_findMinAndMax(ain1, null);
350    }
351
352    // ain1 = "float in"
353    public result_int2 reduce_findMinAndMax(Allocation ain1, Script.LaunchOptions sc) {
354        // check ain1
355        if (!ain1.getType().getElement().isCompatible(__F32)) {
356            throw new RSRuntimeException("Type mismatch with F32!");
357        }
358        Allocation aout = Allocation.createSized(mRSLocal, __I32_2, 1);
359        aout.setAutoPadding(true);
360        reduce(mExportReduceIdx_findMinAndMax, new Allocation[]{ain1}, aout, sc);
361        return new result_int2(aout);
362    }
363
364    private final static int mExportReduceIdx_fz = 4;
365    // in1 = "inVal"
366    public result_int reduce_fz(int[] in1) {
367        // Verify that "in1" is non-null.
368        if (in1 == null) {
369            throw new RSIllegalArgumentException("Array \"in1\" is null!");
370        }
371        Allocation ain1 = Allocation.createSized(mRSLocal, __I32, in1.length);
372        ain1.setAutoPadding(true);
373        ain1.copyFrom(in1);
374
375        result_int result = reduce_fz(ain1, null);
376        result.mTempIns = new Allocation[]{ain1};
377        return result;
378    }
379
380    // ain1 = "int inVal"
381    public result_int reduce_fz(Allocation ain1) {
382        return reduce_fz(ain1, null);
383    }
384
385    // ain1 = "int inVal"
386    public result_int reduce_fz(Allocation ain1, Script.LaunchOptions sc) {
387        // check ain1
388        if (!ain1.getType().getElement().isCompatible(__I32)) {
389            throw new RSRuntimeException("Type mismatch with I32!");
390        }
391        Allocation aout = Allocation.createSized(mRSLocal, __I32, 1);
392        aout.setAutoPadding(true);
393        reduce(mExportReduceIdx_fz, new Allocation[]{ain1}, aout, sc);
394        return new result_int(aout);
395    }
396
397    private final static int mExportReduceIdx_fz2 = 5;
398    // in1 = "inVal"
399    public result_int2 reduce_fz2(int[] in1) {
400        // Verify that "in1" is non-null.
401        if (in1 == null) {
402            throw new RSIllegalArgumentException("Array \"in1\" is null!");
403        }
404        Allocation ain1 = Allocation.createSized(mRSLocal, __I32, in1.length);
405        ain1.setAutoPadding(true);
406        ain1.copyFrom(in1);
407
408        result_int2 result = reduce_fz2(ain1, null);
409        result.mTempIns = new Allocation[]{ain1};
410        return result;
411    }
412
413    // ain1 = "int inVal"
414    public result_int2 reduce_fz2(Allocation ain1) {
415        return reduce_fz2(ain1, null);
416    }
417
418    // ain1 = "int inVal"
419    public result_int2 reduce_fz2(Allocation ain1, Script.LaunchOptions sc) {
420        // check ain1
421        if (!ain1.getType().getElement().isCompatible(__I32)) {
422            throw new RSRuntimeException("Type mismatch with I32!");
423        }
424        Allocation aout = Allocation.createSized(mRSLocal, __I32_2, 1);
425        aout.setAutoPadding(true);
426        reduce(mExportReduceIdx_fz2, new Allocation[]{ain1}, aout, sc);
427        return new result_int2(aout);
428    }
429
430    private final static int mExportReduceIdx_histogram = 6;
431    // in1 = "in"
432    public resultArray256_uint reduce_histogram(byte[] in1) {
433        // Verify that "in1" is non-null.
434        if (in1 == null) {
435            throw new RSIllegalArgumentException("Array \"in1\" is null!");
436        }
437        Allocation ain1 = Allocation.createSized(mRSLocal, __U8, in1.length);
438        ain1.setAutoPadding(true);
439        ain1.copyFrom(in1);
440
441        resultArray256_uint result = reduce_histogram(ain1, null);
442        result.mTempIns = new Allocation[]{ain1};
443        return result;
444    }
445
446    // ain1 = "uchar in"
447    public resultArray256_uint reduce_histogram(Allocation ain1) {
448        return reduce_histogram(ain1, null);
449    }
450
451    // ain1 = "uchar in"
452    public resultArray256_uint reduce_histogram(Allocation ain1, Script.LaunchOptions sc) {
453        // check ain1
454        if (!ain1.getType().getElement().isCompatible(__U8)) {
455            throw new RSRuntimeException("Type mismatch with U8!");
456        }
457        Allocation aout = Allocation.createSized(mRSLocal, __U32, 256);
458        aout.setAutoPadding(true);
459        reduce(mExportReduceIdx_histogram, new Allocation[]{ain1}, aout, sc);
460        return new resultArray256_uint(aout);
461    }
462
463    private final static int mExportReduceIdx_mode = 7;
464    // in1 = "in"
465    public result_int2 reduce_mode(byte[] in1) {
466        // Verify that "in1" is non-null.
467        if (in1 == null) {
468            throw new RSIllegalArgumentException("Array \"in1\" is null!");
469        }
470        Allocation ain1 = Allocation.createSized(mRSLocal, __U8, in1.length);
471        ain1.setAutoPadding(true);
472        ain1.copyFrom(in1);
473
474        result_int2 result = reduce_mode(ain1, null);
475        result.mTempIns = new Allocation[]{ain1};
476        return result;
477    }
478
479    // ain1 = "uchar in"
480    public result_int2 reduce_mode(Allocation ain1) {
481        return reduce_mode(ain1, null);
482    }
483
484    // ain1 = "uchar in"
485    public result_int2 reduce_mode(Allocation ain1, Script.LaunchOptions sc) {
486        // check ain1
487        if (!ain1.getType().getElement().isCompatible(__U8)) {
488            throw new RSRuntimeException("Type mismatch with U8!");
489        }
490        Allocation aout = Allocation.createSized(mRSLocal, __I32_2, 1);
491        aout.setAutoPadding(true);
492        reduce(mExportReduceIdx_mode, new Allocation[]{ain1}, aout, sc);
493        return new result_int2(aout);
494    }
495
496}
497
498