00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef PNMFILETYPETGA_H
00016 #define PNMFILETYPETGA_H
00017
00018 #include "pandabase.h"
00019
00020 #ifdef HAVE_TGA
00021
00022 #include "pnmFileType.h"
00023 #include "pnmReader.h"
00024 #include "pnmWriter.h"
00025 #include "ppmcmap.h"
00026 #include "pnmimage_base.h"
00027
00028 struct ImageHeader;
00029
00030
00031
00032
00033
00034
00035 class EXPCL_PANDA_PNMIMAGETYPES PNMFileTypeTGA : public PNMFileType {
00036 public:
00037 PNMFileTypeTGA();
00038
00039 virtual string get_name() const;
00040
00041 virtual int get_num_extensions() const;
00042 virtual string get_extension(int n) const;
00043 virtual string get_suggested_extension() const;
00044
00045 virtual PNMReader *make_reader(istream *file, bool owns_file = true,
00046 const string &magic_number = string());
00047 virtual PNMWriter *make_writer(ostream *file, bool owns_file = true);
00048
00049 public:
00050 class Reader : public PNMReader {
00051 public:
00052 Reader(PNMFileType *type, istream *file, bool owns_file, string magic_number);
00053 virtual ~Reader();
00054
00055 virtual int read_data(xel *array, xelval *alpha);
00056
00057 private:
00058 void readtga ( istream* ifp, struct ImageHeader* tgaP, const string &magic_number );
00059 void get_map_entry ( istream* ifp, pixel* Value, int Size,
00060 gray* Alpha);
00061 void get_pixel ( istream* ifp, pixel* dest, int Size, gray* alpha_p);
00062 unsigned char getbyte ( istream* ifp );
00063
00064 int rows, cols, rlencoded, mapped;
00065 struct ImageHeader *tga_head;
00066 pixel *ColorMap;
00067 gray *AlphaMap;
00068 int RLE_count, RLE_flag;
00069 };
00070
00071 class Writer : public PNMWriter {
00072 public:
00073 Writer(PNMFileType *type, ostream *file, bool owns_file);
00074 virtual ~Writer();
00075
00076 virtual int write_data(xel *array, xelval *alpha);
00077
00078 private:
00079 void writetga ( struct ImageHeader* tgaP, char* id );
00080 void put_map_entry ( pixel* valueP, int size, pixval maxval );
00081 void compute_runlengths ( int cols, pixel* pixelrow, int* runlength );
00082 void put_pixel ( pixel* pP, int imgtype, pixval maxval, colorhash_table cht );
00083 void put_mono ( pixel* pP, pixval maxval );
00084 void put_map ( pixel* pP, colorhash_table cht );
00085 void put_rgb ( pixel* pP, pixval maxval );
00086
00087 int rle_flag;
00088 int rows, cols;
00089 struct ImageHeader *tgaHeader;
00090 colorhist_vector chv;
00091 colorhash_table cht;
00092 int ncolors;
00093 int *runlength;
00094 };
00095
00096
00097
00098 public:
00099 static void register_with_read_factory();
00100
00101 protected:
00102 static TypedWritable *make_PNMFileTypeTGA(const FactoryParams ¶ms);
00103
00104 public:
00105 static TypeHandle get_class_type() {
00106 return _type_handle;
00107 }
00108 static void init_type() {
00109 PNMFileType::init_type();
00110 register_type(_type_handle, "PNMFileTypeTGA",
00111 PNMFileType::get_class_type());
00112 }
00113 virtual TypeHandle get_type() const {
00114 return get_class_type();
00115 }
00116 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00117
00118 private:
00119 static TypeHandle _type_handle;
00120 };
00121
00122 #endif // HAVE_TGA
00123
00124 #endif
00125
00126