Commit d5ee237a authored by Boudewijn Rempt's avatar Boudewijn Rempt

Something fucked up git-svn

I think these are the last changes that ought to be committed.

svn path=/trunk/koffice/; revision=971294
parent 7f430012
......@@ -88,6 +88,7 @@ set(kritaimage_LIB_SRCS
generator/kis_generator_layer.cpp
generator/kis_generator_registry.cpp
kis_adjustment_layer.cc
kis_background.cpp
kis_base_node.cpp
kis_base_processor.cpp
kis_basic_math_toolbox.cpp
......
/*
* Copyright (c) 2002 Patrick Julien <freak@codepimps.org>
* Copyright (c) 2009 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., 675 mass ave, cambridge, ma 02139, usa.
*/
#include "kis_global.h"
#include "kis_background.h"
inline uint UINT8_BLEND(uint a, uint b, uint alpha)
{
// Basically we do a*alpha + b*(1-alpha)
// However refactored to (a-b)*alpha + b since that saves a multiplication
// Signed arithmetic is needed since a-b might be negative
int c = ((int(a) - int(b)) * int(alpha)) >> 8;
return uint(c + b);
}
KisBackground::KisBackground(const QImage& patternTile)
: KisShared()
{
m_patternTile = patternTile;
}
KisBackground::~KisBackground()
{
}
const QImage& KisBackground::patternTile() const
{
return m_patternTile;
}
void KisBackground::paintBackground(QImage& image, const QRect& rc)
{
int imageLeftX = rc.x();
int imageTopY = rc.y();
int patternLeftX;
if (imageLeftX >= 0) {
patternLeftX = imageLeftX % PATTERN_WIDTH;
} else {
patternLeftX = (PATTERN_WIDTH - (-imageLeftX % PATTERN_WIDTH)) % PATTERN_WIDTH;
}
int patternTopY;
if (imageTopY >= 0) {
patternTopY = imageTopY % PATTERN_HEIGHT;
} else {
patternTopY = (PATTERN_HEIGHT - (-imageTopY % PATTERN_HEIGHT)) % PATTERN_HEIGHT;
}
int imageWidth = rc.width();
int imageHeight = rc.height();
int patternY = patternTopY;
for (int y = 0; y < imageHeight; y++)
{
QRgb *imagePixelPtr = reinterpret_cast<QRgb *>(image.scanLine(y));
const QRgb *patternScanLine = reinterpret_cast<const QRgb *>(m_patternTile.scanLine(patternY));
int patternX = patternLeftX;
for (int x = 0; x < imageWidth; x++)
{
QRgb imagePixel = *imagePixelPtr;
quint8 imagePixelAlpha = qAlpha(imagePixel);
if (imagePixelAlpha != 255) {
QRgb patternPixel = patternScanLine[patternX];
quint8 imageRed = UINT8_BLEND(qRed(imagePixel), qRed(patternPixel), imagePixelAlpha);
quint8 imageGreen = UINT8_BLEND(qGreen(imagePixel), qGreen(patternPixel), imagePixelAlpha);
quint8 imageBlue = UINT8_BLEND(qBlue(imagePixel), qBlue(patternPixel), imagePixelAlpha);
*imagePixelPtr = qRgba(imageRed, imageGreen, imageBlue, 255);
}
++imagePixelPtr;
++patternX;
if (patternX == PATTERN_WIDTH) {
patternX = 0;
}
}
++patternY;
if (patternY == PATTERN_HEIGHT) {
patternY = 0;
}
}
}
void KisBackground::paintBackground(QImage& img,
const QRect& scaledImageRect,
const QSize& scaledImageSize,
const QSize& imageSize)
{
if (scaledImageRect.isEmpty() || scaledImageSize.isEmpty() || imageSize.isEmpty()) {
return;
}
Q_ASSERT(img.size() == scaledImageRect.size());
if (img.size() != scaledImageRect.size()) {
return;
}
qint32 imageWidth = imageSize.width();
qint32 imageHeight = imageSize.height();
for (qint32 y = 0; y < scaledImageRect.height(); ++y) {
qint32 scaledY = scaledImageRect.y() + y;
qint32 srcY = (scaledY * imageHeight) / scaledImageSize.height();
qint32 patternY = srcY % PATTERN_HEIGHT;
QRgb *imagePixelPtr = reinterpret_cast<QRgb *>(img.scanLine(y));
const QRgb *patternScanLine = reinterpret_cast<const QRgb *>(m_patternTile.scanLine(patternY));
for (qint32 x = 0; x < scaledImageRect.width(); ++x) {
QRgb imagePixel = *imagePixelPtr;
quint8 imagePixelAlpha = qAlpha(imagePixel);
if (imagePixelAlpha != 255) {
qint32 scaledX = scaledImageRect.x() + x;
qint32 srcX = (scaledX * imageWidth) / scaledImageSize.width();
qint32 patternX = srcX % PATTERN_WIDTH;
QRgb patternPixel = patternScanLine[patternX];
quint8 imageRed = UINT8_BLEND(qRed(imagePixel), qRed(patternPixel), imagePixelAlpha);
quint8 imageGreen = UINT8_BLEND(qGreen(imagePixel), qGreen(patternPixel), imagePixelAlpha);
quint8 imageBlue = UINT8_BLEND(qBlue(imagePixel), qBlue(patternPixel), imagePixelAlpha);
*imagePixelPtr = qRgba(imageRed, imageGreen, imageBlue, 255);
}
++imagePixelPtr;
}
}
}
/*
* Copyright (c) 2002 Patrick Julien <freak@codepimps.org>
* Copyright (c) 2009 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., 675 mass ave, cambridge, ma 02139, usa.
*/
#ifndef KIS_BACKGROUND_H_
#define KIS_BACKGROUND_H_
#include <QImage>
#include <kis_shared.h>
#include <krita_export.h>
/**
* KisBackground paints the background pattern into the image,
* behind the image contents.
*
* Note: this is for things like fixed color, paper patterns,
* not for transparency checks.
*/
class KRITAIMAGE_EXPORT KisBackground : public KisShared {
public:
KisBackground(const QImage& patternTile);
virtual ~KisBackground();
// Paint the background pattern into the image, 'behind' the image
// contents. The coordinates are for the image's top-left corner
// in image space.
void paintBackground(QImage& image, const QRect& rc);
void paintBackground(QImage& img, const QRect& scaledImageRect, const QSize& scaledImageSize, const QSize& imageSize);
// Returns the pattern tile.
const QImage& patternTile() const;
protected:
KisBackground(KisBackground& rhs);
KisBackground& operator=(KisBackground& rhs);
static const int PATTERN_WIDTH = 64;
static const int PATTERN_HEIGHT = 64;
QImage m_patternTile;
};
#endif // KIS_BACKGROUND_H_
......@@ -44,6 +44,7 @@
#include "recorder/kis_action_recorder.h"
#include "kis_adjustment_layer.h"
#include "kis_annotation.h"
#include "kis_background.h"
#include "kis_change_profile_visitor.h"
#include "kis_colorspace_convert_visitor.h"
#include "kis_count_visitor.h"
......@@ -71,7 +72,7 @@
class KisImage::KisImagePrivate
{
public:
KisPaintDeviceSP backgroundPattern;
KisBackgroundSP backgroundPattern;
quint32 lockCount;
bool sizeChangedWhileLocked;
KisPerspectiveGrid* perspectiveGrid;
......@@ -257,16 +258,17 @@ void KisImage::setDeleselectedGlobalSelection(KisSelectionSP selection)
m_d->deselectedGlobalSelection = selection;
}
KisPaintDeviceSP KisImage::backgroundPattern() const
KisBackgroundSP KisImage::backgroundPattern() const
{
return m_d->backgroundPattern;
}
void KisImage::setBackgroundPattern(KisPaintDeviceSP image)
void KisImage::setBackgroundPattern(KisBackgroundSP background)
{
if (image != m_d->backgroundPattern) {
m_d->backgroundPattern = image;
m_d->rootLayer->setDirty();
qDebug() << "setBackgroundPattern() " << background << ", current " << m_d->backgroundPattern;
if (background != m_d->backgroundPattern) {
m_d->backgroundPattern = background;
emit sigImageUpdated(bounds());
}
}
......@@ -827,8 +829,10 @@ QImage KisImage::convertToQImage(qint32 x,
if (!dev) return QImage();
QImage img = dev->convertToQImage(const_cast<KoColorProfile*>(profile), x, y, w, h);
if (m_d->backgroundPattern) {
m_d->backgroundPattern->paintBackground(img, QRect(x, y, w, h));
}
if (!img.isNull()) {
#ifdef WORDS_BIGENDIAN
uchar * data = img.bits();
for (int i = 0; i < w * h; ++i) {
......@@ -852,82 +856,6 @@ QImage KisImage::convertToQImage(qint32 x,
}
QImage KisImage::convertToQImage(const QRect& r, const double xScale, const double yScale, const KoColorProfile *profile, KisSelectionSP mask)
{
Q_UNUSED(mask);
qDebug() << "KisImage::convertToQimage " << r << ", x scale " << xScale << ", y scale " << yScale;
#ifdef __GNUC__
#warning "KisImage::convertToQImage: Implement direct rendering of current mask onto scaled image pixels"
#endif
if (r.isEmpty()) {
return QImage();
}
quint32 pixelSize = colorSpace()->pixelSize();
QRect srcRect;
srcRect.setLeft(static_cast<int>(r.left() * xScale));
srcRect.setRight(static_cast<int>(ceil((r.right() + 1) * xScale)) - 1);
srcRect.setTop(static_cast<int>(r.top() * yScale));
srcRect.setBottom(static_cast<int>(ceil((r.bottom() + 1) * yScale)) - 1);
KisPaintDeviceSP mergedImage = m_d->rootLayer->projection();
quint8 *scaledImageData = new quint8[r.width() * r.height() * pixelSize];
quint8 *imageRow = new quint8[srcRect.width() * pixelSize];
const qint32 imageRowX = srcRect.x();
for (qint32 y = 0; y < r.height(); ++y) {
qint32 dstY = r.y() + y;
qint32 dstX = r.x();
qint32 srcY = int(dstY * yScale);
mergedImage->readBytes(imageRow, imageRowX, srcY, srcRect.width(), 1);
quint8 *dstPixel = scaledImageData + (y * r.width() * pixelSize);
quint32 columnsRemaining = r.width();
while (columnsRemaining > 0) {
qint32 srcX = int(dstX * xScale);
memcpy(dstPixel, imageRow + ((srcX - imageRowX) * pixelSize), pixelSize);
++dstX;
dstPixel += pixelSize;
--columnsRemaining;
}
}
delete [] imageRow;
QImage image = colorSpace()->convertToQImage(scaledImageData, r.width(), r.height(), const_cast<KoColorProfile*>(profile), KoColorConversionTransformation::IntentPerceptual);
delete [] scaledImageData;
#ifdef WORDS_BIGENDIAN
uchar * data = image.bits();
for (int i = 0; i < image.width() * image.height(); ++i) {
uchar r, g, b, a;
a = data[0];
b = data[1];
g = data[2];
r = data[3];
data[0] = r;
data[1] = g;
data[2] = b;
data[3] = a;
data += 4;
}
#endif
return image;
}
QImage KisImage::convertToQImage(const QRect& r, const QSize& scaledImageSize, const KoColorProfile *profile)
{
......@@ -987,6 +915,10 @@ QImage KisImage::convertToQImage(const QRect& r, const QSize& scaledImageSize, c
QImage image = colorSpace()->convertToQImage(scaledImageData, r.width(), r.height(), const_cast<KoColorProfile*>(profile), KoColorConversionTransformation::IntentPerceptual);
if (m_d->backgroundPattern) {
m_d->backgroundPattern->paintBackground(image, r, scaledImageSize, QSize(imageWidth, imageHeight));
}
delete [] scaledImageData;
#ifdef __BIG_ENDIAN__
......
......@@ -98,27 +98,6 @@ public:
qint32 height,
const KoColorProfile * profile);
/**
* Render the projection scaled onto a QImage. Use this when zoom
* < 100% to avoid color-adjusting pixels that will be filtered
* away anyway. It uses nearest-neighbour sampling, so the result
* is inaccurate and ugly. Set the option "fast_zoom" to true to
* make Krita use this.
*
* XXX: Implement the mask option to draw the mask onto the
* scaled image.
*
* @param r the source rectangle in pixels that needs to be drawn
* @param xScale the X axis scale (1.0 == 100%)
* @param yScale the Y axis scale (1.0 == 100%)
* @param projection the display profile
* @param mask the mask that will be rendered on top of the image
* @return a qimage containing the sampled image pixels
*/
QImage convertToQImage(const QRect& r,
const double xScale, const double yScale,
const KoColorProfile *profile,
KisSelectionSP mask = 0);
QImage convertToQImage(const QRect& r, const QSize& scaledImageSize, const KoColorProfile *profile);
......@@ -143,12 +122,12 @@ public:
/**
* @return the image that is used as background tile.
*/
KisPaintDeviceSP backgroundPattern() const;
KisBackgroundSP backgroundPattern() const;
/**
* Set a 64x64 tile for the background of the image.
*/
void setBackgroundPattern(KisPaintDeviceSP image);
void setBackgroundPattern(KisBackgroundSP image);
/**
* @return the global selection object or 0 if there is none. The
......
......@@ -126,6 +126,9 @@ typedef KisWeakSharedPtr<KisGroupLayer> KisGroupLayerWSP;
class KisSelection;
typedef KisSharedPtr<KisSelection> KisSelectionSP;
class KisBackground;
typedef KisSharedPtr<KisBackground> KisBackgroundSP;
class KisSelectionMask;
typedef KisSharedPtr<KisSelectionMask> KisSelectionMaskSP;
......
* enable Add, Remove, Reset buttons
* label the background patterns somehow
* add solid-color background patterns and use a categorized view for them
* add a custom-color background pattern
* add lots of nice patters (copy from MyPaint?)
......@@ -34,7 +34,7 @@
#include <kis_view2.h>
#include <kis_image.h>
#include <kis_paint_device.h>
#include <kis_background.h>
#include "dlg_backgrounds.h"
typedef KGenericFactory<Backgrounds> BackgroundsFactory;
......
......@@ -26,6 +26,7 @@
#include <kis_view2.h>
#include <kis_image.h>
#include <kis_paint_device.h>
#include <kis_background.h>
DlgBackgrounds::DlgBackgrounds(KisView2* view)
: KDialog(view)
......@@ -46,15 +47,19 @@ DlgBackgrounds::~DlgBackgrounds()
{
}
KisPaintDeviceSP DlgBackgrounds::background()
KisBackgroundSP DlgBackgrounds::background()
{
QImage img = m_page->lstBackgrounds->currentItem()->data(Qt::DecorationRole).value<QImage>();
KisPaintDeviceSP dev = new KisPaintDevice(m_view->image()->colorSpace());
dev->convertFromQImage(img, "");
return dev;
QListWidgetItem* item = m_page->lstBackgrounds->currentItem();
QString file = item->data(Qt::UserRole + 1).value<QString>();
if (file.isEmpty()) {
return 0;
}
else {
QImage img = item->data(Qt::DecorationRole).value<QImage>();
return new KisBackground(img);
}
}
void DlgBackgrounds::applyClicked()
{
accept();
......
......@@ -41,7 +41,7 @@ public:
DlgBackgrounds(KisView2* view);
~DlgBackgrounds();
KisPaintDeviceSP background();
KisBackgroundSP background();
private slots:
......
......@@ -18,15 +18,19 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "wdg_backgrounds.h"
#include <kstandarddirs.h>
#include <kcomponentdata.h>
#include "kis_factory2.h"
#include <QPainter>
#include <QStringList>
#include <QImage>
#include <QListWidgetItem>
#include <QDebug>
#include <kstandarddirs.h>
#include <kcomponentdata.h>
#include "kis_factory2.h"
#include "kis_config.h"
WdgBackgrounds::WdgBackgrounds(QWidget* parent)
: QWidget(parent)
{
......@@ -35,13 +39,28 @@ WdgBackgrounds::WdgBackgrounds(QWidget* parent)
QStringList backgroundFileNames =
KisFactory2::componentData().dirs()->findAllResources("kis_backgrounds", "*.png");
KisConfig cfg;
QImage none(QSize(64,64), QImage::Format_RGB32);
QPainter pt(&none);
pt.fillRect(none.rect(), Qt::white);
pt.fillRect(0, 0, 32, 32, cfg.checkersColor());
pt.fillRect(32, 32, 32, 32, cfg.checkersColor());
pt.end();
QListWidgetItem* noneItem = new QListWidgetItem(lstBackgrounds);
noneItem->setData(Qt::DecorationRole, none);
noneItem->setData(Qt::UserRole + 1, "none");
foreach(QString fileName, backgroundFileNames) {
QImage img = QImage(fileName).copy(0, 0, 64, 64);
QListWidgetItem* item = new QListWidgetItem(lstBackgrounds);
//item->setData(Qt::DisplayRole, fileName);
item->setData(Qt::DecorationRole, img);
item->setData(Qt::UserRole + 1, fileName);
}
lblName->setVisible( false );
bnAdd->setVisible( false );
bnAdd->setIcon( SmallIcon( "list-add" ) );
bnAdd->setToolTip( i18n("Import existing background") );
......
......@@ -15,7 +15,7 @@
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="blName">
<widget class="QLabel" name="lblName">
<property name="text">
<string>TextLabel</string>
</property>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment