Archive for 2006

New MacBooks, but…

Tuesday, May 16th, 2006

The new MacBook is out, replacing the iBook. The upside, besides now being an ICBM, is that it now comes in black. The downside is that the screen is glossy.

MacBook webpage, with “13-inch glossy widescreen display” highlighted in red.

You see this a lot on PC laptops made in the last few years. Sure, the colors are beautiful on such a display — but there’s so much glare! If I wanted a mirror in my computer, I’d just launch iChat and use the iSight as one.

This in addition to my usual lack of desire for a laptop. I won’t be buying one.

Technorati tags: .

GiantColorSwatch

Sunday, May 14th, 2006

Certainly one of my simplest applications ever.

A screenshot of the swatch window, set to white, with the Color Panel in front of it.

You can download it from the GiantColorSwatch webpage.

How to make Photoshop open your EPS file

Sunday, May 14th, 2006

Sometimes, when I want to draw a graphic, I write it instead. I write it in PostScript, as an EPS file, and then convert to whatever destination format I want.

The problem with this plan is that I was never able to get Photoshop to import the EPS directly. I always got this error message:

Could not open “foo.eps” because the parser module cannot parse the file.

Finally, today, I went looking for the solution. I used strings to see what the EPS Parser plug-in looks for. I found it in under a minute.

So, at minimum, this is what your EPS file must contain:

%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 0 0 width height
%%EndComments

The %%EndComments line is the one that I was missing. Make sure yours isn’t missing it too.

In case you want to know more, these special comments (% is the comment character in PostScript) are defined by the Document Structuring Conventions. EPS is an application of DSC.

Technorati tags: , , , .

Report-an-Apple-bug Friday! 40

Friday, May 12th, 2006

This bug is IB refuses to keep pop-up menus open. It was filed on 2006-05-12 at 02:33 PDT.


Summary:

IB closes a pop-up menu being edited in response to any key or mouse event in the menu.

Steps to Reproduce:

  1. Drag a pop-up button into a window in a nib.
  2. Double-click on the pop-up button to edit it.
  3. Change the selection by clicking on any item, or pressing up or down. Or, double-click on an item to rename it, then press return or enter or change the selection.

Expected Results:

The current selected item changes, or is renamed, or both.

Actual Results:

The current selected item changes, or is renamed, or both, and then IB closes the menu, interrupting any plans to further edit the menu until the menu is reopened by the user.

Regression:

This used to work, although I don’t know in what version.

Notes:

No Console output is emitted by IB.


UPDATE 2006-05-24: I got an email from Apple recently telling me that the bug was a duplicate, and just today, Xcode 2.3 came out, including IB 2.5.4 which fixes this bug.


Technorati tags: ,

Why iTunes videos are not widescreen

Tuesday, May 9th, 2006

One of the most frequent complaints about the iTunes Video Store is the resolution. All videos are 320×240.

The reason why lies on Apple’s iPod specifications page:

Display

  • 2.5 inch (diagonal) QVGA transflective, over 65,000-color liquid crystal display with white LED backlight
  • 320 x 240 pixel resolution, .156-mm dot pitch

Let’s say that iTVS sold shows in their native resolution. Joe User buys a show that comes in 720p HD (a 16:9 resolution). He transfers this to his iPod, and watches it on the train. What does he say as soon as the title screen comes on?

“Wow, this sucks. They cut off the top and bottom of the video. I won’t be buying any more TV shows from iTunes again.”

What happened?

Well, remember that the iPod’s screen has a 4:3 aspect ratio. If you show all of a 16:9 video frame on it, you have empty vertical space — usually manifest as black matte above and below the frame, called “letterboxing” (because it’s like looking through a mail slot). Joe User has a screen of a certain height, and the video is not filling that height, so he assumes that the video has been cut.

The other solution is to cut off part of the frame, so that the height is filled, at the expense of the left and/or right end(s) of the frame (called “pan and scan” because the crop must be moved back and forth to keep the important part in-frame). This, in fact, is what Apple does: the videos you buy from Apple have been pre-cut to fit the iPod’s screen. Joe User is happy, even though he is in fact seeing fewer pixels than before.

