September 21, 2009

Using Windows Live Writer to publish to Warwick Blogs

I’ve been playing around with the Atom Publishing Protocol the last couple of days, and as part of this I’ve been able to make a few improvements to the Atom implementation that we have on Warwick Blogs. As a result, it’s now possible to use Windows Live Writer to publish blog entries, which is pretty neat-o as it has draft saving and some better formatting options than can be reliably provided in a browser. Some people may prefer to use it to publish blog entries, although there are a few caveats (in particular, uploading files isn’t supported in our Atom implementation yet so you won’t be able to add pictures inline into blog entries, which is a bit of a shame).

To set it up, you need to add a new account in Windows Live Writer.

Choose “Other blog service”.

Enter the URL of your blog and your ITS username and password. For the security conscious: information sent to the Atom API is sent over HTTPS using HTTP Basic Auth.

As the blog type, select Atom Publishing Protocol, and as the service document enter https://blogs.warwick.ac.uk/blogbuilder/admin/api/atom.spr?forcebasic=true (the https is important here)

Windows Live Writer will then attempt to verify your settings, and make a test post to try and download the theme for your blog. This is a bit hit and miss, I’ve had it working on some blogs but not on others.

Et voilá! Now you’re all set up. Note that this doesn’t support Warwick Blogs-specific behaviour such as permissions (all entries will default to being viewable and commentable by anyone).


September 14, 2009

Using subsample averaging instead of scaling in JAI to get better results

I was looking over this press release about using parallel computing with Xboxes this morning and was struck by just how rubbish the resized images look in it. We use JAI to do image resizing in pure Java in our CMS, and obviously it’s not coming out very well. We’re turning a high quality source image into a very low quality thumbnail.

I tried fiddling with the interpolation on our operation, from Bilinear to Bicubic or Nearest-Neighbour but nothing seemed to make a noticable difference. In the end, however, I stumbled upon this which suggested using Subsample Averaging instead of Scaling as the operation in JAI. Success!


// We have sourceSS, a SeekableStream, and an OutputStream, out

// Load the image from a source stream
RenderedOp source = JAI.create("stream", sourceSS);

// scale the image
float width = source.getWidth();
float height = source.getHeight();

// assume no resizing at first
double scale = 1;

// if the image is too wide, scale down
if (shouldResizeWidth(source, maxWidth)) {
    scale = maxWidth / width;
}

// if the image is too hight, scale down
// IF that makes it smaller than maxWidth has done already
if (shouldResizeHeight(source, maxHeight)) {
    float heightScale = maxHeight / height;
    if (heightScale < scale) {
scale = heightScale;
    }
}

ParameterBlock params = new ParameterBlock();
params.addSource(source);
params.add(scale);// x scale factor
params.add(scale);// y scale factor
params.add(0.0F);// x translate
params.add(0.0F);// y translate

Map<RenderingHints.Key, Object> map = Maps.newHashMap();
map.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
map.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
map.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
map.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

RenderingHints hints = new RenderingHints(map);

params.add(interpolation);

// Here's the important bit - use "SubsampleAverage" instead of "scale" 
RenderedOp alteredImage = JAI.create("SubsampleAverage", params, hints);

ImageEncoder encoder;

switch (fileType) {
    case gif:
    case jpg:
        // now re-encode
        JPEGEncodeParam jpegEncodeParam = new JPEGEncodeParam();
        jpegEncodeParam.setQuality(DEFAULT_SAMPLING_QUALITY);
        // who knows what all this could possibly mean ?
        jpegEncodeParam.setHorizontalSubsampling(0, 1);
        jpegEncodeParam.setHorizontalSubsampling(1, 2);
        jpegEncodeParam.setHorizontalSubsampling(2, 2);
        jpegEncodeParam.setVerticalSubsampling(0, 1);
        jpegEncodeParam.setVerticalSubsampling(1, 1);
        jpegEncodeParam.setVerticalSubsampling(2, 1);
        final int restartInterval = 64;
        jpegEncodeParam.setRestartInterval(restartInterval);

        // done messing with the image. Send the bytes to the
        // outputstream.
        encoder = ImageCodec.createImageEncoder("JPEG", out, jpegEncodeParam);

        break;
    case png:
        PNGEncodeParam.RGB pngEncodeParam = new PNGEncodeParam.RGB();
        encoder = ImageCodec.createImageEncoder("PNG", out, pngEncodeParam);
        break;
    default:
        throw new IllegalArgumentException("Unrecognised image");
}

PlanarImage planarImage = alteredImage.getRendering();
encoder.encode(planarImage);

The difference is actually pretty startling.

Resized using “scale” with bicubic interpolation Resized using “SubsampleAverage”

June 30, 2009

How do programmers feel about their software?

Writing about web page http://www.natpryce.com/articles/000748.html

