Subversion Repositories Scribus

Compare Revisions

Ignore whitespace Rev 5233 → Rev 5234

/branches/Version13x/Scribus/scribus/scimage.h
85,11 → 85,11
void initialize();
 
// Routines for PDF/PS output of images
QString ImageToTxt();
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);
QByteArray ImageToArray();
QByteArray ImageToGray();
QByteArray ImageToCMYK_PS(int pl, bool pre);
QByteArray ImageToCMYK_PDF(bool pre);
QByteArray getAlpha(QString fn, bool PDF, bool pdf14, int gsRes = 72);
void Convert2JPG(QString fn, int Quality, bool isCMYK, bool isGray);
 
// Image effects
105,6 → 105,10
// 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);
 
// 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, QByteArray *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);
/branches/Version13x/Scribus/scribus/util.cpp
348,7 → 348,6
QFileInfo fi(f);
if (fi.exists())
{
bool ret;
QCString tempBuf(f.size() + 1);
if (f.open(IO_ReadOnly))
{
364,6 → 363,27
return ret;
}
 
bool loadRawBytes(const QString & filename, QByteArray & buf)
{
bool ret = false;
QFile f(filename);
QFileInfo fi(f);
if (fi.exists())
{
QByteArray tempBuf(f.size());
if (f.open(IO_ReadOnly))
{
unsigned int bytesRead = f.readBlock(tempBuf.data(), f.size());
ret = bytesRead == f.size();
if (ret)
buf = tempBuf; // sharing makes this efficient
}
}
if (f.isOpen())
f.close();
return ret;
}
 
QPointArray RegularPolygon(double w, double h, uint c, bool star, double factor, double rota)
{
uint cx = star ? c * 2 : c;
435,7 → 455,7
{
for (uint poi=0; poi<ina.size()-3; poi += 4)
{
if (ina.point(poi).x() > 900000)
if (ina.point(poi).x() > 900000 && cli.size() > 0)
{
outa.resize(outa.size()+1);
outa.setPoint(outa.size()-1, cli.point(cli.size()-1));
520,6 → 540,28
return out;
}
 
QByteArray CompressArray(QByteArray *in)
{
QByteArray out;
#ifdef HAVE_LIBZ
uLong exlen = uint(in->size() * 0.001 + 16) + in->size();
QByteArray temp(exlen);
int errcode = compress2((Byte *)temp.data(), &exlen, (Byte *)in->data(), uLong(in->size()), 9);
if (errcode != Z_OK)
{
qDebug("compress2 failed with code %i", errcode);
out = *in;
}
else {
temp.resize(exlen);
out = temp;
}
#else
out = *in;
#endif
return out;
}
 
char *toHex( uchar u )
{
static char hexVal[3];
/branches/Version13x/Scribus/scribus/pslib.h
103,7 → 103,11
bool Art;
private:
void PutSeite(QString c);
void PutSeite(QByteArray& array, bool hexEnc);
void PutSeite(const char* array, int length, bool hexEnc);
void PutDoc(QString c);
void PutDoc(QByteArray& array, bool hexEnc);
void PutDoc(const char* in, int length, bool hexEnc);
QString ToStr(double c);
QString IToStr(int c);
QString PSEncode(QString in);
/branches/Version13x/Scribus/scribus/pdflib.cpp
271,6 → 271,35
return uk;
}
 
QByteArray PDFlib::EncStreamArray(const QByteArray & in, int ObjNum)
{
if (in.size() < 1)
return QByteArray();
else if (!Options.Encrypt)
return in;
rc4_context_t rc4;
int dlen = 0;
QByteArray out(in.size());
QByteArray data(10);
if (KeyLen > 5)
data.resize(21);
for (int cd = 0; cd < KeyLen; ++cd)
{
data[cd] = EncryKey[cd];
dlen++;
}
data[dlen++] = ObjNum;
data[dlen++] = ObjNum >> 8;
data[dlen++] = ObjNum >> 16;
data[dlen++] = 0;
data[dlen++] = 0;
QByteArray step1(16);
step1 = ComputeMD5Sum(&data);
rc4_init(&rc4, reinterpret_cast<uchar*>(step1.data()), QMIN(KeyLen+5, 16));
rc4_encrypt(&rc4, reinterpret_cast<uchar*>(in.data()), reinterpret_cast<uchar*>(out.data()), in.size());
return out;
}
 
QString PDFlib::EncString(const QString & in, int ObjNum)
{
if (!Options.Encrypt)
1573,17 → 1602,20
if (Options.Thumbnails)
{
ScImage img = pm.convertToImage();
QString im = img.ImageToTxt();
QByteArray array = img.ImageToArray();
if ((Options.Compress) && (CompAvail))
im = CompressStr(&im);
array = CompressArray(&array);
StartObj(ObjCounter);
PutDoc("<<\n/Width "+QString::number(img.width())+"\n");
PutDoc("/Height "+QString::number(img.height())+"\n");
PutDoc("/ColorSpace /DeviceRGB\n/BitsPerComponent 8\n");
PutDoc("/Length "+QString::number(im.length()+1)+"\n");
PutDoc("/Length "+QString::number(array.size()+1)+"\n");
if ((Options.Compress) && (CompAvail))
PutDoc("/Filter /FlateDecode\n");
PutDoc(">>\nstream\n"+EncStream(im, ObjCounter)+"\nendstream\nendobj\n");
PutDoc(">>\nstream\n");
PutDoc(EncStreamArray(array, ObjCounter));
PutDoc("\nendstream\nendobj\n");
Seite.Thumb = ObjCounter;
ObjCounter++;
}
4108,19 → 4140,19
if (!ite->Pfile2.isEmpty())
{
img.LoadPicture(ite->Pfile2, "", 0, false, false, 1, 72);
QString im = "";
QByteArray im;
im = img3.getAlpha(ite->Pfile2, true, false);
IconOb += !im.isEmpty() ? 3 : 2;
im = "";
im.resize(0);
PutDoc("/IX "+QString::number(ObjCounter+IconOb-1)+" 0 R ");
}
if (!ite->Pfile3.isEmpty())
{
img2.LoadPicture(ite->Pfile3, "", 0, false, false, 1, 72);
QString im = "";
QByteArray im;
im = img3.getAlpha(ite->Pfile3, true, false);
IconOb += !im.isEmpty() ? 3 : 2;
im = "";
im.resize(0);
PutDoc("/RI "+QString::number(ObjCounter+IconOb-1)+" 0 R ");
}
PutDoc("/TP "+QString::number(ite->annotation().IPlace())+" ");
4505,12 → 4537,13
QFileInfo fi = QFileInfo(fn);
QString ext = fi.extension(false).lower();
ScImage img;
QString im, tmp, tmpy, dummy, cmd1, cmd2, BBox;
QByteArray im;
QString tmp, tmpy, dummy, cmd1, cmd2, BBox;
QChar tc;
bool found = false;
bool alphaM = false;
bool realCMYK = false;
int afl;
int afl = 72;
double x2, ax, ay, a2, a1;
double sxn = 0;
double syn = 0;
4701,7 → 4734,7
int components = 0;
StartObj(ObjCounter);
ObjCounter++;
QString dataP = "";
QByteArray dataP;
struct ICCD dataD;
if ((Embedded) && (!Options.EmbeddedI))
{
4710,12 → 4743,12
{
if (img.imgInfo.colorspace == 1)
{
loadText((Embedded ? ScMW->InputProfilesCMYK[Options.ImageProf] : ScMW->InputProfilesCMYK[Profil]), &dataP);
loadRawBytes((Embedded ? ScMW->InputProfilesCMYK[Options.ImageProf] : ScMW->InputProfilesCMYK[Profil]), dataP);
components = 4;
}
else
{
loadText((Embedded ? ScMW->InputProfiles[Options.ImageProf] : ScMW->InputProfiles[Profil]), &dataP);
loadRawBytes((Embedded ? ScMW->InputProfiles[Options.ImageProf] : ScMW->InputProfiles[Profil]), dataP);
components = 3;
}
}
4724,12 → 4757,12
{
if (img.imgInfo.colorspace == 1)
{
loadText((Embedded ? ScMW->InputProfilesCMYK[Options.ImageProf] : ScMW->InputProfilesCMYK[Profil]), &dataP);
loadRawBytes((Embedded ? ScMW->InputProfilesCMYK[Options.ImageProf] : ScMW->InputProfilesCMYK[Profil]), dataP);
components = 4;
}
else
{
loadText((Embedded ? ScMW->InputProfiles[Options.ImageProf] : ScMW->InputProfiles[Profil]), &dataP);
loadRawBytes((Embedded ? ScMW->InputProfiles[Options.ImageProf] : ScMW->InputProfiles[Profil]), dataP);
components = 3;
}
}
4737,11 → 4770,13
if ((Options.CompressMethod != 3) && (CompAvail))
{
PutDoc("/Filter /FlateDecode\n");
dataP = CompressStr(&dataP);
dataP = CompressArray(&dataP);
}
PutDoc("/Length "+QString::number(dataP.length()+1)+"\n");
PutDoc("/Length "+QString::number(dataP.size()+1)+"\n");
PutDoc("/N "+QString::number(components)+"\n");
PutDoc(">>\nstream\n"+EncStream(dataP, ObjCounter-1)+"\nendstream\nendobj\n");
PutDoc(">>\nstream\n");
PutDoc(EncStreamArray(dataP, ObjCounter-1));
PutDoc("\nendstream\nendobj\n");
StartObj(ObjCounter);
dataD.ResName = ResNam+QString::number(ResCount);
dataD.ICCArray = "[ /ICCBased "+QString::number(ObjCounter-1)+" 0 R ]";
4754,7 → 4789,7
}
}
#endif
QString im2 = "";
QByteArray im2;
ScImage img2;
if (Options.Version >= 14)
im2 = img2.getAlpha(fn, true, true, afl);
4788,30 → 4823,32
if (Options.Version >= 14)
{
if ((Options.CompressMethod != 3) && (CompAvail))
im2 = CompressStr(&im2);
im2 = CompressArray(&im2);
PutDoc("/Width "+QString::number(origWidth)+"\n");
PutDoc("/Height "+QString::number(origHeight)+"\n");
PutDoc("/ColorSpace /DeviceGray\n");
PutDoc("/BitsPerComponent 8\n");
PutDoc("/Length "+QString::number(im2.length())+"\n");
PutDoc("/Length "+QString::number(im2.size())+"\n");
}
else
{
if ((Options.CompressMethod != 3) && (CompAvail))
im2 = CompressStr(&im2);
im2 = CompressArray(&im2);
PutDoc("/Width "+QString::number(origWidth)+"\n");
PutDoc("/Height "+QString::number(origHeight)+"\n");
PutDoc("/ImageMask true\n/BitsPerComponent 1\n");
PutDoc("/Length "+QString::number(im2.length())+"\n");
PutDoc("/Length "+QString::number(im2.size())+"\n");
}
if ((Options.CompressMethod != 3) && (CompAvail))
PutDoc("/Filter /FlateDecode\n");
PutDoc(">>\nstream\n"+EncStream(im2, ObjCounter-1)+"\nendstream\nendobj\n");
PutDoc(">>\nstream\n");
PutDoc(EncStreamArray(im2, ObjCounter-1));
PutDoc("\nendstream\nendobj\n");
Seite.ImgObjects[ResNam+QString::number(ResCount)] = ObjCounter-1;
ResCount++;
}
if (Options.UseRGB)
im = img.ImageToTxt();
im = img.ImageToArray();
else
{
if (Options.isGrayscale)
4820,7 → 4857,7
{
#ifdef HAVE_CMS
if ((CMSuse) && (Options.UseProfiles2) && (!realCMYK))
im = img.ImageToTxt();
im = img.ImageToArray();
else
#endif
im = img.ImageToCMYK_PDF(true);
4829,7 → 4866,7
StartObj(ObjCounter);
ObjCounter++;
if (((Options.CompressMethod == 2) || (Options.CompressMethod == 0)) && (CompAvail))
im = CompressStr(&im);
im = CompressArray(&im);
PutDoc("<<\n/Type /XObject\n/Subtype /Image\n");
PutDoc("/Width "+QString::number(img.width())+"\n");
PutDoc("/Height "+QString::number(img.height())+"\n");
4865,14 → 4902,14
{
if (((Options.UseRGB || Options.UseProfiles2) && (cm == 0) && (c->effectsInUse.count() == 0) && (img.imgInfo.colorspace == 0)) && (!img.imgInfo.progressive) && (!((Options.RecalcPic) && (Options.PicRes < (QMAX(72.0 / c->imageXScale(), 72.0 / c->imageYScale()))))))
{
im = "";
loadText(fn, &im);
im.resize(0);
loadRawBytes(fn, im);
cm = 1;
}
else if (((!Options.UseRGB) && (!Options.isGrayscale) && (!Options.UseProfiles2)) && (cm== 0) && (c->effectsInUse.count() == 0) && (img.imgInfo.colorspace == 1) && (!((Options.RecalcPic) && (Options.PicRes < (QMAX(72.0 / c->imageXScale(), 72.0 / c->imageYScale()))))) && (!img.imgInfo.progressive))
{
im = "";
loadText(fn, &im);
im.resize(0);
loadRawBytes(fn, im);
cm = 1;
specialCMYK = true;
}
4893,8 → 4930,8
specialCMYK = true;
}
}
im = "";
loadText(tmpFile, &im);
im.resize(0);
loadRawBytes(tmpFile, im);
cm = 1;
QFile::remove(tmpFile);
}
4922,10 → 4959,10
if (Options.CompressMethod == 0)
{
QFileInfo fi(tmpFile);
if (fi.size() < im.length())
if (fi.size() < im.size())
{
im = "";
loadText(tmpFile, &im);
im.resize(0);
loadRawBytes(tmpFile, im);
cm = 1;
}
else
4933,8 → 4970,8
}
else
{
im = "";
loadText(tmpFile, &im);
im.resize(0);
loadRawBytes(tmpFile, im);
cm = 1;
}
QFile::remove(tmpFile);
4941,7 → 4978,7
}
}
PutDoc("/BitsPerComponent 8\n");
PutDoc("/Length "+QString::number(im.length())+"\n");
PutDoc("/Length "+QString::number(im.size())+"\n");
if (CompAvail)
{
if (cm == 1)
4958,7 → 4995,9
else
PutDoc("/Mask "+QString::number(ObjCounter-2)+" 0 R\n");
}
PutDoc(">>\nstream\n"+EncStream(im, ObjCounter-1)+"\nendstream\nendobj\n");
PutDoc(">>\nstream\n");
PutDoc(EncStreamArray(im, ObjCounter-1));
PutDoc("\nendstream\nendobj\n");
// }
Seite.ImgObjects[ResNam+QString::number(ResCount)] = ObjCounter-1;
ImRes = ResCount;
/branches/Version13x/Scribus/scribus/pdflib.h
76,6 → 76,7
void closeAndCleanup();
 
QString EncStream(const QString & in, int ObjNum);
QByteArray EncStreamArray(const QByteArray & in, int ObjNum);
QString EncString(const QString & in, int ObjNum);
void CalcOwnerKey(const QString & Owner, const QString & User);
void CalcUserKey(const QString & User, int Permission);
/branches/Version13x/Scribus/scribus/scimage.cpp
851,14 → 851,13
delete [] row_pointer[0];
}
 
