xref: /haiku/src/add-ons/translators/psd/PSDLoader.h (revision e1c4049fed1047bdb957b0529e1921e97ef94770)
1 /*
2  * Copyright 2013, Gerasim Troeglazov, 3dEyes@gmail.com. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #ifndef PSD_LOADER_H
8 #define PSD_LOADER_H
9 
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <string.h>
13 
14 #include <Translator.h>
15 #include <TranslatorFormats.h>
16 #include <TranslationDefs.h>
17 #include <GraphicsDefs.h>
18 #include <InterfaceDefs.h>
19 #include <String.h>
20 #include <DataIO.h>
21 #include <File.h>
22 #include <ByteOrder.h>
23 #include <List.h>
24 
25 #define PSD_MAX_CHANNELS 16
26 
27 
28 enum psd_version {
29 	PSD_FILE = 1,
30 	PSB_FILE = 2
31 };
32 
33 
34 enum psd_compressed_type {
35 	PSD_COMPRESSED_RAW	= 0,
36 	PSD_COMPRESSED_RLE = 1
37 };
38 
39 
40 enum psd_color_mode {
41 	PSD_COLOR_MODE_BITS = 0,
42 	PSD_COLOR_MODE_GRAYSCALE = 1,
43 	PSD_COLOR_MODE_INDEXED = 2,
44 	PSD_COLOR_MODE_RGB = 3,
45 	PSD_COLOR_MODE_CMYK = 4,
46 	PSD_COLOR_MODE_MULTICHANNEL = 7,
47 	PSD_COLOR_MODE_DUOTONE = 8,
48 	PSD_COLOR_MODE_LAB = 9
49 };
50 
51 
52 enum psd_color_format {
53 	PSD_COLOR_FORMAT_UNSUPPORTED,
54 	PSD_COLOR_FORMAT_BITMAP,
55 	PSD_COLOR_FORMAT_RGB,
56 	PSD_COLOR_FORMAT_RGB_A,
57 	PSD_COLOR_FORMAT_GRAY,
58 	PSD_COLOR_FORMAT_GRAY_A,
59 	PSD_COLOR_FORMAT_MULTICHANNEL,
60 	PSD_COLOR_FORMAT_CMYK,
61 	PSD_COLOR_FORMAT_CMYK_A,
62 	PSD_COLOR_FORMAT_LAB,
63 	PSD_COLOR_FORMAT_LAB_A,
64 	PSD_COLOR_FORMAT_DUOTONE,
65 	PSD_COLOR_FORMAT_INDEXED
66 };
67 
68 
69 class PSDLoader {
70 public:
71 					PSDLoader(BPositionIO *stream);
72 					~PSDLoader();
73 
74 	status_t		Decode(BPositionIO *target);
75 	bool			IsLoaded(void);
76 	bool			IsSupported(void);
77 
78 	BString			ColorFormatName(void);
79 
80 private:
81 	int64			_GetInt64FromStream(BPositionIO *in);
82 	int32			_GetInt32FromStream(BPositionIO *in);
83 	int16			_GetInt16FromStream(BPositionIO *in);
84 	uint8			_GetUInt8FromStream(BPositionIO *in);
85 	int8			_GetInt8FromStream(BPositionIO *in);
86 	void			_SkipStreamBlock(BPositionIO *in, size_t count);
87 
88 	status_t		_ParseImageResources(void);
89 
90 	psd_color_format _ColorFormat(void);
91 
92 	BPositionIO 	*fStream;
93 	uint8			*fStreamBuffer;
94 	size_t			fStreamSize;
95 	size_t			fStreamPos;
96 
97 	size_t			fColorModeDataSize;
98 	size_t			fColorModeDataPos;
99 
100 	off_t			fImageResourceSectionSize;
101 	off_t			fImageResourceSectionPos;
102 
103 	int32 			fSignature;
104 	int16 			fVersion;
105 	int16 			fChannels;
106 	int32 			fHeight;
107 	int32			fWidth;
108 	int16			fDepth;
109 	int16			fColorFormat;
110 	int16			fCompression;
111 
112 	uint16			fTransparentIndex;
113 
114 	bool			fLoaded;
115 };
116 
117 
118 #endif	/* PSD_LOADER_H */
119