... but it's still better than using pygame's scaling functions to do the same. Whoever wrote those has no idea whatsoever about signal processing, colour spaces or maths in general. Try it out - scale a simple drawing down by a factor of 20, scale it back to original size, and weep about the result.
Code: Select all
init python:
import pygame
class FlatBlur(im.ImageBase):
def __init__(self, baseImage, radius, **properties):
baseImage = im.image(baseImage)
super(FlatBlur, self).__init__(baseImage, radius, **properties)
self.image = baseImage
self.radius = radius
def get_mtime(self):
return self.image.get_mtime()
def load(self):
surf = im.cache.get(self.image)
rv = renpy.display.pgrender.surface(surf.get_size(), True)
width = surf.get_width()
height = surf.get_height()
# output surface
rvpa = pygame.PixelArray(rv)
for x in range(0, width -1):
for y in range(0, height -1):
# calculate the region we want to use for averaging
top = max(0, y - self.radius)
left = max(0, x - self.radius)
bottom = min(height - 1, y + self.radius)
right = min(width - 1, x + self.radius)
r = pygame.Rect(left, top, (right - left), (bottom - top))
rvpa[x][y] = rv.map_rgb(pygame.transform.average_color(surf, r))
return rv
def predict_files(self):
return self.image.predict_files()
Code: Select all
image bg filename_blurred = FlatBlur("filename.jpg", 5)