QString ScImage::ImageToTxt()
QByteArray ScImage::ImageToArray()
{
int i = 0;
int h = height();
int w = width();
unsigned char u;
QString ImgStr = "";
ImgStr.reserve(3 * h * w);
QByteArray imgArray(3 * h * w);
for( int yi=0; yi < h; ++yi )
{
QRgb * s = (QRgb*)(scanLine( yi ));
866,23 → 865,22
{
QRgb r=*s++;
u=qRed(r);
ImgStr[i++] = u;
imgArray[i++] = u;
u=qGreen(r);
ImgStr[i++] = u;
imgArray[i++] = u;
u=qBlue(r);
ImgStr[i++] = u;
imgArray[i++] = u;
}
}
return ImgStr;
return imgArray;
}
 
QString ScImage::ImageToGray()
QByteArray ScImage::ImageToGray()
{
int i = 0;
int h = height();
int w = width();
QString ImgStr = "";
ImgStr.reserve( h * w);
QByteArray imgArray(h * w);
for( int yi=0; yi < h; ++yi )
{
QRgb * s = (QRgb*)(scanLine( yi ));
891,20 → 889,19
QRgb r=*s;
int k = QMIN(qRound(0.3 * qRed(r) + 0.59 * qGreen(r) + 0.11 * qBlue(r)), 255);
*s = qRgba(k, 0, 0, 0);
ImgStr[i++] = k;
imgArray[i++] = k;
s++;
}
}
return ImgStr;
return imgArray;
}
 
