summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-08-30 03:53:25 -0300
committerWerner Almesberger <werner@almesberger.net>2016-08-30 03:55:27 -0300
commitfe2d12a590aa637881c7f3fc53d3cca9e246c195 (patch)
tree4e416fb6381a1cf5912cb35cb2796ee0424b714d
parentb710a5cbfa013f72c91b877f3ba9e613dba92fd6 (diff)
downloadeeshow-fe2d12a590aa637881c7f3fc53d3cca9e246c195.tar.gz
eeshow-fe2d12a590aa637881c7f3fc53d3cca9e246c195.tar.bz2
eeshow-fe2d12a590aa637881c7f3fc53d3cca9e246c195.zip
gfx/cro.c (cro_img): add alpha mode; get rid of paint_yellow
This didn't work before because we didn't use CAIRO_OPERATOR_SOURCE.
-rw-r--r--TODO2
-rw-r--r--gfx/cro.c17
-rw-r--r--gfx/cro.h2
-rw-r--r--gfx/diff.c4
-rw-r--r--gui/index.c36
5 files changed, 19 insertions, 42 deletions
diff --git a/TODO b/TODO
index 3932e9b..2f0be3c 100644
--- a/TODO
+++ b/TODO
@@ -78,5 +78,3 @@ GUI/index:
- needs keyboard shortcut to invoke
- add keyboard shortcuts (cursor, Enter)
- examine interaction with background, suppress conflicts
-- try to use alpha instead of "yellow"; consider CAIRO_OPERATOR_SOURCE:
- https://www.cairographics.org/FAQ/#paint_from_a_surface
diff --git a/gfx/cro.c b/gfx/cro.c
index bd7b2ee..bf51cb5 100644
--- a/gfx/cro.c
+++ b/gfx/cro.c
@@ -810,7 +810,7 @@ void cro_canvas_draw(struct cro_ctx *cc, cairo_t *cr, int xo, int yo,
uint32_t *cro_img(struct cro_ctx *cc, struct cro_ctx *cc_extra,
int xo, int yo, int w, int h,
- float scale, cairo_t **res_cr, int *res_stride)
+ float scale, double alpha, cairo_t **res_cr, int *res_stride)
{
int stride;
uint32_t *data;
@@ -822,11 +822,20 @@ uint32_t *cro_img(struct cro_ctx *cc, struct cro_ctx *cc_extra,
data = alloc_size(stride * h);
s = cairo_image_surface_create_for_data((unsigned char *) data,
- CAIRO_FORMAT_RGB24, w, h, stride);
+ alpha == 1 ? CAIRO_FORMAT_RGB24 : CAIRO_FORMAT_ARGB32,
+ w, h, stride);
cr = cairo_create(s);
- cairo_set_source_rgb(cr, 1, 1, 1);
- cairo_paint(cr);
+ if (alpha == 1) {
+ cairo_set_source_rgb(cr, 1, 1, 1);
+ cairo_paint(cr);
+ } else {
+ cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
+ cairo_set_source_rgba(cr, 1, 1, 1, alpha);
+ cairo_paint(cr);
+ cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
+
+ }
/*
* @@@ hack ! we should use a properly scaled width for each
diff --git a/gfx/cro.h b/gfx/cro.h
index fb9f32a..5b22a1b 100644
--- a/gfx/cro.h
+++ b/gfx/cro.h
@@ -49,7 +49,7 @@ void cro_canvas_draw(struct cro_ctx *cc, cairo_t *cr,
uint32_t *cro_img(struct cro_ctx *cc, struct cro_ctx *cc_extra,
int x0, int yo, int w, int h,
- float scale, cairo_t **res_cr, int *res_stride);
+ float scale, double alpha, cairo_t **res_cr, int *res_stride);
cairo_surface_t *cro_img_surface(struct cro_ctx *cc);
#endif /* !GFX_CRO_H */
diff --git a/gfx/diff.c b/gfx/diff.c
index a00e928..68c3ef9 100644
--- a/gfx/diff.c
+++ b/gfx/diff.c
@@ -403,9 +403,9 @@ static cairo_t *make_diff(cairo_t *cr, int cx, int cy, float scale,
yo = -ymin * scale;
}
- img_old = cro_img(old, old_extra, xo, yo, sw, sh, scale,
+ img_old = cro_img(old, old_extra, xo, yo, sw, sh, scale, 1,
&old_cr, &stride);
- img_new = cro_img(new, new_extra, xo, yo, sw, sh, scale,
+ img_new = cro_img(new, new_extra, xo, yo, sw, sh, scale, 1,
NULL, NULL);
struct diff diff = {
diff --git a/gui/index.c b/gui/index.c
index f87f158..72ccfe7 100644
--- a/gui/index.c
+++ b/gui/index.c
@@ -143,7 +143,7 @@ static void thumb_set_style(struct gui_sheet *sheet, bool selected)
}
if (sheet->thumb_yellow)
- style.bg = RGBA(1.0, 1.0, 0, 1);
+ style.bg = RGBA(1.0, 1.0, 0, 1);
overlay_style(sheet->thumb_over, &style);
}
@@ -229,32 +229,6 @@ static bool best_ratio(const struct gui *gui)
}
-/*
- * @@@ We should use Cairo's alpha blending instead of manipulating pixels.
- * The idea would be to make an ARGB32 surface for the thumbnail and then
- * pre-fill it with alpha = 0. Then we make a solid background and paint the
- * thumbnail over it. Alas, this produces artefacts, spots where background
- * color shines through.
- */
-
-#define MASK 0xffffff
-
-
-static void paint_yellow(uint32_t *data, int w, int h, int stride)
-{
- uint32_t *p;
- int line = stride >> 2;
- int x, y;
-
- for (y = 0; y != h; y++) {
- p = data + y * line;
- for (x = 0; x != w; x++)
- if ((p[x] & MASK) == MASK)
- p[x] = 0xffff00;
- }
-}
-
-
static void index_render_sheet(const struct gui *gui,
struct gui_sheet *sheet)
{
@@ -262,7 +236,6 @@ static void index_render_sheet(const struct gui *gui,
float fw, fh, f;
bool yellow = 0;
int xo, yo;
- uint32_t *data;
int stride;
if (!sheet->gfx_thumb) {
@@ -303,11 +276,8 @@ static void index_render_sheet(const struct gui *gui,
xo = -(xmin + w / 2) * f + thumb_w / 2;
yo = -(ymin + h / 2) * f + thumb_h / 2;
- data = cro_img(gfx_user(sheet->gfx_thumb), NULL,
- xo, yo, thumb_w, thumb_h, f, NULL, &stride);
-
- if (yellow)
- paint_yellow(data, thumb_w, thumb_h, stride);
+ cro_img(gfx_user(sheet->gfx_thumb), NULL,
+ xo, yo, thumb_w, thumb_h, f, 0, NULL, &stride);
sheet->thumb_surf = cro_img_surface(gfx_user(sheet->gfx_thumb));
sheet->thumb_w = thumb_w;