Krita Source Code Documentation
Loading...
Searching...
No Matches
PSDColorModeBlock Class Reference

#include <psd_colormode_block.h>

Public Member Functions

 PSDColorModeBlock (psd_color_mode colormode)
 
bool read (QIODevice &io)
 
bool valid ()
 
bool write (QIODevice &io)
 

Public Attributes

quint32 blocksize
 
QList< QColor > colormap
 
psd_color_mode colormode
 
QByteArray data
 
QByteArray duotoneSpecification
 
QString error
 

Detailed Description

Definition at line 15 of file psd_colormode_block.h.

Constructor & Destructor Documentation

◆ PSDColorModeBlock()

PSDColorModeBlock::PSDColorModeBlock ( psd_color_mode colormode)

Definition at line 11 of file psd_colormode_block.cpp.

12 : blocksize(0)
14{
15}
psd_color_mode colormode

Member Function Documentation

◆ read()

bool PSDColorModeBlock::read ( QIODevice & io)

Definition at line 17 of file psd_colormode_block.cpp.

18{
19 // get length
20 psdread(io, blocksize);
21
22 if (blocksize == 0) {
23 if (colormode == Indexed || colormode == DuoTone) {
24 error = "Blocksize of 0 and Indexed or DuoTone colormode";
25 return false;
26 }
27 else {
28 return true;
29 }
30 }
31
32 if (colormode == Indexed && blocksize != 768) {
33 error = QString("Indexed mode, but block size is %1.").arg(blocksize);
34 return false;
35 }
36
37 data = io.read(blocksize);
38 if ((quint32)data.size() != blocksize) return false;
39
40 if (colormode == Indexed) {
41 int i = 0;
42 while (i <= 767) {
43 colormap.append(qRgb(data[i],data[i + 1],data[i + 2]));
44 i += 3;
45 }
46 }
47 else {
49 }
50 return valid();
51}
QByteArray duotoneSpecification
QList< QColor > colormap
@ DuoTone
Definition psd.h:57
@ Indexed
Definition psd.h:53
std::enable_if_t< std::is_arithmetic< T >::value, bool > psdread(QIODevice &io, T &v)
Definition psd_utils.h:397

References blocksize, colormap, colormode, data, DuoTone, duotoneSpecification, error, Indexed, psdread(), and valid().

◆ valid()

bool PSDColorModeBlock::valid ( )

Definition at line 78 of file psd_colormode_block.cpp.

79{
80 if (blocksize == 0 && (colormode == Indexed || colormode == DuoTone)) {
81 error = "Blocksize of 0 and Indexed or DuoTone colormode";
82 return false;
83 }
84 if (colormode == Indexed && blocksize != 768) {
85 error = QString("Indexed mode, but block size is %1.").arg(blocksize);
86 return false;
87 }
88 if (colormode == DuoTone && blocksize == 0) {
89 error = QString("DuoTone mode, but data block is empty");
90 return false;
91 }
92 if ((quint32)data.size() != blocksize) {
93 error = QString("Data size is %1, but block size is %2").arg(data.size()).arg(blocksize);
94 return false;
95 }
96 return true;
97}

References blocksize, colormode, data, DuoTone, error, and Indexed.

◆ write()

bool PSDColorModeBlock::write ( QIODevice & io)

Definition at line 53 of file psd_colormode_block.cpp.

54{
55 if (!valid()) {
56 error = "Cannot write an invalid Color Mode Block";
57 return false;
58 }
59 if (colormap.size() > 0 && colormode == Indexed) {
60 error = "Cannot write indexed color data";
61 return false;
62 }
63 else if (duotoneSpecification.size() > 0 && colormode == DuoTone) {
64 quint32 blocksize = duotoneSpecification.size();
66 if (io.write(duotoneSpecification.constData(), blocksize) != blocksize) {
67 error = "Failed to write duotone specification";
68 return false;
69 }
70 }
71 else {
72 quint32 i = 0;
73 psdwrite(io, i);
74 }
75 return true;
76}
std::enable_if_t< std::is_arithmetic< T >::value, bool > psdwrite(QIODevice &io, T v)
Definition psd_utils.h:170

References blocksize, colormap, colormode, DuoTone, duotoneSpecification, error, Indexed, psdwrite(), and valid().

Member Data Documentation

◆ blocksize

quint32 PSDColorModeBlock::blocksize

Definition at line 25 of file psd_colormode_block.h.

◆ colormap

QList<QColor> PSDColorModeBlock::colormap

Definition at line 33 of file psd_colormode_block.h.

◆ colormode

psd_color_mode PSDColorModeBlock::colormode

Definition at line 26 of file psd_colormode_block.h.

◆ data

QByteArray PSDColorModeBlock::data

Definition at line 27 of file psd_colormode_block.h.

◆ duotoneSpecification

QByteArray PSDColorModeBlock::duotoneSpecification

Definition at line 34 of file psd_colormode_block.h.

◆ error

QString PSDColorModeBlock::error

Definition at line 29 of file psd_colormode_block.h.


The documentation for this class was generated from the following files: