aboutsummaryrefslogtreecommitdiff
path: root/mp/src/public/bitmap/psd.h
blob: aae3cbfac5b53bce36f399850b160fe66ffb0684 (plain) (blame)
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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Methods relating to saving + loading PSD files (photoshop)
//
// $NoKeywords: $
//===========================================================================//

#ifndef PSD_H
#define PSD_H

#ifdef _WIN32
#pragma once
#endif

#include "bitmap/imageformat.h" //ImageFormat enum definition

//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class CUtlBuffer;
struct Bitmap_t;

class PSDImageResources
{
public:
	enum Resource {
		eResFileInfo = 0x0404
	};

	struct ResElement {
		Resource		m_eType;
		// unsigned char	m_pReserved[4];
		unsigned short	m_numBytes;
		unsigned char const *m_pvData;
	};

public:
	explicit PSDImageResources( unsigned int numBytes, unsigned char const *pvBuffer ) : m_numBytes( numBytes ), m_pvBuffer( pvBuffer ) {}

public:
	ResElement FindElement( Resource eType ) const;

protected:
	unsigned int			m_numBytes;
	unsigned char const *	m_pvBuffer;
};

class PSDResFileInfo
{
public:
	enum ResFileInfo {
		eTitle					= 0x05,
		eAuthor					= 0x50,
		eAuthorTitle			= 0x55,
		eDescription			= 0x78,
		eDescriptionWriter		= 0x7A,
		eKeywords				= 0x19,
		eCopyrightNotice		= 0x74
	};

	struct ResFileInfoElement {
		ResFileInfo			m_eType;
		unsigned short		m_numBytes;
		unsigned char const *m_pvData;
	};

public:
	explicit PSDResFileInfo( PSDImageResources::ResElement res ) : m_res( res ) {}

public:
	ResFileInfoElement FindElement( ResFileInfo eType ) const;

protected:
	PSDImageResources::ResElement m_res;
};


//-----------------------------------------------------------------------------
// Is a file a PSD file?
//-----------------------------------------------------------------------------
bool IsPSDFile( const char *pFileName, const char *pPathID );
bool IsPSDFile( CUtlBuffer &buf );


//-----------------------------------------------------------------------------
// Returns information about the PSD file
//-----------------------------------------------------------------------------
bool PSDGetInfo( const char *pFileName, const char *pPathID, int *pWidth, int *pHeight, ImageFormat *pImageFormat, float *pSourceGamma );
bool PSDGetInfo( CUtlBuffer &buf, int *pWidth, int *pHeight, ImageFormat *pImageFormat, float *pSourceGamma );


//-----------------------------------------------------------------------------
// Get PSD file image resources, pointers refer into the utlbuffer
//-----------------------------------------------------------------------------
PSDImageResources PSDGetImageResources( CUtlBuffer &buf );


//-----------------------------------------------------------------------------
// Reads the PSD file into the specified buffer
//-----------------------------------------------------------------------------
bool PSDReadFileRGBA8888( CUtlBuffer &buf, Bitmap_t &bitmap );
bool PSDReadFileRGBA8888( const char *pFileName, const char *pPathID, Bitmap_t &bitmap );


#endif // PSD_H