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
|
/*
* Copyright (c) 2009 Boudewijn Rempt <boud@valdyas.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "psd_colormode_block.h"
#include "psd.h"
#include "psd_utils.h"
PSDColorModeBlock::PSDColorModeBlock(PSDColorMode colormode)
: blocksize(0)
, colormode(colormode)
{
}
bool PSDColorModeBlock::read(QIODevice* io)
{
// get length
psdread(io, &blocksize);
if (blocksize == 0) {
if (colormode == Indexed || colormode == DuoTone) {
error = "Blocksize of 0 and Indexed or DuoTone colormode";
return false;
}
else {
return true;
}
}
if (colormode == Indexed && blocksize != 768) {
error = QString("Indexed mode, but block size is %1.").arg(blocksize);
return false;
}
data = io->read(blocksize);
if ((quint32)data.size() != blocksize) return false;
if (colormode == Indexed) {
qFatal("TODO: Compute the colormap");
return false;
}
return valid();
}
bool PSDColorModeBlock::write(QIODevice* io)
{
Q_UNUSED(io);
Q_ASSERT(valid());
if (!valid()) {
error = "Cannot write an invalid Color Mode Block";
return false;
}
qFatal("TODO: implement writing the colormode block");
return false;
}
bool PSDColorModeBlock::valid()
{
if (blocksize == 0 && (colormode == Indexed || colormode == DuoTone)) {
error = "Blocksize of 0 and Indexed or DuoTone colormode";
return false;
}
if (colormode == Indexed && blocksize != 768) {
error = QString("Indexed mode, but block size is %1.").arg(blocksize);
return false;
}
if (colormode == DuoTone && blocksize == 0) {
error == QString("DuoTone mode, but data block is empty");
return false;
}
if ((quint32)data.size() != blocksize) {
error = QString("Data size is %1, but block size is %2").arg(data.size()).arg(blocksize);
return false;
}
return true;
}
|