Result SoundSourceCoreAudio::parseHeader() { if (getFilename().endsWith(".m4a")) { setType("m4a"); TagLib::MP4::File f(getFilename().toLocal8Bit().constData()); if (!readFileHeader(this, f)) { return ERR; } TagLib::MP4::Tag *mp4(f.tag()); if (mp4) { readMP4Tag(this, *mp4); } else { // fallback const TagLib::Tag *tag(f.tag()); if (tag) { readTag(this, *tag); } else { return ERR; } } } else if (getFilename().endsWith(".mp3")) { setType("mp3"); TagLib::MPEG::File f(getFilename().toLocal8Bit().constData()); if (!readFileHeader(this, f)) { return ERR; } TagLib::ID3v2::Tag* id3v2 = f.ID3v2Tag(); if (id3v2) { readID3v2Tag(this, *id3v2); } else { TagLib::APE::Tag *ape = f.APETag(); if (ape) { readAPETag(this, *ape); } else { // fallback const TagLib::Tag *tag(f.tag()); if (tag) { readTag(this, *tag); } else { return ERR; } } } } else if (getFilename().endsWith(".mp2")) { setType("mp2"); //TODO: MP2 metadata. Does anyone use mp2 files anymore? // Feels like 1995 again... return ERR; } return OK; }
int PackVmlinuzI386::canUnpack() { if (readFileHeader() != getFormat()) return false; fi->seek(setup_size, SEEK_SET); return readPackHeader(1024) ? 1 : -1; }
BMP readBMP(FILE* source, int* error) { BMP bmp; bmp.fileHeader = readFileHeader(source); if (bmp.fileHeader.type != 0x4d42) { *error = CABEZERA_INCORRECTA; return bmp; } fread(&bmp.size, sizeof(bmp.size), 1, source); fread(&bmp.width, sizeof(bmp.width), 1, source); fread(&bmp.height, sizeof(bmp.height), 1, source); fread(&bmp.planes, sizeof(bmp.planes), 1, source); fread(&bmp.bits, sizeof(bmp.bits), 1, source); fread(&bmp.compression, sizeof(bmp.compression), 1, source); fread(&bmp.imagesize, sizeof(bmp.imagesize), 1, source); fread(&bmp.xresolution, sizeof(bmp.xresolution), 1, source); fread(&bmp.yresolution, sizeof(bmp.yresolution), 1, source); fread(&bmp.ncolours, sizeof(bmp.ncolours), 1, source); fread(&bmp.importantcolours, sizeof(bmp.importantcolours), 1, source); bmp.memory = malloc(bmp.imagesize); fread(bmp.memory, 1, bmp.imagesize, source); return bmp; }
int PackTmt::canUnpack() { if (!readFileHeader()) return false; fi->seek(adam_offset, SEEK_SET); return readPackHeader(512) ? 1 : -1; }
void LodConfigSerializer::importLodConfig(Ogre::LodConfig* config, DataStreamPtr& stream) { mStream = stream; mLodConfig = config; // Determine endianness (must be the first thing we do!) determineEndianness(mStream); // Check header readFileHeader(mStream); pushInnerChunk(mStream); while (!mStream->eof()) { unsigned short streamID = readChunk(mStream); switch (streamID) { case LCCID_LOD_CONFIG: readLodConfig(); break; default: backpedalChunkHeader(mStream); popInnerChunk(mStream); return; } } popInnerChunk(mStream); }
//--------------------------------------------------------------------- void SkeletonSerializer::importSkeleton(DataStreamPtr& stream, Skeleton* pSkel) { // Determine endianness (must be the first thing we do!) determineEndianness(stream); // Check header readFileHeader(stream); unsigned short streamID; while(!stream->eof()) { streamID = readChunk(stream); switch (streamID) { case SKELETON_BONE: readBone(stream, pSkel); break; case SKELETON_BONE_PARENT: readBoneParent(stream, pSkel); break; case SKELETON_ANIMATION: readAnimation(stream, pSkel); break; case SKELETON_ANIMATION_LINK: readSkeletonAnimationLink(stream, pSkel); break; } } // Assume bones are stored in the binding pose pSkel->setBindingPose(); }
YUV::YUV(char *filename) { if (readFileHeader(filename)) throw new std::runtime_error("Unable to read file header!"); init(); }
void PackTos::fileInfo() { if (!readFileHeader()) return; con_fprintf(stdout, " text: %d, data: %d, sym: %d, bss: %d, flags=0x%x\n", (int)ih.fh_text, (int)ih.fh_data, (int)ih.fh_sym, (int)ih.fh_bss, (int)ih.fh_flag); }
bool PackArmPe::canPack() { if (!readFileHeader() || (ih.cpu != 0x1c0 && ih.cpu != 0x1c2)) return false; use_thumb_stub |= ih.cpu == 0x1c2 || (ih.entry & 1) == 1; use_thumb_stub |= (opt->cpu == opt->CPU_8086); // FIXME return true; }
void Application::paramChange(void *) { //fprintf(stderr,"param change\n"); int i; char msg[200]; // clear data delete_data(); // read data file name parameter if (!getFilename()) return; // open the file if (!openFile()) return; // read the file header if (!readFileHeader(fp, Title, &nVars, VarNames)) { fclose(fp); return; } fclose(fp); sprintf(msg, "TITLE: \"%s\"", Title); Covise::sendInfo(msg); sprintf(msg, "%i VARIABLES", nVars); Covise::sendInfo(msg); // copy variable names to choice param // Covise::update_choice_param ("datax", nVars+1, VarNames, 1); strcpy(msg, "(none)"); if (nVars >= MAX_N_VARS) { Covise::sendError("Limit of maximum number of variables exceeded in ReadFlower"); return; } for (i = 1; i < nVars + 1; i++) { strcat(msg, " "); strcat(msg, VarNames[i]); } if (!Covise::update_string_param("allVars", msg)) { Covise::sendError("error at call 'update_string_param ()' in function 'paramChange'."); return; } strcpy(msg, VarNames[1]); for (i = 2; i < 4; i++) { strcat(msg, "/"); strcat(msg, VarNames[i]); } Covise::update_string_param("gridselect", msg); preInitOK = TRUE; }
IMAGE* readRGB(char *fileName, bool printInfo) { if(printInfo) printf("Reading File...\n"); FileHeader fileHeader; BMPHeader bmpHeader; FILE *fhandle = fopen(fileName,"rb"); readFileHeader(fhandle, &fileHeader, printInfo); readDataHeader(fhandle, &bmpHeader, printInfo); IMAGE *image = readRaster(fhandle, &fileHeader, &bmpHeader, printInfo); fclose(fhandle); return image; }
/** Read image in @e filename into memory. * * @throw ImageException from open() * @throw ImageException from readFileHeader() * @throw ImageException from readInfoHeader() * @throw ImageException from readPixels() * * @see getFormat() * @see getPixels() * @see getSize() * @see getWidth() * @see getHeight() */ void BmpImageReader::read(const string &filename) { try { open(filename); readFileHeader(); readInfoHeader(); readPixels(); close(); } catch (BasicException &e) { close(); throw e; } }
void ImportAnnotationsFromCSVDialog::preview(bool silent) { QString fileName = checkInputGroup(silent); if (fileName.isEmpty()) { return; } QString text = readFileHeader(fileName, silent); previewTable->clear(); rawPreview->clear(); rawPreview->setPlainText(text); if (!checkSeparators(true)) { return; } CSVParsingConfig parseOptions; toParsingConfig(parseOptions); if (parseOptions.splitToken.isEmpty() && parseOptions.parsingScript.isEmpty()) { return; } int columnCount = 0; TaskStateInfo ti; QList<QStringList> lines = ReadCSVAsAnnotationsTask::parseLinesIntoTokens(text, parseOptions, columnCount, ti); if (ti.hasError()) { QMessageBox::critical(this, L10N::errorTitle(), ti.getError()); return; } prepareColumnsConfig(columnCount); columnCount = qMax(columnCount, columnsConfig.size()); previewTable->setRowCount(lines.size()); previewTable->setColumnCount(columnCount); for (int column = 0; column < columnCount; column++) { QTableWidgetItem* headerItem = createHeaderItem(column); previewTable->setHorizontalHeaderItem(column, headerItem); } for (int row = 0; row < lines.size(); row++) { const QStringList& rowData = lines.at(row); for (int column = 0; column < rowData.size(); column ++) { QString token = rowData.at(column); QTableWidgetItem* item = new QTableWidgetItem(token); item->setFlags(Qt::ItemIsEnabled); previewTable->setItem(row, column, item); } } }
int PackTos::canUnpack() { if (!readFileHeader()) return false; if (!readPackHeader(768)) return false; // check header as set by packer if ((ih.fh_text & 3) != 0 || (ih.fh_data & 3) != 0 || (ih.fh_bss & 3) != 0 || ih.fh_sym != 0 || ih.fh_reserved != 0 || ih.fh_reloc > 1) throwCantUnpack("program header damaged"); // generic check if (!checkFileHeader()) throwCantUnpack("unsupported header flags"); return true; }
bool PackTos::canPack() { if (!readFileHeader()) return false; unsigned char buf[768]; fi->readx(buf, sizeof(buf)); checkAlreadyPacked(buf, sizeof(buf)); if (!checkFileHeader()) throwCantPack("unsupported header flags"); if (file_size < 1024) throwCantPack("program is too small"); return true; }
IMAGE* readGrey(char *fileName, bool printInfo) { if(printInfo) printf("Reading File...\n"); FileHeader fileHeader; BMPHeader bmpHeader; FILE *fhandle = fopen(fileName,"rb"); readFileHeader(fhandle, &fileHeader, printInfo); readDataHeader(fhandle, &bmpHeader, printInfo); IMAGE *image; if(bmpHeader.bitCount == 8) image = readRaster(fhandle, &fileHeader, &bmpHeader, printInfo); else image = readLuminance(fhandle, &fileHeader, &bmpHeader, printInfo); fclose(fhandle); return image; }
//--------------------------------------------------------------------- void SkeletonSerializer::importSkeleton(DataStreamPtr& stream, Skeleton* pSkel) { // Determine endianness (must be the first thing we do!) determineEndianness(stream); // Check header readFileHeader(stream); pushInnerChunk(stream); unsigned short streamID = readChunk(stream); while(!stream->eof()) { switch (streamID) { case SKELETON_BLENDMODE: { // Optional blend mode uint16 blendMode; readShorts(stream, &blendMode, 1); pSkel->setBlendMode(static_cast<SkeletonAnimationBlendMode>(blendMode)); break; } case SKELETON_BONE: readBone(stream, pSkel); break; case SKELETON_BONE_PARENT: readBoneParent(stream, pSkel); break; case SKELETON_ANIMATION: readAnimation(stream, pSkel); break; case SKELETON_ANIMATION_LINK: readSkeletonAnimationLink(stream, pSkel); break; default: break; } streamID = readChunk(stream); } // Assume bones are stored in the binding pose pSkel->setBindingPose(); popInnerChunk(stream); }
void ImportAnnotationsFromCSVDialog::guessSeparator(bool silent) { QString url = checkInputGroup(silent); if (url.isEmpty()) { return; } QString text = readFileHeader(url, silent); CSVParsingConfig config; toParsingConfig(config); QString sep = ReadCSVAsAnnotationsTask::guessSeparatorString(text, config); if (sep.isEmpty()) { if (!silent) { QMessageBox::critical(this, L10N::errorTitle(), tr("Failed to guess separator sequence!")); readFileName->setFocus(); } return; } separatorEdit->setText(sep); preview(silent); }
int main(int argc, char *argv[]) { FILE * fin = NULL; FILE * fout = NULL; char ltr[MAX]; char lineOne[MAX]; char lineTwo[MAX]; char outputName[MAX]; int edgeWidth, centerRow, centerColumn, radius; int ** imageNumbers = NULL; int rows, columns, intensity; int i; fin = openFile(argc, argv, ltr, &edgeWidth, ¢erRow, ¢erColumn, &radius, outputName); fout = fopen(outputName, "w"); readFileHeader(fin, &rows, &columns, &intensity, lineOne, lineTwo); imageNumbers = (int**) malloc(rows * sizeof(int*)); for(i = 0; i < rows; i++) imageNumbers[i] = (int*)malloc(columns * sizeof(int)); fill2DArray(imageNumbers, rows, columns, fin); if(strcmp(ltr, "-e") == 0) createBorder(imageNumbers, rows, columns, edgeWidth); else createCircle(imageNumbers, centerRow, centerColumn, radius, rows, columns); intensity = findMax2DArray(imageNumbers,rows,columns); printArray2DToFile(imageNumbers, rows, columns, fout, lineOne, outputName, intensity); cleanUp(imageNumbers,rows); if(fin != NULL) fclose(fin); if(fout != NULL) fclose(fout); return 0; }
/*------------------------------------------------------------------------------------------------------------ * ビットマップファイルを読み込む * * path: 読み込むビットマップファイル */ void Bitmap::readFile(const char *path) { FILE *ifp = fopen(path, "rb"); if (ifp == 0) { perror("fopen"); fprintf(stderr, "file: %s\n", path); throw MyError("bitmap file open failed", __FUNCTION__); } int error; error = readFileHeader(ifp); if (error > 0) { throw MyError("failed to read bitmap file header", __FUNCTION__); } error = readInfoHeader(ifp); if (error > 0) { throw MyError("failed to read bitmap info header", __FUNCTION__); } mDataSize = mFileHeader.bfSize - mInfoHeader.biSize - sizeof(mFileHeader); if (mDataSize != 0) { delete [] mData; } mData = new unsigned char[mDataSize]; error = readBitmapData(ifp); if (error > 0) { throw MyError("failed toread bitmap data", __FUNCTION__); } mWidth = mInfoHeader.biWidth; mHeight = mInfoHeader.biHeight; fclose(ifp); }
/* Parse the the file to get metadata */ Result SoundSourceOggVorbis::parseHeader() { QByteArray qBAFilename = getFilename().toLocal8Bit(); TagLib::Ogg::Vorbis::File f(qBAFilename.constData()); if (!readFileHeader(this, f)) { return ERR; } TagLib::Ogg::XiphComment *xiph = f.tag(); if (xiph) { readXiphComment(this, *xiph); } else { // fallback const TagLib::Tag *tag(f.tag()); if (tag) { readTag(this, *tag); } else { return ERR; } } return OK; }
void OgreMeshDeserializer::deserialize() { // Determine endianness (must be the first thing we do!) determineEndianness(m_stream); // Check header readFileHeader(m_stream); unsigned short streamID = readChunk(m_stream); while (!m_stream.eof()) { switch (streamID) { case M_MESH: readMesh(); break; default: skipChunk(m_stream); } streamID = readChunk(m_stream); } }
int MidiFile::read(const char *fileName) { if (fileName == NULL) return 1; setFileName(fileName); _target = openFile(fileName); if (!_target) return 1; readFileHeader(); setType(); setTrackCount(); setBPM(); for (int i = 0; i < _fileHeader._tracks; i++) { _curTrack = i; readTrack(); printContour(); } fclose(_target); return 0; }
bool PackVmlinuzI386::canPack() { return readFileHeader() == getFormat(); }
/********************************************************************* 功能:载入文件到数据集中,并保存传入文件名记录为当前文件名 参数:filename,文件名 返回:>0,成功,记录数;<0,失败 作者:叶文林 2012-08-22 *********************************************************************/ int CFixedLenRecordFile::load(const char * filename) { if (filename == NULL) return -1; m_pCritical->enter(); //进临界区 int ret1 = 0; DWORD count = 0; DWORD readlen = 0; int len = 0; //保存文件名 saveFileName(filename); //打开文件 int res = -1; FILE * f = fopen(filename,"rb"); if (f == NULL) goto LAB_END_ERR_LOADFILE; //读文件头 res = -2; TFileHeaderFixedLenRecord fileHeader; ret1 = readFileHeader(&fileHeader,f); if (ret1 <= 0) goto LAB_END_ERR_LOADFILE; //读文件体 res = -3; count = (fileHeader.recoredCount < m_maxRecCount) ? fileHeader.recoredCount : m_maxRecCount; //可读取记录数 fileHeader.recoredCount = count; readlen = fileHeader.perRecLen * count; if (m_pBody != NULL) delete [] m_pBody; m_recCountForBodyMem = (count + m_reservedRecCountForBody < m_maxRecCount) ? count + m_reservedRecCountForBody : m_maxRecCount; //实际为文件body区分配内存 m_pBody = NULL; m_pBody = new BYTE [m_recCountForBodyMem * fileHeader.perRecLen]; len = fread(m_pBody,1,readlen,f); if (len <readlen) goto LAB_END_ERR_READBODY; //关闭文件 fclose(f); //保存文件头 memcpy(&m_header,&fileHeader,sizeof(TFileHeaderFixedLenRecord)); //给索引指针重赋值 resetRecList(); res = fileHeader.recoredCount; goto LAB_END; LAB_END_ERR_READBODY: //分配文件体空间后,读取出错 delete [] m_pBody; m_pBody = NULL; LAB_END_ERR_LOADFILE: //未能成功载入文件 if (f != NULL) fclose(f); //关闭文件 //分配空间(只分配最小预留内存) if (m_pBody == NULL) { initEmpFileHeader(); m_recCountForBodyMem = m_reservedRecCountForBody; if (m_recCountForBodyMem>0) { m_pBody = new BYTE [m_recCountForBodyMem * m_header.perRecLen]; WLOutDebug(">> m_pBody = %.8X,len = %d",m_pBody,m_recCountForBodyMem * m_header.perRecLen); } } LAB_END: //完成 m_pCritical->leave(); //出临界区 return res; }
int PackArmPe::canUnpack() { if (!readFileHeader() || (ih.cpu != 0x1c0 && ih.cpu != 0x1c2)) return false; unsigned objs = ih.objects; isection = new pe_section_t[objs]; fi->seek(pe_offset+sizeof(ih),SEEK_SET); fi->readx(isection,sizeof(pe_section_t)*objs); if (ih.objects < 3) return -1; bool is_packed = ((ih.objects == 3 || ih.objects == 4) && (IDSIZE(15) || ih.entry > isection[1].vaddr)); bool found_ph = false; if (memcmp(isection[0].name,"UPX",3) == 0) { // current version fi->seek(isection[1].rawdataptr - 64, SEEK_SET); found_ph = readPackHeader(1024); if (!found_ph) { // old versions fi->seek(isection[2].rawdataptr, SEEK_SET); found_ph = readPackHeader(1024); } } if (is_packed && found_ph) return true; if (!is_packed && !found_ph) return -1; if (is_packed && ih.entry < isection[2].vaddr) { unsigned char buf[256]; bool x = false; memset(buf, 0, sizeof(buf)); try { fi->seek(ih.entry - isection[1].vaddr + isection[1].rawdataptr, SEEK_SET); fi->read(buf, sizeof(buf)); // FIXME this is for x86 static const unsigned char magic[] = "\x8b\x1e\x83\xee\xfc\x11\xdb"; // mov ebx, [esi]; sub esi, -4; adc ebx,ebx int offset = find(buf, sizeof(buf), magic, 7); if (offset >= 0 && find(buf + offset + 1, sizeof(buf) - offset - 1, magic, 7) >= 0) x = true; } catch (...) { //x = true; } if (x) throwCantUnpack("file is modified/hacked/protected; take care!!!"); else throwCantUnpack("file is possibly modified/hacked/protected; take care!"); return false; // not reached } // FIXME: what should we say here ? //throwCantUnpack("file is possibly modified/hacked/protected; take care!"); return false; }
Result SoundSourceSndFile::parseHeader() { QString location = getFilename(); setType(location.section(".",-1).toLower()); bool is_flac = location.endsWith("flac", Qt::CaseInsensitive); bool is_wav = location.endsWith("wav", Qt::CaseInsensitive); QByteArray qBAFilename = getFilename().toLocal8Bit(); if (is_flac) { TagLib::FLAC::File f(qBAFilename.constData()); if (!readFileHeader(this, f)) { return ERR; } TagLib::Ogg::XiphComment* xiph = f.xiphComment(); if (xiph) { readXiphComment(this, *xiph); } else { TagLib::ID3v2::Tag *id3v2(f.ID3v2Tag()); if (id3v2) { readID3v2Tag(this, *id3v2); } else { // fallback const TagLib::Tag *tag(f.tag()); if (tag) { readTag(this, *tag); } else { return ERR; } } } } else if (is_wav) { TagLib::RIFF::WAV::File f(qBAFilename.constData()); if (!readFileHeader(this, f)) { return ERR; } TagLib::ID3v2::Tag *id3v2(f.ID3v2Tag()); if (id3v2) { readID3v2Tag(this, *id3v2); } else { // fallback const TagLib::Tag *tag(f.tag()); if (tag) { readTag(this, *tag); } else { return ERR; } } if (getDuration() <= 0) { // we're using a taglib version which doesn't know how to do wav // durations, set it with info from sndfile -bkgood // XXX remove this when ubuntu ships with an sufficiently // intelligent version of taglib, should happen in 11.10 // Have to open the file for info to be valid. if (fh == NULL) { open(); } if (info.samplerate > 0) { setDuration(info.frames / info.samplerate); } else { qDebug() << "WARNING: WAV file with invalid samplerate." << "Can't get duration using libsndfile."; } } } else { // Try AIFF TagLib::RIFF::AIFF::File f(qBAFilename.constData()); if (!readFileHeader(this, f)) { return ERR; } TagLib::ID3v2::Tag *id3v2(f.tag()); if (id3v2) { readID3v2Tag(this, *id3v2); } else { return ERR; } } return OK; }
bool ZipArchive::readZipFile() { if (checkFileHandleValid() == false) return false; ZipEOCDHeaderRecord eocdHeaderRec; if (readEOCDHeaderRecord(eocdHeaderRec) == false) return false; if (eocdHeaderRec.numberOfDisk != eocdHeaderRec.numberOfDiskWithStartOfCD) { LERROR("Need disk #" << eocdHeaderRec.numberOfDiskWithStartOfCD << " to read central directory!"); return false; } if (eocdHeaderRec.numberOfEntriesInCD <= 0) { LERROR("Error: central directory does not contain any entries!"); return false; } size_t offset = eocdHeaderRec.offsetStartCD; for (uint16_t i = 0; i < eocdHeaderRec.numberOfEntriesInCD; ++i) { ArchivedFile af; ZipFileHeader& fileHeader = af.zipFileHader_; bool res = readFileHeader(af.zipFileHader_, offset); if (res == true) { if (fileHeader.generalPurposeFlag != 0x0000) { LWARNING("A file seems to make use of advanced features "); LWARNING("this reader is unable to understand. skipping..."); continue; } bool validCompression = false; switch (fileHeader.compressionMethod) { case 0: case 8: validCompression = true; break; default: break; } if (validCompression == false) { LWARNING("Unsupported compression method (code = " << fileHeader.compressionMethod << ")!"); LWARNING("This archiver only supports standard deflate (code 8) and uncompressed (code 0)."); continue; } size_t fileNameOffset = (offset + SIZE_ZIPFILEHEADER); size_t extraFieldOffset = fileNameOffset + fileHeader.filenameLength; size_t commentOffset = extraFieldOffset + fileHeader.extraFieldLength; if (fileHeader.filenameLength > 0) af.fileName_ = readString(fileNameOffset, fileHeader.filenameLength); if (fileHeader.extraFieldLength > 0) af.fileExtra_ = readString(extraFieldOffset, fileHeader.extraFieldLength); if (fileHeader.fileCommentLength > 0) af.fileComment_ = readString(commentOffset, fileHeader.fileCommentLength); af.isNewInArchive_ = false; af.localHeaderOffset_ = fileHeader.localHeaderOffset; std::pair<ArchiveMap::iterator, bool> rs = files_.insert(std::make_pair(af.fileName_, af)); if (rs.second == false) LERROR("failed to extract directory entry for file '" << af.fileName_ << "'!"); } else LERROR("Failed to read directory entry for entry #" << i << "!"); // The next file header is found at the current offset plus the size of // this FileHeader struct (constant) and plus the 3 variable length fields // offset += (SIZE_ZIPFILEHEADER + fileHeader.filenameLength + fileHeader.extraFieldLength + fileHeader.fileCommentLength); } return true; }
/** * Initialize data structures needed buy the player and read the whole file into memory * @param filename Video file name * @param frameCallback Function to call each video frame * @param game Pointer to the Game instance * @param dx An offset on the x axis for the video to be rendered * @param dy An offset on the y axis for the video to be rendered */ bool FlcPlayer::init(const char *filename, void(*frameCallBack)(), Game *game, int dx, int dy) { if (_fileBuf != 0) { Log(LOG_ERROR) << "Trying to init a video player that is already initialized"; return false; } _frameCallBack = frameCallBack; _realScreen = game->getScreen(); _realScreen->clear(); _game = game; _dx = dx; _dy = dy; _fileSize = 0; _frameCount = 0; _audioFrameData = 0; _hasAudio = false; _audioData.loadingBuffer = 0; _audioData.playingBuffer = 0; std::ifstream file; file.open(filename, std::ifstream::in | std::ifstream::binary | std::ifstream::ate); if (!file.is_open()) { Log(LOG_ERROR) << "Could not open FLI/FLC file: " << filename; return false; } std::streamoff size = file.tellg(); file.seekg(0, std::ifstream::beg); // TODO: substitute with a cross-platform memory mapped file? _fileBuf = new Uint8[size]; _fileSize = size; file.read((char *)_fileBuf, size); file.close(); _audioFrameData = _fileBuf + 128; // Let's read the first 128 bytes readFileHeader(); // If it's a FLC or FLI file, it's ok if (_headerType == SDL_SwapLE16(FLI_TYPE) || (_headerType == SDL_SwapLE16(FLC_TYPE))) { _screenWidth = _headerWidth; _screenHeight = _headerHeight; _screenDepth = 8; Log(LOG_INFO) << "Playing flx, " << _screenWidth << "x" << _screenHeight << ", " << _headerFrames << " frames"; } else { Log(LOG_ERROR) << "Flx file failed header check."; return false; } // If the current surface used is at 8bpp use it if (_realScreen->getSurface()->getSurface()->format->BitsPerPixel == 8) { _mainScreen = _realScreen->getSurface()->getSurface(); } else // Otherwise create a new one { _mainScreen = SDL_AllocSurface(SDL_SWSURFACE, _screenWidth, _screenHeight, 8, 0, 0, 0, 0); } return true; }
bool PackTmt::canPack() { if (!readFileHeader()) return false; return true; }