//========================================================== // GshhsPolygon_WDB (entete de type GSHHS récent) //========================================================== GshhsPolygon_WDB::GshhsPolygon_WDB(ZUFILE *file_) { file = file_; ok = true; id = readInt4(); n = readInt4(); flag = readInt4(); west = readInt4() * 1e-6; east = readInt4() * 1e-6; south = readInt4() * 1e-6; north = readInt4() * 1e-6; area = readInt4(); greenwich = false; antarctic = false; if (ok) { for (int i=0; i<n; i++) { double x, y; x = readInt4() * 1e-6; if (greenwich && x > 270) x -= 360; y = readInt4() * 1e-6; lsPoints.push_back(new GshhsPoint(x,y)); } } }
static bool patchApplyPPF1(FILE *f, u8 **rom, int *size) { fseek(f, 0, SEEK_END); int count = ftell(f); if (count < 56) return false; count -= 56; fseek(f, 56, SEEK_SET); u8 *mem = *rom; while (count > 0) { int offset = readInt4(f); if (offset == -1) break; int len = fgetc(f); if (len == EOF) break; if (offset+len > *size) break; if (fread(&mem[offset], 1, len, f) != (size_t)len) break; count -= 4 + 1 + len; } return (count == 0); }
static bool patchApplyPPF2(FILE *f, u8 **rom, int *size) { fseek(f, 0, SEEK_END); int count = ftell(f); if (count < 56+4+1024) return false; count -= 56+4+1024; fseek(f, 56, SEEK_SET); int datalen = readInt4(f); if (datalen != *size) return false; u8 *mem = *rom; u8 block[1024]; fread(&block, 1, 1024, f); if (memcmp(&mem[0x9320], &block, 1024) != 0) return false; int idlen = ppfFileIdLen(f, 2); if (idlen > 0) count -= 16 + 16 + idlen; fseek(f, 56+4+1024, SEEK_SET); while (count > 0) { int offset = readInt4(f); if (offset == -1) break; int len = fgetc(f); if (len == EOF) break; if (offset+len > *size) break; if (fread(&mem[offset], 1, len, f) != (size_t)len) break; count -= 4 + 1 + len; } return (count == 0); }
static int ppfFileIdLen(FILE *f, int version) { if (version == 2) { fseeko64(f, -8, SEEK_END); } else { fseeko64(f, -6, SEEK_END); } if (fgetc(f) != '.' || fgetc(f) != 'D' || fgetc(f) != 'I' || fgetc(f) != 'Z') return 0; return (version == 2) ? readInt4(f) : readInt2(f); }
//========================================================== // GshhsPolygon (compatible avec le format .rim de RANGS) //========================================================== GshhsPolygon::GshhsPolygon(ZUFILE *file_) { file = file_; ok = true; id = readInt4(); n = readInt4(); flag = readInt4(); west = readInt4() * 1e-6; east = readInt4() * 1e-6; south = readInt4() * 1e-6; north = readInt4() * 1e-6; area = readInt4(); greenwich = readInt2(); readInt2(); // source antarctic = (west==0 && east==360); if (ok) { double x, y=-90; for (int i=0; i<n; i++) { x = readInt4() * 1e-6; if (greenwich && x > 270) x -= 360; y = readInt4() * 1e-6; lsPoints.push_back(new GshhsPoint(x,y)); } // force l'Antarctic à être un "rectangle" qui passe par le pôle if (antarctic) { lsPoints.insert (lsPoints.begin(), 2, (GshhsPoint*)0); lsPoints [1] = new GshhsPoint(360, y); lsPoints [0] = new GshhsPoint(360,-90); lsPoints.push_back(new GshhsPoint(0,-90)); } } }