0.1.1
by Oleksandr Moskalenko
Import upstream version 1.3.4.dfsg+svn20071115 |
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 |
#include <qfile.h> |
|
8 |
#include <qfileinfo.h> |
|
9 |
#include "scimgdataloader_gimp.h" |
|
10 |
||
11 |
ScImgDataLoader_GIMP::ScImgDataLoader_GIMP(void) : ScImgDataLoader() |
|
12 |
{
|
|
13 |
initSupportedFormatList(); |
|
14 |
}
|
|
15 |
||
16 |
void ScImgDataLoader_GIMP::initSupportedFormatList(void) |
|
17 |
{
|
|
18 |
m_supportedFormats.clear(); |
|
19 |
m_supportedFormats.append( "pat" ); |
|
20 |
}
|
|
21 |
||
22 |
void ScImgDataLoader_GIMP::loadEmbeddedProfile(const QString& fn) |
|
23 |
{
|
|
24 |
m_embeddedProfile.resize(0); |
|
25 |
m_profileComponents = 0; |
|
26 |
}
|
|
27 |
||
28 |
bool ScImgDataLoader_GIMP::loadPicture(const QString& fn, int /*res*/, bool /*thumbnail*/) |
|
29 |
{
|
|
30 |
if (!QFile::exists(fn)) |
|
31 |
return false; |
|
32 |
initialize(); |
|
33 |
QFile f(fn); |
|
34 |
if (f.open(IO_ReadOnly)) |
|
35 |
{
|
|
36 |
QDataStream s( &f ); |
|
37 |
s.setByteOrder( QDataStream::BigEndian ); |
|
38 |
uint headersize, versionInfo, patternWidth, patternHeight, patternType; |
|
39 |
uchar chData, alpha, r, g, b; |
|
40 |
uchar magicKey[4]; |
|
41 |
s >> headersize; |
|
42 |
s >> versionInfo; |
|
43 |
s >> patternWidth; |
|
44 |
s >> patternHeight; |
|
45 |
s >> patternType; |
|
46 |
QString magic = ""; |
|
47 |
for( int i = 0; i < 4; i++ ) |
|
48 |
{
|
|
49 |
s >> magicKey[i]; |
|
50 |
magic += QChar(magicKey[i]); |
|
51 |
}
|
|
52 |
if (magic != "GPAT") |
|
53 |
return false; |
|
54 |
s.device()->at( headersize ); |
|
55 |
if( !m_image.create( patternWidth, patternHeight, 32 )) |
|
56 |
return false; |
|
57 |
m_image.setAlphaBuffer( true ); |
|
58 |
QRgb *d; |
|
59 |
for (uint y = 0; y < patternHeight; y++) |
|
60 |
{
|
|
61 |
d = (QRgb*)(m_image.scanLine( y )); |
|
62 |
if (patternType == 1) |
|
63 |
{
|
|
64 |
for (uint x = 0; x < patternWidth; x++) |
|
65 |
{
|
|
66 |
s >> chData; |
|
67 |
*d = qRgba(chData, chData, chData, 255); |
|
68 |
d++; |
|
69 |
}
|
|
70 |
}
|
|
71 |
else if (patternType == 2) |
|
72 |
{
|
|
73 |
for (uint x = 0; x < patternWidth; x++) |
|
74 |
{
|
|
75 |
s >> chData; |
|
76 |
s >> alpha; |
|
77 |
*d = qRgba(chData, chData, chData, alpha); |
|
78 |
d++; |
|
79 |
}
|
|
80 |
}
|
|
81 |
else if (patternType == 3) |
|
82 |
{
|
|
83 |
for (uint x = 0; x < patternWidth; x++) |
|
84 |
{
|
|
85 |
s >> r; |
|
86 |
s >> g; |
|
87 |
s >> b; |
|
88 |
*d = qRgba(r, g, b, 255); |
|
89 |
d++; |
|
90 |
}
|
|
91 |
}
|
|
92 |
else if (patternType == 4) |
|
93 |
{
|
|
94 |
for (uint x = 0; x < patternWidth; x++) |
|
95 |
{
|
|
96 |
s >> r; |
|
97 |
s >> g; |
|
98 |
s >> b; |
|
99 |
s >> alpha; |
|
100 |
*d = qRgba(r, g, b, alpha); |
|
101 |
d++; |
|
102 |
}
|
|
103 |
}
|
|
104 |
}
|
|
105 |
m_imageInfoRecord.type = 6; |
|
106 |
m_imageInfoRecord.exifDataValid = false; |
|
107 |
m_imageInfoRecord.xres = 72; |
|
108 |
m_imageInfoRecord.yres = 72; |
|
109 |
m_imageInfoRecord.BBoxX = 0; |
|
110 |
m_imageInfoRecord.colorspace = 0; |
|
111 |
m_imageInfoRecord.BBoxH = m_image.height(); |
|
112 |
return true; |
|
113 |
}
|
|
114 |
return true; |
|
115 |
}
|
|
116 |
||
117 |
void ScImgDataLoader_GIMP::preloadAlphaChannel(const QString& fn, int res) |
|
118 |
{
|
|
119 |
initialize(); |
|
120 |
return; |
|
121 |
}
|