ext/track.c in rmov-0.1.4 vs ext/track.c in rmov-0.1.5

- old
+ new

@@ -189,11 +189,11 @@ SetTrackOffset(TRACK(obj), TRACK_TIME(obj, seconds)); return Qnil; } /* - call-seq: new_video_media + call-seq: new_video_media() Creates a new video media for this track. Generally this method is not called directly, instead you can make a new video track using Movie#new_video_track. @@ -203,11 +203,11 @@ NewTrackMedia(TRACK(obj), VideoMediaType, 600, 0, 0); return obj; } /* - call-seq: new_audio_media + call-seq: new_audio_media() Creates a new audio media for this track. Generally this method is not called directly, instead you can make a new audio track using Movie#new_audio_track. @@ -217,11 +217,11 @@ NewTrackMedia(TRACK(obj), SoundMediaType, 44100, 0, 0); return obj; } /* - call-seq: new_text_media + call-seq: new_text_media() Creates a new text media for this track. Generally this method is not called directly, instead you can make a new text track using Movie#new_text_track. @@ -230,10 +230,105 @@ { NewTrackMedia(TRACK(obj), TextMediaType, 600, 0, 0); return obj; } +/* + call-seq: enable_alpha() + + Enable the straight alpha graphic mode for this track. + + This is best used on an overlayed video track which includes some + alpha transparency (such as in a PNG image). +*/ +static VALUE track_enable_alpha(VALUE obj) +{ + MediaSetGraphicsMode(GetMediaHandler(TRACK_MEDIA(obj)), graphicsModeStraightAlpha, 0); + return obj; +} + +/* + call-seq: scale(width, height) + + Scale the track's size by width and height respectively. + + The value passed is a relative float where "1" is the current size. +*/ +static VALUE track_scale(VALUE obj, VALUE width, VALUE height) +{ + MatrixRecord matrix; + GetTrackMatrix(TRACK(obj), &matrix); + ScaleMatrix(&matrix, FloatToFixed(NUM2DBL(width)), FloatToFixed(NUM2DBL(height)), 0, 0); + SetTrackMatrix(TRACK(obj), &matrix); + return obj; +} + +/* + call-seq: translate(x, y) + + Offset a track's position by x and y values respectively. + + Values should be in pixels. +*/ +static VALUE track_translate(VALUE obj, VALUE x, VALUE y) +{ + MatrixRecord matrix; + GetTrackMatrix(TRACK(obj), &matrix); + TranslateMatrix(&matrix, FloatToFixed(NUM2DBL(x)), FloatToFixed(NUM2DBL(y))); + SetTrackMatrix(TRACK(obj), &matrix); + return obj; +} + +/* + call-seq: rotate(degrees) + + Rotate the track by the given number of degrees. +*/ +static VALUE track_rotate(VALUE obj, VALUE degrees) +{ + MatrixRecord matrix; + GetTrackMatrix(TRACK(obj), &matrix); + RotateMatrix(&matrix, FloatToFixed(NUM2DBL(degrees)), 0, 0); + SetTrackMatrix(TRACK(obj), &matrix); + return obj; +} + +/* + call-seq: bounds() -> bounds_hash + + Returns a hash of boundaries. The hash contains four keys: :left, :top, + :right, :bottom. Each holds an integer representing the pixel value. +*/ +static VALUE track_bounds(VALUE obj) +{ + VALUE bounds_hash = rb_hash_new(); + RgnHandle region; + Rect bounds; + region = GetTrackDisplayBoundsRgn(TRACK(obj)); + GetRegionBounds(region, &bounds); + DisposeRgn(region); + rb_hash_aset(bounds_hash, ID2SYM(rb_intern("left")), INT2NUM(bounds.left)); + rb_hash_aset(bounds_hash, ID2SYM(rb_intern("top")), INT2NUM(bounds.top)); + rb_hash_aset(bounds_hash, ID2SYM(rb_intern("right")), INT2NUM(bounds.right)); + rb_hash_aset(bounds_hash, ID2SYM(rb_intern("bottom")), INT2NUM(bounds.bottom)); + return bounds_hash; +} + +/* + call-seq: reset_transformations() + + Revert any transformations (scale, translate, rotate) performed on this track. +*/ +static VALUE track_reset_transformations(VALUE obj) +{ + MatrixRecord matrix; + GetTrackMatrix(TRACK(obj), &matrix); + SetIdentityMatrix(&matrix); + SetTrackMatrix(TRACK(obj), &matrix); + return obj; +} + void Init_quicktime_track() { VALUE mQuickTime; mQuickTime = rb_define_module("QuickTime"); cTrack = rb_define_class_under(mQuickTime, "Track", rb_cObject); @@ -253,6 +348,12 @@ rb_define_method(cTrack, "offset", track_get_offset, 0); rb_define_method(cTrack, "offset=", track_set_offset, 1); rb_define_method(cTrack, "new_video_media", track_new_video_media, 0); rb_define_method(cTrack, "new_audio_media", track_new_audio_media, 0); rb_define_method(cTrack, "new_text_media", track_new_text_media, 0); + rb_define_method(cTrack, "enable_alpha", track_enable_alpha, 0); + rb_define_method(cTrack, "scale", track_scale, 2); + rb_define_method(cTrack, "translate", track_translate, 2); + rb_define_method(cTrack, "rotate", track_rotate, 1); + rb_define_method(cTrack, "bounds", track_bounds, 0); + rb_define_method(cTrack, "reset_transformations", track_reset_transformations, 0); }