├── README.md ├── pvrspi.h ├── pngwriter.h ├── buffer.h ├── mt5parser.h ├── Unpacker.cbp ├── taparser.h ├── database.h ├── pngwriter.cpp ├── Unpacker.layout ├── buffer.cpp ├── database.cpp ├── Unpacker.depend ├── main.cpp ├── pnglibconf.h ├── pvrspi.cpp ├── taparser.cpp ├── zconf.h ├── pngconf.h └── mt5parser.cpp /README.md: -------------------------------------------------------------------------------- 1 | shencon 2 | ======= 3 | 4 | Unpacks Dreamcast Shenmue .pks, .pkf and .mt5 files. The texture files are converted to a .png, the .mt5 files to .dae (Collada) files. 5 | -------------------------------------------------------------------------------- /pvrspi.h: -------------------------------------------------------------------------------- 1 | #ifndef PVRSPI_H 2 | #define PVRSPI_H 3 | 4 | int pvr2bin(const unsigned char *buf,unsigned char *&res,int &width, int &height, int &img_size, int &bits); 5 | 6 | #endif // PVRSPI_H 7 | -------------------------------------------------------------------------------- /pngwriter.h: -------------------------------------------------------------------------------- 1 | #ifndef PNG_WRITER 2 | #define PNG_WRITER 3 | int writePng(const char *fname, const unsigned char *buf, const unsigned int width, const unsigned int height, const unsigned int bits); 4 | 5 | #endif // PNG_WRITER 6 | -------------------------------------------------------------------------------- /buffer.h: -------------------------------------------------------------------------------- 1 | #ifndef BUFFER_H 2 | #define BUFFER_H 3 | 4 | class buffer { 5 | public: 6 | buffer(const char *fname); 7 | buffer(const buffer *orig, const unsigned long ofs, unsigned long bsize); 8 | ~buffer(); 9 | 10 | bool seek(unsigned long pos); 11 | unsigned long tell(); 12 | bool eof() const; 13 | unsigned char rb(); 14 | unsigned short rw(); 15 | unsigned long rl(); 16 | float rf(); 17 | const unsigned char *ptr(); 18 | const unsigned long blen() const; 19 | 20 | void dump(const char *fname, unsigned long ofs, unsigned long writeSize); 21 | private: 22 | unsigned char *buf; 23 | unsigned long cursor; 24 | unsigned long buflen; 25 | }; 26 | 27 | extern buffer *b; 28 | 29 | #endif // BUFFER_H 30 | -------------------------------------------------------------------------------- /mt5parser.h: -------------------------------------------------------------------------------- 1 | #ifndef MT5PARSER_H 2 | #define MT5PARSER_H 3 | 4 | #include 5 | #include 6 | 7 | #include "buffer.h" 8 | 9 | struct texn { 10 | public: 11 | char name[8]; 12 | }; 13 | 14 | class node; 15 | class textureData; 16 | 17 | class mt5 { 18 | public: 19 | mt5(); 20 | ~mt5(); 21 | 22 | void readData(buffer *nbuf); 23 | 24 | public: //!!MH!! change to private with friend classes 25 | node *m; 26 | textureData *t; 27 | }; 28 | 29 | class colladaExport { 30 | public: 31 | colladaExport(); 32 | ~colladaExport(); 33 | 34 | void exportModel(const char * nfname, mt5 *model); 35 | void expNode(std::ofstream &expFile, node *sm, textureData *td, int level); 36 | std::string getModelName(unsigned long ofs, unsigned long id); 37 | std::string getMeshName(unsigned long ofs); 38 | std::string getTextureName(texn *name); 39 | std::string getTextureFileName(texn *name); 40 | 41 | private: 42 | char *fname; 43 | }; 44 | 45 | #endif // MT5PARSER_H 46 | -------------------------------------------------------------------------------- /Unpacker.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 61 | 62 | -------------------------------------------------------------------------------- /taparser.h: -------------------------------------------------------------------------------- 1 | #ifndef TAPARSER_H 2 | #define TAPARSER_H 3 | 4 | #include "buffer.h" 5 | 6 | class taparser { 7 | public: 8 | taparser(buffer *buf, const unsigned long ofs); 9 | ~taparser(); 10 | 11 | void dump(); 12 | 13 | enum {ISP_TSP_INSTR = 0, PARAM_CTRL = 1, TEXTURE_CTRL = 2, TSP_INSTR = 3}; 14 | private: 15 | unsigned long globalParam[8]; 16 | 17 | unsigned long paraType; 18 | unsigned long endOfStrip; 19 | unsigned long listType; 20 | 21 | unsigned long groupEn; 22 | unsigned long stripLen; 23 | unsigned long userClip; 24 | 25 | unsigned long shadow; 26 | unsigned long volume; 27 | unsigned long colType; 28 | unsigned long texture; 29 | unsigned long offset; 30 | unsigned long gouraud; 31 | unsigned long uv16Bit; 32 | 33 | unsigned long depthCompare; // or volumeInstruction 34 | unsigned long cullingMode; 35 | unsigned long zWriteDisable; 36 | unsigned long cacheBypass; 37 | unsigned long dCalcCtrl; 38 | 39 | unsigned long srcAlphaInstr; 40 | unsigned long dstAlphaInstr; 41 | unsigned long srcSelect; 42 | unsigned long dstSelect; 43 | unsigned long fogControl; 44 | unsigned long colorClamp; 45 | unsigned long useAlpha; 46 | unsigned long ignoreTexAlpha; 47 | unsigned long flipUV; 48 | unsigned long clampUV; 49 | unsigned long filterMode; 50 | unsigned long superSampleTex; 51 | unsigned long mipMapDAdj; 52 | unsigned long texShadInstr; 53 | unsigned long texUSize; 54 | unsigned long texVSize; 55 | 56 | unsigned long mipMapped; 57 | unsigned long vqCompressed; 58 | unsigned long pixelFormat; 59 | unsigned long scanOrder; 60 | unsigned long strideSelect; 61 | unsigned long paletteSelector; 62 | 63 | unsigned long bits(const unsigned long param, const unsigned long startbit, const unsigned long stopbit); 64 | }; 65 | 66 | #endif // TAPARSER_H 67 | -------------------------------------------------------------------------------- /database.h: -------------------------------------------------------------------------------- 1 | #ifndef DATABASE_H 2 | #define DATABASE_H 3 | 4 | #include 5 | #include 6 | 7 | #include "mt5parser.h" 8 | 9 | class textureDB { 10 | public: 11 | textureDB(); 12 | ~textureDB(); 13 | unsigned long getID(texn *t); 14 | private: 15 | struct entry { 16 | unsigned long id; 17 | texn name; 18 | }; 19 | std::vector tlist; 20 | unsigned long tval; 21 | }; 22 | 23 | 24 | class nodeDB { 25 | public: 26 | nodeDB(); 27 | ~nodeDB(); 28 | unsigned long getID(unsigned long nid, unsigned long sid); 29 | void clear(); 30 | private: 31 | struct entry{ 32 | unsigned long id; 33 | unsigned long nid; // Offset in file 34 | unsigned long sid; // Sega ID for node 35 | }; 36 | std::vector nlist; 37 | unsigned long nval; 38 | }; 39 | 40 | class meshDB { 41 | public: 42 | meshDB(); 43 | ~meshDB(); 44 | unsigned long getID(unsigned long mid); 45 | void clear(); 46 | private: 47 | struct entry { 48 | unsigned long id; 49 | unsigned long mid; // Offset in file 50 | }; 51 | std::vector mlist; 52 | unsigned long mval; 53 | }; 54 | 55 | /*class materialDB { 56 | public: 57 | materialDB(); 58 | ~materialDB(); 59 | private: 60 | struct entry{ 61 | unsigned long id; 62 | taparser *tadata; 63 | unsigned long texid; 64 | }; 65 | std::vector matlist; 66 | unsigned long matval; 67 | }; 68 | */ 69 | class fileDB { 70 | public: 71 | fileDB(); 72 | ~fileDB(); 73 | unsigned long getID(std::string name); 74 | private: 75 | struct entry { 76 | unsigned long id; 77 | std::string name; 78 | }; 79 | std::vector flist; 80 | unsigned long fval; 81 | }; 82 | 83 | extern textureDB texDB; 84 | extern fileDB fDB; 85 | extern nodeDB nDB; 86 | extern meshDB mDB; 87 | //extern materialDB matDB; 88 | 89 | #endif // DATABASE_H 90 | -------------------------------------------------------------------------------- /pngwriter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | #include "pngwriter.h" 8 | 9 | using namespace std; 10 | 11 | void abort_(const char *s, ...) { 12 | va_list args; 13 | va_start(args, s); 14 | vfprintf(stderr, s, args); 15 | fprintf(stderr, "\n"); 16 | va_end(args); 17 | abort(); 18 | } 19 | 20 | int writePng(const char *fname, const unsigned char *buf, const unsigned int width, const unsigned int height, const unsigned int bits) { 21 | png_structp png_ptr; 22 | png_infop info_ptr; 23 | png_bytep * row_pointers; 24 | unsigned int y; 25 | 26 | // allocate heap space 27 | row_pointers = (png_bytep *) malloc(sizeof(png_bytep) * height); 28 | for (y=0; y 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /buffer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "buffer.h" 8 | 9 | using namespace std; 10 | 11 | buffer::buffer(const char *fname) : buf(NULL), cursor(0), buflen(0) { 12 | FILE *f = fopen(fname, "rb"); 13 | if (!f) { 14 | cerr << "error opening file " << fname << endl; 15 | return; 16 | } 17 | unsigned short magic; 18 | fread(&magic, sizeof(short), 1, f); 19 | if (magic == 0x8b1f) { 20 | fseek(f, -4L, SEEK_END); 21 | fread(&buflen, sizeof(unsigned long), 1, f); 22 | cout << "gzip compressed file with size " << buflen << endl; 23 | } else { 24 | fseek(f, 0L, SEEK_END); 25 | buflen = ftell(f); 26 | cout << "uncompressed file with size" << buflen << endl; 27 | } 28 | fclose(f); 29 | buf = new unsigned char[buflen]; 30 | gzFile gf = gzopen(fname, "rb"); 31 | if (gzread(gf, buf, buflen) != buflen) { 32 | gzclose(gf); 33 | delete [] buf; 34 | buf = NULL; 35 | buflen = 0; 36 | cerr << "error reading file " << fname << endl; 37 | return; 38 | } 39 | gzclose(gf); 40 | cout << "successful read " << buflen << " bytes from file " << fname << endl; 41 | 42 | } 43 | 44 | buffer::buffer(const buffer *orig, const unsigned long ofs, unsigned long bsize) : cursor(0), buflen(bsize) { 45 | buf = new unsigned char[bsize]; 46 | memcpy(buf, orig->buf + ofs, bsize); 47 | } 48 | 49 | buffer::~buffer() { 50 | if (buf) delete [] buf; 51 | } 52 | 53 | const unsigned long buffer::blen() const 54 | { 55 | return buflen; 56 | } 57 | 58 | bool buffer::seek(unsigned long pos) { 59 | if (pos= buflen;} 70 | 71 | unsigned char buffer::rb() {return buf[cursor++];} 72 | 73 | unsigned short buffer::rw() {unsigned short val=*((unsigned short *)(buf + cursor)); cursor+=2; return val;} 74 | 75 | unsigned long buffer::rl() {unsigned long val=*((unsigned long *)(buf + cursor)); cursor+=4; return val;} 76 | 77 | float buffer::rf() {float val=*((float *)(buf + cursor)); cursor+=4; return val;} 78 | 79 | const unsigned char *buffer::ptr() {return buf + cursor;} 80 | 81 | void buffer::dump(const char *fname, unsigned long ofs, unsigned long writeSize) { 82 | FILE *f = fopen(fname, "wb"); 83 | if (!f) { 84 | cerr << "error opening file " << fname << endl; 85 | return; 86 | } 87 | if (fwrite(buf+ofs, sizeof(char), writeSize, f) != writeSize) { 88 | fclose(f); 89 | cerr << "error writing file " << fname << endl; 90 | return; 91 | } 92 | fclose(f); 93 | cout << "successful wrote " << writeSize << " bytes to file " << fname << endl; 94 | } 95 | 96 | buffer *b; 97 | -------------------------------------------------------------------------------- /database.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "database.h" 7 | 8 | using namespace std; 9 | 10 | textureDB::textureDB() { 11 | char line[256]; 12 | FILE *f = fopen("tex.db", "rb"); 13 | if (f) { 14 | tval = 0; 15 | entry e; 16 | while (!feof(f)) { 17 | if (fgets(line, 255, f) == 0) continue; 18 | int c = sscanf(line, "%x %x %d", (unsigned long *)(e.name.name), (unsigned long *)(e.name.name + 4), &(e.id)); 19 | if (c==3) { 20 | tlist.push_back(e); 21 | if (e.id >= tval) tval = e.id + 1; 22 | } 23 | } 24 | fclose(f); 25 | } 26 | 27 | } 28 | 29 | textureDB::~textureDB() { 30 | FILE *f = fopen("tex.db", "wb"); 31 | if (f) { 32 | for (vector ::iterator tit=tlist.begin(); tit != tlist.end(); tit++) { 33 | fprintf(f, "%x %x %d\n", *((unsigned long *)(tit->name.name)),*((unsigned long *)(tit->name.name + 4)),tit->id); 34 | } 35 | fclose(f); 36 | } else { 37 | cerr << "error writing updated texture database" << endl; 38 | } 39 | } 40 | 41 | unsigned long textureDB::getID(texn *t) { 42 | for (vector ::iterator tit=tlist.begin(); tit != tlist.end(); tit++) { 43 | if (!memcmp(tit->name.name, t->name, 8)) { 44 | return tit->id; 45 | } 46 | } 47 | entry e; 48 | memcpy(e.name.name, t->name, 8); 49 | e.id = tval; 50 | tlist.push_back(e); 51 | return tval++; 52 | } 53 | 54 | fileDB::fileDB() { 55 | char line[256]; 56 | char name[256]; 57 | FILE *f = fopen("file.db", "rb"); 58 | if (f) { 59 | fval = 0; 60 | entry e; 61 | while (!feof(f)) { 62 | if (fgets(line, 255, f) == 0) continue; 63 | int c = sscanf(line, "%s %d", &(name), &(e.id)); 64 | e.name = name; 65 | if (c==2) { 66 | flist.push_back(e); 67 | if (e.id >= fval) fval = e.id + 1; 68 | } 69 | } 70 | fclose(f); 71 | } 72 | 73 | } 74 | 75 | fileDB::~fileDB() { 76 | FILE *f = fopen("file.db", "wb"); 77 | if (f) { 78 | for (vector ::iterator fit=flist.begin(); fit != flist.end(); fit++) { 79 | fprintf(f, "%s %d\n", fit->name.c_str(), fit->id); 80 | } 81 | fclose(f); 82 | } else { 83 | cerr << "error writing file database" << endl; 84 | } 85 | } 86 | 87 | unsigned long fileDB::getID(string name) { 88 | for (vector ::iterator fit=flist.begin(); fit != flist.end(); fit++) { 89 | if (name == fit->name) { 90 | return fit->id; 91 | } 92 | } 93 | entry e; 94 | e.name = name; 95 | e.id = fval; 96 | flist.push_back(e); 97 | return fval++; 98 | } 99 | 100 | nodeDB::nodeDB() { 101 | } 102 | 103 | nodeDB::~nodeDB() { 104 | } 105 | 106 | unsigned long nodeDB::getID(unsigned long nid, unsigned long sid) { 107 | for (vector ::iterator nit=nlist.begin(); nit != nlist.end(); nit++) { 108 | if (nid == nit->nid) { 109 | return nit->id; 110 | } 111 | } 112 | entry e; 113 | e.nid = nid; 114 | e.sid = sid; 115 | e.id = nval; 116 | nlist.push_back(e); 117 | return nval++; 118 | } 119 | 120 | void nodeDB::clear() { 121 | nlist.clear(); 122 | nval = 0; 123 | } 124 | 125 | meshDB::meshDB() { 126 | } 127 | 128 | meshDB::~meshDB() { 129 | } 130 | 131 | unsigned long meshDB::getID(unsigned long mid) { 132 | for (vector ::iterator mit=mlist.begin(); mit != mlist.end(); mit++) { 133 | if (mid == mit->mid) { 134 | return mit->id; 135 | } 136 | } 137 | entry e; 138 | e.mid = mid; 139 | e.id = mval; 140 | mlist.push_back(e); 141 | return mval++; 142 | } 143 | 144 | void meshDB::clear() { 145 | mlist.clear(); 146 | mval = 0; 147 | } 148 | 149 | fileDB fDB; 150 | textureDB texDB; 151 | nodeDB nDB; 152 | meshDB mDB; 153 | -------------------------------------------------------------------------------- /Unpacker.depend: -------------------------------------------------------------------------------- 1 | # depslib dependency file v1.0 2 | 1415405084 source:c:\users\marc\eigene programme\unpacker\main.cpp 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 1417208773 source:c:\users\marc\google drive\projekte\unpacker\main.cpp 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | "pngwriter.h" 19 | "pvrspi.h" 20 | "buffer.h" 21 | "mt5parser.h" 22 | "database.h" 23 | 24 | 1415771527 source:c:\users\marc\google drive\projekte\unpacker\pvrtdecompress.cpp 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | "PVRTDecompress.h" 33 | 34 | 1415813248 c:\users\marc\google drive\projekte\unpacker\pvrtdecompress.h 35 | 36 | 1416263174 source:c:\users\marc\google drive\projekte\unpacker\pngwriter.cpp 37 | 38 | 39 | 40 | 41 | "pngwriter.h" 42 | 43 | 1415803043 c:\users\marc\google drive\projekte\unpacker\png.h 44 | "pnglibconf.h" 45 | "pngconf.h" 46 | 47 | 1415803043 c:\users\marc\google drive\projekte\unpacker\pnglibconf.h 48 | 49 | 1415803043 c:\users\marc\google drive\projekte\unpacker\pngconf.h 50 | 51 | 52 | 53 | 54 | 55 | 56 | 1416263157 c:\users\marc\google drive\projekte\unpacker\pngwriter.h 57 | 58 | 1415890855 c:\users\marc\google drive\projekte\unpacker\pvrspi.h 59 | 60 | 1416537717 source:c:\users\marc\google drive\projekte\unpacker\pvrspi.cpp 61 | 62 | 63 | 64 | "pvrspi.h" 65 | 66 | 1416320721 source:c:\users\marc\google drive\projekte\unpacker\buffer.cpp 67 | 68 | 69 | 70 | 71 | 72 | "buffer.h" 73 | 74 | 1416320749 c:\users\marc\google drive\projekte\unpacker\buffer.h 75 | 76 | 1417208781 source:c:\users\marc\google drive\projekte\unpacker\mt5parser.cpp 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | "buffer.h" 87 | "pngwriter.h" 88 | "pvrspi.h" 89 | "mt5parser.h" 90 | "taparser.h" 91 | "database.h" 92 | 93 | 1416783330 c:\users\marc\google drive\projekte\unpacker\mt5parser.h 94 | 95 | 96 | "buffer.h" 97 | 98 | 1367191429 c:\users\marc\google drive\projekte\unpacker\zlib.h 99 | "zconf.h" 100 | 101 | 1367186231 c:\users\marc\google drive\projekte\unpacker\zconf.h 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 1416571500 source:c:\users\marc\google drive\projekte\unpacker\taparser.cpp 111 | 112 | 113 | "taparser.h" 114 | "buffer.h" 115 | 116 | 1416571506 c:\users\marc\google drive\projekte\unpacker\taparser.h 117 | "buffer.h" 118 | 119 | 1416783222 c:\users\marc\google drive\projekte\unpacker\texdb.h 120 | 121 | "mt5parser.h" 122 | 123 | 1416784236 source:c:\users\marc\google drive\projekte\unpacker\texdb.cpp 124 | 125 | 126 | 127 | 128 | "texdb.h" 129 | 130 | 1417208409 source:c:\users\marc\google drive\projekte\unpacker\database.cpp 131 | 132 | 133 | 134 | 135 | "database.h" 136 | 137 | 1417208369 c:\users\marc\google drive\projekte\unpacker\database.h 138 | 139 | 140 | "mt5parser.h" 141 | 142 | 1416320722 source:c:\users\march_000\documents\projekte\unpacker\buffer.cpp 143 | 144 | 145 | 146 | 147 | 148 | "buffer.h" 149 | 150 | 1367195030 c:\users\march_000\documents\projekte\unpacker\zlib.h 151 | "zconf.h" 152 | 153 | 1367189832 c:\users\march_000\documents\projekte\unpacker\zconf.h 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 1416320750 c:\users\march_000\documents\projekte\unpacker\buffer.h 163 | 164 | 1417208774 source:c:\users\march_000\documents\projekte\unpacker\main.cpp 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | "pngwriter.h" 173 | "pvrspi.h" 174 | "buffer.h" 175 | "mt5parser.h" 176 | "database.h" 177 | 178 | 1416263158 c:\users\march_000\documents\projekte\unpacker\pngwriter.h 179 | 180 | 1415890856 c:\users\march_000\documents\projekte\unpacker\pvrspi.h 181 | 182 | 1417373809 c:\users\march_000\documents\projekte\unpacker\mt5parser.h 183 | 184 | 185 | "buffer.h" 186 | 187 | 1417375154 c:\users\march_000\documents\projekte\unpacker\database.h 188 | 189 | 190 | "mt5parser.h" 191 | 192 | 1416263176 source:c:\users\march_000\documents\projekte\unpacker\pngwriter.cpp 193 | 194 | 195 | 196 | 197 | "pngwriter.h" 198 | 199 | 1415803044 c:\users\march_000\documents\projekte\unpacker\png.h 200 | "pnglibconf.h" 201 | "pngconf.h" 202 | 203 | 1415803044 c:\users\march_000\documents\projekte\unpacker\pnglibconf.h 204 | 205 | 1415803044 c:\users\march_000\documents\projekte\unpacker\pngconf.h 206 | 207 | 208 | 209 | 210 | 211 | 212 | 1416537718 source:c:\users\march_000\documents\projekte\unpacker\pvrspi.cpp 213 | 214 | 215 | 216 | "pvrspi.h" 217 | 218 | 1416571502 source:c:\users\march_000\documents\projekte\unpacker\taparser.cpp 219 | 220 | 221 | "taparser.h" 222 | "buffer.h" 223 | 224 | 1416571508 c:\users\march_000\documents\projekte\unpacker\taparser.h 225 | "buffer.h" 226 | 227 | 1417377736 source:c:\users\march_000\documents\projekte\unpacker\database.cpp 228 | 229 | 230 | 231 | 232 | "database.h" 233 | 234 | 1417377292 source:c:\users\march_000\documents\projekte\unpacker\mt5parser.cpp 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | "buffer.h" 245 | "pngwriter.h" 246 | "pvrspi.h" 247 | "mt5parser.h" 248 | "taparser.h" 249 | "database.h" 250 | 251 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "pngwriter.h" 10 | #include "pvrspi.h" 11 | #include "buffer.h" 12 | #include "mt5parser.h" 13 | #include "database.h" 14 | 15 | using namespace std; 16 | 17 | struct ipacDirEntry { 18 | char name[9]; 19 | char ext[5]; 20 | unsigned long ipacOfs; 21 | unsigned long ipacSize; 22 | }; 23 | 24 | void convertMT5(buffer *nb, const char *basename, unsigned long nofs, unsigned long nsize) { 25 | buffer *nbuf = new buffer(b, nofs, nsize); 26 | mt5 *mydata = new mt5(); 27 | mydata->readData(nbuf); 28 | 29 | fDB.getID(basename); 30 | 31 | stringstream fname; 32 | fname.clear(); 33 | fname.str(""); 34 | fname << basename; 35 | colladaExport *cExp = new colladaExport(); 36 | cExp->exportModel(fname.str().c_str(), mydata); 37 | 38 | delete cExp; 39 | delete mydata; 40 | delete nbuf; 41 | } 42 | 43 | class ipac { 44 | public: 45 | ipac(unsigned long ofs) { 46 | b->seek(ofs); 47 | unsigned long magic = b->rl(); 48 | if (magic != 'CAPI') { 49 | cerr << "wrong magic number for IPAC" << endl; 50 | exit(1); 51 | } 52 | unsigned long ipacSize1 = b->rl(); 53 | unsigned long ipacNum = b->rl(); 54 | unsigned long ipacSize2 = b->rl(); 55 | cout << "IPAC size1=" << ipacSize1 << " numFiles=" << ipacNum << " size2=" << ipacSize2 << endl; 56 | b->seek(ofs+ipacSize1); 57 | for (unsigned long i=0; irl(); 60 | de.name[8] = 0; 61 | *((unsigned long *)(de.name+4))=b->rl(); 62 | de.ext[4] = 0; 63 | *((unsigned long *)(de.ext))=b->rl(); 64 | de.ipacOfs = b->rl(); 65 | de.ipacSize = b->rl(); 66 | cout << "file " << i << " name=" << de.name << "." << de.ext << " ofs=" << hex << de.ipacOfs << " size=" << de.ipacSize << dec << endl; 67 | stringstream fname; 68 | fname << de.name << "." << de.ext; 69 | b->dump(fname.str().c_str(), de.ipacOfs+ofs, de.ipacSize); 70 | unsigned long savepos = b->tell(); 71 | if (!strcmp(de.ext, "CHRM") || !strcmp(de.ext, "MAPM")) { 72 | cout << "converting map file" << endl; 73 | convertMT5(b, fname.str().c_str(), de.ipacOfs+ofs, de.ipacSize); 74 | } 75 | b->seek(savepos); 76 | ipacDir.push_back(de); 77 | } 78 | } 79 | private: 80 | vector ipacDir; 81 | }; 82 | 83 | class pakf { 84 | public: 85 | pakf() : nTex(0) { 86 | b->seek(0); 87 | unsigned long magic = b->rl(); 88 | if (magic != 'FKAP') { 89 | cerr << "wrong magic number for PAKF" << endl; 90 | exit(1); 91 | } 92 | unsigned long pakfSize = b->rl(); 93 | unsigned long pakfC1 = b->rl(); 94 | unsigned long pakfNumTex = b->rl(); 95 | cout << "PAKF file size=" << pakfSize << " c1=" << hex << pakfC1 << " numTex=" << pakfNumTex << dec << endl; 96 | unsigned long ofs = 16; 97 | do { 98 | b->seek(ofs); 99 | magic = b->rl(); 100 | unsigned long sectionSize = b->rl(); 101 | unsigned long texn1, texn2; 102 | unsigned long gbix; 103 | unsigned long texn3, texn4; 104 | int width, height; 105 | int image_size; 106 | int bits; 107 | unsigned char *outptr; 108 | int ret; 109 | stringstream fname; 110 | switch (magic) { 111 | case (0): 112 | continue; 113 | case ('YMUD'): 114 | cout << "Dummy" << endl; 115 | break; 116 | case ('NXET'): 117 | texn1 = b->rl(); 118 | texn2 = b->rl(); 119 | gbix = b->rl(); 120 | texn3 = b->rl(); 121 | texn4 = b->rl(); 122 | if (gbix != 'XIBG') { 123 | cerr << "no GBIX signature" << endl; 124 | exit(1); 125 | } 126 | cout << "Texture " << hex << nTex << " size=" << sectionSize << " texn1=" << texn1 << " texn2=" << texn2 << dec << endl; 127 | // Dump texture to PVR file 128 | fname.clear(); 129 | fname.str(""); 130 | fname << "tex_" << hex << texn1 << "_" << texn2 << ".pvr" << dec; 131 | b->dump(fname.str().c_str(), b->tell(), sectionSize-28); 132 | // Convert Dreamcast Texture to PNG file for blender export 133 | b->seek(ofs+0x10); 134 | ret = pvr2bin(b->ptr(),outptr,width, height, image_size, bits); 135 | cout << "res:" << ret << " width:" << width << " height:" << height << endl; 136 | fname.clear(); 137 | fname.str(""); 138 | texn t; 139 | memcpy(t.name, &texn1, 4); 140 | memcpy(t.name+4, &texn2, 4); 141 | fname << "t" << hex << texDB.getID(&t) << ".png"; 142 | writePng(fname.str().c_str(), outptr, width, height, bits); 143 | free(outptr); 144 | nTex++; 145 | break; 146 | default: 147 | cerr << "unknown PAKF section type " << (char)magic << (char)(magic>>8) << (char)(magic>>16) << (char)(magic>>24) << ", please check file format" << endl; 148 | exit(1); 149 | } 150 | ofs += sectionSize; 151 | } while (magic != 0); 152 | if (nTex != pakfNumTex) { 153 | cerr << "number of PAKF textures in file not compatible with header" << endl; 154 | exit(1); 155 | } 156 | if (ofs+16 != pakfSize) { 157 | cerr << "size of PAKF payload " << hex << ofs+16 << " in file not compatible with header " << pakfSize << endl; 158 | exit(1); 159 | } 160 | ipacData = new ipac(pakfSize); 161 | } 162 | ~pakf() { 163 | if (ipacData) delete ipacData; 164 | } 165 | private: 166 | unsigned long nTex; 167 | ipac *ipacData; 168 | }; 169 | 170 | class paks { 171 | public: 172 | paks() : ipacData(NULL){ 173 | b->seek(0); 174 | unsigned long magic = b->rl(); 175 | unsigned long paksSize = b->rl(); 176 | unsigned long paksC1 = b->rl(); 177 | unsigned long paksC2 = b->rl(); 178 | if (magic != 'SKAP') { 179 | cerr << "wrong magic number for PAKS" << endl; 180 | exit(1); 181 | } 182 | if (paksSize != 16) { 183 | cerr << "unusual section size of PAKS, please check file format" << endl; 184 | } 185 | cout << "PAKS file c1=" << hex << paksC1 << ", c2=" << paksC2 << dec << endl; 186 | ipacData = new ipac(paksSize); 187 | } 188 | ~paks() { 189 | if (ipacData) delete ipacData; 190 | } 191 | private: 192 | ipac *ipacData; 193 | }; 194 | 195 | int main(int argc, char **argv) 196 | { 197 | if (argc != 2) { 198 | fprintf (stderr, "This program unpacks Shenmue *.PKF, *.PFS files and *.MT5 files.\nUsage %s \n", argv[0]); 199 | exit(-1); 200 | } 201 | paks *myPaks; 202 | pakf *myPakf; 203 | 204 | b = new buffer(argv[1]); 205 | b->seek(0); 206 | unsigned long magic = b->rl(); 207 | switch (magic) { 208 | case ('SKAP'): 209 | myPaks = new paks(); 210 | break; 211 | case ('FKAP'): 212 | myPakf = new pakf(); 213 | break; 214 | case ('MCRH'): 215 | convertMT5(b, argv[1], 0, b->blen()); 216 | break; 217 | } 218 | return 0; 219 | } 220 | -------------------------------------------------------------------------------- /pnglibconf.h: -------------------------------------------------------------------------------- 1 | /* pnglibconf.h - library build configuration */ 2 | 3 | /* libpng version 1.6.14 - October 23, 2014 */ 4 | 5 | /* Copyright (c) 1998-2014 Glenn Randers-Pehrson */ 6 | 7 | /* This code is released under the libpng license. */ 8 | /* For conditions of distribution and use, see the disclaimer */ 9 | /* and license in png.h */ 10 | 11 | /* pnglibconf.h */ 12 | /* Machine generated file: DO NOT EDIT */ 13 | /* Derived from: scripts/pnglibconf.dfa */ 14 | #ifndef PNGLCONF_H 15 | #define PNGLCONF_H 16 | /* options */ 17 | #define PNG_16BIT_SUPPORTED 18 | #define PNG_ALIGNED_MEMORY_SUPPORTED 19 | /*#undef PNG_ARM_NEON_API_SUPPORTED*/ 20 | /*#undef PNG_ARM_NEON_CHECK_SUPPORTED*/ 21 | #define PNG_BENIGN_ERRORS_SUPPORTED 22 | #define PNG_BENIGN_READ_ERRORS_SUPPORTED 23 | /*#undef PNG_BENIGN_WRITE_ERRORS_SUPPORTED*/ 24 | #define PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED 25 | #define PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED 26 | #define PNG_COLORSPACE_SUPPORTED 27 | #define PNG_CONSOLE_IO_SUPPORTED 28 | #define PNG_CONVERT_tIME_SUPPORTED 29 | #define PNG_EASY_ACCESS_SUPPORTED 30 | /*#undef PNG_ERROR_NUMBERS_SUPPORTED*/ 31 | #define PNG_ERROR_TEXT_SUPPORTED 32 | #define PNG_FIXED_POINT_SUPPORTED 33 | #define PNG_FLOATING_ARITHMETIC_SUPPORTED 34 | #define PNG_FLOATING_POINT_SUPPORTED 35 | #define PNG_FORMAT_AFIRST_SUPPORTED 36 | #define PNG_FORMAT_BGR_SUPPORTED 37 | #define PNG_GAMMA_SUPPORTED 38 | #define PNG_GET_PALETTE_MAX_SUPPORTED 39 | #define PNG_HANDLE_AS_UNKNOWN_SUPPORTED 40 | #define PNG_INCH_CONVERSIONS_SUPPORTED 41 | #define PNG_INFO_IMAGE_SUPPORTED 42 | #define PNG_IO_STATE_SUPPORTED 43 | #define PNG_MNG_FEATURES_SUPPORTED 44 | #define PNG_POINTER_INDEXING_SUPPORTED 45 | #define PNG_PROGRESSIVE_READ_SUPPORTED 46 | #define PNG_READ_16BIT_SUPPORTED 47 | #define PNG_READ_ALPHA_MODE_SUPPORTED 48 | #define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED 49 | #define PNG_READ_BACKGROUND_SUPPORTED 50 | #define PNG_READ_BGR_SUPPORTED 51 | #define PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED 52 | #define PNG_READ_COMPOSITE_NODIV_SUPPORTED 53 | #define PNG_READ_COMPRESSED_TEXT_SUPPORTED 54 | #define PNG_READ_EXPAND_16_SUPPORTED 55 | #define PNG_READ_EXPAND_SUPPORTED 56 | #define PNG_READ_FILLER_SUPPORTED 57 | #define PNG_READ_GAMMA_SUPPORTED 58 | #define PNG_READ_GET_PALETTE_MAX_SUPPORTED 59 | #define PNG_READ_GRAY_TO_RGB_SUPPORTED 60 | #define PNG_READ_INTERLACING_SUPPORTED 61 | #define PNG_READ_INT_FUNCTIONS_SUPPORTED 62 | #define PNG_READ_INVERT_ALPHA_SUPPORTED 63 | #define PNG_READ_INVERT_SUPPORTED 64 | #define PNG_READ_OPT_PLTE_SUPPORTED 65 | #define PNG_READ_PACKSWAP_SUPPORTED 66 | #define PNG_READ_PACK_SUPPORTED 67 | #define PNG_READ_QUANTIZE_SUPPORTED 68 | #define PNG_READ_RGB_TO_GRAY_SUPPORTED 69 | #define PNG_READ_SCALE_16_TO_8_SUPPORTED 70 | #define PNG_READ_SHIFT_SUPPORTED 71 | #define PNG_READ_STRIP_16_TO_8_SUPPORTED 72 | #define PNG_READ_STRIP_ALPHA_SUPPORTED 73 | #define PNG_READ_SUPPORTED 74 | #define PNG_READ_SWAP_ALPHA_SUPPORTED 75 | #define PNG_READ_SWAP_SUPPORTED 76 | #define PNG_READ_TEXT_SUPPORTED 77 | #define PNG_READ_TRANSFORMS_SUPPORTED 78 | #define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED 79 | #define PNG_READ_USER_CHUNKS_SUPPORTED 80 | #define PNG_READ_USER_TRANSFORM_SUPPORTED 81 | #define PNG_READ_bKGD_SUPPORTED 82 | #define PNG_READ_cHRM_SUPPORTED 83 | #define PNG_READ_gAMA_SUPPORTED 84 | #define PNG_READ_hIST_SUPPORTED 85 | #define PNG_READ_iCCP_SUPPORTED 86 | #define PNG_READ_iTXt_SUPPORTED 87 | #define PNG_READ_oFFs_SUPPORTED 88 | #define PNG_READ_pCAL_SUPPORTED 89 | #define PNG_READ_pHYs_SUPPORTED 90 | #define PNG_READ_sBIT_SUPPORTED 91 | #define PNG_READ_sCAL_SUPPORTED 92 | #define PNG_READ_sPLT_SUPPORTED 93 | #define PNG_READ_sRGB_SUPPORTED 94 | #define PNG_READ_tEXt_SUPPORTED 95 | #define PNG_READ_tIME_SUPPORTED 96 | #define PNG_READ_tRNS_SUPPORTED 97 | #define PNG_READ_zTXt_SUPPORTED 98 | /*#undef PNG_SAFE_LIMITS_SUPPORTED*/ 99 | #define PNG_SAVE_INT_32_SUPPORTED 100 | #define PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED 101 | #define PNG_SEQUENTIAL_READ_SUPPORTED 102 | #define PNG_SETJMP_SUPPORTED 103 | #define PNG_SET_CHUNK_CACHE_LIMIT_SUPPORTED 104 | #define PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED 105 | #define PNG_SET_OPTION_SUPPORTED 106 | #define PNG_SET_UNKNOWN_CHUNKS_SUPPORTED 107 | #define PNG_SET_USER_LIMITS_SUPPORTED 108 | #define PNG_SIMPLIFIED_READ_AFIRST_SUPPORTED 109 | #define PNG_SIMPLIFIED_READ_BGR_SUPPORTED 110 | #define PNG_SIMPLIFIED_READ_SUPPORTED 111 | #define PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED 112 | #define PNG_SIMPLIFIED_WRITE_BGR_SUPPORTED 113 | #define PNG_SIMPLIFIED_WRITE_SUPPORTED 114 | #define PNG_STDIO_SUPPORTED 115 | #define PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED 116 | #define PNG_TEXT_SUPPORTED 117 | #define PNG_TIME_RFC1123_SUPPORTED 118 | #define PNG_UNKNOWN_CHUNKS_SUPPORTED 119 | #define PNG_USER_CHUNKS_SUPPORTED 120 | #define PNG_USER_LIMITS_SUPPORTED 121 | #define PNG_USER_MEM_SUPPORTED 122 | #define PNG_USER_TRANSFORM_INFO_SUPPORTED 123 | #define PNG_USER_TRANSFORM_PTR_SUPPORTED 124 | #define PNG_WARNINGS_SUPPORTED 125 | #define PNG_WRITE_16BIT_SUPPORTED 126 | #define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED 127 | #define PNG_WRITE_BGR_SUPPORTED 128 | #define PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED 129 | #define PNG_WRITE_COMPRESSED_TEXT_SUPPORTED 130 | #define PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED 131 | #define PNG_WRITE_FILLER_SUPPORTED 132 | #define PNG_WRITE_FILTER_SUPPORTED 133 | #define PNG_WRITE_FLUSH_SUPPORTED 134 | #define PNG_WRITE_GET_PALETTE_MAX_SUPPORTED 135 | #define PNG_WRITE_INTERLACING_SUPPORTED 136 | #define PNG_WRITE_INT_FUNCTIONS_SUPPORTED 137 | #define PNG_WRITE_INVERT_ALPHA_SUPPORTED 138 | #define PNG_WRITE_INVERT_SUPPORTED 139 | #define PNG_WRITE_OPTIMIZE_CMF_SUPPORTED 140 | #define PNG_WRITE_PACKSWAP_SUPPORTED 141 | #define PNG_WRITE_PACK_SUPPORTED 142 | #define PNG_WRITE_SHIFT_SUPPORTED 143 | #define PNG_WRITE_SUPPORTED 144 | #define PNG_WRITE_SWAP_ALPHA_SUPPORTED 145 | #define PNG_WRITE_SWAP_SUPPORTED 146 | #define PNG_WRITE_TEXT_SUPPORTED 147 | #define PNG_WRITE_TRANSFORMS_SUPPORTED 148 | #define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED 149 | #define PNG_WRITE_USER_TRANSFORM_SUPPORTED 150 | #define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 151 | #define PNG_WRITE_bKGD_SUPPORTED 152 | #define PNG_WRITE_cHRM_SUPPORTED 153 | #define PNG_WRITE_gAMA_SUPPORTED 154 | #define PNG_WRITE_hIST_SUPPORTED 155 | #define PNG_WRITE_iCCP_SUPPORTED 156 | #define PNG_WRITE_iTXt_SUPPORTED 157 | #define PNG_WRITE_oFFs_SUPPORTED 158 | #define PNG_WRITE_pCAL_SUPPORTED 159 | #define PNG_WRITE_pHYs_SUPPORTED 160 | #define PNG_WRITE_sBIT_SUPPORTED 161 | #define PNG_WRITE_sCAL_SUPPORTED 162 | #define PNG_WRITE_sPLT_SUPPORTED 163 | #define PNG_WRITE_sRGB_SUPPORTED 164 | #define PNG_WRITE_tEXt_SUPPORTED 165 | #define PNG_WRITE_tIME_SUPPORTED 166 | #define PNG_WRITE_tRNS_SUPPORTED 167 | #define PNG_WRITE_zTXt_SUPPORTED 168 | #define PNG_bKGD_SUPPORTED 169 | #define PNG_cHRM_SUPPORTED 170 | #define PNG_gAMA_SUPPORTED 171 | #define PNG_hIST_SUPPORTED 172 | #define PNG_iCCP_SUPPORTED 173 | #define PNG_iTXt_SUPPORTED 174 | #define PNG_oFFs_SUPPORTED 175 | #define PNG_pCAL_SUPPORTED 176 | #define PNG_pHYs_SUPPORTED 177 | #define PNG_sBIT_SUPPORTED 178 | #define PNG_sCAL_SUPPORTED 179 | #define PNG_sPLT_SUPPORTED 180 | #define PNG_sRGB_SUPPORTED 181 | #define PNG_tEXt_SUPPORTED 182 | #define PNG_tIME_SUPPORTED 183 | #define PNG_tRNS_SUPPORTED 184 | #define PNG_zTXt_SUPPORTED 185 | /* end of options */ 186 | /* settings */ 187 | #define PNG_API_RULE 0 188 | #define PNG_COST_SHIFT 3 189 | #define PNG_DEFAULT_READ_MACROS 1 190 | #define PNG_GAMMA_THRESHOLD_FIXED 5000 191 | #define PNG_IDAT_READ_SIZE PNG_ZBUF_SIZE 192 | #define PNG_INFLATE_BUF_SIZE 1024 193 | #define PNG_MAX_GAMMA_8 11 194 | #define PNG_QUANTIZE_BLUE_BITS 5 195 | #define PNG_QUANTIZE_GREEN_BITS 5 196 | #define PNG_QUANTIZE_RED_BITS 5 197 | #define PNG_TEXT_Z_DEFAULT_COMPRESSION (-1) 198 | #define PNG_TEXT_Z_DEFAULT_STRATEGY 0 199 | #define PNG_WEIGHT_SHIFT 8 200 | #define PNG_ZBUF_SIZE 8192 201 | #define PNG_ZLIB_VERNUM 0x1280 202 | #define PNG_Z_DEFAULT_COMPRESSION (-1) 203 | #define PNG_Z_DEFAULT_NOFILTER_STRATEGY 0 204 | #define PNG_Z_DEFAULT_STRATEGY 1 205 | #define PNG_sCAL_PRECISION 5 206 | #define PNG_sRGB_PROFILE_CHECKS 2 207 | /* end of settings */ 208 | #endif /* PNGLCONF_H */ 209 | -------------------------------------------------------------------------------- /pvrspi.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "pvrspi.h" 6 | 7 | typedef struct { 8 | unsigned char id[4]; 9 | unsigned long length; 10 | unsigned char type[4]; 11 | unsigned short width; 12 | unsigned short height; 13 | } PVRHDR; 14 | 15 | #define SKIP_GBIX(data) \ 16 | if (memcmp(data,"GBIX",4)==0) {\ 17 | long size = ((long*)data)[1]; \ 18 | data+=size+8; \ 19 | } 20 | 21 | enum {ARGB1555,RGB565,ARGB4444,YUV422,BUMP,PAL4,PAL8}; 22 | 23 | int pvr2binhdr(int &width, int &height, int &img_size,int &bits, PVRHDR *hdr); 24 | int pvr2bindata(unsigned char *pbin,const PVRHDR *hdr); 25 | 26 | int pvr2bin(const unsigned char *buf,unsigned char *&res, int &width, int &height, int &img_size, int &bits) 27 | { 28 | const unsigned char *data; 29 | PVRHDR *hdr; 30 | 31 | data = buf; 32 | SKIP_GBIX(data); 33 | if (memcmp(data,"PVRT",4)) return -1; 34 | hdr = (PVRHDR*)data; 35 | 36 | pvr2binhdr(width, height, img_size, bits, hdr); 37 | res = (unsigned char *)malloc(img_size); 38 | pvr2bindata(res,hdr); 39 | 40 | return 0; 41 | } 42 | 43 | static int calc_n(int n) 44 | { 45 | int sum = 1; 46 | while(n) { 47 | n>>=1; 48 | sum +=n*n; 49 | } 50 | return sum; 51 | } 52 | 53 | typedef struct { 54 | int rmask, rmult, radd, rshift; 55 | int gmask, gmult, gadd, gshift; 56 | int bmask, bmult, badd, bshift; 57 | int amask, amult, aadd, ashift; 58 | } SHIFTTBL; 59 | 60 | const static SHIFTTBL shifttbl[]= { 61 | { /* ARGB1555 */ 62 | 0x7c00, 527, 23<<10, 16, 63 | 0x03e0, 527, 23<<5, 11, 64 | 0x001f, 527, 23, 6, 65 | 0x8000, 0x1ff, 0, 16 66 | },{ 67 | /* RGB565 */ 68 | 0xf800, 527, 23<<11, 17, 69 | 0x07e0, 259, 33<<5, 11, 70 | 0x001f, 527, 23, 6, 71 | 0x0000, 0, 0xff, 0 72 | },{ 73 | /* ARGB4444 */ 74 | 0x0f00, 1088, 32<<8, 14, 75 | 0x00f0, 1088, 32<<4, 10, 76 | 0x000f, 1088, 32, 6, 77 | 0xf000, 1088, 32<<12, 18 78 | } 79 | }; 80 | 81 | static unsigned long twiddle(unsigned long xSize, unsigned long ySize, unsigned long xPos, unsigned long yPos) 82 | { 83 | //Initially assume X is the larger size. 84 | unsigned long minDimension=xSize; 85 | unsigned long maxValue=yPos; 86 | unsigned long twiddled=0; 87 | unsigned long srcBitPos=1; 88 | unsigned long dstBitPos=1; 89 | int shiftCount=0; 90 | 91 | //If Y is the larger dimension - switch the min/max values. 92 | if(xSize > ySize) { 93 | minDimension = ySize; 94 | maxValue = xPos; 95 | } 96 | 97 | // Step through all the bits in the "minimum" dimension 98 | while(srcBitPos < minDimension) { 99 | if(yPos & srcBitPos) twiddled |= dstBitPos; 100 | if(xPos & srcBitPos) twiddled |= (dstBitPos << 1); 101 | srcBitPos <<= 1; 102 | dstBitPos <<= 2; 103 | shiftCount += 1; 104 | } 105 | 106 | // Prepend any unused bits 107 | maxValue >>= shiftCount; 108 | twiddled |= (maxValue << (2*shiftCount)); 109 | 110 | return twiddled; 111 | } 112 | 113 | enum {R,G,B,A}; 114 | 115 | int decode_small_vq(unsigned char *out,const unsigned char *in0,const unsigned char *in1,int width,int height,int mode) 116 | { 117 | unsigned char vqtab[4*4*16]; 118 | const unsigned char *in; 119 | 120 | int x,y,wbyte; 121 | const SHIFTTBL *s; 122 | 123 | const unsigned short *in_w = (unsigned short *) in1; 124 | unsigned char *p = vqtab; 125 | 126 | s = &shifttbl[mode]; 127 | for(x=0;x<16*4;x++) { 128 | int c = in_w[x]; 129 | p[R] = ((c & s->rmask) * s->rmult + s->radd) >> s->rshift; 130 | p[G] = ((c & s->gmask) * s->gmult + s->gadd) >> s->gshift; 131 | p[B] = ((c & s->bmask) * s->bmult + s->badd) >> s->bshift; 132 | p[A] = ((c & s->amask) * s->amult + s->aadd) >> s->ashift; 133 | p+=4; 134 | } 135 | 136 | in = in0; 137 | wbyte = width*4; 138 | for(y=0;y>4)*16]; 167 | p-=wbyte*2; 168 | 169 | p[0] = vq[0]; 170 | p[1] = vq[1]; 171 | p[2] = vq[2]; 172 | p[3] = vq[3]; 173 | 174 | p[4] = vq[8]; 175 | p[5] = vq[9]; 176 | p[6] = vq[10]; 177 | p[7] = vq[11]; 178 | 179 | p[0-wbyte] = vq[4]; 180 | p[1-wbyte] = vq[5]; 181 | p[2-wbyte] = vq[6]; 182 | p[3-wbyte] = vq[7]; 183 | 184 | p[4-wbyte] = vq[12]; 185 | p[5-wbyte] = vq[13]; 186 | p[6-wbyte] = vq[14]; 187 | p[7-wbyte] = vq[15]; 188 | 189 | p+=wbyte*2; 190 | p+=8; 191 | } 192 | } 193 | return 0; 194 | } 195 | 196 | int decode_twiddled_vq(unsigned char *out,const unsigned char *in0,const unsigned char *in1,int width,int height,int mode) 197 | { 198 | unsigned char vqtab[4*4*256]; 199 | const unsigned char *in; 200 | 201 | int x,y,wbyte; 202 | const SHIFTTBL *s; 203 | 204 | const unsigned short *in_w = (const unsigned short *)in1; 205 | unsigned char *p = vqtab; 206 | 207 | s = &shifttbl[mode]; 208 | for(x=0;x<256*4;x++) { 209 | int c = in_w[x]; 210 | p[R] = ((c & s->rmask) * s->rmult + s->radd) >> s->rshift; 211 | p[G] = ((c & s->gmask) * s->gmult + s->gadd) >> s->gshift; 212 | p[B] = ((c & s->bmask) * s->bmult + s->badd) >> s->bshift; 213 | p[A] = ((c & s->amask) * s->amult + s->aadd) >> s->ashift; 214 | p+=4; 215 | } 216 | 217 | in = in0; 218 | wbyte = width*4; 219 | for(y=0;y>4) | (c1&0xf0); 267 | } 268 | } 269 | break; 270 | case PAL8: 271 | wbyte = (width+3)&~3; 272 | for(y=0;yrmask) * s->rmult + s->radd) >> s->rshift; 289 | p[G] = ((c & s->gmask) * s->gmult + s->gadd) >> s->gshift; 290 | p[B] = ((c & s->bmask) * s->bmult + s->badd) >> s->bshift; 291 | p[A] = ((c & s->amask) * s->amult + s->aadd) >> s->ashift; 292 | p+=4; 293 | } 294 | } 295 | } 296 | return 0; 297 | } 298 | 299 | int decode_rectangle(unsigned char *out,const unsigned char *in0,int width,int height,int mode) 300 | { 301 | int x,y,wbyte; 302 | const SHIFTTBL *s; 303 | if (mode<=2) 304 | s = &shifttbl[mode]; 305 | 306 | wbyte = width*4; 307 | for(y=0;yrmask) * s->rmult + s->radd) >> s->rshift; 313 | p[G] = ((c & s->gmask) * s->gmult + s->gadd) >> s->gshift; 314 | p[B] = ((c & s->bmask) * s->bmult + s->badd) >> s->bshift; 315 | p[A] = ((c & s->amask) * s->amult + s->aadd) >> s->ashift; 316 | p+=4; 317 | } 318 | } 319 | return 0; 320 | } 321 | 322 | int decode_rectangle_twiddled(unsigned char *out,const unsigned char *in0,int width,int height,int mode) 323 | { 324 | int x,y,wbyte; 325 | const SHIFTTBL *s; 326 | if (mode<=2) 327 | s = &shifttbl[mode]; 328 | 329 | wbyte = width*4; 330 | for(y=0;yrmask) * s->rmult + s->radd) >> s->rshift; 336 | p[G] = ((c & s->gmask) * s->gmult + s->gadd) >> s->gshift; 337 | p[B] = ((c & s->bmask) * s->bmult + s->badd) >> s->bshift; 338 | p[A] = ((c & s->amask) * s->amult + s->aadd) >> s->ashift; 339 | p+=4; 340 | } 341 | } 342 | return 0; 343 | } 344 | 345 | int pvr2binhdr(int &width, int &height, int &img_size,int &bits, PVRHDR *hdr) 346 | { 347 | // !!MH!! change handling to include both 24 and 32 bit color depth. 348 | // Right now the alpha channel is always used. 349 | switch(hdr->type[0]){ 350 | case 0x00: /* ARGB155 */ 351 | case 0x01: /* RGB565 */ 352 | case 0x02: /* ARGB4444 */ 353 | case 0x03: /* YUV422 */ 354 | bits = 32; break; 355 | case 0x04: /* BUMP */ 356 | case 0x05: /* 4BPP */ 357 | bits = 4; break; 358 | case 0x06: /* 8BPP */ 359 | bits = 8; break; 360 | default: 361 | break; 362 | } 363 | width = hdr->width; 364 | height = hdr->height; 365 | img_size = ((hdr->width*bits/8+3)&~3) * hdr->height; 366 | return 0; 367 | } 368 | 369 | int pvr2bindata(unsigned char *pbin,const PVRHDR *hdr) 370 | { 371 | const unsigned char *data = (const unsigned char*)(hdr+1); 372 | 373 | switch(hdr->type[1]){ 374 | case 0x01: /* twiddled */ 375 | decode_twiddled(pbin,data,hdr->width,hdr->height,hdr->type[0]); 376 | break; 377 | case 0x02: /* twiddled & mipmap */ 378 | decode_twiddled(pbin,data+calc_n(hdr->width)*2,hdr->width,hdr->height,hdr->type[0]); 379 | break; 380 | case 0x03: /* VQ */ 381 | decode_twiddled_vq(pbin,data+2048,data,hdr->width,hdr->height,hdr->type[0]); 382 | break; 383 | case 0x04: /* VQ & MIPMAP */ 384 | decode_twiddled_vq(pbin,data+2048+calc_n(hdr->width/2),data,hdr->width,hdr->height,hdr->type[0]); 385 | break; 386 | case 0x05: /* twiddled 4bit? */ 387 | decode_twiddled(pbin,data,hdr->width,hdr->height,hdr->type[0]); 388 | break; 389 | case 0x06: /* twiddled & mipmap 4bit? */ 390 | decode_twiddled(pbin,data+calc_n(hdr->width)/2,hdr->width,hdr->height,hdr->type[0]); 391 | break; 392 | case 0x07: /* twiddled 8bit? */ 393 | decode_twiddled(pbin,data,hdr->width,hdr->height,hdr->type[0]); 394 | break; 395 | case 0x08: /* twiddled & mipmap 8bit? */ 396 | decode_twiddled(pbin,data+calc_n(hdr->width),hdr->width,hdr->height,hdr->type[0]); 397 | break; 398 | case 0x09: /* RECTANGLE */ 399 | decode_rectangle(pbin,data,hdr->width,hdr->height,hdr->type[0]); 400 | break; 401 | case 0x0d: /* RECTANGLE twiddled */ 402 | decode_rectangle_twiddled(pbin,data,hdr->width,hdr->height,hdr->type[0]); 403 | break; 404 | case 0x10: /* SMALL_VQ */ 405 | decode_small_vq(pbin,data+128,data,hdr->width,hdr->height,hdr->type[0]); 406 | break; 407 | case 0x11: /* SMALL_VQ & MIPMAP */ 408 | decode_small_vq(pbin,data+128+calc_n(hdr->width/2)/2,data,hdr->width,hdr->height,hdr->type[0]); 409 | break; 410 | default: 411 | break; 412 | } 413 | return 0; 414 | } 415 | -------------------------------------------------------------------------------- /taparser.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "taparser.h" 5 | #include "buffer.h" 6 | 7 | using namespace std; 8 | 9 | taparser::taparser(buffer *buf, const unsigned long ofs) { 10 | buf->seek(ofs); 11 | for (int i=0;i<7;i++) globalParam[i] = buf->rl(); 12 | 13 | paraType = bits(PARAM_CTRL, 29, 31); 14 | endOfStrip = bits(PARAM_CTRL, 28, 28); 15 | listType = bits(PARAM_CTRL, 24, 26); 16 | groupEn = bits(PARAM_CTRL, 23, 23); 17 | stripLen = bits(PARAM_CTRL, 18, 19); 18 | userClip = bits(PARAM_CTRL, 16, 17); 19 | shadow = bits(PARAM_CTRL, 7, 7); 20 | volume = bits(PARAM_CTRL, 6, 6); 21 | colType = bits(PARAM_CTRL, 4, 5); 22 | texture = bits(PARAM_CTRL, 3, 3); 23 | offset = bits(PARAM_CTRL, 2, 2); 24 | gouraud = bits(PARAM_CTRL, 1, 1); 25 | uv16Bit = bits(PARAM_CTRL, 0, 0); 26 | 27 | depthCompare = bits(ISP_TSP_INSTR, 29, 31); 28 | cullingMode = bits(ISP_TSP_INSTR, 27,28); 29 | zWriteDisable = bits(ISP_TSP_INSTR, 26, 26); 30 | cacheBypass = bits(ISP_TSP_INSTR, 21, 21); 31 | dCalcCtrl = bits(ISP_TSP_INSTR, 20, 20); 32 | 33 | srcAlphaInstr = bits(TSP_INSTR, 29, 31); 34 | dstAlphaInstr = bits(TSP_INSTR, 26, 28); 35 | srcSelect = bits(TSP_INSTR, 25, 25); 36 | dstSelect = bits(TSP_INSTR, 24, 24); 37 | fogControl = bits(TSP_INSTR, 22, 23); 38 | colorClamp = bits(TSP_INSTR, 21, 21); 39 | useAlpha = bits(TSP_INSTR, 20, 20); 40 | ignoreTexAlpha = bits(TSP_INSTR, 19, 19); 41 | flipUV = bits(TSP_INSTR, 17, 18); 42 | clampUV = bits(TSP_INSTR, 15, 16); 43 | filterMode = bits(TSP_INSTR, 13, 14); 44 | superSampleTex = bits(TSP_INSTR, 12, 12); 45 | mipMapDAdj = bits(TSP_INSTR, 8, 11); 46 | texShadInstr = bits(TSP_INSTR, 6, 7); 47 | texUSize = bits(TSP_INSTR, 3, 5); 48 | texVSize = bits(TSP_INSTR, 0, 2); 49 | 50 | mipMapped = bits(TEXTURE_CTRL, 31, 31); 51 | vqCompressed = bits(TEXTURE_CTRL, 30, 30); 52 | pixelFormat = bits(TEXTURE_CTRL, 27, 29); 53 | scanOrder = bits(TEXTURE_CTRL, 26, 26); 54 | strideSelect = bits(TEXTURE_CTRL, 25, 25); 55 | paletteSelector = bits(TEXTURE_CTRL, 21, 26); 56 | } 57 | 58 | taparser::~taparser() { 59 | } 60 | 61 | void taparser::dump() { 62 | string paraTypeStr; 63 | switch (paraType) { 64 | case (0): 65 | paraTypeStr = "End_of_List"; 66 | break; 67 | case (1): 68 | paraTypeStr = "User_Tile_Clip"; 69 | break; 70 | case (2): 71 | paraTypeStr = "Object_List_Set"; 72 | break; 73 | case (3): 74 | paraTypeStr = "Reserved_(Control_Parameter)"; 75 | break; 76 | case (4): 77 | paraTypeStr = "Polygon_or_Modifier_Volume"; 78 | break; 79 | case (5): 80 | paraTypeStr = "Sprite"; 81 | break; 82 | case (6): 83 | paraTypeStr = "Reserved_(Global_Parameter)"; 84 | break; 85 | case (7): 86 | paraTypeStr = "Vertex_Parameter"; 87 | break; 88 | } 89 | cout << paraTypeStr << " "; 90 | 91 | if (paraType == 1 || paraType == 2 || paraType == 4 || paraType == 5) { 92 | string listTypeStr; 93 | switch (listType) { 94 | case (0): 95 | listTypeStr = "Opaque"; 96 | break; 97 | case (1): 98 | listTypeStr = "Opaque_Modifier_Volume"; 99 | break; 100 | case (2): 101 | listTypeStr = "Translucent"; 102 | break; 103 | case (3): 104 | listTypeStr = "Translucent_Modifier_Volume"; 105 | break; 106 | case (4): 107 | listTypeStr = "Punch_Through"; 108 | break; 109 | default: 110 | listTypeStr = "Reserved_(prohibited)"; 111 | break; 112 | } 113 | cout << listTypeStr << " "; 114 | } 115 | 116 | if (paraType == 4 || paraType == 5) { 117 | string stripLenStr; 118 | switch (stripLen) { 119 | case (0): 120 | stripLenStr = "1strip"; 121 | break; 122 | case (1): 123 | stripLenStr = "2strip"; 124 | break; 125 | case (2): 126 | stripLenStr = "4strip"; 127 | break; 128 | case (3): 129 | stripLenStr = "6strip"; 130 | break; 131 | } 132 | 133 | string userClipStr; 134 | switch (userClip) { 135 | case(0): 136 | userClipStr = "Disable"; 137 | break; 138 | case(1): 139 | userClipStr = "Reserved_(userClip)"; 140 | break; 141 | case (2): 142 | userClipStr = "Inside_enable"; 143 | break; 144 | case (3): 145 | userClipStr = "Outside_enable"; 146 | break; 147 | } 148 | cout << "stripLen:" << stripLenStr << " userClip:" << userClipStr << " "; 149 | 150 | string srcAlphaInstrStr; 151 | switch (srcAlphaInstr) { 152 | case(0): 153 | srcAlphaInstrStr = "Zero"; 154 | break; 155 | case(1): 156 | srcAlphaInstrStr = "One"; 157 | break; 158 | case(2): 159 | srcAlphaInstrStr = "Other_Color"; 160 | break; 161 | case(3): 162 | srcAlphaInstrStr = "Inverse_Other_Color"; 163 | break; 164 | case(4): 165 | srcAlphaInstrStr = "Src_Alpha"; 166 | break; 167 | case(5): 168 | srcAlphaInstrStr = "Inverse_Src_Alpha"; 169 | break; 170 | case(6): 171 | srcAlphaInstrStr = "Dst_Alpha"; 172 | break; 173 | case(7): 174 | srcAlphaInstrStr = "Inverse_Dst_Alpha"; 175 | break; 176 | } 177 | string dstAlphaInstrStr; 178 | switch (dstAlphaInstr) { 179 | case(0): 180 | dstAlphaInstrStr = "Zero"; 181 | break; 182 | case(1): 183 | dstAlphaInstrStr = "One"; 184 | break; 185 | case(2): 186 | dstAlphaInstrStr = "Other_Color"; 187 | break; 188 | case(3): 189 | dstAlphaInstrStr = "Inverse_Other_Color"; 190 | break; 191 | case(4): 192 | dstAlphaInstrStr = "Src_Alpha"; 193 | break; 194 | case(5): 195 | dstAlphaInstrStr = "Inverse_Src_Alpha"; 196 | break; 197 | case(6): 198 | dstAlphaInstrStr = "Dst_Alpha"; 199 | break; 200 | case(7): 201 | dstAlphaInstrStr = "Inverse_Dst_Alpha"; 202 | break; 203 | } 204 | string fogControlStr; 205 | switch (fogControl) { 206 | case(0): 207 | fogControlStr="Fog:Look_up_table"; 208 | break; 209 | case(1): 210 | fogControlStr="Fog:PerVertex"; 211 | break; 212 | case(2): 213 | fogControlStr="No_Fog"; 214 | break; 215 | case(3): 216 | fogControlStr="Fog:Look_up_table_Mode_2"; 217 | break; 218 | } 219 | string filterModeStr; 220 | switch (filterMode) { 221 | case(0): 222 | filterModeStr = "Point_sampled"; 223 | break; 224 | case(1): 225 | filterModeStr = "Bilinear"; 226 | break; 227 | case(2): 228 | filterModeStr = "Trilinear_Pass_A"; 229 | break; 230 | case(3): 231 | filterModeStr = "Trilinear_Pass_B"; 232 | break; 233 | } 234 | string texShadInstrStr; 235 | switch (texShadInstr) { 236 | case(0): 237 | texShadInstrStr ="Decal"; 238 | break; 239 | case(1): 240 | texShadInstrStr ="Modulate"; 241 | break; 242 | case(2): 243 | texShadInstrStr ="Decal_Alpha"; 244 | break; 245 | case(3): 246 | texShadInstrStr ="Modulate_Alpha"; 247 | break; 248 | } 249 | cout << "srcAlphaInstrStr:" << srcAlphaInstrStr << " dstAlphaInstrStr:" << dstAlphaInstrStr << " srcSelect:" << srcSelect << " dstSelect:" << dstSelect << " " << fogControlStr 250 | << " colorClamp:" << colorClamp << " useAlpha(Color):" << useAlpha << " ignoreTexAlpha:" << ignoreTexAlpha << " flipUV:" << flipUV 251 | << " clampUV:" << clampUV << " filterMode:" << filterModeStr << " superSampleTex:" << superSampleTex << " mipMapDAdj:" << 0.25 * (float)mipMapDAdj 252 | << " texShadInstr:" << texShadInstrStr << " "; 253 | 254 | string cullingModeStr; 255 | switch (cullingMode) { 256 | case (0): 257 | cullingModeStr = "no_culling"; 258 | break; 259 | case (1): 260 | cullingModeStr = "cull_if_small"; 261 | break; 262 | case (2): 263 | cullingModeStr = "cull_if_negative"; 264 | break; 265 | case (3): 266 | cullingModeStr = "cull_if_positive"; 267 | break; 268 | } 269 | if (listType == 1 || listType == 3) { 270 | string volumeInstrStr; 271 | switch (depthCompare) { 272 | case(0): 273 | volumeInstrStr = "normal_polygon"; 274 | break; 275 | case(1): 276 | volumeInstrStr = "inside_last_polygon"; 277 | break; 278 | case(2): 279 | volumeInstrStr = "outside_last_polygon"; 280 | break; 281 | default: 282 | volumeInstrStr = "reserved"; 283 | break; 284 | } 285 | cout << "volumeInstr:" << volumeInstrStr << " cullingMode:" << cullingModeStr << " "; 286 | } else { 287 | string depthCompareStr; 288 | switch (depthCompare) { 289 | case(0): 290 | depthCompareStr = "never"; 291 | break; 292 | case(1): 293 | depthCompareStr = "less"; 294 | break; 295 | case(2): 296 | depthCompareStr = "equal"; 297 | break; 298 | case(3): 299 | depthCompareStr = "less_or_equal"; 300 | break; 301 | case(4): 302 | depthCompareStr = "greater"; 303 | break; 304 | case(5): 305 | depthCompareStr = "not_equal"; 306 | break; 307 | case(6): 308 | depthCompareStr = "greater_or_equal"; 309 | break; 310 | case(7): 311 | depthCompareStr = "always"; 312 | break; 313 | } 314 | cout << "depthCompareMode:" << depthCompareStr << " cullingMode:" << cullingModeStr << " zWriteDisable:" << zWriteDisable << " cacheBypass:" << cacheBypass << " dCalcCtrl:" << dCalcCtrl << " "; 315 | 316 | string pixelFormatStr; 317 | switch (pixelFormat) { 318 | case (0): 319 | pixelFormatStr = "1555"; 320 | break; 321 | case (1): 322 | pixelFormatStr = "565"; 323 | break; 324 | case (2): 325 | pixelFormatStr = "4444"; 326 | break; 327 | case (3): 328 | pixelFormatStr = "YUV422"; 329 | break; 330 | case (4): 331 | pixelFormatStr = "BumpMap"; 332 | break; 333 | case (5): 334 | pixelFormatStr = "4BPP_Palette"; 335 | break; 336 | case (6): 337 | pixelFormatStr = "8BPP_Palette"; 338 | break; 339 | case (7): 340 | pixelFormatStr = "Reserved"; 341 | break; 342 | } 343 | cout << "mipMapped:" << mipMapped << " vqCompressed:" << vqCompressed << " pixelFormat:" << pixelFormatStr << " "; 344 | if (pixelFormat == 5 || pixelFormat == 6) { 345 | cout << "paletteSelector:" << paletteSelector << " "; 346 | } else { 347 | cout << "scanOrder:" << (scanOrder == 0 ? "twiddled " : "non twiddled") << " strideSelect:" << strideSelect << " "; 348 | } 349 | } 350 | } 351 | cout << endl; 352 | } 353 | 354 | unsigned long taparser::bits(const unsigned long param, const unsigned long startbit, const unsigned long stopbit) { 355 | return (globalParam[param]>>startbit) & ((1 << (stopbit - startbit + 1))-1); 356 | } 357 | 358 | -------------------------------------------------------------------------------- /zconf.h: -------------------------------------------------------------------------------- 1 | /* zconf.h -- configuration of the zlib compression library 2 | * Copyright (C) 1995-2013 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #ifndef ZCONF_H 9 | #define ZCONF_H 10 | 11 | /* 12 | * If you *really* need a unique prefix for all types and library functions, 13 | * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. 14 | * Even better than compiling with -DZ_PREFIX would be to use configure to set 15 | * this permanently in zconf.h using "./configure --zprefix". 16 | */ 17 | #ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ 18 | # define Z_PREFIX_SET 19 | 20 | /* all linked symbols */ 21 | # define _dist_code z__dist_code 22 | # define _length_code z__length_code 23 | # define _tr_align z__tr_align 24 | # define _tr_flush_bits z__tr_flush_bits 25 | # define _tr_flush_block z__tr_flush_block 26 | # define _tr_init z__tr_init 27 | # define _tr_stored_block z__tr_stored_block 28 | # define _tr_tally z__tr_tally 29 | # define adler32 z_adler32 30 | # define adler32_combine z_adler32_combine 31 | # define adler32_combine64 z_adler32_combine64 32 | # ifndef Z_SOLO 33 | # define compress z_compress 34 | # define compress2 z_compress2 35 | # define compressBound z_compressBound 36 | # endif 37 | # define crc32 z_crc32 38 | # define crc32_combine z_crc32_combine 39 | # define crc32_combine64 z_crc32_combine64 40 | # define deflate z_deflate 41 | # define deflateBound z_deflateBound 42 | # define deflateCopy z_deflateCopy 43 | # define deflateEnd z_deflateEnd 44 | # define deflateInit2_ z_deflateInit2_ 45 | # define deflateInit_ z_deflateInit_ 46 | # define deflateParams z_deflateParams 47 | # define deflatePending z_deflatePending 48 | # define deflatePrime z_deflatePrime 49 | # define deflateReset z_deflateReset 50 | # define deflateResetKeep z_deflateResetKeep 51 | # define deflateSetDictionary z_deflateSetDictionary 52 | # define deflateSetHeader z_deflateSetHeader 53 | # define deflateTune z_deflateTune 54 | # define deflate_copyright z_deflate_copyright 55 | # define get_crc_table z_get_crc_table 56 | # ifndef Z_SOLO 57 | # define gz_error z_gz_error 58 | # define gz_intmax z_gz_intmax 59 | # define gz_strwinerror z_gz_strwinerror 60 | # define gzbuffer z_gzbuffer 61 | # define gzclearerr z_gzclearerr 62 | # define gzclose z_gzclose 63 | # define gzclose_r z_gzclose_r 64 | # define gzclose_w z_gzclose_w 65 | # define gzdirect z_gzdirect 66 | # define gzdopen z_gzdopen 67 | # define gzeof z_gzeof 68 | # define gzerror z_gzerror 69 | # define gzflush z_gzflush 70 | # define gzgetc z_gzgetc 71 | # define gzgetc_ z_gzgetc_ 72 | # define gzgets z_gzgets 73 | # define gzoffset z_gzoffset 74 | # define gzoffset64 z_gzoffset64 75 | # define gzopen z_gzopen 76 | # define gzopen64 z_gzopen64 77 | # ifdef _WIN32 78 | # define gzopen_w z_gzopen_w 79 | # endif 80 | # define gzprintf z_gzprintf 81 | # define gzvprintf z_gzvprintf 82 | # define gzputc z_gzputc 83 | # define gzputs z_gzputs 84 | # define gzread z_gzread 85 | # define gzrewind z_gzrewind 86 | # define gzseek z_gzseek 87 | # define gzseek64 z_gzseek64 88 | # define gzsetparams z_gzsetparams 89 | # define gztell z_gztell 90 | # define gztell64 z_gztell64 91 | # define gzungetc z_gzungetc 92 | # define gzwrite z_gzwrite 93 | # endif 94 | # define inflate z_inflate 95 | # define inflateBack z_inflateBack 96 | # define inflateBackEnd z_inflateBackEnd 97 | # define inflateBackInit_ z_inflateBackInit_ 98 | # define inflateCopy z_inflateCopy 99 | # define inflateEnd z_inflateEnd 100 | # define inflateGetHeader z_inflateGetHeader 101 | # define inflateInit2_ z_inflateInit2_ 102 | # define inflateInit_ z_inflateInit_ 103 | # define inflateMark z_inflateMark 104 | # define inflatePrime z_inflatePrime 105 | # define inflateReset z_inflateReset 106 | # define inflateReset2 z_inflateReset2 107 | # define inflateSetDictionary z_inflateSetDictionary 108 | # define inflateGetDictionary z_inflateGetDictionary 109 | # define inflateSync z_inflateSync 110 | # define inflateSyncPoint z_inflateSyncPoint 111 | # define inflateUndermine z_inflateUndermine 112 | # define inflateResetKeep z_inflateResetKeep 113 | # define inflate_copyright z_inflate_copyright 114 | # define inflate_fast z_inflate_fast 115 | # define inflate_table z_inflate_table 116 | # ifndef Z_SOLO 117 | # define uncompress z_uncompress 118 | # endif 119 | # define zError z_zError 120 | # ifndef Z_SOLO 121 | # define zcalloc z_zcalloc 122 | # define zcfree z_zcfree 123 | # endif 124 | # define zlibCompileFlags z_zlibCompileFlags 125 | # define zlibVersion z_zlibVersion 126 | 127 | /* all zlib typedefs in zlib.h and zconf.h */ 128 | # define Byte z_Byte 129 | # define Bytef z_Bytef 130 | # define alloc_func z_alloc_func 131 | # define charf z_charf 132 | # define free_func z_free_func 133 | # ifndef Z_SOLO 134 | # define gzFile z_gzFile 135 | # endif 136 | # define gz_header z_gz_header 137 | # define gz_headerp z_gz_headerp 138 | # define in_func z_in_func 139 | # define intf z_intf 140 | # define out_func z_out_func 141 | # define uInt z_uInt 142 | # define uIntf z_uIntf 143 | # define uLong z_uLong 144 | # define uLongf z_uLongf 145 | # define voidp z_voidp 146 | # define voidpc z_voidpc 147 | # define voidpf z_voidpf 148 | 149 | /* all zlib structs in zlib.h and zconf.h */ 150 | # define gz_header_s z_gz_header_s 151 | # define internal_state z_internal_state 152 | 153 | #endif 154 | 155 | #if defined(__MSDOS__) && !defined(MSDOS) 156 | # define MSDOS 157 | #endif 158 | #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) 159 | # define OS2 160 | #endif 161 | #if defined(_WINDOWS) && !defined(WINDOWS) 162 | # define WINDOWS 163 | #endif 164 | #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) 165 | # ifndef WIN32 166 | # define WIN32 167 | # endif 168 | #endif 169 | #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) 170 | # if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) 171 | # ifndef SYS16BIT 172 | # define SYS16BIT 173 | # endif 174 | # endif 175 | #endif 176 | 177 | /* 178 | * Compile with -DMAXSEG_64K if the alloc function cannot allocate more 179 | * than 64k bytes at a time (needed on systems with 16-bit int). 180 | */ 181 | #ifdef SYS16BIT 182 | # define MAXSEG_64K 183 | #endif 184 | #ifdef MSDOS 185 | # define UNALIGNED_OK 186 | #endif 187 | 188 | #ifdef __STDC_VERSION__ 189 | # ifndef STDC 190 | # define STDC 191 | # endif 192 | # if __STDC_VERSION__ >= 199901L 193 | # ifndef STDC99 194 | # define STDC99 195 | # endif 196 | # endif 197 | #endif 198 | #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) 199 | # define STDC 200 | #endif 201 | #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) 202 | # define STDC 203 | #endif 204 | #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) 205 | # define STDC 206 | #endif 207 | #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) 208 | # define STDC 209 | #endif 210 | 211 | #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ 212 | # define STDC 213 | #endif 214 | 215 | #ifndef STDC 216 | # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ 217 | # define const /* note: need a more gentle solution here */ 218 | # endif 219 | #endif 220 | 221 | #if defined(ZLIB_CONST) && !defined(z_const) 222 | # define z_const const 223 | #else 224 | # define z_const 225 | #endif 226 | 227 | /* Some Mac compilers merge all .h files incorrectly: */ 228 | #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) 229 | # define NO_DUMMY_DECL 230 | #endif 231 | 232 | /* Maximum value for memLevel in deflateInit2 */ 233 | #ifndef MAX_MEM_LEVEL 234 | # ifdef MAXSEG_64K 235 | # define MAX_MEM_LEVEL 8 236 | # else 237 | # define MAX_MEM_LEVEL 9 238 | # endif 239 | #endif 240 | 241 | /* Maximum value for windowBits in deflateInit2 and inflateInit2. 242 | * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files 243 | * created by gzip. (Files created by minigzip can still be extracted by 244 | * gzip.) 245 | */ 246 | #ifndef MAX_WBITS 247 | # define MAX_WBITS 15 /* 32K LZ77 window */ 248 | #endif 249 | 250 | /* The memory requirements for deflate are (in bytes): 251 | (1 << (windowBits+2)) + (1 << (memLevel+9)) 252 | that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) 253 | plus a few kilobytes for small objects. For example, if you want to reduce 254 | the default memory requirements from 256K to 128K, compile with 255 | make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" 256 | Of course this will generally degrade compression (there's no free lunch). 257 | 258 | The memory requirements for inflate are (in bytes) 1 << windowBits 259 | that is, 32K for windowBits=15 (default value) plus a few kilobytes 260 | for small objects. 261 | */ 262 | 263 | /* Type declarations */ 264 | 265 | #ifndef OF /* function prototypes */ 266 | # ifdef STDC 267 | # define OF(args) args 268 | # else 269 | # define OF(args) () 270 | # endif 271 | #endif 272 | 273 | #ifndef Z_ARG /* function prototypes for stdarg */ 274 | # if defined(STDC) || defined(Z_HAVE_STDARG_H) 275 | # define Z_ARG(args) args 276 | # else 277 | # define Z_ARG(args) () 278 | # endif 279 | #endif 280 | 281 | /* The following definitions for FAR are needed only for MSDOS mixed 282 | * model programming (small or medium model with some far allocations). 283 | * This was tested only with MSC; for other MSDOS compilers you may have 284 | * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, 285 | * just define FAR to be empty. 286 | */ 287 | #ifdef SYS16BIT 288 | # if defined(M_I86SM) || defined(M_I86MM) 289 | /* MSC small or medium model */ 290 | # define SMALL_MEDIUM 291 | # ifdef _MSC_VER 292 | # define FAR _far 293 | # else 294 | # define FAR far 295 | # endif 296 | # endif 297 | # if (defined(__SMALL__) || defined(__MEDIUM__)) 298 | /* Turbo C small or medium model */ 299 | # define SMALL_MEDIUM 300 | # ifdef __BORLANDC__ 301 | # define FAR _far 302 | # else 303 | # define FAR far 304 | # endif 305 | # endif 306 | #endif 307 | 308 | #if defined(WINDOWS) || defined(WIN32) 309 | /* If building or using zlib as a DLL, define ZLIB_DLL. 310 | * This is not mandatory, but it offers a little performance increase. 311 | */ 312 | # ifdef ZLIB_DLL 313 | # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) 314 | # ifdef ZLIB_INTERNAL 315 | # define ZEXTERN extern __declspec(dllexport) 316 | # else 317 | # define ZEXTERN extern __declspec(dllimport) 318 | # endif 319 | # endif 320 | # endif /* ZLIB_DLL */ 321 | /* If building or using zlib with the WINAPI/WINAPIV calling convention, 322 | * define ZLIB_WINAPI. 323 | * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. 324 | */ 325 | # ifdef ZLIB_WINAPI 326 | # ifdef FAR 327 | # undef FAR 328 | # endif 329 | # include 330 | /* No need for _export, use ZLIB.DEF instead. */ 331 | /* For complete Windows compatibility, use WINAPI, not __stdcall. */ 332 | # define ZEXPORT WINAPI 333 | # ifdef WIN32 334 | # define ZEXPORTVA WINAPIV 335 | # else 336 | # define ZEXPORTVA FAR CDECL 337 | # endif 338 | # endif 339 | #endif 340 | 341 | #if defined (__BEOS__) 342 | # ifdef ZLIB_DLL 343 | # ifdef ZLIB_INTERNAL 344 | # define ZEXPORT __declspec(dllexport) 345 | # define ZEXPORTVA __declspec(dllexport) 346 | # else 347 | # define ZEXPORT __declspec(dllimport) 348 | # define ZEXPORTVA __declspec(dllimport) 349 | # endif 350 | # endif 351 | #endif 352 | 353 | #ifndef ZEXTERN 354 | # define ZEXTERN extern 355 | #endif 356 | #ifndef ZEXPORT 357 | # define ZEXPORT 358 | #endif 359 | #ifndef ZEXPORTVA 360 | # define ZEXPORTVA 361 | #endif 362 | 363 | #ifndef FAR 364 | # define FAR 365 | #endif 366 | 367 | #if !defined(__MACTYPES__) 368 | typedef unsigned char Byte; /* 8 bits */ 369 | #endif 370 | typedef unsigned int uInt; /* 16 bits or more */ 371 | typedef unsigned long uLong; /* 32 bits or more */ 372 | 373 | #ifdef SMALL_MEDIUM 374 | /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ 375 | # define Bytef Byte FAR 376 | #else 377 | typedef Byte FAR Bytef; 378 | #endif 379 | typedef char FAR charf; 380 | typedef int FAR intf; 381 | typedef uInt FAR uIntf; 382 | typedef uLong FAR uLongf; 383 | 384 | #ifdef STDC 385 | typedef void const *voidpc; 386 | typedef void FAR *voidpf; 387 | typedef void *voidp; 388 | #else 389 | typedef Byte const *voidpc; 390 | typedef Byte FAR *voidpf; 391 | typedef Byte *voidp; 392 | #endif 393 | 394 | #if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC) 395 | # include 396 | # if (UINT_MAX == 0xffffffffUL) 397 | # define Z_U4 unsigned 398 | # elif (ULONG_MAX == 0xffffffffUL) 399 | # define Z_U4 unsigned long 400 | # elif (USHRT_MAX == 0xffffffffUL) 401 | # define Z_U4 unsigned short 402 | # endif 403 | #endif 404 | 405 | #ifdef Z_U4 406 | typedef Z_U4 z_crc_t; 407 | #else 408 | typedef unsigned long z_crc_t; 409 | #endif 410 | 411 | #ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ 412 | # define Z_HAVE_UNISTD_H 413 | #endif 414 | 415 | #ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */ 416 | # define Z_HAVE_STDARG_H 417 | #endif 418 | 419 | #ifdef STDC 420 | # ifndef Z_SOLO 421 | # include /* for off_t */ 422 | # endif 423 | #endif 424 | 425 | #if defined(STDC) || defined(Z_HAVE_STDARG_H) 426 | # ifndef Z_SOLO 427 | # include /* for va_list */ 428 | # endif 429 | #endif 430 | 431 | #ifdef _WIN32 432 | # ifndef Z_SOLO 433 | # include /* for wchar_t */ 434 | # endif 435 | #endif 436 | 437 | /* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and 438 | * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even 439 | * though the former does not conform to the LFS document), but considering 440 | * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as 441 | * equivalently requesting no 64-bit operations 442 | */ 443 | #if defined(_LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1 444 | # undef _LARGEFILE64_SOURCE 445 | #endif 446 | 447 | #if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H) 448 | # define Z_HAVE_UNISTD_H 449 | #endif 450 | #ifndef Z_SOLO 451 | # if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE) 452 | # include /* for SEEK_*, off_t, and _LFS64_LARGEFILE */ 453 | # ifdef VMS 454 | # include /* for off_t */ 455 | # endif 456 | # ifndef z_off_t 457 | # define z_off_t off_t 458 | # endif 459 | # endif 460 | #endif 461 | 462 | #if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0 463 | # define Z_LFS64 464 | #endif 465 | 466 | #if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64) 467 | # define Z_LARGE64 468 | #endif 469 | 470 | #if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64) 471 | # define Z_WANT64 472 | #endif 473 | 474 | #if !defined(SEEK_SET) && !defined(Z_SOLO) 475 | # define SEEK_SET 0 /* Seek from beginning of file. */ 476 | # define SEEK_CUR 1 /* Seek from current position. */ 477 | # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ 478 | #endif 479 | 480 | #ifndef z_off_t 481 | # define z_off_t long 482 | #endif 483 | 484 | #if !defined(_WIN32) && defined(Z_LARGE64) 485 | # define z_off64_t off64_t 486 | #else 487 | # if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO) 488 | # define z_off64_t __int64 489 | # else 490 | # define z_off64_t z_off_t 491 | # endif 492 | #endif 493 | 494 | /* MVS linker does not support external names larger than 8 bytes */ 495 | #if defined(__MVS__) 496 | #pragma map(deflateInit_,"DEIN") 497 | #pragma map(deflateInit2_,"DEIN2") 498 | #pragma map(deflateEnd,"DEEND") 499 | #pragma map(deflateBound,"DEBND") 500 | #pragma map(inflateInit_,"ININ") 501 | #pragma map(inflateInit2_,"ININ2") 502 | #pragma map(inflateEnd,"INEND") 503 | #pragma map(inflateSync,"INSY") 504 | #pragma map(inflateSetDictionary,"INSEDI") 505 | #pragma map(compressBound,"CMBND") 506 | #pragma map(inflate_table,"INTABL") 507 | #pragma map(inflate_fast,"INFA") 508 | #pragma map(inflate_copyright,"INCOPY") 509 | #endif 510 | 511 | #endif /* ZCONF_H */ 512 | -------------------------------------------------------------------------------- /pngconf.h: -------------------------------------------------------------------------------- 1 | 2 | /* pngconf.h - machine configurable file for libpng 3 | * 4 | * libpng version 1.6.14 - October 23, 2014 5 | * 6 | * Copyright (c) 1998-2014 Glenn Randers-Pehrson 7 | * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) 8 | * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) 9 | * 10 | * This code is released under the libpng license. 11 | * For conditions of distribution and use, see the disclaimer 12 | * and license in png.h 13 | * 14 | */ 15 | 16 | /* Any machine specific code is near the front of this file, so if you 17 | * are configuring libpng for a machine, you may want to read the section 18 | * starting here down to where it starts to typedef png_color, png_text, 19 | * and png_info. 20 | */ 21 | 22 | #ifndef PNGCONF_H 23 | #define PNGCONF_H 24 | 25 | /* To do: Do all of this in scripts/pnglibconf.dfa */ 26 | #ifdef PNG_SAFE_LIMITS_SUPPORTED 27 | # ifdef PNG_USER_WIDTH_MAX 28 | # undef PNG_USER_WIDTH_MAX 29 | # define PNG_USER_WIDTH_MAX 1000000L 30 | # endif 31 | # ifdef PNG_USER_HEIGHT_MAX 32 | # undef PNG_USER_HEIGHT_MAX 33 | # define PNG_USER_HEIGHT_MAX 1000000L 34 | # endif 35 | # ifdef PNG_USER_CHUNK_MALLOC_MAX 36 | # undef PNG_USER_CHUNK_MALLOC_MAX 37 | # define PNG_USER_CHUNK_MALLOC_MAX 4000000L 38 | # endif 39 | # ifdef PNG_USER_CHUNK_CACHE_MAX 40 | # undef PNG_USER_CHUNK_CACHE_MAX 41 | # define PNG_USER_CHUNK_CACHE_MAX 128 42 | # endif 43 | #endif 44 | 45 | #ifndef PNG_BUILDING_SYMBOL_TABLE /* else includes may cause problems */ 46 | 47 | /* From libpng 1.6.0 libpng requires an ANSI X3.159-1989 ("ISOC90") compliant C 48 | * compiler for correct compilation. The following header files are required by 49 | * the standard. If your compiler doesn't provide these header files, or they 50 | * do not match the standard, you will need to provide/improve them. 51 | */ 52 | #include 53 | #include 54 | 55 | /* Library header files. These header files are all defined by ISOC90; libpng 56 | * expects conformant implementations, however, an ISOC90 conformant system need 57 | * not provide these header files if the functionality cannot be implemented. 58 | * In this case it will be necessary to disable the relevant parts of libpng in 59 | * the build of pnglibconf.h. 60 | * 61 | * Prior to 1.6.0 string.h was included here; the API changes in 1.6.0 to not 62 | * include this unnecessary header file. 63 | */ 64 | 65 | #ifdef PNG_STDIO_SUPPORTED 66 | /* Required for the definition of FILE: */ 67 | # include 68 | #endif 69 | 70 | #ifdef PNG_SETJMP_SUPPORTED 71 | /* Required for the definition of jmp_buf and the declaration of longjmp: */ 72 | # include 73 | #endif 74 | 75 | #ifdef PNG_CONVERT_tIME_SUPPORTED 76 | /* Required for struct tm: */ 77 | # include 78 | #endif 79 | 80 | #endif /* PNG_BUILDING_SYMBOL_TABLE */ 81 | 82 | /* Prior to 1.6.0 it was possible to turn off 'const' in declarations using 83 | * PNG_NO_CONST; this is no longer supported except for data declarations which 84 | * apparently still cause problems in 2011 on some compilers. 85 | */ 86 | #define PNG_CONST const /* backward compatibility only */ 87 | 88 | /* This controls optimization of the reading of 16 and 32 bit values 89 | * from PNG files. It can be set on a per-app-file basis - it 90 | * just changes whether a macro is used when the function is called. 91 | * The library builder sets the default; if read functions are not 92 | * built into the library the macro implementation is forced on. 93 | */ 94 | #ifndef PNG_READ_INT_FUNCTIONS_SUPPORTED 95 | # define PNG_USE_READ_MACROS 96 | #endif 97 | #if !defined(PNG_NO_USE_READ_MACROS) && !defined(PNG_USE_READ_MACROS) 98 | # if PNG_DEFAULT_READ_MACROS 99 | # define PNG_USE_READ_MACROS 100 | # endif 101 | #endif 102 | 103 | /* COMPILER SPECIFIC OPTIONS. 104 | * 105 | * These options are provided so that a variety of difficult compilers 106 | * can be used. Some are fixed at build time (e.g. PNG_API_RULE 107 | * below) but still have compiler specific implementations, others 108 | * may be changed on a per-file basis when compiling against libpng. 109 | */ 110 | 111 | /* The PNGARG macro was used in versions of libpng prior to 1.6.0 to protect 112 | * against legacy (pre ISOC90) compilers that did not understand function 113 | * prototypes. It is not required for modern C compilers. 114 | */ 115 | #ifndef PNGARG 116 | # define PNGARG(arglist) arglist 117 | #endif 118 | 119 | /* Function calling conventions. 120 | * ============================= 121 | * Normally it is not necessary to specify to the compiler how to call 122 | * a function - it just does it - however on x86 systems derived from 123 | * Microsoft and Borland C compilers ('IBM PC', 'DOS', 'Windows' systems 124 | * and some others) there are multiple ways to call a function and the 125 | * default can be changed on the compiler command line. For this reason 126 | * libpng specifies the calling convention of every exported function and 127 | * every function called via a user supplied function pointer. This is 128 | * done in this file by defining the following macros: 129 | * 130 | * PNGAPI Calling convention for exported functions. 131 | * PNGCBAPI Calling convention for user provided (callback) functions. 132 | * PNGCAPI Calling convention used by the ANSI-C library (required 133 | * for longjmp callbacks and sometimes used internally to 134 | * specify the calling convention for zlib). 135 | * 136 | * These macros should never be overridden. If it is necessary to 137 | * change calling convention in a private build this can be done 138 | * by setting PNG_API_RULE (which defaults to 0) to one of the values 139 | * below to select the correct 'API' variants. 140 | * 141 | * PNG_API_RULE=0 Use PNGCAPI - the 'C' calling convention - throughout. 142 | * This is correct in every known environment. 143 | * PNG_API_RULE=1 Use the operating system convention for PNGAPI and 144 | * the 'C' calling convention (from PNGCAPI) for 145 | * callbacks (PNGCBAPI). This is no longer required 146 | * in any known environment - if it has to be used 147 | * please post an explanation of the problem to the 148 | * libpng mailing list. 149 | * 150 | * These cases only differ if the operating system does not use the C 151 | * calling convention, at present this just means the above cases 152 | * (x86 DOS/Windows sytems) and, even then, this does not apply to 153 | * Cygwin running on those systems. 154 | * 155 | * Note that the value must be defined in pnglibconf.h so that what 156 | * the application uses to call the library matches the conventions 157 | * set when building the library. 158 | */ 159 | 160 | /* Symbol export 161 | * ============= 162 | * When building a shared library it is almost always necessary to tell 163 | * the compiler which symbols to export. The png.h macro 'PNG_EXPORT' 164 | * is used to mark the symbols. On some systems these symbols can be 165 | * extracted at link time and need no special processing by the compiler, 166 | * on other systems the symbols are flagged by the compiler and just 167 | * the declaration requires a special tag applied (unfortunately) in a 168 | * compiler dependent way. Some systems can do either. 169 | * 170 | * A small number of older systems also require a symbol from a DLL to 171 | * be flagged to the program that calls it. This is a problem because 172 | * we do not know in the header file included by application code that 173 | * the symbol will come from a shared library, as opposed to a statically 174 | * linked one. For this reason the application must tell us by setting 175 | * the magic flag PNG_USE_DLL to turn on the special processing before 176 | * it includes png.h. 177 | * 178 | * Four additional macros are used to make this happen: 179 | * 180 | * PNG_IMPEXP The magic (if any) to cause a symbol to be exported from 181 | * the build or imported if PNG_USE_DLL is set - compiler 182 | * and system specific. 183 | * 184 | * PNG_EXPORT_TYPE(type) A macro that pre or appends PNG_IMPEXP to 185 | * 'type', compiler specific. 186 | * 187 | * PNG_DLL_EXPORT Set to the magic to use during a libpng build to 188 | * make a symbol exported from the DLL. Not used in the 189 | * public header files; see pngpriv.h for how it is used 190 | * in the libpng build. 191 | * 192 | * PNG_DLL_IMPORT Set to the magic to force the libpng symbols to come 193 | * from a DLL - used to define PNG_IMPEXP when 194 | * PNG_USE_DLL is set. 195 | */ 196 | 197 | /* System specific discovery. 198 | * ========================== 199 | * This code is used at build time to find PNG_IMPEXP, the API settings 200 | * and PNG_EXPORT_TYPE(), it may also set a macro to indicate the DLL 201 | * import processing is possible. On Windows systems it also sets 202 | * compiler-specific macros to the values required to change the calling 203 | * conventions of the various functions. 204 | */ 205 | #if defined(_Windows) || defined(_WINDOWS) || defined(WIN32) ||\ 206 | defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) 207 | /* Windows system (DOS doesn't support DLLs). Includes builds under Cygwin or 208 | * MinGW on any architecture currently supported by Windows. Also includes 209 | * Watcom builds but these need special treatment because they are not 210 | * compatible with GCC or Visual C because of different calling conventions. 211 | */ 212 | # if PNG_API_RULE == 2 213 | /* If this line results in an error, either because __watcall is not 214 | * understood or because of a redefine just below you cannot use *this* 215 | * build of the library with the compiler you are using. *This* build was 216 | * build using Watcom and applications must also be built using Watcom! 217 | */ 218 | # define PNGCAPI __watcall 219 | # endif 220 | 221 | # if defined(__GNUC__) || (defined(_MSC_VER) && (_MSC_VER >= 800)) 222 | # define PNGCAPI __cdecl 223 | # if PNG_API_RULE == 1 224 | /* If this line results in an error __stdcall is not understood and 225 | * PNG_API_RULE should not have been set to '1'. 226 | */ 227 | # define PNGAPI __stdcall 228 | # endif 229 | # else 230 | /* An older compiler, or one not detected (erroneously) above, 231 | * if necessary override on the command line to get the correct 232 | * variants for the compiler. 233 | */ 234 | # ifndef PNGCAPI 235 | # define PNGCAPI _cdecl 236 | # endif 237 | # if PNG_API_RULE == 1 && !defined(PNGAPI) 238 | # define PNGAPI _stdcall 239 | # endif 240 | # endif /* compiler/api */ 241 | 242 | /* NOTE: PNGCBAPI always defaults to PNGCAPI. */ 243 | 244 | # if defined(PNGAPI) && !defined(PNG_USER_PRIVATEBUILD) 245 | # error "PNG_USER_PRIVATEBUILD must be defined if PNGAPI is changed" 246 | # endif 247 | 248 | # if (defined(_MSC_VER) && _MSC_VER < 800) ||\ 249 | (defined(__BORLANDC__) && __BORLANDC__ < 0x500) 250 | /* older Borland and MSC 251 | * compilers used '__export' and required this to be after 252 | * the type. 253 | */ 254 | # ifndef PNG_EXPORT_TYPE 255 | # define PNG_EXPORT_TYPE(type) type PNG_IMPEXP 256 | # endif 257 | # define PNG_DLL_EXPORT __export 258 | # else /* newer compiler */ 259 | # define PNG_DLL_EXPORT __declspec(dllexport) 260 | # ifndef PNG_DLL_IMPORT 261 | # define PNG_DLL_IMPORT __declspec(dllimport) 262 | # endif 263 | # endif /* compiler */ 264 | 265 | #else /* !Windows */ 266 | # if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__) 267 | # define PNGAPI _System 268 | # else /* !Windows/x86 && !OS/2 */ 269 | /* Use the defaults, or define PNG*API on the command line (but 270 | * this will have to be done for every compile!) 271 | */ 272 | # endif /* other system, !OS/2 */ 273 | #endif /* !Windows/x86 */ 274 | 275 | /* Now do all the defaulting . */ 276 | #ifndef PNGCAPI 277 | # define PNGCAPI 278 | #endif 279 | #ifndef PNGCBAPI 280 | # define PNGCBAPI PNGCAPI 281 | #endif 282 | #ifndef PNGAPI 283 | # define PNGAPI PNGCAPI 284 | #endif 285 | 286 | /* PNG_IMPEXP may be set on the compilation system command line or (if not set) 287 | * then in an internal header file when building the library, otherwise (when 288 | * using the library) it is set here. 289 | */ 290 | #ifndef PNG_IMPEXP 291 | # if defined(PNG_USE_DLL) && defined(PNG_DLL_IMPORT) 292 | /* This forces use of a DLL, disallowing static linking */ 293 | # define PNG_IMPEXP PNG_DLL_IMPORT 294 | # endif 295 | 296 | # ifndef PNG_IMPEXP 297 | # define PNG_IMPEXP 298 | # endif 299 | #endif 300 | 301 | /* In 1.5.2 the definition of PNG_FUNCTION has been changed to always treat 302 | * 'attributes' as a storage class - the attributes go at the start of the 303 | * function definition, and attributes are always appended regardless of the 304 | * compiler. This considerably simplifies these macros but may cause problems 305 | * if any compilers both need function attributes and fail to handle them as 306 | * a storage class (this is unlikely.) 307 | */ 308 | #ifndef PNG_FUNCTION 309 | # define PNG_FUNCTION(type, name, args, attributes) attributes type name args 310 | #endif 311 | 312 | #ifndef PNG_EXPORT_TYPE 313 | # define PNG_EXPORT_TYPE(type) PNG_IMPEXP type 314 | #endif 315 | 316 | /* The ordinal value is only relevant when preprocessing png.h for symbol 317 | * table entries, so we discard it here. See the .dfn files in the 318 | * scripts directory. 319 | */ 320 | #ifndef PNG_EXPORTA 321 | 322 | # define PNG_EXPORTA(ordinal, type, name, args, attributes)\ 323 | PNG_FUNCTION(PNG_EXPORT_TYPE(type),(PNGAPI name),PNGARG(args), \ 324 | extern attributes) 325 | #endif 326 | 327 | /* ANSI-C (C90) does not permit a macro to be invoked with an empty argument, 328 | * so make something non-empty to satisfy the requirement: 329 | */ 330 | #define PNG_EMPTY /*empty list*/ 331 | 332 | #define PNG_EXPORT(ordinal, type, name, args)\ 333 | PNG_EXPORTA(ordinal, type, name, args, PNG_EMPTY) 334 | 335 | /* Use PNG_REMOVED to comment out a removed interface. */ 336 | #ifndef PNG_REMOVED 337 | # define PNG_REMOVED(ordinal, type, name, args, attributes) 338 | #endif 339 | 340 | #ifndef PNG_CALLBACK 341 | # define PNG_CALLBACK(type, name, args) type (PNGCBAPI name) PNGARG(args) 342 | #endif 343 | 344 | /* Support for compiler specific function attributes. These are used 345 | * so that where compiler support is available incorrect use of API 346 | * functions in png.h will generate compiler warnings. 347 | * 348 | * Added at libpng-1.2.41. 349 | */ 350 | 351 | #ifndef PNG_NO_PEDANTIC_WARNINGS 352 | # ifndef PNG_PEDANTIC_WARNINGS_SUPPORTED 353 | # define PNG_PEDANTIC_WARNINGS_SUPPORTED 354 | # endif 355 | #endif 356 | 357 | #ifdef PNG_PEDANTIC_WARNINGS_SUPPORTED 358 | /* Support for compiler specific function attributes. These are used 359 | * so that where compiler support is available, incorrect use of API 360 | * functions in png.h will generate compiler warnings. Added at libpng 361 | * version 1.2.41. Disabling these removes the warnings but may also produce 362 | * less efficient code. 363 | */ 364 | # if defined(__clang__) && defined(__has_attribute) 365 | /* Clang defines both __clang__ and __GNUC__. Check __clang__ first. */ 366 | # if !defined(PNG_USE_RESULT) && __has_attribute(__warn_unused_result__) 367 | # define PNG_USE_RESULT __attribute__((__warn_unused_result__)) 368 | # endif 369 | # if !defined(PNG_NORETURN) && __has_attribute(__noreturn__) 370 | # define PNG_NORETURN __attribute__((__noreturn__)) 371 | # endif 372 | # if !defined(PNG_ALLOCATED) && __has_attribute(__malloc__) 373 | # define PNG_ALLOCATED __attribute__((__malloc__)) 374 | # endif 375 | # if !defined(PNG_DEPRECATED) && __has_attribute(__deprecated__) 376 | # define PNG_DEPRECATED __attribute__((__deprecated__)) 377 | # endif 378 | # if !defined(PNG_PRIVATE) 379 | # ifdef __has_extension 380 | # if __has_extension(attribute_unavailable_with_message) 381 | # define PNG_PRIVATE __attribute__((__unavailable__(\ 382 | "This function is not exported by libpng."))) 383 | # endif 384 | # endif 385 | # endif 386 | # ifndef PNG_RESTRICT 387 | # define PNG_RESTRICT __restrict 388 | # endif 389 | 390 | # elif defined(__GNUC__) 391 | # ifndef PNG_USE_RESULT 392 | # define PNG_USE_RESULT __attribute__((__warn_unused_result__)) 393 | # endif 394 | # ifndef PNG_NORETURN 395 | # define PNG_NORETURN __attribute__((__noreturn__)) 396 | # endif 397 | # if __GNUC__ >= 3 398 | # ifndef PNG_ALLOCATED 399 | # define PNG_ALLOCATED __attribute__((__malloc__)) 400 | # endif 401 | # ifndef PNG_DEPRECATED 402 | # define PNG_DEPRECATED __attribute__((__deprecated__)) 403 | # endif 404 | # ifndef PNG_PRIVATE 405 | # if 0 /* Doesn't work so we use deprecated instead*/ 406 | # define PNG_PRIVATE \ 407 | __attribute__((warning("This function is not exported by libpng."))) 408 | # else 409 | # define PNG_PRIVATE \ 410 | __attribute__((__deprecated__)) 411 | # endif 412 | # endif 413 | # if ((__GNUC__ > 3) || !defined(__GNUC_MINOR__) || (__GNUC_MINOR__ >= 1)) 414 | # ifndef PNG_RESTRICT 415 | # define PNG_RESTRICT __restrict 416 | # endif 417 | # endif /* __GNUC__.__GNUC_MINOR__ > 3.0 */ 418 | # endif /* __GNUC__ >= 3 */ 419 | 420 | # elif defined(_MSC_VER) && (_MSC_VER >= 1300) 421 | # ifndef PNG_USE_RESULT 422 | # define PNG_USE_RESULT /* not supported */ 423 | # endif 424 | # ifndef PNG_NORETURN 425 | # define PNG_NORETURN __declspec(noreturn) 426 | # endif 427 | # ifndef PNG_ALLOCATED 428 | # if (_MSC_VER >= 1400) 429 | # define PNG_ALLOCATED __declspec(restrict) 430 | # endif 431 | # endif 432 | # ifndef PNG_DEPRECATED 433 | # define PNG_DEPRECATED __declspec(deprecated) 434 | # endif 435 | # ifndef PNG_PRIVATE 436 | # define PNG_PRIVATE __declspec(deprecated) 437 | # endif 438 | # ifndef PNG_RESTRICT 439 | # if (_MSC_VER >= 1400) 440 | # define PNG_RESTRICT __restrict 441 | # endif 442 | # endif 443 | 444 | # elif defined(__WATCOMC__) 445 | # ifndef PNG_RESTRICT 446 | # define PNG_RESTRICT __restrict 447 | # endif 448 | # endif 449 | #endif /* PNG_PEDANTIC_WARNINGS */ 450 | 451 | #ifndef PNG_DEPRECATED 452 | # define PNG_DEPRECATED /* Use of this function is deprecated */ 453 | #endif 454 | #ifndef PNG_USE_RESULT 455 | # define PNG_USE_RESULT /* The result of this function must be checked */ 456 | #endif 457 | #ifndef PNG_NORETURN 458 | # define PNG_NORETURN /* This function does not return */ 459 | #endif 460 | #ifndef PNG_ALLOCATED 461 | # define PNG_ALLOCATED /* The result of the function is new memory */ 462 | #endif 463 | #ifndef PNG_PRIVATE 464 | # define PNG_PRIVATE /* This is a private libpng function */ 465 | #endif 466 | #ifndef PNG_RESTRICT 467 | # define PNG_RESTRICT /* The C99 "restrict" feature */ 468 | #endif 469 | 470 | #ifndef PNG_FP_EXPORT /* A floating point API. */ 471 | # ifdef PNG_FLOATING_POINT_SUPPORTED 472 | # define PNG_FP_EXPORT(ordinal, type, name, args)\ 473 | PNG_EXPORT(ordinal, type, name, args); 474 | # else /* No floating point APIs */ 475 | # define PNG_FP_EXPORT(ordinal, type, name, args) 476 | # endif 477 | #endif 478 | #ifndef PNG_FIXED_EXPORT /* A fixed point API. */ 479 | # ifdef PNG_FIXED_POINT_SUPPORTED 480 | # define PNG_FIXED_EXPORT(ordinal, type, name, args)\ 481 | PNG_EXPORT(ordinal, type, name, args); 482 | # else /* No fixed point APIs */ 483 | # define PNG_FIXED_EXPORT(ordinal, type, name, args) 484 | # endif 485 | #endif 486 | 487 | #ifndef PNG_BUILDING_SYMBOL_TABLE 488 | /* Some typedefs to get us started. These should be safe on most of the common 489 | * platforms. 490 | * 491 | * png_uint_32 and png_int_32 may, currently, be larger than required to hold a 492 | * 32-bit value however this is not normally advisable. 493 | * 494 | * png_uint_16 and png_int_16 should always be two bytes in size - this is 495 | * verified at library build time. 496 | * 497 | * png_byte must always be one byte in size. 498 | * 499 | * The checks below use constants from limits.h, as defined by the ISOC90 500 | * standard. 501 | */ 502 | #if CHAR_BIT == 8 && UCHAR_MAX == 255 503 | typedef unsigned char png_byte; 504 | #else 505 | # error "libpng requires 8 bit bytes" 506 | #endif 507 | 508 | #if INT_MIN == -32768 && INT_MAX == 32767 509 | typedef int png_int_16; 510 | #elif SHRT_MIN == -32768 && SHRT_MAX == 32767 511 | typedef short png_int_16; 512 | #else 513 | # error "libpng requires a signed 16 bit type" 514 | #endif 515 | 516 | #if UINT_MAX == 65535 517 | typedef unsigned int png_uint_16; 518 | #elif USHRT_MAX == 65535 519 | typedef unsigned short png_uint_16; 520 | #else 521 | # error "libpng requires an unsigned 16 bit type" 522 | #endif 523 | 524 | #if INT_MIN < -2147483646 && INT_MAX > 2147483646 525 | typedef int png_int_32; 526 | #elif LONG_MIN < -2147483646 && LONG_MAX > 2147483646 527 | typedef long int png_int_32; 528 | #else 529 | # error "libpng requires a signed 32 bit (or more) type" 530 | #endif 531 | 532 | #if UINT_MAX > 4294967294 533 | typedef unsigned int png_uint_32; 534 | #elif ULONG_MAX > 4294967294 535 | typedef unsigned long int png_uint_32; 536 | #else 537 | # error "libpng requires an unsigned 32 bit (or more) type" 538 | #endif 539 | 540 | /* Prior to 1.6.0 it was possible to disable the use of size_t, 1.6.0, however, 541 | * requires an ISOC90 compiler and relies on consistent behavior of sizeof. 542 | */ 543 | typedef size_t png_size_t; 544 | typedef ptrdiff_t png_ptrdiff_t; 545 | 546 | /* libpng needs to know the maximum value of 'size_t' and this controls the 547 | * definition of png_alloc_size_t, below. This maximum value of size_t limits 548 | * but does not control the maximum allocations the library makes - there is 549 | * direct application control of this through png_set_user_limits(). 550 | */ 551 | #ifndef PNG_SMALL_SIZE_T 552 | /* Compiler specific tests for systems where size_t is known to be less than 553 | * 32 bits (some of these systems may no longer work because of the lack of 554 | * 'far' support; see above.) 555 | */ 556 | # if (defined(__TURBOC__) && !defined(__FLAT__)) ||\ 557 | (defined(_MSC_VER) && defined(MAXSEG_64K)) 558 | # define PNG_SMALL_SIZE_T 559 | # endif 560 | #endif 561 | 562 | /* png_alloc_size_t is guaranteed to be no smaller than png_size_t, and no 563 | * smaller than png_uint_32. Casts from png_size_t or png_uint_32 to 564 | * png_alloc_size_t are not necessary; in fact, it is recommended not to use 565 | * them at all so that the compiler can complain when something turns out to be 566 | * problematic. 567 | * 568 | * Casts in the other direction (from png_alloc_size_t to png_size_t or 569 | * png_uint_32) should be explicitly applied; however, we do not expect to 570 | * encounter practical situations that require such conversions. 571 | * 572 | * PNG_SMALL_SIZE_T must be defined if the maximum value of size_t is less than 573 | * 4294967295 - i.e. less than the maximum value of png_uint_32. 574 | */ 575 | #ifdef PNG_SMALL_SIZE_T 576 | typedef png_uint_32 png_alloc_size_t; 577 | #else 578 | typedef png_size_t png_alloc_size_t; 579 | #endif 580 | 581 | /* Prior to 1.6.0 libpng offered limited support for Microsoft C compiler 582 | * implementations of Intel CPU specific support of user-mode segmented address 583 | * spaces, where 16-bit pointers address more than 65536 bytes of memory using 584 | * separate 'segment' registers. The implementation requires two different 585 | * types of pointer (only one of which includes the segment value.) 586 | * 587 | * If required this support is available in version 1.2 of libpng and may be 588 | * available in versions through 1.5, although the correctness of the code has 589 | * not been verified recently. 590 | */ 591 | 592 | /* Typedef for floating-point numbers that are converted to fixed-point with a 593 | * multiple of 100,000, e.g., gamma 594 | */ 595 | typedef png_int_32 png_fixed_point; 596 | 597 | /* Add typedefs for pointers */ 598 | typedef void * png_voidp; 599 | typedef const void * png_const_voidp; 600 | typedef png_byte * png_bytep; 601 | typedef const png_byte * png_const_bytep; 602 | typedef png_uint_32 * png_uint_32p; 603 | typedef const png_uint_32 * png_const_uint_32p; 604 | typedef png_int_32 * png_int_32p; 605 | typedef const png_int_32 * png_const_int_32p; 606 | typedef png_uint_16 * png_uint_16p; 607 | typedef const png_uint_16 * png_const_uint_16p; 608 | typedef png_int_16 * png_int_16p; 609 | typedef const png_int_16 * png_const_int_16p; 610 | typedef char * png_charp; 611 | typedef const char * png_const_charp; 612 | typedef png_fixed_point * png_fixed_point_p; 613 | typedef const png_fixed_point * png_const_fixed_point_p; 614 | typedef png_size_t * png_size_tp; 615 | typedef const png_size_t * png_const_size_tp; 616 | 617 | #ifdef PNG_STDIO_SUPPORTED 618 | typedef FILE * png_FILE_p; 619 | #endif 620 | 621 | #ifdef PNG_FLOATING_POINT_SUPPORTED 622 | typedef double * png_doublep; 623 | typedef const double * png_const_doublep; 624 | #endif 625 | 626 | /* Pointers to pointers; i.e. arrays */ 627 | typedef png_byte * * png_bytepp; 628 | typedef png_uint_32 * * png_uint_32pp; 629 | typedef png_int_32 * * png_int_32pp; 630 | typedef png_uint_16 * * png_uint_16pp; 631 | typedef png_int_16 * * png_int_16pp; 632 | typedef const char * * png_const_charpp; 633 | typedef char * * png_charpp; 634 | typedef png_fixed_point * * png_fixed_point_pp; 635 | #ifdef PNG_FLOATING_POINT_SUPPORTED 636 | typedef double * * png_doublepp; 637 | #endif 638 | 639 | /* Pointers to pointers to pointers; i.e., pointer to array */ 640 | typedef char * * * png_charppp; 641 | 642 | #endif /* PNG_BUILDING_SYMBOL_TABLE */ 643 | 644 | #endif /* PNGCONF_H */ 645 | -------------------------------------------------------------------------------- /mt5parser.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "buffer.h" 12 | #include "pngwriter.h" 13 | #include "pvrspi.h" 14 | #include "mt5parser.h" 15 | #include "taparser.h" 16 | #include "database.h" 17 | 18 | using namespace std; 19 | 20 | buffer *buf; 21 | 22 | struct vector3d { float x, y, z; }; 23 | struct vector2d { float u, v;}; 24 | struct vertUV { 25 | unsigned long vertex; 26 | unsigned long uv; 27 | unsigned long color; 28 | }; 29 | 30 | class vertexNormalUVData { 31 | public: 32 | vertexNormalUVData(unsigned long ofs, unsigned long ncount) : count(ncount) { 33 | vector3d p; 34 | buf->seek(ofs); 35 | cout << " VertexNormal " << count << endl; 36 | for (unsigned long i=0; irf(); 38 | p.y = buf->rf(); 39 | p.z = buf->rf(); 40 | vertexVector.push_back(p); 41 | // cout << " " << i << " (" << p.x << "," << p.y << "," << p.z << ")"; 42 | p.x = buf->rf(); 43 | p.y = buf->rf(); 44 | p.z = buf->rf(); 45 | normalVector.push_back(p); 46 | // cout << " (" << p.x << "," << p.y << "," << p.z << ")" << endl; 47 | } 48 | } 49 | ~vertexNormalUVData() { 50 | vertexVector.clear(); 51 | normalVector.clear(); 52 | uvVector.clear(); 53 | colorVector.clear(); 54 | } 55 | 56 | public: //!!MH!! better private with friends 57 | unsigned long count; 58 | vector vertexVector; 59 | vector normalVector; 60 | vector uvVector; 61 | vector colorVector; 62 | }; 63 | 64 | class meshStrip { 65 | public: 66 | meshStrip(unsigned long ofs,unsigned short nformat, vertexNormalUVData *pVertexNormalUV) : format(nformat){ 67 | buf->seek(ofs); 68 | nVertUV = (unsigned long) (0xffff - buf->rw() + 1); 69 | // cout << " MeshStrip " << nVertUV << " "; 70 | vertUV v; 71 | vector2d uvCoord; 72 | vector2d color; 73 | for (unsigned long i=0; irw(); 77 | v.uv = 0xffffffff; 78 | v.color = 0xffffffff; 79 | // cout << i << "(" << v.vertex << ") "; 80 | break; 81 | case 0x11: 82 | v.vertex = (unsigned long)buf->rw(); 83 | v.uv = pVertexNormalUV->uvVector.size(); 84 | v.color = 0xffffffff; 85 | uvCoord.u = (float)((signed short)(buf->rw()))/(float)(0x3ff); 86 | uvCoord.v = (float)((signed short)(buf->rw()))/(float)(0x3ff); 87 | pVertexNormalUV->uvVector.push_back(uvCoord); 88 | // cout << i << "(" << v.vertex << "," << v.u << "," << v.v << ") "; 89 | break; 90 | case 0x1c: 91 | v.vertex = (unsigned long)buf->rw(); 92 | v.uv = pVertexNormalUV->uvVector.size(); 93 | uvCoord.u = (float)((signed short)(buf->rw()))/(float)(0x3ff); 94 | uvCoord.v = (float)((signed short)(buf->rw()))/(float)(0x3ff); 95 | pVertexNormalUV->uvVector.push_back(uvCoord); 96 | v.color = pVertexNormalUV->colorVector.size(); 97 | color.u = buf->rw(); 98 | color.v = buf->rw(); 99 | pVertexNormalUV->colorVector.push_back(color); 100 | //cout << i << "(" << hex << color.u << "," << color.v << ") " << dec; 101 | break; 102 | default: 103 | cerr << "unknown mesh strip format" << hex << format << endl; 104 | exit(1); 105 | } 106 | vertUVVector.push_back(v); 107 | } 108 | // cout << endl; 109 | } 110 | ~meshStrip() { 111 | vertUVVector.clear(); 112 | } 113 | unsigned long getSize() { 114 | switch (format) { 115 | case 0x10: // only vertex information 116 | return nVertUV * 2+2; 117 | break; 118 | case 0x11: // vertex and uv information 119 | return nVertUV * 6+2; 120 | break; 121 | case 0x1c: // vertex and uv and additional (color?) information 122 | return nVertUV * 10+2; 123 | break; 124 | default: 125 | cerr << "unknown mesh strip format" << hex << format << endl; 126 | exit(1); 127 | } 128 | } // +2 (number of vertices in strip) 129 | 130 | public: //!!MH!! better make it public with friend classes 131 | unsigned long nVertUV; 132 | unsigned short format; 133 | vector vertUVVector; 134 | }; 135 | 136 | class meshObject { 137 | public: 138 | meshObject(unsigned long nofs, vertexNormalUVData *pVertexNormalUV) : ofs(nofs){ 139 | taparser ta(buf, ofs); 140 | ta.dump(); 141 | buf->seek(ofs); 142 | cout << " MeshObject ofs=" << ofs << " "; 143 | for (int i=0; i<3; i++) { 144 | header[i] = buf->rw(); 145 | cout << hex << header[i] << " "; 146 | } 147 | switch (getType()) { 148 | case 0x2e: 149 | case 0x0a: // Type 0x2e is a regular textured Mesh, Type 0x0a also contains interpolated color 150 | headerSize = 16; 151 | break; 152 | case 0x26: // no texture coordinates (flat?) 153 | headerSize = 12; 154 | break; 155 | default: 156 | cerr << "unknown mesh object format" << hex << header[2] << endl; 157 | exit(1); 158 | } 159 | for (unsigned long i=3; irw(); 161 | cout << hex << header[i] << " "; 162 | } 163 | cout << endl; 164 | nStrips = buf->rw(); 165 | cout << " Number of strips " << nStrips << endl; 166 | unsigned long pos = ofs + 2 + headerSize*2; // header size + number of strips 167 | for (unsigned long i=0; igetSize(); 171 | } 172 | } 173 | ~meshObject() { 174 | for (vector::iterator it = meshStripVector.begin(); it != meshStripVector.end(); it++) { 175 | delete *it; 176 | } 177 | meshStripVector.clear(); 178 | } 179 | unsigned long getID() {return ofs;} 180 | unsigned long getSize() {return (unsigned long)header[headerSize-1]+headerSize*2;}// add size of strip header 181 | unsigned short getTrans() {return header[0];} 182 | unsigned short getType() {return header[2];} 183 | unsigned short getTextureNumber() {return header[11];} 184 | unsigned short getPrimitiveType() {return header[headerSize-2];} 185 | public: //!!MH!! better make it private with friend classes 186 | unsigned long ofs; 187 | unsigned short header[16]; 188 | 189 | unsigned long headerSize; 190 | unsigned long nStrips; 191 | vector meshStripVector; 192 | }; 193 | 194 | class meshData { 195 | public: 196 | meshData(unsigned long ofs, unsigned long nObjStart) : objStart(nObjStart) { 197 | buf->seek(ofs); 198 | for (int i=0; i<4; i++) header[i] = buf->rl(); 199 | cout << " MeshData " << hex << header[0] << " " << header[1] << " " << header[2] << " " << header[3] << endl; 200 | } 201 | ~meshData() { 202 | } 203 | private: 204 | unsigned long header[4]; 205 | unsigned long objStart; // First object that is described by this data 206 | }; 207 | 208 | class modelData { 209 | public: 210 | modelData(unsigned long ofs) : pVertexNormalUV(NULL) { 211 | buf->seek(ofs); 212 | polyType = buf->rl(); 213 | oVertexNormal = buf->rl(); 214 | vertexCount = buf->rl(); 215 | oMesh = buf->rl(); 216 | f1 = buf->rl(); 217 | f2 = buf->rl(); 218 | f3 = buf->rl(); 219 | f4 = buf->rl(); 220 | cout << "polyType=" << polyType << " oVertexNormal=" << hex << oVertexNormal << " vertexCount=" << vertexCount << " oMesh=" << hex << oMesh << endl; 221 | cout << "f1=" << hex << f1 << " f2=" << f2 << " f3=" << f3 << " f4=" << f4 << dec << endl; 222 | 223 | pVertexNormalUV = new vertexNormalUVData(oVertexNormal, vertexCount); 224 | meshData *pMeshData; 225 | meshObject *pMeshObject; 226 | unsigned long pos = oMesh; 227 | unsigned long magic; 228 | do { 229 | buf->seek(pos); 230 | magic = buf->rl(); 231 | switch (magic) { 232 | case 0x00100002: 233 | case 0x00100003: 234 | case 0x00100004: 235 | pMeshObject = new meshObject(pos, pVertexNormalUV); 236 | meshObjectVector.push_back(pMeshObject); 237 | pos += pMeshObject->getSize(); 238 | break; 239 | case 0x0008000e: 240 | pMeshData = new meshData(pos, meshObjectVector.size()); 241 | meshDataVector.push_back(pMeshData); 242 | pos += 16; 243 | break; 244 | case 0xffff8000: 245 | // end Model data 246 | break; 247 | default: 248 | cerr << "unknown magic " << hex << magic << endl; 249 | exit(1); 250 | break; 251 | } 252 | } while (magic != 0xffff8000); 253 | } 254 | ~modelData() { 255 | if (pVertexNormalUV) delete pVertexNormalUV; 256 | for (vector::iterator it = meshDataVector.begin(); it != meshDataVector.end(); it++) { 257 | delete *it; 258 | } 259 | meshDataVector.clear(); 260 | for (vector::iterator it = meshObjectVector.begin(); it != meshObjectVector.end(); it++) { 261 | delete *it; 262 | } 263 | meshObjectVector.clear(); 264 | } 265 | 266 | public: // !!MH!! better private with friends? 267 | unsigned long polyType; 268 | unsigned long oVertexNormal; 269 | unsigned long vertexCount; 270 | unsigned long oMesh; 271 | unsigned long f1, f2, f3, f4; 272 | 273 | vertexNormalUVData *pVertexNormalUV; 274 | vector meshDataVector; 275 | vector meshObjectVector; 276 | }; 277 | 278 | class node; 279 | map modelMap; 280 | 281 | class node { 282 | public: 283 | node(unsigned long ofs) : myOfs(ofs), pDown(NULL), pNext(NULL), pUp(NULL) { 284 | modelMap[ofs] = this; 285 | buf->seek(ofs); 286 | nodeID = buf->rl(); 287 | oMeshHeader = buf->rl(); 288 | rotX = 360. * ((float)buf->rl())/((float)(0xffff)); 289 | rotY = 360. * ((float)buf->rl())/((float)(0xffff)); 290 | rotZ = 360. * ((float)buf->rl())/((float)(0xffff)); 291 | scaleX = buf->rf(); 292 | scaleY = buf->rf(); 293 | scaleZ = buf->rf(); 294 | x = buf->rf(); 295 | y = buf->rf(); 296 | z = buf->rf(); 297 | oDown = buf->rl(); 298 | oNext = buf->rl(); 299 | oUp = buf->rl(); 300 | unsigned long unknown0 = buf->rl(); 301 | unsigned long unknown1 = buf->rl(); 302 | if (unknown0 != 0 || unknown1 != 0) { 303 | cerr << "node definition ofs=" << ofs << " has unknown bytes not equal to zero." << endl; 304 | exit(1); 305 | } 306 | map ::iterator found; 307 | cout << "nodeID=" << hex << nodeID << " oMeshHeader=" << hex << oMeshHeader 308 | << " rotX=" << rotX << " rotY=" << rotY << " rotZ=" << rotZ 309 | << " scaleX=" << scaleX << " scaleY=" << scaleY << " scaleZ=" << scaleZ 310 | << " x=" << x << " y=" << y << " z=" << z 311 | << " oDown=" << hex << oDown << " oNext=" << hex << oNext << " oUp=" << hex << oUp << endl; 312 | if (oMeshHeader) pData = new modelData(oMeshHeader); else pData = NULL; 313 | if (oUp) { 314 | if ((found = modelMap.find(oUp)) == modelMap.end()) { 315 | pUp = new node(oUp); 316 | } else pUp = found->second; 317 | } 318 | if (oNext) { 319 | if ((found = modelMap.find(oNext)) == modelMap.end()) { 320 | pNext = new node(oNext); 321 | } else pNext = found->second; 322 | } 323 | if (oDown) { 324 | if ((found = modelMap.find(oDown)) == modelMap.end()) { 325 | pDown = new node(oDown); 326 | } else pDown = found->second; 327 | } 328 | } 329 | public: //!!MH!! better private with friends ? 330 | unsigned long nodeID; 331 | unsigned long oMeshHeader; 332 | float rotX, rotY, rotZ; 333 | float scaleX, scaleY, scaleZ; 334 | float x,y,z; 335 | unsigned long oDown, oNext, oUp; 336 | 337 | unsigned long myOfs; 338 | 339 | node *pDown; 340 | node *pNext; 341 | node *pUp; 342 | 343 | modelData *pData; 344 | }; 345 | 346 | map nameMap; 347 | 348 | struct texl { 349 | public: 350 | unsigned long ofs; 351 | unsigned long u1, u2; 352 | texn *name; 353 | }; 354 | 355 | class textureData { 356 | public: 357 | textureData(unsigned long ofs) { 358 | unsigned long i; 359 | unsigned long start; 360 | texn *name; 361 | texl load; 362 | do { 363 | buf->seek(ofs); 364 | if (buf->eof()) break; 365 | unsigned long magic = buf->rl(); 366 | unsigned long length = buf->rl(); 367 | switch (magic) { 368 | case ('DXET'): 369 | nTextures = buf->rl(); 370 | break; 371 | case ('NXET'): 372 | readTexture(ofs); 373 | break; 374 | case ('EMAN'): 375 | for (i=0; i<((length-8)/8);i++) { 376 | name = new texn; 377 | *((unsigned long *)name->name)=buf->rl(); 378 | *((unsigned long *)((name->name)+4))=buf->rl(); 379 | textureNameVector.push_back(name); 380 | cout << hex << *(unsigned long *)name->name << *(unsigned long *)((name->name)+4) << endl; 381 | nameMap[ofs] = name; 382 | } 383 | break; 384 | case ('LXET'): 385 | start = buf->rl(); 386 | nLoads = buf->rl(); 387 | for (i=0; i<((length-16)/12);i++) { 388 | load.ofs=buf->rl(); 389 | load.u1=buf->rl(); 390 | load.u2=buf->rl(); 391 | map::iterator found; 392 | if ((found = nameMap.find(load.ofs))==nameMap.end()) load.name = NULL; else load.name = found->second; 393 | textureLoadVector.push_back(load); 394 | } 395 | if (start != ofs+16) { 396 | cerr << "TEXL start is strange (ofs=" << hex << ofs << ",start=" << start << ")" << endl; 397 | exit(1); 398 | } 399 | if (nLoads != (length-16)/12) { 400 | cerr << "TEXL number of loads is strange (nLoads=" << hex << nLoads << ",(length-16)/12=" << (length-16)/12 << ")" << endl; 401 | exit(1); 402 | } 403 | break; 404 | case ('LRTP'): 405 | nPtr = buf->rl(); 406 | for (i=0; i<((length-12)/4); i++) { 407 | texturePtrVector.push_back(buf->rl()); 408 | } 409 | if (nPtr != (length-12)/4) { 410 | cerr << "PTRL number of pointers is strange (nPtr=" << hex << nPtr << ",(length-12)/4=" << (length-12)/4 << ")" << endl; 411 | exit(1); 412 | } 413 | break; 414 | default: 415 | cerr << "unknown texture magic word " << hex << magic << endl; 416 | exit(1); 417 | } 418 | ofs += length; 419 | } while (true); 420 | } 421 | 422 | ~textureData() { 423 | for (vector::iterator it = textureNameVector.begin(); it != textureNameVector.end(); it++) { 424 | delete *it; 425 | } 426 | textureNameVector.clear(); 427 | textureLoadVector.clear(); 428 | texturePtrVector.clear(); 429 | } 430 | 431 | void readTexture(unsigned long ofs) { 432 | buf->seek(ofs); 433 | unsigned long magic1 = buf->rl(); 434 | if (magic1 != 'NXET') { 435 | cerr << "Wrong Texture Magic Word" << endl; 436 | exit(1); 437 | } 438 | unsigned long texSize = buf->rl(); 439 | texn *name = new texn; 440 | *((unsigned long *)name->name)=buf->rl(); 441 | *((unsigned long *)((name->name)+4))=buf->rl(); 442 | textureNameVector.push_back(name); 443 | nameMap[ofs] = name; 444 | unsigned long magic2 = buf->rl(); 445 | if (magic2 != 'XIBG') { 446 | cerr << "Wrong GBIX Magic Word" << endl; 447 | exit(1); 448 | } 449 | unsigned long unknown = buf->rl(); 450 | unsigned long texnum = buf->rl(); 451 | unsigned long magic3 = buf->rl(); 452 | if (magic3 != 'TRVP') { 453 | cerr << "Wrong PVRT Magic Word" << endl; 454 | exit(1); 455 | } 456 | cout << "Texture " << texnum << ": size=" << texSize << ", name=" << hex << *((unsigned long *)(name->name)) << "_" << *((unsigned long *)(name->name+4)) << ", unknown=" << unknown << endl; 457 | 458 | int width, height; 459 | int image_size; 460 | int bits; 461 | unsigned char *outptr; 462 | int ret; 463 | stringstream fname; 464 | 465 | fname.clear(); 466 | fname.str(""); 467 | fname << "tex_" << hex << *((unsigned long *)(name->name)) << "_" << *((unsigned long *)(name->name+4)) << ".pvr" << dec; 468 | b->dump(fname.str().c_str(), ofs+28, texSize-28); 469 | // Convert Dreamcast Texture to PNG file for blender export 470 | b->seek(ofs+28); 471 | ret = pvr2bin(b->ptr(),outptr,width, height, image_size, bits); 472 | cout << "res:" << ret << " width:" << width << " height:" << height << endl; 473 | fname.clear(); 474 | fname.str(""); 475 | texn t; 476 | memcpy(t.name, name->name, 8); 477 | fname << "t" << hex << texDB.getID(&t) << ".png"; 478 | writePng(fname.str().c_str(), outptr, width, height, bits); 479 | free(outptr); 480 | } 481 | 482 | public: //!!MH!! change to private with friends classes 483 | unsigned long nTextures; 484 | unsigned long nLoads; 485 | unsigned long nPtr; 486 | vector textureNameVector; 487 | vector textureLoadVector; 488 | vector texturePtrVector; 489 | }; 490 | 491 | mt5::mt5() : m(NULL){} 492 | 493 | mt5::~mt5() { 494 | if (m) delete m; 495 | modelMap.clear(); 496 | nameMap.clear(); 497 | } 498 | 499 | void mt5::readData(buffer *nbuf) { 500 | buf = nbuf; 501 | buf->seek(0); 502 | modelMap.clear(); 503 | nameMap.clear(); 504 | unsigned long magic = buf->rl(); 505 | unsigned long oTex = buf->rl(); 506 | unsigned long oModel = buf->rl(); 507 | 508 | // Read Header 509 | if (magic != 'MCRH') { 510 | cerr << "unknown format (only HRCM supported)" << endl; 511 | return; 512 | } 513 | cout << "Texture Pointer:" << std::hex << oTex << " Model Pointer:" << std::hex << oModel << endl; 514 | 515 | m = new node(oModel); 516 | t = new textureData(oTex); 517 | } 518 | 519 | colladaExport::colladaExport() :fname(NULL){} 520 | colladaExport::~colladaExport() { 521 | if (fname) delete [] fname; 522 | } 523 | 524 | void colladaExport::exportModel(const char * nfname, mt5 *model) { 525 | string mname; 526 | string texName; 527 | string matName; 528 | ofstream expFile; 529 | 530 | mDB.clear(); 531 | nDB.clear(); 532 | 533 | fname = new char[strlen(nfname)+1]; 534 | strcpy(fname, nfname); 535 | 536 | expFile.open((string(fname)+".dae").c_str()); 537 | 538 | // Export Header 539 | expFile << "" << endl; 540 | expFile << "" << endl; 541 | expFile << "" << endl; 542 | expFile << "\t" << endl; 543 | expFile << "\t\tMT5Converter (Marc.Hellwig@gmail.com)" << endl; 544 | expFile << "\t" << endl; 545 | expFile << "\t" << endl; 546 | expFile << "\tY_UP" << endl; 547 | expFile << "" << endl; 548 | 549 | // Export the texture names 550 | expFile << "" << endl; 551 | for (vector ::iterator tit=model->t->textureNameVector.begin(); tit != model->t->textureNameVector.end(); tit++) { 552 | texName = getTextureName(*tit); 553 | expFile << "\t" << endl; 554 | expFile << "\t\t" << getTextureFileName(*tit) << "" << endl; 555 | expFile << "\t" << endl; 556 | } 557 | expFile << "" << endl; 558 | 559 | // Export the material 560 | expFile << "" << endl; 561 | // go through all the models and figure out, which textures are in use 562 | for (map ::iterator it=modelMap.begin(); it != modelMap.end(); it++) { 563 | if (it->second->pData) { 564 | // go through ALL mesh objects 565 | mname = getModelName(it->first, it->second->nodeID); 566 | for (vector::iterator mObIt = it->second->pData->meshObjectVector.begin(); mObIt != it->second->pData->meshObjectVector.end(); mObIt++) { 567 | unsigned short mtype = (*mObIt)->getType(); 568 | if (mtype == 0x2e || mtype == 0x0a) texName = getTextureName(model->t->textureNameVector[(*mObIt)->getTextureNumber()]); 569 | matName = mname + getMeshName((*mObIt)->getID()); 570 | expFile << "\t" << endl; 571 | expFile << "\t\t" << endl; 572 | if (mtype == 0x2e || mtype == 0x0a) { 573 | expFile << "\t\t\t" << endl; 574 | expFile << "\t\t\t\t" << endl; 575 | expFile << "\t\t\t\t\t" << texName << "_png" << endl; 576 | expFile << "\t\t\t\t" << endl; 577 | expFile << "\t\t\t" << endl; 578 | expFile << "\t\t\t" << endl; 579 | expFile << "\t\t\t\t" << endl; 580 | expFile << "\t\t\t\t\t" << texName << "_png-surface" << endl; 581 | expFile << "\t\t\t\t" << endl; 582 | expFile << "\t\t\t" << endl; 583 | } 584 | expFile << "\t\t\t" << endl; 585 | expFile << "\t\t\t\t" << endl; 586 | expFile << "\t\t\t\t\t" << endl; 587 | expFile << "\t\t\t\t\t\t0 0 0 1" << endl; 588 | expFile << "\t\t\t\t\t" << endl; 589 | expFile << "\t\t\t\t\t" << endl; 590 | expFile << "\t\t\t\t\t\t0.5 0.5 0.5 1" << endl; 591 | expFile << "\t\t\t\t\t" << endl; 592 | if (mtype == 0x2e || mtype == 0x0a) { 593 | expFile << "\t\t\t\t\t" << endl; 594 | expFile << "\t\t\t\t\t\t" << endl; 595 | expFile << "\t\t\t\t\t" << endl; 596 | } 597 | expFile << "\t\t\t\t\t" << endl; 598 | expFile << "\t\t\t\t\t\t0.1 0.1 0.1 1" << endl; 599 | expFile << "\t\t\t\t\t" << endl; 600 | expFile << "\t\t\t\t\t" << endl; 601 | expFile << "\t\t\t\t\t\t50" << endl; 602 | expFile << "\t\t\t\t\t" << endl; 603 | if ((*mObIt)->getTrans() == 3) { 604 | if (mtype == 0x2e || mtype == 0x0a) { 605 | expFile << "\t\t\t\t\t" << endl; 606 | expFile << "\t\t\t\t\t\t" << endl; 607 | expFile << "\t\t\t\t\t" << endl; 608 | } 609 | expFile << "\t\t\t\t\t" << endl; 610 | expFile << "\t\t\t\t\t\t0" << endl; 611 | expFile << "\t\t\t\t\t" << endl; 612 | } 613 | expFile << "\t\t\t\t\t" << endl; 614 | expFile << "\t\t\t\t\t\t1" << endl; 615 | expFile << "\t\t\t\t\t" << endl; 616 | expFile << "\t\t\t\t" << endl; 617 | expFile << "\t\t\t" << endl; 618 | expFile << "\t\t" << endl; 619 | expFile << "\t" << endl; 620 | } 621 | } 622 | } 623 | expFile << "" << endl; 624 | expFile << "" << endl; 625 | // go through all the models and figure out, which textures are in use 626 | for (map ::iterator it=modelMap.begin(); it != modelMap.end(); it++) { 627 | if (it->second->pData) { 628 | mname = getModelName(it->first, it->second->nodeID); 629 | for (vector::iterator mObIt = it->second->pData->meshObjectVector.begin(); mObIt != it->second->pData->meshObjectVector.end(); mObIt++) { 630 | matName = mname + getMeshName((*mObIt)->getID()); 631 | expFile << "\t" << endl; 632 | expFile << "\t\t" << endl; 633 | expFile << "\t" << endl; 634 | } 635 | } 636 | } 637 | expFile << "" << endl; 638 | 639 | // Export the geometry of the models 640 | expFile << "" << endl; 641 | for (map ::iterator it=modelMap.begin(); it != modelMap.end(); it++) { 642 | mname = getModelName(it->first, it->second->nodeID); 643 | if (it->second->pData) { 644 | expFile << "\t" << endl; 645 | expFile << "\t\t" << endl; 646 | 647 | // Vertex Data 648 | expFile << "\t\t\t" << endl; 649 | expFile << "\t\t\t\tsecond->pData->vertexCount*3 << "\">"; 650 | for (vector::iterator vit=it->second->pData->pVertexNormalUV->vertexVector.begin(); vit != it->second->pData->pVertexNormalUV->vertexVector.end(); vit++) { 651 | expFile << vit->x << " " << vit->y << " " << vit->z << " "; 652 | } 653 | expFile << "" << endl; 654 | expFile << "\t\t\t\t" << endl; 655 | expFile << "\t\t\t\t\tsecond->pData->vertexCount << "\" stride=\"3\">" << endl; 656 | expFile << "\t\t\t\t\t\t" << endl; 657 | expFile << "\t\t\t\t\t\t" << endl; 658 | expFile << "\t\t\t\t\t\t" << endl; 659 | expFile << "\t\t\t\t\t" << endl; 660 | expFile << "\t\t\t\t" << endl; 661 | expFile << "\t\t\t" << endl; 662 | 663 | // Normal Data 664 | expFile << "\t\t\t" << endl; 665 | expFile << "\t\t\t\tsecond->pData->vertexCount*3 << "\">"; 666 | for (vector::iterator vit=it->second->pData->pVertexNormalUV->normalVector.begin(); vit != it->second->pData->pVertexNormalUV->normalVector.end(); vit++) { 667 | expFile << vit->x << " " << vit->y << " " << vit->z << " "; 668 | } 669 | expFile << "" << endl; 670 | expFile << "\t\t\t\t" << endl; 671 | expFile << "\t\t\t\t\tsecond->pData->vertexCount << "\" stride=\"3\">" << endl; 672 | expFile << "\t\t\t\t\t\t" << endl; 673 | expFile << "\t\t\t\t\t\t" << endl; 674 | expFile << "\t\t\t\t\t\t" << endl; 675 | expFile << "\t\t\t\t\t" << endl; 676 | expFile << "\t\t\t\t" << endl; 677 | expFile << "\t\t\t" << endl; 678 | 679 | // UV Data 680 | if (it->second->pData->pVertexNormalUV->uvVector.size()) { 681 | expFile << "\t\t\t" << endl; 682 | expFile << "\t\t\t\tsecond->pData->pVertexNormalUV->uvVector.size() * 2 << "\">"; 683 | for (vector::iterator vit=it->second->pData->pVertexNormalUV->uvVector.begin(); vit != it->second->pData->pVertexNormalUV->uvVector.end(); vit++) { 684 | expFile << vit->u << " " << vit->v << " "; 685 | } 686 | expFile << "" << endl; 687 | expFile << "\t\t\t\t" << endl; 688 | expFile << "\t\t\t\t\tsecond->pData->pVertexNormalUV->uvVector.size() << "\" stride=\"2\">" << endl; 689 | expFile << "\t\t\t\t\t\t" << endl; 690 | expFile << "\t\t\t\t\t\t" << endl; 691 | expFile << "\t\t\t\t\t" << endl; 692 | expFile << "\t\t\t\t" << endl; 693 | expFile << "\t\t\t" << endl; 694 | } 695 | 696 | // Color Data 697 | /* if (it->second->pData->pVertexNormalUV->colorVector.size()) { 698 | expFile << "\t\t\t" << endl; 699 | expFile << "\t\t\t\tsecond->pData->pVertexNormalUV->colorVector.size() * 2 << "\">"; 700 | for (vector::iterator vit=it->second->pData->pVertexNormalUV->colorVector.begin(); vit != it->second->pData->pVertexNormalUV->colorVector.end(); vit++) { 701 | expFile << vit->u << " " << vit->v << " "; 702 | } 703 | expFile << "" << endl; 704 | expFile << "\t\t\t\t" << endl; 705 | expFile << "\t\t\t\t\tsecond->pData->pVertexNormalUV->uvVector.size() << "\" stride=\"2\">" << endl; 706 | expFile << "\t\t\t\t\t\t" << endl; 707 | expFile << "\t\t\t\t\t\t" << endl; 708 | expFile << "\t\t\t\t\t" << endl; 709 | expFile << "\t\t\t\t" << endl; 710 | expFile << "\t\t\t" << endl; 711 | }*/ 712 | 713 | // Vertices 714 | expFile << "\t\t\t" << endl; 715 | expFile << "\t\t\t\t" << endl; 716 | expFile << "\t\t\t" << endl; 717 | 718 | #ifdef USE_TRIANGLE_STRIPS 719 | // Now the triangles, quads and trianglestrips 720 | for (vector::iterator mObIt = it->second->pData->meshObjectVector.begin(); mObIt != it->second->pData->meshObjectVector.end(); mObIt++) { 721 | expFile << "\t\t\tnStrips << "\">" << endl; 722 | expFile << "\t\t\t\t" << endl; 723 | expFile << "\t\t\t\t" << endl; 724 | expFile << "\t\t\t\t" << endl; 725 | for (vector::iterator mStIt = (*mObIt)->meshStripVector.begin(); mStIt != (*mObIt)->meshStripVector.end(); mStIt++) { 726 | expFile << "\t\t\t\t

