# Box Blur Challenge

The challenge is to implement a box blur in any language. The input will be as a 32-bit uncompressed bitmap, BGRA, preceded by one byte defining the radius of the blur and one byte defining the width of the image. The output should be in the same format as the input (minus the blur radius, of course).

Fastest code wins, and a 50-point bounty to the shortest entry, and another to the "most obfuscated" in my opinion.

-
Is this 1 dimensional or 2 dimensional? if 2, how do we determine the image dimensions? – Keith Randall Jun 11 '11 at 4:53
Challenge is way too vague as it stands - at the very least you need to specify the blur algorithm much more precisely – Paul R Jun 11 '11 at 14:03
@minitech: if the image is 2-D, then we'll need to know the X and Y dimensions, not just the total size (X*Y) which we can get from the input size. – Keith Randall Jun 12 '11 at 18:37
@Joey: for greyscale yes, but for RGBA there is more than one way of applying a box blur – Paul R Jun 12 '11 at 20:19
Is the input a bitmap (1 bit per pixel), or a greyscale pixmap (with 8? 32? bits per pixel)? – MtnViewMark Jun 13 '11 at 0:11

## 1 Answer

eTeX, too many chars

\immediate\openout5\jobname.out\let\x\newlinechar\x0\catcode0=12\let\y
\linepenalty\def\ndef#1{\expandafter\edef\csname\the#1\endcsname}\loop
\lccode0\x\lowercase{\ndef\x{^^@}}\ifnum\x<255\advance\x1\repeat\def\R
#1 #2 #3 {\Sr#1 \def\Y{#2}\x=0 \Rl#3????}\def\Rle#1\fi#2\Rc{\fi\Rl#1}
\def\Ry#1#2{\ndef{\y;\the\x.#1}{\number#2 }}\def\Rc#1#2#3#4{\ifnum\Y=
\y\Rle#1#2#3#4\fi\advance\y1 \Ry1#1\Ry2#2\Ry3#3\Ry4#4\Rc}\def\Re{\fi\x
-1\immediate\write5{\Bl1;1.!}\end}\def\Rl#1{\edef\X{\the\x}\advance\x1
\y0 \ifx?#1\Re\fi\Rc#1}\def\Bl#1;{\ifnum\X<#1 \Ble\fi\Bc#1;}\def\Ble
#1!{\fi}\def\Bc#1;#2.{\ifnum\Y<#2 \Bce\fi\By#1;#2.1\By#1;#2.2\By
#1;#2.3\By#1;#2.4\expandafter\Bc\number#1\expandafter;\the\numexpr
#2+1.}\def\Bce#1#2#3;{#1\expandafter\Bl\the\numexpr#3+1;1.}\def\Sr#1
{\x-#1\def~{}\Sl#1 \edef~{\def\noexpand\By####1;####2.####3{\noexpand
\csname\noexpand\the\numexpr(\unexpanded\expandafter{~}+0)/(\unexpanded
{\Bt\X}#1 ####1 *\unexpanded{\Bt\Y}#1 ####2 )\endcsname}}~}\def\Sl#1
{\ifnum#1<\x\else\y-#1 \Sc#1 \advance\x1 \Sl#1 \fi}\def\Sc#1 {\ifnum
#1<\y\else\edef~{\unexpanded\expandafter{~}\unexpanded{\expandafter\t
\csname\the}\numexpr####2+\the\x;\noexpand\the\numexpr####1+\the\y
.####3\endcsname}\advance\y1 \Sc#1 \fi}\def\t#1{\ifx\relax#1\else+#1\fi
}\def\Bt#1#2 #3 {\expandafter\use\the\numexpr(\ifnum#2<#3 1+#2\else
#3\fi+\ifnum\numexpr#2+#3>#1 #1-#3\else#2\fi);}\def\use#1;{#1}
\expandafter\R\noexpand


Run as for instance

etex filename 10 3 55555555qqqq55555555qqqq5555qqqqqqqq5555qqqqqqqq
`
-