Subversion Repositories Scribus

Rev

Rev 6129 | Rev 6578 | Go to most recent revision | 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
 
5593 avox 48
class SCRIBUS_API ScImage : private QImage
2004 fschmid 49
{
50
public:
51
        ScImage();
4222 craig 52
        ScImage(const QImage & image);
5593 avox 53
        ScImage(const ScImage & image);
2004 fschmid 54
        ScImage( int width, int height );
4050 cbradney 55
        ~ScImage();
4222 craig 56
 
5345 mrdocs 57
        enum RequestType
58
        {
59
                CMYKData = 0,
60
                RGBData = 1,
61
                RGBProof = 2,
62
                RawData = 3,
63
                Thumbnail = 4,
64
        };
65
 
2082 fschmid 66
        enum ImageEffectCode
67
        {
68
                EF_INVERT = 0,
69
                EF_GRAYSCALE = 1,
70
                EF_COLORIZE = 2,
71
                EF_BRIGHTNESS = 3,
2092 fschmid 72
                EF_CONTRAST = 4,
2095 fschmid 73
                EF_SHARPEN = 5,
2096 fschmid 74
                EF_BLUR = 6,
6080 fschmid 75
                EF_SOLARIZE = 7,
76
                EF_DUOTONE = 8,
77
                EF_TRITONE = 9,
6116 fschmid 78
                EF_QUADTONE = 10,
79
                EF_GRADUATE = 11
2082 fschmid 80
        };
4222 craig 81
 
2074 fschmid 82
        struct imageEffect
83
        {
84
                int effectCode;
85
                QString effectParameters;
86
        };
2012 fschmid 87
        void initialize();
4222 craig 88
 
5593 avox 89
        const QImage& qImage();
6063 fschmid 90
        QImage* qImagePtr();
5593 avox 91
        QImage smoothScale(int h, int w, QImage::ScaleMode mode = ScaleFree) const;
92
 
93
        int height() const { return QImage::height(); }
94
        int width() const { return QImage::width(); }
95
        bool hasAlpha() const { return QImage::hasAlphaBuffer(); }
96
 
4222 craig 97
        // Routines for PDF/PS output of images
5234 fschmid 98
        QByteArray ImageToArray();
99
        QByteArray ImageToGray();
100
        QByteArray ImageToCMYK_PS(int pl, bool pre);
101
        QByteArray ImageToCMYK_PDF(bool pre);
102
        QByteArray getAlpha(QString fn, bool PDF, bool pdf14, int gsRes = 72);
2004 fschmid 103
        void Convert2JPG(QString fn, int Quality, bool isCMYK, bool isGray);
4222 craig 104
 
105
        // Image effects
2886 fschmid 106
        void applyEffect(QValueList<imageEffect> effectsList, QMap<QString,ScColor> colors, bool cmyk);
4222 craig 107
 
108
        // Generate a low res image for user preview
2025 fschmid 109
        void createLowRes(double scale);
4222 craig 110
 
111
        // Scale this image in-place
2004 fschmid 112
        void scaleImage(int width, int height);
113
 
4222 craig 114
        // Retrieve an embedded ICC profile from the file path `fn', storing it in `profile'.
115
        // TODO: Bad API. Should probably be static member returning an ICCProfile (custom class) or something like that.
5234 fschmid 116
        void getEmbeddedProfile(const QString & fn, QByteArray *profile, int *components);
117
 
4222 craig 118
        // Load an image into this ScImage instance
119
        // TODO: document params, split into smaller functions
5977 jghali 120
        bool LoadPicture(const QString & fn, const CMSettings& cmSettings, bool useEmbedded, bool useProf, RequestType requestType, int gsRes, bool *realCMYK = 0, bool showMsg = false);
4222 craig 121
 
5937 jghali 122
        ImageInfoRecord imgInfo;
4222 craig 123
 
2004 fschmid 124
private:
4222 craig 125
        // Image effects
126
        void solarize(double factor, bool cmyk);
6011 fschmid 127
//      void blur(double radius= 0.0, double sigma = 1.0);
128
        void blur(int radius = 0);
4222 craig 129
        void sharpen(double radius= 0.0, double sigma = 1.0);
130
        void contrast(int contrastValue, bool cmyk);
131
        void brightness(int brightnessValue, bool cmyk);
132
        void invert(bool cmyk);
133
        void colorize(ScColor color, int shade, bool cmyk);
6193 fschmid 134
        void duotone(ScColor color1, int shade1, FPointArray curve1, bool lin1, ScColor color2, int shade2, FPointArray curve2, bool lin2, bool cmyk);
135
        void tritone(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);
136
        void quadtone(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 137
        void toGrayscale(bool cmyk);
6193 fschmid 138
        void doGraduate(FPointArray curve, bool cmyk, bool linear);
4222 craig 139
        void swapRGBA();
140
 
141
        // Misc implementation
2095 fschmid 142
        void liberateMemory(void **memory);
6011 fschmid 143
//      void blurScanLine(double *kernel, int width, unsigned int *src, unsigned int *dest, int columns);
144
//      int getBlurKernel(int width, double sigma, double **kernel);
2092 fschmid 145
        bool convolveImage(QImage *dest, const unsigned int order, const double *kernel);
146
        int getOptimalKernelWidth(double radius, double sigma);
2082 fschmid 147
        void applyCurve(bool cmyk);
2012 fschmid 148
        char* iccbuf;
149
        uint icclen;
4050 cbradney 150
        //std::valarray<int> curveTable;
151
        QMemArray<int> curveTable;
3836 fschmid 152
        QValueList<unsigned int> colorTable;
3905 fschmid 153
        int random_table[4096];
4222 craig 154
 
2004 fschmid 155
};
156
#endif