Permalink
Browse files

adding movie.export_image as a generic way to export a frame to multi…

…ple formats
  • Loading branch information...
1 parent f3561a7 commit 68c70ce785e4550e7c5649c15b6b5d25203cf5b8 @ryanb committed Oct 3, 2008
Showing with 30 additions and 58 deletions.
  1. +1 −0 .gitignore
  2. +4 −0 CHANGELOG
  3. +6 −56 ext/movie.c
  4. +3 −0 ext/rmov_ext.h
  5. +14 −0 lib/quicktime/movie.rb
  6. +2 −2 spec/quicktime/movie_spec.rb
View
@@ -4,5 +4,6 @@ Makefile
spec/output/*.mov
spec/output/*.st
spec/output/*.pct
+spec/output/*.png
pkg
doc
View
@@ -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
View
@@ -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)->ptr, &fs, 0);
- if (err != fnfErr)
- rb_raise(eQuickTime, "Error %d occurred while opening file for export at %s.", err, RSTRING(filepath)->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, "Error %d occurred while converting handle for pict export %s.", err, RSTRING(filepath)->ptr);
-
- err = OpenADefaultComponent(GraphicsImporterComponentType, kQTFileTypePicture, &component);
- if (err != noErr)
- rb_raise(eQuickTime, "Error %d occurred while opening picture component for %s.", err, RSTRING(filepath)->ptr);
-
- err = GraphicsImportSetDataHandle(component, handle);
- if (err != noErr)
- rb_raise(eQuickTime, "Error %d occurred while setting graphics importer data handle for %s.", err, RSTRING(filepath)->ptr);
-
- err = GraphicsImportExportImageFile(component, 0, 0, &fs, smSystemScript);
- if (err != noErr)
- rb_raise(eQuickTime, "Error %d occurred while exporting pict to file %s.", err, RSTRING(filepath)->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, "Error %d occurred while setting graphics importer data handle for %s.", err, RSTRING(filepath)->ptr);
- err = GraphicsImportExportImageFile(component, 'PNGf', 0, &fs, smSystemScript);
+ err = GraphicsImportExportImageFile(component, OSTYPE(RSTRING(ostype_obj)->ptr), 0, &fs, smSystemScript);
if (err != noErr)
rb_raise(eQuickTime, "Error %d occurred while exporting pict to file %s.", err, RSTRING(filepath)->ptr);
@@ -498,8 +449,7 @@ void Init_quicktime_movie()
rb_define_method(cMovie, "changed?", movie_changed, 0);
rb_define_method(cMovie, "clear_changed_status", movie_clear_changed_status, 0);
rb_define_method(cMovie, "flatten", movie_flatten, 1);
- rb_define_method(cMovie, "export_pict", movie_export_pict, 2);
- rb_define_method(cMovie, "export_png", movie_export_png, 2);
+ rb_define_method(cMovie, "export_image_type", movie_export_image_type, 3);
rb_define_method(cMovie, "dispose", movie_dispose, 0);
rb_define_method(cMovie, "poster_time", movie_get_poster_time, 0);
rb_define_method(cMovie, "poster_time=", movie_set_poster_time, 1);
View
@@ -3,6 +3,9 @@
extern VALUE eQuickTime, cMovie, cTrack, cExporter;
+
+#define OSTYPE(str) ((str[0] << 24) | (str[1] << 16) | (str[2] << 8) | str[3])
+
/*** MOVIE ***/
void Init_quicktime_movie();
View
@@ -79,5 +79,19 @@ def new_text_track(width, height)
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, "Unable to guess ostype from file extension of #{filepath}"
+ end
+ export_image_type(filepath, seconds, type)
+ end
end
end
@@ -120,13 +120,13 @@
it "export_pict should output a pict file at a given duration" 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 "export_png should output a png file at a given duration" 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 "should default poster time to 0" do

0 comments on commit 68c70ce

Please sign in to comment.