-
Notifications
You must be signed in to change notification settings - Fork 1
/
crt.scm
78 lines (59 loc) · 2.21 KB
/
crt.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
; CRT v1.0
; Tested on Gimp v2.8
(define (script-fu-crt image drawable)
; Start an undo group
(gimp-image-undo-group-start image)
; Save the context
(gimp-context-push)
; Set the background color to black
(gimp-context-set-background '(0 0 0))
; Scalings will be done without interpolation
(gimp-context-set-interpolation INTERPOLATION-NONE)
(let* (; Retrieve width and height of the original image
(width (car (gimp-image-width image)))
(height (car (gimp-image-height image)))
)
; Scale the image × 2
(gimp-image-scale image (* 2 width) (* 2 height))
; Create the scanlines by removing even lines (no info is lost since the
; image was upscaled)
(script-fu-erase-rows image drawable 0 0 0)
; Scale the image × 8
(gimp-image-scale image (* 8 width) (* 8 height))
; Ensure there is no transparent background after script-fu-erase-rows
(gimp-layer-flatten drawable)
; Lines drawn on the CRT are not perfect, add some imperfections
(plug-in-spread RUN-NONINTERACTIVE image drawable 2 2)
; Dots drawn on the CRT are not squares
(plug-in-gauss-rle2 RUN-NONINTERACTIVE image drawable 8 4)
; Compensate lost luminosity
(gimp-curves-spline drawable HISTOGRAM-VALUE 6 #(0 0 96 192 255 255))
; Traditional CRTs are not flat, add concativity
(plug-in-lens-distortion RUN-NONINTERACTIVE image drawable 0 0 10 0 0 20)
; Add an extra layer of black noise
(let* ((layer (car (gimp-layer-new image (* 8 width) (* 8 height)
RGB-IMAGE "Noise" 100 LIGHTEN-ONLY-MODE))))
(gimp-image-insert-layer image layer 0 -1)
; Do the noise
(plug-in-rgb-noise RUN-NONINTERACTIVE image layer 0 0 0.3 0.3 0.3 0.3)
; Blur the noise to make it more realistic
(plug-in-gauss-rle2 RUN-NONINTERACTIVE image layer 24 24)
)
)
; Restore the original context
(gimp-context-pop)
; End the undo group
(gimp-image-undo-group-end image)
; Flush the display
(gimp-displays-flush)
)
(script-fu-register "script-fu-crt"
"<Image>/Filters/Distorts/CRT emulator"
"CRT emulator"
"Frédéric BISSON"
"Frédéric BISSON"
"01/11/2014"
"RGB*"
SF-IMAGE "Image" 0
SF-DRAWABLE "Drawable" 0
)