MCPcopy Create free account
hub / github.com/ICE27182/Python-3D-renderer / fxaa

Function fxaa

pyrender.py:3321–3387  ·  view source on GitHub ↗

Frame post-processing input a frame and it will return a processed one if the sum of different reaches threshold, blur will be applied channel can either be 0 or 1. 0 for using green channel as luminance, whereas 1 means to calculate the luminace using all rgb values.

(frame, threshold=0.1, channel=0)

Source from the content-addressed store, hash-verified

3319
3320
3321def fxaa(frame, threshold=0.1, channel=0) -> list:
3322 """
3323 Frame post-processing
3324 input a frame and it will return a processed one
3325 if the sum of different reaches threshold, blur will be applied
3326 channel can either be 0 or 1. 0 for using green channel as luminance, whereas
3327 1 means to calculate the luminace using all rgb values.
3328 """
3329 width = len(frame[0])
3330 height = len(frame)
3331 frame_aa = (frame[0:1] +
3332 [[None] * width for _ in range(height - 2)] +
3333 frame[height - 1:])
3334 # I wrote this if here, so it won't be needed to run on every pixel
3335 # though it does make the code more redundant
3336 if channel == 0:
3337 threshold *= 1024
3338 for y in range(1, height - 1):
3339 frame_aa[y][0] = frame[y][0]
3340 frame_aa[y][width - 1] = frame[y][width - 1]
3341 for x in range(1, width - 1):
3342 if (abs(frame[y - 1][x][1] - frame[y][x][1]) +
3343 abs(frame[y + 1][x][1] - frame[y][x][1]) +
3344 abs(frame[y][x - 1][1] - frame[y][x][1]) +
3345 abs(frame[y][x + 1][1] - frame[y][x][1])) > threshold:
3346 frame_aa[y][x] = ((frame[y-1][x-1][0] + frame[y-1][x][0] + frame[y-1][x+1][0] +
3347 frame[y][x-1][0] + frame[y][x][0] + frame[y][x+1][0] +
3348 frame[y+1][x-1][0] + frame[y+1][x][0] + frame[y+1][x+1][0]) // 9,
3349 (frame[y-1][x-1][1] + frame[y-1][x][1] + frame[y-1][x+1][1] +
3350 frame[y][x-1][1] + frame[y][x][1] + frame[y][x+1][1] +
3351 frame[y+1][x-1][1] + frame[y+1][x][1] + frame[y+1][x+1][1]) // 9,
3352 (frame[y-1][x-1][2] + frame[y-1][x][2] + frame[y-1][x+1][2] +
3353 frame[y][x-1][2] + frame[y][x][2] + frame[y][x+1][2] +
3354 frame[y+1][x-1][2] + frame[y+1][x][2] + frame[y+1][x+1][2]) // 9,)
3355 else:
3356 frame_aa[y][x] = frame[y][x]
3357 elif channel == 1:
3358 threshold *= 512
3359 for y in range(1, height - 1):
3360 frame_aa[y][0] = frame[y][0]
3361 frame_aa[y][width - 1] = frame[y][width - 1]
3362 for x in range(1, width - 1):
3363 if (0.299 * (
3364 abs(frame[y][x][0] - frame[y + 1][x][0]) +
3365 abs(frame[y][x][0] - frame[y][x + 1][0])
3366 ) +
3367 0.587 * (
3368 abs(frame[y][x][1] - frame[y + 1][x][1]) +
3369 abs(frame[y][x][1] - frame[y][x + 1][1])
3370 ) +
3371 0.114 * (
3372 abs(frame[y][x][2] - frame[y + 1][x][2]) +
3373 abs(frame[y][x][2] - frame[y][x + 1][2])
3374 )
3375 ) >= threshold:
3376 frame_aa[y][x] = ((frame[y-1][x-1][0] + frame[y-1][x][0] + frame[y-1][x+1][0] +
3377 frame[y][x-1][0] + frame[y][x][0] + frame[y][x+1][0] +
3378 frame[y+1][x-1][0] + frame[y+1][x][0] + frame[y+1][x+1][0]) // 9,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected