~ubuntu-branches/ubuntu/maverick/scribus-ng/maverick-backports

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
#include <qfile.h>
#include <qfileinfo.h>
#include "scimgdataloader_gimp.h"

ScImgDataLoader_GIMP::ScImgDataLoader_GIMP(void) : ScImgDataLoader()
{
	initSupportedFormatList();
}

void ScImgDataLoader_GIMP::initSupportedFormatList(void)
{
	m_supportedFormats.clear();
	m_supportedFormats.append( "pat" );
}

void ScImgDataLoader_GIMP::loadEmbeddedProfile(const QString& fn)
{
	m_embeddedProfile.resize(0);
	m_profileComponents = 0;
}

bool ScImgDataLoader_GIMP::loadPicture(const QString& fn, int /*res*/, bool /*thumbnail*/)
{
	if (!QFile::exists(fn))
		return false;
	initialize();
	QFile f(fn);
	if (f.open(IO_ReadOnly))
	{
		QDataStream s( &f );
		s.setByteOrder( QDataStream::BigEndian );
		uint headersize, versionInfo, patternWidth, patternHeight, patternType;
		uchar chData, alpha, r, g, b;
		uchar magicKey[4];
		s >> headersize;
		s >> versionInfo;
		s >> patternWidth;
		s >> patternHeight;
		s >> patternType;
		QString magic = "";
		for( int i = 0; i < 4; i++ )
		{
			s >> magicKey[i];
			magic += QChar(magicKey[i]);
		}
		if (magic != "GPAT")
			return false;
		s.device()->at( headersize );
		if( !m_image.create( patternWidth, patternHeight, 32 ))
			return false;
		m_image.setAlphaBuffer( true );
		QRgb *d;
		for (uint y = 0; y < patternHeight; y++)
		{
			d = (QRgb*)(m_image.scanLine( y ));
			if (patternType == 1)
			{
				for (uint x = 0; x < patternWidth; x++)
				{
					s >> chData;
					*d = qRgba(chData, chData, chData, 255);
					d++;
				}
			}
			else if (patternType == 2)
			{
				for (uint x = 0; x < patternWidth; x++)
				{
					s >> chData;
					s >> alpha;
					*d = qRgba(chData, chData, chData, alpha);
					d++;
				}
			}
			else if (patternType == 3)
			{
				for (uint x = 0; x < patternWidth; x++)
				{
					s >> r;
					s >> g;
					s >> b;
					*d = qRgba(r, g, b, 255);
					d++;
				}
			}
			else if (patternType == 4)
			{
				for (uint x = 0; x < patternWidth; x++)
				{
					s >> r;
					s >> g;
					s >> b;
					s >> alpha;
					*d = qRgba(r, g, b, alpha);
					d++;
				}
			}
		}
		m_imageInfoRecord.type = 6;
		m_imageInfoRecord.exifDataValid = false;
		m_imageInfoRecord.xres = 72;
		m_imageInfoRecord.yres = 72;
		m_imageInfoRecord.BBoxX = 0;
		m_imageInfoRecord.colorspace = 0;
		m_imageInfoRecord.BBoxH = m_image.height();
		return true;
	}
	return true;
}

void ScImgDataLoader_GIMP::preloadAlphaChannel(const QString& fn, int res)
{
	initialize();
	return;
}