14 ms·
John Carmack on JPEG
- nt2h9uh238h 5y agoThis sounds exactly like Cloudflare could add this as a 1-click feature to save 50% bandwidth.
- sandreas 5y agoInteresting approach, but what about more modern alternatives like webp and avif? I know that jpeg has its advantages but the current the lack of support is a problem, that time will solve.
- grishka 5y agoIIRC all video codecs (WebP and AVIF are simply intra frames from VP8 and AV1 respectively) work in the YUV color space because the color information is much lower frequency than brightness, and thus YUV is more easily compressible than RGB. Chroma subsampling (making each U and V correspond to a 2x2 block of Y) works for the same reason.
- jokoon 5y agoYeah, I'm more convinced by Bellard's BPG. The comparison speaks for itself: https://bellard.org/bpg/lena.html https://bellard.org/bpg/lena.html
- WalterGR 5y agoI feel daft, but: The vast majority of images are jpegs, which are internally 420 YUV, but they get converted to 32 bit RGB for use in apps. Using native YUV formats would save half the memory and rendering bandwidth, speed loading, and provide a tiny quality improvement. What does he mean by using native YUV formats? Something (I wave my hand) in the rendering pipeline from the JPEG in memory to pixels on the screen?
- vlovich123 5y agoYup. You typically first decode the JPEG into a raw image format in GPU memory & then that gets transferred to scanout HW that actually sends it to the display (e.g. via HDMI). The argument feels a bit weak though. At that point why not just use JPEG through your entire pipeline & save even more bandwidth. Of course you have to decompress if you’re modifying the image in any way so it doesn’t help there.
- edflsafoiewq 5y agoYou can't texel-fetch directly from JPEG data, it has to be decompressed first.
- vlovich123 5y agoYes of course. GPUs already support compressed textures though that get decompressed on the fly. Of course JPEG has a lot of baggage that actually makes it a poor format for this but perhaps newer ones might be useful. What you lose in “optimality” (compression schemes designed for GPUs are better for games), you win in “generality” (ability to use this outside games to, for example, improve web browsing battery life).
- mrec 5y agoThere's a very hard distinction between GPU texture compression formats and general image compression formats - the former need to support random access lookup in constant time. Anything meeting that criterion is not going to be generally competitive; it's like the difference between UTF-32 strings and UTF-8 strings.
- david-gpu 5y agoYou could do the YUV to RGB conversion operation in your pixel shaders in the GPU. That way you save a bit of bandwidth compared to uncompressed RGB. It's been done. There are even GPUs that support this operation natively, so there's no additional overhead.
- mindfulplay 5y agoI would imagine a shader that converts YUV to ARGB at the time of rendering as opposed to storing it all the way along the pipeline as 32 bit integers. It's a bit tricky because rendering pipelines composite the final image through many layers of offscreen compositing before the pixel hits the screen. The core issue is that the offscreen composited layers would still be 32bit textures which is a bigger issue. I would imagine a Skia-based draw list to encode this through the pipeline which could help preserve this perhaps.
- PragmaticPulp 5y ago> What does he mean by using native YUV formats? Your display uses 3 bytes per pixel. 8 bits for each of the R, G, and B channels. This is known as RGB888. (Ignoring the A or alpha transparency channel for now). YUV420 uses chroma subsampling, which means the color information is stored at a lower resolution than the brightness information. Groups of 4 pixels will have the same color, but each pixel can have a different brightness. Our eyes are more sensitive to brightness changes than color changes, so this is usually unnoticeable. This is very advantageous for compression because YUV420 requires 6 bytes per 4 pixels, or 1.5 bytes per pixel, because groups of pixels share a single color value. That's half as many bytes as RGB888. When you decompress a JPEG, you first get a YUV420 output. Converting from YUV420 to RGB888 doesn't add any information, but it doubles the number of bits used to represent the image because it stores the color value for every individual pixel instead of groups of pixels. This is easier to manipulate in software, but it takes twice as much memory to store and twice as much bandwidth to move around relative to YUV420. The idea is that if your application can work with YUV420 through the render pipeline and then let a GPU shader do the final conversion to RGB888 within the GPU, you cut your memory and bandwidth requirements in half at the expense of additional code complexity. Wikipedia is a good source of diagrams and details that explain this further: https://en.wikipedia.org/wiki/YUV#Y%E2%80%B2UV420p_(and_Y%E2%80%B2V12_or_YV12)_to_RGB888_conversion https://en.wikipedia.org/wiki/YUV#Y%E2%80%B2UV420p_(and_Y%E2...
- Jare 5y agoIn Commandos 2 we stored the huge map images in YCbCr 420 in memory, and converted to RGB during rendering via lookup tables rather than shaders (this was back in 1999, all CPU!). We compressed the range of each component below 8 bits, running a histogram so our bits represented values inside the range actually present in the original image. We got it down to 6 bits per pixel or something close to that. Converting via lookup tables, one for each component, made it very cheap to perform palette-style tricks like tonemapping and smooth color shifts from day to night. [Edit: it may have actually been CIE Lab, not YUV/YCbCr, because the a&b tended to have narrower ranges. It's been too long!]
- rgoulter 5y ago
- TazeTSchnitzel 5y ago> You can do [direct use of YUV] today, but you need to do the color conversion manually in a shader Many mobile GPUs support an extension that does YUV conversion for you (GL_EXT_YUV_target). Maybe it's of less interest to desktop GPU vendors?
- jayd16 5y agoI think the problem is moving the dev flow from layered bitmaps to a shaded flow.
- hatsunearu 5y agoMaybe I'm too stupid to understand this but AFAIK YUV isn't exactly linear so you still need to convert to linear space (trichromatic linear color space like RGB/XYZ)... no?
- david-gpu 5y agoYUV is a linear transformation of RGB to the best of my knowledge. Wikipedia seems to agree.
- jacobolus 5y agoJPEG uses Y'CbCr, not YUV per se. The matrix transformation is applied to gamma-encoded R'G'B' (typically sRGB), not linear RGB. http://poynton.ca/PDFs/YUV_and_luminance_harmful.pdf http://poynton.ca/PDFs/YUV_and_luminance_harmful.pdf
- brigade 5y agoThe only important bit of pedantry over analog/digital and prime is reminding people that no one deals with linear light unless you already know you're doing so, and that blending in nonlinear space is rarely correct, no matter how common it is to do so.
- david-gpu 5y agoI think we are in agreement? What you are saying is that conversion from linear YUV to linear RGB is, indeed, linear. Further, the transformation from Y'CrCb to gamma-encoded R'G'B' is also a linear operation. Right?
- jacobolus 5y agoIt depends what you want to do with the data. If you want to send your sRGB-profile Y'CbCr JPEG image directly to an sRGB display then you are done after applying a matrix. If you want to composite multiple images, do other intermediate processing, or display the image on an arbitrary non-sRGB display, you probably want to convert to a linear space along the way.
- kragen 5y agoThe XVideo extension, commonly used by MPlayer (at least in the past, maybe still?), has supported sending YUV images to your video card for 20½ years, since XFree86 4.0.2: https://www.cs.ait.ac.th/~on/mplayer/en/xv.html https://www.cs.ait.ac.th/~on/mplayer/en/xv.html There are various problems in XVideo that make it hard to use for general application display, but the fact that this was a thing they included in it makes me think that a substantial number of video cards have included YUV decoding capability in hardware since the previous millennium.
- dirkt 5y ago> makes me think that a substantial number of video cards have included YUV decoding capability in hardware since the previous millennium. You are correct, and you can find details on that by reading the card documentation (as far as it is available). That was in particular the case when cards had a fixed-function rendering pipeline. With the advent of more general purpose cores on the GPU for the rendering pipeline, YUV decoding has been offloaded to them.
- amelius 5y agoDoes Wayland support this?
- brigade 5y agoOverlay support tends to be very limited - it's effectively blitting to the final framebuffer after compositing, which means no transparency and a limited number of surfaces. The desire is for the compositor or any other shaders to be able to read YCbCr surfaces natively, converting to RGB as a part of the sample. Namely, VK_KHR_sampler_ycbcr_conversion. I'm actually not sure if other APIs provide the equivalent yet, the HW capability is pretty recent...
- grishka 5y agoAndroid has had ColorMatrixColorFilter[1] since the beginning and YUV -> RGB conversion is actually an example use case they specify. Problem is, however, that many YUV formats do chroma subsampling, and you can't exactly put that into a regular bitmap without shuffling a lot of bytes around, which kinda defeats the purpose. [1] https://developer.android.com/reference/android/graphics/ColorMatrixColorFilter https://developer.android.com/reference/android/graphics/Col...
- onurcel 5y agoI thought he was working on AGI
- xnx 5y agoI think a lot of the input data to his models are images.
- TheDudeMan 5y agoThat's only some of the threads.
- sillysaurusx 5y agoNot only is he working on AGI, but he has some of the most interesting and unique ideas about how to achieve it. Everyone is currently approaching AGI in what you might call a traditional way. Carmack's way is completely different, which was refreshing. I think Carmack's technique has the highest chance of reaching AGI. The tweet chain isn't as unrelated as it seems.
- truckerbill 5y agoDo you have a link outlining the details of his approach?
- sillysaurusx 5y agoIt was in DMs, so I don't feel comfortable presenting the idea publicly. He'll talk about it when he's ready. You could try asking him. He likes talking about this, especially if you phrase your questions well.
- cornstalks 5y agoOne of the challenges with Y'CbCr (what Carmack is calling "YUV") is that there are so many flavors. He mentions 4:2:0 chroma subsampling. But he doesn't mention chroma siting. Or alternative sumbsampling schemes. Or matrix coefficients. Or full-range vs video-range (a.k.a. JPEG vs MPEG range). Heck, how you even arrange subsampled data varies by system (many libraries like planar; Apple likes bi-planar; etc.). I'd love to see more support for rendering subsampled Y'CbCr formats so you don't have to use so much RAM, but it gets complicated quick.
- jayd16 5y agoIs this a real problem? Surely something in the current pipeline understands what YUV flavor JPEG uses.
- berkut 5y agoJPEG can use multiple: you can select the chroma-subsampling (with comp_info[0].h_samp_factor), and do 420, 422 or 444...
- jayd16 5y agoAnd the pipeline is able to convert it to RGB fine, so isn't the information available to use? Why would it be a challenge passing along that information?
- cornstalks 5y agoThe information is there (sometimes... it's amazing how many times you have to make a "reasonable" guess when decoding images/video because metadata is missing). Passing it along is feasible. But it does complicate things (especially the implementation) pretty quickly. A lot of Y'CbCr -> RGB converters actually disagree with each other. They're all close enough that casual users don't notice or care about the small discrepancies.
- 5y ago
- modeless 5y agoThis would save memory but add compute cost if the image is drawn to the framebuffer or another sRGB buffer more than once or twice. It wouldn't necessarily be a win to make this behavior the default everywhere. In the case of web browsers it depends how the image is used. An <img> with a large JPEG is probably drawn only once during tile rasterization, and browsers could certainly use the memory savings, so it would probably be a win. But if you had a small JPEG used as a page background and tiled over the whole screen, the memory savings would be small and you'd be wasting power converting the same pixels from YUV to sRGB over and over, so that would likely be a loss.
- NL807 5y agoIn some cases compute trade-off is still cheaper than memory latency.
- raphlinus 5y agoThat is not necessarily true. In some cases, the compositor maybe configured to sample the input buffer directly from YUV420, applying the transformation on scanout and thereby saving memory bandwidth to read from the framebuffer. This makes a tremendous amount of sense when the source is a video, but much less sense when the source may be rendered vector graphics, which generally look pretty bad with subsampled chroma.
- modeless 5y agoSure, if you can use a YUV framebuffer then that can save memory bandwidth during scanout (though the conversion to RGB still happens because the screen is not YUV). But that doesn't apply in the tiled page background case I mentioned, as web page contents are composited in RGB.
- lilyball 5y agoI am fascinated by his use of backslash-escaping the tweet EOD to signify that it's being followed by another one.
- supernintendo 5y agoI suppose it takes less characters than marking the ordinal of the tweet and probably familiar to Carmack's technically-minded audience as escaping the return character in a command line (to add a new line to the command instead of running it).
- saagarjha 5y agoIt is also how you continue a line in a preprocessor macro.
- Animats 5y agoThere's JPEG 2000, which is nothing like classic JPEG. It doesn't have the artifacts classic JPEG introduces at sharp edges, so you can read text. It has more color depth if you want it. It also doesn't mess up non-color data such as normal maps the way classic JPEG does. JPEG 2000 is not used much. Decoding is slow, and encoding is slower. The decoders are either buggy or proprietary. It has way too many options internally. The big users of JPEG 2000 are medical. It has a "lossless" mode, and medical imagery is usually stored lossless because you really don't want compression artifacts in X-rays. (I've been struggling with JPEG 2000 recently. Second Life and Open Simulator use it for asset storage. Some images won't decompress properly with OpenJPEG, a free decoder. I finally found out why. There's a field used for "personal health information" in JPEG 2000. This is where the patient name and such go in a CAT scan. That feature was added after the original version. Some older images apparently have junk in that field, which causes problems.)
- PostThisTooFast 5y agoFun note: Red Camera ripped off JPEG2000 and of course got a patent on it through the USA's derelict patent office. Now they're extorting any company that wants to do compressed raw recording.
- user-the-name 5y agoJPEG 2000 is ancient. It is nearly as old as JPEG itself, it long since missed it's change to become relevant. Today it is a legacy format and should be mostly ignored. It has its own types of artefacts, which in some cases are even worse for image quality than those of JPEG. JPEG has introduced multiple new formats since JPEG 2000, all of which are better, such as JPEG XR and JPEG XL.
- j16sdiz 5y agoJPEG was designed in 1992 JPEG2000 was designed 1997-2000
- moron4hire 5y agoThe year right now is 2021. So yes, JPEG 2000 is almost as old as JPEG.
- Dylan16807 5y agoDoes anyone know what fraction of jpegs in the real world are 4:2:0? For photos I use whatever the camera likes, but for everything else I use 4:4:4.
- NL807 5y ago> Does anyone know what fraction of jpegs in the real world are 4:2:0? Most of them. Pretty much the default subsampling for libjpeg(-turbo).
- npteljes 5y agoI sampled my jpegs randomly. My image downloads seem to be all 420, and the photos 422.
- colonwqbang 5y agoIt's good to remember that image sensor pixels only have one colour anyway (they are each either G, R or B). 67% of colour information is made up right from the start before your even encode anything. Another reason why 4:2:0 sampling may not be as bad as it sounds.
- Dylan16807 5y agoFor cameras outputting at their max megapixel rating, yes. If you're outputting at a lower resolution or not using a camera then it can be a notable loss of quality. Most web images are probably scaled down, and in other contexts I bet it's similar. If you're looking at a raw camera shot you're usually only dealing with one at a time, so while simplicity is nice the RAM impact of those will be limited.
- colonwqbang 5y agoIf you're looking to save on storage/bandwidth (hence not using the max resolution of your camera) it can absolutely be a good idea to spend more bits on Y than on C.
- berkut 5y ago
- yboris 5y agoThe future of images is JPEG XL - https://jpeg.org/jpegxl/ https://jpeg.org/jpegxl/ A great overview and explanation: https://cloudinary.com/blog/time_for_next_gen_codecs_to_dethrone_jpeg https://cloudinary.com/blog/time_for_next_gen_codecs_to_deth...
- afiori 5y agocompared to JPEG2000 it feels like it is actually trying to offer an upgrade path
- GuB-42 5y agoI don't know, JPEG has the "problem" of being good enough for what it is used for. We could do better for decades but because everyone understands JPEG it is still the standard. And if JPEG doesn't fit, chances are that PNG does. There are alternatives. Google optionally uses webp, because it saves them bandwidth and they control the entire chain. And specialized applications like maps sometimes use better suited formats, but if you want to share a picture, that's JPEG. The same thing happens with audio. The go to format is still MP3 even though it is well outdated. In fact, we had what is close to the perfect lossy audio codec (Opus) since 2012 and support it is pretty much only used when you control the entire chain, like in video games. So maybe JPEG XL is the perfect image format, but it is still a tough sell when you have something universal that is good enough against it. The only way I can see it gain traction is if tech giants get together and force it on us. Like they have been doing for web standards. And if there are patents, even that may not work. Video is different because it uses a huge amount of bandwidth and no formats are "good enough" yet.
- MrRadar 5y agoJPEG XL's party trick is that you can losslessly (and reversibly) transcode regular JPEG images to XL images, at less CPU cost than fully decoding and then encoding, for a size savings of ~30%. I think this will be enough to put it over the top and drive adoption as CDNs will be able to transparently serve either JPEG or XL for a resource originally uploaded as a standard JPEG depending on whether the requesting user agent supports XL.
- 5y ago
- pornel 5y agoIIRC this optimization has already been used by Opera Mobile and Edge in the past: upload YUV to the GPU RAM, and then convert pixels to RGB on the fly when displaying. Unfortunately, I can't find the links to their respective blog posts (<shakes fist at Google substituting all keywrods with their synonyms and searching recent pages only>). However, chroma subsampling is a very primitive form of 2x2 block compression (NB: not related to JPEG's DCT block size). These days GPUs support much better compression natively, with 4x4 blocks, and much fancier modes (ETC1, ASTC). With clever encoding of such textures, it's even possible to achieve compression ratio comparable with JPEG's, while having a straightforward way to convert the compressed file to the compressed texture format.
- pornel 5y agoThat's the one: https://jatindersmann.com/2013/09/12/using-hardware-to-decode-and-load-jpg-images-up-to-45-faster-in-internet-explorer-11/ https://jatindersmann.com/2013/09/12/using-hardware-to-decod... and it was in IE11 even!
- arp242 5y ago> shakes fist at Google substituting all keywrods with their synonyms and searching recent pages only You can set a time range in Google; "Tools" link under the search bar. DuckDuckGo has this as well. Super useful, especially if there's some recent/prominent news and you want to find things other than this news, or if you're looking specifically for older stuff. I think you can use "word" (with quotes) to prevent the synonym thing; not entirely sure about that.
- SquareWheel 5y agoI use the Tools > Time Range feature constantly. It's extremely useful. I don't know if quotes prevent synonyms, but verbatim mode should.
- ehsankia 5y agoJust searched `opera browser "jpg" "yuv"`, no date filtering. Second result is: https://timkadlec.com/remembers/2018-03-22-compressive-images-revisited/ https://timkadlec.com/remembers/2018-03-22-compressive-image... Seems to be it?
- 0xbadcafebee 5y agoTwitter is a bad blogging platform.
- danwills 5y agoI gave up after the first section after mashing some bits of the 'UI' to try to read the next bit.. simply posting a link could provide a far better reading experience imo.
- lnanek2 5y ago> The vast majority of images are jpegs, which are internally 420 YUV, but they get converted to 32 bit RGB for use in apps. Using native YUV formats would save ... > You can do it today, but you need to do the color conversion manually in a shader, which can be a big ask for some devs Where the perf. really matters, and shaders are involved, doesn't everyone use texture compression formats like ETC1 and PVRTC? https://developer.android.com/guide/playcore/asset-delivery/texture-compression https://developer.android.com/guide/playcore/asset-delivery/...
- cornstalks 5y agoETC1/PVRTC are lossy. If your source material is 4:2:0 then it's best to just stay with it. If you convert to RGB and then compress you don't really gain anything except a slight reduction in quality.
- vardump 5y ago> and shaders are involved, doesn't everyone use texture compression formats like ETC1 and PVRTC? Yes, when they can pay the computational price for compression beforehand. Not going to work, if you had to compress in realtime.
- corysama 5y agoThey are used widely in games. But, not so much elsewhere. Non-game-app designers get upset by the artifacts. I've shipped games using them for UI. We were hapy to tolerate the artifacts in exchange for the 8X memory usage & memory bandwidth reduction (RGBA8888 vs. PVTRC4). However, I've heard that Netflix was one of the first sponsors of https://github.com/BinomialLLC/basis_universal https://github.com/BinomialLLC/basis_universal They are shipping innumerable images to a huge variety of underpowered set top boxes. Totally worth investing in a giant-leap memory optimization.
- thesz 5y agoThe vast majority of time F-15 flies at subsonic speed. Converting it to propeller-driven design will save a lot of fuel and production and maintenance costs. YUV format is lossy. The one that is twice as bandwidth-efficient as RGB records four times less color difference than full bandwidth YUV or RGB. Add to that that RGB often used with alpha channel and for half the bandwidth you will get twice the artifacts. The subsampling scheme that is half of RGB is called 4:1:1: https://en.wikipedia.org/wiki/Chroma_subsampling#4:1:1 https://en.wikipedia.org/wiki/Chroma_subsampling#4:1:1 It is not broadcast quality. 4:2:0 is also not good for today's standards.
- cornstalks 5y agoMathematically Y'CbCr is a lossless conversion of RGB. Practically there are some losses, though, especially if you use video-range. 4:1:1 is half of RGB but I've never seen anyone ever use it. Pretty much everything in use today (at the consumer level) uses 4:2:0. It's good enough for today's standards (AV1 Main profile only supports 4:0:0 and 4:2:0).
- layoutIfNeeded 5y ago>Mathematically Y'CbCr is a lossless conversion of RGB. Assuming infinite precision, sure. Interestingly however, there's a closely related color space called YCoCg, that actually does achieve lossless coversion to/from RGB (this lossless variant is often referred to as YCoCg-R, the R stands for "reversible"): https://en.wikipedia.org/wiki/YCoCg#The_lifting-based_YCoCg-R_variation https://en.wikipedia.org/wiki/YCoCg#The_lifting-based_YCoCg-...
- cvwright 5y agoWhat’s 4:1:1? What people call 4:2:0 is actually 4 pixels of Y and 1 each of Cb and Cr.
- cornstalks 5y agoWikipedia has a decent article with visuals: https://en.wikipedia.org/wiki/Chroma_subsampling#Sampling_systems_and_ratios https://en.wikipedia.org/wiki/Chroma_subsampling#Sampling_sy... The difference between 4:1:1 and 4:2:0 is that in 4:1:1 the chroma covers a 1x4 line of pixels whereas in 4:2:0 the chroma covers a 2x2 square of pixels.
- rahimiali 5y agoIf the goal is to save memory, you can go farther than this. You could store the JPEG in RAM, compressed, and have the GPU decompress & shade. Each of the DCT blocks can be converted massively parallely on GPU.
- astrange 5y agoYou can't do image decompression in GPGPU because the last step (Huffman coding) is not parallelizable - in fact if any compression is parallelizable it's not compressed enough. But you can do it in dedicated hardware.
- rahimiali 5y agoOk, maybe not the arithmetic code (or huffman), but I was thinking you'd at least invert the DCT on GPU.
- throw7 5y agoPlease stop using twitter John. It's the 21st century and brilliant minds are posting thoughts in broken unreadable parts on websites that completely don't work unless you're a religious "the modern web requires javascript REEEEEEE" zealot.
- jasonmp85 5y ago(a) Unless I'm mistaken, there are three tweets. Three. (b) Can you use curl? Maybe hit the API. (c) The modern web DOES require JavaScript. Sure, I'm not clear on what that has to do with reading three tweets available on a public API, but it's pretty weird to object to a declarative statement of truth.
- boomka 5y agogiven that the article is about inefficient use of content delivery technology, it is poetically ironic to try (and kinda fail) to post said article on a website that doesn't allow the article to be fully posted
- danwills 5y agoHere here! This format stands right in the way of simply reading.
- maria27368 5y agoOrchid mantis Fun Facts These flowers can walk like animals https://www.interestingnews.club/2021/06/orchid-mantis-fun-facts.html https://www.interestingnews.club/2021/06/orchid-mantis-fun-f... Secret plan for weight loss Step by step guide http://healthwithbeauty.xyz/2021/06/02/six-week-makeover-diet-plan/ http://healthwithbeauty.xyz/2021/06/02/six-week-makeover-die... Wheel whackers' keep snakes out of planes in California desert https://www.interestingnews.club/2021/06/wheel-whackers-keep-snakes-out-of.html https://www.interestingnews.club/2021/06/wheel-whackers-keep... Earn money using Pinterest Trusted method with detail https://blogtips2022.blogspot.com/2021/05/how-to-earn-money-from-pinterest-in.html https://blogtips2022.blogspot.com/2021/05/how-to-earn-money-... 34% discount on 2020 Ultrasonic Mini Air Humidifier https://topsaleproductsonline.blogspot.com/2021/04/34-discount-on-2020-ultrasonic-mini-air.html https://topsaleproductsonline.blogspot.com/2021/04/34-discou...
- thordenmark 5y agomeh. PNG's are the way to go. All the advantages, none of the draw backs. And it has Alpha.
- gmueckl 5y agoCrysis 3 used YUV 4:2:2 in its G Buffer. I think only the final tonemapped LDR image was converted to RGB. It was a peculiar optimization that I haven't seen anywhere else again.