Coding Challenge #22

Coding Challenge Series / Technical Interview Series

Now that you’ve become an expert in efficiently copying bytes (you did solve the last challenge, didn’t you?), I have an even more challenging question….

You have a large block of byte oriented data representing a 256-color LCD panel. Each byte represents the color of the pixel.

You’ll need to write a Copy Image function for me …

Your function is provided: width and height of the LCD panel, a reference (or pointer) to the LCD pixel storage, an array with the new colors to set, and a rectangle with the bounds for the new pixels.

The LCD display’s size may not be evenly divisible by 8, yet a pixel row must end on a boundary that is evenly divisible by 8. The image bytes as being provided do not have this behavior.

Copy the new pixels/colors into the LCD storage.

Microsoft AutoCollage 2008

Microsoft AutoCollage web site

I was tempted to try this new application out for a few reasons:

  1. It was new
  2. It was from Microsoft Research and claims some interesting features (like object and face recognition)
  3. It seems to be built using WPF (the screens all look WPF-ized)

Then, before I downloaded it and installed it, I decided I wouldn’t bother for a few reasons:

  1. It’s $20US (a research project?! — just drop the “Research” part!!!)
  2. I didn’t care for any of the sample collages that they have on the web site – the results look amazingly average.
  3. I didn’t know what I’d do with an image that was produced. I suppose I could have emailed it, but I’d rather send full photos than a blurry mess of photos.

They have a flickr group (but ironically they only have 1 member and no collages published as of Sept 4, 2008?! Not even a sample?! That’s awful marketing. Maybe that’s why they’re in research. :)

In any case, if you’re interested, there’s an image gallery here (that for some reason includes head shots of the people who “incubated” the project, the logo, and a photo of the building. Oh, and a few samples and shots of the product.

Where do you "event"?

From JohnPapa.net, “Siliverlight 2-Tip – Declaring Events.”

He thinks that the place to wire up an event is always in code rather than in markup (like XAML).

“What’s my opinion? I firmly believe the handlers belong in the code and not in the XAML.”

I’d suggest that’s not always right either (and maybe not the right question to ask). This technique doesn’t allow the designer to have freedom to decide how to build the interface freely. If you wire up to a “button” click, then the designer has to implement a certain UI feature as a button. Maybe that’s not what they wanted. The UI/code are wound together extremely tightly when using this pattern.

A command/message driven architecture that splits the actual implementation as much as possible is the best pattern for growth and true separation of roles. That being said, it’s not always practical to build a system like that.

I like the CONCEPT of WPF’s RoutedCommand system which is a way in WPF to handle this pattern, but I don’t care for the way that things are enabled and disabled via the CanExecute event handlers. The event handlers can be called hundreds of times a minute depending on your user interface.

The bad news is that Silverlight doesn’t lend itself easily to a message/command driven architecture (as the RoutedCommand system isn’t available in Silverlight 2.0). So what’s a developer to do? :)

I like the ‘toolability’ of doing inline (in XAML) wire-up of events. If the developer just provides a common set of end-points (events) to the UI designer, then they may have an opportunity to more freely control and adjust the user interface as needed without requiring code changes.

So in John’s example code, instead of

btnAddToCard.Click += new RoutedEventHandler(btnAddToCard_Click);

It might be better to provide a method called:

AddToCard(object sender, RoutedEventArgs e) {

}

That way, the designer can wire-up any way they want.

Or, I suppose one could build a rudimentary message/command system by using attached properties and a common event handler which handles all command driven user interface elements. (And now that I think about that more — I think that could end up being quite slick if done carefully).

DIPP – Digital Image Protection Paranoia?

I enjoy Moose Peterson’s photography and blog. He’s a great photographer and an interesting writer. However, he recently changed the way he embeds photos to “better protect them”.  Instead of a simple image embed, he’s now using Flash.

We’ve made some changes here on the blog that you might not have noticed. The images are now being posted as Flash. This is curtosey of my bud Roger,RC (of Layers fame who also created the Moose Gallery) and of course my longtime webmistress Jan. We’ve gone to this because it offers the greatest amount of protection for the images in a web environment. (Oh yeah, forgot to mention, might mess up RSS feeds too.)

I’m not sure what he’s protecting exactly by using Flash for a tiny 350 pixel wide image?

I totally respect his rights as a photographer — that he owns the pictures he’s taken and he doesn’t want others to use them. But, hiding them in Flash just makes the honest people more honest … if you want to steal the tiny image, it’s still REAALY easy to do.

I’ve intentionally distorted the section of the blog containing the image and rotated it to show it’s so easy to do (I used SnagIt 9). It took me a total of 10 seconds to do the fancy work. It would have taken less if I just wanted to grab the bear.

image

(image and content owned by Moose — clipped here for editorial demonstration and distorted as an example)

What impact does this have on me? Well, as suggested in the quote above, the new technique is causing my RSS Reader of choice (Google Reader) to not show any of his beautiful images. And that’s a big loss!

I’d still recommend his web site and content nonetheless … but here’s to hoping he can find a better way to “protect” his images while retaining the ability for RSS readers to show the photography.