Live data from Hacker News

Building a New Image Format

richardwalshlabs.blogspot.co.uk

21–30 of 31 posts

Re: Building a New Image Format

#21
I have three major problems with WebP. Well, I have one major problem: it's a video format, not an image format, and that leads to three major consequences.

First off, the concept of using the intra-frame compressor of a video format to compress images is unsound. Video compression has constraints that don't apply in still-image compression, and you are dragging that baggage around for no reason. These constraints lead to my other two issues.

One of the biggest problems with JPEG is that block artifacts are often visible even at relatively high quality settings. Post-decoding deblocking algorithms have proven utterly inadequate for fixing this.

One simple and effective leap in mitigating block artifacts is to use larger block sizes. Modern computers are obscenely fast compared to when JPEG was introduced, and we could bump the block size up from 8x8 to 16x16 or even 32x32 without breaking a sweat. This reduces the number of pixels that are at block boundaries, and that means less block artifacts. WebP uses smaller blocks because it's a video format, not an image format.

Another way that you can avoid edge artifacts is to overlap the blocks so that the edge artifacts don't create discontinuities. This is called "time-domain alias cancellation" and it's used in the 1D case by every lossy audio codec you've ever used. It generalizes easily to the 2D case, and it would generalize easily to the 3D case, but for reasons that I don't understand because video compression is not really my field, nobody does video compression by taking the DCT of 3D blocks of video. Instead they use a more ad hoc method of motion compensation, which consists of brute force searching for where blocks in one frame have moved in the next frame. It's not clear how you'd reconcile that with overlapping blocks in the interframe compressor, so VP8 doesn't use overlapping blocks. And by extension, neither does WebM.

Beating JPEG with a new video format is not all that difficult. We have two decades of research between JPEG's introduction and today, and each of us routinely carries hardware in our pocket that would have been considered a major military asset in 1992. It isn't at all surprising that the key frame compressor of a modern video codec would beat JPEG by 25%, but we can do so much better than that. Once we manage to displace JPEG, we're going to be stuck with whatever displaces it for a long time. So we need to make sure we have the best format we can muster before we make that commitment.

Re: Building a New Image Format

#22

This makes very little sense. The article suggests that you bundle many sizes of the same image into the same file; say, a 1024x1024 version as well as a 512x512 version. This means that a browser that only wants the 512x image will also download the 1024x image whether it wants to or not. So why not just pick the 1024x image and resize it on the client size, if everyone is going to download it? This is something tha…

Maybe it could be in a stream [headers][512px data][1024px data] and you could stop after the [512px data]. And since 512px image is a subset of 1024px one, you could do [headers][512px data][1024px\512px data] and so on.

(Just a guess.)

Re: Building a New Image Format

#23

This makes very little sense. The article suggests that you bundle many sizes of the same image into the same file; say, a 1024x1024 version as well as a 512x512 version. This means that a browser that only wants the 512x image will also download the 1024x image whether it wants to or not. So why not just pick the 1024x image and resize it on the client size, if everyone is going to download it? This is something tha…

>At 2x resolutions you can even skip interpolation and just go for nearest-neighbour scaling.

I'm not sure what your reasoning is there, but it's incorrect. Nearest-neighbor looks really bad even when scaling down to half size.

Re: Building a New Image Format

#24

This makes very little sense. The article suggests that you bundle many sizes of the same image into the same file; say, a 1024x1024 version as well as a 512x512 version. This means that a browser that only wants the 512x image will also download the 1024x image whether it wants to or not. So why not just pick the 1024x image and resize it on the client size, if everyone is going to download it? This is something tha…

>At 2x resolutions you can even skip interpolation and just go for nearest-neighbour scaling. I'm not sure what your reasoning is there, but it's incorrect. Nearest-neighbor looks really bad even when scaling down to half size.

Depends very much on the size. The resulting edginess becomes much more pronounced the fewer pixels you have. I'm just pointing out that in some cases you can conserve CPU usage by cheating. You could render a shoddy version first just to get the page up, for example, and then replace it with a high-quality version; some browsers already do this today.

Re: Building a New Image Format

#25
post #22

This makes very little sense. The article suggests that you bundle many sizes of the same image into the same file; say, a 1024x1024 version as well as a 512x512 version. This means that a browser that only wants the 512x image will also download the 1024x image whether it wants to or not. So why not just pick the 1024x image and resize it on the client size, if everyone is going to download it? This is something tha…

