blob: 33764e0bc285591a87649f4e7e12b37587911325 [file] [log] [blame]
Jason Samscf9ea9f2012-09-23 17:00:54 -07001/*
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
Jason Sams709a0972012-11-15 18:18:04 -080018#include "rsCpuIntrinsic.h"
19#include "rsCpuIntrinsicInlines.h"
Jason Samscf9ea9f2012-09-23 17:00:54 -070020
21using namespace android;
22using namespace android::renderscript;
23
Jason Sams709a0972012-11-15 18:18:04 -080024namespace android {
25namespace renderscript {
26
27
28class RsdCpuScriptIntrinsicBlend : public RsdCpuScriptIntrinsic {
29public:
30 virtual void populateScript(Script *);
31
32 virtual ~RsdCpuScriptIntrinsicBlend();
Jason Samsc905efd2012-11-26 15:20:18 -080033 RsdCpuScriptIntrinsicBlend(RsdCpuReferenceImpl *ctx, const Script *s, const Element *e);
Jason Sams709a0972012-11-15 18:18:04 -080034
35protected:
36 static void kernel(const RsForEachStubParamStruct *p,
37 uint32_t xstart, uint32_t xend,
38 uint32_t instep, uint32_t outstep);
Jason Samscf9ea9f2012-09-23 17:00:54 -070039};
40
Jason Sams709a0972012-11-15 18:18:04 -080041}
42}
43
Jason Samscf9ea9f2012-09-23 17:00:54 -070044
Jason Samscf9ea9f2012-09-23 17:00:54 -070045enum {
46 BLEND_CLEAR = 0,
47 BLEND_SRC = 1,
48 BLEND_DST = 2,
49 BLEND_SRC_OVER = 3,
50 BLEND_DST_OVER = 4,
51 BLEND_SRC_IN = 5,
52 BLEND_DST_IN = 6,
53 BLEND_SRC_OUT = 7,
54 BLEND_DST_OUT = 8,
55 BLEND_SRC_ATOP = 9,
56 BLEND_DST_ATOP = 10,
57 BLEND_XOR = 11,
58
59 BLEND_NORMAL = 12,
60 BLEND_AVERAGE = 13,
61 BLEND_MULTIPLY = 14,
62 BLEND_SCREEN = 15,
63 BLEND_DARKEN = 16,
64 BLEND_LIGHTEN = 17,
65 BLEND_OVERLAY = 18,
66 BLEND_HARDLIGHT = 19,
67 BLEND_SOFTLIGHT = 20,
68 BLEND_DIFFERENCE = 21,
69 BLEND_NEGATION = 22,
70 BLEND_EXCLUSION = 23,
71 BLEND_COLOR_DODGE = 24,
72 BLEND_INVERSE_COLOR_DODGE = 25,
73 BLEND_SOFT_DODGE = 26,
74 BLEND_COLOR_BURN = 27,
75 BLEND_INVERSE_COLOR_BURN = 28,
76 BLEND_SOFT_BURN = 29,
77 BLEND_REFLECT = 30,
78 BLEND_GLOW = 31,
79 BLEND_FREEZE = 32,
80 BLEND_HEAT = 33,
81 BLEND_ADD = 34,
82 BLEND_SUBTRACT = 35,
83 BLEND_STAMP = 36,
84 BLEND_RED = 37,
85 BLEND_GREEN = 38,
86 BLEND_BLUE = 39,
87 BLEND_HUE = 40,
88 BLEND_SATURATION = 41,
89 BLEND_COLOR = 42,
90 BLEND_LUMINOSITY = 43
91};
92
Simon Hosie5d069192014-02-19 16:33:45 -080093extern "C" int rsdIntrinsicBlend_K(uchar4 *out, uchar4 const *in, int slot,
94 uint32_t xstart, uint32_t xend);
Jason Samsfa17cda2012-09-26 18:33:58 -070095
Jason Sams709a0972012-11-15 18:18:04 -080096void RsdCpuScriptIntrinsicBlend::kernel(const RsForEachStubParamStruct *p,
97 uint32_t xstart, uint32_t xend,
98 uint32_t instep, uint32_t outstep) {
99 RsdCpuScriptIntrinsicBlend *cp = (RsdCpuScriptIntrinsicBlend *)p->usr;
Tim Murray36889a02012-09-24 14:52:48 -0700100
101 // instep/outstep can be ignored--sizeof(uchar4) known at compile time
Jason Samscf9ea9f2012-09-23 17:00:54 -0700102 uchar4 *out = (uchar4 *)p->out;
103 uchar4 *in = (uchar4 *)p->in;
104 uint32_t x1 = xstart;
105 uint32_t x2 = xend;
106
Simon Hosie5d069192014-02-19 16:33:45 -0800107#if defined(ARCH_ARM_HAVE_VFP)
108 if (gArchUseSIMD) {
109 if (rsdIntrinsicBlend_K(out, in, p->slot, x1, x2) >= 0)
110 return;
111 }
112#endif
Jason Samscf9ea9f2012-09-23 17:00:54 -0700113 switch (p->slot) {
114 case BLEND_CLEAR:
115 for (;x1 < x2; x1++, out++) {
116 *out = 0;
117 }
118 break;
119 case BLEND_SRC:
120 for (;x1 < x2; x1++, out++, in++) {
Tim Murray36889a02012-09-24 14:52:48 -0700121 *out = *in;
Jason Samscf9ea9f2012-09-23 17:00:54 -0700122 }
123 break;
Tim Murray36889a02012-09-24 14:52:48 -0700124 //BLEND_DST is a NOP
Jason Samscf9ea9f2012-09-23 17:00:54 -0700125 case BLEND_DST:
Tim Murray36889a02012-09-24 14:52:48 -0700126 break;
127 case BLEND_SRC_OVER:
Jason Samscf9ea9f2012-09-23 17:00:54 -0700128 for (;x1 < x2; x1++, out++, in++) {
Tim Murray36889a02012-09-24 14:52:48 -0700129 short4 in_s = convert_short4(*in);
130 short4 out_s = convert_short4(*out);
Tim Murray0b575de2013-03-15 15:56:43 -0700131 in_s = in_s + ((out_s * (short4)(255 - in_s.w)) >> (short4)8);
Tim Murray36889a02012-09-24 14:52:48 -0700132 *out = convert_uchar4(in_s);
Jason Samscf9ea9f2012-09-23 17:00:54 -0700133 }
134 break;
Tim Murray36889a02012-09-24 14:52:48 -0700135 case BLEND_DST_OVER:
136 for (;x1 < x2; x1++, out++, in++) {
137 short4 in_s = convert_short4(*in);
138 short4 out_s = convert_short4(*out);
Tim Murray0b575de2013-03-15 15:56:43 -0700139 in_s = out_s + ((in_s * (short4)(255 - out_s.w)) >> (short4)8);
Tim Murray36889a02012-09-24 14:52:48 -0700140 *out = convert_uchar4(in_s);
141 }
142 break;
143 case BLEND_SRC_IN:
144 for (;x1 < x2; x1++, out++, in++) {
145 short4 in_s = convert_short4(*in);
Tim Murray0b575de2013-03-15 15:56:43 -0700146 in_s = (in_s * out->w) >> (short4)8;
Tim Murray36889a02012-09-24 14:52:48 -0700147 *out = convert_uchar4(in_s);
148 }
149 break;
150 case BLEND_DST_IN:
151 for (;x1 < x2; x1++, out++, in++) {
152 short4 out_s = convert_short4(*out);
Tim Murray0b575de2013-03-15 15:56:43 -0700153 out_s = (out_s * in->w) >> (short4)8;
Tim Murray36889a02012-09-24 14:52:48 -0700154 *out = convert_uchar4(out_s);
155 }
156 break;
157 case BLEND_SRC_OUT:
158 for (;x1 < x2; x1++, out++, in++) {
159 short4 in_s = convert_short4(*in);
Tim Murray0b575de2013-03-15 15:56:43 -0700160 in_s = (in_s * (short4)(255 - out->w)) >> (short4)8;
Tim Murray36889a02012-09-24 14:52:48 -0700161 *out = convert_uchar4(in_s);
162 }
163 break;
164 case BLEND_DST_OUT:
165 for (;x1 < x2; x1++, out++, in++) {
166 short4 out_s = convert_short4(*out);
Tim Murray0b575de2013-03-15 15:56:43 -0700167 out_s = (out_s * (short4)(255 - in->w)) >> (short4)8;
Tim Murray36889a02012-09-24 14:52:48 -0700168 *out = convert_uchar4(out_s);
169 }
170 break;
171 case BLEND_SRC_ATOP:
172 for (;x1 < x2; x1++, out++, in++) {
173 short4 in_s = convert_short4(*in);
174 short4 out_s = convert_short4(*out);
Tim Murray0b575de2013-03-15 15:56:43 -0700175 out_s.xyz = ((in_s.xyz * out_s.w) +
176 (out_s.xyz * ((short3)255 - (short3)in_s.w))) >> (short3)8;
Tim Murray36889a02012-09-24 14:52:48 -0700177 *out = convert_uchar4(out_s);
178 }
179 break;
180 case BLEND_DST_ATOP:
181 for (;x1 < x2; x1++, out++, in++) {
182 short4 in_s = convert_short4(*in);
183 short4 out_s = convert_short4(*out);
Tim Murray0b575de2013-03-15 15:56:43 -0700184 out_s.xyz = ((out_s.xyz * in_s.w) +
185 (in_s.xyz * ((short3)255 - (short3)out_s.w))) >> (short3)8;
Tim Murray36889a02012-09-24 14:52:48 -0700186 *out = convert_uchar4(out_s);
187 }
188 break;
189 case BLEND_XOR:
190 for (;x1 < x2; x1++, out++, in++) {
191 *out = *in ^ *out;
192 }
193 break;
194 case BLEND_NORMAL:
195 ALOGE("Called unimplemented blend intrinsic BLEND_NORMAL");
196 rsAssert(false);
197 break;
198 case BLEND_AVERAGE:
199 ALOGE("Called unimplemented blend intrinsic BLEND_AVERAGE");
200 rsAssert(false);
201 break;
202 case BLEND_MULTIPLY:
203 for (;x1 < x2; x1++, out++, in++) {
204 *out = convert_uchar4((convert_short4(*in) * convert_short4(*out))
205 >> (short4)8);
206 }
207 break;
208 case BLEND_SCREEN:
209 ALOGE("Called unimplemented blend intrinsic BLEND_SCREEN");
210 rsAssert(false);
211 break;
212 case BLEND_DARKEN:
213 ALOGE("Called unimplemented blend intrinsic BLEND_DARKEN");
214 rsAssert(false);
215 break;
216 case BLEND_LIGHTEN:
217 ALOGE("Called unimplemented blend intrinsic BLEND_LIGHTEN");
218 rsAssert(false);
219 break;
220 case BLEND_OVERLAY:
221 ALOGE("Called unimplemented blend intrinsic BLEND_OVERLAY");
222 rsAssert(false);
223 break;
224 case BLEND_HARDLIGHT:
225 ALOGE("Called unimplemented blend intrinsic BLEND_HARDLIGHT");
226 rsAssert(false);
227 break;
228 case BLEND_SOFTLIGHT:
229 ALOGE("Called unimplemented blend intrinsic BLEND_SOFTLIGHT");
230 rsAssert(false);
231 break;
232 case BLEND_DIFFERENCE:
233 ALOGE("Called unimplemented blend intrinsic BLEND_DIFFERENCE");
234 rsAssert(false);
235 break;
236 case BLEND_NEGATION:
237 ALOGE("Called unimplemented blend intrinsic BLEND_NEGATION");
238 rsAssert(false);
239 break;
240 case BLEND_EXCLUSION:
241 ALOGE("Called unimplemented blend intrinsic BLEND_EXCLUSION");
242 rsAssert(false);
243 break;
244 case BLEND_COLOR_DODGE:
245 ALOGE("Called unimplemented blend intrinsic BLEND_COLOR_DODGE");
246 rsAssert(false);
247 break;
248 case BLEND_INVERSE_COLOR_DODGE:
249 ALOGE("Called unimplemented blend intrinsic BLEND_INVERSE_COLOR_DODGE");
250 rsAssert(false);
251 break;
252 case BLEND_SOFT_DODGE:
253 ALOGE("Called unimplemented blend intrinsic BLEND_SOFT_DODGE");
254 rsAssert(false);
255 break;
256 case BLEND_COLOR_BURN:
257 ALOGE("Called unimplemented blend intrinsic BLEND_COLOR_BURN");
258 rsAssert(false);
259 break;
260 case BLEND_INVERSE_COLOR_BURN:
261 ALOGE("Called unimplemented blend intrinsic BLEND_INVERSE_COLOR_BURN");
262 rsAssert(false);
263 break;
264 case BLEND_SOFT_BURN:
265 ALOGE("Called unimplemented blend intrinsic BLEND_SOFT_BURN");
266 rsAssert(false);
267 break;
268 case BLEND_REFLECT:
269 ALOGE("Called unimplemented blend intrinsic BLEND_REFLECT");
270 rsAssert(false);
271 break;
272 case BLEND_GLOW:
273 ALOGE("Called unimplemented blend intrinsic BLEND_GLOW");
274 rsAssert(false);
275 break;
276 case BLEND_FREEZE:
277 ALOGE("Called unimplemented blend intrinsic BLEND_FREEZE");
278 rsAssert(false);
279 break;
280 case BLEND_HEAT:
281 ALOGE("Called unimplemented blend intrinsic BLEND_HEAT");
282 rsAssert(false);
283 break;
284 case BLEND_ADD:
285 for (;x1 < x2; x1++, out++, in++) {
Tim Murray0b575de2013-03-15 15:56:43 -0700286 uint32_t iR = in->x, iG = in->y, iB = in->z, iA = in->w,
287 oR = out->x, oG = out->y, oB = out->z, oA = out->w;
288 out->x = (oR + iR) > 255 ? 255 : oR + iR;
289 out->y = (oG + iG) > 255 ? 255 : oG + iG;
290 out->z = (oB + iB) > 255 ? 255 : oB + iB;
291 out->w = (oA + iA) > 255 ? 255 : oA + iA;
Tim Murray36889a02012-09-24 14:52:48 -0700292 }
293 break;
294 case BLEND_SUBTRACT:
295 for (;x1 < x2; x1++, out++, in++) {
Tim Murray0b575de2013-03-15 15:56:43 -0700296 int32_t iR = in->x, iG = in->y, iB = in->z, iA = in->w,
297 oR = out->x, oG = out->y, oB = out->z, oA = out->w;
298 out->x = (oR - iR) < 0 ? 0 : oR - iR;
299 out->y = (oG - iG) < 0 ? 0 : oG - iG;
300 out->z = (oB - iB) < 0 ? 0 : oB - iB;
301 out->w = (oA - iA) < 0 ? 0 : oA - iA;
Tim Murray36889a02012-09-24 14:52:48 -0700302 }
303 break;
304 case BLEND_STAMP:
305 ALOGE("Called unimplemented blend intrinsic BLEND_STAMP");
306 rsAssert(false);
307 break;
308 case BLEND_RED:
309 ALOGE("Called unimplemented blend intrinsic BLEND_RED");
310 rsAssert(false);
311 break;
312 case BLEND_GREEN:
313 ALOGE("Called unimplemented blend intrinsic BLEND_GREEN");
314 rsAssert(false);
315 break;
316 case BLEND_BLUE:
317 ALOGE("Called unimplemented blend intrinsic BLEND_BLUE");
318 rsAssert(false);
319 break;
320 case BLEND_HUE:
321 ALOGE("Called unimplemented blend intrinsic BLEND_HUE");
322 rsAssert(false);
323 break;
324 case BLEND_SATURATION:
325 ALOGE("Called unimplemented blend intrinsic BLEND_SATURATION");
326 rsAssert(false);
327 break;
328 case BLEND_COLOR:
329 ALOGE("Called unimplemented blend intrinsic BLEND_COLOR");
330 rsAssert(false);
331 break;
332 case BLEND_LUMINOSITY:
333 ALOGE("Called unimplemented blend intrinsic BLEND_LUMINOSITY");
334 rsAssert(false);
335 break;
Jason Samscf9ea9f2012-09-23 17:00:54 -0700336
Tim Murray36889a02012-09-24 14:52:48 -0700337 default:
338 ALOGE("Called unimplemented value %d", p->slot);
339 rsAssert(false);
Jason Samscf9ea9f2012-09-23 17:00:54 -0700340
341 }
Jason Samscf9ea9f2012-09-23 17:00:54 -0700342}
343
Jason Samscf9ea9f2012-09-23 17:00:54 -0700344
Jason Samsc905efd2012-11-26 15:20:18 -0800345RsdCpuScriptIntrinsicBlend::RsdCpuScriptIntrinsicBlend(RsdCpuReferenceImpl *ctx,
346 const Script *s, const Element *e)
347 : RsdCpuScriptIntrinsic(ctx, s, e, RS_SCRIPT_INTRINSIC_ID_BLEND) {
Jason Samscf9ea9f2012-09-23 17:00:54 -0700348
Jason Sams709a0972012-11-15 18:18:04 -0800349 mRootPtr = &kernel;
Jason Samscf9ea9f2012-09-23 17:00:54 -0700350}
351
Jason Sams709a0972012-11-15 18:18:04 -0800352RsdCpuScriptIntrinsicBlend::~RsdCpuScriptIntrinsicBlend() {
353}
354
355void RsdCpuScriptIntrinsicBlend::populateScript(Script *s) {
356 s->mHal.info.exportedVariableCount = 0;
357}
358
Jason Samsc905efd2012-11-26 15:20:18 -0800359RsdCpuScriptImpl * rsdIntrinsic_Blend(RsdCpuReferenceImpl *ctx,
360 const Script *s, const Element *e) {
361 return new RsdCpuScriptIntrinsicBlend(ctx, s, e);
Jason Sams709a0972012-11-15 18:18:04 -0800362}
363
364
Jason Samscf9ea9f2012-09-23 17:00:54 -0700365