Thursday, September 20, 2012

Some Magic for CSS3 Linear Gradients


About a year ago, I was implementing linear gradients for an OpenType font renderer (using Cairo graphics library) and I decided to support CSS3 Linear Gradient syntax and functionality. Soon I realized that the specification is missing a basic feature of corner-to-corner linear gradients, that is getting the gradient's perpendicular lines (the lines that get the same color) sticking to the other opposite corners. This feature is pretty useful for the Web, where the page designer cannot be sure of the aspect ratio of the box in the user's end — as opposed to the traditional graphics design practice where document was delivered with a solid fixed layout.

I wrote to the CSS3 working group about the problem and proposed to add a keyword to enable this behavior, and temporarily called the keyword magic, as it was supposed to do something traditionally was done manually (and having a good eye). Although, the working group decided to totally change the behavior of the corner keywords and not add yet another keyword for this feature, the name magic corners stuck and is used for the invisible ending points of the gradient vector that makes this magical behavior possible.

This is the story of the name magic corners.

Now for you: The following box uses CSS3 (and some browser-specific directives) to set a magical linear gradient that is supposed to look like the image on the top of this post. If they do look alike, Congratulations! You've got some magic in your browser!

A box with magic-corner linear gradient.

background: linear-gradient(to top right, red, white, blue);

Wednesday, August 08, 2012

Lytro Camera and Light Field Pictures (LFP)

Finally got my Lytro camera two month ago and have already filled up my Lytro photo library with more than one thousand pictures, which stores more than 20GB wroth of data on my hard driver. Of course I keep a backup on my Dropbox folder, which means another 20GB on my hard driver and my paid cloud storage service.

Light field cameras are new technologies, as well as light field pictures. Lytro, Inc. has developed a new file format, called LFP (which is short for Light Field Photography or Light Field Pictures), that is used for almost everything, let it be storing some (about 1GB) mixture of text and binary data about the camera, including the lens array calibration information and wifi MAC address, or storing the raw data and/or the processed data for a light field picture. Now, the best thing about the Lytro, Inc. is that, besides developing this new file format (which is simple enough to reverse-engineer quickly), they are keeping everything transparent, making it easy to understand the logic behind their software and be able to liberate our own data. More importantly, this method allows using common technologies to develop for the Lytro camera, the Lytro Desktop application, and the light field pictures.

Since Lytro released a Windows version of the Lytro Desktop application a couple of weeks ago, I was able to play with my photo library and LFP files. The result is two new pet projects.

Lytro Library Merger

This small Python application lets you merge any Lytro Desktop photo library to your main photo library. For example, if you have a photo library on a Mac OS X machine and have created another one on a Windows machine, now you can merge these two and get all your photos in one place.

More on Lytro Library Merger at http://behnam.github.com/lytro_library_merger/

python-lfp-reader

This is small Python library that comes with some very useful command-line scripts for working with LFP files. But the more interesting feature for some users can be lfp_picture_viewer which displays any processed LFP image and allows you to refocus the image; and it works (almost) any platform that supports Python, including Linux, Windows, and Mac OS X.

Download it at http://pypi.python.org/pypi/lfp-reader or if you prefer the command-line, try "easy_install lfp-reader".

More on http://behnam.github.com/python-lfp-reader/

Moving to zwnj.behnam.es

It was eight years ago that I registered the domain zwnj.org and began writing about software engineering, the Internet and the Persian language. I am still going to do the same, more or less, but I have decided to move this blog to a new address, zwnj.behnam.es, as I'm moving my whole digital identity to one place, behnam.es.