1 /*  Copyright (c) MediaArea.net SARL. All Rights Reserved.
2  *
3  *  Use of this source code is governed by a BSD-style license that can
4  *  be found in the License.html file in the root of the source tree.
5  */
6 
7 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8 //
9 // Information about PSD files
10 //
11 // Contributor: Lionel Duchateau, kurtnoise@free.fr
12 //
13 // From http://www.adobe.com/devnet-apps/photoshop/fileformatashtml/PhotoshopFileFormats.htm
14 //
15 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
16 
17 //---------------------------------------------------------------------------
18 // Pre-compilation
19 #include "MediaInfo/PreComp.h"
20 #ifdef __BORLANDC__
21     #pragma hdrstop
22 #endif
23 //---------------------------------------------------------------------------
24 
25 //---------------------------------------------------------------------------
26 #include "MediaInfo/Setup.h"
27 //---------------------------------------------------------------------------
28 
29 //---------------------------------------------------------------------------
30 #if defined(MEDIAINFO_PSD_YES)
31 //---------------------------------------------------------------------------
32 
33 //---------------------------------------------------------------------------
34 #include "MediaInfo/Image/File_Psd.h"
35 //---------------------------------------------------------------------------
36 
37 namespace MediaInfoLib
38 {
39 
40 //***************************************************************************
41 // Infos
42 //***************************************************************************
43 
44 //---------------------------------------------------------------------------
Psd_ColorMode(int16u ColorMode)45 static const char* Psd_ColorMode(int16u ColorMode)
46 {
47     switch(ColorMode)
48     {
49         case 0 : return "Bitmap";
50         case 1 : return "Grayscale";
51         case 2 : return "Indexed";
52         case 3 : return "RGB";
53         case 4 : return "CMYK";
54         case 7 : return "Multichannel";
55         case 8 : return "Duotone";
56         case 9 : return "Lab";
57         default: return "";
58     }
59 }
60 
61 //***************************************************************************
62 // Static stuff
63 //***************************************************************************
64 
65 //---------------------------------------------------------------------------
FileHeader_Begin()66 bool File_Psd::FileHeader_Begin()
67 {
68     //Element_Size
69     if (Buffer_Size<4)
70         return false; //Must wait for more data
71 
72     if (CC4(Buffer)!=0x38425053) //"8BPS"
73     {
74         Reject("PSD");
75         return false;
76     }
77 
78     //All should be OK...
79     return true;
80 }
81 
82 //***************************************************************************
83 // File Header Information
84 //***************************************************************************
85 
86 //---------------------------------------------------------------------------
Read_Buffer_Continue()87 void File_Psd::Read_Buffer_Continue()
88 {
89     //Parsing
90     int32u Width, Height;
91     int16u BitsDepth, Version, channels, ColorMode;
92     Skip_C4(                                                    "Signature");
93     Get_B2 (Version,                                            "Version"); //  1 = PSD, 2 = PSB
94     Skip_B6(                                                    "Reserved");
95     Get_B2 (channels,                                           "channels"); // 1 to 56, including alpha channel
96     Get_B4 (Height,                                             "Height");
97     Get_B4 (Width,                                              "Width");
98     Get_B2 (BitsDepth,                                          "Depth"); // 1,8,16 or 32
99     Get_B2 (ColorMode,                                          "Color Mode"); Param_Info1(Psd_ColorMode(ColorMode));
100 
101     FILLING_BEGIN();
102         Accept("PSD");
103         Stream_Prepare(Stream_Image);
104         Fill(Stream_Image, 0, Image_Format, Version==1?"PSD":"PSB");
105         Fill(Stream_Image, 0, Image_Format_Version, Version);
106         Fill(Stream_Image, 0, Image_ColorSpace, Psd_ColorMode(ColorMode));
107         Fill(Stream_Image, 0, Image_Width, Width);
108         Fill(Stream_Image, 0, Image_Height, Height);
109         Fill(Stream_Image, 0, Image_BitDepth, BitsDepth);
110         Finish("PSD");
111     FILLING_END();
112 }
113 
114 
115 } //NameSpace
116 
117 #endif
118