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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Echo/printf to write images in 5 LoC with zero libraries or headersnetpbm

129 点作者 stargrave超过 4 年前

13 条评论

rwmj超过 4 年前
Been doing this forever. From C it&#x27;s the easiest way to output images, using popen and piping to netpbm or imagemagick. Without error handling it goes like this:<p><pre><code> fp = popen (&quot;pnmtojpeg &gt; output.jpg&quot;, &quot;w&quot;); fprintf (fp, &quot;P3 %d %d 255&quot;, width, height); &#x2F;* print pixels as R G B triples *&#x2F; pclose (fp);</code></pre>
评论 #24997882 未加载
roywiggins超过 4 年前
PPM always reminds me of the 2008 winner of the Underhanded C Competition.<p><a href="http:&#x2F;&#x2F;www.underhanded-c.org&#x2F;_page_id_17.html" rel="nofollow">http:&#x2F;&#x2F;www.underhanded-c.org&#x2F;_page_id_17.html</a>
评论 #24999581 未加载
saagarjha超过 4 年前
I love love love NetPBM. It’s really easy to drop into your code for debugging or simple image exporting and it is so easy to work with. The amount of information you can get out of a good image is just so high that getting NetPBM output of your complicated thing can be so worth it, even if you are writing it from scratch each time. Plus you can kind of “read” it without an image viewer if you use P1.<p>The other one I really like is Graphviz :)
评论 #24997980 未加载
chubot超过 4 年前
Very related from 5 days ago:<p><i>How to create minimal music with code in any programming language</i><p><a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=24940624" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=24940624</a><p>Basically pipe values into mplayer, etc.<p>These should go in my #shell-the-good-parts series, which is very backlogged...<p><a href="https:&#x2F;&#x2F;www.oilshell.org&#x2F;blog&#x2F;tags.html?tag=shell-the-good-parts#shell-the-good-parts" rel="nofollow">https:&#x2F;&#x2F;www.oilshell.org&#x2F;blog&#x2F;tags.html?tag=shell-the-good-p...</a>
an_ko超过 4 年前
I&#x27;ve used GIMP as a game level editor this way. Draw your level, save it as PPM, and parse it into tiles in your game. The file is dead easy to parse. For a &quot;real game&quot; you might want to use Tiled or another actual map editor, but for little fun things this is light and Unixy and reliable.
oefrha超过 4 年前
&gt; you can easily slot into Netpbm’s wonderfully Unix-y set of tools by reading&#x2F;writing PPM on stdin&#x2F;stdout<p>No experience with the netpbm suite of tools, but ImageMagick (which TFA mentioned addition to netpbm) supports reading&#x2F;writing any supported format on stdin&#x2F;stdout, the skills of which I dare say are a bit more transferrable. A trivial example:<p><pre><code> $ &lt;my_image.ppm convert ppm:- jpeg:- | convert jpeg:- png:- &gt;my_image.png &amp;&amp; identify my_image.png my_image.png PNG 250x250 250x250+0+0 8-bit sRGB 15836B 0.000u 0:00.000</code></pre>
评论 #24997107 未加载
ratww超过 4 年前
This reminds me of Wavefront OBJ files, which is the format I use the mostly for a lot of my 3D stuff. It&#x27;s limited but super easy to parse and generate, and macOS Finder can preview it natively.<p><a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Wavefront_.obj_file" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Wavefront_.obj_file</a>
jedimastert超过 4 年前
Chris Wellons uses the same format extensively<p><a href="https:&#x2F;&#x2F;nullprogram.com&#x2F;blog&#x2F;2017&#x2F;11&#x2F;03&#x2F;" rel="nofollow">https:&#x2F;&#x2F;nullprogram.com&#x2F;blog&#x2F;2017&#x2F;11&#x2F;03&#x2F;</a> <a href="https:&#x2F;&#x2F;nullprogram.com&#x2F;blog&#x2F;2020&#x2F;06&#x2F;29&#x2F;" rel="nofollow">https:&#x2F;&#x2F;nullprogram.com&#x2F;blog&#x2F;2020&#x2F;06&#x2F;29&#x2F;</a>
userbinator超过 4 年前
When I first heard of these text-based raster image formats, I was surprised at both their inefficiency and seemingly widespread use (outside of PCs), especially given their age.<p>My go-to for uncompressed bitmaps is BMP, also trivial to read and write, and is easy to manipulate the image in memory with indexing operations.
spiritplumber超过 4 年前
PPM is easy to work with when you&#x27;re close to the metal. I remember one time I bet a MUSH admin that I could get a webcam working on the MUSH command line, and basically implemented an ascii cam over serial using a Parallax Propeller.<p>Won the bet and promptly got kicked from the MUSH. Fun times.
codazoda超过 4 年前
Finding this format might be timely for me. I broke out my TRS-80 CoCo the other day and I&#x27;ve been trying to do some graphics work inside its constraints. Maybe this format, or a variation of it, could work for that.
jnwatson超过 4 年前
There is something to be said for simple file formats.<p>I recall making pbms for my Data Structures class in the mid-90&#x27;s. It is definitely a good target for budding programmers.
memset超过 4 年前
This is interesting, netpbm is new to me!<p>Is there a similar format for video, which can be generated on the fly without transcoding or invoking ffmpeg?
评论 #24998028 未加载
评论 #24997671 未加载
评论 #24998040 未加载
评论 #24997583 未加载
评论 #25000358 未加载
评论 #24997532 未加载