QString ScImage::ImageToCMYK_PDF(bool pre)
QByteArray ScImage::ImageToCMYK_PDF(bool pre)
{
int i = 0;
int h = height();
int w = width();
QString ImgStr = "";
ImgStr.reserve( 4 * h * w );
QByteArray imgArray( 4 * h * w );
if (pre)
{
for( int yi=0; yi < h; ++yi )
917,11 → 914,10
int m = qGreen(r);
int y = qBlue(r);
int k = qAlpha(r);
/* *s = qRgba(m, y, k, c); */
ImgStr[i++] = static_cast<unsigned char> (c);
ImgStr[i++] = static_cast<unsigned char> (m);
ImgStr[i++] = static_cast<unsigned char> (y);
ImgStr[i++] = static_cast<unsigned char> (k);
imgArray[i++] = static_cast<unsigned char> (c);
imgArray[i++] = static_cast<unsigned char> (m);
imgArray[i++] = static_cast<unsigned char> (y);
imgArray[i++] = static_cast<unsigned char> (k);
s++;
}
}
938,29 → 934,27
int m = 255 - qGreen(r);
int y = 255 - qBlue(r);
int k = QMIN(QMIN(c, m), y);
// *s = qRgba(m, y, k, c);
// *s = qRgba(c, m, y, k);
ImgStr[i++] = static_cast<unsigned char> (c - k);
ImgStr[i++] = static_cast<unsigned char> (m - k);
ImgStr[i++] = static_cast<unsigned char> (y - k);
ImgStr[i++] = static_cast<unsigned char> (k);
imgArray[i++] = static_cast<unsigned char> (c - k);
imgArray[i++] = static_cast<unsigned char> (m - k);
imgArray[i++] = static_cast<unsigned char> (y - k);
imgArray[i++] = static_cast<unsigned char> (k);
s++;
}
}
}
return ImgStr;
return imgArray;
}
 