"; 727 | for (vector::iterator tVIt = (*mStIt)->vertUVVector.begin(); tVIt != (*mStIt)->vertUVVector.end(); tVIt++) { 728 | expFile << tVIt->vertex << " " << tVIt->vertex << " " << tVIt->uv << " "; 729 | } 730 | expFile << "

" << endl; 731 | } 732 | expFile << "\t\t\t
" << endl; 733 | } 734 | #else 735 | for (vector::iterator mObIt = it->second->pData->meshObjectVector.begin(); mObIt != it->second->pData->meshObjectVector.end(); mObIt++) { 736 | matName = " material=\"" + getModelName(it->first, it->second->nodeID) + getMeshName((*mObIt)->getID()) + "-material\""; 737 | for (vector::iterator mStIt = (*mObIt)->meshStripVector.begin(); mStIt != (*mObIt)->meshStripVector.end(); mStIt++) { 738 | expFile << "\t\t\tformat == 0x11 || (*mStIt)->format == 0x1c) expFile << matName; 740 | expFile << " count=\"" << (*mStIt)->vertUVVector.size()-2 << "\">" << endl; 741 | expFile << "\t\t\t\t" << endl; 742 | expFile << "\t\t\t\t" << endl; 743 | if ((*mStIt)->format == 0x11 || (*mStIt)->format == 0x1c) expFile << "\t\t\t\t" << endl; 744 | // if ((*mStIt)->format == 0x1c) expFile << "\t\t\t\t" << endl; 745 | expFile << "\t\t\t\t

" << endl; 746 | for (unsigned long triangleLoop = 0; triangleLoop < (*mStIt)->vertUVVector.size()-2; triangleLoop++) { 747 | expFile << string(5,'\t') 748 | << ((triangleLoop%2) ? ((*mStIt)->vertUVVector[triangleLoop+1].vertex) : ((*mStIt)->vertUVVector[triangleLoop].vertex)) << " " 749 | << ((triangleLoop%2) ? ((*mStIt)->vertUVVector[triangleLoop+1].vertex) : ((*mStIt)->vertUVVector[triangleLoop].vertex)) << " "; 750 | if ((*mStIt)->format == 0x11 || (*mStIt)->format == 0x1c) expFile << ((triangleLoop%2) ? ((*mStIt)->vertUVVector[triangleLoop+1].uv) : ((*mStIt)->vertUVVector[triangleLoop].uv)) << " "; 751 | // if ((*mStIt)->format == 0x1c) expFile << ((triangleLoop%2) ? ((*mStIt)->vertUVVector[triangleLoop+1].color) : ((*mStIt)->vertUVVector[triangleLoop].color)) << " "; 752 | expFile << " "; 753 | expFile << ((triangleLoop%2) ? ((*mStIt)->vertUVVector[triangleLoop].vertex) : ((*mStIt)->vertUVVector[triangleLoop+1].vertex)) << " " 754 | << ((triangleLoop%2) ? ((*mStIt)->vertUVVector[triangleLoop].vertex) : ((*mStIt)->vertUVVector[triangleLoop+1].vertex)) << " "; 755 | if ((*mStIt)->format == 0x11 || (*mStIt)->format == 0x1c) expFile << ((triangleLoop%2) ? ((*mStIt)->vertUVVector[triangleLoop].uv) : ((*mStIt)->vertUVVector[triangleLoop+1].uv)) << " "; 756 | // if ((*mStIt)->format == 0x1c) expFile << ((triangleLoop%2) ? ((*mStIt)->vertUVVector[triangleLoop].color) : ((*mStIt)->vertUVVector[triangleLoop+1].color)) << " "; 757 | expFile << " "; 758 | expFile << (*mStIt)->vertUVVector[triangleLoop+2].vertex << " " 759 | << (*mStIt)->vertUVVector[triangleLoop+2].vertex << " "; 760 | if ((*mStIt)->format == 0x11 || (*mStIt)->format == 0x1c) expFile << (*mStIt)->vertUVVector[triangleLoop+2].uv << " "; 761 | // if ((*mStIt)->format == 0x1c) expFile << (*mStIt)->vertUVVector[triangleLoop+2].color << " "; 762 | expFile << endl; 763 | } 764 | expFile << "\t\t\t\t

" << endl; 765 | expFile << "\t\t\t" << endl; 766 | } 767 | } 768 | #endif 769 | 770 | // End of Geometry 771 | expFile << "\t\t
" << endl; 772 | expFile << "\t
" << endl; 773 | } 774 | } 775 | expFile << "
" << endl; 776 | 777 | // Export the scene 778 | expFile << "" << endl; 779 | expFile << "\t" << endl; 780 | expNode(expFile, model->m, model->t, 0); 781 | expFile << "\t" << endl; 782 | expFile << "" << endl; 783 | 784 | // End of File 785 | expFile << "" << endl; 786 | expFile << "\t" << endl; 787 | expFile << "" << endl; 788 | expFile << "
" << endl; 789 | 790 | expFile.close(); 791 | } 792 | 793 | void colladaExport::expNode(ofstream &expFile, node *sm, textureData *td, int level) { 794 | string mname = getModelName(sm->myOfs, sm->nodeID); 795 | string matName; 796 | 797 | expFile << string(level, '\t') << "\t\t" << endl; 798 | expFile << string(level, '\t') << "\t\t\t" << sm->x << " " << sm->y << " " << sm->z << "" << endl; 799 | expFile << string(level, '\t') << "\t\t\t1 0 0 " << sm->rotX << "" << endl; 800 | expFile << string(level, '\t') << "\t\t\t0 1 0 " << sm->rotY << "" << endl; 801 | expFile << string(level, '\t') << "\t\t\t0 0 1 " << sm->rotZ << "" << endl; 802 | expFile << string(level, '\t') << "\t\t\t" << sm->scaleX << " " << sm->scaleY << " " << sm->scaleZ << "" << endl; 803 | if (sm->pData) { 804 | expFile << string(level, '\t') << "\t\t\t" << endl; 805 | 806 | // go through ALL mesh objects 807 | for (vector::iterator mObIt = sm->pData->meshObjectVector.begin(); mObIt != sm->pData->meshObjectVector.end(); mObIt++) { 808 | matName = mname + getMeshName((*mObIt)->getID()); 809 | expFile << string(level, '\t') << "\t\t\t\t" << endl; 810 | expFile << string(level, '\t') << "\t\t\t\t\t" << endl; 811 | expFile << string(level, '\t') << "\t\t\t\t\t\t" << endl; 812 | if ((*mObIt)->getType() == 0x2e || (*mObIt)->getType() == 0x0a) { 813 | expFile << string(level, '\t') << "\t\t\t\t\t\t\t" << endl; 814 | } 815 | expFile << string(level, '\t') << "\t\t\t\t\t\t" << endl; 816 | expFile << string(level, '\t') << "\t\t\t\t\t" << endl; 817 | expFile << string(level, '\t') << "\t\t\t\t" << endl; 818 | } 819 | expFile << string(level, '\t') << "\t\t\t" << endl; 820 | } 821 | if (sm->pDown) expNode(expFile, sm->pDown, td, level+1); 822 | expFile << string(level, '\t') << "\t\t" << endl; 823 | if (sm->pNext) expNode(expFile, sm->pNext, td, level); 824 | } 825 | 826 | string colladaExport::getModelName(unsigned long ofs, unsigned long id) { 827 | stringstream res; 828 | res << "f" << hex << fDB.getID(fname) << "n" << hex << nDB.getID(ofs, id); 829 | return res.str(); 830 | } 831 | 832 | string colladaExport::getMeshName(unsigned long ofs) { 833 | stringstream res; 834 | res << "m" << hex << mDB.getID(ofs); 835 | return res.str(); 836 | } 837 | 838 | string colladaExport::getTextureName(texn *name) { 839 | stringstream res; 840 | res << "f" << hex << fDB.getID(fname) << "t" << hex << texDB.getID(name); 841 | return res.str(); 842 | } 843 | 844 | string colladaExport::getTextureFileName(texn *name) { 845 | stringstream res; 846 | res << "t" << hex << texDB.getID(name) << ".png"; 847 | return res.str(); 848 | } 849 | 850 | /*int main(int argc, char **argv) 851 | { 852 | if (argc != 3) { 853 | fprintf(stderr, "Shenmue MT5 Converter\nusage:%s \n", argv[0]); 854 | exit(-1); 855 | } 856 | b = new buffer(argv[1]); 857 | mt5 *mydata = new mt5(); 858 | mydata->readData(); 859 | cout << "Export Model" << endl; 860 | colladaExport *cExp = new colladaExport(); 861 | cExp->exportModel(argv[2], mydata); 862 | 863 | delete cExp; 864 | delete mydata; 865 | 866 | return 0; 867 | }*/ 868 | --------------------------------------------------------------------------------