MCPcopy Create free account
hub / github.com/android/ndk-samples / fill_plasma

Function fill_plasma

bitmap-plasma/app/src/main/cpp/plasma.cpp:168–243  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

166}
167
168static void fill_plasma(AndroidBitmapInfo* info, void* pixels, double t) {
169 Fixed yt1 = FIXED_FROM_FLOAT(t / 1230.);
170 Fixed yt2 = yt1;
171 Fixed xt10 = FIXED_FROM_FLOAT(t / 3000.);
172 Fixed xt20 = xt10;
173
174#define YT1_INCR FIXED_FROM_FLOAT(1 / 100.)
175#define YT2_INCR FIXED_FROM_FLOAT(1 / 163.)
176
177 for (uint32_t yy = 0; yy < info->height; yy++) {
178 uint16_t* line = (uint16_t*)pixels;
179 Fixed base = fixed_sin(yt1) + fixed_sin(yt2);
180 Fixed xt1 = xt10;
181 Fixed xt2 = xt20;
182
183 yt1 += YT1_INCR;
184 yt2 += YT2_INCR;
185
186#define XT1_INCR FIXED_FROM_FLOAT(1 / 173.)
187#define XT2_INCR FIXED_FROM_FLOAT(1 / 242.)
188
189#if OPTIMIZE_WRITES
190 /* optimize memory writes by generating one aligned 32-bit store
191 * for every pair of pixels.
192 */
193 uint16_t* line_end = line + info->width;
194
195 if (line < line_end) {
196 if (((uint32_t)(uintptr_t)line & 3) != 0) {
197 Fixed ii = base + fixed_sin(xt1) + fixed_sin(xt2);
198
199 xt1 += XT1_INCR;
200 xt2 += XT2_INCR;
201
202 line[0] = palette_from_fixed(ii >> 2);
203 line++;
204 }
205
206 while (line + 2 <= line_end) {
207 Fixed i1 = base + fixed_sin(xt1) + fixed_sin(xt2);
208 xt1 += XT1_INCR;
209 xt2 += XT2_INCR;
210
211 Fixed i2 = base + fixed_sin(xt1) + fixed_sin(xt2);
212 xt1 += XT1_INCR;
213 xt2 += XT2_INCR;
214
215 uint32_t pixel = ((uint32_t)palette_from_fixed(i1 >> 2) << 16) |
216 (uint32_t)palette_from_fixed(i2 >> 2);
217
218 ((uint32_t*)line)[0] = pixel;
219 line += 2;
220 }
221
222 if (line < line_end) {
223 Fixed ii = base + fixed_sin(xt1) + fixed_sin(xt2);
224 line[0] = palette_from_fixed(ii >> 2);
225 line++;

Callers 1

RenderPlasmaFunction · 0.85

Calls 2

fixed_sinFunction · 0.85
palette_from_fixedFunction · 0.85

Tested by

no test coverage detected