summaryrefslogtreecommitdiffstats
path: root/chalk/colorspaces/ycbcr_u16
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2011-06-26 00:41:16 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2011-06-26 00:41:16 +0000
commit698569f8428ca088f764d704034a1330517b98c0 (patch)
treebf45be6946ebbbee9cce5a5bcf838f4c952d87e6 /chalk/colorspaces/ycbcr_u16
parent2785103a6bd4de55bd26d79e34d0fdd4b329a73a (diff)
downloadkoffice-698569f8428ca088f764d704034a1330517b98c0.tar.gz
koffice-698569f8428ca088f764d704034a1330517b98c0.zip
Finish rebranding of Krita as Chalk
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1238363 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'chalk/colorspaces/ycbcr_u16')
-rw-r--r--chalk/colorspaces/ycbcr_u16/Makefile.am27
-rw-r--r--chalk/colorspaces/ycbcr_u16/chalk_ycbcr_u16_plugin.desktop71
-rw-r--r--chalk/colorspaces/ycbcr_u16/kis_ycbcr_u16_colorspace.cc338
-rw-r--r--chalk/colorspaces/ycbcr_u16/kis_ycbcr_u16_colorspace.h144
-rw-r--r--chalk/colorspaces/ycbcr_u16/ycbcr_u16_plugin.cc60
-rw-r--r--chalk/colorspaces/ycbcr_u16/ycbcr_u16_plugin.h38
6 files changed, 678 insertions, 0 deletions
diff --git a/chalk/colorspaces/ycbcr_u16/Makefile.am b/chalk/colorspaces/ycbcr_u16/Makefile.am
new file mode 100644
index 00000000..d2e0aca3
--- /dev/null
+++ b/chalk/colorspaces/ycbcr_u16/Makefile.am
@@ -0,0 +1,27 @@
+# Install the desktop file needed to detect the plugin
+kde_services_DATA = chalk_ycbcr_u16_plugin.desktop
+
+INCLUDES = -I$(srcdir)/../../sdk \
+ -I$(srcdir)/../../chalkcolor/color_strategy/ \
+ -I$(srcdir)/../../chalkcolor/ \
+ $(KOFFICE_INCLUDES) \
+ $(all_includes)
+
+lib_LTLIBRARIES = libchalk_ycbcr_u16.la
+
+libchalk_ycbcr_u16_la_LDFLAGS = $(all_libraries)
+libchalk_ycbcr_u16_la_LIBADD = ../../chalkcolor/libchalkcolor.la
+
+# Install this plugin in the KDE modules directory
+kde_module_LTLIBRARIES = chalk_ycbcr_u16_plugin.la
+
+# Srcs for the plugin
+chalk_ycbcr_u16_plugin_la_SOURCES = ycbcr_u16_plugin.cc
+noinst_HEADERS = ycbcr_u16_plugin.h kis_ycbcr_u16_colorspace.h
+
+chalk_ycbcr_u16_plugin_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) $(LIB_QT) -lkdecore -lkdeui -lkjs -lkdefx -lkio -lkparts -llcms
+chalk_ycbcr_u16_plugin_la_LIBADD = libchalk_ycbcr_u16.la ../../chalkcolor/libchalkcolor.la
+
+METASOURCES = AUTO
+
+libchalk_ycbcr_u16_la_SOURCES = kis_ycbcr_u16_colorspace.cc
diff --git a/chalk/colorspaces/ycbcr_u16/chalk_ycbcr_u16_plugin.desktop b/chalk/colorspaces/ycbcr_u16/chalk_ycbcr_u16_plugin.desktop
new file mode 100644
index 00000000..eaa0c2a1
--- /dev/null
+++ b/chalk/colorspaces/ycbcr_u16/chalk_ycbcr_u16_plugin.desktop
@@ -0,0 +1,71 @@
+[Desktop Entry]
+Name=YCbCr Color Model (16-bit integer)
+Name[bg]=Цветови модел YCbCr (16 бита)
+Name[ca]=Model de color YCbCr (enters de 16 bits)
+Name[da]=YCbCr-farvemodel (16-bit heltal)
+Name[de]=YCbCr-Farbmodell (16-bit Ganzzahl)
+Name[el]=Χρωματικό μοντέλο YCbCr (16-bit ακέραιοι)
+Name[eo]=YCbCr-Kolormodelo (16-bita entjero)
+Name[es]=Modelo de color YCbCr (entero de 16 bits)
+Name[et]=YCbCr värvimudel (16-bitine täisarv)
+Name[fa]=مدل رنگ YCbCr )عدد صحیح ۱۶ بیتی(
+Name[fr]=Modèle de couleurs YCbCr (entiers 16 bits)
+Name[fy]=YCbCr-kleurmodel (16-bit integer)
+Name[gl]=Modelo de Cores YCbCr (inteiro de 16-bit)
+Name[hu]=YCbCr színmodell (16 bites egész)
+Name[it]=Modello di colore YCbCr (intero a 16 bit)
+Name[ja]=YCbCr カラーモデル (16 ビット整数)
+Name[km]=គំរូ​ពណ៌ CMYK (ចំនួន​គត់ ១៦ ប៊ីត)
+Name[lt]=YCbCr spalvų modelis (16-bitų sveikasis)
+Name[nb]=YCbCr-fargemodell (16-bit heltall)
+Name[nds]=YCbCr-Klöörmodell (16-Bit Heeltall)
+Name[ne]=वाईसी ी ी आर रङ मोडेल (१६-बिट इन्टिजर)
+Name[nl]=YCbCr-kleurmodel (16-bit integer)
+Name[pl]=Przestrzeń barw YCbCr (16-bitowa liczbowa całkowita)
+Name[pt]=Modelo de Cor YCbCr (inteiros de 16 bits)
+Name[pt_BR]=Modelo de Cor YCbCr (inteiros de 16 bits)
+Name[ru]=YCbCr (целое 16-бит)
+Name[sk]=Model farieb YCbCr (16-biové čísla)
+Name[sl]=Barvni model YCbCr (16-bitno celo število)
+Name[sr]=YCbCr модел боја (16-битно целобројно)
+Name[sr@Latn]=YCbCr model boja (16-bitno celobrojno)
+Name[sv]=YCbCr-färgmodell (16-bitars heltal)
+Name[uk]=Модель кольорів YCbCr (16-бітне ціле)
+Name[uz]=YCbCr rang usuli (16-bit butun)
+Name[uz@cyrillic]=YCbCr ранг усули (16-бит бутун)
+Name[zh_TW]=YCbCr 色彩模型 (16-bit 整數)
+Comment=Color model for 16-bit integer per channel YCbCr images
+Comment[bg]=Цветови модел за 16 битови YCbCr изображения
+Comment[ca]=Model de color d'enters de 16 bits per a canal d'imatges YCbCr
+Comment[da]=Farvemodel for 16-bit heltal pr kanal YCbCr-billeder
+Comment[de]=Farbmodell für 16-bit pro Kanal YCbCr-Bilder
+Comment[el]=Χρωματικό μοντέλο για 16-bit ακεραίους ανά κανάλι YCbCr εικόνες
+Comment[es]=Modelo de color de entero de 16 bits por canal para imágenes YCbCr
+Comment[et]=16-bitiste täisarvuliste kanalitega YCbCr-piltide värvimudel
+Comment[fa]=مدل رنگ برای عدد صحیح ۱۶ بیتی برای هر تصویر YCbCr مجرا
+Comment[fr]=Modèle de couleurs pour des images YCbCr à 16 bits par canal
+Comment[fy]=Kleurmodel foar16-bit/kanaal fan YCbCr-ôfbyldings
+Comment[gl]=Modelo de Cores para imaxes YCbCr de inteiro de 16-bit por canal
+Comment[hu]=Színmodell 16 bit/csatorna YCbCr képekhez
+Comment[it]=Modello di colore per immagini YCbCr a canale di 16 bit interi
+Comment[ja]=16 ビット整数/チャンネル YCbCr 画像のためのカラーモデル
+Comment[km]=គំរូ​ពណ៌​សម្រាប់​រូបភាព CMYK ចំនួនគត់ ១៦ ប៊ីត​ក្នុង​មួយ​ឆានែល
+Comment[nb]=Fargemodell for YCbCr-bilder med 16-bit heltall per kanal
+Comment[nds]=Klöörmodell för YCbCr-Biller mit 16-Bit Heeltall pro Kanaal
+Comment[ne]=प्रति च्यानल वाईसीबीसीआर छविहरूको १६-बिट इन्टिजरका लागि रङ मोडेल
+Comment[nl]=Kleurmodel voor 16-bit/kanaal van YCbCr-afbeeldingen
+Comment[pl]=Przestrzeń barw dla obrazków YCbCr z 16-bitowymi liczbami całkowitymi na kanał
+Comment[pt]=Modelo de cor para imagens YCbCr com 16 bits por canal
+Comment[pt_BR]=Modelo de cor para imagens YCbCr com 16 bits por canal
+Comment[ru]=Цветовое пространство YCbCr (целое 16-бит/канал)
+Comment[sk]=Model farieb pre YCbCr obrázky so 16 bitmi na kanál
+Comment[sl]=Barvni model za slike YCbCr s 16 biti/kanal
+Comment[sr]=Модел боја за YCbCr слике, 16-битно целобројно по каналу
+Comment[sr@Latn]=Model boja za YCbCr slike, 16-bitno celobrojno po kanalu
+Comment[sv]=Färgmodell för YCbCr-bilder med 16-bitars heltal per kanal
+Comment[uk]=Модель кольорів для зображень YCbCr з цілим 16-біт/канал
+Comment[zh_TW]=每色頻為 16-bit 的 YCbCr 圖片色彩模型
+ServiceTypes=Chalk/ColorSpace
+Type=Service
+X-KDE-Library=chalk_ycbcr_u16_plugin
+X-Chalk-Version=2
diff --git a/chalk/colorspaces/ycbcr_u16/kis_ycbcr_u16_colorspace.cc b/chalk/colorspaces/ycbcr_u16/kis_ycbcr_u16_colorspace.cc
new file mode 100644
index 00000000..d8ea896b
--- /dev/null
+++ b/chalk/colorspaces/ycbcr_u16/kis_ycbcr_u16_colorspace.cc
@@ -0,0 +1,338 @@
+/*
+ * Copyright (c) 2006 Cyrille Berger <cberger@cberger.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "kis_ycbcr_u16_colorspace.h"
+
+#include <tqimage.h>
+
+#include <kis_integer_maths.h>
+
+const TQ_INT32 MAX_CHANNEL_YCbCr = 3;
+const TQ_INT32 MAX_CHANNEL_YCbCrA = 4;
+
+KisYCbCrU16ColorSpace::KisYCbCrU16ColorSpace(KisColorSpaceFactoryRegistry* tqparent, KisProfile* /*p*/)
+ : KisU16BaseColorSpace(KisID("YCbCrAU16", i18n("YCbCr (16-bit integer/channel)")), TYPE_YCbCr_16, icSigYCbCrData, tqparent, 0)
+{
+ m_channels.push_back(new KisChannelInfo(i18n("Y"), "Y", PIXEL_Y * sizeof(TQ_UINT16), KisChannelInfo::COLOR, KisChannelInfo::UINT16, sizeof(TQ_UINT16)));
+ m_channels.push_back(new KisChannelInfo(i18n("Cb"), "Cb", PIXEL_Cb * sizeof(TQ_UINT16), KisChannelInfo::COLOR, KisChannelInfo::UINT16, sizeof(TQ_UINT16)));
+ m_channels.push_back(new KisChannelInfo(i18n("Cr"), "Cr", PIXEL_Cr * sizeof(TQ_UINT16), KisChannelInfo::COLOR, KisChannelInfo::UINT16, sizeof(TQ_UINT16)));
+ m_channels.push_back(new KisChannelInfo(i18n("Alpha"), "A", PIXEL_ALPHA * sizeof(TQ_UINT16), KisChannelInfo::ALPHA, KisChannelInfo::UINT16, sizeof(TQ_UINT16)));
+
+ m_alphaPos = PIXEL_ALPHA * sizeof(TQ_UINT16);
+ KisAbstractColorSpace::init();
+}
+
+
+KisYCbCrU16ColorSpace::~KisYCbCrU16ColorSpace()
+{
+}
+
+void KisYCbCrU16ColorSpace::setPixel(TQ_UINT8 *dst, TQ_UINT16 Y, TQ_UINT16 Cb, TQ_UINT16 Cr, TQ_UINT16 alpha) const
+{
+ Pixel *dstPixel = reinterpret_cast<Pixel *>(dst);
+
+ dstPixel->Y = Y;
+ dstPixel->Cb = Cb;
+ dstPixel->Cr = Cr;
+ dstPixel->alpha = alpha;
+}
+
+void KisYCbCrU16ColorSpace::getPixel(const TQ_UINT8 *src, TQ_UINT16 *Y, TQ_UINT16 *Cb, TQ_UINT16 *Cr, TQ_UINT16 *alpha) const
+{
+ const Pixel *srcPixel = reinterpret_cast<const Pixel *>(src);
+
+ *Y = srcPixel->Y;
+ *Cb = srcPixel->Cb;
+ *Cr = srcPixel->Cr;
+ *alpha = srcPixel->alpha;
+
+}
+
+void KisYCbCrU16ColorSpace::fromTQColor(const TQColor& c, TQ_UINT8 *dstU8, KisProfile * profile )
+{
+ if(getProfile())
+ {
+ KisU16BaseColorSpace::fromTQColor(c, dstU8, profile);
+ } else {
+ Pixel *dst = reinterpret_cast<Pixel *>(dstU8);
+ dst->Y = computeY( c.red(), c.green(), c.blue());
+ dst->Cb = computeCb( c.red(), c.green(), c.blue());
+ dst->Cr = computeCr( c.red(), c.green(), c.blue());
+ }
+}
+
+void KisYCbCrU16ColorSpace::fromTQColor(const TQColor& c, TQ_UINT8 opacity, TQ_UINT8 *dstU8, KisProfile * profile )
+{
+ if(getProfile())
+ {
+ KisU16BaseColorSpace::fromTQColor(c, opacity, dstU8, profile);
+ } else {
+ Pixel *dst = reinterpret_cast<Pixel *>(dstU8);
+ dst->Y = computeY( c.red(), c.green(), c.blue());
+ dst->Cb = computeCb( c.red(), c.green(), c.blue());
+ dst->Cr = computeCr( c.red(), c.green(), c.blue());
+ dst->alpha = opacity;
+ }
+}
+
+void KisYCbCrU16ColorSpace::toTQColor(const TQ_UINT8 *srcU8, TQColor *c, KisProfile * profile)
+{
+ if(getProfile())
+ {
+ KisU16BaseColorSpace::toTQColor(srcU8, c, profile);
+
+ } else {
+ const Pixel *src = reinterpret_cast<const Pixel *>(srcU8);
+ c->setRgb(computeRed(src->Y,src->Cb,src->Cr) >> 8, computeGreen(src->Y,src->Cb,src->Cr) >> 8, computeBlue(src->Y,src->Cb,src->Cr) >> 8);
+ }
+}
+
+void KisYCbCrU16ColorSpace::toTQColor(const TQ_UINT8 *srcU8, TQColor *c, TQ_UINT8 *opacity, KisProfile * profile)
+{
+ if(getProfile())
+ {
+ KisU16BaseColorSpace::toTQColor(srcU8, c, opacity, profile);
+ } else {
+ const Pixel *src = reinterpret_cast<const Pixel *>(srcU8);
+ c->setRgb(computeRed(src->Y,src->Cb,src->Cr) >> 8, computeGreen(src->Y,src->Cb,src->Cr) >> 8, computeBlue(src->Y,src->Cb,src->Cr) >> 8);
+ *opacity = src->alpha;
+ }
+}
+
+TQ_UINT8 KisYCbCrU16ColorSpace::difference(const TQ_UINT8 *src1U8, const TQ_UINT8 *src2U8)
+{
+ if(getProfile())
+ return KisU16BaseColorSpace::difference(src1U8, src2U8);
+ const Pixel *src1 = reinterpret_cast<const Pixel *>(src1U8);
+ const Pixel *src2 = reinterpret_cast<const Pixel *>(src2U8);
+
+ return TQMAX(TQABS(src2->Y - src1->Y), TQMAX(TQABS(src2->Cb - src1->Cb), TQABS(src2->Cr - src1->Cr))) >> 8;
+
+}
+
+void KisYCbCrU16ColorSpace::mixColors(const TQ_UINT8 **colors, const TQ_UINT8 *weights, TQ_UINT32 nColors, TQ_UINT8 *dst) const
+{
+ TQ_UINT16 totalY = 0, totalCb = 0, totalCr = 0, newAlpha = 0;
+
+ while (nColors--)
+ {
+ const Pixel *pixel = reinterpret_cast<const Pixel *>(*colors);
+
+ TQ_UINT16 alpha = pixel->alpha;
+ float alphaTimesWeight = alpha * *weights;
+
+ totalY += (TQ_UINT16)(pixel->Y * alphaTimesWeight);
+ totalCb += (TQ_UINT16)(pixel->Cb * alphaTimesWeight);
+ totalCr += (TQ_UINT16)(pixel->Cr * alphaTimesWeight);
+ newAlpha += (TQ_UINT16)(alphaTimesWeight);
+
+ weights++;
+ colors++;
+ }
+
+ Pixel *dstPixel = reinterpret_cast<Pixel *>(dst);
+
+ dstPixel->alpha = newAlpha;
+
+ if (newAlpha > 0) {
+ totalY = totalY / newAlpha;
+ totalCb = totalCb / newAlpha;
+ totalCr = totalCr / newAlpha;
+ }
+
+ dstPixel->Y = totalY;
+ dstPixel->Cb = totalCb;
+ dstPixel->Cr = totalCr;
+}
+
+TQValueVector<KisChannelInfo *> KisYCbCrU16ColorSpace::channels() const {
+ return m_channels;
+}
+
+TQ_UINT32 KisYCbCrU16ColorSpace::nChannels() const {
+ return MAX_CHANNEL_YCbCrA;
+}
+
+TQ_UINT32 KisYCbCrU16ColorSpace::nColorChannels() const {
+ return MAX_CHANNEL_YCbCr;
+}
+
+TQ_UINT32 KisYCbCrU16ColorSpace::pixelSize() const {
+ return MAX_CHANNEL_YCbCrA * sizeof(TQ_UINT16);
+}
+
+
+TQImage KisYCbCrU16ColorSpace::convertToTQImage(const TQ_UINT8 *data, TQ_INT32 width, TQ_INT32 height, KisProfile * dstProfile, TQ_INT32 renderingIntent, float exposure )
+{
+ if(getProfile())
+ return KisU16BaseColorSpace::convertToTQImage( data, width, height, dstProfile, renderingIntent, exposure);
+
+ TQImage img = TQImage(width, height, 32, 0, TQImage::LittleEndian);
+ img.setAlphaBuffer(true);
+
+ TQ_INT32 i = 0;
+ uchar *j = img.bits();
+
+ while ( i < width * height * MAX_CHANNEL_YCbCrA) {
+ TQ_UINT16 Y = *( data + i + PIXEL_Y );
+ TQ_UINT16 Cb = *( data + i + PIXEL_Cb );
+ TQ_UINT16 Cr = *( data + i + PIXEL_Cr );
+ *( j + 3) = *( data + i + PIXEL_ALPHA ) >> 8;
+ *( j + 2 ) = computeRed(Y,Cb,Cr) >> 8;
+ *( j + 1 ) = computeGreen(Y,Cb,Cr) >> 8;
+ *( j + 0 ) = computeBlue(Y,Cb,Cr) >> 8;
+ i += MAX_CHANNEL_YCbCrA;
+ j += 4;
+ }
+ return img;
+}
+
+
+void KisYCbCrU16ColorSpace::bitBlt(TQ_UINT8 *dst, TQ_INT32 dstRowStride, const TQ_UINT8 *src, TQ_INT32 srcRowStride, const TQ_UINT8 *srcAlphaMask, TQ_INT32 tqmaskRowStride, TQ_UINT8 opacity, TQ_INT32 rows, TQ_INT32 cols, const KisCompositeOp& op)
+{
+ switch (op.op()) {
+ case COMPOSITE_UNDEF:
+ // Undefined == no composition
+ break;
+ case COMPOSITE_OVER:
+ compositeOver(dst, dstRowStride, src, srcRowStride, srcAlphaMask, tqmaskRowStride, rows, cols, opacity);
+ break;
+ case COMPOSITE_COPY:
+ compositeCopy(dst, dstRowStride, src, srcRowStride, srcAlphaMask, tqmaskRowStride, rows, cols, opacity);
+ break;
+ case COMPOSITE_ERASE:
+ compositeErase(dst, dstRowStride, src, srcRowStride, srcAlphaMask, tqmaskRowStride, rows, cols, opacity);
+ break;
+ default:
+ break;
+ }
+}
+
+void KisYCbCrU16ColorSpace::compositeOver(TQ_UINT8 *dstRowStart, TQ_INT32 dstRowStride, const TQ_UINT8 *srcRowStart, TQ_INT32 srcRowStride, const TQ_UINT8 *tqmaskRowStart, TQ_INT32 tqmaskRowStride, TQ_INT32 rows, TQ_INT32 numColumns, TQ_UINT8 opacity)
+{
+ while (rows > 0) {
+
+ const TQ_UINT16 *src = reinterpret_cast<const TQ_UINT16 *>(srcRowStart);
+ TQ_UINT16 *dst = reinterpret_cast<TQ_UINT16 *>(dstRowStart);
+ const TQ_UINT8 *tqmask = tqmaskRowStart;
+ TQ_INT32 columns = numColumns;
+
+ while (columns > 0) {
+
+ TQ_UINT16 srcAlpha = src[PIXEL_ALPHA];
+
+ // apply the alphatqmask
+ if (tqmask != 0) {
+ TQ_UINT8 U8_tqmask = *tqmask;
+
+ if (U8_tqmask != OPACITY_OPAQUE) {
+ srcAlpha = UINT16_MULT(srcAlpha, UINT8_TO_UINT16(U8_tqmask));
+ }
+ tqmask++;
+ }
+
+ if (srcAlpha != U16_OPACITY_TRANSPARENT) {
+
+ if (opacity != OPACITY_OPAQUE) {
+ srcAlpha = UINT16_MULT(srcAlpha, opacity);
+ }
+
+ if (srcAlpha == U16_OPACITY_OPAQUE) {
+ memcpy(dst, src, MAX_CHANNEL_YCbCrA * sizeof(TQ_UINT16));
+ } else {
+ TQ_UINT16 dstAlpha = dst[PIXEL_ALPHA];
+
+ TQ_UINT16 srcBlend;
+
+ if (dstAlpha == U16_OPACITY_OPAQUE) {
+ srcBlend = srcAlpha;
+ } else {
+ TQ_UINT16 newAlpha = dstAlpha + UINT16_MULT(U16_OPACITY_OPAQUE - dstAlpha, srcAlpha);
+ dst[PIXEL_ALPHA] = newAlpha;
+
+ if (newAlpha != 0) {
+ srcBlend = UINT16_DIVIDE(srcAlpha, newAlpha);
+ } else {
+ srcBlend = srcAlpha;
+ }
+ }
+
+ if (srcBlend == U16_OPACITY_OPAQUE) {
+ memcpy(dst, src, MAX_CHANNEL_YCbCr * sizeof(TQ_UINT16));
+ } else {
+ dst[PIXEL_Y] = UINT16_BLEND(src[PIXEL_Y], dst[PIXEL_Y], srcBlend);
+ dst[PIXEL_Cb] = UINT16_BLEND(src[PIXEL_Cb], dst[PIXEL_Cb], srcBlend);
+ dst[PIXEL_Cr] = UINT16_BLEND(src[PIXEL_Cr], dst[PIXEL_Cr], srcBlend);
+ }
+ }
+ }
+
+ columns--;
+ src += MAX_CHANNEL_YCbCrA;
+ dst += MAX_CHANNEL_YCbCrA;
+ }
+
+ rows--;
+ srcRowStart += srcRowStride;
+ dstRowStart += dstRowStride;
+ if(tqmaskRowStart) {
+ tqmaskRowStart += tqmaskRowStride;
+ }
+ }
+}
+
+void KisYCbCrU16ColorSpace::compositeErase(TQ_UINT8 *dst, TQ_INT32 dstRowSize, const TQ_UINT8 *src, TQ_INT32 srcRowSize, const TQ_UINT8 *srcAlphaMask, TQ_INT32 tqmaskRowStride, TQ_INT32 rows, TQ_INT32 cols, TQ_UINT8 /*opacity*/)
+{
+ while (rows-- > 0)
+ {
+ const Pixel *s = reinterpret_cast<const Pixel *>(src);
+ Pixel *d = reinterpret_cast<Pixel *>(dst);
+ const TQ_UINT8 *tqmask = srcAlphaMask;
+
+ for (TQ_INT32 i = cols; i > 0; i--, s++, d++)
+ {
+ TQ_UINT16 srcAlpha = s->alpha;
+
+ // apply the alphatqmask
+ if (tqmask != 0) {
+ TQ_UINT8 U8_tqmask = *tqmask;
+
+ if (U8_tqmask != OPACITY_OPAQUE) {
+ srcAlpha = UINT16_BLEND(srcAlpha, U16_OPACITY_OPAQUE, UINT8_TO_UINT16(U8_tqmask));
+ }
+ tqmask++;
+ }
+ d->alpha = UINT16_MULT(srcAlpha, d->alpha);
+ }
+
+ dst += dstRowSize;
+ src += srcRowSize;
+ if(srcAlphaMask) {
+ srcAlphaMask += tqmaskRowStride;
+ }
+ }
+}
+
+KisCompositeOpList KisYCbCrU16ColorSpace::userVisiblecompositeOps() const
+{
+ KisCompositeOpList list;
+
+ list.append(KisCompositeOp(COMPOSITE_OVER));
+ return list;
+}
diff --git a/chalk/colorspaces/ycbcr_u16/kis_ycbcr_u16_colorspace.h b/chalk/colorspaces/ycbcr_u16/kis_ycbcr_u16_colorspace.h
new file mode 100644
index 00000000..69c499f2
--- /dev/null
+++ b/chalk/colorspaces/ycbcr_u16/kis_ycbcr_u16_colorspace.h
@@ -0,0 +1,144 @@
+/*
+ * Copyright (c) 2006 Cyrille Berger <cberger@cberger.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef KIS_YCBCR_U16_COLORSPACE_H
+#define KIS_YCBCR_U16_COLORSPACE_H
+
+#include <kis_u16_base_colorspace.h>
+
+#include <klocale.h>
+
+#define LUMA_RED 0.2989
+#define LUMA_GREEN 0.587
+#define LUMA_BLUE 0.114
+
+class KisYCbCrU16ColorSpace : public KisU16BaseColorSpace
+{
+ public:
+ KisYCbCrU16ColorSpace(KisColorSpaceFactoryRegistry* tqparent, KisProfile* p);
+ ~KisYCbCrU16ColorSpace();
+ virtual bool willDegrade(ColorSpaceIndependence )
+ {
+ return false;
+ };
+ public:
+ void setPixel(TQ_UINT8 *pixel, TQ_UINT16 Y, TQ_UINT16 Cb, TQ_UINT16 Cr, TQ_UINT16 alpha) const;
+ void getPixel(const TQ_UINT8 *pixel, TQ_UINT16 *Y, TQ_UINT16 *Cb, TQ_UINT16 *Cr, TQ_UINT16 *alpha) const;
+
+ virtual void fromTQColor(const TQColor& c, TQ_UINT8 *dst, KisProfile * profile = 0);
+ virtual void fromTQColor(const TQColor& c, TQ_UINT8 opacity, TQ_UINT8 *dst, KisProfile * profile = 0);
+
+ virtual void toTQColor(const TQ_UINT8 *src, TQColor *c, KisProfile * profile = 0);
+ virtual void toTQColor(const TQ_UINT8 *src, TQColor *c, TQ_UINT8 *opacity, KisProfile * profile = 0);
+
+ virtual TQ_UINT8 difference(const TQ_UINT8 *src1, const TQ_UINT8 *src2);
+ virtual void mixColors(const TQ_UINT8 **colors, const TQ_UINT8 *weights, TQ_UINT32 nColors, TQ_UINT8 *dst) const;
+
+ virtual TQValueVector<KisChannelInfo *> channels() const;
+ virtual TQ_UINT32 nChannels() const;
+ virtual TQ_UINT32 nColorChannels() const;
+ virtual TQ_UINT32 pixelSize() const;
+
+ virtual TQImage convertToTQImage(const TQ_UINT8 *data, TQ_INT32 width, TQ_INT32 height,
+ KisProfile * dstProfile,
+ TQ_INT32 renderingIntent,
+ float exposure = 0.0f);
+
+ virtual KisCompositeOpList userVisiblecompositeOps() const;
+
+ protected:
+
+ virtual void bitBlt(TQ_UINT8 *dst,
+ TQ_INT32 dstRowStride,
+ const TQ_UINT8 *src,
+ TQ_INT32 srcRowStride,
+ const TQ_UINT8 *srcAlphaMask,
+ TQ_INT32 tqmaskRowStride,
+ TQ_UINT8 opacity,
+ TQ_INT32 rows,
+ TQ_INT32 cols,
+ const KisCompositeOp& op);
+
+ void compositeOver(TQ_UINT8 *dst, TQ_INT32 dstRowStride, const TQ_UINT8 *src, TQ_INT32 srcRowStride, const TQ_UINT8 *tqmask, TQ_INT32 tqmaskRowStride, TQ_INT32 rows, TQ_INT32 columns, TQ_UINT8 opacity);
+ void compositeErase(TQ_UINT8 *dst, TQ_INT32 dstRowStride, const TQ_UINT8 *src, TQ_INT32 srcRowStride, const TQ_UINT8 *tqmask, TQ_INT32 tqmaskRowStride, TQ_INT32 rows, TQ_INT32 columns, TQ_UINT8 opacity);
+
+ private:
+#define CLAMP_TO_16BITCHANNEL(a) CLAMP(a, 0, TQ_UINT16_MAX)
+ inline TQ_UINT16 computeRed(TQ_UINT16 Y, TQ_UINT16 /*Cb*/, TQ_UINT16 Cr)
+ {
+ return (TQ_UINT16)( CLAMP_TO_16BITCHANNEL( (Cr - 32768)* (2-2*LUMA_RED) + Y ) );
+ }
+ inline TQ_UINT16 computeGreen(TQ_UINT16 Y, TQ_UINT16 Cb, TQ_UINT16 Cr)
+ {
+ return (TQ_UINT16)( CLAMP_TO_16BITCHANNEL( (Y - LUMA_BLUE * computeBlue(Y,Cb,Cr) - LUMA_RED * computeRed(Y,Cb,Cr) ) / LUMA_GREEN ) );
+ }
+ inline TQ_UINT16 computeBlue(TQ_UINT16 Y, TQ_UINT16 Cb, TQ_UINT16 /*Cr*/)
+ {
+ return (TQ_UINT16)( CLAMP_TO_16BITCHANNEL( (Cb - 32768)*(2 - 2 * LUMA_BLUE) + Y) );
+ }
+ inline TQ_UINT16 computeY( TQ_UINT16 r, TQ_UINT16 b, TQ_UINT16 g)
+ {
+ return (TQ_UINT16)( CLAMP_TO_16BITCHANNEL( LUMA_RED*r + LUMA_GREEN*g + LUMA_BLUE*b ) );
+ }
+ inline TQ_UINT16 computeCb( TQ_UINT16 r, TQ_UINT16 b, TQ_UINT16 g)
+ {
+ return (TQ_UINT16)( CLAMP_TO_16BITCHANNEL( (b - computeY(r,g,b))/(2-2*LUMA_BLUE) + 32768) );
+ }
+ inline TQ_UINT16 computeCr( TQ_UINT16 r, TQ_UINT16 b, TQ_UINT16 g)
+ {
+ return (TQ_UINT8)( CLAMP_TO_16BITCHANNEL( (r - computeY(r,g,b))/(2-2*LUMA_RED) + 32768) );
+ }
+#undef CLAMP_TO_16BITCHANNEL
+
+ static const TQ_UINT8 PIXEL_Y = 0;
+ static const TQ_UINT8 PIXEL_Cb = 1;
+ static const TQ_UINT8 PIXEL_Cr = 2;
+ static const TQ_UINT8 PIXEL_ALPHA = 3;
+
+ struct Pixel {
+ TQ_UINT16 Y;
+ TQ_UINT16 Cb;
+ TQ_UINT16 Cr;
+ TQ_UINT16 alpha;
+ };
+};
+
+class KisYCbCrU16ColorSpaceFactory : public KisColorSpaceFactory
+{
+ public:
+ /**
+ * Chalk definition for use in .kra files and internally: unchanging name +
+ * i18n'able description.
+ */
+ virtual KisID id() const { return KisID("YCbCrAU16", i18n("YCbCr (16-bit integer/channel)")); };
+
+ /**
+ * lcms colorspace type definition.
+ */
+ virtual TQ_UINT32 colorSpaceType() { return TYPE_YCbCr_16; };
+
+ virtual icColorSpaceSignature colorSpaceSignature() { return icSigYCbCrData; };
+
+ virtual KisColorSpace *createColorSpace(KisColorSpaceFactoryRegistry * tqparent, KisProfile *p) { return new KisYCbCrU16ColorSpace(tqparent, p); };
+
+ virtual TQString defaultProfile() { return ""; };
+};
+
+
+#endif
diff --git a/chalk/colorspaces/ycbcr_u16/ycbcr_u16_plugin.cc b/chalk/colorspaces/ycbcr_u16/ycbcr_u16_plugin.cc
new file mode 100644
index 00000000..d948097b
--- /dev/null
+++ b/chalk/colorspaces/ycbcr_u16/ycbcr_u16_plugin.cc
@@ -0,0 +1,60 @@
+/*
+ * ycbcr_u16_plugin.cc -- Part of Chalk
+ *
+ * Copyright (c) 2006 Cyrille Berger <cberger@cberger.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include <kinstance.h>
+#include <kgenericfactory.h>
+#include <kdebug.h>
+
+#include <kis_debug_areas.h>
+#include <kis_colorspace_factory_registry.h>
+#include <kis_basic_histogram_producers.h>
+#include <kis_debug_areas.h>
+#include "ycbcr_u16_plugin.h"
+#include "kis_ycbcr_u16_colorspace.h"
+
+typedef KGenericFactory<YCbCrU16Plugin> YCbCrU16PluginFactory;
+K_EXPORT_COMPONENT_FACTORY( chalk_ycbcr_u16_plugin, YCbCrU16PluginFactory( "chalk" ) )
+
+
+YCbCrU16Plugin::YCbCrU16Plugin(TQObject *tqparent, const char *name, const TQStringList &)
+ : KParts::Plugin(tqparent, name)
+{
+ setInstance(YCbCrU16PluginFactory::instance());
+
+ if ( tqparent->inherits("KisColorSpaceFactoryRegistry") )
+ {
+ KisColorSpaceFactoryRegistry * f = dynamic_cast<KisColorSpaceFactoryRegistry*>( tqparent );
+
+ KisColorSpace * colorSpaceYCbCrU16 = new KisYCbCrU16ColorSpace(f, 0);
+ KisColorSpaceFactory * csf = new KisYCbCrU16ColorSpaceFactory();
+ Q_CHECK_PTR(colorSpaceYCbCrU16);
+ f->add(csf);
+ KisHistogramProducerFactoryRegistry::instance()->add(
+ new KisBasicHistogramProducerFactory<KisBasicU16HistogramProducer>
+ (KisID("YCbCr16HISTO", i18n("YCbCr16")), colorSpaceYCbCrU16) );
+ }
+
+}
+
+YCbCrU16Plugin::~YCbCrU16Plugin()
+{
+}
+
+#include "ycbcr_u16_plugin.moc"
diff --git a/chalk/colorspaces/ycbcr_u16/ycbcr_u16_plugin.h b/chalk/colorspaces/ycbcr_u16/ycbcr_u16_plugin.h
new file mode 100644
index 00000000..ceb8ec6f
--- /dev/null
+++ b/chalk/colorspaces/ycbcr_u16/ycbcr_u16_plugin.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2006 Cyrille Berger <cberger@cberger.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef YCBCR_U16_PLUGIN_H_
+#define YCBCR_U16_PLUGIN_H_
+
+#include <kparts/plugin.h>
+
+/**
+ * A plugin wrapper around the YCbCr U16 colour space strategy.
+ */
+class YCbCrU16Plugin : public KParts::Plugin
+{
+ Q_OBJECT
+ TQ_OBJECT
+public:
+ YCbCrU16Plugin(TQObject *tqparent, const char *name, const TQStringList &);
+ virtual ~YCbCrU16Plugin();
+
+};
+
+
+#endif // YCBCR_U16_PLUGIN_H_