BOOL DScm::LoadMap(VOID) { if (!m_Chk.Load(CHK_FILE_PATH)) return FALSE; if (!ReadVersion()) return FALSE; if (!ReadEra()) return FALSE; if (!ReadMapSize()) return FALSE; if (!ReadTile()) return FALSE; if (m_Edit) { if (!ReadIsoMap()) return FALSE; } else { if (!ReadThingy()) return FALSE; } if (!Verify()) return FALSE; return TRUE; }
// Read Tile // Read a tile into a read buffer // For version 2.1 only tile with lod=0 are stored in the tile table, so an // error will be returned if you try to use the table with a different lod. bool trpgr_Archive::ReadTile(uint32 x,uint32 y,uint32 lod,trpgMemReadBuffer &buf) { if (!isValid()) return false; // Reality check the address int32 numLods; header.GetNumLods(numLods); if (static_cast<int>(lod) >= numLods) return false; trpg2iPoint lodSize; header.GetLodSize(lod,lodSize); if (static_cast<int>(x) >= lodSize.x || static_cast<int>(y) >= lodSize.y) return false; trpgTileTable::TileMode tileMode; tileTable.GetMode(tileMode); bool status = true; if (tileMode == trpgTileTable::External || tileMode == trpgTileTable::ExternalSaved) { status = ReadExternalTile(x, y, lod, buf); } else { // Local tile. Figure out where it is (which file) int majorVersion, minorVersion; header.GetVersion(majorVersion, minorVersion); if(majorVersion == 2 && minorVersion >=1) { // Version 2.1 // Tile table contains only lod 0 tiles if(lod != 0) status = false; } if(status) { trpgwAppAddress addr; float zmin,zmax; status = tileTable.GetTile(x,y,lod,addr,zmin,zmax); if(status) status = ReadTile(addr, buf); } } return status; }
void LiveServer::OnReceiveChanges(LivePeer* connection, NetworkMessage* nmsg) { std::string data = nmsg->ReadString(); // -1 on address since we skip the first START_NODE when sending bn_reader.assign((uint8_t*)data.c_str() - 1, data.size()); BinaryNode* rootNode = bn_reader.getRootNode(); BinaryNode* tileNode = rootNode->getChild(); NetworkedAction* action = dynamic_cast<NetworkedAction*>(editor->actionQueue->createAction(ACTION_REMOTE)); action->owner = connection->GetClientID(); if (tileNode) do { Tile* t = ReadTile(tileNode, editor->map); if(!t) continue; action->addChange(newd Change(t)); } while (tileNode->advance()); bn_reader.close(); editor->actionQueue->addAction(action); gui.RefreshView(); }
void CTileHandler::ProcessTiles2(void) { unsigned char* data=new unsigned char[1024*1024*4]; bigTex=CBitmap(data,1,1); //free big tex memory int tilex=xsize/4; int tiley=ysize/4; int bigx=tilex/32; int bigy=tiley/32; int a=0; for(int a=0;a<bigx*bigy;++a){ int startTilex=(a%bigx)*32; int startTiley=(a/bigx)*32; #ifdef WIN32 DDSURFACEDESC2 ddsheader; int ddssignature; char name[100]; sprintf(name,"Temp%03i.dds",a); CFileHandler file(name); file.Read(&ddssignature, sizeof(int)); file.Read(&ddsheader, sizeof(DDSURFACEDESC2)); #else char name[100]; snprintf(name, 100, "temp/Temp%03i.bmp.raw", a); CFileHandler file(name); #endif char bigtile[696320]; //1024x1024 and 4 mipmaps file.Read(bigtile, 696320); for(int b=0;b<1024;++b){ int x=b%32; int y=b/32; int xb=startTilex+x; //curr pointer to tile in bigtex int yb=startTiley+y; char* ctile=new char[SMALL_TILE_SIZE]; ReadTile(x*32,y*32,ctile,bigtile); CBitmap* bm=new CBitmap(); bm->CreateFromDXT1((unsigned char*)ctile,32,32); int t1=tileUse[max(0,(yb-1)*tilex+xb)]; int t2=tileUse[max(0,yb*tilex+xb-1)]; int ct=FindCloseTile(bm,t1==t2?t1:-1); if(ct==-1){ tileUse[yb*tilex+xb]=usedTiles; tiles[usedTiles++]=bm; newTiles.push_back(ctile); } else { tileUse[yb*tilex+xb]=ct; delete bm; delete[] ctile; } } printf("Creating tiles %i/%i %i%%\n", usedTiles-numExternalTile,(a+1)*1024,(((a+1)*1024)*100)/(tilex*tiley)); } delete[] data; #ifdef WIN32 system("del /q temp*.dds"); #else system("rm temp/Temp*.bmp.raw"); #endif }
int ImagingLibTiffDecode(Imaging im, ImagingCodecState state, UINT8* buffer, Py_ssize_t bytes) { TIFFSTATE *clientstate = (TIFFSTATE *)state->context; char *filename = "tempfile.tif"; char *mode = "r"; TIFF *tiff; /* buffer is the encoded file, bytes is the length of the encoded file */ /* it all ends up in state->buffer, which is a uint8* from Imaging.h */ TRACE(("in decoder: bytes %d\n", bytes)); TRACE(("State: count %d, state %d, x %d, y %d, ystep %d\n", state->count, state->state, state->x, state->y, state->ystep)); TRACE(("State: xsize %d, ysize %d, xoff %d, yoff %d \n", state->xsize, state->ysize, state->xoff, state->yoff)); TRACE(("State: bits %d, bytes %d \n", state->bits, state->bytes)); TRACE(("Buffer: %p: %c%c%c%c\n", buffer, (char)buffer[0], (char)buffer[1],(char)buffer[2], (char)buffer[3])); TRACE(("State->Buffer: %c%c%c%c\n", (char)state->buffer[0], (char)state->buffer[1],(char)state->buffer[2], (char)state->buffer[3])); TRACE(("Image: mode %s, type %d, bands: %d, xsize %d, ysize %d \n", im->mode, im->type, im->bands, im->xsize, im->ysize)); TRACE(("Image: image8 %p, image32 %p, image %p, block %p \n", im->image8, im->image32, im->image, im->block)); TRACE(("Image: pixelsize: %d, linesize %d \n", im->pixelsize, im->linesize)); dump_state(clientstate); clientstate->size = bytes; clientstate->eof = clientstate->size; clientstate->loc = 0; clientstate->data = (tdata_t)buffer; clientstate->flrealloc = 0; dump_state(clientstate); TIFFSetWarningHandler(NULL); TIFFSetWarningHandlerExt(NULL); if (clientstate->fp) { TRACE(("Opening using fd: %d\n",clientstate->fp)); lseek(clientstate->fp,0,SEEK_SET); // Sometimes, I get it set to the end. tiff = TIFFFdOpen(clientstate->fp, filename, mode); } else { TRACE(("Opening from string\n")); tiff = TIFFClientOpen(filename, mode, (thandle_t) clientstate, _tiffReadProc, _tiffWriteProc, _tiffSeekProc, _tiffCloseProc, _tiffSizeProc, _tiffMapProc, _tiffUnmapProc); } if (!tiff){ TRACE(("Error, didn't get the tiff\n")); state->errcode = IMAGING_CODEC_BROKEN; return -1; } if (clientstate->ifd){ int rv; uint32 ifdoffset = clientstate->ifd; TRACE(("reading tiff ifd %u\n", ifdoffset)); rv = TIFFSetSubDirectory(tiff, ifdoffset); if (!rv){ TRACE(("error in TIFFSetSubDirectory")); return -1; } } if (TIFFIsTiled(tiff)) { UINT32 x, y, tile_y, row_byte_size; UINT32 tile_width, tile_length, current_tile_width; UINT8 *new_data; TIFFGetField(tiff, TIFFTAG_TILEWIDTH, &tile_width); TIFFGetField(tiff, TIFFTAG_TILELENGTH, &tile_length); // We could use TIFFTileSize, but for YCbCr data it returns subsampled data size row_byte_size = (tile_width * state->bits + 7) / 8; state->bytes = row_byte_size * tile_length; /* overflow check for malloc */ if (state->bytes > INT_MAX - 1) { state->errcode = IMAGING_CODEC_MEMORY; TIFFClose(tiff); return -1; } /* realloc to fit whole tile */ new_data = realloc (state->buffer, state->bytes); if (!new_data) { state->errcode = IMAGING_CODEC_MEMORY; TIFFClose(tiff); return -1; } state->buffer = new_data; TRACE(("TIFFTileSize: %d\n", state->bytes)); for (y = state->yoff; y < state->ysize; y += tile_length) { for (x = state->xoff; x < state->xsize; x += tile_width) { if (ReadTile(tiff, x, y, (UINT32*) state->buffer) == -1) { TRACE(("Decode Error, Tile at %dx%d\n", x, y)); state->errcode = IMAGING_CODEC_BROKEN; TIFFClose(tiff); return -1; } TRACE(("Read tile at %dx%d; \n\n", x, y)); current_tile_width = min(tile_width, state->xsize - x); // iterate over each line in the tile and stuff data into image for (tile_y = 0; tile_y < min(tile_length, state->ysize - y); tile_y++) { TRACE(("Writing tile data at %dx%d using tile_width: %d; \n", tile_y + y, x, current_tile_width)); // UINT8 * bbb = state->buffer + tile_y * row_byte_size; // TRACE(("chars: %x%x%x%x\n", ((UINT8 *)bbb)[0], ((UINT8 *)bbb)[1], ((UINT8 *)bbb)[2], ((UINT8 *)bbb)[3])); state->shuffle((UINT8*) im->image[tile_y + y] + x * im->pixelsize, state->buffer + tile_y * row_byte_size, current_tile_width ); } } } } else { UINT32 strip_row, row_byte_size; UINT8 *new_data; UINT32 rows_per_strip; TIFFGetField(tiff, TIFFTAG_ROWSPERSTRIP, &rows_per_strip); TRACE(("RowsPerStrip: %u \n", rows_per_strip)); // We could use TIFFStripSize, but for YCbCr data it returns subsampled data size row_byte_size = (state->xsize * state->bits + 7) / 8; state->bytes = rows_per_strip * row_byte_size; TRACE(("StripSize: %d \n", state->bytes)); /* realloc to fit whole strip */ new_data = realloc (state->buffer, state->bytes); if (!new_data) { state->errcode = IMAGING_CODEC_MEMORY; TIFFClose(tiff); return -1; } state->buffer = new_data; for (; state->y < state->ysize; state->y += rows_per_strip) { if (ReadStrip(tiff, state->y, (UINT32 *)state->buffer) == -1) { TRACE(("Decode Error, strip %d\n", TIFFComputeStrip(tiff, state->y, 0))); state->errcode = IMAGING_CODEC_BROKEN; TIFFClose(tiff); return -1; } TRACE(("Decoded strip for row %d \n", state->y)); // iterate over each row in the strip and stuff data into image for (strip_row = 0; strip_row < min(rows_per_strip, state->ysize - state->y); strip_row++) { TRACE(("Writing data into line %d ; \n", state->y + strip_row)); // UINT8 * bbb = state->buffer + strip_row * (state->bytes / rows_per_strip); // TRACE(("chars: %x %x %x %x\n", ((UINT8 *)bbb)[0], ((UINT8 *)bbb)[1], ((UINT8 *)bbb)[2], ((UINT8 *)bbb)[3])); state->shuffle((UINT8*) im->image[state->y + state->yoff + strip_row] + state->xoff * im->pixelsize, state->buffer + strip_row * row_byte_size, state->xsize); } } } TIFFClose(tiff); TRACE(("Done Decoding, Returning \n")); // Returning -1 here to force ImageFile.load to break, rather than // even think about looping back around. return -1; }
void CTileHandler::ProcessTiles2(void) { unsigned char* data=new unsigned char[1024*1024*4]; bigTex=CBitmap(data,1,1); //free big tex memory int tilex=xsize/4; int tiley=ysize/4; for(int a=0;a<(tilex*tiley)/1024;++a){ int startTile=a*1024; DDSURFACEDESC2 ddsheader; int ddssignature; char name[100]; sprintf(name,"Temp%03i.dds",a); CFileHandler file(name); file.Read(&ddssignature, sizeof(int)); file.Read(&ddsheader, sizeof(DDSURFACEDESC2)); char bigtile[696320]; //1024x1024 and 4 mipmaps file.Read(bigtile, 696320); for(int b=0;b<1024;++b){ int x=b%32; int y=b/32; int xb=(startTile+b)%tilex; int yb=(startTile+b)/tilex; char* ctile=new char[SMALL_TILE_SIZE]; ReadTile(x*32,y*32,ctile,bigtile); CBitmap* bm=new CBitmap(); bm->CreateFromDXT1((unsigned char*)ctile,32,32); int t1=tileUse[max(0,(yb-1)*tilex+xb)]; int t2=tileUse[max(0,yb*tilex+xb-1)]; int ct=FindCloseTile(bm,t1==t2?t1:-1); if(ct==-1){ tileUse[yb*tilex+xb]=usedTiles; tiles[usedTiles++]=bm; newTiles.push_back(ctile); } else { tileUse[yb*tilex+xb]=ct; delete bm; delete[] ctile; } } printf("Creating tiles %i/%i %i%%\n", usedTiles-numExternalTile,(a+1)*1024,(((a+1)*1024)*100)/(tilex*tiley)); } delete[] data; system("del temp*.dds"); /* char execstring[512]; sprintf(execstring, "nvdxt.exe -file temp\\*.bmp -dxt1c -dither"); for(int a=0;a<(usedTiles-numExternalTile+1023)/1024;++a){ int startTile=numExternalTile+a*1024; for(int b=0;b<1024 && startTile+b<usedTiles;++b){ int x=b%32; int y=b/32; for(int y2=0;y2<32;++y2){ for(int x2=0;x2<32;++x2){ data[((y*32+y2)*1024+x*32+x2)*4+0]=tiles[startTile+b]->mem[((y2)*32+x2)*4+0]; data[((y*32+y2)*1024+x*32+x2)*4+1]=tiles[startTile+b]->mem[((y2)*32+x2)*4+1]; data[((y*32+y2)*1024+x*32+x2)*4+2]=tiles[startTile+b]->mem[((y2)*32+x2)*4+2]; data[((y*32+y2)*1024+x*32+x2)*4+3]=tiles[startTile+b]->mem[((y2)*32+x2)*4+3]; } } } CBitmap square(data,1024,1024); char name[100]; sprintf(name,"temp\\Temp%03i.bmp",a); square.Save(name); printf("Writing bmp files %i%%\n", ((a*1024)*100)/(usedTiles)); } printf("Creating dds files\n"); system(execstring); system("del temp\\temp*.bmp"); */ }