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_ycbcr_u8_colorspace.h 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Copyright (c) 2006 Cyrille Berger <cberger@cberger.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17. * Boston, MA 02110-1301, USA.
  18. */
  19. #ifndef KIS_YCBCR_U8_COLORSPACE_H
  20. #define KIS_YCBCR_U8_COLORSPACE_H
  21. #include <kis_u8_base_colorspace.h>
  22. #include <tdelocale.h>
  23. #define LUMA_RED 0.2989
  24. #define LUMA_GREEN 0.587
  25. #define LUMA_BLUE 0.114
  26. class KisYCbCrU8ColorSpace : public KisU8BaseColorSpace
  27. {
  28. public:
  29. KisYCbCrU8ColorSpace(KisColorSpaceFactoryRegistry* parent, KisProfile* p);
  30. ~KisYCbCrU8ColorSpace();
  31. virtual bool willDegrade(ColorSpaceIndependence )
  32. {
  33. return false;
  34. };
  35. public:
  36. void setPixel(TQ_UINT8 *pixel, TQ_UINT8 Y, TQ_UINT8 Cb, TQ_UINT8 Cr, TQ_UINT8 alpha) const;
  37. void getPixel(const TQ_UINT8 *pixel, TQ_UINT8 *Y, TQ_UINT8 *Cb, TQ_UINT8 *Cr, TQ_UINT8 *alpha) const;
  38. virtual void fromTQColor(const TQColor& c, TQ_UINT8 *dst, KisProfile * profile = 0);
  39. virtual void fromTQColor(const TQColor& c, TQ_UINT8 opacity, TQ_UINT8 *dst, KisProfile * profile = 0);
  40. virtual void toTQColor(const TQ_UINT8 *src, TQColor *c, KisProfile * profile = 0);
  41. virtual void toTQColor(const TQ_UINT8 *src, TQColor *c, TQ_UINT8 *opacity, KisProfile * profile = 0);
  42. virtual TQ_UINT8 difference(const TQ_UINT8 *src1, const TQ_UINT8 *src2);
  43. virtual void mixColors(const TQ_UINT8 **colors, const TQ_UINT8 *weights, TQ_UINT32 nColors, TQ_UINT8 *dst) const;
  44. virtual TQValueVector<KisChannelInfo *> channels() const;
  45. virtual TQ_UINT32 nChannels() const;
  46. virtual TQ_UINT32 nColorChannels() const;
  47. virtual TQ_UINT32 pixelSize() const;
  48. virtual TQImage convertToTQImage(const TQ_UINT8 *data, TQ_INT32 width, TQ_INT32 height,
  49. KisProfile * dstProfile,
  50. TQ_INT32 renderingIntent,
  51. float exposure = 0.0f);
  52. virtual KisCompositeOpList userVisiblecompositeOps() const;
  53. protected:
  54. virtual void bitBlt(TQ_UINT8 *dst,
  55. TQ_INT32 dstRowStride,
  56. const TQ_UINT8 *src,
  57. TQ_INT32 srcRowStride,
  58. const TQ_UINT8 *srcAlphaMask,
  59. TQ_INT32 maskRowStride,
  60. TQ_UINT8 opacity,
  61. TQ_INT32 rows,
  62. TQ_INT32 cols,
  63. const KisCompositeOp& op);
  64. void compositeOver(TQ_UINT8 *dst, TQ_INT32 dstRowStride, const TQ_UINT8 *src, TQ_INT32 srcRowStride, const TQ_UINT8 *mask, TQ_INT32 maskRowStride, TQ_INT32 rows, TQ_INT32 columns, TQ_UINT8 opacity);
  65. void compositeErase(TQ_UINT8 *dst, TQ_INT32 dstRowStride, const TQ_UINT8 *src, TQ_INT32 srcRowStride, const TQ_UINT8 *mask, TQ_INT32 maskRowStride, TQ_INT32 rows, TQ_INT32 columns, TQ_UINT8 opacity);
  66. void compositeCopy(TQ_UINT8 *dst, TQ_INT32 dstRowStride, const TQ_UINT8 *src, TQ_INT32 srcRowStride, const TQ_UINT8 *mask, TQ_INT32 maskRowStride, TQ_INT32 rows, TQ_INT32 columns, TQ_UINT8 opacity);
  67. private:
  68. #define CLAMP_TO_8BITCHANNEL(a) CLAMP(a, 0, TQ_UINT8_MAX)
  69. inline TQ_UINT8 computeRed(TQ_UINT8 Y, TQ_UINT8 /*Cb*/, TQ_UINT8 Cr)
  70. {
  71. return (TQ_UINT8)( CLAMP_TO_8BITCHANNEL( (Cr - 128)* (2-2*LUMA_RED) + Y ) );
  72. }
  73. inline TQ_UINT8 computeGreen(TQ_UINT8 Y, TQ_UINT8 Cb, TQ_UINT8 Cr)
  74. {
  75. return (TQ_UINT8)( CLAMP_TO_8BITCHANNEL( (Y - LUMA_BLUE * computeBlue(Y,Cb,Cr) - LUMA_RED * computeRed(Y,Cb,Cr) ) / LUMA_GREEN ) );
  76. }
  77. inline TQ_UINT8 computeBlue(TQ_UINT8 Y, TQ_UINT8 Cb, TQ_UINT8 /*Cr*/)
  78. {
  79. return (TQ_UINT8)( CLAMP_TO_8BITCHANNEL( (Cb - 128)*(2 - 2 * LUMA_BLUE) + Y) );
  80. }
  81. inline TQ_UINT8 computeY( TQ_UINT8 r, TQ_UINT8 b, TQ_UINT8 g)
  82. {
  83. return (TQ_UINT8)( CLAMP_TO_8BITCHANNEL( LUMA_RED*r + LUMA_GREEN*g + LUMA_BLUE*b ) );
  84. }
  85. inline TQ_UINT8 computeCb( TQ_UINT8 r, TQ_UINT8 b, TQ_UINT8 g)
  86. {
  87. return (TQ_UINT8)( CLAMP_TO_8BITCHANNEL( (b - computeY(r,g,b))/(2-2*LUMA_BLUE) + 128) );
  88. }
  89. inline TQ_UINT8 computeCr( TQ_UINT8 r, TQ_UINT8 b, TQ_UINT8 g)
  90. {
  91. return (TQ_UINT8)( CLAMP_TO_8BITCHANNEL( (r - computeY(r,g,b))/(2-2*LUMA_RED) + 128) );
  92. }
  93. #undef CLAMP_TO_8BITCHANNEL
  94. static const TQ_UINT8 PIXEL_Y = 0;
  95. static const TQ_UINT8 PIXEL_Cb = 1;
  96. static const TQ_UINT8 PIXEL_Cr = 2;
  97. static const TQ_UINT8 PIXEL_ALPHA = 3;
  98. struct Pixel {
  99. TQ_UINT8 Y;
  100. TQ_UINT8 Cb;
  101. TQ_UINT8 Cr;
  102. TQ_UINT8 alpha;
  103. };
  104. };
  105. class KisYCbCrU8ColorSpaceFactory : public KisColorSpaceFactory
  106. {
  107. public:
  108. /**
  109. * Chalk definition for use in .kra files and internally: unchanging name +
  110. * i18n'able description.
  111. */
  112. virtual KisID id() const { return KisID("YCbCrAU8", i18n("YCbCr (8-bit integer/channel)")); };
  113. /**
  114. * lcms colorspace type definition.
  115. */
  116. virtual TQ_UINT32 colorSpaceType() { return TYPE_YCbCr_8; };
  117. virtual icColorSpaceSignature colorSpaceSignature() { return icSigYCbCrData; };
  118. virtual KisColorSpace *createColorSpace(KisColorSpaceFactoryRegistry * parent, KisProfile *p) { return new KisYCbCrU8ColorSpace(parent, p); };
  119. virtual TQString defaultProfile() { return ""; };
  120. };
  121. #endif