Tuesday, 30 May 2006

Web Colours

A while I go for my employer I wrote some php that would rotate the colour palette of a gif file in hsl colour space. It let me do things like "get the green version of that blue button"

- I’m not so hot with colours you see, I need things to constrain my choice of possibilities, which is why I appreciate the Accessability Colour Wheel, I can now choose colours on technical reasons instead of asthetic reasons.

I’m more comfortable with this.

Saturday, 20 May 2006

BBC Flash Update

[UPDATE: I have to say it was all my fault. Even though I had the non-free flash plugin install in ubuntu, it wasn’t activiated, I was using GPL Flash 4. Shame! The BBC were blameless - almost - IMHO they should have shown a popup dialog to warn the user and then gone on to see if their flash player could handle it; however thats a minor point compared to my foolish mistake]

To follow up on my previous post, and to prove that it is the javascript flash detection code at fault, I edited the html source of one of the offending pages from this:

if ((ssit_FlashPresent == 2) && (ssit_FlashVersion >= 5)) {
document.write (’<object id="hideandhelp" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="100%" height="85%"><param name="movie" value="intro.swf"><param name="quality" value="high"><param name="bgcolor" value="#FFFF66"><embed name="hideandhelp" src="intro.swf" quality="high" bgcolor="#FFFF66" width="100%" height="85%" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" swLiveconnect="true"></embed></object>’);
}
else {
document.write(’<img src="/cbeebies/totstv/music_sounds/images/console.gif" alt="" width="500" height="300" border="0">’);
}


to this:

if (1 || (ssit_FlashPresent == 2) && (ssit_FlashVersion >= 5)) {
document.write (’<object id="hideandhelp" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="100%" height="85%"><param name="movie" value="intro.swf"><param name="quality" value="high"><param name="bgcolor" value="#FFFF66"><embed name="hideandhelp" src="intro.swf" quality="high" bgcolor="#FFFF66" width="100%" height="85%" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" swLiveconnect="true"></embed></object>’);
}
else {
document.write(’<img src="/cbeebies/totstv/music_sounds/images/console.gif" alt="" width="500" height="300" border="0">’);
}


(In otherwords "just show me the flash anyway, foolish computer); and suddenly the flash all started working again.

If the BBC are buying this ssit flash detection code from a commercial company then I think they are wasting their money, if they would adhere to well known standards there wouldn’t be this problem in the first place.

This would be a better solution:

<object id="hideandhelp" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="100%" height="85%"><param name="movie" value="intro.swf"><param name="quality" value="high"><param name="bgcolor" value="#FFFF66"><embed name="hideandhelp" src="intro.swf" quality="high" bgcolor="#FFFF66" width="100%" height="85%" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" swLiveconnect="true"><img src="/cbeebies/totstv/music_sounds/images/console.gif" alt="" width="500" height="300" border="0"></embed></object>

If they really want to use the ssit stuff… they still shouldn’t. The answer would be to only explicitly block combinations known to fail, rather than only permit those known to succeed; but their source for these combinations known to fail would probably be as faulty as their current code is, and so is doomed to fail.

I’m just writing up a firefox plugin which will be available worldwide on the firefox plugins page to fix known faults with the BBC’s CBeebies website; unless of course the BBC manage to fix their website first….

I have posted my feelings and proofs to the BBC at http://www.bbc.co.uk/feedback/tech_fault_web.shtml

Update: nobody just writes a firefox plugin for the first time. I have more fun finding the fault than writing a work-around which I hope will soon be unnecessary.

BBC and FLASH on Linux

It looks like the BBC web team have changed the way they detect flash support in various browsers.

For example CBeebies pages like Tots-TV no longer work for me.

Where I was able to view flash in BBC websites, I now cannot, even though I can use flash in other websites like www.homestarrunner.com

I have multiple computers running the official flash 7 plugin from macromedia, with a firefox browser and Ubuntu Linux operating system.

Flash works fine for my family on many sites, and used to work on BBC until recently.

A common error with flash  support detection java script is for the person who wrote the script to think that they have covered all cases.

A common unfortunate consequence is for the flash detection javascript to actually be the obstacle instead of the helper.

Flash detection code should offer help or support in case things turn out to work but the  default fallback should always be to try the usual standard way of doing things without clever browser specific tricks.

Friday, 21 April 2006

Key-value pair files to xml

This sed script will read in a key-value pairs file, you know, like this:

NAME=Joe & Freds
CLASS=Cafe


into xsl attribute lists, like this:

name="Joe &amp; Freds" class="Cafe"

ready to be stuck in the middle of a tag.

sed -e '
/=/{ # make sure it has an = sign in
h # save current line
s/=.*/=/
y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/

x # get back original line
s/^[^=]*=// # loose attribute name
/./{ # anything left?
 s/&/&amp;/
 s/"/&quot;/
 s/</&lt;/
 s/>/&gt;/
 s/^/"/;
 s/$/"/;
 H #append to stored line
 x # get it all back
 s/\n//
 p
}
d
}
d
'


Tuesday, 18 April 2006

ALSA stuttering sound

Trouble with applications playing audio stuttering badly, particularly mplayer with:

alsa-space: xrun of at least 0.068 msecs. resetting stream0.4% 10 0
alsa-space: xrun of at least 0.069 msecs. resetting stream0.4% 10 0
alsa-space: xrun of at least 0.065 msecs. resetting stream0.4% 10 0


Wonder no more, read on at the ALSA Wiki, particularly the comment by Daniel further down on why 48000 is sub-optimal in most cases.

Friday, 7 April 2006

Closed Source Kernel Drivers with B#

I commented in recently on use of B# for Linux kernel modules, a B# VM can be done in 8K or less, has a small instruction set and can implement interrupt handlers.

On reflection this is more likely to be popular under the BSD’s who don’t have so much GPL philosophy to contend with.

Hardware manufacturers could provide one set of cross-platform B# binary drivers to run under MAC-OS X and *BSD - any architecture.

Hardware drivers need to make use of a very limited part of the kernel API, the main purpose of a hardware driver is to manage resources for the hardware and implement a standard API for that piece of hardware.

The B# glue layer - somewhat like ndis-wrappers - will be the layer that copes with evolving kernel API’s. And possibly also get ported to the linux kernel - and I really don’t know if this a good thing.  Although Linus has commented against static kernel APIs to support binary modules, he has also refrained from heartily condemning suppliers of binary only kernel modules - often providing their on source-based API glue to the binary module.

While I’m a GPL fan and paying member of the FSF (not card carrying:- my bootable FSF membership card had developed some nasty blemishes making it unbootable by the time I came to need it, so I threw it away) I can see that simpler provision of hardware drivers could speed adoption of a broader selection of  hardware platforms and operating systems.

It remains to been seen to what degree adoption on the wrong terms, i.e. without free software rights, is harmful. If more open source drivers follows the borader consumer adoption, it is maybe beneficial; I’m not yet at the level of Stallman where I can say "free software or no software" - I like my nvidia drivers, although I really wish they were free.

I’m just hoping that B# drivers would require enough meta data to link to make decompilation easy, I do want my source and the ability to fix bugs.

Which might mean that B# is just a glitzy gadget and for the kernel, a bad idea after all.

Monday, 3 April 2006

XSLT Hex to Decimal Conversion

Here’s a trick I came up with to convert some XML values from hex to decimal.

I made clever (awful?) use of substring-after and substring-before and a string-based lookup table.

Very nasty, but with whats available, very neat:

  <!-- output $hexNumber as decimal, recursive so not too many digits please... -->
  <xsl:template name="HexToDecimal">
    <xsl:param name="hexNumber" />
    <xsl:param name="decimalNumber" >0</xsl:param>
    <!– If there is zero hex digits left, output –>
    <xsl:choose>
      <xsl:when test="$hexNumber">
        <xsl:call-template name="HexToDecimal">
          <xsl:with-param name="decimalNumber" select="($decimalNumber*16)+number(substring-before(substring-after(’00/11/22/33/44/55/66/77/88/99/A10/B11/C12/D13/E14/F15/a10/b11/c12/d13/e14/f15/’,substring($hexNumber,1,1)),’/'))" />
          <xsl:with-param name="hexNumber" select="substring($hexNumber,2)" />
        </xsl:call-template>
      </xsl:when>
      <!– otherwise multiply, and add the next digit, and recurse –>
      <xsl:otherwise>
        <xsl:value-of select="$decimalNumber"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <!– If it begins with 0x then parse it for sure, else return it –>
  <xsl:template name="asDecimal">
    <xsl:param name="number" />
    <xsl:choose>
      <xsl:when test="substring($number,1,2)=’0x’">
        <xsl:call-template name="HexToDecimal">
          <xsl:with-param name="hexNumber" select="substring($number,3)"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$number"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>


Invoke with
  <xsl:call-template name="HexToDecimal">
    <xsl:with-param name="hexNumber" select="@hexValueAttribute"/>
  </xsl:call-template>


Or some such