QString ScImage::ImageToCMYK_PS(int pl, bool pre)
QByteArray ScImage::ImageToCMYK_PS(int pl, bool pre)
{
int i = 0;
int h = height();
int w = width();
QString ImgStr = "";
QByteArray imgArray;
if(pl == -1)
ImgStr.reserve(4 * h * w);
imgArray.resize(4 * h * w);
else
ImgStr.reserve(h * w);
imgArray.resize(h * w);
if (pre)
{
for( int yi=0; yi < h; ++yi )
975,23 → 969,23
int k = qAlpha(r);
if (pl == -1)
{
ImgStr[i++] = static_cast<unsigned char> (c);
ImgStr[i++] = static_cast<unsigned char> (m);
ImgStr[i++] = static_cast<unsigned char> (y);
ImgStr[i++] = static_cast<unsigned char> (k);
imgArray[i++] = static_cast<unsigned char> (c);
imgArray[i++] = static_cast<unsigned char> (m);
imgArray[i++] = static_cast<unsigned char> (y);
imgArray[i++] = static_cast<unsigned char> (k);
}
else
{
if (pl == -2)
ImgStr[i++] = static_cast<unsigned char> (QMIN(255, qRound(0.3 * c + 0.59 * m + 0.11 * y + k)));
imgArray[i++] = static_cast<unsigned char> (QMIN(255, qRound(0.3 * c + 0.59 * m + 0.11 * y + k)));
if (pl == 1)
ImgStr[i++] = static_cast<unsigned char> (c);
imgArray[i++] = static_cast<unsigned char> (c);
if (pl == 2)
ImgStr[i++] = static_cast<unsigned char> (m);
imgArray[i++] = static_cast<unsigned char> (m);
if (pl == 3)
ImgStr[i++] = static_cast<unsigned char> (y);
imgArray[i++] = static_cast<unsigned char> (y);
if (pl == 0)
ImgStr[i++] = static_cast<unsigned char> (k);
imgArray[i++] = static_cast<unsigned char> (k);
}
}
}
1010,28 → 1004,28
int k = QMIN(QMIN(c, m), y);
if (pl == -1)
{
ImgStr[i++] = static_cast<unsigned char> (c - k);
ImgStr[i++] = static_cast<unsigned char> (m - k);
ImgStr[i++] = static_cast<unsigned char> (y - k);
ImgStr[i++] = static_cast<unsigned char> (k);
imgArray[i++] = static_cast<unsigned char> (c - k);
imgArray[i++] = static_cast<unsigned char> (m - k);
imgArray[i++] = static_cast<unsigned char> (y - k);
imgArray[i++] = static_cast<unsigned char> (k);
}
else
{
if (pl == -2)
ImgStr[i++] = static_cast<unsigned char> (QMIN(255, qRound(0.3 * c + 0.59 * m + 0.11 * y + k)));
imgArray[i++] = static_cast<unsigned char> (QMIN(255, qRound(0.3 * c + 0.59 * m + 0.11 * y + k)));
if (pl == 1)
ImgStr[i++] = static_cast<unsigned char> (c - k);
imgArray[i++] = static_cast<unsigned char> (c - k);
if (pl == 2)
ImgStr[i++] = static_cast<unsigned char> (m - k);
imgArray[i++] = static_cast<unsigned char> (m - k);
if (pl == 3)
ImgStr[i++] = static_cast<unsigned char> (y - k);
imgArray[i++] = static_cast<unsigned char> (y - k);
if (pl == 0)
ImgStr[i++] = static_cast<unsigned char> (k);
imgArray[i++] = static_cast<unsigned char> (k);
}
}
}
}
return ImgStr;
return imgArray;
}
 
// Check that the header is a valid PSD.
2841,9 → 2835,9
return;
}
 
QString ScImage::getAlpha(QString fn, bool PDF, bool pdf14, int gsRes)
QByteArray ScImage::getAlpha(QString fn, bool PDF, bool pdf14, int gsRes)
{
QString retS = "";
QByteArray retArray;
float xres, yres;
short resolutionunit = 0;
imgInfo.valid = false;
2852,13 → 2846,13
imgInfo.layerInfo.clear();
QFileInfo fi = QFileInfo(fn);
if (!fi.exists())
return retS;
return retArray;
QString tmp, BBox, tmp2;
QString ext = fi.extension(false).lower();
QString tmpFile = QDir::convertSeparators(QDir::homeDirPath()+"/.scribus/sc.png");
QString picFile = QDir::convertSeparators(fn);
if ((ext == "jpg") || (ext == "jpeg"))
return retS;
return retArray;
double x, y, b, h;
bool found = false;
int retg = -1;
2992,7 → 2986,7
if (photometric == PHOTOMETRIC_SEPARATED)
{
TIFFClose(tif);
return retS;
return retArray;
}
else
{
3029,18 → 3023,18
s >> header;
// Check image file format.
if( s.atEnd() || !IsValid( header ) )
return retS;
return retArray;
// Check if it's a supported format.
if( !IsSupported( header ) )
return retS;
return retArray;
if (header.color_mode == CM_CMYK)
return retS;
return retArray;
if( !LoadPSD(s, header) )
return retS;
return retArray;
f.close();
}
else
return retS;
return retArray;
}
else
{
3050,13 → 3044,13
if (hasAlphaBuffer())
setAlphaBuffer(true);
else
return retS;
return retArray;
}
else
return retS;
return retArray;
}
if (isNull())
return retS;
return retArray;
int i = 0;
unsigned char u;
int hm = height();
3064,7 → 3058,7
int w2;
if (pdf14)
{
retS.reserve(hm * wm);
retArray.resize(hm * wm);
for( int yi=0; yi < hm; ++yi )
{
QRgb * s = (QRgb*)(scanLine( yi ));
3072,7 → 3066,7
{
QRgb r=*s++;
u=qAlpha(r);
retS[i++] = u;
retArray[i++] = u;
}
}
}
3084,7 → 3078,7
w2 = wm / 8;
if ((wm % 8) != 0)
w2++;
retS.reserve(hm * w2);
retArray.resize(hm * w2);
for( int yi=0; yi < hm; ++yi )
{
uchar * s = iMask.scanLine( yi );
3092,11 → 3086,11
{
u = *(s+xi);
if(PDF) u = ~u;
retS[i++] = u;
retArray[i++] = u;
}
}
}
return retS;
return retArray;
}
 
#define ICC_MARKER (JPEG_APP0 + 2) /* JPEG marker code for ICC */
3373,6 → 3367,134
#endif // HAVE_CMS
}
 
void ScImage::getEmbeddedProfile(const QString & fn, QByteArray *profile, int *components)
{
Q_ASSERT(profile);
Q_ASSERT(components);
#ifdef HAVE_CMS
cmsHPROFILE tiffProf = 0;
QFileInfo fi = QFileInfo(fn);
if (!fi.exists())
return;
QString ext = fi.extension(false).lower();
iccbuf = 0;
icclen = 0;
if (ext == "psd")
{
QFile f(fn);
if (f.open(IO_ReadOnly))
{
imgInfo.xres = 72;
imgInfo.yres = 72;
QDataStream s( &f );
s.setByteOrder( QDataStream::BigEndian );
PSDHeader header;
s >> header;
// Check image file format.
if( s.atEnd() || !IsValid( header ) )
return;
// Check if it's a supported format.
if( !IsSupported( header ) )
return;
if( !LoadPSD(s, header) )
return;
if (icclen > 0)
{
tiffProf = cmsOpenProfileFromMem(iccbuf, icclen);
if (tiffProf)
{
if (static_cast<int>(cmsGetColorSpace(tiffProf)) == icSigRgbData)
*components = 3;
if (static_cast<int>(cmsGetColorSpace(tiffProf)) == icSigCmykData)
*components = 4;
profile->resize(icclen);
for (uint el = 0; el < icclen; ++el)
(*profile)[el] = iccbuf[el];
}
cmsCloseProfile(tiffProf);
free(iccbuf);
}
f.close();
}
else
return;
}
#ifdef HAVE_TIFF
else if ((ext == "tif") || (ext == "tiff"))
{
TIFF* tif = TIFFOpen(fn.local8Bit(), "r");
if(tif)
{
DWORD EmbedLen = 0;
LPBYTE EmbedBuffer;
if (TIFFGetField(tif, TIFFTAG_ICCPROFILE, &EmbedLen, &EmbedBuffer))
{
tiffProf = cmsOpenProfileFromMem(EmbedBuffer, EmbedLen);
if (tiffProf)
{
if (static_cast<int>(cmsGetColorSpace(tiffProf)) == icSigRgbData)
*components = 3;
if (static_cast<int>(cmsGetColorSpace(tiffProf)) == icSigCmykData)
*components = 4;
profile->resize(EmbedLen);
for (uint el = 0; el < EmbedLen; ++el)
(*profile)[el] = EmbedBuffer[el];
}
cmsCloseProfile(tiffProf);
}
TIFFClose(tif);
}
}
#endif // HAVE_TIFF
else if ((ext == "jpg") || (ext == "jpeg"))
{
struct jpeg_decompress_struct cinfo;
struct my_error_mgr jerr;
FILE *infile;
cinfo.err = jpeg_std_error (&jerr.pub);
jerr.pub.error_exit = my_error_exit;
infile = NULL;
if (setjmp (jerr.setjmp_buffer))
{
jpeg_destroy_decompress (&cinfo);
if (infile)
fclose (infile);
return;
}
jpeg_create_decompress (&cinfo);
if ((infile = fopen (fn.local8Bit(), "rb")) == NULL)
return;
jpeg_stdio_src(&cinfo, infile);
jpeg_save_markers(&cinfo, ICC_MARKER, 0xFFFF);
jpeg_read_header(&cinfo, true);
jpeg_start_decompress(&cinfo);
unsigned int EmbedLen = 0;
unsigned char* EmbedBuffer;
if (read_jpeg_marker(ICC_MARKER,&cinfo, &EmbedBuffer, &EmbedLen))
{
tiffProf = cmsOpenProfileFromMem(EmbedBuffer, EmbedLen);
if (tiffProf)
{
if (static_cast<int>(cmsGetColorSpace(tiffProf)) == icSigRgbData)
*components = 3;
if (static_cast<int>(cmsGetColorSpace(tiffProf)) == icSigCmykData)
*components = 4;
profile->resize(EmbedLen);
for (uint el = 0; el < EmbedLen; ++el)
(*profile)[el] = EmbedBuffer[el];
}
cmsCloseProfile(tiffProf);
free(EmbedBuffer);
}
(void) jpeg_finish_decompress(&cinfo);
fclose (infile);
jpeg_destroy_decompress (&cinfo);
}
else
return;
#endif // HAVE_CMS
}
 
