Open Sourcing Viewfinder
More than 250,000 lines of code released.
Written by Peter Mattis.
Five months ago, our small team at Viewfinder joined Square. We were inspired by Square’s mission and eager to join a world-class engineering and design team, but we were also excited by the company’s commitment to open source.
Today, we add our efforts to that commitment by releasing the complete source for the Viewfinder server and iOS and Android apps. We’re releasing this code in the hopes that it can be of utility to others, either as an archaeological resource or as the basis for other exciting efforts.
Our days are now filled with other priorities, so we won’t be able to provide support or bug fixes for this code. And while the code is not as clean as it could be, we would rather share it with you than hold it hostage.
- The Viewfinder server provides a structured database schema with a variety of indexing options (secondary, full-text, geo) on top of Amazon’s DynamoDB. See schema.py and indexers.py. Also take a look at operation.py which provides at-least-once execution of idempotent operations.
- The server also provided support for versioning at both the database and protocol levels. See versions.py, message.py and json_schema.py.
- The ViewfinderTool required some nifty maths and fancy OpenGL graphics to implement. What is the fastest way to draw a circular gradient? We tried CoreGraphics, CoreImage and an OpenGL shader. Our eventual solution was to approximate a circular gradient using OpenGL triangle fans and very simple and fast color interpolation.
- The Viewfinder Client uses LevelDB for metadata storage on iOS and Android. While arguably not as convenient as CoreData, it allowed sharing the metadata storage code between iOS and Android and we found LevelDB to be easy to use and very very fast. See DB.h and ContentTable.h.
- How to detect duplicate and near duplicate images from the iOS camera roll? Perceptual fingerprints. See ImageFingerprint.h and ImageIndex.h.
- Need a full text search engine that can work on a mobile device? We built one on top of LevelDB that we used for both searching for contacts and searching for photos. See FullTextIndex.h.
- We used GYP for generating Xcode project files and Android build files. GYP is awesome and removed the serious headache during iOS development of how to handle merge conflicts in Xcode project files. And GYP facilitated sharing a large body of code between the iOS and Android code bases.
- Love C++ template meta-programming? Take a look at JNIUtils.h which uses C++11 variadic templates to automatically compute Java method signatures from C++ methods.
All of our code — 250,000 lines worth — can be found at: https://github.com/viewfinderco.