00001 #ifndef image_size_h
00002 #define image_size_h
00003
00004 #include <string>
00005 #include <fstream>
00006
00007
00008 class ImageSize
00009 {
00010 public:
00011
00012 enum Type
00013 {
00014 UNKNOWN = -1,
00015 GIF = 1,
00016 JPEG = 2,
00017 PNG = 3,
00018 BMP = 4
00019 };
00020
00022 enum Error
00023 {
00024 SUCCESS =0,
00025 INVALID_FILE =1,
00026 INVALID_FILE_NAME =2,
00027 INVALID_FILE_TYPE =3,
00028 BAD_HEADER =4,
00029 BAD_IMAGE =5
00030 };
00031
00032 private:
00033 bool valid;
00034
00035 unsigned int width;
00036 unsigned int height;
00037
00038 std::ifstream in;
00039
00040 Type type;
00041
00042 std::string file_name;
00043
00044 Error error;
00045
00046 public:
00047 ImageSize( std::string file_name );
00048
00049 bool operator!() const { return !valid; }
00050 bool is_valid() const { return valid; }
00051
00052 unsigned int get_width() const { return width; }
00053 unsigned int get_height() const { return height; }
00054
00056 Type get_type() const { return type; }
00057
00059 Error get_error() const { return error; }
00060
00061 private:
00062 ImageSize(){}
00063
00065 bool get_image_type();
00066
00068
00069 bool compare( std::string a, std::string b );
00070
00071 bool get_1_byte( unsigned int& byte );
00072
00073 bool get_le_2_bytes( unsigned int& bytes );
00074 bool get_be_2_bytes( unsigned int& bytes );
00075
00076 bool get_le_4_bytes( unsigned int& bytes );
00077 bool get_be_4_bytes( unsigned int& bytes );
00078
00079 bool jump_abs( unsigned int pos);
00080 bool jump_rel( unsigned int n );
00081
00083 bool get_string( std::string& s, unsigned int n );
00084
00085
00086 void get_gif_geometry();
00087 bool check_gif_signature();
00088
00089
00090 void get_jpeg_geometry();
00091 bool check_jpeg_signature();
00092 bool jpeg_find_sof0_marker();
00093
00094
00095 void get_png_geometry();
00096 bool check_png_signature();
00097
00098
00099 void get_bmp_geometry();
00100 bool check_bmp_signature();
00101
00102 };
00103
00104 #endif