VideoModel

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