3 * Copyright (C) 2016-2020 William Morrow
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published
7 * by the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 #if defined(__i386__) || defined(__x86_64__)
22 #if defined (__linux__)
26 #include "arraylist.h"
27 #include "mediadb.inc"
28 #include "filexml.inc"
29 #include "bcwindowbase.inc"
32 #include "../db/tdb.h"
37 #include <semaphore.h>
42 void write_pbm(uint8_t *tp, int w, int h, const char *fmt, ...);
43 void write_pgm(uint8_t *tp, int w, int h, const char *fmt, ...);
44 void pbm_diff(uint8_t *ap, uint8_t *bp, int w, int h, const char *fmt, ...);
48 int rx, ry, rw, rh, iw, ih;
49 int ix0, ix1, iy0, iy1, rsh;
50 double xf0, xf1, yf0, yf1, pw;
52 uint8_t *row(int y) { return idat + (iw<<rsh) * (y>>rsh); }
54 inline double scalex(uint8_t *rp, double v, double yw) {
56 double vv = xf0 * *rp++;
57 int iv = 0; while( ++x < ix1 ) iv += *rp++;
62 inline double scalexy() {
65 if( (yw = pw * yf0) > 0 ) v = scalex(row(y), v, yw);
66 while( ++y < iy1 ) v = scalex(row(y), v, pw);
67 if( (yw = pw * yf1) > 0 ) v = scalex(row(y), v, yw);
71 Scale(uint8_t *idata, int type, int iw, int ih, int rx, int ry, int rw, int rh) {
73 this->idat = idata + ry*iw + rx;
74 this->iw = iw; this->ih = ih;
75 this->rx = rx; this->ry = ry;
76 this->rw = rw; this->rh = rh;
78 void scale(uint8_t *odata, int ow, int oh, int sx, int sy, int sw, int sh);
83 DEL_START, // always the first mark
84 DEL_MARK, // boundary between cur/next media deletion
85 DEL_SKIP, // skip media in current deletion region
86 DEL_OOPS, // ignore previous mark
90 // dele: n. A sign indicating that something is to be removed from <media>
92 class Dele : public ListItem<Dele>
98 Dele(double t, int a) : time(t), action(a) {}
102 class Deletions: public List<Dele>
104 int save(FileXML &xml);
105 int load(FileXML &xml);
108 char filepath[BCTEXTLEN];
109 const char *file_path() { return filepath; }
110 bool empty() { return !first; }
112 int write_dels(const char *filename);
113 static Deletions *read_dels(const char *filename);
115 Deletions(int pid, const char *fn);
120 class Clip : public ListItem<Clip> {
123 int votes, index, groups, cycle, muted;
124 double start, end, best;
126 Clip(int clip_id, double start, double end, int index);
130 class Clips : public List<Clip> {
132 int pid, count, cycle;
134 Clip *locate(int id, double start, double end);
135 int get_clip(int idx, int &id, double &start, double &end);
136 virtual Clip *new_clip(int clip_id, double start, double end, int index);
137 int check(int clip_id, double start, double end, int group, double err);
138 int save(FileXML &xml);
139 int load(FileXML &xml);
144 class Snip : public Clip {
146 ArrayList<double> weights;
147 ArrayList<double> positions;
149 Snip(int clip_id, double start, double end, int index);
153 class Snips : public Clips {
155 Clip *new_clip(int clip_id, double start, double end, int index);
166 uint8_t frm[SFRM_SZ];
167 double position, error_limit;
168 int lid, nid, distance, group_mask;
169 double fmean, fsd, fcx, fcy, fmoment;
170 int64_t lerr, pixlmt;
171 Db::pgRef clip_id_loc;
173 int get_key(Clips *clips, Db::rKey &prev_rkey, Db::rKey &next_rkey);
174 int64_t key_compare(Clips *clips, Db::ObjectLoc &loc);
175 static double mean(uint8_t *dat, int n, int stride=1);
176 static double variance(uint8_t *dat, double mn, int n, int stride=1);
177 static double std_dev(uint8_t *dat, double mn, int n, int stride=1) {
178 return sqrt(variance(dat, mn, n, stride));
180 static double centroid(uint8_t *dat, int n, int stride=1);
181 static void centroid(uint8_t *dat, int w, int h, double &xx, double &yy);
182 static void deviation(uint8_t *a, uint8_t *b, int sz, int margin,
183 double &dev, int &ofs, int stride=1);
184 static int64_t cmpr(uint8_t *ap, uint8_t *bp, int sz);
185 static int64_t diff(uint8_t *a, uint8_t *b, int w, int h, int dx, int dy, int bias);
186 static void fit(int *dat, int n, double &a, double &b);
187 static void eq(uint8_t *sp, uint8_t *dp, int len);
188 static void eq(uint8_t *p, int len) { eq(p, p, len); }
191 int openDb(int rw=0);
192 int resetDb(int rw=0);
196 int attachDb(int rw=0);
201 static void hist_eq(uint8_t *dp, int len);
202 static void scale(uint8_t *idata,int iw,int ih,int rx,int ry,int rw,int rh,
203 uint8_t *odata,int ow,int oh,int sx,int sy,int sw,int sh);
204 int new_clip_set(const char *title, const char *asset_path, double position,
205 double framerate, int frames, int prefix_size, int suffix_size,
206 int64_t creation_time, int64_t system_time);
207 int new_clip_view(int clip_id, int64_t access_time);
208 int access_clip(int clip_id, int64_t access_time=0);
209 int del_clip_set(int clip_id);
210 int new_frame(int clip_id, uint8_t *dat, int no, int group, double offset);
211 int get_timeline_by_frame_id(int fid);
212 int get_timelines(int frame_id);
213 int next_timelines();
214 int get_sequences(int clip_id, int seq_no=0);
215 int next_sequences();
216 int get_image(int id, uint8_t *dat, int &w, int &h);
217 int get_frame_key(uint8_t *dat, int &fid,
218 Clips *clips=0, double pos=0, int mask=~0);
219 int get_media_key(uint8_t *key, int &fid, int dist, double errlmt,
220 Clips *clips=0, double pos=0, int mask=~0);
221 int add_timelines(Clips *clips, int fid, double err);
222 // clip_set accessors
225 int clips_first_id();
227 const char *clip_title();
228 const char *clip_path();
229 double clip_position();
230 double clip_framerate();
231 double clip_average_weight();
232 void clip_average_weight(double avg_wt);
233 double clip_length();
235 int clip_prefix_size();
236 int clip_suffix_size();
238 double *clip_weights();
239 int64_t clip_creation_time();
240 int64_t clip_system_time();
242 // timeline accessors
243 int timeline_id(int id);
245 int timeline_clip_id();
246 int timeline_sequence_no();
247 int timeline_frame_id();
248 int timeline_group();
249 double timeline_offset();
251 // clip_views accessors
252 int views_id(int id);
254 int views_clip_id(int id);
256 int64_t views_access_time();
257 int views_access_count();