Quartz Composer – Resize Image to Fit Screen / Canvas

I wanted an image to fill the screen in a Quartz Composer composition as part of a slideshow. However, there doesn’t seem to be a built in way to do what I wanted, which was to a) fill the screen without distorting the aspect ratio and b) not have any part of the image cropped. This can be accomplished with a Javascript patch and a bit of Javascript.

/*
 * ScaleImageToScreen (Quartz Composer / JavaScript)
 * This JavaScript will scale an image to fit to the screen,
 * dynamically resizing the image to make sure it fills the
 * screen without cropping the image.
 *
 * Robert Scullin - 2009
 *
 * This code is free for any use / purpose.
 * Use it for whatever; let me know if it's something cool / interesting.
 */

function (__number Width, __number Height) main (__number imageWidth, __number imageHeight, __number screenWidth, __number screenHeight)
{
	var result = new Object();

	var screenRatio = screenWidth / screenHeight;
	var imageRatio = imageWidth / imageHeight;

	if(imageRatio > screenRatio)
	{
		result.Width = screenWidth;
		result.Height = (screenWidth/imageWidth)*imageHeight;
	}
	else
	{
		result.Width = (screenHeight/imageHeight)*imageWidth;
		result.Height = screenHeight;
	}

	// Finally, return the scaled values
	return result;
}

And here’s how the patch + supporting patches are wired together. In this case, I created a macro with an Image input and a Width and Height output.

ScaleImageToScreen_Patch.png

And this is what the entire patch setup looks like:

ScaleImageToScreen_Example.png

And now, no matter what size the canvas is, the image will scale to fit the screen, without cropping any part of the image or distorting aspect ratio.

Let me know if you have any comments / suggestions in the comments.

Install / Activate MATLAB in Snow Leopard

While attempting to activate MATLAB r2009a (Student Edition) on Snow Leopard, I ran into the following error:

MATLAB-Snow_Leopard_Activation_Error.png

There was an unexpected exception:
Can't load library:
/ Applications/ MATLAB_R2009aSV.app/ / bin/ maci64/ libactivation.jnilib 
See the log file
(/ var/ folders/ mt/ mtOPDyw7HAan0obU4100xU+++TI/ -Tmp-/ TMW_svact_robert.log) for more details.

Installing MATLAB worked fine, however, without activation, MATLAB wouldn’t launch. After much searching, I found a solution on MATLAB’s site. The solution posted by MathWorks is to run the activation utility using the 32bit version of Java rather than Snow Leopard’s default of 64bit Java. This can be done by opening the Java Preferences utility ( /Applications/Utilities/Java Preferences.app in Snow Leopard) and dragging the 32bit version of Java for Applications to the top of the list — it should look like the following screenshot.

MATLAB-Snow_Leopard_Java_App_Settings.png

At this point, you can launch MATLAB and activate it. Once MATLAB is activated, you can revert the changes you made in the Java Preferences App (either drag the 64bit version back to the top or click ‘Restore Defaults’).

At this point, everything should work. You’ll need to repeat the above steps if you ever have to run the activation utility again; however, MATLAB will run just fine with the 64bit version of Java being the default version.

Best of luck getting MATLAB running, and if you have questions/issues feel free to post a comment.

Review – Networking USB 2.0 Server

Note – This review is in progress. I’m posting it now so that a) people will find it and b) for people to comment on things they’d like to see me test. Feel free to comment, and if I have the resources on hand I’ll try it and report back.

Edits:

  • Edit 1 (June 8, 2009): Works with Windows 7 Beta 64bit
  • Edit 2 (June 9, 2009): Added what it’s used for, what it comes with, more information about model numbers, web interface, etc.
  • Edit 3 (June 12, 2009): Doesn’t work with a Pinnacle Systems PCTV 800e USB TV Tuner. Scroll down for more info.

I recently picked up a USB Printer and Device Server from China Vasion to act as a USB to Ethernet bridge. I didn’t have any particular reason to get it, but I figured that, being a geek, I’d find a home for it.

The device is designed to let you use a USB device over ethernet – you connect your USB device to the adapter and connect it to your network. Then, run software on your computer to connect to your USB device over your network. It works fairly decently in my preliminary testing, but I’ll keep updating as I get more time.