Aspect ratio isn’t the only issue; there’s also the sheer number of pixels to put on the screen. You can’t fit all of a 720-line-high frame onto a 240-line-high screen, unless you scale it. That takes CPU power, which in turn uses up battery life and may reduce the framerate. Apple does that heavy lifting in advance, so that your iPod doesn’t have to.

There’s a third solution: Make the iPod’s LCD widescreen. This means doing one of two things to it:

  1. Cut off 60 vertical pixels, changing the iPod’s resolution to 320×180.
  2. Add 106+⅔ horizontal pixels, further reducing the size of each pixel. One advantage would be that it would further help hide compression artifacts.

The problem with both solutions is that they make it harder to browse music. Vertical space counts here (for scrolling menus); horizontal space is not as important. And the iPod is still a music player first.

I think that Steve Jobs looked at all of this and decided that the iPod Video as implemented is the best way he could come up with. And if so, I agree.

Technorati tags: , , , , , .

How to create a RAM disk

Tuesday, May 9th, 2006

Added 2007-09-29: This is the hard way. The easy way is my free app Make RAM Disk. It does the same process shown here, but with a lot less effort from you.

I just posted to this lisppaste with a punt solution. Since this solution really has nothing to do directly with the problem stated, I thought I’d share it with you as well, with HTMLization and some editing from the original.

  1. hdiutil attach -nomount ram://num_sectors (sector = 512 bytes = 0.5 K)

    This outputs a device path (/dev/foo) on stdout.

  2. newfs_hfs -v volume_name device_path

    Formats the RAM disk as HFS+. See the manpage for other options.

    [Added 2007-09-23] If you want a case-sensitive file-system (HFS+ being case-insensitive by default), add the -s flag before the device_path.

    [Added 2007-10-14] If you’d rather not use HFS+, then you can use newfs_msdos to get FAT12, FAT16, or FAT32 (you choose which with the -F option), or newfs to get UFS.

  3. diskutil mount device_path

    The RAM disk will be mounted at /Volumes/volume_name.

You could also do something involving mount(8) instead of diskutil if you wanted to mount it inside NSTemporaryDirectory(). Remember to unmount it (hdiutil detach device_path, or the Eject command in the Finder or Dock) when you’re done.

UPDATE 2007-08-07: Changed from hdid to hdiutil attach, since hdid is deprecated and hdiutil works just as well.

UPDATE 2007-09-29: Added link to Make RAM Disk.

UPDATE 2007-10-14: Added references to other commands in the newfs family (specifically, newfs_msdos and newfs).

Small world (and: Iron Coder v1!)

Tuesday, May 9th, 2006

So I was uploading a fixed version of one of the screenshots on my Sand Sand Sand blog post, and decided on a whim to look at some of the stats for some of the other pages on my still-temporary (really!) GeoCities site.

Looking at the stats for my plus/minus images, I saw that the #1 referrer (besides “Unknown”) is Jonathan Rentzsch’s del.icio.us. “Cool,” I thought, “Jonathan Rentzsch bookmarked my plus/minus images.”

And as I was scrolling down his del.icio.us page, looking for the link to my plus/minus page, I stumbled upon some news: Iron Coder v1 is coming! Huzzah!

I don’t know yet whether I’ll participate. I’m still residually tired from the last one. It might depend on the API and the theme, and how much work I have as a mentor in Summer of Code.

Technorati tags: Iron Coder.

Some English rants

Tuesday, May 9th, 2006

I’ve been compiling a list of maltreatments of the English language. Here are my top 10 so far.

  • compatability; definate(ly); desparate(ly); seperate(ly)

    You mean compatibility, definite(ly), desperate(ly), and separate(ly) (respectively). The first one arises from confusion with “ability”, and certainly the conflation of “desperate” with “separate” is easy enough. I don’t know what excuse there is for “definate”.

  • compl[ie]ment

    A compliment is praise. A complement is the inverse of something (for example, 0b101010 is the two’s one’s (thanks, CHz!) complement of 0b010101, and a film negative is the complement of the positive print).

  • [ae]ffect

    When you affect something, you effect a change in it.

  • Held accountable

    Can’t happen. A person is accountable if they can be held to account.

  • classified

    Classified what? USDA Choice? The correct usage is “classified secret“.

  • X Department (of the United States Cabinet, e.g. State Department)

    You wouldn’t say “United States State Department”, would you? No, you wouldn’t, because that sounds redundant. It’s “Department of State”. Also “Department of Defense”, “Department of Energy”, “Department of Justice”, etc. Some of the Departments have a “the”, like the Department of the Interior. But deviation from the rule doesn’t go beyond that.

  • Dilemma (as problem)

    A lemma is a course of action or line of reasoning (dictionaries define it as a subsidiary proposition … used to demonstrate a principal proposition; in this case, the principal proposition is often a course of action). A dilemma is two of these, from which a person must choose. Not every difficult problem is a dilemma.

  • “Welcome to …” (telephone system, website, etc.)

    “Welcome to” should only be used for a place. “Welcome to Huntington Beach, population 189,594“. It should never be used for anything else, including web sites and phone systems. When I hear “Welcome to (mumble). Please choose from the following selections:”, I want to reach through the phone and unplug that answering system.

  • Lower 48 states, Continental United States

    First, Hawaii is lower than the lower 48. Technically, the lowest 48 states include Hawaii and exclude Maine. Also, “lower” would be only correct when there are two (e.g. “lower case” vs. “upper case”). We have never had fewer than 13.

    As for “continental United States”, you have to include Alaska on this one. It’s on the same continent.

    Just use “contiguous United States”.

  • x, y and z

    No, no, and no. Use the “serial comma”, the comma after the second-to-last element in the list. It just looks better that way. (This does not apply when the list has two or fewer elements.)

Technorati tags: .

Some notes about Sand Sand Sand

Monday, May 8th, 2006

I’ve been playing Sand Sand Sand lately. It’s the successor to World of Sand, and it has some important additions.

  • Water now exhibits waves. This means very little, except that it is now impossible to get a perfectly level field of Water.

  • Salt now mixes with Water. Saltwater sinks in plain Water, but other than that, possesses no buoyancy; other substances (besides Water) are suspended in it, rather than floating or sinking.

  • Buoyancy has been added. Oil floats on top of Water; Water floats on top of Sand. But as I mentioned above, this only applies to plain Water, not Saltwater.

  • Wall has been changed to Ground.

  • A new tool has been added: Seed. This tool isn’t draggable; you only get one Seed per click. The Seed will disappear if it hits any substance that is not Ground. If it does hit Ground, it is planted, and grows a fractal tree.

    1. The tree starts off with a trunk made of Wood, which is a slow-burning version of Oil (in that it is flammable and erodes surrounding Ground or whatever when it burns).
    2. After a fractal generation or two, it begins growing Leaves instead of Wood.
    3. The Leaves periodically generate Pollen (or maybe it’s Sap). Pollen suspends (doesn’t float or sink) in any substance, including Water.
  • Fire now generates Smoke, which of course rises. It disappears after a short time, but it can bottle up a small opening. Watch for this if you funnel lots of Oil through a tiny (1–2 px) hole onto a burning stick of Wax.

    A cone filled with Water, pouring onto a roughly diamond-shaped division inside of a small inverted cone. At the mouth of the lower cone is three sticks of Wax, each burning, generating enough smoke to seal off (briefly) the opening between the two cones.

  • Pouring Water now contains bubbles of air/nothing, which of course float to the top. And Saltwater, poured into Water, gets bubbles of Water.

    A cone filled with Water, pouring into empty space. Bubbles are floating up through the Water.
    A cone filled with Water and Saltwater, pouring directly into a second cone filled with plain Water. Water bubbles have appeared in the Saltwater, and air/vacuum bubbles in the top Water.

And a couple of problems:

  • This one existed in WoS, too: Liquids behave more like powders.

    1. They don’t equalize. Create a U-shaped container from Ground, with an upright division in the middle (with a gap between that and the floor of the U). Fill one side, above the gap, with Water or Oil or Saltwater. The other side will fill up to the gap, but not above it.

      A box as described. The left side is full to the top; the right side is filled right up to the bottom of the division.

    2. If you rush a large amount of a liquid down an incline, it takes too long for the level at the bottom to equal the level at the top. A liquid would reach the same level at both ends much more quickly than a powder; the behavior in the game is that of a powder, even when the substance being poured is a liquid (Water, Oil, or Saltwater).

    I think that this can be attributed to the game’s apparent use of pixels as the backing for all game substances; they act as particles of a powder. Of course, I’m just guessing, having not seen the inner workings of the game for myself. But that is my guess and I’m sticking to it.

  • If you fill a container with Water, then put a lid on it with Pollen or Ground, then inject Oil into the Water, it will float up, but it will not even out. It will just form a lump at the top of the field of Water.

  • Bubbles don’t happen in any other liquids or powders, only plain Water. Also, bubbles would only happen when the top is not open (as in a bottle held upside down); a bowl, cone, or box should not have any bubbles. (Maybe I’m asking too much, but you know me: I’m a pedant.)

UPDATE 2006-05-09 04:02 PDT: I knew I forgot one. Turns out I forgot two. Added the list items for smoke and bubbles (amusingly enough, both names of Growl displays).

UPDATE 2006-05-09 05:04 PDT: Error correction to the bubbles list item: Air in water isn’t the only kind of bubble in the game. Also added screenshots.

Shading in PostScript

Monday, May 8th, 2006

I’ve recently been beating my head against PostScript’s gradient (“shading”) system. Plenty of documentation and examples are available for when you’re working in the DeviceGray color space, but when you’re in DeviceRGB, it gets hard. Part of this is due to the fact that the PostScript Language Reference Manual’s description of shadings and the functions that power them is overly abstract and decorated with too much math for my language-oriented mind.

So, here I’ll try and explain it more clearly, particularly by explaining functions in the context of shadings, rather than separately.

A shading in PostScript is represented by a dictionary. Valid keys in the shading dictionary are:

ShadingType
The type of gradient: axial, radial, etc.
ColorSpace
The color space of colors returned by the function.
Coords
The start and end of the gradient on the page. Defined more specifically by the PLRM.
Function
A function dictionary, or an array of them.

Functions aren’t as you expect them to be. Rather than a callable object (a procedure), a function is a dictionary. (This, BTW, is the architectural reason for Quartz’s CGFunction class, although CGFunction actually uses a C function callback — what would be a procedure in PostScript.) There are three types of function dictionaries; I’ll only deal with type 0, a sampled function (a “sample” is a step in the gradient). A sampled function contains, or fetches from a file, the samples it will return, in a “data source”.

FunctionType
Guess.
Domain
Two numbers for every input, constraining that input to a range. If an input is below the first number, it will be replaced with the first number; if it is above the second number, it will be replaced by the second number. Generally, these two numbers are 0 and 1. In an axial shading function, there is only one input, so your domain should be two numbers (e.g. [0 1]).
Range
The other end from Domain. Works the same way, but it constrains your outputs rather than your inputs. For a shading function, there is one pair of numbers for each component. So, in DeviceGray, Range should be two numbers; in DeviceRGB, it should be six.
BitsPerSample
Named slightly misleadingly (the PLRM clarifies), this is actually the number of bits per component. So if you’re doing 24-bit RGB, this should be 8.
Size
An array containing the number of samples as an int.
DataSource
Either a file or a string from which to get the sample data.

You might expect that the samples should be given as an array. You would be wrong. Instead, PostScript wants pure binary data, either from a file or encoded as a string. So, for example, in RGB, every three characters (bytes) are one sample. I use a hexadecimal literal, or when I want to use an array, this procedure (which you may consider to be under the modified BSD license):

% array -> hexstr -> string
% Converts an array of integers to a string. [ 65 66 67 13 10 ] -> (ABC\r\n).
/hexstr {
4 dict begin
/elements exch def
/len elements length def
/str len string def

/i 0 def
{
i len ge { exit } if

str i
%The element of the array, as a hexadecimal string. If it exceeds 16#FF, this will fail with a rangecheck.
elements i get cvi
put

/i i 1 add def
} loop

str
end
} def

And yes, I know that that procedure has nothing to do with hexadecimal. I was probably tired when I wrote it.

Note: If you use hexstr to create a shading dynamically from an array of samples, be aware that when you divide the length of the array by 1 (gray) or 3 (RGB) or 4 (CMYK) to get the proper value for Size, you must use cvi on the quotient, because div returns a real and makepattern demands an int.

Beware the nib

Sunday, May 7th, 2006

Say you have an object, X, and a nib containing two other objects, Y and Z. X has two outlets, y and z, with typical accessors for each.

X, or another object on behalf of X, loads the nib with X as its owner. NSNib, naturally, sets the y and z properties of X to the two objects in the nib, using the accessors since they exist.

Now, when an object is instantiated, it has a retain count of 1; it is implicitly owned by the object that created it. If you release that object, the retain count goes down to 0 and the object dies.

Such is the case of the objects Y and Z when they are unarchived from the nib: After they come out of deep freeze, they have that starting retain count of 1. But then they are passed to the accessors of X, which, if written in the usual way, retain Y and Z. Now the retain counts are 2 each.

When X is finished with Y and Z, it releases them, of course (perhaps by calling its accessors with nil). But the implicit retains still exist. Therefore, so do Y and Z.

This isn’t a nib bug, though; the bug is in X. Outlets aren’t supposed to be retained. So, if you do implement accessors, they should be non-retaining. Or, if you can, omit the accessors; NSNib will do the Right Thing for you.

Example of the bug: NibLeak (source code with Xcode 2.2.1 project).

Technorati tags: .

Report-an-Apple-bug Friday! 39

Friday, May 5th, 2006

This bug is Reason parameter to SystemSound API functions. It was filed on 2006-05-05 at 00:23 PDT.


Summary:

SystemSound API should have functions that take a reason (expressed as a CFString) for the beep.

Steps to Reproduce:

  1. Open .

Expected Results:

One or more functions exist that take a CFString parameter called inReason.

Actual Results:

No such functions exist.

Regression:

None.

Notes:

One of the most annoying things that can happen in the Mac environment is when a beep occurs, with no explanation. Sometimes this is the result of a processing delay, with the application beeping multiple seconds after the event that triggered the beep (by which time the user has moved on to some parallel task). Other times, the app is just broken, only beeping when it should also display a dialog or when it should use a Growl notification instead (some apps beep at the completion of a task, optionally or otherwise).

This can be solved by adding new functions to SystemSound (and, for convenience, AppKit — NSBeepWithReason, say) that take a reason for the beep. This reason would be logged to the Console (example format: “Beeped (Reason: ^0)”), and if the user so desires, displayed to the user in a bezel (or, better yet, a Growl notification). Existing functions, or the new functions with reason=NULL, would use a localized “No reason was supplied” message.

Example Console.log line:

2006-05-04 22:52:15.974 Safari[252] Beeped (Reason: Quit playing online games and get back to work!).

2006-05-04 22:52:16.974 AppThatDoesNotSupplyAReason[253] Beeped (no reason supplied).

Even if no reason is supplied, the log message is still useful, because it at least says which app beeped.

A Growl notification could have “APPNAME beeped” as the title and the reason as the description. Separate notifications should exist for reason and no reason, with the with-reason notification turned on by default, and the no-reason notification turned off by default.


Technorati tags: ,

More Beads

Tuesday, May 2nd, 2006

My entry in Iron Coder, Beads, had a bug in it. I fixed this bug and called it 1.1. You can get it at the shiny new Beads webpage.

I also finished an article that I’d been working on, called How to draw Beads. It documents the creation of the pretty bead graphics, step-by-step.

Technorati tags: , .

W00t

Monday, May 1st, 2006

I got my California ID card today. :D

Report-an-Apple-bug Friday! 38

Friday, April 28th, 2006

This bug is Can’t drag text into a text input in a form. It was filed on 2006-04-28 at 01:07 PDT.


Summary:

Inputs of type “text” do not register themselves as drop targets.

