Monday, March 15, 2010

The Silverlight 4 Release Candidate

Scott Guthrie et al. announced many awesome new things during the keynotes at Microsoft's MIX10 conference. One of it was the Silverlight 4 Release Candidate which replaces the beta version and is now available for download. Beside all the great new features that were added, it's now finally possible to use the Visual Studio 2010 RC for Silverlight 4 development. Kudos to the Silverlight team for catching up with Visual Studio 2010 and all the cool new features they implemented. 

The final Silverlight 4 RTW version will be available next month (April 2010). Additonaly the first CTP of the Winows Phone SDK was released and Silverlight is THE platform for Windows Phone 7 series development and it's free! Silverlight for Symbian is also now available for Nokia S60 5th Edition devices like the N97. So Silverlight is becoming more and more a full multi platform technology. Awesome!

This blog post focuses on the Silverlight 4 RC and contains a summary of all the new features that were added since the Silverlight 4 Beta to the Silverlight 4 RC and the breaking changes that naturally come along with betas. Plus some details about the CaptureSource's new capture usage pattern.


New Silverlight 4 RC features

Rich Text
  • RichTextBox rename
  • Text position and selection APIs
  • XAML property for serializing text content
  • XAML clipboard format
  • FlowDirection support on Runs
  • "Format then type" support
  • Thai / Vietnamese / Indic support
  • UI Automation Text pattern
Networking
  • UploadProgress support (Client stack)
  • Caching support (Client stack)
  • Sockets security restrictions removal (Full Trust)
  • Sockets policy file retrieval via HTTP
  • Accept-Language header
Out of Browser (Full Trust)
  • XAP signing
  • Silent install and emulation mode
  • Custom window chrome
  • Better support for COM Automation
  • Cancelable shutdown event
  • Updated security dialogs
Media
  • Pinned full-screen mode on secondary display
  • Webcam / Mic configuration preview
  • More descriptive MediaSourceStream errors
  • Content & Output protection updates
  • Updates to H.264 content protection (ClearNAL)
  • Digital Constraint Token
  • CGMS-A
  • Multicast
  • Graphics card driver validation & revocation
Graphics and Printing
  • Hardware accelerated perspective transformations
  • Ability to query page size and printable area
  • Memory usage and performance improvements
Data
  • Entity-level validation support of INotifyDataErrorInfo for DataGrid
  • XPath support for XML
Parser
  • New architecture enables future innovation
  • Performance and stability improvements
  • XmlnsPrefix & XmlnsDefinition attributes
  • Support setting order-dependent properties
Globalization & Localization
  • Support for 31 new languages
  • Arabic, Hebrew and Thai input on Mac
  • Indic support
More
  • Update to DeepZoom code base with hardware acceleration
  • Support for Private mode browsing
  • Google Chrome support (Windows)
  • FrameworkElement.Unloaded event
  • HTML Hosting accessibility
  • IsoStore performance improvements
  • Native hosting performance improvements (e.g. Bing Toolbar)
  • Consistency with Silverlight for Mobile APIs and Tooling
  • System.Numerics.dll
  • Dynamic XAP support (MEF)
  • Frame / Navigation refresh support
The new webcam and microphone configuration preview is pretty neat. The user can now select the default webcam & microphone device really comfortable and we only need to use CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice() or CaptureDeviceConfiguration.GetDefaultAudioCaptureDevice() to get the selected default video and audio device.


The webcam permission dialog is now consent and can remember if the user has previously allowed that certain application. Tim Heuer's blog post has more details about this handy new feature.


Breaking Changes since the Silverlight 4 beta
The first and most important take away: As usual all Silverlight 4 beta applications have to be updated to the RC and recompiled, otherwise the new RC runtime won't execute them.
  • Renamed RichTextArea to RichTextBox
  • Changes to DRM API
  • TextSelection.SetPropertyValue is now named .ApplyPropertyValue
  • INotifyDataErrorInfo moved to core (System.Windows.dll)
  • WebBrowser.ScriptNotify signature change
  • NotificationWindow.Visible and NotificationWindow.Closed were changed
  • Webcam and output protection change
  • COM Interop API changes (name and namespace)
  • RichTextBox.TextWrapping default value changed
  • Binding declarations in XAML where the target is a DependencyObject
  • HtmlBrush renamed to WebBrowserBrush

The official breaking changes document contains all the details and Koen Zwikstra (@kozw) has made some useful diff lists.

Changed usage pattern for AsyncCaptureImage
The biggest difference in the webcam API besides the renaming of some enums, properties and other members is the change of the AsyncCaptureImage method which was renamed to CaptureImageAsync. Additionally the usage pattern of the CaptureImageAsync method was updated to the standard .Net / Silverlight asynchronous event pattern.

Before the Silverlight 4 RC, AsyncCaptureImage was used like this:
// Initialization
captureSource = new CaptureSource();
captureSource.VideoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();

// Capture image
captureSource.AsyncCaptureImage(bitmap =>
{
   // Process camera snapshot
   Process(bitmap);
});

The new RC CaptureImageAsync usage pattern:
// Initialization
captureSource = new CaptureSource();
captureSource.VideoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();
// Wiring the CaptureImageCompleted event handler
captureSource.CaptureImageCompleted += (s, e) =>
{
   // Process camera snapshot (e.Result is a WriteableBitmap)
   Process(e.Result);
};

// CaptureImageAsync fires the CaptureImageCompleted event
captureSource.ImageCaptureAsync();

Although the pre-RC pattern was smaller and easier, it's overall more consistent now and I welcome the changes.

Blog.SL4++
I already updated SLARToolkit and the samples and I will continue to update some of my Silverlight 4 beta samples during the next days. Furthermore I will make a Silverlight 4 RC build of the Matrix3DEx sample that should take advantage of the new hardware accelerated perspective transformations.

Wednesday, March 10, 2010

Poll Results: Do you block Google Analytics tracking in your browser?

I recently encountered a large difference between the Google Analytics statistics of my website and the server logs. This raised the question in me how reliable the Google Analytics data really is and I asked you to take part in a small survey: Do you block Google Analytics tracking in your browser?. The poll is closed now and here are the results.

The poll got 267 votes total and 68 people voted "Yes, I block Google Analytics." 199 voted for "No, I don't block Google Analytics." This means 25.47% of the participants block Google Analytics in their browser. 

You can now use a simple formula to get the real world Google Analytics statistics (at least for my visitors - the best of all). :-)

GAreal = GAreport * 1.25468164794007490636704119850187


Big thanks to all that helped me and took part in the survey!

Wednesday, February 24, 2010

SLARToolkit - Silverlight Augmented Reality Toolkit

In my last blog post I've preannounced SLARToolkit: The open source Silverlight Augmented Reality Toolkit. Today I'm proud to announce that SLARToolkit is now available at CodePlex.
The aim of SLARToolkit is to make Augmented Reality with Silverlight as easy as possible so that everyone will be able to make Silverlight Augmented Reality applications. Therefore the SLARToolkit release not only includes the full Balder sample you might know from this blog post, it also comes with a brand new sample that uses Silverlight's 3D projection capabilities through my Matrix3DEx library to project different UIElements on the marker.

The SLARToolkit project description from the CodePlex site:
SLARToolkit is a flexible Augmented Reality library for Silverlight with the aim to make real time Augmented Reality applications with Silverlight as easy and fast as possible. It can be used with Silverlight's Webcam API or with any other CaptureSource or a WriteableBitmap. SLARTookit is based on the established NyARToolkit and ARToolkit. SLARToolkit uses a dual license model and could be used for open or closed source applications under certain conditions. See the License page for details.
Features:
Live
A webcam and at least the Silverlight 4 runtime must be installed to run the sample. It's available for Windows and Mac. Alternatively there is also a new video of the Silverlight projection sample embedded below.
If you want to try it yourself you need do download the SLAR and / or L marker, print them and hold them in front of the camera. The marker(s) should be printed non-scaled at the original size (80 x 80 mm) and centered for a small white border. Also make sure the camera is set up properly and the scene is illuminated well without hard shadows. See the SLARToolkit Markers documentation for more details.




Simply press the "Start Fun" Button to start the webcam. Use the ComboBox to select a different UIElement that will be mapped on the marker. The size and the orientation can be changed with the "Scale" and "Rotation" Sliders. The "Threshold" Slider controls the threshold for the marker detection. The "Flip x-axis" Checkbox could be used to flip the video (the webcam output is mirror-reversed by default).
If you click the "Start Fun" Button for the first time you need to give your permission for the capturing. This application uses the default Silverlight capture device. You can specify the video and audio devices that are used by default with the Silverlight Configuration. Just press the right mouse button over the application, click "Silverlight" in the context menu and select the "Webcam / Mic" tab to set them.

Video
I've recorded a short video of the new sample with Expression Encoder's Screen Capture feature. Please keep in mind that the screen recording software eats up a lot of resources while recording and that the actual frame rate is way better.


Background music is leandi by mosaik.


How it works
This sample uses the SLARToolkit CaptureSourceMarkerDetector to detect the markers in each webcam frame. The detection result contains a transformation matrix for each found marker which is then used to transform the selected UIElement. The tracked marker region is highlighted with a red quad through the WriteableBitmapEx library.

Download it, build your app and augment your reality
The open source SLARToolkit library and the samples are hosted at CodePlex. If you have any comments, questions or suggestions don't hesitate and write a comment, use the Issue Tracker on the CodePlex site or contact me via any other media.
Have fun with the library and please keep me updated if you use it anywhere so I can put a link on the project site.

Update 03-15-2010
Updated to the Silverlight 4 Release Candidate.

Update 04-15-2010
Updated to the final Silverlight 4 RTW build.

Monday, February 15, 2010

SLARToolkit Preannouncement

SLARToolkit has been released. Please read this blog post.

In my latest blog posts, the comments and on Twitter I hinted at on one of the projects I'm currently working on: SLARToolkit - The Silverlight Augmented Reality Toolkit. My aim for SLARToolkit is to make Augmented Reality with Silverlight as easy as possible, fast and open source. With this everyone will be able to make Silverlight Augmented Reality applications like that one. SLARToolkit is based on NyARToolkit which is a extented port of the famous ARToolkit. I'm almost done with the implementation and in contact with ARToolworks, which are holding the license for ARToolkit, to get a license agreement. I hope I'll be able to release SLARToolkit within the next two or three weeks at CodePlex. Please stay tuned.


Two weeks ago Julien Dollon contacted me and asked if I could help him with an Augmented Reality demo for his Silverlight 4 talk at Microsoft TechDays 2010 in Paris. Since I'm a nice guy, I've built a special SLARToolkit version for him and send it along with the source code of the SLARToolkit Silverlight projection sample. The sample uses my Matrix3DEx library to project UIElements on the markers. Actually the Matrix3DEx library has its roots there.
Julien altered the sample a bit and showed it at MS TechDays 2010 during his Silverlight 4 talk last week. The presentation was recorded and the official video is available, but you can also watch Julien's self recorded video of the session. The SLARToolkit demo starts at 39:02.





And the official screen cast:

Thursday, January 28, 2010

Rounder, Faster, Better - WriteableBitmapEx 0.9.0.0

A lot of things happened since the release of the last WriteableBitmapEx version. I used the time I have to wait for a third party [spoiler] until I could release my Silverlight Augmented Reality framework SLARToolkit [/spoiler] to work on the WriteableBitmapEx project. Beside some optimizations and smaller extensions, the main addition in the new version is the support for parametric curves. I implemented the cubic Beziér spline and the Cardinal spline. The Cardinal spline is not part of Silverlight's and WPF's Geometry nor shape classes, but the DrawCurve method is part of GDI+ and many people appreciate the characteristics of cardinal splines. Fortunately the WriteableBitmapEx library fills this gap now for the WriteableBitmap.

New features
  • Draw methods for parametric curves: Cubic Beziér splines and the Cardinal splines similar to the GDI+ API. 
  • Clone method to copy the whole WriteableBitmap to a new instance.
  • Boundary check for the Draw* (Shape) methods. The coordinates are now clipped to the WriteableBitmap's size.
  • A new, even faster DrawLine method overload that uses the bitmap's pixels int array, width and height directly as parameters. This method should be used if many lines are drawn to the same WriteableBitmap.
  • Optimization of the byte array conversion methods using the Buffer.BlockCopy method. This improvement was suggested in this comment.
  • WriteTga method to write a WriteableBitmap as a TGA image to a stream. The original method was provided in this blog post.
  • Fast path for Blitting using the Buffer.BlockCopy method if the BlendMode is None and the bitmap should not be tinted. The result is a performance boost by factor 3.5 compared to traditional loop iteration. This improvement was suggested in this CodePlex discussion. 
  • Adam Kinney contributed two new blend modes for the Blit method: Multiply and Mask. He used these in his cool torn photo effect.
  • A new method that takes a function as parameter and iterates over each pixel and sets its color. The method is called ForEach and has two overloads. Usage example:
    writeableBmp.ForEach((x, y, color) => Color.FromArgb(color.A, color.R / 2, (byte)(x * y), 100));
    The method was suggested in this CodePlex discussion. 
The code listing on the project's CodePlex site was updated to show the usage of the new methods.
    Live
    I also wrote a new sample application that shows the spline methods in action. The sample starts with a demo animation that uses the Cardinal spline DrawCurve method to draw an artificial plant that grows procedurally. The other part of the sample is interactive and allows to draw and manipulate Beziér and Cardinal splines with the mouse.



    Uncheck the "Growing plant demo" Checkbox to change to the interactive mode where you can add new or move curve control points with the left mouse button. Press the DEL key while a control point is selected to remove it. The used curve type can be changed with the Radio Buttons. A cardinal spline needs at least 3 points and a cubic Beziér 4 points, a start point, the control point 1, the control point 2 and the end point.The Slider controls the tension of the Cardinal spline. The tension defines the shape of the curve and is usually between 0 and 1. A value of 0 would be a straight line.
    Uncheck the "Points" Checkbox to hide the control points and press the Clear Button to remove all control points. Click the Save Button to write the WriteableBitmap to a TGA image file.
    The other controls should be self-explaining.

    Get it while it's hot
    The WriteableBitmapEx library is hosted at CodePlex. You can find the new binary release here.