bool ScImage::LoadPicture(const QString & fn, const QString & Prof,
int rend, bool useEmbedded, bool useProf,
int requestType, int gsRes, bool *realCMYK)
/branches/Version13x/Scribus/scribus/util.h
54,6 → 54,7
char SCRIBUS_API *toHex( uchar u );
QString SCRIBUS_API String2Hex(QString *in, bool lang = true);
QString SCRIBUS_API CompressStr(QString *in);
QByteArray SCRIBUS_API CompressArray(QByteArray *in);
void SCRIBUS_API Level2Layer(ScribusDoc *currentDoc, struct Layer *ll, int Level);
//int Layer2Level(ScribusDoc *currentDoc, int LayerNr);
void SCRIBUS_API BezierPoints(QPointArray *ar, QPoint n1, QPoint n2, QPoint n3, QPoint n4);
89,6 → 90,7
There is no need to preallocate the buffer, and the new data replaces any
old contents. */
bool SCRIBUS_API loadRawText(const QString & filename, QCString & buf);
bool SCRIBUS_API loadRawBytes(const QString & filename, QByteArray & buf);
QString SCRIBUS_API GetAttr(QDomElement *el, QString at, QString def="0");
QImage SCRIBUS_API ProofImage(QImage *Im);
/**
/branches/Version13x/Scribus/scribus/pslib.cpp
242,6 → 242,48
t.writeRawBytes(c, c.length());
}
 
void PSLib::PutSeite(QByteArray& array, bool hexEnc)
{
QTextStream t(&Spool);
if(hexEnc)
{
int length = 0;
for (int i = 0; i < array.size(); i++)
{
length++;
t << toHex(array[i]);
if ( length > 40 )
{
t << "\n";
length = 0;
}
}
}
else
t.writeRawBytes(array, array.size());
}
 
void PSLib::PutSeite(const char* array, int length, bool hexEnc)
{
QTextStream t(&Spool);
if(hexEnc)
{
int len = 0;
for (int i = 0; i < length; i++)
{
len++;
t << toHex(array[i]);
if ( len > 40 )
{
t << "\n";
len = 0;
}
}
}
else
t.writeRawBytes(array, length);
}
 
void PSLib::PutDoc(QString c)
{
QTextStream t(&Spool);
248,6 → 290,48
t.writeRawBytes(c, c.length());
}
 
void PSLib::PutDoc(QByteArray& array, bool hexEnc)
{
QTextStream t(&Spool);
if(hexEnc)
{
int length = 0;
for (int i = 0; i < array.size(); i++)
{
length++;
t << toHex(array[i]);
if ( length > 40 )
{
t << "\n";
length = 0;
}
}
}
else
t.writeRawBytes(array, array.size());
}
 
void PSLib::PutDoc(const char* array, int length, bool hexEnc)
{
QTextStream t(&Spool);
if(hexEnc)
{
int len = 0;
for (int i = 0; i < length; i++)
{
len++;
t << toHex(array[i]);
if ( len > 40 )
{
t << "\n";
len = 0;
}
}
}
else
t.writeRawBytes(array, length);
}
 
QString PSLib::ToStr(double c)
{
QString cc;
677,31 → 761,32
void PSLib::PS_ImageData(PageItem *c, QString fn, QString Name, QString Prof, bool UseEmbedded, bool UseProf)
{
bool dummy;
QString tmp;
QCString tmp;
QFileInfo fi = QFileInfo(fn);
QString ext = fi.extension(false).lower();
if (ext == "eps")
{
if (loadText(fn, &tmp))
if (loadRawText(fn, tmp))
{
PutSeite("currentfile 1 (%ENDEPSDATA) /SubFileDecode filter /ReusableStreamDecode filter\n");
PutSeite("%%BeginDocument: " + fi.fileName() + "\n");
if (getDouble(tmp.mid(0, 4), true) == 0xC5D0D3C6)
if (getDouble(QString(tmp.mid(0, 4)), true) == 0xC5D0D3C6)
{
uint startPos = getDouble(tmp.mid(4, 4), false);
uint length = getDouble(tmp.mid(8, 4), false);
PutSeite(tmp.mid(startPos, length)+"\n");
char* data = tmp.data();
uint startPos = getDouble(QString(tmp.mid(4, 4)), false);
uint length = getDouble(QString(tmp.mid(8, 4)), false);
PutSeite(data+startPos, length, false);
}
else
PutSeite(tmp+"\n");
PutSeite("%ENDEPSDATA\n");
PutSeite(tmp, false);
PutSeite("\n%ENDEPSDATA\n");
PutSeite("%%EndDocument\n");
PutSeite("/"+PSEncode(Name)+"Bild exch def\n");
}
return;
}
QString ImgStr = "";
ScImage image;
QByteArray imgArray;
image.imgInfo.valid = false;
image.imgInfo.clipPath = "";
image.imgInfo.PDSpathData.clear();
710,32 → 795,30
image.imgInfo.isRequest = c->pixm.imgInfo.isRequest;
image.LoadPicture(fn, Prof, 0, UseEmbedded, UseProf, 0, 300, &dummy);
image.applyEffect(c->effectsInUse, colorsToUse, true);
ImgStr = image.ImageToCMYK_PS(-1, true);
imgArray = image.ImageToCMYK_PS(-1, true);
if (CompAvail)
{
PutSeite("currentfile /ASCIIHexDecode filter /FlateDecode filter /ReusableStreamDecode filter\n");
ImgStr = CompressStr(&ImgStr);
imgArray = CompressArray(&imgArray);
}
else
PutSeite("currentfile /ASCIIHexDecode filter /ReusableStreamDecode filter\n");
ImgStr = String2Hex(&ImgStr);
PutSeite(ImgStr);
PutSeite(imgArray, true);
PutSeite("\n>\n");
PutSeite("/"+PSEncode(Name)+"Bild exch def\n");
ImgStr = "";
QString iMask = "";
iMask = image.getAlpha(fn, false, false);
if (!iMask.isEmpty())
imgArray.resize(0);
QByteArray maskArray;
maskArray = image.getAlpha(fn, false, false);
if (maskArray.size() > 0)
{
if (CompAvail)
{
PutSeite("currentfile /ASCIIHexDecode filter /FlateDecode filter /ReusableStreamDecode filter\n");
iMask = CompressStr(&iMask);
maskArray = CompressArray(&maskArray);
}
else
PutSeite("currentfile /ASCIIHexDecode filter /ReusableStreamDecode filter\n");
iMask = String2Hex(&iMask);
PutSeite(iMask);
PutSeite(maskArray, true);
PutSeite("\n>\n");
PutSeite("/"+PSEncode(Name)+"Mask exch def\n");
}
744,12 → 827,12
void PSLib::PS_image(PageItem *c, double x, double y, QString fn, double scalex, double scaley, QString Prof, bool UseEmbedded, bool UseProf, QString Name)
{
bool dummy;
QString tmp;
QCString tmp;
QFileInfo fi = QFileInfo(fn);
QString ext = fi.extension(false).lower();
if (ext == "eps")
{
if (loadText(fn, &tmp))
if (loadRawText(fn, tmp))
{
PutSeite("bEPS\n");
PutSeite(ToStr(PrefsManager::instance()->appPrefs.gs_Resolution / 72.0 * scalex) + " " + ToStr(PrefsManager::instance()->appPrefs.gs_Resolution / 72.0 * scaley) + " sc\n");
762,15 → 845,16
else
{
PutSeite("%%BeginDocument: " + fi.fileName() + "\n");
if (getDouble(tmp.mid(0, 4), true) == 0xC5D0D3C6)
if (getDouble(QString(tmp.mid(0, 4)), true) == 0xC5D0D3C6)
{
char* data = tmp.data();
uint startPos = getDouble(tmp.mid(4, 4), false);
uint length = getDouble(tmp.mid(8, 4), false);
PutSeite(tmp.mid(startPos, length)+"\n");
PutSeite(data+startPos, length, false);
}
else
PutSeite(tmp+"\n");
PutSeite("%%EndDocument\n");
PutSeite(tmp);
PutSeite("\n%%EndDocument\n");
}
PutSeite("eEPS\n");
}
777,8 → 861,8
}
else
{
QString ImgStr = "";
ScImage image;
QByteArray imgArray;
image.imgInfo.valid = false;
image.imgInfo.clipPath = "";
image.imgInfo.PDSpathData.clear();
797,38 → 881,36
PutSeite(ToStr(x*scalex) + " " + ToStr(y*scaley) + " tr\n");
PutSeite(ToStr(scalex*w) + " " + ToStr(scaley*h) + " sc\n");
PutSeite(((!DoSep) && (!GraySc)) ? "/DeviceCMYK setcolorspace\n" : "/DeviceGray setcolorspace\n");
QString iMask = "";
QByteArray maskArray;
ScImage img2;
iMask = img2.getAlpha(fn, false, false);
if (!iMask.isEmpty())
maskArray = img2.getAlpha(fn, false, false);
if (maskArray.size() > 0)
{
if (DoSep)
ImgStr = image.ImageToCMYK_PS(Plate, true);
imgArray = image.ImageToCMYK_PS(Plate, true);
else
ImgStr = GraySc ? image.ImageToCMYK_PS( -2, true) : image.ImageToCMYK_PS(-1, true);
imgArray = GraySc ? image.ImageToCMYK_PS( -2, true) : image.ImageToCMYK_PS(-1, true);
if (Name.isEmpty())
{
if (CompAvail)
{
PutSeite("currentfile /ASCIIHexDecode filter /FlateDecode filter /ReusableStreamDecode filter\n");
ImgStr = CompressStr(&ImgStr);
imgArray = CompressArray(&imgArray);
}
else
PutSeite("currentfile /ASCIIHexDecode filter /ReusableStreamDecode filter\n");
ImgStr = String2Hex(&ImgStr);
PutSeite(ImgStr);
ImgStr = "";
PutSeite(imgArray, true);
imgArray.resize(0);
PutSeite("\n>\n");
PutSeite("/Bild exch def\n");
if (CompAvail)
{
PutSeite("currentfile /ASCIIHexDecode filter /FlateDecode filter /ReusableStreamDecode filter\n");
iMask = CompressStr(&iMask);
maskArray = CompressArray(&maskArray);
}
else
PutSeite("currentfile /ASCIIHexDecode filter /ReusableStreamDecode filter\n");
iMask = String2Hex(&iMask);
PutSeite(iMask);
PutSeite(maskArray, true);
PutSeite("\n>\n");
PutSeite("/Mask exch def\n");
}
897,13 → 979,12
" /DataSource currentfile /ASCIIHexDecode filter >>\n");
PutSeite("image\n");
if (DoSep)
ImgStr = image.ImageToCMYK_PS(Plate, true);
imgArray = image.ImageToCMYK_PS(Plate, true);
else
ImgStr = GraySc ? image.ImageToCMYK_PS(-2, true) : image.ImageToCMYK_PS(-1, true);
imgArray = GraySc ? image.ImageToCMYK_PS(-2, true) : image.ImageToCMYK_PS(-1, true);
if (CompAvail)
ImgStr = CompressStr(&ImgStr);
ImgStr = String2Hex(&ImgStr);
PutSeite(ImgStr);
imgArray = CompressArray(&imgArray);
PutSeite(imgArray, true);
PutSeite("\n>\n");
}
}