One of the main selling points that the page listed was “Operating System Support: Windows 2000/XP/2003/Vista, Mac OSX 10.5 or later” – HOWEVER, there doesn’t seem to be any OS X software on the disc. I’ll make an image of it and load it on my Mac and see if there’s a separate partition on the disc, but I don’t believe there is.

That being said, it seems to work fine with Windows XP SP3 32bit and Windows 7 64bit (tested on the Beta, but I see no reason why it won’t work with the RC / final).

The site claims it will work with most USB devices, so as I get the time I’ll test what I can. If you have any suggestions, post them in the comments and I’ll try to test your scenario.

What it comes with:

Photos to come soon!

  • USB 2.0 Server – about 2″ x 2″ x 1″, running firmware version 100.072
  • Switching power adapter with a Chinese plug. China Vasion ships a plug converter depending on where you’re located, but it doesn’t grip the Chinese plug well at all. A slight tug on the power cord, and the adapter slides right out of the plug converter. I’ll likely order a power adapter to replace the one made for China.
  • 6ft Ethernet cable
  • Mini-CD with drivers and software – The “Networking USB Server” tool is version 1124
  • Quick Start Guide

Model Numbers (yes, there are many)

Unfortunately, there doesn’t seem to be a particular model number for this device, so the following is a list of every model name that I’ve found thus far for this USB server. I’m still not exactly sure how it should be referenced.

  • Manufacturer Ref: ZE0MA2RJOQ
  • Web Interface: Networking USB 2.0 Server M1
  • Web Interface’s Support List: MFP41
Picture 429.png
(Part of) The USB Server’s Web Interface

Scenarios that I’ve tested:

Flash Drive – Works!

I did the following tests using HD Tune on a Windows XP machine over a 100mbit network (the fastest the USB server supports) with a 4GB SanDisk Cruzer flash drive.

HDTune_Benchmark_SanDisk_Cruzer_USB_Server.png

Over the Network – 5.5MB/s average, 5.5MB/s max, 3.2MB/s min, 2.2ms access time

HDTune_Benchmark_SanDisk_Cruzer_Local.png

Locally – 26.3MB/s average, 27.5MB/s max, 25.6MB/s min, 0.6ms access time

Clearly, the local connection (over USB 2.0) is significantly faster – 26.3MB/s versus 5.5MB/s over the network. This is a limitation caused both by the 100mbit network connection, as well as overhead on the USB adapter.

Keyboard / Mouse – Works!

Both my generic USB keyboard and Logitec G9 laser mouse work with no problems. I’m not sure how responsive the G9 would be for low-latency uses like gaming, but for general use it seems fine.

Pinnacle Systems PCTV 800e USB TV Tuner – Doesn’t Work

The PCTV 800e is a analog cable / analog broadcast (not that it matters now) / digital broadcast (ATSC). Windows Media Center detects it, but can’t actually pull video over it / tune to anything. It would have been great had it worked, as that would have made an easy way for me to get great ATSC reception without having to run coax all over the house to get a better signal.

Multiple Devices on a USB Hub – Doesn’t Work

This doesn’t work (I wasn’t expecting it to anyways). The software only lets you connect to the device that was connected first.

USB_Server_Multiple_Devices.png

No luck connecting multiple USB devices with a USB hub.

Scenarios that I’d like to test:

  • USB to Serial adapter
  • Webcam
  • Camera control of my Nikon D80 dSLR
  • Game controller (Who knows, someone might find some use for this – some kind of exhibit?)
  • Graphics Tablet (Same reason)
  • Printer
  • Scanner
  • iPod / iPhone
  • Audio adapters – I have a few different kinds lying around
  • SD card readers
  • Whatever else I can find, and anything else you can think of that I might happen to have lying around – suggest it and I’ll try it if I have it!

I’ll keep updating this as I have more time and try more devices – again, comment if you have something to add!

Hello World!

Hello World! This is yet another incarnation of my blog, but this time I intend on posting content. I’ll likely post stuff about electronics, code (Perl, Quartz Composer, PHP, bash, etc.), general geekery, photography, amateur / ham radio, or anything else related that I think other people might enjoy.

If there’s anything that you find interesting, post a comment or subscribe to my RSS feed, and I’ll try to not let you down :) Once you comment and it’s approved (manually), all future comments will be auto-posted provided they’re not spam.

Anyways, welcome, and I hope you enjoy!

The views and ideas in this blog are strictly my own and do not necessarily reflect the views of anyone else, including any employeer, past, present, or future.