void ECAT7DirectoryEntry::swapEndianness() { id_ = swapEndian(id_); startBlock_ = swapEndian(startBlock_); endBlock_ = swapEndian(endBlock_); status_ = swapEndian(status_); }
bool dtNavMeshHeaderSwapEndian(unsigned char* data, const int /*dataSize*/) { dtMeshHeader* header = (dtMeshHeader*)data; int swappedMagic = DT_NAVMESH_MAGIC; int swappedVersion = DT_NAVMESH_VERSION; swapEndian(&swappedMagic); swapEndian(&swappedVersion); if ((header->magic != DT_NAVMESH_MAGIC || header->version != DT_NAVMESH_VERSION) && (header->magic != swappedMagic || header->version != swappedVersion)) { return false; } swapEndian(&header->magic); swapEndian(&header->version); swapEndian(&header->x); swapEndian(&header->y); swapEndian(&header->userId); swapEndian(&header->polyCount); swapEndian(&header->vertCount); swapEndian(&header->maxLinkCount); swapEndian(&header->detailMeshCount); swapEndian(&header->detailVertCount); swapEndian(&header->detailTriCount); swapEndian(&header->bvNodeCount); swapEndian(&header->offMeshConCount); swapEndian(&header->offMeshBase); swapEndian(&header->walkableHeight); swapEndian(&header->walkableRadius); swapEndian(&header->walkableClimb); swapEndian(&header->bmin[0]); swapEndian(&header->bmin[1]); swapEndian(&header->bmin[2]); swapEndian(&header->bmax[0]); swapEndian(&header->bmax[1]); swapEndian(&header->bmax[2]); swapEndian(&header->bvQuantFactor); // Freelist index and pointers are updated when tile is added, no need to swap. return true; }
bool dtNavMeshDataSwapEndian(unsigned char* data, const int /*dataSize*/) { // Make sure the data is in right format. dtMeshHeader* header = (dtMeshHeader*)data; if (header->magic != DT_NAVMESH_MAGIC) return false; if (header->version != DT_NAVMESH_VERSION) return false; // Patch header pointers. const int headerSize = dtAlign4(sizeof(dtMeshHeader)); const int vertsSize = dtAlign4(sizeof(float)*3*header->vertCount); const int polysSize = dtAlign4(sizeof(dtPoly)*header->polyCount); const int linksSize = dtAlign4(sizeof(dtLink)*(header->maxLinkCount)); const int detailMeshesSize = dtAlign4(sizeof(dtPolyDetail)*header->detailMeshCount); const int detailVertsSize = dtAlign4(sizeof(float)*3*header->detailVertCount); const int detailTrisSize = dtAlign4(sizeof(unsigned char)*4*header->detailTriCount); const int bvtreeSize = dtAlign4(sizeof(dtBVNode)*header->bvNodeCount); const int offMeshLinksSize = dtAlign4(sizeof(dtOffMeshConnection)*header->offMeshConCount); unsigned char* d = data + headerSize; float* verts = (float*)d; d += vertsSize; dtPoly* polys = (dtPoly*)d; d += polysSize; /*dtLink* links = (dtLink*)d;*/ d += linksSize; dtPolyDetail* detailMeshes = (dtPolyDetail*)d; d += detailMeshesSize; float* detailVerts = (float*)d; d += detailVertsSize; /*unsigned char* detailTris = (unsigned char*)d;*/ d += detailTrisSize; dtBVNode* bvTree = (dtBVNode*)d; d += bvtreeSize; dtOffMeshConnection* offMeshCons = (dtOffMeshConnection*)d; d += offMeshLinksSize; // Vertices for (int i = 0; i < header->vertCount*3; ++i) { swapEndian(&verts[i]); } // Polys for (int i = 0; i < header->polyCount; ++i) { dtPoly* p = &polys[i]; // poly->firstLink is update when tile is added, no need to swap. for (int j = 0; j < DT_VERTS_PER_POLYGON; ++j) { swapEndian(&p->verts[j]); swapEndian(&p->neis[j]); } swapEndian(&p->flags); } // Links are rebuild when tile is added, no need to swap. // Detail meshes for (int i = 0; i < header->detailMeshCount; ++i) { dtPolyDetail* pd = &detailMeshes[i]; swapEndian(&pd->vertBase); swapEndian(&pd->vertCount); swapEndian(&pd->triBase); swapEndian(&pd->triCount); } // Detail verts for (int i = 0; i < header->detailVertCount*3; ++i) { swapEndian(&detailVerts[i]); } // BV-tree for (int i = 0; i < header->bvNodeCount; ++i) { dtBVNode* node = &bvTree[i]; for (int j = 0; j < 3; ++j) { swapEndian(&node->bmin[j]); swapEndian(&node->bmax[j]); } swapEndian(&node->i); } // Off-mesh Connections. for (int i = 0; i < header->offMeshConCount; ++i) { dtOffMeshConnection* con = &offMeshCons[i]; for (int j = 0; j < 6; ++j) swapEndian(&con->pos[j]); swapEndian(&con->rad); swapEndian(&con->poly); } return true; }
Message * Parser::buildOC(char * buffer, uint64_t & reference) { char type = *buffer; reference = swapEndian((uint64_t*)(buffer + 11)); uint64_t shares = swapEndian((uint32_t*)(buffer + 19)); return new OCMessage(type, shares); }
Message * Parser::buildOD(char * buffer, uint64_t & reference) { char type = *buffer; reference = swapEndian((uint64_t*)(buffer + 11)); return new Message(type); }
DDS_IMAGE_DATA *loadDDSTextureFile(string filename) { DDSURFACEDESC2 ddsd; char filecode[4] = " "; FILE *pFile; int factor; int bufferSize; static DDS_IMAGE_DATA *pDDSImageData = NULL; static int prevBufferSize = 0; // Open the file pFile = fopen(filename.c_str(), "rb"); if (pFile == NULL) { cout << ("loadDDSTextureFile couldn't find, or failed to load " + filename); return NULL; } // Verify the file is a true .dds file if (!fread(filecode, 4, 1, pFile) || strncmp(filecode, "DDS ", 4) != 0) { cout << ("The file " + filename + " doesn't appear to be a valid .dds file!" ); fclose(pFile); return NULL; } // Get the surface descriptor if (!fread(&ddsd, sizeof(ddsd), 1, pFile)) { fclose(pFile); return NULL; } swapEndian(true, &ddsd, sizeof(long int), sizeof(ddsd) / sizeof(long int)); // This .dds loader supports the loading of compressed formats DXT1, DXT3 and DXT5. GLenum format; switch(ddsd.ddpfPixelFormat.dwFourCC) { case FOURCC_DXT1: // DXT1's compression ratio is 8:1 format = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; factor = 2; break; case FOURCC_DXT3: // DXT3's compression ratio is 4:1 pDDSImageData->format = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; factor = 4; break; case FOURCC_DXT5: // DXT5's compression ratio is 4:1 pDDSImageData->format = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; factor = 4; break; default: cout << ("The file " + filename + " doesn't appear to be compressed using DXT1, DXT3, or DXT5!"); fclose(pFile); return NULL; } if (ddsd.dwLinearSize == 0) ddsd.dwLinearSize = ddsd.dwWidth * ddsd.dwHeight / factor; if (ddsd.dwMipMapCount > 1) bufferSize = ddsd.dwLinearSize * factor; else bufferSize = ddsd.dwLinearSize; if (bufferSize > prevBufferSize || prevBufferSize > 512*512) { if (pDDSImageData) delete pDDSImageData; pDDSImageData = (DDS_IMAGE_DATA *) malloc(sizeof(DDS_IMAGE_DATA) + bufferSize * sizeof(unsigned char)); memset(pDDSImageData, 0, sizeof(DDS_IMAGE_DATA)); pDDSImageData->data = (unsigned char *) pDDSImageData + sizeof(DDS_IMAGE_DATA); prevBufferSize = bufferSize; } pDDSImageData->format = format; pDDSImageData->sizeX = ddsd.dwWidth; pDDSImageData->sizeY = ddsd.dwHeight; pDDSImageData->numMipMaps = ddsd.dwMipMapCount > 0 ? ddsd.dwMipMapCount : 1; if (ddsd.ddpfPixelFormat.dwFourCC == FOURCC_DXT1) pDDSImageData->components = 3; else pDDSImageData->components = 4; fread(pDDSImageData->data, bufferSize, 1, pFile); fclose(pFile); return pDDSImageData; }
Message * Parser::buildBT(char * buffer, uint64_t & match) { char type = *buffer; match =swapEndian((uint64_t*)(buffer + 11)); return new Message(type); }
/* ============================================================================= =============================================================================== */ void GLFontBase::CreateImpl(string fileName, bool bPixelPerfect) { clean(); m_PixelPerfect = bPixelPerfect; // Open font file FILE *fp = NULL; if (!(fp = fopen(fileName.c_str(), "rb"))) throw GLFontError::InvalidFile(); // Read glFont structure fread(&m_Font, sizeof(GLFONT), 1, fp); swapEndian(true, &(m_Font), sizeof(int), 5); //Save texture number ; //GLuint Tex; //glGenTextures(1, &Tex); //m_txID = Tex; // Get number of characters int Num = m_Font.IntEnd - m_Font.IntStart + 1; m_CharList.resize(Num); // Read glFont characters fread(&m_CharList[0], sizeof(GLFONTCHAR), Num, fp); swapEndian(true, &m_CharList[0], sizeof(float), 6 * Num); // Get texture size Num = m_Font.TexWidth * m_Font.TexHeight * 2; vector<char> TexBytes(Num); // Read texture data fread(&TexBytes[0], sizeof(char), Num, fp); // Set texture attributes /* glBindTexture(GL_TEXTURE_2D, m_txID); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); if (m_PixelPerfect) { glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } else { glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } // Create texture glTexImage2D(GL_TEXTURE_2D,0,2,m_Font.TexWidth,m_Font.TexHeight,0,GL_LUMINANCE_ALPHA,GL_UNSIGNED_BYTE,(void *) &TexBytes[0]); // Clean up glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); */ fclose(fp); }
/* this routine loads particle data from one block of Gadget's default * binary file format. (A snapshot may be distributed * into multiple files. */ int load_snapshot(char *fname, int block, int files) { char buf[200]; int i,k,dummy,ntot_withmasses; int n,pc,pc_new,pc_sph; int nread; int swap = 0; int type; int iDim; FILE *fd; int iBlock; int nskip; #define SKIP fread(&dummy, sizeof(dummy), 1, fd); for(i=0, pc=1; i<files; i++, pc=pc_new) { if(files>1) sprintf(buf,"%s.%d",fname,i); else sprintf(buf,"%s",fname); if(!(fd=fopen(buf,"r"))) { fprintf(stderr,"can't open file `%s`\n",buf); exit(0); } fread(&dummy, sizeof(dummy), 1, fd); if(dummy!=sizeof(header1)) { swap = 1; fprintf(stderr, "Trying endian swap\n"); swapEndian(&dummy, sizeof(dummy), 1); assert(dummy == sizeof(header1)); } nread = fread(&header1, sizeof(header1), 1, fd); if(nread != 1) { fprintf(stderr, "Bad header read of %s\n", buf); exit(-1); } if(swap) { swapEndian(&header1, 4, 6); // 6 integers swapEndian(&header1.mass, 8, 8); // 8 doubles swapEndian(&header1.flag_sfr, 4, 10); // 10 more integers swapEndian(&header1.BoxSize,8, 4); // 4 more doubles } fprintf(stderr, "BoxSize: %g\n", header1.BoxSize); fprintf(stderr, "Hubble parameter: %g\n", header1.HubbleParam); fread(&dummy, sizeof(dummy), 1, fd); NumPart = 0; if(files==1) { for(type = 0; type < 6; type++) NumPart += header1.npart[type]; } else { for(type = 0; type < 6; type++) NumPart += header1.npartTotal[type]; } if(i==0) allocate_memory(); for(iBlock = 0; iBlock < block; iBlock++) { SKIP; nskip = dummy; fseek(fd, nskip, SEEK_CUR); SKIP; assert(dummy == nskip); } SKIP; if(dummy == NumPart*sizeof(float)) iDim = 1; else if(dummy == 3*NumPart*sizeof(float)) iDim = 3; else assert(0); for(n=0;n<NumPart;n++) { if(iDim == 3) { nread = fread(&P[pc_new].Pos[0], sizeof(float), 3, fd); assert(nread == 3); if(swap) swapEndian(&P[pc_new].Pos[0], sizeof(float), 3); } if(iDim == 1) { nread = fread(&P[pc_new].Pos[0], sizeof(float), 1, fd); assert(nread == 1); if(swap) swapEndian(&P[pc_new].Pos[0], sizeof(float), 1); } pc_new++; } } fclose(fd); return iDim; }
void Stream::write64(uint64 l) { swapEndian(&l, sizeof(uint64)); write(&l, sizeof(uint64)); }
void Stream::write32(uint32 i) { swapEndian(&i, 4); write(&i, 4); }
void Stream::write16(uint16 s) { swapEndian(&s, 2); write(&s, 2); }
/****************************************************** *|F| int main(int argc, char **argv) ******************************************************/ int main(int argc, char **argv) { int a, i, trace, endian; printf("Video @ %i\n", VIDEO_BASE); trace = 0; endian = 0; strcpy(vm.filename, "retroImage"); init_vm(); init_devices(); vm.shrink = 0; /* Parse the command line arguments */ for (i = 1; i < argc; i++) { if (strcmp(argv[i], "--trace") == 0) { trace = 1; } else if (strcmp(argv[i], "--endian") == 0) { endian = 1; } else if (strcmp(argv[i], "--shrink") == 0) { vm.shrink = 1; } else if (strcmp(argv[i], "--help") == 0) { fprintf(stderr, "%s [options] [imagename]\n", argv[0]); fprintf(stderr, "Valid options are:\n"); fprintf(stderr, " --trace Execution trace\n"); fprintf(stderr, " --endian Load an image with a different endianness\n"); fprintf(stderr, " --shrink Only save used heap during save operation\n"); exit(0); } else { strcpy(vm.filename, argv[i]); } } /* Load the image */ a = vm_load_image(vm.filename); /* Swap endian if --endian was passed */ if (endian == 1) swapEndian(); /* Process the image */ if (trace == 0) { for (vm.ip = 0; vm.ip < IMAGE_SIZE; vm.ip++) { vm_process(vm.image[vm.ip]); update_display(0); } } else { for (vm.ip = 0; vm.ip < IMAGE_SIZE; vm.ip++) { display_instruction(); vm_process(vm.image[vm.ip]); update_display(0); } } /* Once done, cleanup */ cleanup_devices(); return 0; }
void Directory::updateChecksum() { swapEndian(); calculateChecksumBE(reinterpret_cast<uint16_t*>(__raw), 0xFFE, &m_checksum, &m_checksumInv); swapEndian(); }