mirror of
				https://gitlab.freedesktop.org/wayland/wayland.git
				synced 2025-11-03 09:01:42 -05:00 
			
		
		
		
	Fix a few bugs in blur implementation
This commit is contained in:
		
							parent
							
								
									80d746f6e3
								
							
						
					
					
						commit
						49e868cb05
					
				
					 2 changed files with 6 additions and 21 deletions
				
			
		
							
								
								
									
										10
									
								
								cairo-util.c
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								cairo-util.c
									
										
									
									
									
								
							| 
						 | 
					@ -37,7 +37,7 @@ blur_surface(cairo_surface_t *surface, int margin)
 | 
				
			||||||
	uint8_t *src, *dst;
 | 
						uint8_t *src, *dst;
 | 
				
			||||||
	uint32_t *s, *d, a, p;
 | 
						uint32_t *s, *d, a, p;
 | 
				
			||||||
	int i, j, k, size, half;
 | 
						int i, j, k, size, half;
 | 
				
			||||||
	uint8_t kernel[35];
 | 
						uint32_t kernel[49];
 | 
				
			||||||
	double f;
 | 
						double f;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	size = ARRAY_LENGTH(kernel);
 | 
						size = ARRAY_LENGTH(kernel);
 | 
				
			||||||
| 
						 | 
					@ -49,11 +49,9 @@ blur_surface(cairo_surface_t *surface, int margin)
 | 
				
			||||||
	dst = malloc(height * stride);
 | 
						dst = malloc(height * stride);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	half = size / 2;
 | 
						half = size / 2;
 | 
				
			||||||
	a = 0;
 | 
					 | 
				
			||||||
	for (i = 0; i < size; i++) {
 | 
						for (i = 0; i < size; i++) {
 | 
				
			||||||
		f = (i - half);
 | 
							f = (i - half);
 | 
				
			||||||
		kernel[i] = exp(- f * f / 30.0) * 80;
 | 
							kernel[i] = exp(- f * f / ARRAY_LENGTH(kernel)) * 10000;
 | 
				
			||||||
		a += kernel[i];
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (i = 0; i < height; i++) {
 | 
						for (i = 0; i < height; i++) {
 | 
				
			||||||
| 
						 | 
					@ -69,6 +67,7 @@ blur_surface(cairo_surface_t *surface, int margin)
 | 
				
			||||||
			y = 0;
 | 
								y = 0;
 | 
				
			||||||
			z = 0;
 | 
								z = 0;
 | 
				
			||||||
			w = 0;
 | 
								w = 0;
 | 
				
			||||||
 | 
								a = 0;
 | 
				
			||||||
			for (k = 0; k < size; k++) {
 | 
								for (k = 0; k < size; k++) {
 | 
				
			||||||
				if (j - half + k < 0 || j - half + k >= width)
 | 
									if (j - half + k < 0 || j - half + k >= width)
 | 
				
			||||||
					continue;
 | 
										continue;
 | 
				
			||||||
| 
						 | 
					@ -78,6 +77,7 @@ blur_surface(cairo_surface_t *surface, int margin)
 | 
				
			||||||
				y += ((p >> 16) & 0xff) * kernel[k];
 | 
									y += ((p >> 16) & 0xff) * kernel[k];
 | 
				
			||||||
				z += ((p >> 8) & 0xff) * kernel[k];
 | 
									z += ((p >> 8) & 0xff) * kernel[k];
 | 
				
			||||||
				w += (p & 0xff) * kernel[k];
 | 
									w += (p & 0xff) * kernel[k];
 | 
				
			||||||
 | 
									a += kernel[k];
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			d[j] = (x / a << 24) | (y / a << 16) | (z / a << 8) | w / a;
 | 
								d[j] = (x / a << 24) | (y / a << 16) | (z / a << 8) | w / a;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					@ -96,6 +96,7 @@ blur_surface(cairo_surface_t *surface, int margin)
 | 
				
			||||||
			y = 0;
 | 
								y = 0;
 | 
				
			||||||
			z = 0;
 | 
								z = 0;
 | 
				
			||||||
			w = 0;
 | 
								w = 0;
 | 
				
			||||||
 | 
								a = 0;
 | 
				
			||||||
			for (k = 0; k < size; k++) {
 | 
								for (k = 0; k < size; k++) {
 | 
				
			||||||
				if (i - half + k < 0 || i - half + k >= height)
 | 
									if (i - half + k < 0 || i - half + k >= height)
 | 
				
			||||||
					continue;
 | 
										continue;
 | 
				
			||||||
| 
						 | 
					@ -106,6 +107,7 @@ blur_surface(cairo_surface_t *surface, int margin)
 | 
				
			||||||
				y += ((p >> 16) & 0xff) * kernel[k];
 | 
									y += ((p >> 16) & 0xff) * kernel[k];
 | 
				
			||||||
				z += ((p >> 8) & 0xff) * kernel[k];
 | 
									z += ((p >> 8) & 0xff) * kernel[k];
 | 
				
			||||||
				w += (p & 0xff) * kernel[k];
 | 
									w += (p & 0xff) * kernel[k];
 | 
				
			||||||
 | 
									a += kernel[k];
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			d[j] = (x / a << 24) | (y / a << 16) | (z / a << 8) | w / a;
 | 
								d[j] = (x / a << 24) | (y / a << 16) | (z / a << 8) | w / a;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										17
									
								
								cairo-util.h
									
										
									
									
									
								
							
							
						
						
									
										17
									
								
								cairo-util.h
									
										
									
									
									
								
							| 
						 | 
					@ -23,23 +23,6 @@
 | 
				
			||||||
#ifndef _CAIRO_UTIL_H
 | 
					#ifndef _CAIRO_UTIL_H
 | 
				
			||||||
#define _CAIRO_UTIL_H
 | 
					#define _CAIRO_UTIL_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct buffer {
 | 
					 | 
				
			||||||
	int width, height, stride;
 | 
					 | 
				
			||||||
	uint32_t name, handle;
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
struct buffer *
 | 
					 | 
				
			||||||
buffer_create(int fd, int width, int height, int stride);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
int
 | 
					 | 
				
			||||||
buffer_destroy(struct buffer *buffer, int fd);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
int
 | 
					 | 
				
			||||||
buffer_data(struct buffer *buffer, int fd, void *data);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
struct buffer *
 | 
					 | 
				
			||||||
buffer_create_from_cairo_surface(int fd, cairo_surface_t *surface);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
blur_surface(cairo_surface_t *surface, int margin);
 | 
					blur_surface(cairo_surface_t *surface, int margin);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue