Waveson WindowShade

Waveson WindowShadeOver at Waveson, I’ve put up the first version of Waveson WindowShade.

Waveson WindowShade is a utility for Windows which draws an unobtrusive, translucent shade over the desktop and windows other than the one with which the user is interacting, helping him or her focus on the video they’re watching, the document they’re editing, etc.

Z- or depth-related artefacts in GLSL shaders on iPhone 6/6 Plus

Multiplying Matrices with AVX. For Fun*

(Cross-posted from GitHub)

Having previously tinkered only very briefly, in assembly, I was keen to try my hand at more.

I do best with a practical, defined problem to solve; having used more or less the same unrolled-loop implementation of a 4×4 matrix multiplication I wrote in university, it seemed a good candidate for a 21st Century update, using Advanced Vector Extensions (AVX) which first shipped with Sandy Bridge processors in 2011. Non-trivial, but tractable.

*Performance was never a motivation of this side project – the problem is too small – but there wouldn’t be much point if the output were slower. And it isn’t: on my (Ivy Bridge) Macbook Pro, it executes in half as many cycles as my previous unrolled-loop implementation and in slightly more than two-thirds as many cycles on a Haswell Ultrabook.

But not faster than XMMatrixMultiply.

Using Intel’s Secure Key (RDRAND) in MS Visual C++ 2010

UPDATE (29/05/2016): added a function to use RDRAND to generate a random value within a specified range, and refactored the logic into a static library and wrapped it with a dynamic library for use with P/Invoke.

Among the features added to Intel’s 3rd-Generation Core i* processors is a Digital Random Number Generator (DRNG) backed by an on-die hardware entropy source. This new hardware feature is made available to software via the also-new RDRAND instruction.

If you’re still using the compiler which shipped with Visual C++ 2010, it seems the only way to leverage the DRNG is either via a third-party library (the one available from Intel’s website is, as of writing, broken) or by dipping into assembly programming. Of these the latter comes with a couple of catches: the mnenomic/intrinsic for the instruction is not available for older assemblers/compilers, and the assembly is slightly different for 32- and 64-bit environments.

The sample project illustrates testing whether the host processor supports the RDRAND instruction as well as invoking it (via assembly). When built for 32-bit CPUs, the assembly is inlined; when built for 64-bit CPUs, the assembly is linked in via an exernal module (the 64-bit compiler in Visual Studio 2010 does not support inline assembly).

For the most part, the project simply follows the Software Implementation Guide from Intel. Additionally, it demonstrates invoking the instruction via its opcode, and linking a module implemented in assembly into a VC++ project.

Installing Windows 7 under Boot Camp 4.0 (OS X Lion)

This is odd. But true.

This week, I upgraded the hard disk that shipped in a mid-2010 13″ MacBook Pro (MacBookPro7,1) to a larger capacity disk which necessitated clean installs of OS X and Windows. But the Windows 7 installer (quietly) hung at the last step in the installation process. “Completing installation…”, indeed.

Looking on-line, I came across posts from several other other people who were having the same problem, but just the one, improbable-looking, solution.

Improbable as it may have appeared, after following each step, exactly as described, Windows 7 Professional (32-bit edition) installed without complaint..

All Hail the Mighty PNGCRUSH

Among other things, I develop games for Flashbang Science. Earlier this week, I posted an update to our first game, Tubes.


Tubes is Flash-based (written using the Flex SDK), but from very early on we wanted it to appear to integrate seamlessly with the web page in which it is embedded. This was fairly straightforwardly accomplished via CSS positioning and cutting the graphics to match.

But there was a problem under Safari for Windows, as well as both Safari and Google Chrome for OS X: the browser appeared to render the PNG (Portable Network Graphics) images on the page with less contrast than Flash rendered its graphics (which were cut from the same source, using the same tools, etc.), subtly but unmistakeably breaking the illusion of seamlessness.

After much searching, the solution was to use pngcrush to remove the gamma information, embedded ICC profile, and other ancillary colour information from the PNG images which surrounded the game on the page, as follows:

pngcrush -rem cHRM -rem gAMA -rem iCCP -rem sRGB input.png output.png

The above may seem self-evident to designers and others who spend a lot of time working with images on the Web, but this is the post for which I was looking when I searched for safari webkit flash colour difference.

The Bouncy Castle Provider

Recently I was using a Java applet which generated a digital certificate for storage on the local file system, but which was failing, silently, at the last step.

Switching the browser’s security settings down to the lowest (i.e. least secure) level and, subsequently, starting the browser as an Administrator made no difference.

Bringing up the Java Console, I found a stack trace of exceptions with the following root:
java.lang.RuntimeException: java.lang.NoClassDefFoundError: org/bouncycastle/jce/provider/BouncyCastleProvider

This indicated that the applet depended on one or more third-party libraries which had not been deployed with the applet. The solution, here, was to download the current implementation of the Bouncy Castle Cryptography library.

I copied the four .jar files (you don’t need to download the ‘Test Classes’) into the Optional Package directory of my Java installation.

(On Windows, Java is typically installed into the Java folder/directory under Program Files, or, if you are using 32-bit Java on 64-bit Windows, in the Java folder/directory under ‘Program Files (x86)’.)

