Subversion Repositories Scribus

Rev

Rev 8002 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4430 cbradney 1
/*
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
6
*/
2004 fschmid 7
#ifndef SCIMAGE_H
8
#define SCIMAGE_H
9
 
2688 craig 10
#include "scconfig.h"
2969 craig 11
#include "scribusapi.h"
5937 jghali 12
#include "scimagestructs.h"
2004 fschmid 13
 
14
#include <setjmp.h>
15
#include <cstdlib>
16
#include <cmath>
2702 craig 17
#ifdef HAVE_UNISTD_H
2004 fschmid 18
#include <unistd.h>
2702 craig 19
#endif
4050 cbradney 20
//#include <valarray>
21
#include <qmemarray.h>
2004 fschmid 22
#include <qimage.h>
23
#include <qstring.h>
24
#include <qdatastream.h>
25
#include <qmap.h>
26
#include <qvaluelist.h>
27
#include <qfile.h>
28
#include <qdir.h>
29
#include <qstringlist.h>
5781 cbradney 30
 
31
#include "cmsettings.h"
2004 fschmid 32
#include "fpointarray.h"
2886 fschmid 33
#include "sccolor.h"
2004 fschmid 34
extern "C"
35
{
36
#define XMD_H           // shut JPEGlib up
37
#if defined(Q_OS_UNIXWARE)
38
#  define HAVE_BOOLEAN  // libjpeg under Unixware seems to need this
39
#endif
40
#include <jpeglib.h>
41
#include <jerror.h>
42
#undef HAVE_STDLIB_H
43
#ifdef const
44
#  undef const          // remove crazy C hackery in jconfig.h
45
#endif
46
}
47
 
7478 jghali 48
class ScribusDoc;
49
 