Steps to Reproduce:

  1. Select some text. I used some text in Adium’s inputline, and in a textarea in Safari, and on the page in Safari.
  2. Drag it into an input of type “text” in a form on a page in Safari.

Expected Results:

The input accepts the drop.

Actual Results:

The input fails the drop.

Regression:

None known.

Notes:

Dragging to a textarea works.


At 05:14, I uploaded a test case.


Technorati tags: ,

Report-an-Apple-bug Friday! 37

Friday, April 28th, 2006

This bug is Volume MenuExtra is not accessible. It was filed on 2006-04-28 at 00:54 PDT.


Summary:

The slider in the Volume MenuExtra is not usable by Accessibility applications.

Steps to Reproduce:

  1. Launch the Accessibility Inspector.
  2. Click on the Volume MenuExtra.
  3. Point to the slider.

Expected Results:

Accessibility Inspector describes a slider.

Actual Results:

Attributes:

AXRole: “AXUnknown”

AXRoleDescription: “unknown”

AXChildren: “

AXParent: “

AXPosition: “x=987 y=22”

AXSize: “w=29 h=116”

AXEnabled: “true”

Regression:

None known. The Volume MenuExtra from Panther (10.3.9) has the same problem.

Notes:

None.


Technorati tags: ,

Report-an-Apple-bug Friday! 36

Friday, April 28th, 2006

This bug is -mtune (Instruction Scheduling) does not include Intel processors. It was filed on 2006-04-28 at 00:35 PDT.


Summary:

With the move to Intel processors, Xcode needs to support processor-specific optimization for them.

Steps to Reproduce:

  1. Get info on a target or project.
  2. Switch to the Build tab.
  3. Change the active Collection to one that includes GCC/Code Generation.
  4. Edit the “Instruction Scheduling” setting.

Expected Results:

At least pentium-m is listed, being (presumably) the most similar to Yonah (the “Core Solo”/”Core Duo” processors). Ideally, scheduling optimizations for Yonah itself should be added to GCC, with a matching listing in Xcode’s pop-up menu.

Actual Results:

Only G3, G4, and G5 are listed (besides “None”).

Regression:

This wasn’t a problem before the move to Intel.

Notes:

Direct Yonah support isn’t supported by GCC (yet) according to the GCC manual’s page “i386 and x86-64 Options”. GNU’s current documentation doesn’t list it either.


Technorati tags: ,

Unscheduled downtime

Thursday, April 27th, 2006

Last night, my hard drive started making some unpleasant noises (click-of-death-ish). So I backed up my C and Obj-C programs (annoying my dad, who wanted to watch NCIS during that time). They resumed with renewed vigor tonight, so I’m now backing up everything, and today I’ll be going to CompUSA to buy a new hard drive. It’s more than twice as big as my current drive (250 GB rather than 120 GB), and it’ll be $60 after rebate.

Preceding that will be lunch at Sizzler, and following it will be photocopying the rebate form and the receipt so we can mail the required documents to Maxtor. I don’t know when I’ll be back — probably a day or two.

Free SEE (maybee)

Tuesday, April 25th, 2006

MacZOT is doing a thing called BlogZOT. Every time somebody posts and submits a blog post about it, the price of SubEthaEdit goes down by 5 cents (USD, I guess). As of this writing, it’s at $11.75 with 365 posts. And the lower bound? $0. That’s right; if enough people blog about it, SEE will be free for the rest of the day. This post is my contribution.

Hope you enjoy your free SEE!

UPDATE 15:18 PDT: I looked at the MacZOT homepage and they mention two other requirements for a blog post:

  • MacZOT and TheCodingMonkeys will award $105,000 in Mac software
  • any comments you have about the software, the web site, or the promotion

So, uh, yeah. MacZOT and TheCodingMonkeys will award 105 kilobucks of Mac software. And SEE rocks.

Technorati tags: MacZOT, BlogZOT, SubEthaEdit.

Boring personal stuff #2

Monday, April 24th, 2006

Filed for my state ID today. Supposed to arrive in “about three weeks”. Next on the list will be passport.