#import <AppKit/AppKit.h>

/* Minimalistic program to convert an image file to PNG format.
   Writes the PNG image in the current directory.  */

int
main (int argc, char **argv)
{
  CREATE_AUTORELEASE_POOL (pool);
  NSString *file, *newFile;
  NSData *data;
  NSBitmapImageRep *rep;

  if (argc != 2)
    {
      printf ("Usage: %s /path/to/file.tiff\n", argv[0]);
      exit (EXIT_FAILURE);
    }

  file = [NSString stringWithCString: argv[1]];
  rep = [NSImageRep imageRepWithContentsOfFile: file];
  NSCAssert (rep, @"Could not create image representation");

  data = [rep representationUsingType: NSPNGFileType properties: nil];
  newFile = [[[file lastPathComponent] stringByDeletingPathExtension]
              stringByAppendingPathExtension: @"png"];
  [data writeToFile: newFile atomically: YES];

  RELEASE (pool);

  exit (EXIT_SUCCESS);
}
