<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -4,5 +4,6 @@ Makefile
 spec/output/*.mov
 spec/output/*.st
 spec/output/*.pct
+spec/output/*.png
 pkg
 doc</diff>
      <filename>.gitignore</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,7 @@
+* adding PNG image format to export_image
+
+* adding movie.export_image as a generic way to export a frame to multiple formats
+
 0.1.3 (October 3rd, 2008)
 
 * some support for text tracks</diff>
      <filename>CHANGELOG</filename>
    </modified>
    <modified>
      <diff>@@ -346,62 +346,13 @@ static VALUE movie_flatten(VALUE obj, VALUE filepath)
 }
 
 /*
-  call-seq: export_pict(filepath, time)
+  call-seq: export_image_type(filepath, time, ostype)
   
-  Exports a PICT file to given filepath (should end in .pct) at the given 
-  time. Time should be a floating point in seconds.
+  Exports an image as the given ostype. It is best to use export_image
+  instead if the ostype can be determined from the filepath extension.
 */
-
-static VALUE movie_export_pict(VALUE obj, VALUE filepath, VALUE frame_time)
-{
-  GraphicsImportComponent component;
-  PicHandle picture;
-  Handle handle;
-  FSSpec fs;
-  OSErr err;
-  
-  picture = GetMoviePict(MOVIE(obj), MOVIE_TIME(obj, frame_time));
-  
-  err = NativePathNameToFSSpec(RSTRING(filepath)-&gt;ptr, &amp;fs, 0);
-  if (err != fnfErr)
-    rb_raise(eQuickTime, &quot;Error %d occurred while opening file for export at %s.&quot;, err, RSTRING(filepath)-&gt;ptr);
-  
-  // Convert the picture handle into a PICT file (still in a handle)
-  // by adding a 512-byte header to the start.
-  handle = NewHandleClear(512);
-  err = HandAndHand((Handle)picture, handle);
-  if (err != noErr)
-    rb_raise(eQuickTime, &quot;Error %d occurred while converting handle for pict export %s.&quot;, err, RSTRING(filepath)-&gt;ptr);
-  
-  err = OpenADefaultComponent(GraphicsImporterComponentType, kQTFileTypePicture, &amp;component);
-  if (err != noErr)
-    rb_raise(eQuickTime, &quot;Error %d occurred while opening picture component for %s.&quot;, err, RSTRING(filepath)-&gt;ptr);
-  
-  err = GraphicsImportSetDataHandle(component, handle);
-  if (err != noErr)
-    rb_raise(eQuickTime, &quot;Error %d occurred while setting graphics importer data handle for %s.&quot;, err, RSTRING(filepath)-&gt;ptr);
-  
-  err = GraphicsImportExportImageFile(component, 0, 0, &amp;fs, smSystemScript);
-  if (err != noErr)
-    rb_raise(eQuickTime, &quot;Error %d occurred while exporting pict to file %s.&quot;, err, RSTRING(filepath)-&gt;ptr);
-  
-  CloseComponent(component);
-  DisposeHandle(handle);
-  DisposeHandle((Handle)picture);
-  
-  return Qnil;
-}
-
-/*
-  call-seq: export_png(filepath, time)
-  
-  Exports a PNG file to given filepath (should end in .png) at the given 
-  time. Time should be a floating point in seconds.
-*/
-
-static VALUE movie_export_png(VALUE obj, VALUE filepath, VALUE frame_time)
+static VALUE movie_export_image_type(VALUE obj, VALUE filepath, VALUE frame_time, VALUE ostype_obj)
 {
-  // TODO refactor out duplication with export_pict
   GraphicsImportComponent component;
   PicHandle picture;
   Handle handle;
@@ -429,7 +380,7 @@ static VALUE movie_export_png(VALUE obj, VALUE filepath, VALUE frame_time)
   if (err != noErr)
     rb_raise(eQuickTime, &quot;Error %d occurred while setting graphics importer data handle for %s.&quot;, err, RSTRING(filepath)-&gt;ptr);
   
-  err = GraphicsImportExportImageFile(component, 'PNGf', 0, &amp;fs, smSystemScript);
+  err = GraphicsImportExportImageFile(component, OSTYPE(RSTRING(ostype_obj)-&gt;ptr), 0, &amp;fs, smSystemScript);
   if (err != noErr)
     rb_raise(eQuickTime, &quot;Error %d occurred while exporting pict to file %s.&quot;, err, RSTRING(filepath)-&gt;ptr);
   
@@ -498,8 +449,7 @@ void Init_quicktime_movie()
   rb_define_method(cMovie, &quot;changed?&quot;, movie_changed, 0);
   rb_define_method(cMovie, &quot;clear_changed_status&quot;, movie_clear_changed_status, 0);
   rb_define_method(cMovie, &quot;flatten&quot;, movie_flatten, 1);
-  rb_define_method(cMovie, &quot;export_pict&quot;, movie_export_pict, 2);
-  rb_define_method(cMovie, &quot;export_png&quot;, movie_export_png, 2);
+  rb_define_method(cMovie, &quot;export_image_type&quot;, movie_export_image_type, 3);
   rb_define_method(cMovie, &quot;dispose&quot;, movie_dispose, 0);
   rb_define_method(cMovie, &quot;poster_time&quot;, movie_get_poster_time, 0);
   rb_define_method(cMovie, &quot;poster_time=&quot;, movie_set_poster_time, 1);</diff>
      <filename>ext/movie.c</filename>
    </modified>
    <modified>
      <diff>@@ -3,6 +3,9 @@
 
 extern VALUE eQuickTime, cMovie, cTrack, cExporter;
 
+
+#define OSTYPE(str) ((str[0] &lt;&lt; 24) | (str[1] &lt;&lt; 16) | (str[2] &lt;&lt; 8) | str[3])
+
 /*** MOVIE ***/
 
 void Init_quicktime_movie();</diff>
      <filename>ext/rmov_ext.h</filename>
    </modified>
    <modified>
      <diff>@@ -79,5 +79,19 @@ module QuickTime
       track.new_text_media
       track
     end
+    
+    # Exports a frame of the movie at the given time (in seconds) to the given file. 
+    # The image format is automatically determined from the file extension. If this
+    # cannot be determined from the extension then you can use export_image_type to
+    # specify the ostype manually.
+    def export_image(filepath, seconds)
+      # TODO support more file types
+      type = case File.extname(filepath)
+        when '.pct' then 'PICT'
+        when '.png' then 'PNGf'
+        else raise QuickTime::Error, &quot;Unable to guess ostype from file extension of #{filepath}&quot;
+      end
+      export_image_type(filepath, seconds, type)
+    end
   end
 end</diff>
      <filename>lib/quicktime/movie.rb</filename>
    </modified>
    <modified>
      <diff>@@ -120,13 +120,13 @@ describe QuickTime::Movie do
     it &quot;export_pict should output a pict file at a given duration&quot; do
       path = File.dirname(__FILE__) + '/../output/example.pct'
       File.delete(path) rescue nil
-      @movie.export_pict(path, 1.2)
+      @movie.export_image(path, 1.2)
     end
     
     it &quot;export_png should output a png file at a given duration&quot; do
       path = File.dirname(__FILE__) + '/../output/example.png'
       File.delete(path) rescue nil
-      @movie.export_png(path, 1.2)
+      @movie.export_image(path, 1.2)
     end
     
     it &quot;should default poster time to 0&quot; do</diff>
      <filename>spec/quicktime/movie_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>f3561a7dde539dc6187ab213cf82e148e9fbe897</id>
    </parent>
  </parents>
  <author>
    <name>Ryan Bates</name>
    <email>ryan@railscasts.com</email>
  </author>
  <url>http://github.com/ryanb/rmov/commit/68c70ce785e4550e7c5649c15b6b5d25203cf5b8</url>
  <id>68c70ce785e4550e7c5649c15b6b5d25203cf5b8</id>
  <committed-date>2008-10-03T14:02:53-07:00</committed-date>
  <authored-date>2008-10-03T14:02:53-07:00</authored-date>
  <message>adding movie.export_image as a generic way to export a frame to multiple formats</message>
  <tree>9fbddabb0a2ca606f93a6712485d6b4a41cd8f6a</tree>
  <committer>
    <name>Ryan Bates</name>
    <email>ryan@railscasts.com</email>
  </committer>
</commit>
