Polar Heart Rate Monitor Logos

Polar F6 heart rate monitor Last week I bought a Polar F6 heart rate monitor which I use to improve my fitness workout. Just like many mobile phones it's possible to customize the display with monitor icons. Unfortunatly you must use the Polar Uplink tool to make and upload them. I normally use photoshop for bitmap editing and that's why I wrote this little PHP script (using the GD library) to convert PNG images to the Polar Monitor Bitmap(PMB) format.

Most of the F-series and S-series support custom monitor logos. These are transferred either with infrared or soniclink (audio over speakers). You need the polar uplink tool to edit and transfer the logos. Unfortunatly this tool is far from perfect and I rather use Photoshop to do the editing and then load the file into the editor and upload it. This is however impossible because the tool only supports it’s own PMB format.

For those of you who don’t want to do any programming or want to skip the technical stuff I made a little demo where you can upload your own files and get them converted to the PMB format.

Start the PNG to Polar Monitor Bitmap demo

The Polar Monitor Bitmap (PMB) format

I initially couldn’t find any information on the PMB files polar uses with their upload tool. Luckily once I looked at the internals of the file it turns out to be a very simple text format which looks something like this.

	[BitmapInfo2]
	47
	16
	0
	1024
	0
	512
	0
	...
	

A new search for the BitmapInfo2 pointed me into direction of a internal OS/2 bitmap format. There are similarities between the two but they are not the same. Lucikly I had enough information to decipher the format.

The first number below the header is the width of the bitmap and the second is the height. All lines below that contain the actual image information.

Every line represents one vertical image line and is built up from left to right. Each number is a bit flag counted from bottom to top. Meaning that every pixel represents a bit.

Counting pixels (bits), where black is 1 and white is 0, we get a number which represents a complete line of pixels. There’s an easy formula to determine the value for each pixel

VALUE = COLOR  x  2 ^ POSITION

Where:

color
1 or 0 (black or white)
position
is the y-coordinate of the pixel counted from the bottom of the image

Converting using PHP and the GD library

The PHP GD library has numerous functions to read and interpret images which is just what we need for the conversion. We use it to load an image file (PNG in this situation) and then loop through every pixel in it to determine the bit flags.

If you want to use other formats for the conervsion you need to modify the script below which I use for the PNG transformations.

function image2pmb($imgLoc)
{
  if ( function_exists('ImageCreateFromPng') )
  {
    $imginfo = getimagesize($imgLoc);
    if ( $imginfo )
    {
      if( $imginfo[0]>0 &&
          $imginfo[0]<50 &&
          $imginfo[1]>0 &&
          $imginfo[1]<50 &&
          $imginfo[2]==IMAGETYPE_PNG )
      {

        $img = ImageCreateFromPng($imgLoc);
        $pmb = '[BitmapInfo2]'."\n";
        $pmb .= $imginfo[0]."\n";
        $pmb .= $imginfo[1]."\n";
        for( $x=0; $x<$imginfo[0]; $x++ )
        {
          $line = 0;
          for( $y=0; $y<$imginfo[1]; $y++ )
          {
              $color = ImageColorAt($img, $x, $y);
              $pos = ($imginfo[1]-$y-1);
              $line = ($line | $color * pow(2,$pos));
          }
          $pmb .= $line."\n";
        }
      } else {
        $pmb = 'Image isn\'t a PNG file or exceeds maximum size
                (50x50 pixels).';
      }
      return $pmb;
    }
    else
    {
      return false;
    }
  }
  else
  {
    return 'GD library not found. Unable to convert image.';
  }
}

This function takes only one argument the file location of your image file. Paste it into your scripts to do your own conversions.

And here are some I made earlier

                       

Categorieën: experiments PHP