Nat Pryce posted an article entitled "What do Programmers Feel About Their Software?", which provided a program to try and visualise what the comments in code indicate about programmers' emotions. The program basically analyses all of the comments in the program (which are usually only seen by other programmers working on the same software) and uses Synesketch to display a visual representation of emotion.

So, naturally, I plugged in some of our own software, and the results were quite surprising... There are some demos on the Synesketch website which show some examples of what the images mean.

Blogbuilder

Blogbuilder

Surprisingly, there is a lot of happiness here (signified by circles in bright colours).

Files.Warwick

Files.Warwick

Again, strong happiness for our file-sharing application.

Our (unreleased and unnamed) portal project

Portal Project

Even stronger happiness here, which is to be expected more since it's a relatively new project and I'm the only one who's worked on it...

Sitebuilder2

Sitebuilder2

In sharp (and dire) contrast, comments in our CMS show severe sadness. There are probably a few reasons for this... use of Swing WebFlow is probably up there as one of the top reasons. There's also a LOT more code (and more programmers) than in any of the other projects, and we're a lot more likely to look at each others' code and go "wrong!"


June 08, 2009

The BNP are elected, and we have nobody to blame but ourselves

Writing about web page http://action.hopenothate.org.uk/page/s/notinmyname

There were a lot of people talking on Thursday about going out to vote to make sure the BNP “doesn’t get in”, but it looks like that’s failed since the BNP got their first ever country councillors and have had two people elected to be MEPs.

Since I’ve spent the majority of my adult life living a couple of miles away from Coalville, having a BNP Country Councillor getting the most votes there is particularly poignant to me. I may be being naïve but I simply cannot fathom how anyone in the streets can agree with BNP policies.

Indeed, there has been some suggestion that a lot of people who vote for the BNP do so without understanding their policies. So, the BNP in a nutshell:

  • Do not allow anyone to join who isn’t “indigenous Caucasian”, even if they have been born/brought up in the UK
  • Non-”indigenous Caucasian” peoples will be allowed to stay in the UK, but only as “guests”
  • No mixed-race relationships. The BNP “do not [...] accept miscegenation as moral or normal.”
  • Belief that homosexuality is “unnatural” – opposition to civil partnerships
  • Repatriation of non-Caucasians.
  • Reintroduce capital punishment for convicted terrorists, paedophiles, murderers
  • Holocaust denial (by Nick Griffin, at least – the party has removed most anti-semitic policies). This seems mostly due to a wish to remain anti-Islamic, which has led the party to come out in support of Israel.
  • Introduce a Muslim no-fly policy to stop Muslims flying in and out of the UK
  • Ban Halal/Kosher slaughter of animals
  • Propose that “citizens” should keep a rifle and ammunition in their home

I wonder how many of those hundreds of thousands of people who voted BNP did so because they were in agreement with these policies. Having spent a lot of time in Coalville I can understand that some people definitely agree with these policies, sadly (in my view).

Some have suggested that Labour are to blame for the BNP getting in. This, frankly, is ridiculous – the media are fully prepared to jump on the anti-Labour bandwagon at the moment because the momentum is there and that’s the general public “opinion” at the moment. The fact of the matter is that fewer people voted BNP this time than in 2004 – the problem was that there was:

  • A (relatively) small swing from Labour to Tory, UKIP, Green
  • Lots of people who traditionally would vote Labour decided not to vote at all

So who’s fault is it that the BNP got in? Ours. By not voting, or not explaining to those people willing to vote BNP and didn’t fully understand their policies, we’ve allowed a fascist party a soapbox to preach their messages of hate. Brilliant. I can’t think of a time I’ve felt more depressed about people in this country.

There is a petition, Nick Griffin: Not In My Name which may be a good place to express at least some of the outrage.


April 04, 2009

Tonight, I went for a run for the first time in 16 years

The “done” thing whenever you do exercise and have a blog seems to be to use some kind of new-agey tech tool to tell everyone about it. That’ll learn you for reading my blog!

In other news, I’ve now lost nearly 4st. I’d lost over 4st a while ago but I then kind of fell off the wagon… time to get back on that horse.


<about />

 

I’m a Web Developer in e-lab, part of IT Services at the University of Warwick.

<input type="search" />

<ol id="recentComments">

  • Hi Matthew, having a problem putting favourites into folders, it on… by Rupert Elder on this entry
  • I wrote one entry in Chinese. It published the content as lots of q… by Hongfeng Sun on this entry
  • I’m sure there’s a setting somewhere that’d filte… by Nick on this entry
  • it can’t do anything for that waistcoat though can it! by Steve Ranford on this entry
  • Lastkingoftheenglish – Stupid liberals tampering? You mean pe… by Gavin Alexander on this entry

<ol id="archive">

Loading…

Am I still fat?

Not signed in
Sign in

Powered by BlogBuilder
© MMX