blob: a5647e45071e1001f1e08499be28693f17ae5637 [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
18#include "rsdCore.h"
19#include "rsdIntrinsics.h"
20#include "rsdAllocation.h"
21
22#include "rsdIntrinsicInlines.h"
23
24using namespace android;
25using namespace android::renderscript;
26
27struct ConvolveParams {
28 float f[4];
29};
30
31
32static void One(const RsForEachStubParamStruct *p, uchar4 *out,
33 const uchar4 *py, const float* coeff) {
34 float4 i = convert_float4(py[0]);
35
36 float4 sum;
37 sum.x = i.x * coeff[0] +
38 i.y * coeff[4] +
39 i.z * coeff[8] +
40 i.w * coeff[12];
41 sum.y = i.x * coeff[1] +
42 i.y * coeff[5] +
43 i.z * coeff[9] +
44 i.w * coeff[13];
45 sum.z = i.x * coeff[2] +
46 i.y * coeff[6] +
47 i.z * coeff[10] +
48 i.w * coeff[14];
49 sum.w = i.x * coeff[3] +
50 i.y * coeff[7] +
51 i.z * coeff[11] +
52 i.w * coeff[15];
53
54 sum.x = sum.x < 0 ? 0 : (sum.x > 255 ? 255 : sum.x);
55 sum.y = sum.y < 0 ? 0 : (sum.y > 255 ? 255 : sum.y);
56 sum.z = sum.z < 0 ? 0 : (sum.z > 255 ? 255 : sum.z);
57 sum.w = sum.w < 0 ? 0 : (sum.w > 255 ? 255 : sum.w);
58
59 *out = convert_uchar4(sum);
60}
61
62enum {
63 BLEND_CLEAR = 0,
64 BLEND_SRC = 1,
65 BLEND_DST = 2,
66 BLEND_SRC_OVER = 3,
67 BLEND_DST_OVER = 4,
68 BLEND_SRC_IN = 5,
69 BLEND_DST_IN = 6,
70 BLEND_SRC_OUT = 7,
71 BLEND_DST_OUT = 8,
72 BLEND_SRC_ATOP = 9,
73 BLEND_DST_ATOP = 10,
74 BLEND_XOR = 11,
75
76 BLEND_NORMAL = 12,
77 BLEND_AVERAGE = 13,
78 BLEND_MULTIPLY = 14,
79 BLEND_SCREEN = 15,
80 BLEND_DARKEN = 16,
81 BLEND_LIGHTEN = 17,
82 BLEND_OVERLAY = 18,
83 BLEND_HARDLIGHT = 19,
84 BLEND_SOFTLIGHT = 20,
85 BLEND_DIFFERENCE = 21,
86 BLEND_NEGATION = 22,
87 BLEND_EXCLUSION = 23,
88 BLEND_COLOR_DODGE = 24,
89 BLEND_INVERSE_COLOR_DODGE = 25,
90 BLEND_SOFT_DODGE = 26,
91 BLEND_COLOR_BURN = 27,
92 BLEND_INVERSE_COLOR_BURN = 28,
93 BLEND_SOFT_BURN = 29,
94 BLEND_REFLECT = 30,
95 BLEND_GLOW = 31,
96 BLEND_FREEZE = 32,
97 BLEND_HEAT = 33,
98 BLEND_ADD = 34,
99 BLEND_SUBTRACT = 35,
100 BLEND_STAMP = 36,
101 BLEND_RED = 37,
102 BLEND_GREEN = 38,
103 BLEND_BLUE = 39,
104 BLEND_HUE = 40,
105 BLEND_SATURATION = 41,
106 BLEND_COLOR = 42,
107 BLEND_LUMINOSITY = 43
108};
109
110static void ColorMatrix_uchar4(const RsForEachStubParamStruct *p,
111 uint32_t xstart, uint32_t xend,
112 uint32_t instep, uint32_t outstep) {
113 ConvolveParams *cp = (ConvolveParams *)p->usr;
114 uchar4 *out = (uchar4 *)p->out;
115 uchar4 *in = (uchar4 *)p->in;
116 uint32_t x1 = xstart;
117 uint32_t x2 = xend;
118
119 in += xstart;
120 out += xstart;
121
122 switch (p->slot) {
123 case BLEND_CLEAR:
124 for (;x1 < x2; x1++, out++) {
125 *out = 0;
126 }
127 break;
128 case BLEND_SRC:
129 for (;x1 < x2; x1++, out++, in++) {
130 uchar4 t = *in;
131 t.rgb = (t.rgb * t.a) >> 8;
132 *out = t;
133 }
134 break;
135 case BLEND_DST:
136 for (;x1 < x2; x1++, out++, in++) {
137 uchar4 t = *in;
138 t.rgb = (t.rgb * t.a) >> 8;
139 *out = t;
140 }
141 break;
142
143
144
145
146 }
147
148 if(x2 > x1) {
149 while(x1 != x2) {
150 One(p, out++, in++, cp->f);
151 x1++;
152 }
153 }
154}
155
156void * rsdIntrinsic_InitBlend(const android::renderscript::Context *dc,
157 android::renderscript::Script *script,
158 RsdIntriniscFuncs_t *funcs) {
159
160 script->mHal.info.exportedVariableCount = 0;
161 funcs->root = ColorMatrix_uchar4;
162
163 ConvolveParams *cp = (ConvolveParams *)calloc(1, sizeof(ConvolveParams));
164 return cp;
165}
166
167