1 // ==========================================================
2 // Photoshop Loader
3 //
4 // Design and implementation by
5 // - Hervé Drolon (drolon@infonie.fr)
6 // - Mihail Naydenov (mnaydenov@users.sourceforge.net)
7 // - Garrick Meeker (garrickmeeker@users.sourceforge.net)
8 //
9 // Based on LGPL code created and published by http://sourceforge.net/projects/elynx/
10 //
11 // This file is part of FreeImage 3
12 //
13 // COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
14 // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
15 // THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
16 // OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
17 // CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
18 // THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
19 // SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
20 // PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
21 // THIS DISCLAIMER.
22 //
23 // Use at your own risk!
24 // ==========================================================
25
26 #include "FreeImage.h"
27 #include "Utilities.h"
28 #include "PSDParser.h"
29
30 // ==========================================================
31 // Plugin Interface
32 // ==========================================================
33
34 static int s_format_id;
35
36 // ==========================================================
37 // Plugin Implementation
38 // ==========================================================
39
40 static const char * DLL_CALLCONV
Format()41 Format() {
42 return "PSD";
43 }
44
45 static const char * DLL_CALLCONV
Description()46 Description() {
47 return "Adobe Photoshop";
48 }
49
50 static const char * DLL_CALLCONV
Extension()51 Extension() {
52 return "psd,psb";
53 }
54
55 static const char * DLL_CALLCONV
MimeType()56 MimeType() {
57 return "image/vnd.adobe.photoshop";
58 }
59
60 static BOOL DLL_CALLCONV
Validate(FreeImageIO * io,fi_handle handle)61 Validate(FreeImageIO *io, fi_handle handle) {
62 BYTE psd_id[] = { 0x38, 0x42, 0x50, 0x53 };
63 BYTE signature[4] = { 0, 0, 0, 0 };
64
65 io->read_proc(signature, 1, 4, handle);
66
67 if(memcmp(psd_id, signature, 4) == 0)
68 return TRUE;
69
70 return FALSE;
71 }
72
73 static BOOL DLL_CALLCONV
SupportsExportDepth(int depth)74 SupportsExportDepth(int depth) {
75 return (
76 (depth == 1) ||
77 (depth == 8) ||
78 (depth == 24) ||
79 (depth == 32)
80 );
81 }
82
83 static BOOL DLL_CALLCONV
SupportsExportType(FREE_IMAGE_TYPE type)84 SupportsExportType(FREE_IMAGE_TYPE type) {
85 return (
86 (type == FIT_BITMAP) ||
87 (type == FIT_UINT16) ||
88 (type == FIT_INT16) ||
89 (type == FIT_FLOAT) ||
90 (type == FIT_RGB16) ||
91 (type == FIT_RGBA16) ||
92 (type == FIT_RGBF) ||
93 (type == FIT_RGBAF)
94 );
95 }
96
97 static BOOL DLL_CALLCONV
SupportsICCProfiles()98 SupportsICCProfiles() {
99 return TRUE;
100 }
101
102 static BOOL DLL_CALLCONV
SupportsNoPixels()103 SupportsNoPixels() {
104 return TRUE;
105 }
106
107 // ----------------------------------------------------------
108
109 static FIBITMAP * DLL_CALLCONV
Load(FreeImageIO * io,fi_handle handle,int page,int flags,void * data)110 Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
111 if(!handle) {
112 return NULL;
113 }
114 try {
115 psdParser parser;
116
117 FIBITMAP *dib = parser.Load(io, handle, s_format_id, flags);
118
119 return dib;
120
121 } catch(const char *text) {
122 FreeImage_OutputMessageProc(s_format_id, text);
123 return NULL;
124 }
125 }
126
127 static BOOL DLL_CALLCONV
Save(FreeImageIO * io,FIBITMAP * dib,fi_handle handle,int page,int flags,void * data)128 Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data) {
129 if(!handle) {
130 return FALSE;
131 }
132 try {
133 psdParser parser;
134
135 bool b = parser.Save(io, dib, handle, page, flags, data);
136
137 return b;
138
139 } catch(const char *text) {
140 FreeImage_OutputMessageProc(s_format_id, text);
141 return FALSE;
142 }
143 }
144
145 // ==========================================================
146 // Init
147 // ==========================================================
148
149 void DLL_CALLCONV
InitPSD(Plugin * plugin,int format_id)150 InitPSD(Plugin *plugin, int format_id) {
151 s_format_id = format_id;
152
153 plugin->format_proc = Format;
154 plugin->description_proc = Description;
155 plugin->extension_proc = Extension;
156 plugin->regexpr_proc = NULL;
157 plugin->open_proc = NULL;
158 plugin->close_proc = NULL;
159 plugin->pagecount_proc = NULL;
160 plugin->pagecapability_proc = NULL;
161 plugin->load_proc = Load;
162 plugin->save_proc = Save;
163 plugin->validate_proc = Validate;
164 plugin->mime_proc = MimeType;
165 plugin->supports_export_bpp_proc = SupportsExportDepth;
166 plugin->supports_export_type_proc = SupportsExportType;
167 plugin->supports_icc_profiles_proc = SupportsICCProfiles;
168 plugin->supports_no_pixels_proc = SupportsNoPixels;
169 }
170