ConvertShape.h

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2002, 2003 The Pentagram Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 #ifndef CONVERTSHAPE_H
00020 #define CONVERTSHAPE_H
00021 
00022 class IDataSource;
00023 class ODataSource;
00024 
00025 // Convert shape C
00026 
00027 /********** Update AutoShapeFormat in shapeconv/ShapeConv.cpp when changed! **********/
00028 struct ConvertShapeFormat
00029 {
00030         const char *            name;
00031                                                                                                         //      U8              U8 Gump U8.SKF  Cru             Cru2D   Pent    Comp
00032         uint32                          len_header;                                     //      6               6               2               6               6               8               11
00033         const char *            ident;                                          //  ""          ""              "\2\0"  ""              ""              "PSHP"  ""
00034         uint32                          bytes_ident;                            //      0               0               2               0               0               4               0
00035         uint32                          bytes_special;                          //      0               0               0               0               0               0               5
00036         uint32                          bytes_header_unk;                       //      4               4               0               4               4               0               4
00037         uint32                          bytes_num_frames;                       //      2               2               0               2               2               4               2
00038 
00039         uint32                          len_frameheader;                        //      6               6               0               8               8               8               6
00040         uint32                          bytes_frame_offset;                     //      3               3               0               3               3               4               4
00041         uint32                          bytes_frameheader_unk;          //      1               2               0               2               2               0               0
00042         uint32                          bytes_frame_length;                     //      2               2               0               3               3               4               2
00043         uint32                          bytes_frame_length_kludge;      //      0               8               0               0               0               0               0
00044 
00045         uint32                          len_frameheader2;                       //      18              18              10              28              20              20              10
00046         uint32                          bytes_frame_unknown;            //      8               8               0               8               0               0               0
00047         uint32                          bytes_frame_compression;        //      2               2               2               4               4               4               2
00048         uint32                          bytes_frame_width;                      //      2               2               2               4               4               4               2
00049         uint32                          bytes_frame_height;                     //      2               2               2               4               4               4               2
00050         uint32                          bytes_frame_xoff;                       //      2               2               2               4               4               4               2
00051         uint32                          bytes_frame_yoff;                       //      2               2               2               4               4               4               2
00052 
00053         uint32                          bytes_line_offset;                      //      2               2               2               4               4               4               0
00054         uint32                          line_offset_absolute;           //      0               0               0               0               0               1               0
00055 };
00056 
00057 // ConvertShapeFrame structure
00058 
00059 struct ConvertShapeFrame 
00060 {
00061         uint8                           header_unknown[2];
00062 
00063         uint8                           unknown[8];
00064         uint32                          compression;
00065         sint32                          width;
00066         sint32                          height;
00067         sint32                          xoff;
00068         sint32                          yoff;
00069 
00070         uint32                          *line_offsets;          // Note these are offsets into rle_data
00071 
00072         sint32                          bytes_rle;                      // Number of bytes of RLE Data
00073         uint8                           *rle_data;
00074 
00075         void Free()
00076         {
00077                 delete [] line_offsets;
00078                 line_offsets = 0;
00079 
00080                 delete [] rle_data;
00081                 rle_data = 0;
00082         }
00083 
00084         void Read(IDataSource *source, const ConvertShapeFormat *csf, uint32 frame_length);
00085 
00086         void ReadCmpFrame(IDataSource *source, const ConvertShapeFormat *csf, const uint8 special[256], ConvertShapeFrame *prev);
00087 
00088         void GetPixels(uint8 *buf, sint32 count, sint32 x, sint32 y);
00089 };
00090 
00091 
00092 // ConvertShape structure
00093 
00094 class ConvertShape
00095 {
00096         uint8                           header_unknown[4];
00097         uint32                          num_frames;
00098         ConvertShapeFrame       *frames;
00099 
00100 public:
00101         ConvertShape() : num_frames(0), frames(0)
00102         {
00103         }
00104 
00105         ~ConvertShape()
00106         {
00107                 Free();
00108         }
00109 
00110         void Free()
00111         {
00112                 if (frames)
00113                         for(uint32 i = 0; i < num_frames; ++i)
00114                                 frames[i].Free();
00115                 
00116                 delete [] frames;
00117                 frames = 0;
00118                 num_frames = 0;
00119         }
00120 
00121 
00122         void Read(IDataSource *source, const ConvertShapeFormat *csf, uint32 real_len);
00123         void Write(ODataSource *source, const ConvertShapeFormat *csf, uint32 &write_len);
00124 
00125         // This will check to see if a Shape is of a certain type. Return true if ok, false if bad
00126         static bool Check(IDataSource *source, const ConvertShapeFormat *csf, uint32 real_len);
00127 
00128         // This will also check to see if a shape is of a certain type. However it won't check
00129         // the rle data, it only checks headers. Return true if ok, false if bad
00130         static bool CheckUnsafe(IDataSource *source, const ConvertShapeFormat *csf, uint32 real_len);
00131 
00132         // Algorithmically calculate the number of frames
00133         static int CalcNumFrames(IDataSource *source, const ConvertShapeFormat *csf, uint32 real_len, uint32 start_pos);
00134 };
00135 
00136 // Shape format configuration for Pentagram format
00137 extern const ConvertShapeFormat         PentagramShapeFormat;
00138 
00139 #endif //CONVERTSHAPE_H

Generated on Fri Jul 27 22:27:12 2007 for pentagram by  doxygen 1.4.7