/lib/utils/mixers.js

https://github.com/ajanthanm/cssfilterlab · JavaScript · 59 lines · 37 code · 7 blank · 15 comment · 3 complexity · 058ae4c648281320f4ba48736216d602 MD5 · raw file

  1. /*
  2. * Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. (function(){
  17. var mixers = {
  18. mixNumber: function(a, b, t) {
  19. return a * (1 - t) + b * t;
  20. },
  21. mixVector: function(a, b, t) {
  22. var r = [];
  23. for (var i=0; i<a.length; ++i)
  24. r.push(mixers.mixNumber(a[i], b[i], t));
  25. return r;
  26. },
  27. mixVectorOfVectors: function(a, b, t) {
  28. var r = [];
  29. for (var i=0; i < a.length; ++i) {
  30. var row = []; r.push(row);
  31. var l2 = a[i].length;
  32. for (var j=0; j < l2; ++j)
  33. row.push(Global.mixers.mixVector(a[i][j], b[i][j], t));
  34. }
  35. return r;
  36. },
  37. mixHash: function(fn) {
  38. var mixFn = Global.mixers[fn];
  39. return function(a, b, t) {
  40. var r = {};
  41. $.each(a, function(key, valueA) {
  42. r[key] = mixFn(valueA, b[key], t);
  43. });
  44. return r;
  45. }
  46. },
  47. dontMix: function(a, b, t) {
  48. return a;
  49. }
  50. };
  51. Global.mixers = mixers;
  52. })();