News for hackers. Stuff that matters.
Re:Free Lossless Image Format by iraphael on Friday October 02, 2015 @09:00AM (#10318166)
This is really interesting. One of the most interesting parts is the progressive decoding/responsive images. http://flif.info/example.php (go to the bottom of the page).

Basically, the last example shows that, if you want a scaled version of the image, you can simply stop decompressing. No need for multiple image files. Just create one with very high quality and decompress until you get the quality you want and scale it down with html.

edit: more info on the responsive side of FLIF: http://flif.info/responsive.php

Re:Free Lossless Image Format by hngiszmo on Friday October 02, 2015 @11:10AM (#10319022)
Also no more .thumbnails folders

I imagine images appearing as fast as I can scroll, with enough visual clue to them to find images way way more quickly than with thumbnails today. As a start, thumbnails could use flif.

Re:Free Lossless Image Format by panzi on Friday October 02, 2015 @11:26AM (#10319127)
I think some formats already support embedded thumbnails. (EXIF metadata can contain thumbnails, I believe)
Re:Free Lossless Image Format by jo909 on Friday October 02, 2015 @11:47AM (#10319270)
But that is not the same. That is a small, but fixed size, second version of the image, embedded into the same file.

With FLIF you simply read the first N bytes of the full image and have a resonable preview. You choose how big or small N has to be, depending on the size of the thumbnail you want to show. Maybe first read N bytes for each image to get a quick but rough preview, then repeatedly read a few bytes more to enhance the thumbnail.

Re:Free Lossless Image Format by magicalist on Friday October 02, 2015 @03:52PM (#10320876)
To be fair, that's not the same thing either. A thumbnail is resampled in a way to resemble the original at a smaller size. This will be resampled with (more or less) nearest neighbor, which means lots of aliasing and possibly looking nothing like the original, depending on the subject.
Re:Free Lossless Image Format by jonsneyers on Friday October 02, 2015 @06:00PM (#10321608)
That's true. I tried a variant where the resampling would be better, but while it is possible, it hurts the compression rate significantly. At the level of a single step: if you have two pixels A and B that are both 8-bit numbers, then if you want some lossless way to store both (A+B)/2 (an 8-bit number) and enough information to restore both A and B, it will take at least one extra bit (9 bits, e.g. to store B and the least significant bit of A+B). So a 24-bit RGB image would become a 27-bit images when interlaced with better resampling (except for the very first pixel, which would need only 24 bits).

In practice, the simplistic resampling is not likely to be an issue -- of course you can create a malicious image which is white on the even rows and black on the odd rows, and then all previews would be black while they should be grey. But most of the actual images are not like that -- e.g. photographs. You can just decode at somewhat higher resolution and scale down from that. (You have to start from a power-of-two scaled image anyway.) Also note that Y is emitted at more detail earlier than chroma, so most of the error will be in those less important chroma channels. Other than that it's just Adam7 interlacing, but with no upper bound on the number of passes (so you could call it Adam-infinity interlacing).

Re:Free Lossless Image Format by DiThi on Friday October 02, 2015 @05:16PM (#10321388)
I haven't checked, but I suspect that a better down scaling method can be used while still being compatible with the same decoding algorithm.
Re:Free Lossless Image Format by magicalist on Friday October 02, 2015 @05:40PM (#10321518)
hmm, how could it be? The pixels values have to fit into the eventual reconstructed image. If the values were different than any pixels found in the final image, it wouldn't be progressively loading, it would have several different size images embedded in it.
Re:Free Lossless Image Format by DiThi on Friday October 02, 2015 @06:40PM (#10321755)
(edited) After reading the author's comment above mine, you're very probably right.
Re:Free Lossless Image Format by ke7ofi on Friday October 02, 2015 @04:15PM (#10321008)
Part of the beauty of FLIF is that there are no dedicated thumbnails, though.
Re:Free Lossless Image Format by hngiszmo on Friday October 02, 2015 @11:51PM (#10322516)
As long as you don't directly work with FLIF, cause tools don't support it, having the file browser's preview-feature work using FLIF would be awesome. This way it doesn't need to store n previews for the supported preview resolutions but could store just a flif of the max preview size per document (psd, jpg, png, svg, pdf) and then, when you seek 3 pages down, the system reads the first kB of each such preview to render it and reads the next kB to improve the images, etc.

Sure, for actual flif files you would not have a separate preview file.

Re:Free Lossless Image Format by rplnt on Friday October 02, 2015 @10:02AM (#10318562)
This would be great. A lot of "responsive" sites nowadays use only one image as well, the highest resolution available. So you are downloading that 4K jpeg whether you are on mobile or on a desktop.
Re:Free Lossless Image Format by acdha on Friday October 02, 2015 @12:23PM (#10319480)
Your example also shows why it needs to be left up to the browser: downloading a large JPEG makes more sense on an iPhone 6S+ with a 1080p display and LTE than the 1024x768 computers at the local school sharing a basic cable modem.

The part which would really make sense for this would be something like an extension to <picture> or <img srcset> which would allow you to provide the byte ranges for each resolution so the client could issue a standard HTTP range request for the level of pixels it actually needs. You'd still have one file to manage and CDNs could cache it intelligently rather than lowering hit rates by caching different versions.

Re:Free Lossless Image Format by zyxley on Friday October 02, 2015 @06:02PM (#10321623)
I wonder if it would be feasible to have browser functionality that starts the download, then stops it once it has enough data to make an image the width of the element on the page. (Maybe then continuing the download later if it's resized larger?)
Re:Free Lossless Image Format by acdha on Friday October 02, 2015 @06:04PM (#10321628)
You could certainly build that in as a heuristic similar to how many browsers implement <video>: issue Range requests for a certain chunk size and stop once you have enough data. It's not as efficient as being able to get it all in one go but if you have a progressive image format that might be a better experience if it can start rendering quickly and fill details later.
Re:Free Lossless Image Format by colanderman on Friday October 02, 2015 @10:24AM (#10318724)
Progressive JPEG has supported this for decades. Anyone over 25 should remember them from dial-up years.
Re:Free Lossless Image Format by hansjorg on Friday October 02, 2015 @10:58AM (#10318948)
I think the suggestion is that the client could just stop downloading at a set threshold, maybe taking current bandwidth, cost, etc. into consideration.

Judging from the video, something like that could work very well (and much better than with progressive jpegs).

Re:Free Lossless Image Format by guelo on Friday October 02, 2015 @01:28PM (#10319933)
It's an interesting concept. But I'm not sure how it could work. Resizing introduces artifacts so best quality is always going to be achieved by reencoding for different resolutions. Also, how would the client know when to stop downloading?
Re:Free Lossless Image Format by iopq on Friday October 02, 2015 @02:30PM (#10320358)
The client would download the first 1KB for an icon, 4K for a thumbnail and the whole image for the full size. The best part is that all of those are actually the same file, not separate embedded thumbnails inside the file.

The client could decide BY ITSELF to download only 2K for a thumbnail because it's currently on 3g.

Re:Free Lossless Image Format by guelo on Friday October 02, 2015 @02:49PM (#10320461)
Where are you getting 1KB and 4KB from? The compression is highly dependent on the image so there's no way to know the quality of the thumbnail image.
Re:Free Lossless Image Format by iopq on Friday October 02, 2015 @04:03PM (#10320941)
Maybe a future version of the format would specify useful cut-off points for browsers to make the decision inside the header. Then the browser can decide to download 4K version on wifi and 1K version on 3g.
Re:Free Lossless Image Format by hansjorg on Friday October 02, 2015 @02:39PM (#10320412)
You'd need to set the thresholds in the file manually, based on the artists judgement of quality.

It would take a few extra seconds when creating it, but could save both bandwidth and create a better user experience on mobile.

Re:Free Lossless Image Format by magicalist on Friday October 02, 2015 @03:56PM (#10320896)
This will have to be automated or it's going to be really annoying for development. To eliminate that, maybe the file format could incorporate some internal tags for good size thresholds, or even just a handful of coefficients at the beginning for a simple curve approximating the byte-to-resolution mapping.
Re:Free Lossless Image Format by radarsat1 on Friday October 02, 2015 @03:27PM (#10320687)
But how is that different from progressive JPEG?
Re:Free Lossless Image Format by kevin_thibedeau on Friday October 02, 2015 @07:06PM (#10321858)
And then there was magic of watching interlaced GIFs download before the era of JREG.
Re:Free Lossless Image Format by jessaustin on Friday October 02, 2015 @11:47AM (#10319265)
However jpeg is lossy.
Re:Free Lossless Image Format by colanderman on Friday October 02, 2015 @12:03PM (#10319368)
So is a FLIF that you only download half of.
Re:Free Lossless Image Format by mthoms on Friday October 02, 2015 @12:14PM (#10319423)
If compared to the original yes, but that's apples to oranges. They are different resolutions.

It'd be more accurate to compare it to a pre-generated resizing of the original image (at the same effective resolution as the "half downloaded" FLIF).

Re:Free Lossless Image Format by colanderman on Friday October 02, 2015 @12:34PM (#10319552)
A compressed image which does not reconstitute to the original image is by definition lossy. You can't scale a PNG down by 25% and call that "lossless compression".

Though I'll gladly take your logic and call the first 1/64th of a progressive JPEG lossess (which it is, since at that point you only have the DC offsets of basic blocks, which undergo no lossy compression).

Re:Free Lossless Image Format by jonsneyers on Friday October 02, 2015 @06:07PM (#10321640)
I think JPEG's color transform is lossy, so even those basic blocks are somewhat lossy. A better approximation of the entire 8x8 block than the exact pixel at the top-left position of the block, which is what FLIF and PNG with Adam7 interlacing do, but still lossy. If you would take an image, magnify it by a factor of 8 in both directions so each pixel gets blown up to an 8x8 block, then convert it to JPEG, there is still some information lost.
Re:Free Lossless Image Format by mthoms on Friday October 02, 2015 @02:19PM (#10320271)
It's lossless (in theory) when compared to a 1/64th scaled version of the original image (which is what was clearly meant).
Re:Free Lossless Image Format by err4nt on Friday October 02, 2015 @09:32PM (#10322252)
Snall screens dont always have small resolutions. There are more pixels on an iphone than my laptop!
Re:Free Lossless Image Format by silverbacknet on Saturday October 03, 2015 @04:44AM (#10323139)
I don't feel like that page is entirely fair.

The PNG and GIF comparisons are unfair; they're the same low resolution as FLIF, but given nearest-neighbor upsampling instead of bilinear. Most web browsers use bilinear or bicubic upsampling for progressive pictures now, so FLIF isn't nearly as unique as it presents itself. Aside from that, progressive is only useful if you're on a slow connection or the file is broken; in other cases re-rendering multiple times becomes a bottleneck and battery drain. In general it's rare that progressive decoding is a win anymore (although progressive encoding of JPEG is always a win).

In another comment I pointed out that jpeg2000 can be encoded to any size, even 1k, even though the q-scale doesn't go that low, by using the target size parameter instead. It looks better than anything but BPG and is fully progressive. Of course, J2K is a dead format outside of DejaVu, PDF, and the medical field, but it serves as a useful baseline.

A comparison to JXR would have been nice; it's an open, patent-indemnified format that fully supports progressive decoding, and compresses about as well as WebP. That format's the biggest disappointment for me, I thought it had everything in place to displace JPEG.

BPG could be made somewhat progressive, but only by changing the underlying HEVC bitstream, while one of its goals is to stay as close as possible. The inclusion of a thumbnail is the only recourse.

Re:Free Lossless Image Format by jonsneyers on Saturday October 03, 2015 @05:12AM (#10323206)
You're right about the interpolation method (bilinear vs nearest-neighbor), it's indeed not a fair comparison in that respect. However, I do think that most PNG viewers use nearest-neighbor (at least that's what my viewer did when I gave it a partial PNG file).

But it's not just the interpolation that makes a difference: PNG interlaces full RGB pixels (all 3 channels at the same time), while FLIF gives priority to luma so you get a chroma subsampling effect on partial files. Also GIF only has vertical interlacing and PNG only does 7 passes of 2D interlacing, which means that for huge images, the first pass can still take a while.

Another point: I am proposing to use progressive decoding to avoid having to download the full lossless image (so a browser supporting FLIF would need some mechanism to stop downloading the image file when "enough" detail is available). Repeated re-rendering is not necessary. E.g. on a mobile phone you would rather just download some prefix of the file (the size of the prefix could depend on the available bandwidth) and render it once, at least until the user zooms in on the image, or saves or prints it or something -- then the download should be resumed in order to load more/all detail.

Re:Free Lossless Image Format by digi_owl on Friday October 02, 2015 @09:23AM (#10318308)
Makes me think of the web of old, where sometimes an image would load in multiple passes.
Re:Free Lossless Image Format by michaelmior on Friday October 02, 2015 @09:26AM (#10318329)
I assume you're talking about progressive JPEGs. These are still fairly common in my experience. It's just that with today's typical connection speed, you'll rarely notice.
Re:Free Lossless Image Format by masklinn on Friday October 02, 2015 @09:37AM (#10318395)
There's also progressive PNGs. Progressive JPEGs have the advantage that they increase compression ratio (though they're more expensive to decode, as you need multiple passes and refresh)
Re:Free Lossless Image Format by darkmighty on Friday October 02, 2015 @11:51AM (#10319302)
They increase compression ratio? That's counter-intuitive. You're effectively imposing an ordering requiring certain information to be available first, so you'd expect the compression be at most as good as non-progressive. I guess the changed ordering makes the statistics simpler and easier to compress, or something like that.
Re:Free Lossless Image Format by cbr on Friday October 02, 2015 @03:00PM (#10320533)
The downside is memory usage during compression. A non-progressive jpeg can be compressed locally but a progressive encoding requires the whole image. But this is only a small downside.

(Converting JPEG images to progressive format is one of the optimizations mod_pagespeed makes.)

Re:Free Lossless Image Format by mzs on Friday October 02, 2015 @12:08PM (#10319394)
The initial passes are lower freq, so they compress better. More over you have control over them when encoding so you can optimize there (and there are tools that do so), but the defaults used by all encoders are very good across most all images.
Re:Free Lossless Image Format by michaelmior on Friday October 02, 2015 @09:25AM (#10318316)
That part is pretty cool. If this were widely deployed, I could imagine this making the use of responsive images much easier.
Re:Free Lossless Image Format by est on Friday October 02, 2015 @11:07AM (#10319005)
JPEG has something cooler, you can first load a black-white smaller picture, then load more color and more detail.
Re:Free Lossless Image Format by theoh on Friday October 02, 2015 @11:22AM (#10319098)
Thinking back to the old days, are you sure the black and white image you have in mind didn't come from the "lowsrc" attribute of an img tag? Progressive jpeg is typically full colour from the start, and it does offer the progressive enhancement of resolution that you mention.
Re:Free Lossless Image Format by mixmastamyk on Friday October 02, 2015 @01:15PM (#10319850)
Interesting, just last week I had a use for lowsrc for the first time in years and tried to use it, only to find out it had been removed from all browsers a while back.
Re:Free Lossless Image Format by a_t48 on Friday October 02, 2015 @01:47PM (#10320072)
Re:Free Lossless Image Format by grumblestumble on Friday October 02, 2015 @06:11PM (#10321651)
please be aware that w3schools is a terrible resource loaded with inaccuracies and misinformation. It's the National Enquirer of web development. I'd recommend using MDN instead: https://developer.mozilla.org/en-US/.
Re:Free Lossless Image Format by mzs on Friday October 02, 2015 @02:32PM (#10320367)
Look at what the js ia actually doing, lowsrc has been obsoleted in html5: http://www.w3.org/TR/html5/obsolete.html
Re:Free Lossless Image Format by est on Friday October 02, 2015 @11:04PM (#10322435)
Re:Free Lossless Image Format by mzs on Friday October 02, 2015 @12:09PM (#10319398)
It depends on the encoder, it very well could be the first pass is just Y.
Re:Free Lossless Image Format by theoh on Friday October 02, 2015 @12:24PM (#10319483)
I'd call that "grayscale" rather than black and white, but interesting suggestion. I've never seen it done but looks like all sorts of things are possible: http://hodapple.com/blag/2011/11/24/obscure-features-of-jpeg...
Re:Free Lossless Image Format by mzs on Friday October 02, 2015 @03:37PM (#10320774)
Here's the Mandrill test image from SIPI and Utah as a 75% progressive JPEG with just the first scan of the most significant bit of just the DC for Y only, which is a totally expected scheme for the web back in the '90s:

https://lh3.googleusercontent.com/-4tX6mfFoY4c/Vg7bg85RwcI/A...

Re:Free Lossless Image Format by theoh on Friday October 02, 2015 @06:49PM (#10321800)
What do you mean by "totally expected"? A Turing machine "totally expects" an infinite ribbon.
Re:Free Lossless Image Format by mzs on Monday October 05, 2015 @08:30AM (#10331336)
Back in the '90s I was doing work funded by DEC and later NSF with JPEG and one of the things I did was find an decent way to store them at a smaller size and resolution. I found that having the first scan be just the MSB of DC of Y and then later the MSBs of the other two DCs was the same as having the first be all three give or take two bytes over more than 90% of our corpus and it let something display in about half the time (when a 9600 baud modem was target).

It's been a long time but I think what I ended-up with was first scan MSB of Y DC, next six bits of Y AC. Then MSB of Cb and Cr DC, then a scan with a few bits of Cb and Cr DC and AC and finally the rest. The idea was that for a B&W, greyscale, or color thumbnail the same JPEG would be used but only the first N scans sent followed by 0xffd9 with a width and height in the img tag. Anyway, I can't be the only one that figured-out in the days of SLIP over modems that doing this trick was a good idea.

Re:Free Lossless Image Format by jonsneyers on Friday October 02, 2015 @12:45PM (#10319635)
FLIF also emits Y first (actually alpha first), before the chroma channels.
Re:Free Lossless Image Format by isthmus_ on Friday October 02, 2015 @01:50PM (#10320092)
Who needs mipmaps?
Re:Free Lossless Image Format by malkia on Friday October 02, 2015 @02:01PM (#10320161)
The GPU!- skipping those pixels hurts the cache, even if swizzled :)

And my eyes - shimmering car grills and garden fences begone!

Re:Free Lossless Image Format by alanh on Friday October 02, 2015 @03:28PM (#10320693)
Wow, okay, this comment and its parent lost me :)
Re:Free Lossless Image Format by malkia on Saturday October 03, 2015 @01:00AM (#10322679)
Rough context: When the GPU (or the CPU back in the days) had to draw a texture, it had to sample pixels, maybe one, maybe four and do some say bi-linear filtering in between them, and then use that pixel as a result.

Now several problems:

1. If your texture is sampled roughly one pixel from it to one pixel on the screen, and if all pixels are read linearly ("horizontally"), then you are good with the cache, cause for the first pixel you've read the cache maybe cold at that address, but it'll load the next pixels just in case you need them, and here is the catch - you need to get always benefit from that - it's like always using your coupons, and deals, and your employer perks. So the CPU/GPU might read 4, 8, 16 who really knows (but you) bytes in advance, or around that pixel.

2. But then you turn the texture 90 degrees, and suddenly it's much slower. You draw a pixel from the texture, but then the next pixel is 256, 512, or more away ("vertically), and then next too, your cache line of 4, 8, 16, 32 or 64 read bytes that you did not used, and by the time you might need them again, the cache discarded them. Hence the slowness now - much much slower!

4. To fix it, you come up with "swizzling" - e.g. instead of the texture being purely scan-line by scan-line, you kind of split your image in blocks - maybe 8x8 tiles, or 32x32, and then make sure those tiles are linearly written one to each other. You can go even further, but the idea is that under any angle, if you decide to read, you most likely would hit pixels from the same cache line you've read before. It's not that simple, and my explantation is poor, but here is someone who can do that better than me: https://fgiesen.wordpress.com/2011/01/17/texture-tiling-and-...

8. But even with swizzling, tiling, whatever you call that magic to keep pixels together in any direction really together stops working as soon as you have to draw that big texture/image on a much smaller scale.

16. Say 256x256 would have to be drawn as 16x16 - And you say I don't need mipmapping, I don't need smaller versions of my image, I can just use my own image - well then nomatter how you swizzle/tile, you'll be skipping a lot of pixels - hop from here to there, and lost cache lines.

32. For that reasons mipmaps are here to help, but stay with me for one more minute - and see how they almost fix the shimmering problem of textures with "fences", "grills on a car", a pet's cage, or something like it.

64. And when you hear the artist ready to put real spider-man logo on the character made out of real polygons, and real grill in front of the car, made out of real polygons, and real barbed-wired made out of polygons very nice looking fence - then stay away, as these polys woulds shimmer, no good level of detail can be done for them (it'll pop) and such things are just much easily done with textures and mipmaps - it kind of solves a lot of problems.

128. Read about impostor textures.

Re:Free Lossless Image Format by linkydinkandyou on Friday October 02, 2015 @09:27AM (#10318333)
JPEG 2000 has that same feature.

FLIF claims it will beat the lossless compression ratio of JPEG 2000

Re:Free Lossless Image Format by espadrine on Friday October 02, 2015 @09:47AM (#10318469)
It also claims to beat the lossy version, which cannot even be encoded for the transparent fish image at the tested file sizes: http://flif.info/example.php

[ed. image size → file size to emphasize that they had a target byte count for the purpose of comparison]

Re:Free Lossless Image Format by jpambrun on Friday October 02, 2015 @10:02AM (#10318563)
JPEG 2000 is capable of compressing 1969x1307 images without issues. I work with JPEG 2000 codecs every day. It is commonly used in Virtual Microscopy with images in the tens of gigabytes as well as with small 256x256 MRI. I don't know why the author does not present "JPEG 2000 at this size".

Edit: I was confused since with most coders you can specify precise mean squared error optimal truncation points (called quality layers) and it should have been very easy to obtain a stream of any particular file size.

Re:Free Lossless Image Format by vidarh on Friday October 02, 2015 @10:15AM (#10318659)
That example is looking at a specific file size. So what he's saying is that he was unable to produce a JPEG 2000 image in a file that size from that image, not from an image of that resolution in general.
Re:Free Lossless Image Format by silverbacknet on Saturday October 03, 2015 @01:28AM (#10322733)
He didn't try hard enough. OpenJPEG has a file size parameter, which can go well below its -q 0 size. I was easily able to generate a 16.9K jp2 by specifying the size: https://dl.dropboxusercontent.com/u/54412753/doom9/fish.jp2 which in png looks like: https://dl.dropboxusercontent.com/u/54412753/doom9/fish.jp2....

Looks better than anything else but BPG at that size, to me, although FLIF obviously isn't optimized for lossy.

Re:Free Lossless Image Format by jonsneyers on Saturday October 03, 2015 @05:31AM (#10323243)
Thanks for pointing this out! I only tried ImageMagick convert at minimum -quality. Sorry about that.
Re:Free Lossless Image Format by mzs on Friday October 02, 2015 @12:23PM (#10319482)
One interesting thing from that page is that GIF89a allows interlacing. So it really can be that some combo every eighth line is displayed very early on. Moreover there is a notion of image blocks, so for that particular image taking 64x64 blocks for example you could first encode the fishy portions. Also if you used 16x16 blocks you could have true color, though it would be very large, though there would be some improvement running through gzip over http.
Re:Free Lossless Image Format by linkydinkandyou on Friday October 02, 2015 @01:40PM (#10320029)
I'm not picking on FLIF, it may well be better! But the concept of progressively decoding for different quality levels isn't what makes it new.
Re:Free Lossless Image Format by sergiotapia on Friday October 02, 2015 @01:41PM (#10320031)
If you want to use a similar feature -today-, there's this service called Imgix: https://www.imgix.com/

Basically, it allows you to use responsive images using 1 single master image. Makes for a really snappy user experience, and it's very easy to integrate into any project, new or old.

Re:Free Lossless Image Format by rjcaricio on Friday October 02, 2015 @04:27PM (#10321092)
Free & Open Source version: http://thumbor.org/