|
| 1 | +/* |
| 2 | + * Copyright (C) 2012 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 | +package com.android.rs.image2; |
| 18 | + |
| 19 | +import java.lang.Math; |
| 20 | +import java.lang.Short; |
| 21 | + |
| 22 | +import android.support.v8.renderscript.*; |
| 23 | +import android.util.Log; |
| 24 | +import android.widget.SeekBar; |
| 25 | +import android.widget.TextView; |
| 26 | +import android.widget.AdapterView; |
| 27 | +import android.widget.ArrayAdapter; |
| 28 | +import android.view.View; |
| 29 | +import android.widget.Spinner; |
| 30 | + |
| 31 | +public class Blend extends TestBase { |
| 32 | + private ScriptIntrinsicBlend mBlend; |
| 33 | + private ScriptC_blend mBlendHelper; |
| 34 | + private short image1Alpha = 128; |
| 35 | + private short image2Alpha = 128; |
| 36 | + |
| 37 | + String mIntrinsicNames[]; |
| 38 | + |
| 39 | + private Allocation image1; |
| 40 | + private Allocation image2; |
| 41 | + private int currentIntrinsic = 0; |
| 42 | + |
| 43 | + private AdapterView.OnItemSelectedListener mIntrinsicSpinnerListener = |
| 44 | + new AdapterView.OnItemSelectedListener() { |
| 45 | + public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { |
| 46 | + currentIntrinsic = pos; |
| 47 | + runTest(); |
| 48 | + act.updateDisplay(); |
| 49 | + } |
| 50 | + |
| 51 | + public void onNothingSelected(AdapterView parent) { |
| 52 | + |
| 53 | + } |
| 54 | + }; |
| 55 | + |
| 56 | + public void createTest(android.content.res.Resources res) { |
| 57 | + mBlend = ScriptIntrinsicBlend.create(mRS, Element.U8_4(mRS)); |
| 58 | + mBlendHelper = new ScriptC_blend(mRS); |
| 59 | + mBlendHelper.set_alpha((short)128); |
| 60 | + |
| 61 | + image1 = Allocation.createTyped(mRS, mInPixelsAllocation.getType()); |
| 62 | + image2 = Allocation.createTyped(mRS, mInPixelsAllocation2.getType()); |
| 63 | + |
| 64 | + mIntrinsicNames = new String[14]; |
| 65 | + mIntrinsicNames[0] = "Source"; |
| 66 | + mIntrinsicNames[1] = "Destination"; |
| 67 | + mIntrinsicNames[2] = "Source Over"; |
| 68 | + mIntrinsicNames[3] = "Destination Over"; |
| 69 | + mIntrinsicNames[4] = "Source In"; |
| 70 | + mIntrinsicNames[5] = "Destination In"; |
| 71 | + mIntrinsicNames[6] = "Source Out"; |
| 72 | + mIntrinsicNames[7] = "Destination Out"; |
| 73 | + mIntrinsicNames[8] = "Source Atop"; |
| 74 | + mIntrinsicNames[9] = "Destination Atop"; |
| 75 | + mIntrinsicNames[10] = "XOR"; |
| 76 | + mIntrinsicNames[11] = "Add"; |
| 77 | + mIntrinsicNames[12] = "Subtract"; |
| 78 | + mIntrinsicNames[13] = "Multiply"; |
| 79 | + } |
| 80 | + |
| 81 | + public boolean onSpinner1Setup(Spinner s) { |
| 82 | + s.setAdapter(new ArrayAdapter<String>( |
| 83 | + act, R.layout.spinner_layout, mIntrinsicNames)); |
| 84 | + s.setOnItemSelectedListener(mIntrinsicSpinnerListener); |
| 85 | + return true; |
| 86 | + } |
| 87 | + |
| 88 | + public boolean onBar1Setup(SeekBar b, TextView t) { |
| 89 | + t.setText("Image 1 Alpha"); |
| 90 | + b.setMax(255); |
| 91 | + b.setProgress(image1Alpha); |
| 92 | + return true; |
| 93 | + } |
| 94 | + |
| 95 | + public void onBar1Changed(int progress) { |
| 96 | + image1Alpha = (short)progress; |
| 97 | + } |
| 98 | + |
| 99 | + public boolean onBar2Setup(SeekBar b, TextView t) { |
| 100 | + t.setText("Image 2 Alpha"); |
| 101 | + b.setMax(255); |
| 102 | + b.setProgress(image2Alpha); |
| 103 | + return true; |
| 104 | + } |
| 105 | + |
| 106 | + public void onBar2Changed(int progress) { |
| 107 | + image2Alpha = (short)progress; |
| 108 | + } |
| 109 | + |
| 110 | + public void runTest() { |
| 111 | + image1.copy2DRangeFrom(0, 0, mInPixelsAllocation.getType().getX(), mInPixelsAllocation.getType().getY(), mInPixelsAllocation, 0, 0); |
| 112 | + image2.copy2DRangeFrom(0, 0, mInPixelsAllocation2.getType().getX(), mInPixelsAllocation2.getType().getY(), mInPixelsAllocation2, 0, 0); |
| 113 | + |
| 114 | + mBlendHelper.set_alpha(image1Alpha); |
| 115 | + mBlendHelper.forEach_setImageAlpha(image1); |
| 116 | + |
| 117 | + mBlendHelper.set_alpha(image2Alpha); |
| 118 | + mBlendHelper.forEach_setImageAlpha(image2); |
| 119 | + |
| 120 | + switch (currentIntrinsic) { |
| 121 | + case 0: |
| 122 | + mBlend.forEachSrc(image1, image2); |
| 123 | + break; |
| 124 | + case 1: |
| 125 | + mBlend.forEachDst(image1, image2); |
| 126 | + break; |
| 127 | + case 2: |
| 128 | + mBlend.forEachSrcOver(image1, image2); |
| 129 | + break; |
| 130 | + case 3: |
| 131 | + mBlend.forEachDstOver(image1, image2); |
| 132 | + break; |
| 133 | + case 4: |
| 134 | + mBlend.forEachSrcIn(image1, image2); |
| 135 | + break; |
| 136 | + case 5: |
| 137 | + mBlend.forEachDstIn(image1, image2); |
| 138 | + break; |
| 139 | + case 6: |
| 140 | + mBlend.forEachSrcOut(image1, image2); |
| 141 | + break; |
| 142 | + case 7: |
| 143 | + mBlend.forEachDstOut(image1, image2); |
| 144 | + break; |
| 145 | + case 8: |
| 146 | + mBlend.forEachSrcAtop(image1, image2); |
| 147 | + break; |
| 148 | + case 9: |
| 149 | + mBlend.forEachDstAtop(image1, image2); |
| 150 | + break; |
| 151 | + case 10: |
| 152 | + mBlend.forEachXor(image1, image2); |
| 153 | + break; |
| 154 | + case 11: |
| 155 | + mBlend.forEachAdd(image1, image2); |
| 156 | + break; |
| 157 | + case 12: |
| 158 | + mBlend.forEachSubtract(image1, image2); |
| 159 | + break; |
| 160 | + case 13: |
| 161 | + mBlend.forEachMultiply(image1, image2); |
| 162 | + break; |
| 163 | + } |
| 164 | + |
| 165 | + mOutPixelsAllocation.copy2DRangeFrom(0, 0, image2.getType().getX(), image2.getType().getY(), image2, 0, 0); |
| 166 | + } |
| 167 | + |
| 168 | +} |
0 commit comments