Back to index

scribus-ng  1.3.4.dfsg+svn20071115
scimage.h
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 #ifndef SCIMAGE_H
00008 #define SCIMAGE_H
00009 
00010 #include "scconfig.h"
00011 #include "scribusapi.h"
00012 #include "scimagestructs.h"
00013 
00014 #include <setjmp.h>
00015 #include <cstdlib>
00016 #include <cmath>
00017 #ifdef HAVE_UNISTD_H
00018 #include <unistd.h>
00019 #endif
00020 //#include <valarray>
00021 #include <qmemarray.h>
00022 #include <qimage.h>
00023 #include <qstring.h>
00024 #include <qdatastream.h>
00025 #include <qmap.h>
00026 #include <qvaluelist.h>
00027 #include <qfile.h>
00028 #include <qdir.h>
00029 #include <qstringlist.h>
00030 
00031 #include "cmsettings.h"
00032 #include "fpointarray.h"
00033 #include "sccolor.h"
00034 extern "C"
00035 {
00036 #define XMD_H           // shut JPEGlib up
00037 #if defined(Q_OS_UNIXWARE)
00038 #  define HAVE_BOOLEAN  // libjpeg under Unixware seems to need this
00039 #endif
00040 #include <jpeglib.h>
00041 #include <jerror.h>
00042 #undef HAVE_STDLIB_H
00043 #ifdef const
00044 #  undef const          // remove crazy C hackery in jconfig.h
00045 #endif
00046 }
00047 
00048 class ScribusDoc;
00049 
00050 class SCRIBUS_API ScImage : private QImage
00051 {
00052 public:
00053        ScImage();
00054        ScImage(const QImage & image);
00055        ScImage(const ScImage & image);
00056        ScImage( int width, int height );
00057        ~ScImage();
00058 
00059        enum RequestType
00060        {
00061               CMYKData = 0,
00062               RGBData = 1,
00063               RGBProof = 2,
00064               RawData = 3,
00065               Thumbnail = 4,
00066        };
00067 
00068        enum ImageEffectCode
00069        {
00070               EF_INVERT = 0,
00071               EF_GRAYSCALE = 1,
00072               EF_COLORIZE = 2,
00073               EF_BRIGHTNESS = 3,
00074               EF_CONTRAST = 4,
00075               EF_SHARPEN = 5,
00076               EF_BLUR = 6,
00077               EF_SOLARIZE = 7,
00078               EF_DUOTONE = 8,
00079               EF_TRITONE = 9,
00080               EF_QUADTONE = 10,
00081               EF_GRADUATE = 11
00082        };
00083 
00084        struct imageEffect
00085        {
00086               int effectCode;
00087               QString effectParameters;
00088        };
00089        void initialize();
00090 
00091        const QImage& qImage();
00092        QImage* qImagePtr();
00093        QImage smoothScale(int h, int w, QImage::ScaleMode mode = ScaleFree) const;
00094        
00095        int height() const { return QImage::height(); }
00096        int width() const { return QImage::width(); }
00097        bool hasAlpha() const { return QImage::hasAlphaBuffer(); }
00098        
00099        // Routines for PDF/PS output of images
00100        QByteArray ImageToArray();
00101        QByteArray ImageToGray();
00102        QByteArray ImageToCMYK_PS(int pl, bool pre);
00103        QByteArray ImageToCMYK_PDF(bool pre);
00104        QByteArray getAlpha(QString fn, bool PDF, bool pdf14, int gsRes = 72, int scaleXSize = 0, int scaleYSize = 0);
00105        void Convert2JPG(QString fn, int Quality, bool isCMYK, bool isGray);
00106 
00107        // Image effects
00108        void applyEffect(QValueList<imageEffect> effectsList, ColorList& colors, bool cmyk);
00109 
00110        // Generate a low res image for user preview
00111        void createLowRes(double scale);
00112 
00113        // Scale this image in-place
00114        void scaleImage(int width, int height);
00115 
00116        // Retrieve an embedded ICC profile from the file path `fn', storing it in `profile'.
00117        // TODO: Bad API. Should probably be static member returning an ICCProfile (custom class) or something like that.
00118        void getEmbeddedProfile(const QString & fn, QByteArray *profile, int *components);
00119 
00120        // Load an image into this ScImage instance
00121        // TODO: document params, split into smaller functions
00122        bool LoadPicture(const QString & fn, const CMSettings& cmSettings, bool useEmbedded, bool useProf, RequestType requestType, int gsRes, bool *realCMYK = 0, bool showMsg = false);
00123 
00124        ImageInfoRecord imgInfo;
00125 
00126 private:
00127        // Image effects
00128        void solarize(double factor, bool cmyk);
00129 //     void blur(double radius= 0.0, double sigma = 1.0);
00130        void blur(int radius = 0);
00131        void sharpen(double radius= 0.0, double sigma = 1.0);
00132        void contrast(int contrastValue, bool cmyk);
00133        void brightness(int brightnessValue, bool cmyk);
00134        void invert(bool cmyk);
00135        void colorize(ScribusDoc* doc, ScColor color, int shade, bool cmyk);
00136        void duotone(ScribusDoc* doc, ScColor color1, int shade1, FPointArray curve1, bool lin1, ScColor color2, int shade2, FPointArray curve2, bool lin2, bool cmyk);
00137        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);
00138        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);
00139        void toGrayscale(bool cmyk);
00140        void doGraduate(FPointArray curve, bool cmyk, bool linear);
00141        void swapRGBA();
00142 
00143        // Misc implementation
00144 //     void liberateMemory(void **memory);
00145 //     void blurScanLine(double *kernel, int width, unsigned int *src, unsigned int *dest, int columns);
00146 //     int getBlurKernel(int width, double sigma, double **kernel);
00147        bool convolveImage(QImage *dest, const unsigned int order, const double *kernel);
00148        int getOptimalKernelWidth(double radius, double sigma);
00149        void applyCurve(bool cmyk);
00150        char* iccbuf;
00151        uint icclen;
00152        //std::valarray<int> curveTable;
00153        QMemArray<int> curveTable;
00154        QValueList<unsigned int> colorTable;
00155        int random_table[4096];
00156        
00157 };
00158 
00159 typedef QValueList<ScImage::imageEffect> ScImageEffectList;
00160 
00161 #endif