5593 avox 50
class SCRIBUS_API ScImage : private QImage
2004 fschmid 51
{
52
public:
53
        ScImage();
4222 craig 54
        ScImage(const QImage & image);
5593 avox 55
        ScImage(const ScImage & image);
2004 fschmid 56
        ScImage( int width, int height );
4050 cbradney 57
        ~ScImage();
4222 craig 58
 
5345 mrdocs 59
        enum RequestType
60
        {
61
                CMYKData = 0,
62
                RGBData = 1,
63
                RGBProof = 2,
64
                RawData = 3,
65
                Thumbnail = 4,
66
        };
67
 
2082 fschmid 68
        enum ImageEffectCode
69
        {
70
                EF_INVERT = 0,
71
                EF_GRAYSCALE = 1,
72
                EF_COLORIZE = 2,
73
                EF_BRIGHTNESS = 3,
2092 fschmid 74
                EF_CONTRAST = 4,
2095 fschmid 75
                EF_SHARPEN = 5,
2096 fschmid 76
                EF_BLUR = 6,
6080 fschmid 77
                EF_SOLARIZE = 7,
78
                EF_DUOTONE = 8,
79
                EF_TRITONE = 9,
6116 fschmid 80
                EF_QUADTONE = 10,
81
                EF_GRADUATE = 11
2082 fschmid 82
        };
4222 craig 83
 
2074 fschmid 84
        struct imageEffect
85
        {
86
                int effectCode;
87
                QString effectParameters;
88
        };
2012 fschmid 89
        void initialize();
4222 craig 90
 
5593 avox 91
        const QImage& qImage();
6063 fschmid 92
        QImage* qImagePtr();
5593 avox 93
        QImage smoothScale(int h, int w, QImage::ScaleMode mode = ScaleFree) const;
94
 
95
        int height() const { return QImage::height(); }
96
        int width() const { return QImage::width(); }
97
        bool hasAlpha() const { return QImage::hasAlphaBuffer(); }
98
 
4222 craig 99
        // Routines for PDF/PS output of images
5234 fschmid 100
        QByteArray ImageToArray();
101
        QByteArray ImageToGray();
102
        QByteArray ImageToCMYK_PS(int pl, bool pre);
103
        QByteArray ImageToCMYK_PDF(bool pre);
8403 fschmid 104
        QByteArray getAlpha(QString fn, bool PDF, bool pdf14, int gsRes = 72, int scaleXSize = 0, int scaleYSize = 0);
2004 fschmid 105
        void Convert2JPG(QString fn, int Quality, bool isCMYK, bool isGray);
4222 craig 106
 
107
        // Image effects
7478 jghali 108
        void applyEffect(QValueList<imageEffect> effectsList, ColorList& colors, bool cmyk);
4222 craig 109
 
110
        // Generate a low res image for user preview
2025 fschmid 111
        void createLowRes(double scale);
4222 craig 112
 
113
        // Scale this image in-place
2004 fschmid 114
        void scaleImage(int width, int height);
115
 
4222 craig 116
        // Retrieve an embedded ICC profile from the file path `fn', storing it in `profile'.
117
        // TODO: Bad API. Should probably be static member returning an ICCProfile (custom class) or something like that.
5234 fschmid 118
        void getEmbeddedProfile(const QString & fn, QByteArray *profile, int *components);
119
 
4222 craig 120
        // Load an image into this ScImage instance
121
        // TODO: document params, split into smaller functions
5977 jghali 122
        bool LoadPicture(const QString & fn, const CMSettings& cmSettings, bool useEmbedded, bool useProf, RequestType requestType, int gsRes, bool *realCMYK = 0, bool showMsg = false);
4222 craig 123
 
5937 jghali 124
        ImageInfoRecord imgInfo;
4222 craig 125
 
2004 fschmid 126
private:
4222 craig 127
        // Image effects
128
        void solarize(double factor, bool cmyk);
6011 fschmid 129
//      void blur(double radius= 0.0, double sigma = 1.0);
130
        void blur(int radius = 0);
4222 craig 131
        void sharpen(double radius= 0.0, double sigma = 1.0);
132
        void contrast(int contrastValue, bool cmyk);
133
        void brightness(int brightnessValue, bool cmyk);
134
        void invert(bool cmyk);
7478 jghali 135
        void colorize(ScribusDoc* doc, ScColor color, int shade, bool cmyk);
136
        void duotone(ScribusDoc* doc, ScColor color1, int shade1, FPointArray curve1, bool lin1, ScColor color2, int shade2, FPointArray curve2, bool lin2, bool cmyk);
137
        void tritone(ScribusDoc* doc, ScColor color1, int shade1, FPointArray curve1, bool lin1, ScColor color2, int shade2, FPointArray curve2, bool lin2, ScColor color3, int shade3, FPointArray curve3, bool lin3, bool cmyk);
138
        void quadtone(ScribusDoc* doc, ScColor color1, int shade1, FPointArray curve1, bool lin1, ScColor color2, int shade2, FPointArray curve2, bool lin2, ScColor color3, int shade3, FPointArray curve3, bool lin3, ScColor color4, int shade4, FPointArray curve4, bool lin4, bool cmyk);
4222 craig 139
        void toGrayscale(bool cmyk);
6193 fschmid 140
        void doGraduate(FPointArray curve, bool cmyk, bool linear);
4222 craig 141
        void swapRGBA();
142
 
143
        // Misc implementation
8002 fschmid 144
//      void liberateMemory(void **memory);
6011 fschmid 145
//      void blurScanLine(double *kernel, int width, unsigned int *src, unsigned int *dest, int columns);
146
//      int getBlurKernel(int width, double sigma, double **kernel);
2092 fschmid 147
        bool convolveImage(QImage *dest, const unsigned int order, const double *kernel);
148
        int getOptimalKernelWidth(double radius, double sigma);
2082 fschmid 149
        void applyCurve(bool cmyk);
2012 fschmid 150
        char* iccbuf;
151
        uint icclen;
4050 cbradney 152
        //std::valarray<int> curveTable;
153
        QMemArray<int> curveTable;
3836 fschmid 154
        QValueList<unsigned int> colorTable;
3905 fschmid 155
        int random_table[4096];
4222 craig 156
 
2004 fschmid 157
};
6578 cbradney 158
 
159
typedef QValueList<ScImage::imageEffect> ScImageEffectList;
160
 
2004 fschmid 161
#endif