2011-11-05 16:46:53 +00:00
|
|
|
'use strict';
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
2012-05-31 10:32:54 +00:00
|
|
|
Ox.SmallVideoTimelineImage <f> Small Video Timeline Image
|
2012-05-21 10:38:18 +00:00
|
|
|
options <o> Options
|
|
|
|
self <o> Shared private variable
|
2012-07-04 11:29:18 +00:00
|
|
|
([options[, self]]) -> <o:Ox.Element> Small Video Timeline Image
|
2012-05-21 10:38:18 +00:00
|
|
|
@*/
|
2011-05-15 18:50:05 +00:00
|
|
|
Ox.SmallVideoTimelineImage = function(options, self) {
|
2011-05-15 16:18:58 +00:00
|
|
|
|
|
|
|
self = self || {};
|
|
|
|
var that = Ox.Element({}, self)
|
|
|
|
.defaults({
|
2011-05-17 09:43:54 +00:00
|
|
|
duration: 0,
|
2012-04-18 07:43:32 +00:00
|
|
|
imageURL: '',
|
2013-02-12 06:28:52 +00:00
|
|
|
invertHighlight: false,
|
2011-05-15 16:18:58 +00:00
|
|
|
'in': 0,
|
2012-04-18 07:43:32 +00:00
|
|
|
mode: 'player',
|
2011-05-15 16:18:58 +00:00
|
|
|
out: 0,
|
|
|
|
results: [],
|
2013-02-15 05:17:49 +00:00
|
|
|
showInToOut: false,
|
2012-01-04 17:27:32 +00:00
|
|
|
state: 'default',
|
2011-05-15 16:18:58 +00:00
|
|
|
subtitles: [],
|
2012-04-18 07:43:32 +00:00
|
|
|
type: '',
|
2012-05-26 15:48:19 +00:00
|
|
|
width: 256
|
2011-05-15 16:18:58 +00:00
|
|
|
})
|
|
|
|
.options(options || {})
|
2012-05-28 19:35:41 +00:00
|
|
|
.update({
|
2013-07-13 21:03:05 +00:00
|
|
|
imageURL: function() {
|
|
|
|
self.$timeline.attr({src: self.options.imageURL});
|
|
|
|
},
|
2012-05-28 19:35:41 +00:00
|
|
|
'in': function() {
|
|
|
|
self.$selection.attr({
|
|
|
|
src: getImageURL('selection')
|
|
|
|
});
|
|
|
|
},
|
|
|
|
out: function() {
|
|
|
|
self.$selection.attr({
|
|
|
|
src: getImageURL('selection')
|
|
|
|
});
|
|
|
|
},
|
|
|
|
results: function() {
|
|
|
|
self.$results.attr({
|
|
|
|
src: getImageURL('results')
|
|
|
|
});
|
|
|
|
},
|
|
|
|
selection: function() {
|
|
|
|
self.$selection.attr({
|
|
|
|
src: getImageURL('selection')
|
|
|
|
});
|
|
|
|
},
|
|
|
|
subtitles: function() {
|
|
|
|
self.$subtitles.attr({
|
|
|
|
src: getImageURL('subtitles')
|
|
|
|
});
|
|
|
|
},
|
|
|
|
state: function() {
|
|
|
|
self.$selection.attr({
|
|
|
|
src: getImageURL('selection')
|
|
|
|
});
|
|
|
|
},
|
|
|
|
width: function() {
|
|
|
|
var width = self.options.width;
|
|
|
|
that.css({width: width + 'px'});
|
|
|
|
self.$results
|
|
|
|
.attr({src: getImageURL('results')})
|
|
|
|
.css({width: width + 'px'});
|
|
|
|
self.$selection
|
|
|
|
.attr({src: getImageURL('selection')})
|
|
|
|
.css({width: width + 'px'});
|
|
|
|
self.$subtitles.css({width: width + 'px'});
|
|
|
|
self.$timeline.css({width: width + 'px'});
|
|
|
|
}
|
|
|
|
})
|
2011-05-15 16:18:58 +00:00
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
|
|
|
width: self.options.width + 'px'
|
|
|
|
});
|
|
|
|
|
2013-02-15 05:17:49 +00:00
|
|
|
if (self.options.showInToOut) {
|
|
|
|
self.pixelsPerSecond = (
|
|
|
|
screen.width < 1024 ? 1024 : screen.width
|
|
|
|
) / self.options.duration;
|
|
|
|
}
|
|
|
|
self.images = Ox.isString(self.options.imageURL) ? 1
|
|
|
|
: Math.ceil(self.options.duration / 3600);
|
|
|
|
self.imageWidth = Ox.isString(self.options.imageURL) ? 1920
|
|
|
|
: self.options.showInToOut ? (
|
|
|
|
self.pixelsPerSecond <= 1
|
|
|
|
? Math.round(self.options.duration)
|
|
|
|
: Math.round(self.options.duration * 25)
|
|
|
|
)
|
|
|
|
: Math.round(self.options.duration);
|
|
|
|
self.height = self.options.mode == 'editor' ? 24 : 16;
|
|
|
|
self.imageHeight = self.options.mode == 'editor' ? 18 : 16;
|
|
|
|
self.imageTop = self.options.mode == 'editor' ? 3 : 0;
|
|
|
|
self.timelineTop = self.options.mode == 'editor' ? 4 : 0;
|
2012-12-28 16:59:34 +00:00
|
|
|
self.themeData = Ox.Theme.getThemeData();
|
2011-05-15 16:18:58 +00:00
|
|
|
|
2013-02-15 05:17:49 +00:00
|
|
|
that.css({height: self.height + 'px'});
|
2011-05-15 16:18:58 +00:00
|
|
|
|
2012-04-18 07:43:32 +00:00
|
|
|
if (Ox.isString(self.options.imageURL)) {
|
2011-05-17 10:00:49 +00:00
|
|
|
self.$timeline = $('<img>')
|
|
|
|
.attr({
|
2012-04-18 07:43:32 +00:00
|
|
|
src: self.options.imageURL
|
2011-05-17 10:00:49 +00:00
|
|
|
})
|
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
2011-05-17 17:04:33 +00:00
|
|
|
top: self.timelineTop + 'px',
|
2011-05-17 10:00:49 +00:00
|
|
|
width: self.options.width + 'px',
|
2011-05-17 17:04:33 +00:00
|
|
|
height: '16px'
|
2011-05-17 10:00:49 +00:00
|
|
|
})
|
2012-06-15 13:20:07 +00:00
|
|
|
.appendTo(that);
|
2013-02-15 05:17:49 +00:00
|
|
|
} else if (self.options.showInToOut) {
|
|
|
|
self.$timeline = getClipTimeline()
|
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
|
|
|
top: self.timelineTop + 'px',
|
|
|
|
width: self.options.width + 'px',
|
|
|
|
height: '16px'
|
|
|
|
})
|
|
|
|
.appendTo(that);
|
2011-05-17 10:00:49 +00:00
|
|
|
} else {
|
|
|
|
Ox.loop(self.images, function(i) {
|
|
|
|
$('<img>')
|
|
|
|
.attr({
|
2012-04-18 07:43:32 +00:00
|
|
|
src: self.options.imageURL(self.options.type, i)
|
2011-05-17 10:00:49 +00:00
|
|
|
})
|
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
|
|
|
left: (i * 3600) + 'px',
|
2011-05-17 17:04:33 +00:00
|
|
|
top: self.timelineTop + 'px',
|
2012-06-15 15:20:17 +00:00
|
|
|
width: (i == self.images - 1 ? self.imageWidth % 3600 || 3600 : 3600) + 'px',
|
2011-05-17 17:04:33 +00:00
|
|
|
height: '16px'
|
2011-05-17 10:00:49 +00:00
|
|
|
})
|
2012-06-15 13:20:07 +00:00
|
|
|
.appendTo(that);
|
2011-05-15 16:18:58 +00:00
|
|
|
});
|
2011-05-17 10:00:49 +00:00
|
|
|
}
|
2011-05-15 16:18:58 +00:00
|
|
|
|
|
|
|
self.$subtitles = $('<img>')
|
|
|
|
.attr({
|
|
|
|
src: getImageURL('subtitles')
|
|
|
|
})
|
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
2011-05-17 10:00:49 +00:00
|
|
|
top: self.imageTop + 'px',
|
2011-05-15 16:18:58 +00:00
|
|
|
width: self.options.width + 'px',
|
2011-05-17 10:00:49 +00:00
|
|
|
height: self.imageHeight + 'px'
|
2011-05-15 16:18:58 +00:00
|
|
|
})
|
2012-06-26 16:21:39 +00:00
|
|
|
.appendTo(that);
|
2011-05-15 16:18:58 +00:00
|
|
|
|
|
|
|
self.$results = $('<img>')
|
|
|
|
.attr({
|
|
|
|
src: getImageURL('results')
|
|
|
|
})
|
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
2011-05-17 10:00:49 +00:00
|
|
|
top: self.imageTop + 'px',
|
2011-05-15 16:18:58 +00:00
|
|
|
width: self.options.width + 'px',
|
2011-05-17 10:00:49 +00:00
|
|
|
height: self.imageHeight + 'px'
|
2011-05-15 16:18:58 +00:00
|
|
|
})
|
2012-06-26 16:21:39 +00:00
|
|
|
.appendTo(that);
|
2011-05-15 16:18:58 +00:00
|
|
|
|
|
|
|
self.$selection = $('<img>')
|
|
|
|
.attr({
|
|
|
|
src: getImageURL('selection')
|
|
|
|
})
|
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
2011-05-17 10:00:49 +00:00
|
|
|
top: self.imageTop + 'px',
|
2011-05-15 16:18:58 +00:00
|
|
|
width: self.options.width + 'px',
|
2011-05-17 10:00:49 +00:00
|
|
|
height: self.imageHeight + 'px'
|
2011-05-15 16:18:58 +00:00
|
|
|
})
|
2012-06-26 16:21:39 +00:00
|
|
|
.appendTo(that);
|
2011-05-15 16:18:58 +00:00
|
|
|
|
2013-02-15 05:17:49 +00:00
|
|
|
function getClipTimeline() {
|
|
|
|
var $canvas, context, image,
|
|
|
|
firstTile, lastTile, tileHeight, tileOffset, tileWidth;
|
|
|
|
if (self.pixelsPerSecond <= 1) {
|
|
|
|
firstTile = Math.floor(self.options['in'] / 3600);
|
|
|
|
lastTile = Math.floor(self.options.out / 3600);
|
|
|
|
tileHeight = 16;
|
|
|
|
tileOffset = -Math.round(self.options['in'] % 3600);
|
|
|
|
tileWidth = 3600;
|
|
|
|
} else {
|
|
|
|
firstTile = Math.floor(self.options['in'] / 60);
|
|
|
|
lastTile = Math.floor(self.options.out / 60);
|
|
|
|
tileHeight = 64;
|
2013-02-15 05:51:17 +00:00
|
|
|
tileOffset = -Math.round(self.options['in'] % 60 * 25);
|
2013-02-15 05:17:49 +00:00
|
|
|
tileWidth = 1500;
|
|
|
|
}
|
|
|
|
$canvas = $('<canvas>').attr({
|
|
|
|
width: self.imageWidth,
|
|
|
|
height: tileHeight
|
|
|
|
});
|
|
|
|
context = $canvas[0].getContext('2d');
|
|
|
|
Ox.loop(firstTile, lastTile + 1, function(tileIndex) {
|
|
|
|
var $image = $('<img>')
|
|
|
|
.one({
|
|
|
|
load: function() {
|
|
|
|
context.drawImage(
|
|
|
|
$image[0],
|
|
|
|
tileOffset + (tileIndex - firstTile) * tileWidth,
|
|
|
|
0
|
|
|
|
);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.attr({
|
|
|
|
src: self.options.imageURL(tileHeight, tileIndex)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return $canvas;
|
|
|
|
}
|
|
|
|
|
2011-05-15 16:18:58 +00:00
|
|
|
function getImageURL(image, callback) {
|
2012-01-04 17:27:32 +00:00
|
|
|
var width = image == 'results' || image == 'selection'
|
|
|
|
? self.options.width : self.imageWidth,
|
2011-05-15 16:18:58 +00:00
|
|
|
height = self.imageHeight,
|
2013-02-15 05:17:49 +00:00
|
|
|
canvas = $('<canvas>').attr({
|
|
|
|
width: width,
|
|
|
|
height: height
|
|
|
|
})[0],
|
2011-05-15 16:18:58 +00:00
|
|
|
context = canvas.getContext('2d'),
|
|
|
|
imageData = context.createImageData(width, height),
|
|
|
|
data = imageData.data;
|
|
|
|
if (image == 'results') {
|
|
|
|
var top = 0,
|
|
|
|
bottom = height;
|
|
|
|
self.options.results.forEach(function(result) {
|
2011-05-16 07:03:37 +00:00
|
|
|
var left = Math.round(
|
2011-05-17 09:43:54 +00:00
|
|
|
result['in'] / self.options.duration * width
|
2011-05-16 07:03:37 +00:00
|
|
|
),
|
|
|
|
right = Math.round(
|
2011-05-17 09:43:54 +00:00
|
|
|
result.out / self.options.duration * width
|
2012-12-28 16:59:34 +00:00
|
|
|
) + 1,
|
|
|
|
rgb = self.themeData.videoTimelineResultGradient;
|
2011-05-15 16:18:58 +00:00
|
|
|
Ox.loop(left, right, function(x) {
|
|
|
|
Ox.loop(top, bottom, function(y) {
|
2012-04-18 07:43:32 +00:00
|
|
|
var alpha = self.options.mode == 'editor'
|
2012-02-01 05:21:29 +00:00
|
|
|
&& (y == top || y == bottom - 1) ? 255 : 128,
|
2012-12-28 16:59:34 +00:00
|
|
|
color = rgb[[2, 3, 6].indexOf(x % 4 + y % 4) > -1 ? 0 : 1],
|
2011-05-15 16:18:58 +00:00
|
|
|
index = x * 4 + y * 4 * width;
|
|
|
|
data[index] = color[0];
|
|
|
|
data[index + 1] = color[1];
|
|
|
|
data[index + 2] = color[2];
|
2012-01-04 09:50:07 +00:00
|
|
|
data[index + 3] = alpha;
|
2011-05-15 16:18:58 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2013-02-15 05:17:49 +00:00
|
|
|
} else if (
|
|
|
|
image == 'selection'
|
|
|
|
&& self.options.out > self.options['in']
|
|
|
|
&& !self.options.showInToOut
|
|
|
|
) {
|
2011-05-16 07:03:37 +00:00
|
|
|
var left = Math.round(
|
2011-05-17 09:43:54 +00:00
|
|
|
self.options['in'] / self.options.duration * width
|
2011-05-16 07:03:37 +00:00
|
|
|
),
|
|
|
|
right = Math.round(
|
2011-05-17 09:43:54 +00:00
|
|
|
self.options.out / self.options.duration * width
|
2011-05-16 07:03:37 +00:00
|
|
|
) + 1,
|
2013-02-12 06:28:52 +00:00
|
|
|
spans = self.options.invertHighlight
|
2013-02-12 06:40:49 +00:00
|
|
|
? [{left: 0, right: left}, {left: right, right: width}]
|
2013-02-12 06:28:52 +00:00
|
|
|
: [{left: left, right: right}],
|
2011-05-15 16:18:58 +00:00
|
|
|
top = 0,
|
|
|
|
bottom = height,
|
2012-12-28 16:59:34 +00:00
|
|
|
rgb = self.themeData[
|
|
|
|
self.options.state == 'editable' ? 'videoTimelineEditableGradient'
|
|
|
|
: self.options.state == 'editing' ? 'videoTimelineEditingGradient'
|
|
|
|
: self.options.state == 'selected' ? 'videoTimelineSelectedGradient'
|
|
|
|
: 'videoTimelineDefaultGradient'
|
|
|
|
];
|
2013-02-12 06:28:52 +00:00
|
|
|
spans.forEach(function(span) {
|
|
|
|
Ox.loop(span.left, span.right, function(x) {
|
|
|
|
Ox.loop(top, bottom, function(y) {
|
|
|
|
var alpha = self.options.mode == 'editor'
|
|
|
|
&& (y == top || y == bottom - 1) ? 255 : 128,
|
|
|
|
color = rgb[[2, 3, 6].indexOf(x % 4 + y % 4) > -1 ? 0 : 1],
|
|
|
|
index = x * 4 + y * 4 * width;
|
|
|
|
data[index] = color[0];
|
|
|
|
data[index + 1] = color[1];
|
|
|
|
data[index + 2] = color[2];
|
|
|
|
data[index + 3] = alpha;
|
|
|
|
});
|
2011-05-15 16:18:58 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
} else if (image == 'subtitles') {
|
2013-02-15 05:17:49 +00:00
|
|
|
var bottom = self.options.mode == 'editor' ? 15 : 14,
|
|
|
|
offset = self.options.showInToOut ? (
|
|
|
|
self.pixelsPerSecond <= 1
|
|
|
|
? -self.options['in']
|
|
|
|
: -self.options['in'] * 25
|
|
|
|
) : 0,
|
|
|
|
subtitles = self.options.showInToOut
|
|
|
|
? self.options.subtitles.filter(function(subtitle) {
|
|
|
|
return (
|
|
|
|
subtitle['in'] >= self.options['in']
|
|
|
|
&& subtitle['in'] <= self.options.out
|
|
|
|
) || (
|
|
|
|
subtitle.out >= self.options['in']
|
|
|
|
&& subtitle.out <= self.options.out
|
|
|
|
) || (
|
|
|
|
subtitle['in'] < self.options['in']
|
|
|
|
&& subtitle.out > self.options.out
|
|
|
|
)
|
|
|
|
})
|
|
|
|
: self.options.subtitles;
|
|
|
|
subtitles.forEach(function(subtitle) {
|
2011-05-17 09:43:54 +00:00
|
|
|
var left = Math.round(
|
|
|
|
subtitle['in'] / self.options.duration * self.imageWidth
|
2013-02-15 05:17:49 +00:00
|
|
|
) + offset,
|
2011-05-17 09:43:54 +00:00
|
|
|
right = Math.round(
|
|
|
|
subtitle.out / self.options.duration * self.imageWidth
|
2013-02-15 05:17:49 +00:00
|
|
|
) + offset + 1,
|
2012-01-04 09:50:07 +00:00
|
|
|
top = bottom - subtitle.text.split('\n').length - 2;
|
2011-05-15 16:18:58 +00:00
|
|
|
Ox.loop(left, right, function(x) {
|
|
|
|
Ox.loop(top, bottom, function(y) {
|
2012-01-04 09:50:07 +00:00
|
|
|
var alpha = 128,
|
|
|
|
color = (y == top || y == bottom - 1) ? [0, 0, 0] : [255, 255, 255],
|
2011-05-15 16:18:58 +00:00
|
|
|
index = x * 4 + y * 4 * width;
|
|
|
|
data[index] = color[0];
|
|
|
|
data[index + 1] = color[1];
|
|
|
|
data[index + 2] = color[2];
|
2012-02-19 07:41:19 +00:00
|
|
|
data[index + 3] = alpha;
|
2011-05-15 16:18:58 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2011-05-17 10:00:49 +00:00
|
|
|
context.putImageData(imageData, 0, 0);
|
|
|
|
return canvas.toDataURL();
|
2011-05-15 16:18:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return that;
|
|
|
|
|
2011-10-24 13:13:00 +00:00
|
|
|
};
|