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

#include <psd_header.h>

Public Member Functions

 PSDHeader ()
 
bool read (QIODevice &device)
 
bool valid ()
 
bool write (QIODevice &device)
 

Public Attributes

psd_byte_order byteOrder
 
quint16 channelDepth
 
psd_color_mode colormode
 
QString error
 
quint32 height
 
quint16 nChannels
 
QString signature
 
bool tiffStyleLayerBlock
 
quint16 version
 
quint32 width
 

Detailed Description

Definition at line 18 of file psd_header.h.

Constructor & Destructor Documentation

◆ PSDHeader()

PSDHeader::PSDHeader ( )

Definition at line 24 of file psd_header.cpp.

25 : version(0)
26 , nChannels(0)
27 , height(0)
28 , width(0)
29 , channelDepth(0)
32 , tiffStyleLayerBlock(false)
33{
34}
psd_color_mode colormode
Definition psd_header.h:48
quint16 channelDepth
Definition psd_header.h:47
quint16 version
Definition psd_header.h:43
bool tiffStyleLayerBlock
Definition psd_header.h:50
quint16 nChannels
Definition psd_header.h:44
quint32 height
Definition psd_header.h:45
quint32 width
Definition psd_header.h:46
psd_byte_order byteOrder
Definition psd_header.h:49
@ COLORMODE_UNKNOWN
Definition psd.h:65

Member Function Documentation

◆ read()

bool PSDHeader::read ( QIODevice & device)

Reads a psd header from the given device.

Returns
false if: reading failed if the 8BPS signature is not found if the version is not 1 or 2

Definition at line 36 of file psd_header.cpp.

37{
38 Header header;
39 quint64 bytesRead = device.read((char *)&header, sizeof(Header));
40 if (bytesRead != sizeof(Header)) {
41 error = "Could not read header: not enough bytes";
42 return false;
43 }
44
45 signature = QString(header.signature);
46 memcpy(&version, header.version, 2);
47 version = qFromBigEndian(version);
48 memcpy(&nChannels, header.nChannels, 2);
49 nChannels = qFromBigEndian(nChannels);
50 memcpy(&height, header.height, 4);
51 height = qFromBigEndian(height);
52 memcpy(&width, header.width, 4);
53 width = qFromBigEndian(width);
54 memcpy(&channelDepth, header.channelDepth, 2);
55 channelDepth = qFromBigEndian(channelDepth);
56 memcpy(&colormode, header.colormode, 2);
57 colormode = (psd_color_mode)qFromBigEndian((quint16)colormode);
58
59 return valid();
60}
bool valid()
QString error
Definition psd_header.h:52
QString signature
Definition psd_header.h:42
psd_color_mode
Definition psd.h:50

References Header::channelDepth, channelDepth, Header::colormode, colormode, error, Header::height, height, Header::nChannels, nChannels, Header::signature, signature, valid(), Header::version, version, Header::width, and width.

◆ valid()

bool PSDHeader::valid ( )

Definition at line 85 of file psd_header.cpp.

86{
87 if (signature != "8BPS") {
88 error = "Not a PhotoShop document. Signature is: " + signature;
89 return false;
90 }
91 if (version < 1 || version > 2) {
92 error = QString("Wrong version: %1").arg(version);
93 return false;
94 }
95 if (nChannels < 1 || nChannels > 56) {
96 error = QString("Channel count out of range: %1").arg(nChannels);
97 return false;
98 }
99 if (version == 1) {
100 if (height < 1 || height > 30000) {
101 error = QString("Height out of range: %1").arg(height);
102 return false;
103 }
104 if (width < 1 || width > 30000) {
105 error = QString("Width out of range: %1").arg(width);
106 return false;
107 }
108 } else /* if (version == 2) */ {
109 if (height < 1 || height > 300000) {
110 error = QString("Height out of range: %1").arg(height);
111 return false;
112 }
113 if (width < 1 || width > 300000) {
114 error = QString("Width out of range: %1").arg(width);
115 return false;
116 }
117 }
118 if (channelDepth != 1 && channelDepth != 8 && channelDepth != 16) {
119 error = QString("Channel depth incorrect: %1").arg(channelDepth);
120 return false;
121 }
122 if (colormode < 0 || colormode > 9) {
123 error = QString("Colormode is out of range: %1").arg(colormode);
124 return false;
125 }
126
127 return true;
128}

References channelDepth, colormode, error, height, nChannels, signature, version, and width.

◆ write()

bool PSDHeader::write ( QIODevice & device)

write the header data to the given device

Returns
false if writing failed or if this is not a valid header

Definition at line 62 of file psd_header.cpp.

63{
64 if (!valid())
65 return false;
66 if (!psdwrite(device, signature))
67 return false;
68 if (!psdwrite(device, version))
69 return false;
70 if (!psdpad(device, 6))
71 return false;
72 if (!psdwrite(device, nChannels))
73 return false;
74 if (!psdwrite(device, height))
75 return false;
76 if (!psdwrite(device, width))
77 return false;
78 if (!psdwrite(device, channelDepth))
79 return false;
80 if (!psdwrite(device, (quint16)colormode))
81 return false;
82 return true;
83}
bool psdpad(QIODevice &io, quint32 padding)
Definition psd_utils.h:248
std::enable_if_t< std::is_arithmetic< T >::value, bool > psdwrite(QIODevice &io, T v)
Definition psd_utils.h:170

References channelDepth, colormode, height, nChannels, psdpad(), psdwrite(), signature, valid(), version, and width.

Member Data Documentation

◆ byteOrder

psd_byte_order PSDHeader::byteOrder

Definition at line 49 of file psd_header.h.

◆ channelDepth

quint16 PSDHeader::channelDepth

Definition at line 47 of file psd_header.h.

◆ colormode

psd_color_mode PSDHeader::colormode

Definition at line 48 of file psd_header.h.

◆ error

QString PSDHeader::error

Definition at line 52 of file psd_header.h.

◆ height

quint32 PSDHeader::height

Definition at line 45 of file psd_header.h.

◆ nChannels

quint16 PSDHeader::nChannels

Definition at line 44 of file psd_header.h.

◆ signature

QString PSDHeader::signature

Definition at line 42 of file psd_header.h.

◆ tiffStyleLayerBlock

bool PSDHeader::tiffStyleLayerBlock

Definition at line 50 of file psd_header.h.

◆ version

quint16 PSDHeader::version

Definition at line 43 of file psd_header.h.

◆ width

quint32 PSDHeader::width

Definition at line 46 of file psd_header.h.


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