@@ -30,13 +30,13 @@ const _error_diffusion_kwargs = """
30
30
type `color_space` before looking up the closest color. Defaults to `true`.
31
31
"""
32
32
33
- struct ErrorDiffusion{F,C } <: AbstractDither
33
+ struct ErrorDiffusion{C,F } <: AbstractDither
34
34
filter:: F
35
35
offset:: Int
36
36
clamp_error:: Bool
37
37
end
38
- function ErrorDiffusion (filter:: AbstractMatrix , offset; color_space = XYZ, clamp_error= true )
39
- return ErrorDiffusion {typeof(filter),float32(color_space )} (filter, offset, clamp_error)
38
+ function ErrorDiffusion (filter:: AbstractMatrix , offset, colorspace = XYZ; clamp_error= true )
39
+ return ErrorDiffusion {float32(colorspace),typeof(filter )} (filter, offset, clamp_error)
40
40
end
41
41
42
42
function construct_filter (:: Type{T} , alg:: ErrorDiffusion ) where {T<: Real }
@@ -85,16 +85,16 @@ function diffuse_error!(img, err, I, filter)
85
85
end
86
86
87
87
function colordither (
88
- alg:: ErrorDiffusion{C} ,
88
+ alg:: ErrorDiffusion{C,F } ,
89
89
img:: GenericImage ,
90
90
cs:: AbstractVector{<:Pixel} ,
91
91
metric:: DifferenceMetric ,
92
- ) where {C}
92
+ ) where {C,F }
93
93
# this function does not yet support OffsetArray
94
94
require_one_based_indexing (img)
95
95
index = Matrix {UInt8} (undef, size (img)... ) # allocate matrix of color indices
96
96
97
- # C is the `color_space ` in which the error is diffused
97
+ # C is the `colorspace ` in which the error is diffused
98
98
img = convert .(C, img)
99
99
cs_err = C .(cs)
100
100
cs_lab = Lab .(cs)
@@ -135,7 +135,9 @@ $(_error_diffusion_kwargs)
135
135
Scale." SID 1975, International Symposium Digest of Technical Papers,
136
136
vol 1975m, pp. 36-37.
137
137
"""
138
- SimpleErrorDiffusion (; kwargs... ) = ErrorDiffusion (SIMPLE_ERROR_DIFFUSION, 1 ; kwargs... )
138
+ function SimpleErrorDiffusion (args... ; kwargs... )
139
+ return ErrorDiffusion (SIMPLE_ERROR_DIFFUSION, 1 , args... ; kwargs... )
140
+ end
139
141
const SIMPLE_ERROR_DIFFUSION = [0 1 ; 1 0 ]// 2
140
142
141
143
"""
@@ -154,7 +156,7 @@ $(_error_diffusion_kwargs)
154
156
Scale." SID 1975, International Symposium Digest of Technical Papers,
155
157
vol 1975m, pp. 36-37.
156
158
"""
157
- FloydSteinberg (; kwargs... ) = ErrorDiffusion (FLOYD_STEINBERG, 2 ; kwargs... )
159
+ FloydSteinberg (args ... ; kwargs... ) = ErrorDiffusion (FLOYD_STEINBERG, 2 , args ... ; kwargs... )
158
160
const FLOYD_STEINBERG = [0 0 7 ; 3 5 1 ]// 16
159
161
160
162
"""
@@ -175,7 +177,7 @@ $(_error_diffusion_kwargs)
175
177
the Display of Continuous Tone Pictures on Bi-Level Displays," Computer
176
178
Graphics and Image Processing, vol. 5, pp. 13-40, 1976.
177
179
"""
178
- JarvisJudice (; kwargs... ) = ErrorDiffusion (JARVIS_JUDICE, 3 ; kwargs... )
180
+ JarvisJudice (args ... ; kwargs... ) = ErrorDiffusion (JARVIS_JUDICE, 3 , args ... ; kwargs... )
179
181
const JARVIS_JUDICE = [0 0 0 7 5 ; 3 5 7 5 3 ; 1 3 5 3 1 ]// 48
180
182
181
183
"""
@@ -195,7 +197,7 @@ $(_error_diffusion_kwargs)
195
197
for bilevel image hardcopy reproduction." Research Report RZ1060, IBM
196
198
Research Laboratory, Zurich, Switzerland, 1981.
197
199
"""
198
- Stucki (; kwargs... ) = ErrorDiffusion (STUCKI, 3 ; kwargs... )
200
+ Stucki (args ... ; kwargs... ) = ErrorDiffusion (STUCKI, 3 , args ... ; kwargs... )
199
201
const STUCKI = [0 0 0 8 4 ; 2 4 8 4 2 ; 1 2 4 2 1 ]// 42
200
202
201
203
"""
@@ -214,7 +216,7 @@ $(_error_diffusion_kwargs)
214
216
[1] Burkes, D., "Presentation of the Burkes error filter for use in preparing
215
217
continuous-tone images for presentation on bi-level devices." Unpublished, 1988.
216
218
"""
217
- Burkes (; kwargs... ) = ErrorDiffusion (BURKES, 3 ; kwargs... )
219
+ Burkes (args ... ; kwargs... ) = ErrorDiffusion (BURKES, 3 , args ... ; kwargs... )
218
220
const BURKES = [0 0 0 8 4 ; 2 4 8 4 2 ]// 32
219
221
220
222
"""
@@ -231,7 +233,7 @@ Also known as Sierra3 or three-row Sierra due to the filter shape.
231
233
232
234
$(_error_diffusion_kwargs)
233
235
"""
234
- Sierra (; kwargs... ) = ErrorDiffusion (SIERRA, 3 ; kwargs... )
236
+ Sierra (args ... ; kwargs... ) = ErrorDiffusion (SIERRA, 3 , args ... ; kwargs... )
235
237
const SIERRA = [0 0 0 5 3 ; 2 4 5 4 2 ; 0 2 3 2 0 ]// 32
236
238
237
239
"""
@@ -246,7 +248,7 @@ Also known as Sierra2.
246
248
247
249
$(_error_diffusion_kwargs)
248
250
"""
249
- TwoRowSierra (; kwargs... ) = ErrorDiffusion (TWO_ROW_SIERRA, 3 ; kwargs... )
251
+ TwoRowSierra (args ... ; kwargs... ) = ErrorDiffusion (TWO_ROW_SIERRA, 3 , args ... ; kwargs... )
250
252
const TWO_ROW_SIERRA = [0 0 0 4 3 ; 1 2 3 2 1 ]// 16
251
253
252
254
"""
@@ -261,7 +263,7 @@ Also known as Sierra-2-4A filter.
261
263
262
264
$(_error_diffusion_kwargs)
263
265
"""
264
- SierraLite (; kwargs... ) = ErrorDiffusion (SIERRA_LITE, 2 ; kwargs... )
266
+ SierraLite (args ... ; kwargs... ) = ErrorDiffusion (SIERRA_LITE, 2 , args ... ; kwargs... )
265
267
const SIERRA_LITE = [0 0 2 ; 1 1 0 ]// 4
266
268
267
269
"""
@@ -276,7 +278,7 @@ Error diffusion algorithm using the filter
276
278
277
279
$(_error_diffusion_kwargs)
278
280
"""
279
- Atkinson (; kwargs... ) = ErrorDiffusion (ATKINSON, 2 ; kwargs... )
281
+ Atkinson (args ... ; kwargs... ) = ErrorDiffusion (ATKINSON, 2 , args ... ; kwargs... )
280
282
const ATKINSON = [0 0 1 1 ; 1 1 1 0 ; 0 1 0 0 ]// 8
281
283
282
284
"""
@@ -296,7 +298,7 @@ $(_error_diffusion_kwargs)
296
298
IS&T's 46th Annual Conference, May 9-14, 1993, Final Program and Advanced Printing of
297
299
Paper Summaries, pp 113-115 (1993).
298
300
"""
299
- Fan93 (; kwargs... ) = ErrorDiffusion (FAN_93, 3 ; kwargs... )
301
+ Fan93 (args ... ; kwargs... ) = ErrorDiffusion (FAN_93, 3 , args ... ; kwargs... )
300
302
const FAN_93 = [0 0 0 7 ; 1 3 5 0 ]// 16
301
303
302
304
"""
@@ -314,7 +316,7 @@ $(_error_diffusion_kwargs)
314
316
[1] J. N. Shiau and Z. Fan. "Method for quantization gray level pixel data with extended
315
317
distribution set", US 5353127A, United States Patent and Trademark Office, Oct. 4, 1993
316
318
"""
317
- ShiauFan (; kwargs... ) = ErrorDiffusion (SHIAU_FAN, 3 ; kwargs... )
319
+ ShiauFan (args ... ; kwargs... ) = ErrorDiffusion (SHIAU_FAN, 3 , args ... ; kwargs... )
318
320
const SHIAU_FAN = [0 0 0 4 ; 1 1 2 0 ]// 8
319
321
320
322
"""
@@ -335,7 +337,7 @@ $(_error_diffusion_kwargs)
335
337
with reduced worm artifacts" Color Imaging: Device-Independent Color, Color Hard Copy,
336
338
and Graphics Arts, volume 2658, pages 222–225. SPIE, March 1996.
337
339
"""
338
- ShiauFan2 (; kwargs... ) = ErrorDiffusion (SHIAU_FAN_2, 4 ; kwargs... )
340
+ ShiauFan2 (args ... ; kwargs... ) = ErrorDiffusion (SHIAU_FAN_2, 4 , args ... ; kwargs... )
339
341
const SHIAU_FAN_2 = [0 0 0 0 8 ; 1 1 2 4 0 ]// 16
340
342
341
343
"""
@@ -356,5 +358,7 @@ There is no reason to use this algorithm, which is why DitherPunk doesn't export
356
358
# References
357
359
[1] http://www.efg2.com/Lab/Library/ImageProcessing/DHALF.TXT
358
360
"""
359
- FalseFloydSteinberg (; kwargs... ) = ErrorDiffusion (FALSE_FLOYD_STEINBERG, 1 ; kwargs... )
361
+ function FalseFloydSteinberg (args... ; kwargs... )
362
+ return ErrorDiffusion (FALSE_FLOYD_STEINBERG, 1 , args... ; kwargs... )
363
+ end
360
364
const FALSE_FLOYD_STEINBERG = [0 3 ; 3 2 ]// 8
0 commit comments