/*! Loads the TGA file to memory (acces data using ITextureFile base class members). */ bool TgaFile::load(const std::string& filename) { // Loads up a targa file. Supported types are 8,24 and 32 // uncompressed images. unsigned char type[4]; unsigned char info[7]; int size = 0; FILE *fp = fopen( filename.c_str(), "rb" ); if( !fp ) return false; fread( &type, sizeof (char), 3, fp ); // Read in colormap info and image type, byte 0 ignored fseek( fp, 12, SEEK_SET); // Seek past the header and useless info fread( &info, sizeof (char), 6, fp ); if( type[1] != 0 || (type[2] != 2 && type[2] != 3) ) { fclose (fp); return false; } m_Width = info[0] + info[1] * 256; m_Height = info[2] + info[3] * 256; m_nBits = info[4]; size = m_Width * m_Height; // Make sure dimension is a power of 2 if( !checkSize(m_Width) || !checkSize(m_Height)) { fclose(fp); return false; } // Make sure we are loading a supported type if( m_nBits != 32 && m_nBits != 24 && m_nBits != 8 ) { fclose(fp); return false; } if( m_nBits == 32 ) m_pData = loadRGBA( fp, size ); else if( m_nBits == 24 ) m_pData = loadRGB( fp, size ); else if( m_nBits == 8 ) m_pData = loadGray( fp, size ); // No image data if( m_pData == NULL ) { fclose(fp); return false; } fclose( fp ); return true; }
bool Loader::load() { QString fn = m_fileName.path(); if ( fn.endsWith( ".nii.gz" ) || fn.endsWith( ".nii" ) || fn.endsWith( ".hdr" ) || fn.endsWith( ".ima" ) || fn.endsWith( ".img" ) ) { return loadNifti(); } if ( m_fileName.path().endsWith( ".fib" ) ) { return loadVTK(); } if ( m_fileName.path().endsWith( ".tck" ) ) { return loadMRtrix(); } if ( m_fileName.path().endsWith( ".vtk" ) ) { return loadVTK(); } if ( m_fileName.path().endsWith( ".json" ) ) { return loadJSON(); } if ( m_fileName.path().endsWith( ".asc" ) ) { //TODO: Deal with offsets: Check if orig is always the same size? return loadASC( QVector3D( 128, 128, 128 ) ); } if ( m_fileName.path().endsWith( ".set" ) ) { return loadSet(); } if ( m_fileName.path().endsWith( ".glyphset" ) ) { return loadGlyphset(); } if ( m_fileName.path().endsWith( ".cons" ) || m_fileName.path().endsWith( ".cxls" ) ) { return loadCons(); } if ( m_fileName.path().endsWith( ".meg" ) ) { return loadMEG(); } if ( m_fileName.path().endsWith( ".htree" ) ) { return loadTree(); } if ( m_fileName.path().endsWith( ".rgb" ) ) { return loadRGB(); } if ( m_fileName.path().endsWith( ".1D" ) ) { return load1D(); } if ( m_fileName.path().endsWith( ".png" ) || m_fileName.path().endsWith( ".jpg" ) ) { return loadPNG(); } return false; }