summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2014-01-21 16:49:43 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2014-02-07 17:33:17 +0900
commit1c9865a8ae8bed79fd58e14a282a7eb98ce19baf (patch)
tree5ca36eb94614c77e4fd336df8818141342c0765f /src
parent2d071a2cd4dff27de960d93c7facf60eaef0cfa4 (diff)
Evas filters: Implement repeat and stretch for rgba to alpha
Use the mapped rendering to implement repeat and stretch with rgba to alpha buffers blending. If stretch is required, it will add one more (expensive) scaling step.
Diffstat (limited to 'src')
-rw-r--r--src/lib/evas/filters/evas_filter_blend.c111
1 files changed, 87 insertions, 24 deletions
diff --git a/src/lib/evas/filters/evas_filter_blend.c b/src/lib/evas/filters/evas_filter_blend.c
index 141d0af50e..b022f603c0 100644
--- a/src/lib/evas/filters/evas_filter_blend.c
+++ b/src/lib/evas/filters/evas_filter_blend.c
@@ -32,6 +32,21 @@ _filter_blend_cpu_alpha(Evas_Filter_Command *cmd)
32 DATA8 *maskdata, *dstdata; 32 DATA8 *maskdata, *dstdata;
33 int sw, sh, dw, dh, ox, oy, sx = 0, sy = 0, dx = 0, dy = 0, rows, cols, y; 33 int sw, sh, dw, dh, ox, oy, sx = 0, sy = 0, dx = 0, dy = 0, rows, cols, y;
34 34
35 /*
36 * NOTE: Alpha to alpha blending does not support stretching operations
37 * yet, because we don't have any scaling functions for alpha buffers.
38 * Also, I'm not going to implement it by converting to RGBA either.
39 */
40 if (cmd->draw.fillmode & EVAS_FILTER_FILL_MODE_STRETCH_XY)
41 {
42 CRI("Alpha to alpha blending does not support stretch");
43 return EINA_FALSE;
44 }
45
46 // TODO: Call _mapped_blend_cpu to implement repeat fill mode.
47 if (cmd->draw.fillmode != EVAS_FILTER_FILL_MODE_NONE)
48 ERR("Fill modes are not implemented for Alpha --> RGBA");
49
35 func = evas_common_alpha_func_get(cmd->draw.render_op); 50 func = evas_common_alpha_func_get(cmd->draw.render_op);
36 if (!func) 51 if (!func)
37 return EINA_FALSE; 52 return EINA_FALSE;
@@ -306,6 +321,10 @@ _filter_blend_cpu_mask_rgba(Evas_Filter_Command *cmd)
306 if (!evas_filter_buffer_alloc(cmd->output, cmd->output->w, cmd->output->h)) 321 if (!evas_filter_buffer_alloc(cmd->output, cmd->output->w, cmd->output->h))
307 return EINA_FALSE; 322 return EINA_FALSE;
308 323
324 // TODO: Call _mapped_blend_cpu to implement repeat fill mode.
325 if (cmd->draw.fillmode != EVAS_FILTER_FILL_MODE_NONE)
326 ERR("Fill modes are not implemented for Alpha --> RGBA");
327
309 in = cmd->input->backing; 328 in = cmd->input->backing;
310 out = cmd->output->backing; 329 out = cmd->output->backing;
311 sw = in->cache_entry.w; 330 sw = in->cache_entry.w;
@@ -349,49 +368,93 @@ _filter_blend_cpu_mask_rgba(Evas_Filter_Command *cmd)
349} 368}
350 369
351static Eina_Bool 370static Eina_Bool
371_image_draw_cpu_rgba2alpha(void *data EINA_UNUSED, void *context EINA_UNUSED,
372 void *surface, void *image,
373 int src_x, int src_y, int src_w, int src_h,
374 int dst_x, int dst_y, int dst_w, int dst_h,
375 int smooth EINA_UNUSED,
376 Eina_Bool do_async EINA_UNUSED)
377{
378 RGBA_Image *src = image;
379 RGBA_Image *dst = surface;
380 DATA32* srcdata = src->image.data;
381 DATA8* dstdata = dst->mask.data;
382 int x, y, sw, dw;
383 DEFINE_DIVIDER(3);
384
385 EINA_SAFETY_ON_FALSE_RETURN_VAL((src_w == dst_w) && (src_h == dst_h), EINA_FALSE);
386
387 sw = src->cache_entry.w;
388 dw = dst->cache_entry.w;
389
390 srcdata += src_y * sw;
391 dstdata += dst_y * dw;
392 for (y = src_h; y; y--)
393 {
394 DATA32 *s = srcdata + src_x;
395 DATA8 *d = dstdata + dst_x;
396 for (x = src_w; x; x--, d++, s++)
397 {
398 // TODO: Add weights like in YUV <--> RGB?
399 *d = DIVIDE(R_VAL(s) + G_VAL(s) + B_VAL(s));
400 }
401 srcdata += sw;
402 dstdata += dw;
403 }
404
405 return EINA_TRUE;
406}
407
408static Eina_Bool
352_filter_blend_cpu_rgba2alpha(Evas_Filter_Command *cmd) 409_filter_blend_cpu_rgba2alpha(Evas_Filter_Command *cmd)
353{ 410{
354 RGBA_Image *in, *out; 411 RGBA_Image *in, *out;
355 DATA8 *dstdata; 412 int sw, sh, dx, dy, dw, dh, sx, sy;
356 DATA32 *srcdata;
357 int sw, sh, dw, dh, ox, oy, sx = 0, sy = 0, dx = 0, dy = 0, rows, cols, y, x;
358 DEFINE_DIVIDER(3);
359 413
360 if (!evas_filter_buffer_alloc(cmd->output, cmd->output->w, cmd->output->h)) 414 if (!evas_filter_buffer_alloc(cmd->output, cmd->output->w, cmd->output->h))
361 return EINA_FALSE; 415 return EINA_FALSE;
362 416
363 in = cmd->input->backing; 417 in = cmd->input->backing;
364 out = cmd->output->backing; 418 out = cmd->output->backing;
419 EINA_SAFETY_ON_NULL_RETURN_VAL(in, EINA_FALSE);
420 EINA_SAFETY_ON_NULL_RETURN_VAL(out, EINA_FALSE);
421
422 sx = 0;
423 sy = 0;
365 sw = in->cache_entry.w; 424 sw = in->cache_entry.w;
366 sh = in->cache_entry.h; 425 sh = in->cache_entry.h;
426
367 dw = out->cache_entry.w; 427 dw = out->cache_entry.w;
368 dh = out->cache_entry.h; 428 dh = out->cache_entry.h;
369 ox = cmd->draw.ox; 429 dx = cmd->draw.ox;
370 oy = cmd->draw.oy; 430 dy = cmd->draw.oy;
371 srcdata = in->image.data;
372 dstdata = out->mask.data;
373
374 _clip_to_target(&sx, &sy, sw, sh, ox, oy, dw, dh, &dx, &dy, &rows, &cols);
375 // FIXME/TODO: Clip to context clip
376 431
377 if (cols <= 0 || rows <= 0) 432 if ((dw <= 0) || (dh <= 0) || (sw <= 0) || (sh <= 0))
378 return EINA_TRUE; 433 return EINA_TRUE;
379 434
380 srcdata += sy * sw; 435 // Stretch if necessary.
381 dstdata += dy * dw; 436 if ((sw != dw || sh != dh) && (cmd->draw.fillmode & EVAS_FILTER_FILL_MODE_STRETCH_XY))
382 for (y = rows; y; y--)
383 { 437 {
384 DATA32 *s = srcdata + sx; 438 Evas_Filter_Buffer *fb;
385 DATA8 *d = dstdata + dx; 439
386 for (x = cols; x; x--, d++, s++) 440 if (cmd->draw.fillmode & EVAS_FILTER_FILL_MODE_STRETCH_X)
387 { 441 sw = dw;
388 // TODO: Add weights? 442 if (cmd->draw.fillmode & EVAS_FILTER_FILL_MODE_STRETCH_Y)
389 *d = DIVIDE(R_VAL(s) + G_VAL(s) + B_VAL(s)); 443 sh = dh;
390 } 444
391 srcdata += sw; 445 BUFFERS_LOCK();
392 dstdata += dw; 446 fb = evas_filter_buffer_scaled_get(cmd->ctx, cmd->input, sw, sh);
447 BUFFERS_UNLOCK();
448
449 EINA_SAFETY_ON_NULL_RETURN_VAL(fb, EINA_FALSE);
450 fb->locked = EINA_FALSE;
451 in = fb->backing;
393 } 452 }
394 453
454 _mapped_blend_cpu(cmd->ENDT, NULL, in, out, cmd->draw.fillmode,
455 sx, sy, sw, sh, dx, dy, dw, dh,
456 _image_draw_cpu_rgba2alpha);
457
395 return EINA_TRUE; 458 return EINA_TRUE;
396} 459}
397 460