From 5e2a1bc9e56003349e533f7e5841041ba5c04e28 Mon Sep 17 00:00:00 2001 From: "N.N." Date: Tue, 4 Oct 2005 02:02:15 +0000 Subject: starting to commit gridflow 0.8.0 ... if you know how to use "cvs import" please mail me and i'll use it for 0.8.1 svn path=/trunk/; revision=3646 --- externals/gridflow/format/quicktimehw.c | 244 ++++++++++++++++++++++++++++++++ 1 file changed, 244 insertions(+) create mode 100644 externals/gridflow/format/quicktimehw.c (limited to 'externals/gridflow/format/quicktimehw.c') diff --git a/externals/gridflow/format/quicktimehw.c b/externals/gridflow/format/quicktimehw.c new file mode 100644 index 00000000..4ae77209 --- /dev/null +++ b/externals/gridflow/format/quicktimehw.c @@ -0,0 +1,244 @@ +/* + $Id: quicktimehw.c,v 1.1 2005-10-04 02:02:15 matju Exp $ + + GridFlow + Copyright (c) 2001,2002,2003 by Mathieu Bouchard + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + See file ../COPYING for further informations on licensing terms. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "../base/grid.h.fcs" +#include +#include +#include +#include +#include + +#include +#ifdef LQT_VERSION +#include +#include +#endif + +\class FormatQuickTimeHW < Format +struct FormatQuickTimeHW : Format { + quicktime_t *anim; + int track; + P dim; + char *codec; + int colorspace; + int channels; + bool started; + P force; + int length; // in frames + float64 framerate; + P bit_packing; + FormatQuickTimeHW() : track(0), dim(0), codec(QUICKTIME_RAW), + started(false), force(0), framerate(29.97), bit_packing(0) {} + \decl void initialize (Symbol mode, Symbol source, String filename); + \decl void close (); + \decl Ruby frame (); + \decl void seek (int frame); + + \decl void _0_force_size (int32 height, int32 width); + \decl void _0_codec (String c); + \decl void _0_colorspace (Symbol c); + \decl void _0_parameter (Symbol name, int32 value); + \decl void _0_framerate (float64 f); + \decl void _0_size (int32 height, int32 width); + \grin 0 int +}; + +\def void _0_force_size (int32 height, int32 width) { force = new Dim(height, width); } +\def void seek (int frame) {quicktime_set_video_position(anim,frame,track);} + +\def Ruby frame () { + int nframe = quicktime_video_position(anim,track); + int length2 = quicktime_video_length(anim,track); + if (nframe >= length) { +// gfpost("nframe=%d length=%d length2=%d",nframe,length,length2); + return Qfalse; + } + /* if it works, only do it once, to avoid silly stderr messages forgotten in LQT */ + if (!quicktime_reads_cmodel(anim,colorspace,0) && !started) { + RAISE("LQT says this video cannot be decoded into the chosen colorspace"); + } + int sx = quicktime_video_width(anim,track); + int sy = quicktime_video_height(anim,track); + int sz = quicktime_video_depth(anim,track); + channels = sz/8; // hack. how do i get the video's native colormodel ? + switch (sz) { + case 24: colorspace=BC_RGB888; break; + case 32: colorspace=BC_RGBA8888; break; + default: gfpost("strange quicktime. ask matju."); break; + } + if (force) { + sy = force->get(0); + sx = force->get(1); + } + Pt buf = ARRAY_NEW(uint8,sy*sx*channels); + uint8 *rows[sy]; for (int i=0; iprod(1); + out.give(sy*sx*channels,buf); + started=true; + return INT2NUM(nframe); +} + +//!@#$ should also support symbol values (how?) +\def void _0_parameter (Symbol name, int32 value) { + quicktime_set_parameter(anim, (char*)rb_sym_name(name), &value); +} + +\def void _0_framerate (float64 f) { + framerate=f; + quicktime_set_framerate(anim, f); +} + +\def void _0_size (int32 height, int32 width) { + if (dim) RAISE("video size already set!"); + // first frame: have to do setup + dim = new Dim(height, width, 3); + quicktime_set_video(anim,1,dim->get(1),dim->get(0),framerate,codec); + quicktime_set_cmodel(anim,colorspace); +} + +GRID_INLET(FormatQuickTimeHW,0) { + if (in->dim->n != 3) RAISE("expecting 3 dimensions: rows,columns,channels"); + if (in->dim->get(2)!=channels) RAISE("expecting %d channels (got %d)",channels,in->dim->get(2)); + in->set_factor(in->dim->prod()); + if (dim) { + if (!dim->equal(in->dim)) RAISE("all frames should be same size"); + } else { + // first frame: have to do setup + dim = in->dim; + quicktime_set_video(anim,1,dim->get(1),dim->get(0),framerate,codec); + quicktime_set_cmodel(anim,colorspace); + quicktime_set_depth(anim,8*channels,track); + } +} GRID_FLOW { + int sx = quicktime_video_width(anim,track); + int sy = quicktime_video_height(anim,track); + uint8 *rows[sy]; + if (sizeof(T)>1) { + uint8 data2[n]; + bit_packing->pack(sx*sy,data,Pt(data2,n)); + for (int i=0; i"); + filename = rb_funcall(mGridFlow,SI(find_file),1,filename); + anim = quicktime_open(rb_str_ptr(filename),mode==SYM(in),mode==SYM(out)); + if (!anim) RAISE("can't open file `%s': %s", rb_str_ptr(filename), strerror(errno)); + if (mode==SYM(in)) { + length = quicktime_video_length(anim,track); + gfpost("quicktime: codec=%s height=%d width=%d depth=%d framerate=%f", + quicktime_video_compressor(anim,track), + quicktime_video_height(anim,track), + quicktime_video_width(anim,track), + quicktime_video_depth(anim,track), + quicktime_frame_rate(anim,track)); +/* This doesn't really work: (is it just for encoding?) + if (!quicktime_supported_video(anim,track)) + RAISE("quicktime: unsupported codec: %s", + quicktime_video_compressor(anim,track)); +*/ + } + _0_colorspace(0,0,SYM(rgb)); + quicktime_set_cpus(anim,1); + uint32 mask[3] = {0x0000ff,0x00ff00,0xff0000}; + bit_packing = new BitPacking(is_le(),3,3,mask); +} + +\classinfo { + IEVAL(rself, +\ruby + install '#io:quicktime',1,1 + @comment=%[Burkhard Plaum's (or HeroineWarrior's) libquicktime] + suffixes_are 'mov' + @flags=6 + def self.info; %[codecs: #{@codecs.keys.join' '}] end +\end ruby +); + +#ifdef LQT_VERSION + lqt_registry_init(); + int n = lqt_get_num_video_codecs(); + Ruby codecs = rb_hash_new(); + Ruby fourccs = rb_hash_new(); + for (int i=0; iname); + Ruby f = rb_ary_new2(s->num_fourccs); + for (int j=0; jnum_fourccs; j++) { + Ruby fn = rb_str_new2(s->fourccs[j]); + rb_ary_push(f,fn); + rb_hash_aset(fourccs,fn,name); + } + rb_hash_aset(codecs,name,f); + } + rb_ivar_set(rself,SI(@codecs),codecs); + rb_ivar_set(rself,SI(@fourccs),fourccs); +#endif +} +\end class FormatQuickTimeHW +void startup_quicktimehw () { + \startall +} -- cgit v1.2.1