After restarting the browser again, the applet functioned as desired.

Windows 8 Developer/Consumer Preview on the Latitude XT

UPDATE – April 2, 2012: N-Trig have posted beta drivers for Windows 8, enabling single-touch, clickthrough and basic multitouch on the Dell Latitude XT under Windows 8 (Consumer Preview).

The Windows 8 Previews install quite straightforwardly onto the Latitude XT, but does not include a driver for the XT’s integrated GPU; likewise, a driver is also not (yet?) available via Windows Update. As such, the display is noticeably slow to update and runs at a lower-than-native resolution.

As of writing, a working solution appears to be to install a “legacy” Windows Vista driver, available for download from AMD. (The linked page refers to the 32-Bit edition of Windows Vista, but the package appears to contain both 32-Bit and 64-Bit drivers; I got this to work using the 32-Bit driver on a 32-Bit installation of the Windows 8 Developer Preview.)

When loaded, the installer may not detect the integrated graphics card and so refuses to install the driver. In which case, the thing to do is start ‘Windows Explorer’, right-click ‘Computer’ and choose ‘Properties’ from the menu which appears.

In the window which opens, choose ‘Device Manager’ (on the left) and then navigate to the Display adapter, which may appear as “Microsoft Basic Display Adapter”. Right-click on the adapter and choose ‘Update Driver Software’ from the menu which appears.

In the window which opens, choose ‘Browse my computer for driver software’ and on the next page ‘Browse..’ to the folder into which the package downloaded from AMD extracted the driver. On my XT, this was C:\ATI\Support\10-02_legacy_vista32-64_dd_ccc\Packages\Drivers\Display. With the folder selected, and the ‘Include subfolders’ box ticked, click ‘Next’ and the driver should install.

With this DirectX 9 driver installed, the display updates smoothly, at native resolution, and scores reasonably well under the Windows Experience Index:

Windows 8 on Latitude XT

glDrawRangeElements and Vertex Buffer Objects

It’s not clear from the official documentation, but when drawing elements from a vertex buffer (VBO) via a bound index buffer, the sixth and final parameter to glDrawRangeElements – indices – acts as an offset into the index buffer to the index of the first element to be rendered.

Moreover, the offset is given in bytes and not numbers of elements. So if the values in the index buffer are stored as, say, unsigned short integers – GL_UNSIGNED_SHORT – then the offset to the fifth element would be:
4 * sizeof( GLushort )

Switching from Windows Live Mail to OS X Mail

Moving a couple of thousand messages, across a handful of accounts/mailboxes, from Windows Live Mail to ‘Mail’ (Mail.app) on OS X proved an unexpected journey through several other programs, more or less as follows:

  1. On Windows, import Windows Live Mail messages (stored in .eml files, in 1 message per file) into ThunderBird using the ImportExportTools extension.

    You can find the location (otherwise known as the path) of the folder in which Windows Live Mail stores messages by going to ‘Tools’ > ‘Options’, select the ‘Advanced’ tab and then click the ‘Maintenance…’ button. In the window which opens, click the ‘Store Folder…’ button. A further window will open which will state: ‘Your personal message store is located in the following folder:’ followed by the path to the folder.

    You can copy and paste this path into a Windows Explorer window to see the contents of the folder. Each account (or mailbox, if you prefer) will have its own sub-folder, whose name will begin with the name of the corresponding account. Each such mailbox will be further organised into sub-folders, one each for Inbox, Sent Items, etc.

    Inside Thunderbird, create new folders, one each for the Inbox and Sent Items of each account under Windows Live Mail. Right click on each folder and then choose: ‘Import/Export’ > ‘Import all eml files from a directory’ > ‘just from the directory’ and then browse to the corresponding directory discovered above.

  2. Open your ThunderBird profile folder and copy the ‘Local Folders’ folder (look in the ‘Mail’ sub-folder) to OS X.

    Download and install Eudora Mailbox Cleaner* and drop the folders from ThunderBird onto the icon. This will create a corresponding folder hierarchy under ~/Library/Mail/Mailboxes.

    At this point, my expectation was that Mail.app would pick up the imported messages, but refused to do so even when told to ‘Rebuild’ the mailboxes (which it did detect, but displayed as empty). Further steps were required.

  3. Download, install and run emlx to mbox Convertor. Drag the message files – the .emlx files created in the previous step – from the imported folders under ~/Library/Mail/Mailboxes onto the main window and click the “Save mbox…” button. I created one .mbox file per folder of messages.

  4. Import each .mbox file into Mail.app, usings its in-built import function: ‘File’ > ‘Import Mailboxes…’ > ‘Files in mbox format’. Each .mbox file should be imported into its own folder in Mail.app.

There are very probably other methods, involving fewer steps, which can achieve the same end, but I found that when I took skipped any of the above, Mail.app behaved erratically: at one point, it only imported one message from each folder under each account/mailbox; at another, it appeared to import all messages, but some of them displayed as blank in the reading pane; and so on.

Your mileage may vary.

*Eudora Mailbox Cleaner requires Rosetta, which you may be prompted to install if you haven’t before.


My Photos on Flickr

%d bloggers like this: