/src/freeimage-svn/FreeImage/trunk/Source/FreeImage/PluginPSD.cpp
Line | Count | Source (jump to first uncovered line) |
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 |
41 | 2 | Format() { |
42 | 2 | return "PSD"; |
43 | 2 | } |
44 | | |
45 | | static const char * DLL_CALLCONV |
46 | 0 | Description() { |
47 | 0 | return "Adobe Photoshop"; |
48 | 0 | } |
49 | | |
50 | | static const char * DLL_CALLCONV |
51 | 0 | Extension() { |
52 | 0 | return "psd,psb"; |
53 | 0 | } |
54 | | |
55 | | static const char * DLL_CALLCONV |
56 | 0 | MimeType() { |
57 | 0 | return "image/vnd.adobe.photoshop"; |
58 | 0 | } |
59 | | |
60 | | static BOOL DLL_CALLCONV |
61 | 22.4k | Validate(FreeImageIO *io, fi_handle handle) { |
62 | 22.4k | BYTE psd_id[] = { 0x38, 0x42, 0x50, 0x53 }; |
63 | 22.4k | BYTE signature[4] = { 0, 0, 0, 0 }; |
64 | | |
65 | 22.4k | io->read_proc(signature, 1, 4, handle); |
66 | | |
67 | 22.4k | if(memcmp(psd_id, signature, 4) == 0) |
68 | 0 | return TRUE; |
69 | | |
70 | 22.4k | return FALSE; |
71 | 22.4k | } |
72 | | |
73 | | static BOOL DLL_CALLCONV |
74 | 0 | SupportsExportDepth(int depth) { |
75 | 0 | return ( |
76 | 0 | (depth == 1) || |
77 | 0 | (depth == 8) || |
78 | 0 | (depth == 24) || |
79 | 0 | (depth == 32) |
80 | 0 | ); |
81 | 0 | } |
82 | | |
83 | | static BOOL DLL_CALLCONV |
84 | 0 | SupportsExportType(FREE_IMAGE_TYPE type) { |
85 | 0 | return ( |
86 | 0 | (type == FIT_BITMAP) || |
87 | 0 | (type == FIT_UINT16) || |
88 | 0 | (type == FIT_INT16) || |
89 | 0 | (type == FIT_FLOAT) || |
90 | 0 | (type == FIT_RGB16) || |
91 | 0 | (type == FIT_RGBA16) || |
92 | 0 | (type == FIT_RGBF) || |
93 | 0 | (type == FIT_RGBAF) |
94 | 0 | ); |
95 | 0 | } |
96 | | |
97 | | static BOOL DLL_CALLCONV |
98 | 0 | SupportsICCProfiles() { |
99 | 0 | return TRUE; |
100 | 0 | } |
101 | | |
102 | | static BOOL DLL_CALLCONV |
103 | 0 | SupportsNoPixels() { |
104 | 0 | return TRUE; |
105 | 0 | } |
106 | | |
107 | | // ---------------------------------------------------------- |
108 | | |
109 | | static FIBITMAP * DLL_CALLCONV |
110 | 0 | Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { |
111 | 0 | if(!handle) { |
112 | 0 | return NULL; |
113 | 0 | } |
114 | 0 | try { |
115 | 0 | psdParser parser; |
116 | |
|
117 | 0 | FIBITMAP *dib = parser.Load(io, handle, s_format_id, flags); |
118 | | |
119 | 0 | return dib; |
120 | |
|
121 | 0 | } catch(const char *text) { |
122 | 0 | FreeImage_OutputMessageProc(s_format_id, text); |
123 | 0 | return NULL; |
124 | 0 | } |
125 | 0 | } |
126 | | |
127 | | static BOOL DLL_CALLCONV |
128 | 0 | Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data) { |
129 | 0 | if(!handle) { |
130 | 0 | return FALSE; |
131 | 0 | } |
132 | 0 | try { |
133 | 0 | psdParser parser; |
134 | |
|
135 | 0 | bool b = parser.Save(io, dib, handle, page, flags, data); |
136 | | |
137 | 0 | return b; |
138 | |
|
139 | 0 | } catch(const char *text) { |
140 | 0 | FreeImage_OutputMessageProc(s_format_id, text); |
141 | 0 | return FALSE; |
142 | 0 | } |
143 | 0 | } |
144 | | |
145 | | // ========================================================== |
146 | | // Init |
147 | | // ========================================================== |
148 | | |
149 | | void DLL_CALLCONV |
150 | 2 | InitPSD(Plugin *plugin, int format_id) { |
151 | 2 | s_format_id = format_id; |
152 | | |
153 | 2 | plugin->format_proc = Format; |
154 | 2 | plugin->description_proc = Description; |
155 | 2 | plugin->extension_proc = Extension; |
156 | 2 | plugin->regexpr_proc = NULL; |
157 | 2 | plugin->open_proc = NULL; |
158 | 2 | plugin->close_proc = NULL; |
159 | 2 | plugin->pagecount_proc = NULL; |
160 | 2 | plugin->pagecapability_proc = NULL; |
161 | 2 | plugin->load_proc = Load; |
162 | 2 | plugin->save_proc = Save; |
163 | 2 | plugin->validate_proc = Validate; |
164 | 2 | plugin->mime_proc = MimeType; |
165 | 2 | plugin->supports_export_bpp_proc = SupportsExportDepth; |
166 | 2 | plugin->supports_export_type_proc = SupportsExportType; |
167 | 2 | plugin->supports_icc_profiles_proc = SupportsICCProfiles; |
168 | 2 | plugin->supports_no_pixels_proc = SupportsNoPixels; |
169 | 2 | } |