TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Butchering HQX pixel art scaling filters

114 点作者 ux将近 11 年前

2 条评论

byuu将近 11 年前
&gt; Unfortunately, the reference code is more than 12.000 lines of unrolled C code. This code is basically duplicated without a thought in every single project.<p>Not by me. Overly bulky code is one of my pet peeves[1]. Here is my implementation of HQ2x in 6KB, 188 lines of code (not including the header file, which is 1KB and used for external linking.)<p><a href="http://pastebin.com/raw.php?i=DsNupdbc" rel="nofollow">http:&#x2F;&#x2F;pastebin.com&#x2F;raw.php?i=DsNupdbc</a><p>I devised a few observations to reduce the code. First is that the 256 patterns have four cases for each corner. If you rotate the eight surrounding pixels twice, the case blending rules match another corner (sans two cases which appear to be typos in the original algorithm. I asked the author, he apparently made the entire unrolled table by hand.) Now that the algorithm is cut down by 75%, put the switch statement into a lookup table.<p>To speed up the algorithm (and which further reduces its size), I use an old 16&lt;&gt;32-bit expand&#x2F;compact trick, a YUV lookup table, and a really clever mask compare that blargg came up with. At this point, my version is already significant faster than the original algorithm. But I also added in OpenMP parallelization support, which really makes things run fast on multicore systems.<p>But anyway ... this guy clearly bested me. 560 lines with HQ3x and HQ4x included is even more impressive. Hats off to him!<p>([1] I also have inflate in 8kb of code, unzip in (inflate+2KB) of code, PNG decompression in (inflate+8kb) of code, SHA256 hashing in 4KB of code, an SMTP client with authentication+MIME attachments+HTML in 8KB of code, an XML parser (sans DTDs) in 6KB of code, etc.)
评论 #7925831 未加载
评论 #7925935 未加载
评论 #7927111 未加载
madlag将近 11 年前
Nice stuff ! I am wondering how we could use it to improve some of our stuff with this ...