Maybe it could be in a stream [headers][512px data][1024px data] and you could stop after the [512px data]. And since 512px image is a subset of 1024px one, you could do [headers][512px data][1024px\512px data] and so on. (Just a guess.)

Unfortunately, because of buffering I believe this would still be inefficient. Also, it would screw up HTTP keepalive. A better way would be for the browser to fetch the header first by using the HTTP "Range" header, and then fetch the subrange it needs, but that adds one roundtrip just to get an image.

Re: Building a New Image Format

#26
post #22

This makes very little sense. The article suggests that you bundle many sizes of the same image into the same file; say, a 1024x1024 version as well as a 512x512 version. This means that a browser that only wants the 512x image will also download the 1024x image whether it wants to or not. So why not just pick the 1024x image and resize it on the client size, if everyone is going to download it? This is something tha…

Maybe it could be in a stream [headers][512px data][1024px data] and you could stop after the [512px data]. And since 512px image is a subset of 1024px one, you could do [headers][512px data][1024px\512px data] and so on. (Just a guess.)

You've basically just described interlacing. For instance, interlaced PNGs start with a 1/8 scale pass/frame and fill in the remaining pixels with the following 6. (Frames 1-5 would be required for a 1/2 scale image.)

Re: Building a New Image Format

#27
What's needed is a downloadable JavaScript renderer which parses the webp file format and draws the resulting image in an HTML5 Canvas.

Then we don't have to wait for browser makers to implement it in their browsers. You just add a one-line script tag to load webp.js, a script that scans your DOM for img tags with a src that ends with ".webp", and your website has webp support.

If browsers later support webp natively, you can just add a check to webp.js so it turns itself off when a webp-supporting browser is detected.

It's really too bad that Java in the browser never took off; its performance characteristics are far better for writing image decompressors than JS. But JS with a modern HTML5 Canvas running in a modern JS engine on a modern CPU is good enough for the purpose.

Re: Building a New Image Format

#28

Earlier quoted context omitted.

I'm enthusiastic about animation support. It's mind-boggling that we are still using an image format from 80s with crappy compression and limitation to 256 colors.

What's the benefit of a photo-compression with animation support, compared to actual movie formats (H.264)?

Can be used in places that only support images. Can be used in places that don't want audio. Variable frame rate. Auto play enabled by default. Designed to loop continuously.

Have you seen how people use gif animations?

Re: Building a New Image Format

#29
post #14

Earlier quoted context omitted.

I'm enthusiastic about animation support. It's mind-boggling that we are still using an image format from 80s with crappy compression and limitation to 256 colors.

What about the tag? I guess it's nice that WebP support animation as well, but that's what the video tag exists for. Shoe-horning in frame-by-frame animation in an image format when you can just use video (or the canvas, if you want to do something key frame based) seems like a bad idea to me. The only thing I can think of off the top of my head where it's preferable is if you needed to do a video with an alpha chann…

Have you seen how people use gif animations? Video is completely different format than animated images in today's internet. If video formats were preferable, things would have already changed.

Animated images have several advantages:

-Almost all places that support images support also animated image

-Can be downloaded and reposted (as opposed to canvas)

-No worry about audio, there is no audio

-Seamless looping

-Auto play everywhere

-Variable frame rate

These features could be achieved in a video format, but how would you convince websites that support images to support video with these characteristics?

For example, I would never let people upload autoplaying, looping videos as their avatars or as part of their comment unless I could be 100% sure that there will be no audio. I would have to inspect the video for audio and I would need different handling for images and videos.

Re: Building a New Image Format

#30
WebP only seems to support 8-bit integer component values, which makes seems pretty backward for a new format.

Higher-bit depths and floating-point components (ala OpenEXR) seem an important feature for any image format that hopes to become a future standard. 8 bits were maybe sufficient in 1990; not so much today. Even microsoft eventually got that clue with JPEG XR...

You only get so many chances to define a new standard, so going with something as lackluster as WebP would seem to be a mistake. JPEG XR, despite its MS origins, seems to be vastly superior. [JPEG XR has licensing issues with the reference implementation (it's from MS after all), but that's not a fatal flaw...]

Post reply on HN