Commit 732d95c2 authored by Boudewijn Rempt's avatar Boudewijn Rempt

* FEATURE: add 16 bits gray and cmyk colorspaces

    * Removed unused brightnes/contrast methods from all colorspaces -- these are replaced
      by applyAdjustment.
    * Moved the popup buttons to a docker, made the paintop box a combobox and placed
      all of them in their own docker; let's see whether that works out. If you don't
      like this arrangement, shout at me.
    * Filled in the u8 and u16 base colorspaces with alpha/to/from qcolor and other
      common functionality.
    * Optimize bigendian display by using lcms for the byte-swapping
    * Made a generic toQImage that uses lcms.
    * Created a KisDlgLayerProperties dialog that shows the colorspace of the current
      layer and also used a .ui file, instead of a coded layout.
    * Added a createdcop.py script that generates the skeleton for a dcop interface
      class.
    * Messed about with dcop some more
    * Since an icc profiles works with any lcms colorspace, make the lcmscolorspace type
      private to kisprofile.
    * Added icons to the items in the paintop box
    * Fix cutting
    * Fix XYZ colorspace


svn path=/trunk/koffice/; revision=453234
parent 4809a68f
We really should use cvs2changelog or something like that...
We really should use cvs2changelog or something like that...
......@@ -42,7 +42,7 @@ libkritacore_la_SOURCES = kis_color.cc kis_paint_device.cc kis_layer.cc kis_pixe
kis_selection_manager.cc kis_scale_visitor.cc kis_transform_visitor.cc kis_rotate_visitor.cc \
kis_clipboard.cc kis_filter.cc kis_filter_registry.cc kis_filter_strategy.cc \
kis_composite_op.cc kis_part_layer.cc kis_filter_manager.cc kis_tool_manager.cc \
kis_paint_device_iface.cc kis_paint_device_iface.skel kis_histogram.cc
kis_paint_device_iface.cc kis_paint_device_iface.skel kis_histogram.cc #kis_color_iface.cc
noinst_HEADERS = kis_paint_device.h kis_layer.h kis_image.h kis_doc.h \
......@@ -53,7 +53,7 @@ noinst_HEADERS = kis_paint_device.h kis_layer.h kis_image.h kis_doc.h \
kis_matrix.h kis_selection_manager.h kis_scale_visitor.h kis_rotate_visitor.h \
kis_filter.h kis_filter_registry.h kis_composite_op.h kis_part_layer.h \
kis_filter_manager.h kis_tool_manager.h kis_pixel_op.h kis_histogram.h \
kis_paint_device_iface.h
kis_paint_device_iface.h #kis_color_iface.h
libkritacore_la_METASOURCES = AUTO
......
......@@ -10,7 +10,10 @@ libkiscolor_strategy_la_SOURCES = kis_abstract_colorspace.cc \
kis_colorspace_registry.cc \
kis_alpha_colorspace.cc \
kis_color_conversions.cc \
kis_xyz_colorspace.cc
kis_xyz_colorspace.cc \
kis_u8_base_colorspace.cc \
kis_u16_base_colorspace.cc
#kis_abstract_colorspace_iface.cc
libkiscolor_strategy_la_METASOURCES = AUTO
......
......@@ -209,8 +209,8 @@ public:
*
* XXX: We actually do not use the display yet, nor the paint device profile
*/
virtual void fromQColor(const QColor& c, Q_UINT8 *dst, KisProfileSP profile = 0);
virtual void fromQColor(const QColor& c, QUANTUM opacity, Q_UINT8 *dst, KisProfileSP profile = 0);
virtual void fromQColor(const QColor& c, Q_UINT8 *dst, KisProfileSP profile = 0) = 0;
virtual void fromQColor(const QColor& c, QUANTUM opacity, Q_UINT8 *dst, KisProfileSP profile = 0) = 0;
/**
* The toQColor methods take a byte array that is at least pixelSize() long
......@@ -220,14 +220,9 @@ public:
* XXX: We actually do not use the display yet, nor the paint device profile
*
*/
virtual void toQColor(const Q_UINT8 *src, QColor *c, KisProfileSP profile= 0 );
virtual void toQColor(const Q_UINT8 *src, QColor *c, QUANTUM *opacity, KisProfileSP profile = 0);
virtual void toQColor(const Q_UINT8 *src, QColor *c, KisProfileSP profile= 0 ) = 0;
virtual void toQColor(const Q_UINT8 *src, QColor *c, QUANTUM *opacity, KisProfileSP profile = 0) = 0;
/**
* Get the alpha value of the given pixel.
* XXX: Change to float/int to match setAlpha() when that changes.
*/
virtual void getAlpha(const Q_UINT8 *pixel, Q_UINT8 *alpha) = 0;
virtual KisPixelRO toKisPixelRO(const Q_UINT8 *src, KisProfileSP profile) = 0;
virtual KisPixel toKisPixel(Q_UINT8 *src, KisProfileSP profile) = 0;
......@@ -240,7 +235,10 @@ public:
/**
* Convert the pixels in data to (8-bit BGRA) QImage using the specified profiles.
* The pixels are supposed to be encoded in this color model.
* The pixels are supposed to be encoded in this color model. The default implementation
* will convert the pixels using either the profiles or the default profiles for the
* current colorstrategy and the RGBA colorstrategy. If that is not what you want,
* or if you think you can do better than lcms, reimplement this methods.
*
* @param data A pointer to a contiguous memory region containing width * height pixels
* @param width in pixels
......@@ -251,9 +249,9 @@ public:
* @param exposure The exposure setting for rendering a preview of a high dynamic range image.
*/
virtual QImage convertToQImage(const Q_UINT8 *data, Q_INT32 width, Q_INT32 height,
KisProfileSP srcProfile, KisProfileSP dstProfile,
Q_INT32 renderingIntent = INTENT_PERCEPTUAL,
float exposure = 0.0f) = 0;
KisProfileSP srcProfile, KisProfileSP dstProfile,
Q_INT32 renderingIntent = INTENT_PERCEPTUAL,
float exposure = 0.0f);
......@@ -264,55 +262,61 @@ public:
* Returns false if the conversion failed, true if it succeeded
*/
virtual bool convertPixelsTo(const Q_UINT8 * src, KisProfileSP srcProfile,
Q_UINT8 * dst, KisAbstractColorSpace * dstColorStrategy, KisProfileSP dstProfile,
Q_UINT32 numPixels,
Q_INT32 renderingIntent = INTENT_PERCEPTUAL);
Q_UINT8 * dst, KisAbstractColorSpace * dstColorStrategy, KisProfileSP dstProfile,
Q_UINT32 numPixels,
Q_INT32 renderingIntent = INTENT_PERCEPTUAL);
/**
* Convert the value of the channel at the specified position into
* an 8-bit value. The position is not the number of bytes, but
* the position of the channel as defined in the channel info list.
*/
Q_UINT8 scaleToU8(const Q_UINT8 * srcPixel, Q_INT32 channelPos);
virtual Q_UINT8 scaleToU8(const Q_UINT8 * srcPixel, Q_INT32 channelPos) = 0;
/**
* Convert the value of the channel at the specified position into
* a 16-bit value. This may be upscaling or downscaling, depending
* on the defined value of the channel
*/
Q_UINT8 scaleToU16(const Q_UINT8 * srcPixel, Q_INT32 channelPos);
virtual Q_UINT16 scaleToU16(const Q_UINT8 * srcPixel, Q_INT32 channelPos) = 0;
//============================== Manipulation fucntions ==========================//
//
//
// The manipulation functions have default implementations that _convert_ the pixel
// to a QColor and back. Reimplement these methods in your color strategy!
//
/**
* Set the alpha channel to the given value.
* Get the alpha value of the given pixel, downscaled to an 8-bit value.
*/
virtual Q_UINT8 getAlpha(const Q_UINT8 * pixel) = 0;
/**
* Set the alpha channel of the given run of pixels to the given value.
*
* pixels -- a pointer to the pixels that will have their alpha set to this value
* alpha -- XXX: This must become int or float
* alpha -- a downscaled 8-bit value for opacity
* nPixels -- the number of pixels
*
* XXX: Also add a function that modifies the current alpha with the given alpha, i.e., premultiply them?
*/
virtual void setAlpha(Q_UINT8 * pixels, Q_UINT8 alpha, Q_INT32 nPixels);
virtual void setAlpha(Q_UINT8 * pixels, Q_UINT8 alpha, Q_INT32 nPixels) = 0;
/**
* Applies the specified 8-bit alpha mask to the pixels. We assume that there are just
* as many alpha values as pixels but we do not check this.
* as many alpha values as pixels but we do not check this; the alpha values
* are assumed to be 8-bits.
*/
virtual void applyAlphaU8Mask(Q_UINT8 * pixels, Q_UINT8 * alpha, Q_INT32 nPixels);
virtual void applyAlphaU8Mask(Q_UINT8 * pixels, Q_UINT8 * alpha, Q_INT32 nPixels) = 0;
/**
* Applies the inverted 8-bit alpha mask to the pixels. We assume that there are just
* as many alpha values as pixels but we do not check this.
* as many alpha values as pixels but we do not check this; the alpha values
* are assumed to be 8-bits.
*/
virtual void applyInverseAlphaU8Mask(Q_UINT8 * pixels, Q_UINT8 * alpha, Q_INT32 nPixels);
virtual void applyInverseAlphaU8Mask(Q_UINT8 * pixels, Q_UINT8 * alpha, Q_INT32 nPixels) = 0;
/**
* Create an adjustment object for adjusting the brightness and contrast
......@@ -320,13 +324,13 @@ public:
*/
virtual KisColorAdjustment *createBrightnessContrastAdjustment(Q_UINT16 *transferValues);
/**
* Apply the adjustment created with onr of the other functions
*/
virtual void applyAdjustment(const Q_UINT8 *src, Q_UINT8 *dst, KisColorAdjustment *, Q_INT32 nPixels);
// XXX: What with alpha channels? YYY: Add an overloaded function that takes alpha into account?
/**
* Get the difference between 2 colors, normalized in the range (0,255)
......@@ -356,7 +360,7 @@ public:
* Calculate the intensity of the given pixel, scaled down to the range 0-255. XXX: Maybe this should be more flexible
*/
virtual Q_UINT8 intensity8(const Q_UINT8 * src) const;
/**
* Compose two arrays of pixels together. If source and target
* are not the same colour model, the source pixels will be
......@@ -376,6 +380,14 @@ public:
KisProfileSP srcProfile = 0,
KisProfileSP dstProfile = 0);
/**
* Return the default profile for this colorspace. This may be 0.
*/
KisProfileSP getDefaultProfile() { return m_defaultProfile; };
void setDefaultProfile(KisProfileSP profile) { m_defaultProfile = profile; };
//========================== END of Public API ========================================//
protected:
......@@ -402,21 +414,14 @@ protected:
Q_INT32 renderingIntent);
/**
* Return the default profile for this colorspace. This may be 0,
* if it's the kind of colorstrategy, like CMYK, that doesn't have
* a default profile.
*/
KisProfileSP getDefaultProfile() { return m_defaultProfile; };
void setDefaultProfile(KisProfileSP profile) { m_defaultProfile = profile; };
protected:
QStringList m_profileFilenames;
KisProfileSP m_defaultProfile;
Q_UINT8 * m_qcolordata; // A small buffer for conversion from and to qcolor.
Q_INT32 m_alphaPos;
Q_INT32 m_alphaSize;
Q_INT32 m_alphaPos; // The position in _bytes_ of the alpha channel
Q_INT32 m_alphaSize; // The width in _bytes_ of the alpha channel
cmsHTRANSFORM m_defaultToRGB;
cmsHTRANSFORM m_defaultFromRGB;
......@@ -427,7 +432,7 @@ protected:
KisProfileSP m_lastUsedDstProfile;
cmsHTRANSFORM m_lastUsedTransform;
vKisChannelInfoSP m_channels;
private:
......@@ -438,12 +443,10 @@ private:
typedef QMap<KisProfilePair, cmsHTRANSFORM> TransformMap;
TransformMap m_transforms; // Cache for existing transforms
KisAbstractColorSpace(const KisAbstractColorSpace&);
KisAbstractColorSpace& operator=(const KisAbstractColorSpace&);
Q_UINT8 * m_conversionCache;
Q_UINT32 m_conversionCacheSize;
QMemArray<Q_UINT8> m_conversionCache;
};
#endif // KIS_STRATEGY_COLORSPACE_H_
/*
* This file is part of the KDE project
*
* Copyright (C) 2005 Boudewijn Rempt <boud@valdyas.org>
*
* 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 <kapplication.h>
#include "kis_abstract_colorspace_iface.h"
#include "kis_abstract_colorspace.h"
#include <dcopclient.h>
KisAbstractColorSpaceIface::KisAbstractColorSpaceIface( KisAbstractColorSpace * parent )
: DCOPObject(parent->id().id().utf8())
{
m_parent = parent;
}
QString KisAbstractColorSpaceIface::name()
{
return m_parent->id().name();
}
QString KisAbstractColorSpaceIface::id()
{
return m_parent->id().id();
}
/* This file is part of the KDE project
* Copyright (C) 2005 Boudewijn Rempt <boud@valdyas.org>
*
* 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_ABSTRACT_COLORSPACE_IFACE_H
#define _KIS_ABSTRACT_COLORSPACE_IFACE_H
#include <dcopref.h>
#include <dcopobj.h>
#include <qstring.h>
class KisAbstractColorspace;
class KisAbstractColorspaceIface : virtual public DCOPObject
{
K_DCOP
public:
KisAbstractColorspaceIface( KisAbstractColorspace * parent );
k_dcop:
/**
* @returns the human readable, i18n'ed name of this colorspace
*/
QString name();
/**
* @returns the machine-usable, file-format id of this colorspace
*/
QString id();
private:
KisAbstractColorspace *m_parent;
};
#endif
......@@ -104,7 +104,7 @@ bool KisAlphaColorSpace::hasAlpha() const
{
return true; // Of course!
}
#if 0
// XXX: We convert the alpha space to create a mask for display in selection previews
// etc. No need to actually use the profiles here to create a mask image -- they don't
// need to be true color.
......@@ -141,6 +141,7 @@ QImage KisAlphaColorSpace::convertToQImage(const Q_UINT8 *data, Q_INT32 width, Q
}
return img;
}
#endif
bool KisAlphaColorSpace::convertPixelsTo(const Q_UINT8 *src, KisProfileSP /*srcProfile*/,
Q_UINT8 *dst, KisAbstractColorSpace * dstColorStrategy, KisProfileSP dstProfile,
......@@ -165,10 +166,6 @@ bool KisAlphaColorSpace::convertPixelsTo(const Q_UINT8 *src, KisProfileSP /*srcP
}
void KisAlphaColorSpace::adjustBrightnessContrast(const Q_UINT8 *src, Q_UINT8 *dst, Q_INT8 brightness, Q_INT8 contrast, Q_INT32 nPixels) const
{
//XXX does nothing for now
}
//XXX bitblt of ColorSpaceAlpha does not take mask into consideration as this is probably not
// used ever
......@@ -319,14 +316,14 @@ void KisAlphaColorSpace::convolveColors(Q_UINT8** colors, Q_INT32 * kernelValues
while (nColors--)
{
Q_INT32 weight = *kernelValues;
if (weight != 0) {
totalAlpha += (*colors)[PIXEL_MASK] * weight;
}
colors++;
kernelValues++;
}
if (channelFlags & FLAG_ALPHA) {
dst[PIXEL_MASK] = CLAMP((totalAlpha/ factor) + offset, 0, QUANTUM_MAX);
}
......
......@@ -47,7 +47,7 @@ public:
virtual KisPixelRO toKisPixelRO(const Q_UINT8 *src, KisProfileSP profile = 0) { return KisPixelRO (src, src, this, profile); }
virtual KisPixel toKisPixel(Q_UINT8 *src, KisProfileSP profile = 0) { return KisPixel (src, src, this, profile); }
virtual Q_INT8 difference(const Q_UINT8 *src1, const Q_UINT8 *src2);
virtual void mixColors(const Q_UINT8 **colors, const Q_UINT8 *weights, Q_UINT32 nColors, Q_UINT8 *dst) const;
......@@ -60,13 +60,12 @@ public:
virtual QString channelValueText(const Q_UINT8 *pixel, Q_UINT32 channelIndex) const;
virtual QString normalisedChannelValueText(const Q_UINT8 *pixel, Q_UINT32 channelIndex) const;
#if 0
virtual QImage convertToQImage(const Q_UINT8 *data, Q_INT32 width, Q_INT32 height,
KisProfileSP srcProfile, KisProfileSP dstProfile,
Q_INT32 renderingIntent = INTENT_PERCEPTUAL,
float exposure = 0.0f);
virtual void adjustBrightnessContrast(const Q_UINT8 *src, Q_UINT8 *dst, Q_INT8 brightness, Q_INT8 contrast, Q_INT32 nPixels) const;
#endif
virtual void convolveColors(Q_UINT8** colors, Q_INT32* kernelValues, enumChannelFlags channelFlags, Q_UINT8 *dst, Q_INT32 factor, Q_INT32 offset, Q_INT32 nColors) const;
protected:
......@@ -97,8 +96,6 @@ protected:
KisCompositeOpList userVisiblecompositeOps() const;
private:
vKisChannelInfoSP m_channels;
};
#endif // KIS_COLORSPACE_ALPHA_H_
......@@ -34,11 +34,12 @@ class KisF32BaseColorSpace : public KisAbstractColorSpace {
public:
KisF32BaseColorSpace(const KisID & id, DWORD cmType, icColorSpaceSignature colorSpaceSignature)
: KisAbstractColorSpace(id, cmType, colorSpaceSignature)
: KisAbstractColorSpace(id, cmType, colorSpaceSignature)
{
m_alphaSize = sizeof(float);
};
};
#endif // KIS_F32_BASE_COLORSPACE_H_
/*
* Copyright (c) 2005 Boudewijn Rempt <boud@valdyas.org>
*
* 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 "kdebug.h"
#include "kis_global.h"
#include "kis_abstract_colorspace.h"
#include "kis_pixel.h"
#include "kis_integer_maths.h"
#include "kis_u16_base_colorspace.h"
void KisU16BaseColorSpace::fromQColor(const QColor& color, Q_UINT8 *dst, KisProfileSP /*profile*/)
{
m_qcolordata[2] = color.red();
m_qcolordata[1] = color.green();
m_qcolordata[0] = color.blue();
// XXX: Use proper conversion from RGB with profiles
cmsDoTransform(m_defaultFromRGB, m_qcolordata, dst, 1);
if (hasAlpha())
setAlpha(dst, OPACITY_OPAQUE, 1);
}
void KisU16BaseColorSpace::fromQColor(const QColor& color, QUANTUM opacity, Q_UINT8 *dst, KisProfileSP /*profile*/)
{
m_qcolordata[2] = color.red();
m_qcolordata[1] = color.green();
m_qcolordata[0] = color.blue();
// XXX: Use proper conversion from RGB with profiles
cmsDoTransform(m_defaultFromRGB, m_qcolordata, dst, 1);
if (hasAlpha())
setAlpha(dst, opacity, 1);
}
void KisU16BaseColorSpace::toQColor(const Q_UINT8 *src, QColor *c, KisProfileSP /*profile*/)
{
// XXX: Properly convert using the rgb colorspace and the profile
cmsDoTransform(m_defaultToRGB, const_cast <Q_UINT8 *>(src), m_qcolordata, 1);
c -> setRgb(m_qcolordata[2], m_qcolordata[1], m_qcolordata[0]);
}
void KisU16BaseColorSpace::toQColor(const Q_UINT8 *src, QColor *c, QUANTUM *opacity, KisProfileSP /*profile*/)
{
// XXX: Properly convert using the rgb colorspace and the profile
cmsDoTransform(m_defaultToRGB, const_cast <Q_UINT8 *>(src), m_qcolordata, 1);
c -> setRgb(m_qcolordata[2], m_qcolordata[1], m_qcolordata[0]);
if (hasAlpha()) {
const Q_UINT16 *pixel = reinterpret_cast<const Q_UINT16 *>(src + m_alphaPos);
*opacity = UINT16_TO_UINT8(*pixel);
}
else
*opacity = OPACITY_OPAQUE;
}
Q_UINT8 KisU16BaseColorSpace::getAlpha(const Q_UINT8 * U8_pixel)
{
if (m_alphaPos < 0) return OPACITY_OPAQUE;
U8_pixel+= m_alphaPos;
const Q_UINT16 *pixel = reinterpret_cast<const Q_UINT16 *>(U8_pixel);
return UINT16_TO_UINT8(*pixel);
}
void KisU16BaseColorSpace::setAlpha(Q_UINT8 *U8_pixel, Q_UINT8 alpha, Q_INT32 nPixels)
{
if (m_alphaPos < 0) return;
Q_INT32 psize = pixelSize();
while (nPixels > 0) {
Q_UINT16 *pixel = reinterpret_cast<Q_UINT16 *>(U8_pixel + m_alphaPos);
pixel[0] = UINT8_TO_UINT16(alpha);
--nPixels;
U8_pixel += psize;
}
}
void KisU16BaseColorSpace::applyAlphaU8Mask(Q_UINT8 * U8_pixel, Q_UINT8 * alpha8, Q_INT32 nPixels)
{
if (m_alphaPos < 0) return;
Q_INT32 psize = pixelSize();
while (nPixels--) {
// Go to the alpha position (which is given in bytes from the start of the pixel,
// and cast to short.
Q_UINT16 *pixel = reinterpret_cast<Q_UINT16 *>(U8_pixel + m_alphaPos);
pixel[0] = UINT16_MULT(*(pixel + m_alphaPos), UINT8_TO_UINT16(*alpha8));
++alpha8;
U8_pixel += psize;
}
}
void KisU16BaseColorSpace::applyInverseAlphaU8Mask(Q_UINT8 * U8_pixels, Q_UINT8 * alpha8, Q_INT32 nPixels)
{
if (m_alphaPos < 0) return;
Q_INT32 psize = pixelSize();
while(nPixels--) {
Q_UINT16 s_alpha8;
Q_UINT32 p_alpha, s_alpha16;
Q_UINT16 *alpha = reinterpret_cast<Q_UINT16 *>(U8_pixels + m_alphaPos);
p_alpha = *(alpha);
s_alpha8 = MAX_SELECTED - *alpha8;
s_alpha16 = UINT8_TO_UINT16(s_alpha8);
// Go to the alpha position (which is given in bytes from the start of the pixel,
// and cast to short.
alpha[0] = UINT16_MULT(p_alpha, s_alpha16);
U8_pixels += psize;
++alpha8;
}
}
QString KisU16BaseColorSpace::channelValueText(const Q_UINT8 *U8_pixel, Q_UINT32 channelIndex) const
{
Q_ASSERT(channelIndex < (Q_UINT32)nChannels());
const Q_UINT16 *pixel = reinterpret_cast<const Q_UINT16 *>(U8_pixel);
Q_UINT32 channelPosition = channels()[channelIndex] -> pos() / sizeof(Q_UINT16);
return QString().setNum(pixel[channelPosition]);
}
QString KisU16BaseColorSpace::normalisedChannelValueText(const Q_UINT8 *U8_pixel, Q_UINT32 channelIndex) const
{
Q_ASSERT(channelIndex < (Q_UINT32)nChannels());
const Q_UINT16 *pixel = reinterpret_cast<const Q_UINT16 *>(U8_pixel);
Q_UINT32 channelPosition = m_channels[channelIndex] -> pos() / sizeof(Q_UINT16);
return QString().setNum(static_cast<float>(pixel[channelPosition]) / UINT16_MAX);
}
Q_UINT8 KisU16BaseColorSpace::scaleToU8(const Q_UINT8 * U8_pixel, Q_INT32 channelPos)
{
const Q_UINT16 *pixel = reinterpret_cast<const Q_UINT16 *>(U8_pixel);
return UINT16_TO_UINT8(pixel[channelPos]);
}
Q_UINT16 KisU16BaseColorSpace::scaleToU16(const Q_UINT8 * U8_pixel, Q_INT32 channelPos)
{
const Q_UINT16 *pixel = reinterpret_cast<const Q_UINT16 *>(U8_pixel);
return pixel[channelPos];
}
......@@ -24,9 +24,9 @@
#include "kis_integer_maths.h"
/**
* This is the base class for 16-bit/channel colorspaces. It defines
* a number of common methods, like handling 16-bit alpha and up-
* and down-scaling of channels.
* This is the base class for 16-bit/channel colorspaces with 16-bit alpha
* channels. It defines a number of common methods, like handling 16-bit alpha
* and up- and down-scaling of channels.
*/
class KisU16BaseColorSpace : public KisAbstractColorSpace {
......@@ -40,9 +40,26 @@ public:
KisU16BaseColorSpace(const KisID & id, DWORD cmType, icColorSpaceSignature colorSpaceSignature)
: KisAbstractColorSpace(id, cmType, colorSpaceSignature)
{
m_alphaSize = sizeof(Q_UINT16);
m_alphaSize = sizeof(Q_UINT16);
};
virtual void fromQColor(const QColor& c, Q_UINT8 *dst, KisProfileSP profile = 0);
virtual void fromQColor(const QColor& c, QUANTUM opacity, Q_UINT8 *dst, KisProfileSP profile = 0);
virtual void toQColor(const Q_UINT8 *src, QColor *c, KisProfileSP profile = 0);
virtual void toQColor(const Q_UINT8 *src, QColor *c, QUANTUM *opacity, KisProfileSP profile = 0);
virtual Q_UINT8 getAlpha(const Q_UINT8 * pixel);
virtual void setAlpha(Q_UINT8 * pixels, Q_UINT8 alpha, Q_INT32 nPixels);
virtual void applyAlphaU8Mask(Q_UINT8 * pixels, Q_UINT8 * alpha, Q_INT32 nPixels);
virtual void applyInverseAlphaU8Mask(Q_UINT8 * pixels, Q_UINT8 * alpha, Q_INT32 nPixels);
virtual QString channelValueText(const Q_UINT8 *pixel, Q_UINT32 channelIndex) const;
virtual QString normalisedChannelValueText(const Q_UINT8 *pixel, Q_UINT32 channelIndex) const;
virtual Q_UINT8 scaleToU8(const Q_UINT8 * srcPixel, Q_INT32 channelPos);
virtual Q_UINT16 scaleToU16(const Q_UINT8 * srcPixel, Q_INT32 channelPos);
};
#endif // KIS_U16_BASE_COLORSPACE_H_
/*
* Copyright (c) 2005 Boudewijn Rempt <boud@valdyas.org>
*
* 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.
*