Subversion Repositories Scribus

Compare Revisions

Ignore whitespace Rev 4221 → Rev 4222

/branches/Version13x/Scribus/scribus/scimage.h
43,10 → 43,22
{
public:
ScImage();
ScImage(QImage image);
ScImage(const QImage & image);
ScImage( int width, int height );
~ScImage();
 
enum PSDColorMode
{
CM_BITMAP = 0,
CM_GRAYSCALE = 1,
CM_INDEXED = 2,
CM_RGB = 3,
CM_CMYK = 4,
CM_MULTICHANNEL = 7,
CM_DUOTONE = 8,
CM_LABCOLOR = 9
};
 
enum ImageEffectCode
{
EF_INVERT = 0,
58,6 → 70,7
EF_BLUR = 6,
EF_SOLARIZE = 7
};
 
struct imageEffect
{
int effectCode;
64,54 → 77,32
QString effectParameters;
};
void initialize();
 
// Routines for PDF/PS output of images
QString ImageToTxt();
QString ImageToCMYK();
QString ImageToGray();
QString ImageToCMYK_PS(int pl, bool pre);
QString ImageToCMYK_PDF(bool pre);
QString getAlpha(QString fn, bool PDF, bool pdf14, int gsRes = 72);
void Convert2JPG(QString fn, int Quality, bool isCMYK, bool isGray);
QString MaskToTxt(bool PDF = true);
QString MaskToTxt14();
 
// Image effects
void applyEffect(QValueList<imageEffect> effectsList, QMap<QString,ScColor> colors, bool cmyk);
void solarize(double factor, bool cmyk);
void blur(double radius= 0.0, double sigma = 1.0);
void sharpen(double radius= 0.0, double sigma = 1.0);
void contrast(int contrastValue, bool cmyk);
void brightness(int brightnessValue, bool cmyk);
void invert(bool cmyk);
void colorize(ScColor color, int shade, bool cmyk);
void toGrayscale(bool cmyk);
void swapRGBA();
 
// Generate a low res image for user preview
void createLowRes(double scale);
 
// Scale this image in-place
void scaleImage(int width, int height);
void getEmbeddedProfile(QString fn, QString *profile, int *components);
bool LoadPicture(QString fn, QString Prof, int rend, bool useEmbedded, bool useProf, int requestType, int gsRes, bool *realCMYK = 0);
QString getAlpha(QString fn, bool PDF, bool pdf14, int gsRes = 72);
 
enum PSDColorMode
{
CM_BITMAP = 0,
CM_GRAYSCALE = 1,
CM_INDEXED = 2,
CM_RGB = 3,
CM_CMYK = 4,
CM_MULTICHANNEL = 7,
CM_DUOTONE = 8,
CM_LABCOLOR = 9
};
struct PSDHeader
{
uint signature;
ushort version;
uchar reserved[6];
ushort channel_count;
uint height;
uint width;
ushort depth;
ushort color_mode;
};
// Retrieve an embedded ICC profile from the file path `fn', storing it in `profile'.
// TODO: Bad API. Should probably be static member returning an ICCProfile (custom class) or something like that.
void getEmbeddedProfile(const QString & fn, QString *profile, int *components);
 
// Load an image into this ScImage instance
// TODO: document params, split into smaller functions
bool LoadPicture(const QString & fn, const QString & Prof, int rend, bool useEmbedded, bool useProf, int requestType, int gsRes, bool *realCMYK = 0);
 
struct PSDLayer
{
QValueList<uint> channelLen;
131,6 → 122,18
QString blend;
QImage thumb;
};
 
struct PSDHeader
{
uint signature;
ushort version;
uchar reserved[6];
ushort channel_count;
uint height;
uint width;
ushort depth;
ushort color_mode;
};
struct LoadRequest
{
138,7 → 141,7
ushort opacity;
QString blend;
};
 
struct ExifValues
{
int width;
152,7 → 155,7
QString dateTime;
QImage thumbnail;
};
 
struct ImageInfoRecord
{
int typ; /* 0 = jpg, 1 = tiff, 2 = psd, 3 = eps/ps, 4 = pdf, 5 = jpg2000, 6 = other */
176,6 → 179,18
} imgInfo;
 
private:
// Image effects
void solarize(double factor, bool cmyk);
void blur(double radius= 0.0, double sigma = 1.0);
void sharpen(double radius= 0.0, double sigma = 1.0);
void contrast(int contrastValue, bool cmyk);
void brightness(int brightnessValue, bool cmyk);
void invert(bool cmyk);
void colorize(ScColor color, int shade, bool cmyk);
void toGrayscale(bool cmyk);
void swapRGBA();
 
// Misc implementation
void liberateMemory(void **memory);
void blurScanLine(double *kernel, int width, unsigned int *src, unsigned int *dest, int columns);
int getBlurKernel(int width, double sigma, double **kernel);
207,5 → 222,6
QMemArray<int> curveTable;
QValueList<unsigned int> colorTable;
int random_table[4096];
};
#endif
/branches/Version13x/Scribus/scribus/scimage.cpp
52,7 → 52,7
return s;
}
 
