mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-11-01 22:58:40 -04:00
Move cairo-util.[ch] to clients/
This commit is contained in:
parent
1db21f1cf5
commit
b91cd10fcb
6 changed files with 7 additions and 9 deletions
|
|
@ -11,12 +11,12 @@ all : $(egl_clients) $(cairo_clients)
|
|||
clean :
|
||||
rm -f $(egl_clients) $(cairo_clients) *.o
|
||||
|
||||
flower : flower.o window.o wayland-glib.o ../cairo-util.o
|
||||
gears : gears.o window.o wayland-glib.o ../cairo-util.o
|
||||
screenshot : screenshot.o wayland-glib.o ../cairo-util.o
|
||||
terminal : terminal.o window.o wayland-glib.o ../cairo-util.o
|
||||
image : image.o window.o wayland-glib.o ../cairo-util.o
|
||||
view : view.o window.o wayland-glib.o ../cairo-util.o
|
||||
flower : flower.o window.o wayland-glib.o cairo-util.o
|
||||
gears : gears.o window.o wayland-glib.o cairo-util.o
|
||||
screenshot : screenshot.o wayland-glib.o cairo-util.o
|
||||
terminal : terminal.o window.o wayland-glib.o cairo-util.o
|
||||
image : image.o window.o wayland-glib.o cairo-util.o
|
||||
view : view.o window.o wayland-glib.o cairo-util.o
|
||||
|
||||
terminal : LDLIBS += -lutil
|
||||
view : CFLAGS += $(POPPLER_CFLAGS)
|
||||
|
|
|
|||
255
clients/cairo-util.c
Normal file
255
clients/cairo-util.c
Normal file
|
|
@ -0,0 +1,255 @@
|
|||
/*
|
||||
* Copyright © 2008 Kristian Høgsberg
|
||||
*
|
||||
* Permission to use, copy, modify, distribute, and sell this software and its
|
||||
* documentation for any purpose is hereby granted without fee, provided that
|
||||
* the above copyright notice appear in all copies and that both that copyright
|
||||
* notice and this permission notice appear in supporting documentation, and
|
||||
* that the name of the copyright holders not be used in advertising or
|
||||
* publicity pertaining to distribution of the software without specific,
|
||||
* written prior permission. The copyright holders make no representations
|
||||
* about the suitability of this software for any purpose. It is provided "as
|
||||
* is" without express or implied warranty.
|
||||
*
|
||||
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
||||
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
||||
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <cairo.h>
|
||||
#include "cairo-util.h"
|
||||
|
||||
#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
|
||||
|
||||
void
|
||||
blur_surface(cairo_surface_t *surface, int margin)
|
||||
{
|
||||
int32_t width, height, stride, x, y, z, w;
|
||||
uint8_t *src, *dst;
|
||||
uint32_t *s, *d, a, p;
|
||||
int i, j, k, size, half;
|
||||
uint32_t kernel[49];
|
||||
double f;
|
||||
|
||||
size = ARRAY_LENGTH(kernel);
|
||||
width = cairo_image_surface_get_width(surface);
|
||||
height = cairo_image_surface_get_height(surface);
|
||||
stride = cairo_image_surface_get_stride(surface);
|
||||
src = cairo_image_surface_get_data(surface);
|
||||
|
||||
dst = malloc(height * stride);
|
||||
|
||||
half = size / 2;
|
||||
for (i = 0; i < size; i++) {
|
||||
f = (i - half);
|
||||
kernel[i] = exp(- f * f / ARRAY_LENGTH(kernel)) * 10000;
|
||||
}
|
||||
|
||||
for (i = 0; i < height; i++) {
|
||||
s = (uint32_t *) (src + i * stride);
|
||||
d = (uint32_t *) (dst + i * stride);
|
||||
for (j = 0; j < width; j++) {
|
||||
if (margin < j && j < width - margin) {
|
||||
d[j] = s[j];
|
||||
continue;
|
||||
}
|
||||
|
||||
x = 0;
|
||||
y = 0;
|
||||
z = 0;
|
||||
w = 0;
|
||||
a = 0;
|
||||
for (k = 0; k < size; k++) {
|
||||
if (j - half + k < 0 || j - half + k >= width)
|
||||
continue;
|
||||
p = s[j - half + k];
|
||||
|
||||
x += (p >> 24) * kernel[k];
|
||||
y += ((p >> 16) & 0xff) * kernel[k];
|
||||
z += ((p >> 8) & 0xff) * kernel[k];
|
||||
w += (p & 0xff) * kernel[k];
|
||||
a += kernel[k];
|
||||
}
|
||||
d[j] = (x / a << 24) | (y / a << 16) | (z / a << 8) | w / a;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < height; i++) {
|
||||
s = (uint32_t *) (dst + i * stride);
|
||||
d = (uint32_t *) (src + i * stride);
|
||||
for (j = 0; j < width; j++) {
|
||||
if (margin <= i && i < height - margin) {
|
||||
d[j] = s[j];
|
||||
continue;
|
||||
}
|
||||
|
||||
x = 0;
|
||||
y = 0;
|
||||
z = 0;
|
||||
w = 0;
|
||||
a = 0;
|
||||
for (k = 0; k < size; k++) {
|
||||
if (i - half + k < 0 || i - half + k >= height)
|
||||
continue;
|
||||
s = (uint32_t *) (dst + (i - half + k) * stride);
|
||||
p = s[j];
|
||||
|
||||
x += (p >> 24) * kernel[k];
|
||||
y += ((p >> 16) & 0xff) * kernel[k];
|
||||
z += ((p >> 8) & 0xff) * kernel[k];
|
||||
w += (p & 0xff) * kernel[k];
|
||||
a += kernel[k];
|
||||
}
|
||||
d[j] = (x / a << 24) | (y / a << 16) | (z / a << 8) | w / a;
|
||||
}
|
||||
}
|
||||
|
||||
free(dst);
|
||||
cairo_surface_mark_dirty(surface);
|
||||
}
|
||||
|
||||
void
|
||||
tile_mask(cairo_t *cr, cairo_surface_t *surface,
|
||||
int x, int y, int width, int height, int margin)
|
||||
{
|
||||
cairo_pattern_t *pattern;
|
||||
cairo_matrix_t matrix;
|
||||
int i, fx, fy;
|
||||
|
||||
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
|
||||
pattern = cairo_pattern_create_for_surface (surface);
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
fx = i & 1;
|
||||
fy = i >> 1;
|
||||
|
||||
cairo_matrix_init_translate(&matrix,
|
||||
-x + fx * (128 - width),
|
||||
-y + fy * (128 - height));
|
||||
cairo_pattern_set_matrix(pattern, &matrix);
|
||||
|
||||
cairo_reset_clip(cr);
|
||||
cairo_rectangle(cr,
|
||||
x + fx * (width - margin),
|
||||
y + fy * (height - margin),
|
||||
margin, margin);
|
||||
cairo_clip (cr);
|
||||
cairo_mask(cr, pattern);
|
||||
}
|
||||
|
||||
/* Top strecth */
|
||||
cairo_matrix_init_translate(&matrix, 64, 0);
|
||||
cairo_matrix_scale(&matrix, 64.0 / (width - 2 * margin), 1);
|
||||
cairo_matrix_translate(&matrix, -x - width / 2, -y);
|
||||
cairo_pattern_set_matrix(pattern, &matrix);
|
||||
cairo_rectangle(cr, x + margin, y, width - 2 * margin, margin);
|
||||
|
||||
cairo_reset_clip(cr);
|
||||
cairo_rectangle(cr,
|
||||
x + margin,
|
||||
y,
|
||||
width - 2 * margin, margin);
|
||||
cairo_clip (cr);
|
||||
cairo_mask(cr, pattern);
|
||||
|
||||
/* Bottom strecth */
|
||||
cairo_matrix_translate(&matrix, 0, -height + 128);
|
||||
cairo_pattern_set_matrix(pattern, &matrix);
|
||||
|
||||
cairo_reset_clip(cr);
|
||||
cairo_rectangle(cr, x + margin, y + height - margin,
|
||||
width - 2 * margin, margin);
|
||||
cairo_clip (cr);
|
||||
cairo_mask(cr, pattern);
|
||||
|
||||
/* Left strecth */
|
||||
cairo_matrix_init_translate(&matrix, 0, 64);
|
||||
cairo_matrix_scale(&matrix, 1, 64.0 / (height - 2 * margin));
|
||||
cairo_matrix_translate(&matrix, -x, -y - height / 2);
|
||||
cairo_pattern_set_matrix(pattern, &matrix);
|
||||
cairo_reset_clip(cr);
|
||||
cairo_rectangle(cr, x, y + margin, margin, height - 2 * margin);
|
||||
cairo_clip (cr);
|
||||
cairo_mask(cr, pattern);
|
||||
|
||||
/* Right strecth */
|
||||
cairo_matrix_translate(&matrix, -width + 128, 0);
|
||||
cairo_pattern_set_matrix(pattern, &matrix);
|
||||
cairo_rectangle(cr, x + width - margin, y + margin,
|
||||
margin, height - 2 * margin);
|
||||
cairo_reset_clip(cr);
|
||||
cairo_clip (cr);
|
||||
cairo_mask(cr, pattern);
|
||||
|
||||
cairo_pattern_destroy(pattern);
|
||||
cairo_reset_clip(cr);
|
||||
}
|
||||
|
||||
void
|
||||
tile_source(cairo_t *cr, cairo_surface_t *surface,
|
||||
int x, int y, int width, int height, int margin)
|
||||
{
|
||||
cairo_pattern_t *pattern;
|
||||
cairo_matrix_t matrix;
|
||||
int i, fx, fy;
|
||||
|
||||
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
|
||||
pattern = cairo_pattern_create_for_surface (surface);
|
||||
cairo_set_source(cr, pattern);
|
||||
cairo_pattern_destroy(pattern);
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
fx = i & 1;
|
||||
fy = i >> 1;
|
||||
|
||||
cairo_matrix_init_translate(&matrix,
|
||||
-x + fx * (128 - width),
|
||||
-y + fy * (128 - height));
|
||||
cairo_pattern_set_matrix(pattern, &matrix);
|
||||
|
||||
cairo_rectangle(cr,
|
||||
x + fx * (width - margin),
|
||||
y + fy * (height - margin),
|
||||
margin, margin);
|
||||
cairo_fill(cr);
|
||||
}
|
||||
|
||||
/* Top strecth */
|
||||
cairo_matrix_init_translate(&matrix, 64, 0);
|
||||
cairo_matrix_scale(&matrix, 64.0 / (width - 2 * margin), 1);
|
||||
cairo_matrix_translate(&matrix, -x - width / 2, -y);
|
||||
cairo_pattern_set_matrix(pattern, &matrix);
|
||||
cairo_rectangle(cr, x + margin, y, width - 2 * margin, margin);
|
||||
cairo_fill(cr);
|
||||
|
||||
/* Bottom strecth */
|
||||
cairo_matrix_translate(&matrix, 0, -height + 128);
|
||||
cairo_pattern_set_matrix(pattern, &matrix);
|
||||
cairo_rectangle(cr, x + margin, y + height - margin,
|
||||
width - 2 * margin, margin);
|
||||
cairo_fill(cr);
|
||||
|
||||
/* Left strecth */
|
||||
cairo_matrix_init_translate(&matrix, 0, 64);
|
||||
cairo_matrix_scale(&matrix, 1, 64.0 / (height - 2 * margin));
|
||||
cairo_matrix_translate(&matrix, -x, -y - height / 2);
|
||||
cairo_pattern_set_matrix(pattern, &matrix);
|
||||
cairo_rectangle(cr, x, y + margin, margin, height - 2 * margin);
|
||||
cairo_fill(cr);
|
||||
|
||||
/* Right strecth */
|
||||
cairo_matrix_translate(&matrix, -width + 128, 0);
|
||||
cairo_pattern_set_matrix(pattern, &matrix);
|
||||
cairo_rectangle(cr, x + width - margin, y + margin,
|
||||
margin, height - 2 * margin);
|
||||
cairo_fill(cr);
|
||||
}
|
||||
37
clients/cairo-util.h
Normal file
37
clients/cairo-util.h
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright © 2008 Kristian Høgsberg
|
||||
*
|
||||
* Permission to use, copy, modify, distribute, and sell this software and its
|
||||
* documentation for any purpose is hereby granted without fee, provided that
|
||||
* the above copyright notice appear in all copies and that both that copyright
|
||||
* notice and this permission notice appear in supporting documentation, and
|
||||
* that the name of the copyright holders not be used in advertising or
|
||||
* publicity pertaining to distribution of the software without specific,
|
||||
* written prior permission. The copyright holders make no representations
|
||||
* about the suitability of this software for any purpose. It is provided "as
|
||||
* is" without express or implied warranty.
|
||||
*
|
||||
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
||||
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
||||
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef _CAIRO_UTIL_H
|
||||
#define _CAIRO_UTIL_H
|
||||
|
||||
void
|
||||
blur_surface(cairo_surface_t *surface, int margin);
|
||||
|
||||
void
|
||||
tile_mask(cairo_t *cr, cairo_surface_t *surface,
|
||||
int x, int y, int width, int height, int margin);
|
||||
|
||||
void
|
||||
tile_source(cairo_t *cr, cairo_surface_t *surface,
|
||||
int x, int y, int width, int height, int margin);
|
||||
|
||||
#endif
|
||||
|
|
@ -46,7 +46,7 @@
|
|||
#include "wayland-util.h"
|
||||
#include "wayland-client.h"
|
||||
#include "wayland-glib.h"
|
||||
#include "../cairo-util.h"
|
||||
#include "cairo-util.h"
|
||||
|
||||
#include "window.h"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue