36

VideoModel

Objective
  • Model
    • ClipModel
      • VideoModel

An instance of VideoModel is a data model which describes a video clipwith the following properties:

size
hflip
vflip
opacity
invert
contrast
saturate
brightness
grayscale
sepia
blur
  1. function VideoModel(clipname = null) {
  2.     ClipModel.call(this, clipname);
  3.  
  4.     this._value = {
  5.         size:   [VideoModel.defaultWidth, VideoModel.defaultHeight],
  6.         hflip:          VideoModel.defaultHFlip,
  7.         vflip:          VideoModel.defaultVFlip,
  8.         opacity:        VideoModel.defaultOpacity,
  9.         invert:         VideoModel.defaultInvert,
  10.         contrast:       VideoModel.defaultContrast,
  11.         saturate:       VideoModel.defaultSaturate,
  12.         brightness:     VideoModel.defaultBrightness,
  13.         grayscale:      VideoModel.defaultGrayscale,
  14.         sepia:          VideoModel.defaultSepia,
  15.         blur:           VideoModel.defaultBlur
  16.     };
  17. }
  18.  
  19. VideoModel.prototype = Object.create(ClipModel.prototype);
  20.  
  21. Object.defineProperty(VideoModel.prototype, 'constructor', { value: VideoModel, enumerable: false, writable: true });
  22.  
  23. VideoModel.defaultWidth = 480;
  24. VideoModel.defaultHeight = 270;
  25. VideoModel.defaultHFlip = false;
  26. VideoModel.defaultVFlip = false;
  27. VideoModel.defaultOpacity = 1;
  28. VideoModel.defaultInvert = 0;
  29. VideoModel.defaultContrast = 1;
  30. VideoModel.defaultSaturate = 1;
  31. VideoModel.defaultBrightness = 1;
  32. VideoModel.defaultGrayscale = false;
  33. VideoModel.defaultSepia = false;
  34. VideoModel.defaultBlur = false;
  35.  
  36. VideoModel.minWidth = 240;
  37. VideoModel.maxWidth = 1920;
  38. VideoModel.minHeight = 135;
  39. VideoModel.maxHeight = 1080;
  40. VideoModel.minOpacity = 0;
  41. VideoModel.maxOpacitye = 1;
  42. VideoModel.minInvert = 0;
  43. VideoModel.maxInvert = 1;
  44. VideoModel.minContrast = 0;
  45. VideoModel.maxContrast = 2;
  46. VideoModel.minSaturate = 0;
  47. VideoModel.maxSaturate = 2;
  48. VideoModel.minBrightness = 0;
  49. VideoModel.maxBrightness = 2;
  50.  
  51. VideoModel.prototype.validateValue = function(prop, val) {
  52.     if (prop == 'size')
  53.         return Array.isArray(val) && typeof val[0] === 'number' && typeof val[1] === 'number';
  54.  
  55.     if (prop == 'opacity')
  56.         return typeof val === 'number';
  57.  
  58.     if (prop == 'invert')
  59.         return typeof val === 'number';
  60.  
  61.     if (prop == 'contrast')
  62.         return typeof val === 'number';
  63.  
  64.     if (prop == 'saturate')
  65.         return typeof val === 'number';
  66.  
  67.     if (prop == 'brightness')
  68.         return typeof val === 'number';
  69.  
  70.     return true;
  71. };
  72.  
  73. VideoModel.prototype.normalizeValue = function(prop, val) {
  74.     if (prop == 'size') {
  75.         let [w, h] = val;
  76.  
  77.         if (w < VideoModel.minWidth)
  78.             w = VideoModel.minWidth;
  79.         else if (w > VideoModel.maxWidth)
  80.             w = VideoModel.maxWidth;
  81.  
  82.         if (h < VideoModel.minHeight)
  83.             h = VideoModel.minHeight;
  84.         else if (h > VideoModel.maxHeight)
  85.             h = VideoModel.maxHeight;
  86.  
  87.         val = [w, h];
  88.     }
  89.     else if (prop == 'hflip')
  90.         val = val ? true : false;
  91.     else if (prop == 'vflip')
  92.         val = val ? true : false;
  93.     else if (prop == 'grayscale')
  94.         val = val ? true : false;
  95.     else if (prop == 'sepia')
  96.         val = val ? true : false;
  97.     else if (prop == 'blur')
  98.         val = val ? true : false;
  99.     else if (prop == 'opacity') {
  100.         if (val < VideoModel.minOpacity)
  101.             val = VideoModel.minOpacity;
  102.         else if (val > VideoModel.maxOpacity)
  103.             val = VideoModel.maxOpacity;
  104.     }
  105.     else if (prop == 'invert') {
  106.         if (val < VideoModel.minInvert)
  107.             val = VideoModel.minInvert;
  108.         else if (val > VideoModel.maxInvert)
  109.             val = VideoModel.maxInvert;
  110.     }
  111.     else if (prop == 'contrast') {
  112.         if (val < VideoModel.minContrast)
  113.             val = VideoModel.minContrast;
  114.         else if (val > VideoModel.maxContrast)
  115.             val = VideoModel.maxContrast;
  116.     }
  117.     else if (prop == 'saturate') {
  118.         if (val < VideoModel.minSaturate)
  119.             val = VideoModel.minSaturate;
  120.         else if (val > VideoModel.maxSaturate)
  121.             val = VideoModel.maxSaturate;
  122.     }
  123.     else if (prop == 'brightness') {
  124.         if (val < VideoModel.minBrightness)
  125.             val = VideoModel.minBrightness;
  126.         else if (val > VideoModel.maxBrightness)
  127.             val = VideoModel.maxBrightness;
  128.     }
  129.  
  130.     return val;
  131. };
SEE ALSO

Model, ClipModel, ImageModel

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].