6 ms·
How hard would it be to display the contents of an image file on the screen?
- Vampiero 2y ago> It may be worth noting that Chafa uses more of the block symbols, but the printouts it makes look ugly to me, like a JPEG image compressed with very low quality. It may be worth nothing that Chafa can be configured to only use ASCII 219
- capitainenemo 2y agoYeah, that's one of many things I love about chafa. The charsets are very flexible allowing me to get something decentish working even in the limited default fonts and no fallbacks in putty on windows. Or blacklist stuff that looked bad in my preferred linux font. Another nice thing about it is the author made an ffmpeg patch (playable using -c:v rawvideo -pix_fmt rgba -f chafa) that was pretty darn handy for quickly triaging videos on a remote server without having to relay them to a more usable terminal. And it has sixel support too if you happen to be in a terminal that supports that. And since he's delegating to imagemagick, it has loaded every image format I've thrown at it, including RAW.
- pbmahol 2y agoimagemagick does not support RAW video formats.
- capitainenemo 2y agoI think you misunderstood. The video is using ffmpeg. I was talking about RAW from a camera which my imagemagick delegates to ufraw. But running ldd on my copy of chafa I see it now links to a ton of graphic libs directly.
- lmm 2y agoI'm amused by how quickly he shifts from "all existing image viewers have silly bugs, no-one knows what they're doing, I want to understand everything" to "here's some code I copy-pasted that seems to work". What a deeply quixotic approach to, uh, everything in this blog post.
- genewitch 2y agoafter having read the entire thing, i don't find the same amusement. In fact, you concatenated disparate quotes and put them out of order. 1: Image viewer [libraries] have silly bugs a. no one knows what they're doing? 2. Copy and paste code to get images on the screen a. not very accurately b. very slowly 3. I want to understand everything a. here's sRGB, here's Y'UV b. here's tone mapping c. etc the prose and overarching methodology reminds me of frinklang's data file[0] (https://frinklang.org/frinkdata/units.txt https://frinklang.org/frinkdata/units.txt) which is... hilariously and educationally opinionated about ... units and measurements and conversions. the writing style comports with how i approach problems and may not jive with other methodologies, maybe? If i have some problem i generally will try copying and pasting (or copilot.exe or whatever) just to see if the problem space has any state of art. If that does what i want, great. I'm done. if i need to do what i want 10,000 times, i usually will dig in and speed it up, or add features (event handling, etc) I also like scathing commentary about annoyances in technology, and this article had that, for sure. the webp aside was biting! [0] huh, this file has been updated massively since i last viewed it (mid 2010s) - it looks like earth has made some advancements in definitions of primatives - like Ampere - and things might be more exact, now. Hooray!
- metabagel 2y agoThis comment exemplifies the best of HN - respectful and informative.
- yoz 2y agoThank you for reminding me of Frink. Alan Eliasen's work is a delightful rabbit hole, and I'm so glad he's still maintaining and improving[1] Frink. [1] https://frinklang.org/experimental.html#FrinkTNG https://frinklang.org/experimental.html#FrinkTNG
- lmm 2y agoThe scathing, self-righteous arrogance, coupled with the evident genuine insight and talent, is why I have to either laugh or cry when he goes down the route of building yet another image viewer that will very clearly come with its own share of issues, rather than putting in the legwork to actually improve the situation.
- ChrisMarshallNY 2y agoYou want an idea of how tough it is, write a universal TIFF[0] reader (not writer -writers are simple). Fun stuff. BTDT. Got the T-shirt. [0] https://www.itu.int/itudoc/itu-t/com16/tiff-fx/docs/tiff6.pdf https://www.itu.int/itudoc/itu-t/com16/tiff-fx/docs/tiff6.pd...
- mananaysiempre 2y agoIs that even possible? I once tried to make a matched pyramid (JPEG-in-)TIFF reader/writer pair and to retain some compatibility with other people who do this sort of thing (GIS, medical images, etc.). Virtually nobody agrees on how you’re supposed to do it[1]: some prescribe storing smaller versions as siblings (a NextIFD chain started by the main image), some as children of the largest one (a NextIFD chain pointed to by the SubIFD link of the main image), some as children each other (a SubIFD chain started by the main image), some as both simultaneously (a chain of identical SubIFD and NextIFD fields started by the main image). And I mean, I could decide on something for my writer. But now I’m a reader and I get a TIFF file with some IFDs somehow linked by the NextIFD and/or SubIFD fields. WTF am I supposed to do with it? Is it a pyramid? Is it a multipage document? Is it a birdplane^W a sequence of pyramidal pages? I suppose I can walk the whole thing and construct a DAG, but again, how the hell can I tell what the DAG means? (And don’t take this as a knock against TIFF in general—as far as I know, it’s one of the few image formats that takes the possibility of large and larger-than-memory images seriously. I think HEIF also does? But ISO paywalled it after first making it publicly available, so, hard pass.) [1] Here’s a writeup that comes to similar conclusions: https://dpb587.me/entries/tiff-ifd-and-subifd-20240226 https://dpb587.me/entries/tiff-ifd-and-subifd-20240226
- ChrisMarshallNY 2y agoThis was in the ‘90s. About the time the ink was still wet on that spec. It was in C++, and I couldn’t do 100%, but I probably got about 80% (but not so performant). The weirdest thing, if I remember correctly, was pixel data with different sizes between stored components.
- ChrisMarshallNY 2y ago
- sgarland 2y agoEvery time I read a story involving terminals, I am amazed that they function in the first place. The sheer amount of absurd workarounds for backwards compatibility’s sake is mind-boggling.
- olddustytrail 2y agoActually, what's really amazing is that the wheel has been reinvented so many times except for terminals. Seriously, make something new that works either with ssh or wireguatd and cement your name in fame.
- dietr1ch 2y agoThere's a lot of things that could be reworked in much better ways if you drop backwards compatibility and think a bit about usability, but the real problem is the time it takes versus how "just fine" things work once you finally understand how to improve on old tools. To make things worse, tools get much better they get once you start thinking hard about re-implementing things. It seems it takes a lot of hatred to start such a project, and starting is the easy part as it only needs the first 80% of the effort.
- chungy 2y agoThe reason terminal-land is like this, is precisely because the wheel has been reinvented a few hundred times. Basically XKCD 927, perpetually.
- jdiff 2y agoNot really, because backwards compatibility with the most basic terminals has been maintained throughout it all. Instead of fragmentation, what we have is a very inconsistent soup.
- hnlmorg 2y agoSeveral options already exist: - HTTP management interfaces - RPCs such as what’s used in the Microsoft Windows ecosystem - Agent-based configuration management / IaC tools such as Puppet Each has their own strengths and weaknesses. But for all the criticisms people make about the terminal, and many of the complaints are completely justified, it’s often those weird eccentricities that also make the terminal such a powerful interface.
- eurekin 2y ago[flagged]
- Sesse__ 2y agoLet me guess, didn't read the article?
- pornel 2y agoPNG and JPEG are simple enough that a single person can write a useful decoder for them from scratch in a weekend or two. The newer formats achieve better compression by adding more and more stuff. They're year-long projects to reimplement, which makes almost everyone stick to their reference implementations.
- tomrod 2y agoThe newer ones are destined to failure by complexity then?
- lytedev 2y agoNah the space savings can significantly cut down on bandwidth costs at scale. They'll get (and have been?) pushed by Google and friends for that reason.
- deleted 2y ago[deleted]
- astrange 2y agoNewer image formats are based on video codecs, so if you already have the video codec around then theoretically it's not too bad.
- qingcharles 2y agoPNG and JPEG both have ICC color profiles, which complicates things. Even most Windows programs (including Windows Explorer thumbnails) don't display images correctly, which is infuriating.
- pornel 2y agoICC isn't too complex itself, but the bolted-on design of color profiles makes them annoying to handle, and easy to ignore. You can't just handle pixels, you need to handle pixels in a context of input and output profiles. That's a pain like code-page based text encodings before Unicode, and we haven't established a Unicode equivalent for pixels yet.
- throeurir 2y ago[flagged]
- tomrod 2y agoWith due respect, why are these requirements instead of nice-to-haves? The ability to perform an action, as an output, seems unrelated to target outcomes such as you proposed (be they morally justified, fads, or any other thing under the sun).
- throeurir 2y agoMorality is not something optional. It is question of survival and self preservation! You will not get killed, become homeless, or imprisoned if your program crashes. But if it does something morally wrong, maybe you will...
- tomrod 2y agoWhose morality? Ultimately, what we value is subjective. There are some seeming universal morals that most excuse or dismiss without a thought because they feel justified in the abrogation of natural rights and social contracts (to identify the spectrum).
- Throw839494849 2y agoCat pictures are the "universal morals" everybody agrees on! Anything else is questionable (or might be in future/past).
- tomrod 2y agoMy read is you're trying to be fun and agreeable here, but unfortunately, cats are not universally beloved and for some are abominations (either due to status as pets, because they prefer another pet, or the flavor/quality of the meat is off, or other elements we could identify in a universal census). That morals aren't universal is pretty universal :/
- jpc0 2y ago> Finally, remember that the only legal text you are bound by (if at all) is the actual text of the GPL license. It does not matter what Stallman says he intended with the GPL, or what the GPL FAQ says should happen in some fantasy land. Tell that to the lawyers when they send you a cease and desist. The reason non-gpl compliant software don't touch GPL is not because there might be a loophole, it's that there is ni precident set in court and they don't be the ones needing to do it. This requires lawyers with expertise in both copyright law and contract law. It doesn't matter what is copyrightable if you agreed to a contract that you wouldn't do that and that is what the GPL is, a contract that you agree to that mentions how you are allowed to use the code in question. In the end whether the GPL is enforceable in these edge cases is up to the courts not your interpretation of it and if you project becomes a roaring success do you really want to spend time and money on lawyers that you could rather spend on development.
- graemep 2y agoThe author quotes Google vs Oracle where the case was about using headers for compatibility: IIRC to provide an alternative implementation. This is different from vv which uses the headers to link to the GPLed code. IN most jurisdictions the GPL is a license, not a contract, and is definitely designed not to be a contract. That said, as far as I can see vv is in breach of the GPL. This is a case of someone who wants there to be a loophole convincing themselves there is one. I would definitely not redistribute vv because of that. More importantly I think it likely that people packaging software for Linux repos are not going to want to take the risk, and many will object to trying to find a loophole in GPL on principle too.
- tialaramex 2y ago> it's that there is ni precident set in court and they don't be the ones needing to do it. Ah yes, "ni precident". I would suggest people instead get advice from someone who has some idea what they're talking about and a good grasp of the English language to communicate it.
- BlueTemplar 2y agoI must protest, my good sir, I reckon that the Monthy Pythons have a perfect grasp of the English language! https://m.youtube.com/watch?v=zIV4poUZAQo https://m.youtube.com/watch?v=zIV4poUZAQo
- layer8 2y ago> [about the (R)IFF format] Having a generic container for everything doesn’t make sense. It’s a cool concept on paper, but when you have to write file loaders, it turns out that you have very specific needs, and none of those needs play well with “anything can happen lol”. Well, it's not like PNG and SVG are any different.
- HarHarVeryFunny 2y agoRIFF (used for .wav and.avi files) was just a pure container format. The actual payload content was compressed/represented by an open-ended set of CODECs, as indicated by the "FOURCC" (four character code) present in the file.
- layer8 2y agoI know, but what is the practical difference for the file loader? In both cases you have formats with open-ended extensions (PNG chunks and XML elements), and in both cases you have to make sure that the overall format matches what you expect.
- jdiff 2y agoFor SVG there are standards that define how to interact with unknown elements, and a set of standard elements which are actually part of the spec. With PNG, there's a minimum set of chunks that are required, and you can safely stick with those and get something that works for the vast majority of cases. This is totally different from a container which can contain any type of data in any type of format. If you get a valid PNG, you can load something meaningful from it. If you get a generic container, you might be able to inspect it at a surface level but there's no guarantee that the contents are even conceptually meaningful to you.
- layer8 2y agoEffectively the same is true for IFF-compliant formats like ILBM and AIFF, which are usually distinguished either by file extension or by file-system metadata. It’s a bit like criticizing a format for being XML-based, under the argument that XML can represent all kinds of payloads.
- TacticalCoder 2y ago[dead]
- HarHarVeryFunny 2y agoASCII renditions of photos have been around basically forever. Certainly printing these out on a line printer (80x24 screen was too small) was a thing in the mid 70's, and I'd bet go back to the first scanners. Maybe the first quantized picture credit should go to Roman mosaics which quality wise are about the same as a lo-res JPEG.
- astrange 2y agoFrom his footnotes: > I was able to find a reasonable amount of AVIF HDR images, but HEIC HDR is nowhere to be found. Anything taken by an iPhone camera is an HDR HEIF image… sort of. For backwards compatibility reasons it's an SDR image with an additional attached image called a gain map that HDRifies it. (This is mathematically worse for a reason I don't remember; it causes any picture taken at a concert with blacklights or blue spotlights to look bad. Once you see this you'll never unsee it.) I believe the very newest Sony cameras can also save HEIF images, however I don't feel like spending $2500 to upgrade my second-to-newest A7 to a newest A7 to find out. Lightroom also recently added HDR editing so maybe it can export them now?
- alexbock 2y ago> (This is mathematically worse for a reason I don't remember; it causes any picture taken at a concert with blacklights or blue spotlights to look bad. The iPhone camera sensor is prone to saturating and clipping the blue channel when strong light from a blue LED is in the frame. Once the blue channel clips at the maximum value, a typical HDR gain map won't do anything to restore more nuance to it because they're not designed to add high-frequency detail to a blob of clipped pixels with identical values in the base image.
- karlmedley 2y agoLightroom seems determined not to support HEIC export, even though iOS has trouble with all of Lightroom’s other HDR formats. From my testing: - JPEG with HDR gain map is not supported - AVIF and JXL HDR files look fine on initial export, but do not survive being sent anywhere from the Photo Library. So far I haven’t found a way to export an HDR file from Lightroom and then share it with anyone, iOS or Android.
- amelius 2y agoI once tried to get an image on the screen using the Linux framebuffer device, using Cairo in Python. It was for an embedded device. Turned out that the framebuffer supported only BGR ordering while Cairo only did RGB. Which was disappointing because I expected more flexibility.
- OhMeadhbh 2y agoI just use ImageMagick. I put the following function in my ~/.bash_aliases: scat () { if [ "" != "$1" ] then COLS=`tput cols` if [ "$COLS" -gt "96" ] ; then COLS=96 ; fi convert "$1" -resize $(( $COLS * 9))x^200 -background white -flatten sixel:- fi }
- Animats 2y agoHe missed JPEG 2000. It's used by the US National Map, the National Geospatial Intelligence Agency, CAT scanners, and Second Life. JPEG 2000 lets you zoom in and access higher levels of detail without reading the whole file. Or not zoom in and read a low-rez version from a small part of the file. So it's good for map data. Deep zooming doesn't come up much in web usage, and browsers don't support JPEG 2000. The JPEG 2000 decoder situation isn't good. OpenJPEG is slow and has had several reported vulnerabilities. There are better expensive decoders, and GPUs can be used to help with decoding, but the most popular decoders are slow.
- Scaevolus 2y agoArguably the largest usage of JPEG 2000 is as the format movies are distributed to theaters (Digital Cinema Package), and there's been recent work to make decoding faster with HTJ2K.
- Animats 2y agoThat's a different codec for a different application. "Unlike J2K-1, the HT coder is not fully embedded and hence quality scalability is largely sacrificed." [1] The outer file format with the metadata has some commonality, but that's about it. [1] https://ds.jpeg.org/whitepapers/jpeg-htj2k-whitepaper.pdf https://ds.jpeg.org/whitepapers/jpeg-htj2k-whitepaper.pdf
- rasz 2y agoAlso RED camera after some obfuscation.
- aidenn0 2y agoPDFs support j2k, so every PDF renderer includes a j2k decoder. I used this fact for a while because j2k significantly outperforms most JPEG encoders on line-art (e.g. comics). I switched back to JPEG recently though as there is now a JPEG encounter that targets high bpp only uses, and is only like 15% larger, while being fire and forget (as opposed to open JPEG, where I needed to adjust the quality factor depending on the source material).
- 2y ago
- Theodores 2y agoThe author questions whether anyone is using the modern web formats. As I see it, nobody should be using these formats, they should just be served by content delivery networks when JPG and PNG images are requested. The idea being that graphic artists and programmers work in JPG and PNG and the browser request these image formats to actually get webp, AVIF or whatever is the latest thing. Now, if you do right click, save image, it should then make another request with a different header that says webp, AVIF or whatever is not accepted, for the original JPG in high resolution with minimal compression to be downloaded.
- account42 2y agoAnd TFA instead just serves AVIF with no fallback :(
- shiomiru 2y agoSixel is a fun side quest as well, if you want to encode it on your own. You get to work on a color quantization and/or dithering algorithm in $CURRENT_YEAR. And if you're doing text with images, integrating both Sixel and Kitty is especially painful because they have completely different display models. (In particular, Sixel is cell based, so you get Z-ordering for free - with the caveat that writing text on top of images destroys the cells. Meanwhile, Kitty has Z-ordering, but it's per-image, so e.g. to draw a menu on top of an image that partially covers text, you must send a new image with space for the menu erased...) For those who are interested, the best resource I've found on this is the notcurses author's wiki: https://nick-black.com/dankwiki/index.php/Theory_and_Practice_of_Sprixels https://nick-black.com/dankwiki/index.php/Theory_and_Practic...