Commit 307de363 authored by Halla Rempt's avatar Halla Rempt

Move PSD loading/saving common code to a new library, libkispsd

We want to be able to save and load ASL files from krita/image, so that
needs to share code with the PSD plugin.
parent 5fb6b4cc
......@@ -88,6 +88,7 @@ set(KRITA_INCLUDES
# For config-*.h
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_SOURCE_DIR}/krita/libpsd
${CMAKE_SOURCE_DIR}/krita/image
${CMAKE_SOURCE_DIR}/krita/image/brushengine
${CMAKE_SOURCE_DIR}/krita/image/tiles
......@@ -125,6 +126,7 @@ if(HAVE_OPENGL)
endif(HAVE_GLEW)
endif(HAVE_OPENGL)
add_subdirectory( libpsd )
add_subdirectory( image )
add_subdirectory( libbrush )
add_subdirectory( ui )
......
......@@ -277,8 +277,8 @@ set(einspline_SRCS
kde4_add_library(kritaimage SHARED ${kritaimage_LIB_SRCS} ${einspline_SRCS})
target_link_libraries(kritaimage ${KDE4_KDEUI_LIBS} pigmentcms kundo2 kowidgetutils)
target_link_libraries(kritaimage LINK_INTERFACE_LIBRARIES pigmentcms kundo2 kowidgetutils)
target_link_libraries(kritaimage ${KDE4_KDEUI_LIBS} libkispsd pigmentcms kundo2 kowidgetutils)
target_link_libraries(kritaimage LINK_INTERFACE_LIBRARIES libkispsd pigmentcms kundo2 kowidgetutils)
target_link_libraries(kritaimage ${Boost_SYSTEM_LIBRARY})
message("DEBUG_BOOST_LIBRARIES = " ${Boost_LIBRARIES})
......
......@@ -19,8 +19,42 @@
#include <QIODevice>
#include <psd.h>
#include <psd_utils.h>
struct KisPSDLayerStyle::Private
{
Private()
: version(-1)
, effects_count(0)
, visible(false)
{}
quint16 version;
quint8 effects_count; // Effects count: may be 6 (for the 6 effects in Photoshop 5 and 6) or 7 (for Photoshop 7.0)
bool visible; // common state info, visible: always true
psd_layer_effects_drop_shadow drop_shadow;
psd_layer_effects_inner_shadow inner_shadow;
psd_layer_effects_outer_glow outer_glow;
psd_layer_effects_inner_glow inner_glow;
psd_layer_effects_bevel_emboss bevel_emboss;
psd_layer_effects_satin satin;
psd_layer_effects_color_overlay color_overlay;
psd_layer_effects_gradient_overlay gradient_overlay;
psd_layer_effects_pattern_overlay pattern_overlay;
psd_layer_effects_stroke stroke;
QVector<bool> fill;
QVector<bool> valid;
QVector<QString> blend_mode;
QVector<quint8> opacity;
QVector<QColor> *image_data;
QVector<qint32> left;
QVector<qint32> top;
QVector<qint32> right;
QVector<qint32> bottom;
QVector<qint32> width;
QVector<qint32> height;
};
KisPSDLayerStyle::KisPSDLayerStyle(QObject *parent)
......@@ -29,12 +63,24 @@ KisPSDLayerStyle::KisPSDLayerStyle(QObject *parent)
{
}
bool KisPSDLayerStyle::save(QIODevice *io) const
bool KisPSDLayerStyle::writeASL(QIODevice *io) const
{
return false;
}
bool KisPSDLayerStyle::readASL(QIODevice *io)
{
quint32 tag;
return false;
}
bool KisPSDLayerStyle::write(QIODevice *io) const
{
return false;
}
bool KisPSDLayerStyle::load(QIODevice *io)
bool KisPSDLayerStyle::read(QIODevice *io)
{
return false;
}
......@@ -22,19 +22,27 @@
class QIODevice;
#include <krita_export.h>
/**
* @brief The KisPSDLayerStyle class implements loading, saving and applying
* the PSD layer effects.
*
*/
class KisPSDLayerStyle : public QObject
class KRITAIMAGE_EXPORT KisPSDLayerStyle : public QObject
{
Q_OBJECT
public:
explicit KisPSDLayerStyle(QObject *parent = 0);
bool save(QIODevice *io) const;
bool load(QIODevice *io);
/// Save the ASL style format. See http://www.tonton-pixel.com/Photoshop%20Additional%20File%20Formats/styles-file-format.html
bool writeASL(QIODevice *io) const;
/// Load the ASL style format. See http://www.tonton-pixel.com/Photoshop%20Additional%20File%20Formats/styles-file-format.html
bool readASL(QIODevice *io);
bool write(QIODevice *io) const;
bool read(QIODevice *io);
signals:
......
......@@ -607,3 +607,9 @@ target_link_libraries(KisFillIntervalMapTest ${KDE4_KDEUI_LIBS} kritaimage ${QT
set(kis_scanline_fill_test_SRCS kis_scanline_fill_test.cpp )
kde4_add_unit_test(KisScanlineFillTest TESTNAME krita-image-ScanlineFill-Test ${kis_scanline_fill_test_SRCS})
target_link_libraries(KisScanlineFillTest ${KDE4_KDEUI_LIBS} kritaimage ${QT_QTTEST_LIBRARY})
########### next target ###############
set(kis_psd_layer_style_test_SRCS kis_psd_layer_style_test.cpp )
kde4_add_unit_test(KisPSDLayerStyleTest TESTNAME krita-image-PSDLayerStyle-Test ${kis_psd_layer_style_test_SRCS})
target_link_libraries(KisPSDLayerStyleTest ${KDE4_KDEUI_LIBS} kritaimage ${QT_QTTEST_LIBRARY})
/*
* Copyright (c) 2009 Boudewijn Rempt <boud@valdyas.org>
* Copyright (c) 2014 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
......@@ -15,32 +15,34 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PSD_UTILS_H
#define PSD_UTILS_H
#include <QtGlobal>
#include "kis_psd_layer_style_test.h"
#include "kis_psd_layer_style.h"
class QIODevice;
class QString;
#include <QString>
#include <QFile>
#include <QByteArray>
#include <QBuffer>
bool psdwrite(QIODevice* io, quint8 v);
bool psdwrite(QIODevice* io, quint16 v);
bool psdwrite(QIODevice* io, qint16 v);
bool psdwrite(QIODevice* io, quint32 v);
bool psdwrite(QIODevice* io, const QString &s);
bool psdwrite_pascalstring(QIODevice* io, const QString &s);
bool psdwrite_pascalstring(QIODevice* io, const QString &s, int padding);
bool psdpad(QIODevice* io, quint32 padding);
#include <qtest_kde.h>
bool psdread(QIODevice* io, quint8* v);
bool psdread(QIODevice* io, quint16* v);
bool psdread(QIODevice* io, qint16* v);
bool psdread(QIODevice* io, quint32* v);
bool psdread(QIODevice* io, qint32* v);
bool psdread(QIODevice* io, quint64* v);
bool psdread_pascalstring(QIODevice* io, QString& s, int padding);
void KisPSDLayerStyleTest::testRoundTrip()
{
KisPSDLayerStyle layerStyle(0);
QFile f(FILES_DATA_DIR + QDir::separator() + "teststyles.asl");
bool res = f.open(QIODevice::ReadOnly);
Q_ASSERT(res);
QByteArray ba = f.readAll();
f.close();
Q_ASSERT(ba.size() > 0);
QBuffer in(&ba);
res = layerStyle.readASL(&in);
Q_ASSERT(res);
QByteArray ba2;
QBuffer out(&ba2);
res = layerStyle.readASL(&out);
Q_ASSERT(res);
Q_ASSERT(ba2 == ba);
}
bool psd_read_blendmode(QIODevice* io, QString &blendModeKey);
#endif // PSD_UTILS_H
QTEST_KDEMAIN(KisPSDLayerStyleTest, GUI)
/*
* Copyright (c) 2010 Boudewijn Rempt <boud@valdyas.org>
* Copyright (c) 2014 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
......@@ -15,77 +15,17 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*
* Constants and defines taken from gimp and psdparse
*/
#ifndef PSD_H
#define PSD_H
#include <QPair>
#include <QString>
const int MAX_CHANNELS = 56;
typedef qint32 Fixed; /* Represents a fixed point implied decimal */
/**
* Image color/depth modes
*/
enum psd_color_mode {
Bitmap = 0,
Grayscale=1,
Indexed=2,
RGB=3,
CMYK=4,
MultiChannel=7,
DuoTone=8,
Lab=9,
Gray16,
RGB48,
Lab48,
CMYK64,
DeepMultichannel,
Duotone16,
UNKNOWN = 9000
};
#ifndef __KIS_PSD_LAYER_STYLE_TEST_H
#define __KIS_PSD_LAYER_STYLE_TEST_H
#include <QtTest/QtTest>
/**
* Color samplers, apparently distict from PSDColormode
*/
namespace psd_color_sampler {
enum PSDColorSamplers {
RGB,
HSB,
CMYK,
PANTONE, // LAB
FOCOLTONE, // CMYK
TRUMATCH, // CMYK
TOYO, // LAB
LAB,
GRAYSCALE,
HKS, // CMYK
DIC, // LAB
TOTAL_INK,
MONITOR_RGB,
DUOTONE,
OPACITY,
ANPA = 3000 // LAB
class KisPSDLayerStyleTest : public QObject
{
Q_OBJECT
private slots:
void testRoundTrip();
};
}
/**
* Convert PsdColorMode to pigment colormodelid and colordepthid.
* @see KoColorModelStandardIds
*
* @return a QPair containing ColorModelId and ColorDepthID
*/
QPair<QString, QString> psd_colormode_to_colormodelid(psd_color_mode colormode, quint16 channelDepth);
/**
* Convert the Photoshop blend mode strings to Pigment compositeop id's
*/
QString psd_blendmode_to_composite_op(const QString& blendmode);
QString composite_op_to_psd_blendmode(const QString& compositeOp);
#endif // PSD_H
#endif
set(libkispsd_LIB_SRCS
psd_utils.cpp
psd.cpp
compression.cpp
)
kde4_add_library(libkispsd SHARED ${libkispsd_LIB_SRCS} )
if (WIN32)
target_link_libraries(libkispsd pigmentcms ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${WIN32_PLATFORM_NET_LIBS})
else (WIN32)
target_link_libraries(libkispsd pigmentcms ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY})
endif (WIN32)
target_link_libraries(libkispsd LINK_INTERFACE_LIBRARIES ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY})
set_target_properties(libkispsd PROPERTIES
VERSION ${GENERIC_CALLIGRA_LIB_VERSION} SOVERSION ${GENERIC_CALLIGRA_LIB_SOVERSION}
)
install(TARGETS libkispsd ${INSTALL_TARGETS_DEFAULT_ARGS})
......@@ -19,8 +19,9 @@
#define COMPRESSION_H
#include <QByteArray>
#include "libkispsd_export.h"
class Compression
class LIBKISPSD_EXPORT Compression
{
public:
......
/* This file is part of the KDE project
Copyright (C) 2006 David Faure <faure@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef LIBKISPSD_EXPORT_H
#define LIBKISPSD_EXPORT_H
/* needed for KDE_EXPORT and KDE_IMPORT macros */
#include <kdemacros.h>
/* We use _WIN32/_WIN64 instead of Q_OS_WIN so that this header can be used from C files too */
#if defined _WIN32 || defined _WIN64
#ifndef LIBKISPSD_EXPORT
# if defined(MAKE_LIBKISPSD_LIB)
/* We are building this library */
# define LIBKISPSD_EXPORT KDE_EXPORT
# else
/* We are using this library */
# define LIBKISPSD_EXPORT KDE_IMPORT
# endif
#endif
#else /* UNIX */
#define LIBKISPSD_EXPORT KDE_EXPORT
#endif
#endif
......@@ -17,9 +17,10 @@
*/
#include "psd.h"
#include <QDebug>
#include <KoColorModelStandardIds.h>
#include <KoCompositeOpRegistry.h>
#include <kis_debug.h>
QPair<QString, QString> psd_colormode_to_colormodelid(psd_color_mode colormode, quint16 channelDepth)
{
......@@ -125,7 +126,7 @@ QString psd_blendmode_to_composite_op(const QString& blendmode)
// 'lum ' = luminosity
if (blendmode == "lum ") return COMPOSITE_LUMINIZE;
warnFile << "Unknown blendmode:" << blendmode << ". Returning Normal";
qDebug() << "Unknown blendmode:" << blendmode << ". Returning Normal";
return COMPOSITE_OVER;
}
......@@ -189,7 +190,7 @@ QString composite_op_to_psd_blendmode(const QString& compositeop)
// 'lum ' = luminosity
if (compositeop == COMPOSITE_LUMINIZE) return "lum ";
warnFile << "Krita blending mode" << compositeop << "does not exist in Photoshop, returning Normal";
qDebug() << "Krita blending mode" << compositeop << "does not exist in Photoshop, returning Normal";
return "norm";
}
/*
* Copyright (c) 2010 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.
*/
/*
* Constants and defines taken from gimp and psdparse
*/
#ifndef PSD_H
#define PSD_H
#include <QPair>
#include <QString>
#include <QColor>
#include <QVector>
#include "libkispsd_export.h"
const int MAX_CHANNELS = 56;
typedef qint32 Fixed; /* Represents a fixed point implied decimal */
/**
* Image color/depth modes
*/
enum psd_color_mode {
Bitmap = 0,
Grayscale=1,
Indexed=2,
RGB=3,
CMYK=4,
MultiChannel=7,
DuoTone=8,
Lab=9,
Gray16,
RGB48,
Lab48,
CMYK64,
DeepMultichannel,
Duotone16,
UNKNOWN = 9000
};
/**
* Color samplers, apparently distict from PSDColormode
*/
namespace psd_color_sampler {
enum PSDColorSamplers {
RGB,
HSB,
CMYK,
PANTONE, // LAB
FOCOLTONE, // CMYK
TRUMATCH, // CMYK
TOYO, // LAB
LAB,
GRAYSCALE,
HKS, // CMYK
DIC, // LAB
TOTAL_INK,
MONITOR_RGB,
DUOTONE,
OPACITY,
ANPA = 3000 // LAB
};
}
// EFFECTS
enum psd_gradient_style {
psd_gradient_style_linear, // 'Lnr '
psd_gradient_style_radial, // 'Rdl '
psd_gradient_style_angle, // 'Angl'
psd_gradient_style_reflected, // 'Rflc'
psd_gradient_style_diamond // 'Dmnd'
};
enum psd_color_stop_type {
psd_color_stop_type_foreground_color, // 'FrgC'
psd_color_stop_type_background_Color, // 'BckC'
psd_color_stop_type_user_stop // 'UsrS'
};
enum psd_technique_type {
psd_technique_softer,
psd_technique_precise,
psd_technique_slope_limit,
};
enum psd_stroke_position {
psd_stroke_outside,
psd_stroke_inside,
psd_stroke_center
};
enum psd_fill_type {
psd_fill_solid_color,
psd_fill_gradient,
psd_fill_pattern,
};
enum psd_glow_source {
psd_glow_center,
psd_glow_edge,
};
enum psd_bevel_style {
psd_bevel_outer_bevel,
psd_bevel_inner_bevel,
psd_bevel_emboss,
psd_bevel_pillow_emboss,
psd_bevel_stroke_emboss,
};
enum psd_direction {
psd_direction_up,
psd_direction_down
};
enum psd_section_type {
psd_other = 0,
psd_open_folder,
psd_closed_folder,
psd_bounding_divider
};
// GRADIENT MAP
// Each color stop
struct psd_gradient_color_stop
{
qint32 location; // Location of color stop
qint32 midpoint; // Midpoint of color stop
QColor actual_color;
psd_color_stop_type color_stop_type;
};
// Each transparency stop
struct psd_gradient_transparency_stop
{
qint32 location; // Location of transparency stop
qint32 midpoint; // Midpoint of transparency stop
qint8 opacity; // Opacity of transparency stop
};
// Gradient settings (Photoshop 6.0)
struct psd_layer_gradient_map
{
bool reverse; // Is gradient reverse
bool dithered; // Is gradient dithered
qint32 name_length;
quint16 *name; // Name of the gradient: Unicode string, padded
qint8 number_color_stops; // Number of color stops to follow
psd_gradient_color_stop * color_stop;
qint8 number_transparency_stops;// Number of transparency stops to follow
psd_gradient_transparency_stop * transparency_stop;
qint8 expansion_count; // Expansion count ( = 2 for Photoshop 6.0)
qint8 interpolation; // Interpolation if length above is non-zero
qint8 length; // Length (= 32 for Photoshop 6.0)
qint8 mode; // Mode for this gradient
qint32 random_number_seed; // Random number seed
qint8 showing_transparency_flag;// Flag for showing transparency
qint8 using_vector_color_flag;// Flag for using vector color
qint32 roughness_factor; // Roughness factor
QColor min_color;
QColor max_color;
QColor lookup_table[256];
};
struct psd_gradient_color {
qint32 smoothness;
qint32 name_length;
quint16 * name; // Name of the gradient: Unicode string, padded
qint8 number_color_stops; // Number of color stops to follow
psd_gradient_color_stop * color_stop;
qint8 number_transparency_stops;// Number of transparency stops to follow
psd_gradient_transparency_stop *transparency_stop;
};
struct psd_pattern {
psd_color_mode color_mode; // The image mode of the file.
quint8 height; // Point: vertical, 2 bytes and horizontal, 2 bytes
quint8 width;
QString name;
QString uuid;
qint32 version;
quint8 top; // Rectangle: top, left, bottom, right
quint8 left;
quint8 bottom;
quint8 right;
qint32 max_channel; // Max channels
qint32 channel_number;
QVector<QRgb> color_table;
};
// dsdw, isdw: http://www.adobe.com/devnet-apps/photoshop/fileformatashtml/PhotoshopFileFormats.htm#50577409_22203