ScImage::ScImage(QImage image) : QImage(image)
ScImage::ScImage(const QImage & image) : QImage(image)
{
initialize();
}
868,34 → 868,6
return ImgStr;
}
 
QString ScImage::ImageToCMYK()
{
int i = 0;
int h = height();
int w = width();
QString ImgStr = "";
ImgStr.reserve(4 * h * w);
for( int yi=0; yi < h; ++yi )
{
QRgb * s = (QRgb*)(scanLine( yi ));
for( int xi=0; xi < w; ++xi )
{
QRgb r=*s;
int c = 255 - qRed(r);
int m = 255 - qGreen(r);
int y = 255 - qBlue(r);
int k = QMIN(QMIN(c, m), y);
*s = qRgba(m - k, y - k, k, c - k);
ImgStr[i++] = static_cast<char> (c - k);
ImgStr[i++] = static_cast<char> (m - k);
ImgStr[i++] = static_cast<char> (y - k);
ImgStr[i++] = static_cast<char> (k);
s++;
}
}
return ImgStr;
}
 
QString ScImage::ImageToGray()
{
int i = 0;
1054,52 → 1026,6
return ImgStr;
}
 
QString ScImage::MaskToTxt(bool PDF)
{
int i = 0;
int h = height();
int w = width();
int w2;
unsigned char u;
w2 = w / 8;
if ((w % 8) != 0)
w2++;
QString ImgStr = "";
ImgStr.reserve(h * w2);
for( int yi=0; yi < h; ++yi )
{
uchar * s = scanLine( yi );
for( int xi=0; xi < w2; ++xi )
{
u = *(s+xi);
if(PDF) u = ~u;
ImgStr[i++] = u;
}
}
return ImgStr;
}
 
QString ScImage::MaskToTxt14()
{
int i = 0;
int h = height();
int w = width();
unsigned char u;
QString ImgStr = "";
ImgStr.reserve(h * w);
for( int yi=0; yi < h; ++yi )
{
QRgb * s = (QRgb*)(scanLine( yi ));
for( int xi=0; xi < w; ++xi )
{
QRgb r=*s++;
u = qAlpha(r);
ImgStr[i++] = u;
}
}
return ImgStr;
}
 
// Check that the header is a valid PSD.
bool ScImage::IsValid( const PSDHeader & header )
{
3267,8 → 3193,10
return true;
}
 
void ScImage::getEmbeddedProfile(QString fn, QString *profile, int *components)
void ScImage::getEmbeddedProfile(const QString & fn, QString *profile, int *components)
{
Q_ASSERT(profile);
Q_ASSERT(components);
#ifdef HAVE_CMS
cmsHPROFILE tiffProf = 0;
QFileInfo fi = QFileInfo(fn);
3390,7 → 3318,9
#endif // HAVE_CMS
}
 
bool ScImage::LoadPicture(QString fn, QString Prof, int rend, bool useEmbedded, bool useProf, int requestType, int gsRes, bool *realCMYK)
bool ScImage::LoadPicture(const QString & fn, const QString & Prof,
int rend, bool useEmbedded, bool useProf,
int requestType, int gsRes, bool *realCMYK)
{
// requestType - 0: CMYK, 1: RGB, 2: RGB Proof 3 : RawData, 4: Thumbnail
// gsRes - is the resolution that ghostscript will render at