Scribus
Open source desktop publishing at your fingertips
scimage.h
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 */
7 #ifndef SCIMAGE_H
8 #define SCIMAGE_H
9 
10 #include "scconfig.h"
11 #include "scribusapi.h"
12 #include "scimagestructs.h"
13 
14 #ifdef HAVE_UNISTD_H
15 #include <unistd.h>
16 #endif
17 #include <QImage>
18 #include <QString>
19 #include <QDataStream>
20 #include <QMap>
21 #include <QList>
22 #include <QVector>
23 #include <QFile>
24 #include <QDir>
25 #include <QStringList>
26 
27 #include "fpointarray.h"
28 #include "sccolor.h"
29 
30 class ScribusDoc;
31 class ScStreamFilter;
32 class CMSettings;
33 class ScImageCacheProxy;
34 class ScColorProfile;
35 
36 class SCRIBUS_API ScImage : private QImage
37 {
38 public:
39  ScImage();
40  ScImage(const QImage & image);
41  ScImage(const ScImage & image);
42  ScImage( int width, int height );
43  ~ScImage();
44 
45  enum RequestType
46  {
47  CMYKData = 0,
48  RGBData = 1,
49  RawData = 2,
50  OutputProfile = 3,
51  Thumbnail = 4,
52  };
53 
54  enum ImageEffectCode
55  {
56  EF_INVERT = 0,
57  EF_GRAYSCALE = 1,
58  EF_COLORIZE = 2,
59  EF_BRIGHTNESS = 3,
60  EF_CONTRAST = 4,
61  EF_SHARPEN = 5,
62  EF_BLUR = 6,
63  EF_SOLARIZE = 7,
64  EF_DUOTONE = 8,
65  EF_TRITONE = 9,
66  EF_QUADTONE = 10,
67  EF_GRADUATE = 11
68  };
69 
70  void initialize();
71 
72  const QImage& qImage();
73  QImage* qImagePtr();
74  QImage scaled(int h, int w, Qt::AspectRatioMode mode = Qt::IgnoreAspectRatio, Qt::TransformationMode transformMode = Qt::FastTransformation) const;
75 
76  int height() const { return QImage::height(); }
77  int width() const { return QImage::width(); }
78  bool hasAlpha() const { return QImage::hasAlphaChannel(); }
79  bool hasSmoothAlpha();
80 
81  // Routines for PDF/PS output of images
82  QByteArray ImageToArray();
83 
84  void convertToGray(void);
85 
86  bool writeRGBDataToFilter(ScStreamFilter* filter);
87  bool writeGrayDataToFilter(ScStreamFilter* filter, bool precal);
88  bool writeMonochromeDataToFilter(ScStreamFilter* filter, bool fromCmyk);
89  bool writeCMYKDataToFilter(ScStreamFilter* filter);
90 
91  bool writePSImageToFilter(ScStreamFilter* filter, int pl);
92  bool writePSImageToFilter(ScStreamFilter* filter, const QByteArray& mask, int pl);
93 
94  bool getAlpha(QString fn, int page, QByteArray& alpha, bool PDF, bool pdf14, int gsRes = 72, int scaleXSize = 0, int scaleYSize = 0);
95  bool convert2JPG(QString fn, int Quality, bool isCMYK, bool isGray);
96 
97  // Image effects
98  void applyEffect(const ScImageEffectList& effectsList, ColorList& colors, bool cmyk);
99 
100  // Generate a low res image for user preview
101  bool createLowRes(double scale);
102 
103  // Scale this image in-place
104  void scaleImage(int width, int height);
105 
106  // Retrieve an embedded ICC profile from the file path `fn', storing it in `profile'.
107  // TODO: Bad API. Should probably be static member returning an ICCProfile (custom class) or something like that.
108  void getEmbeddedProfile(const QString & fn, QByteArray *profile, int *components, int page = 0);
109 
110  // Load an image into this ScImage instance
111  // TODO: document params, split into smaller functions
112  bool loadPicture(const QString & fn, int page, const CMSettings& cmSettings, RequestType requestType, int gsRes, bool *realCMYK = 0, bool showMsg = false);
113  bool loadPicture(ScImageCacheProxy & cache, bool & fromCache, int page, const CMSettings& cmSettings, RequestType requestType, int gsRes, bool *realCMYK = 0, bool showMsg = false);
114  bool saveCache(ScImageCacheProxy & cache);
115 
116  ImageInfoRecord imgInfo;
117 
118 private:
119 
120  // Scale image in-place : case of 32bpp image (RGBA, RGB32, CMYK)
121  void scaleImage32bpp(int width, int height);
122 
123  // Scale image in-place : generic case
124  void scaleImageGeneric(int width, int height);
125 
126  // Image effects
127  void solarize(double factor, bool cmyk);
128  void blur(int radius = 0);
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(ScribusDoc* doc, ScColor color, int shade, bool cmyk);
134  void duotone(ScribusDoc* doc, ScColor color1, int shade1, FPointArray curve1, bool lin1, ScColor color2, int shade2, FPointArray curve2, bool lin2, bool cmyk);
135  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);
136  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);
137  void toGrayscale(bool cmyk);
138  void doGraduate(FPointArray curve, bool cmyk, bool linear);
139  void swapRGBA();
140  bool convolveImage(QImage *dest, const unsigned int order, const double *kernel);
141  int getOptimalKernelWidth(double radius, double sigma);
142  void applyCurve(const QVector<int>& curveTable, bool cmyk);
143 
144  void addProfileToCacheModifiers(ScImageCacheProxy & cache, const QString & prefix, const ScColorProfile & profile) const;
145 };
146 
147 #endif
Definition: sccolor.h:51
Definition: sccolorprofile.h:16
Definition: scimage.h:36
Definition: sccolor.h:155
the Document Class
Definition: scribusdoc.h:90
Scribus image cache proxy.
Definition: scimagecacheproxy.h:39
Definition: cmsettings.h:37
Definition: fpointarray.h:42
Definition: scstreamfilter.h:14
Definition: scimagestructs.h:126