KOffice – TDE office suite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

kis_filter_strategy.h 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Copyright (c) 2004 Michael Thaler <michael.thaler@physik.tu-muenchen.de>
  3. * Copyright (c) 2005 Casper Boemann <cbr@boemann.dk>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. */
  19. #ifndef KIS_FILTER_STRATEGY_H_
  20. #define KIS_FILTER_STRATEGY_H_
  21. #include <tdelocale.h>
  22. #include "kis_types.h"
  23. #include "kis_generic_registry.h"
  24. #include "kis_id.h"
  25. class KisFilterStrategy
  26. {
  27. public:
  28. KisFilterStrategy(KisID id) : m_id(id) {}
  29. virtual ~KisFilterStrategy() {}
  30. KisID id() {return m_id;};
  31. virtual double valueAt(double /*t*/) const {return 0;};
  32. virtual TQ_UINT32 intValueAt(TQ_INT32 t) const {return TQ_UINT32(255*valueAt(t/256.0));};
  33. double support() { return supportVal;};
  34. TQ_UINT32 intSupport() { return intSupportVal;};
  35. virtual bool boxSpecial() { return false;};
  36. protected:
  37. double supportVal;
  38. TQ_UINT32 intSupportVal;
  39. KisID m_id;
  40. };
  41. class KisHermiteFilterStrategy : public KisFilterStrategy
  42. {
  43. public:
  44. KisHermiteFilterStrategy() : KisFilterStrategy(KisID("Hermite", i18n("Hermite")))
  45. {supportVal = 1.0; intSupportVal = 256;}
  46. virtual ~KisHermiteFilterStrategy() {}
  47. virtual TQ_UINT32 intValueAt(TQ_INT32 t) const;
  48. virtual double valueAt(double t) const;
  49. };
  50. class KisCubicFilterStrategy : public KisFilterStrategy
  51. {
  52. public:
  53. KisCubicFilterStrategy() : KisFilterStrategy(KisID("Bicubic", i18n("Bicubic")))
  54. {supportVal = 1.0; intSupportVal = 256;}
  55. virtual ~KisCubicFilterStrategy() {}
  56. virtual TQ_UINT32 intValueAt(TQ_INT32 t) const;
  57. virtual double valueAt(double t) const;
  58. };
  59. class KisBoxFilterStrategy : public KisFilterStrategy
  60. {
  61. public:
  62. KisBoxFilterStrategy() : KisFilterStrategy(KisID("Box", i18n("Box")))
  63. {supportVal = 0.5; intSupportVal = 128;}
  64. virtual ~KisBoxFilterStrategy() {}
  65. virtual TQ_UINT32 intValueAt(TQ_INT32 t) const;
  66. virtual double valueAt(double t) const;
  67. virtual bool boxSpecial() { return true;};
  68. };
  69. class KisTriangleFilterStrategy : public KisFilterStrategy
  70. {
  71. public:
  72. KisTriangleFilterStrategy() : KisFilterStrategy(KisID("Triangle", i18n("Triangle aka (bi)linear")))
  73. {supportVal = 1.0; intSupportVal = 256;}
  74. virtual ~KisTriangleFilterStrategy() {}
  75. virtual TQ_UINT32 intValueAt(TQ_INT32 t) const;
  76. virtual double valueAt(double t) const;
  77. };
  78. class KisBellFilterStrategy : public KisFilterStrategy
  79. {
  80. public:
  81. KisBellFilterStrategy() : KisFilterStrategy(KisID("Bell", i18n("Bell")))
  82. {supportVal = 1.5; intSupportVal = 128+256;}
  83. virtual ~KisBellFilterStrategy() {}
  84. virtual double valueAt(double t) const;
  85. };
  86. class KisBSplineFilterStrategy : public KisFilterStrategy
  87. {
  88. public:
  89. KisBSplineFilterStrategy() : KisFilterStrategy(KisID("BSpline", i18n("BSpline")))
  90. {supportVal = 2.0; intSupportVal = 512;}
  91. virtual ~KisBSplineFilterStrategy() {}
  92. virtual double valueAt(double t) const;
  93. };
  94. class KisLanczos3FilterStrategy : public KisFilterStrategy
  95. {
  96. public:
  97. KisLanczos3FilterStrategy() : KisFilterStrategy(KisID("Lanczos3", i18n("Lanczos3")))
  98. {supportVal = 3.0; intSupportVal = 768;}
  99. virtual ~KisLanczos3FilterStrategy() {}
  100. virtual double valueAt(double t) const;
  101. private:
  102. double sinc(double x) const;
  103. };
  104. class KisMitchellFilterStrategy : public KisFilterStrategy
  105. {
  106. public:
  107. KisMitchellFilterStrategy() : KisFilterStrategy(KisID("Mitchell", i18n("Mitchell")))
  108. {supportVal = 2.0; intSupportVal = 256;}
  109. virtual ~KisMitchellFilterStrategy() {}
  110. virtual double valueAt(double t) const;
  111. };
  112. class KisFilterStrategyRegistry : public KisGenericRegistry<KisFilterStrategy *>
  113. {
  114. public:
  115. virtual ~KisFilterStrategyRegistry();
  116. static KisFilterStrategyRegistry* instance();
  117. private:
  118. KisFilterStrategyRegistry();
  119. KisFilterStrategyRegistry(const KisFilterStrategyRegistry&);
  120. KisFilterStrategyRegistry operator=(const KisFilterStrategyRegistry&);
  121. private:
  122. static KisFilterStrategyRegistry *m_singleton;
  123. };
  124. #endif // KIS_FILTER_STRATEGY_H_