GLubyte* FileReader::loadTGA(const std::string &fileName, tgaHeader &header) { AAsset* asset = AAssetManager_open(FileReader::manager, fileName.c_str(), AASSET_MODE_UNKNOWN); if(asset == NULL) { writeLog("Asset = NULL"); } AAsset_read(asset, &header.idLength, 1); AAsset_read(asset, &header.colorMapType, 1); AAsset_read(asset, &header.type, 1); AAsset_seek(asset, 9, SEEK_CUR); AAsset_read(asset, &header.width, 2); AAsset_read(asset, &header.height, 2); AAsset_read(asset, &header.depth, 1); AAsset_read(asset, &header.descriptor, 1); AAsset_seek(asset, header.idLength, SEEK_CUR); //writeLog("spritewidth: %d, height: %d, depth: %d", header.width, header.height, header.depth); //24bit / 8 = 3 (RGB), 32bit / 8 = 4 (RGBA) int componentCount = header.depth/8; int size = componentCount * header.width * header.height; GLubyte* data = new GLubyte[size]; AAsset_read(asset, data, size); //data is now BGRA so we format it to RGBA for(int i = 0; i < size; i += componentCount) { GLubyte temp = data[i]; //Switch red and blue data[i] = data[i+2]; data[i+2] = temp; } AAsset_close(asset); return data; }
uint64_t File::Seek( int64_t ofs, DIR dir ) { if ( mType == BUFFER ) { if ( dir == BEGIN && ofs >= 0 && ofs < (int64_t)mBufferSize ) { mOffset = ofs; } else if ( dir == CURR && (int64_t)mOffset + ofs >= 0 && (int64_t)mOffset + ofs < (int64_t)mBufferSize ) { mOffset = mOffset + ofs; } else if ( dir == END && (int64_t)mBufferSize + ofs >= 0 && (int64_t)mBufferSize + ofs < (int64_t)mBufferSize ) { mOffset = mBufferSize + ofs; } return mOffset; } std::ios_base::seekdir std_dir = (std::ios_base::seekdir)-1; std_dir = ( dir == BEGIN ) ? std::ios_base::beg : std_dir; std_dir = ( dir == CURR ) ? std::ios_base::cur : std_dir; std_dir = ( dir == END ) ? std::ios_base::end : std_dir; if ( (int)std_dir != -1 ) { #ifdef GE_ANDROID if ( mIsAsset ) { AAsset_seek( (AAsset*)mStream, ofs, (int)std_dir ); } else #endif { mStream->seekg( ofs, std_dir ); } } #ifdef GE_ANDROID if ( mIsAsset ) { return AAsset_seek( (AAsset*)mStream, 0, 1 ); } #endif return mStream->tellg(); }
/** * Get shader program according to type. */ GLuint ShaderProgramFactory::CreateShaderProgram(AAssetManager* assetManager, ShaderType type) { if (mShaderPrograms[type] != INVALID_PROGRAM) { // Already created. return mShaderPrograms[type]; } TRACE_LOG("Create new ShaderProgram."); // Get vertex/fragment shader src file path. const char* vertexShaderSrcFile = getShaderSrcFileName(GL_VERTEX_SHADER, type); const char* fragmentShaderSrcFile = getShaderSrcFileName(GL_FRAGMENT_SHADER, type); if (vertexShaderSrcFile == NULL || fragmentShaderSrcFile == NULL) { LOGE("Unexpected ShaderType."); return INVALID_PROGRAM; } // Vertex. // Open assets. AAsset* vertexSrcAsset = AAssetManager_open( assetManager, vertexShaderSrcFile, AASSET_MODE_RANDOM); GLsizei vertSrcLen = AAsset_getLength(vertexSrcAsset); // Src codes. GLchar vertSrc[vertSrcLen + 1]; // Read. AAsset_seek(vertexSrcAsset, 0, 0); AAsset_read(vertexSrcAsset, vertSrc, vertSrcLen); vertSrc[vertSrcLen] = NULL; // Terminal. // Close assets. AAsset_close(vertexSrcAsset); // Fragment. // Open assets. AAsset* fragmentSrcAsset = AAssetManager_open( assetManager, fragmentShaderSrcFile, AASSET_MODE_RANDOM); GLsizei fragSrcLen = AAsset_getLength(fragmentSrcAsset); // Src codes. GLchar fragSrc[fragSrcLen + 1]; // Read. AAsset_seek(fragmentSrcAsset, 0, 0); AAsset_read(fragmentSrcAsset, fragSrc, fragSrcLen); fragSrc[fragSrcLen] = NULL; // Terminal. // Close assets. AAsset_close(fragmentSrcAsset); // Create program. mShaderPrograms[type] = createProgram(vertSrc, vertSrcLen + 1, fragSrc, fragSrcLen + 1); return mShaderPrograms[type]; }
void FileAccessAndroid::seek_end(int64_t p_position) { ERR_FAIL_COND(!a); AAsset_seek(a,p_position,SEEK_END); pos=len+p_position; }
static void asset_stream_seek( stream_t* stream, int64_t offset, stream_seek_mode_t direction ) { stream_asset_t* asset = (stream_asset_t*)stream; off_t newpos = AAsset_seek( asset->asset, offset, direction ); if( newpos >= 0 ) asset->position = newpos; }
int parse_area_code(AAsset* asset, struct Area* area, long offset, int no7) { int ret = 0; unsigned int index = 0; AAsset_seek(asset, offset, SEEK_SET); AAsset_read(asset, area, sizeof(struct Area)); if (area->desc == 0) { ret = -1; } else if (area->desc == 0xFF) { /** * hlr扩展表索引,指向十个扩展shlr项,其含义是当前号码向后一位以0~9排列的shlr码表 * 0x000186DC -> 文件读取位置:100060 * 50092-当前索引 -> 文件读取位置:50092*6 = 300552 * 有几种情况: * a.是100060读写位置,area结构不对,desc为0。 * b.是100060索引,即100060*6所对应的shlr码表。(对) * c.是index*6+100060文件读取位置,不对。 */ memcpy(&index, area->shlr, 4); ret = parse_area_code(asset, area, index*6+no7*6, no7); } else if (area->desc >= 1 && area->desc <= 5) { ret = 0; } return ret; }
bool BaseFile::seek(size_t v, int origin) { if (flags & ANDROID_ASSET) { return AAsset_seek(((AAsset*)handle), v, origin) == v; } else { return fseek((FILE*)handle, v, origin) == 0; } }
size_t BaseFile::tell() { if (flags & ANDROID_ASSET) { return AAsset_seek(((AAsset*)handle), 0, SEEK_CUR); } else { return ftell((FILE*)handle); } }
bool FileStreamAndroid::rewind() { if (canSeek()) { return AAsset_seek(_asset, 0, SEEK_SET) != -1; } return false; }
int geSysFileTell(void* file){ if(!file){ return 0; } _ge_android_fd* fd = (_ge_android_fd*)file; if(fd->isAsset){ return AAsset_seek((AAsset*)fd->fd, 0, SEEK_CUR); } return geLibcFileTell(fd->fd); }
void Seek(int offset, SeekOrigin origin) { switch (origin) { case SeekOriginBegin: AAsset_seek(asset, offset, SEEK_SET); return; case SeekOriginCurrent: AAsset_seek(asset, offset, SEEK_CUR); return; case SeekOriginEnd: AAsset_seek(asset, offset, SEEK_END); return; } XLI_THROW_STREAM_CANT_SEEK; }
void FileAsset::setSeek(s32 Pos, const EFileSeekTypes PosType) { /* Seek asset to the given position */ s32 Result = AAsset_seek( Asset_, static_cast<off_t>(Pos), static_cast<s32>(PosType) ); if (Result != -1) Pos_ = Result; }
static long apk_seek(struct stream_t* stream, long offset, int mode) { if (stream == NULL) { return -1; } struct io_stream_apk_t* s = (struct io_stream_apk_t*)stream; return AAsset_seek(s->f, offset, mode); }
GAE_File_t* GAE_FILE_setReadPosition(GAE_File_t* file, const unsigned long readPosition, GAE_FILE_READ_STATUS* status) { GAE_PlatformFile_t* platform = (GAE_PlatformFile_t*)file->platformFile; if (file->fileStatus != GAE_FILE_OPEN) { if (0 != status) *status = GAE_FILE_READ_ERROR; return file; } if (file->openMode != GAE_FILE_OPEN_READ) { if (0 != status) *status = GAE_FILE_READ_ERROR; return file; } if (0 == platform->file) { if (0 != status) *status = GAE_FILE_READ_ERROR; return file; } if (file->readPosition < file->fileSize) { file->readPosition = readPosition; if (0 != platform->file) fseek(platform->file, file->readPosition, SEEK_SET); if (0 != platform->asset) AAsset_seek(platform->asset, file->readPosition, SEEK_SET); if (0 != status) *status = GAE_FILE_READ_OK; return file; } else { file->readPosition = file->fileSize; if (0 != platform->file) fseek(platform->file, 0, SEEK_END); if (0 != platform->asset) AAsset_seek(platform->asset, 0, SEEK_END); if (0 != status) *status = GAE_FILE_READ_EOF; return file; } }
Int64 ResourceStream::seek(Int64 position) { if (m_file) { return AAsset_seek(m_file, position, SEEK_SET); } else { return -1; } }
int ReadStringAM(AAsset* asset, char * buffer, int count, int offset) { AAsset_seek(asset, offset, SEEK_SET); int r_count = AAsset_read(asset, buffer, count); if (r_count <= 0) return r_count; for (int i = 0; i < r_count; ++i) { if (buffer[i] == '\n') { buffer[i] = '\0'; AAsset_seek(asset, offset + i + 1, SEEK_SET); return offset + i + 1; } } if (count == r_count && buffer[r_count - 1] != '\n') return 0; return offset + r_count + 1; }
//-------------------------------------------------------------------------- VeChar8 VeAssetIStream::Peek() noexcept { if (RemainingLength() <= 0) { SetError(true); return -1; } VeChar8 c8Res(-1); VE_ASSERT_EQ(AAsset_read(m_pkAsset, &c8Res, 1), 1); AAsset_seek(m_pkAsset, -1, SEEK_CUR); return c8Res; }
void FileAccessAndroid::seek(size_t p_position) { ERR_FAIL_COND(!a); AAsset_seek(a,p_position,SEEK_SET); pos=p_position; if (pos>len) { pos=len; eof=true; } else { eof=false; } }
static int file_seek_android_asset(FILEHANDLE handle, long offset, int whence) { int retval = AAsset_seek((AAsset *) handle, offset, whence); // __android_log_print(ANDROID_LOG_VERBOSE, "org.libsdl.app", "AssetFile: seek=%d", retval); // need to align to original fseek() return value if (retval >= 0) { retval = 0; } return retval; }
/*---------------------------------------------------------------------*//** 読み込む **//*---------------------------------------------------------------------*/ u32 FileAndroidLargeAsset::read(void* buf, u32 size) { DEVTRACE("== {FileAndroidLargeAsset::read} 000: buf=%x, size=%d\n", buf, size); u32 rdsizeTotal = 0; while(true) { // ファイルを開く s32 ccidx = openAssetCached(); if(ccidx == -1) { DEVTRACE("== {FileAndroidLargeAsset::read} 001: failed.\n"); return 0; } ASSERT((0 <= ccidx) && (ccidx < _numCache)); ASSERT(_oaarr[ccidx]._asset != 0L); // 分割ファイル内でのオフセットを求める u32 ofsDivFileTop = divIndexToOffset(_oaarr[ccidx]._dividx); DEVTRACE("== {FileAndroidLargeAsset::read} 001: ofsDivFileTop=%d, asset=%x\n", ofsDivFileTop, _oaarr[ccidx]._asset); u32 ofsInDivFile = _offset - ofsDivFileTop; DEVTRACE("== {FileAndroidLargeAsset::read} 002: ofsInDivFile=%d, _offset=%d\n", ofsInDivFile, _offset); // 読み込み #if defined(_ANDROID) AAsset_seek(_oaarr[ccidx]._asset, ofsInDivFile, SEEK_SET); DEVTRACE("== {FileAndroidLargeAsset::read} 003: buf=%x, size=%d\n", buf, size); u32 rdsize = AAsset_read(_oaarr[ccidx]._asset, buf, size); #else u32 rdsize = size; #endif // オフセット更新 _offset += rdsize; rdsizeTotal += rdsize; DEVTRACE("== {FileAndroidLargeAsset::read} 004: rdsize=%d, _offset=%d\n", rdsize, _offset); // 次へ if(rdsize < size) { buf = (u8*)buf + rdsize; size -= rdsize; } else { break; } } DEVTRACE("== {FileAndroidLargeAsset::read} 999: _offset=%d\n", _offset); return rdsizeTotal; }
static orxS64 orxFASTCALL orxResource_APK_Seek(orxHANDLE _hResource, orxS64 _s64Offset, orxSEEK_OFFSET_WHENCE _eWhence) { AAsset *poAsset; orxS64 s64Result; /* Gets asset */ poAsset = (AAsset *)_hResource; /* Updates result */ s64Result = (orxS64)AAsset_seek(poAsset, (off_t)_s64Offset, _eWhence); /* Done! */ return s64Result; }
int FileInput::seek(size_t count, SeekDirection direction) { if(!m_asset) return -1; switch(direction) { case SeekDirection_Begin: { return AAsset_seek(m_asset, count, SEEK_SET); }break; case SeekDirection_Current: { return AAsset_seek(m_asset, count, SEEK_CUR); }break; case SeekDirection_End: { return AAsset_seek(m_asset, count, SEEK_END); }break; }; return -1; }
int geSysFileSeek(void* file, int offset, int origin){ if(!file){ return -1; } int ret = 0; _ge_android_fd* fd = (_ge_android_fd*)file; if(fd->isAsset){ ret = AAsset_seek((AAsset*)fd->fd, offset, origin); }else{ geLibcFileSeek(fd->fd, offset, origin); ret = geLibcFileTell(fd->fd); } return ret; }
uint32_t AssetFileCache::readDataFromPage ( char* buf, uint32_t size ) { uint32_t maxFromPage = ( pageSize - ( pos % pageSize ) ); uint32_t bytesToRead; if ( size > maxFromPage ) { bytesToRead = maxFromPage; } else { bytesToRead = size; } uint32_t pageNbr = posToPageNbr ( pos ); Page *page = pages[pageNbr]; page->lastAccess = time; // Check if page is already cached if ( page->pageData ) { // LOGI ( "USING CACHE asset = %p, data = %p", asset, page->pageData->data ); } else { // Get a data block and cache the data PageData *data = getPage(); AAsset_seek ( asset, pageNbr * pageSize, SEEK_SET ); AAsset_read ( asset, data->data, pageSize ); // LOGI ( "CACHE MISS asset = %p, Cached data at %p", asset, data->data ); page->pageData = data; //printBytes( data->data, 50 ); } char * dataSource = page->pageData->data + ( pos % pageSize ); //LOGI("buf = %p, dataSource = %p, bytes = %d", buf, dataSource, bytesToRead); memcpy ( buf, dataSource, bytesToRead ); // printBytes( buf, 50 ); pos += bytesToRead; return bytesToRead; }
void File::Rewind() { if ( mType == BUFFER ) { mOffset = 0; } else if ( mType == FILE ) { #ifdef GE_ANDROID if ( mIsAsset ) { AAsset_seek( (AAsset*)mStream, 0, 0 ); } else #endif { mStream->seekg( 0, std::ios_base::beg ); } } }
bool AssetInputStream::seek(int32 offset, int whence) { int res = AAsset_seek(_asset, offset, whence); if (res == -1) { return false; } if (whence == SEEK_CUR) { _pos += offset; } else if (whence == SEEK_SET) { _pos = offset; } else if (whence == SEEK_END) { _pos = _len + offset; } assert(_pos <= _len); _eos = false; return true; }
//-------------------------------------------------------------------------- void VeAssetIStream::Restart() noexcept { AAsset_seek(m_pkAsset, 0, SEEK_SET); }
//-------------------------------------------------------------------------- void* VeAssetIStream::Skip(VeSizeT stBytes) noexcept { stBytes = VE_MIN(stBytes, RemainingLength()); AAsset_seek(m_pkAsset, stBytes, SEEK_CUR); return nullptr; }
//-------------------------------------------------------------------------- VeResult VeAssetIStream::Seek(VePtrDiff pdOffset, VeWhence eWhence) noexcept { return VE_SUCCEEDED(AAsset_seek(m_pkAsset, pdOffset, eWhence)) ? VE_S_OK : VE_E_FAIL; }
static fpos_t android_seek(void* cookie, fpos_t offset, int whence) { return AAsset_seek((AAsset*)cookie, offset, whence); }