7 #include "bcwindowbase.inc"
10 #include "../db/tdb.h"
15 #include <semaphore.h>
20 void write_pbm(uint8_t *tp, int w, int h, const char *fmt, ...);
21 void write_pgm(uint8_t *tp, int w, int h, const char *fmt, ...);
22 void pbm_diff(uint8_t *ap, uint8_t *bp, int w, int h, const char *fmt, ...);
26 int rx, ry, rw, rh, iw, ih;
27 int ix0, ix1, iy0, iy1, rsh;
28 double xf0, xf1, yf0, yf1, pw;
30 uint8_t *row(int y) { return idat + (iw<<rsh) * (y>>rsh); }
32 inline double scalex(uint8_t *rp, double v, double yw) {
34 double vv = xf0 * *rp++;
35 int iv = 0; while( ++x < ix1 ) iv += *rp++;
40 inline double scalexy() {
43 if( (yw = pw * yf0) > 0 ) v = scalex(row(y), v, yw);
44 while( ++y < iy1 ) v = scalex(row(y), v, pw);
45 if( (yw = pw * yf1) > 0 ) v = scalex(row(y), v, yw);
49 Scale(uint8_t *idata, int type, int iw, int ih, int rx, int ry, int rw, int rh) {
51 this->idat = idata + ry*iw + rx;
52 this->iw = iw; this->ih = ih;
53 this->rx = rx; this->ry = ry;
54 this->rw = rw; this->rh = rh;
56 void scale(uint8_t *odata, int ow, int oh, int sx, int sy, int sw, int sh);
61 DEL_START, // always the first mark
62 DEL_MARK, // boundary between cur/next media deletion
63 DEL_SKIP, // skip media in current deletion region
64 DEL_OOPS, // ignore previous mark
68 // dele: n. A sign indicating that something is to be removed from <media>
70 class Dele : public ListItem<Dele>
76 Dele(double t, int a) : time(t), action(a) {}
80 class Deletions: public List<Dele>
82 int save(FileXML &xml);
83 int load(FileXML &xml);
86 char filepath[BCTEXTLEN];
87 const char *file_path() { return filepath; }
88 bool empty() { return !first; }
90 int write_dels(const char *filename);
91 static Deletions *read_dels(const char *filename);
93 Deletions(int pid, const char *fn);
98 class Clip : public ListItem<Clip> {
101 int votes, index, groups, cycle, muted;
102 double start, end, best;
104 Clip(int clip_id, double start, double end, int index);
108 class Clips : public List<Clip> {
110 int pid, count, cycle;
112 Clip *locate(int id, double start, double end);
113 int get_clip(int idx, int &id, double &start, double &end);
114 virtual Clip *new_clip(int clip_id, double start, double end, int index);
115 int check(int clip_id, double start, double end, int group, double err);
116 int save(FileXML &xml);
117 int load(FileXML &xml);
122 class Snip : public Clip {
124 ArrayList<double> weights;
125 ArrayList<double> positions;
127 Snip(int clip_id, double start, double end, int index);
131 class Snips : public Clips {
133 Clip *new_clip(int clip_id, double start, double end, int index);
144 uint8_t frm[SFRM_SZ];
145 double position, error_limit;
146 int lid, nid, distance, group_mask;
147 double fmean, fsd, fcx, fcy, fmoment;
148 int64_t lerr, pixlmt;
149 Db::pgRef clip_id_loc;
151 int get_key(Clips *clips, Db::rKey &prev_rkey, Db::rKey &next_rkey);
152 int64_t key_compare(Clips *clips, Db::ObjectLoc &loc);
153 static double mean(uint8_t *dat, int n, int stride=1);
154 static double variance(uint8_t *dat, double mn, int n, int stride=1);
155 static double std_dev(uint8_t *dat, double mn, int n, int stride=1) {
156 return sqrt(variance(dat, mn, n, stride));
158 static double centroid(uint8_t *dat, int n, int stride=1);
159 static void centroid(uint8_t *dat, int w, int h, double &xx, double &yy);
160 static void deviation(uint8_t *a, uint8_t *b, int sz, int margin,
161 double &dev, int &ofs, int stride=1);
162 static int64_t cmpr(uint8_t *ap, uint8_t *bp, int sz);
163 static int64_t diff(uint8_t *a, uint8_t *b, int w, int h, int dx, int dy, int bias);
164 static void fit(int *dat, int n, double &a, double &b);
165 static void eq(uint8_t *sp, uint8_t *dp, int len);
166 static void eq(uint8_t *p, int len) { eq(p, p, len); }
169 int openDb(int rw=0);
170 int resetDb(int rw=0);
174 int attachDb(int rw=0);
179 static void hist_eq(uint8_t *dp, int len);
180 static void scale(uint8_t *idata,int iw,int ih,int rx,int ry,int rw,int rh,
181 uint8_t *odata,int ow,int oh,int sx,int sy,int sw,int sh);
182 int new_clip_set(const char *title, const char *asset_path, double position,
183 double framerate, int frames, int prefix_size, int suffix_size,
184 int64_t creation_time, int64_t system_time);
185 int new_clip_view(int clip_id, int64_t access_time);
186 int access_clip(int clip_id, int64_t access_time=0);
187 int del_clip_set(int clip_id);
188 int new_frame(int clip_id, uint8_t *dat, int no, int group, double offset);
189 int get_timeline_by_frame_id(int fid);
190 int get_timelines(int frame_id);
191 int next_timelines();
192 int get_sequences(int clip_id, int seq_no=0);
193 int next_sequences();
194 int get_image(int id, uint8_t *dat, int &w, int &h);
195 int get_frame_key(uint8_t *dat, int &fid,
196 Clips *clips=0, double pos=0, int mask=~0);
197 int get_media_key(uint8_t *key, int &fid, int dist, double errlmt,
198 Clips *clips=0, double pos=0, int mask=~0);
199 int add_timelines(Clips *clips, int fid, double err);
200 // clip_set accessors
203 int clips_first_id();
205 const char *clip_title();
206 const char *clip_path();
207 double clip_position();
208 double clip_framerate();
209 double clip_average_weight();
210 void clip_average_weight(double avg_wt);
211 double clip_length();
213 int clip_prefix_size();
214 int clip_suffix_size();
216 double *clip_weights();
217 int64_t clip_creation_time();
218 int64_t clip_system_time();
220 // timeline accessors
221 int timeline_id(int id);
223 int timeline_clip_id();
224 int timeline_sequence_no();
225 int timeline_frame_id();
226 int timeline_group();
227 double timeline_offset();
229 // clip_views accessors
230 int views_id(int id);
232 int views_clip_id(int id);
234 int64_t views_access_time();
235 int views_access_count();