static bool wava_readChunkHeader (TFB_WaveSoundDecoder* wava, WAVChunkHdr_Struct* chunk) { if (!uio_fread (&chunk->Id, 4, 1, wava->fp) || !uio_fread (&chunk->Size, 4, 1, wava->fp)) return false; chunk->Id = UQM_SwapLE32 (chunk->Id); chunk->Size = UQM_SwapLE32 (chunk->Size); return true; }
static bool wava_readFileHeader (TFB_WaveSoundDecoder* wava, WAVFileHdr_Struct* hdr) { if (!uio_fread (&hdr->Id, 4, 1, wava->fp) || !uio_fread (&hdr->Size, 4, 1, wava->fp) || !uio_fread (&hdr->Type, 4, 1, wava->fp)) { wava->last_error = errno; return false; } hdr->Id = UQM_SwapLE32 (hdr->Id); hdr->Size = UQM_SwapLE32 (hdr->Size); hdr->Type = UQM_SwapLE32 (hdr->Type); return true; }
static bool read_le_32 (uio_Stream *fp, uint32 *v) { if (!uio_fread (v, sizeof(*v), 1, fp)) return false; *v = UQM_SwapLE32 (*v); return true; }
size_t ReadResFile (void *lpBuf, size_t size, size_t count, uio_Stream *fp) { int retval; retval = uio_fread (lpBuf, size, count, fp); return (retval); }
static int wava_Decode (THIS_PTR, void* buf, sint32 bufsize) { TFB_WaveSoundDecoder* wava = (TFB_WaveSoundDecoder*) This; uint32 dec_pcm; dec_pcm = bufsize / wava->FmtHdr.BlockAlign; if (dec_pcm > wava->max_pcm - wava->cur_pcm) dec_pcm = wava->max_pcm - wava->cur_pcm; dec_pcm = uio_fread (buf, wava->FmtHdr.BlockAlign, dec_pcm, wava->fp); wava->cur_pcm += dec_pcm; return dec_pcm * wava->FmtHdr.BlockAlign; }
int sdluio_read (SDL_RWops *context, void *ptr, int size, int maxnum) { size_t numRead; numRead = uio_fread (ptr, (size_t) size, (size_t) maxnum, (uio_Stream *) context->hidden.unknown.data1); if (numRead == 0 && uio_ferror ((uio_Stream *) context->hidden.unknown.data1)) { SDL_SetError ("Error reading from uio_Stream: %s", strerror(errno)); return 0; } return (int) numRead; }
static bool wava_readFormatHeader (TFB_WaveSoundDecoder* wava, WAVFmtHdr_Struct* fmt) { if (!uio_fread (&fmt->Format, 2, 1, wava->fp) || !uio_fread (&fmt->Channels, 2, 1, wava->fp) || !uio_fread (&fmt->SamplesPerSec, 4, 1, wava->fp) || !uio_fread (&fmt->BytesPerSec, 4, 1, wava->fp) || !uio_fread (&fmt->BlockAlign, 2, 1, wava->fp) || !uio_fread (&fmt->BitsPerSample, 2, 1, wava->fp)) return false; fmt->Format = UQM_SwapLE16 (fmt->Format); fmt->Channels = UQM_SwapLE16 (fmt->Channels); fmt->SamplesPerSec = UQM_SwapLE32 (fmt->SamplesPerSec); fmt->BytesPerSec = UQM_SwapLE32 (fmt->BytesPerSec); fmt->BlockAlign = UQM_SwapLE16 (fmt->BlockAlign); fmt->BitsPerSample = UQM_SwapLE16 (fmt->BitsPerSample); return true; }
void * _GetCelData (uio_Stream *fp, DWORD length) { int cel_total, cel_index, n; DWORD opos; char CurrentLine[1024], filename[PATH_MAX]; TFB_Canvas *img; AniData *ani; DRAWABLE Drawable; uio_MountHandle *aniMount = 0; uio_DirHandle *aniDir = 0; uio_Stream *aniFile = 0; opos = uio_ftell (fp); { char *s1, *s2; char aniDirName[PATH_MAX]; const char *aniFileName; uint8 buf[4] = { 0, 0, 0, 0 }; uint32 header; if (_cur_resfile_name == 0 || (((s2 = 0), (s1 = strrchr (_cur_resfile_name, '/')) == 0) && (s2 = strrchr (_cur_resfile_name, '\\')) == 0)) { n = 0; } else { if (s2 > s1) s1 = s2; n = s1 - _cur_resfile_name + 1; } uio_fread(buf, 4, 1, fp); header = buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24); if (_cur_resfile_name && header == 0x04034b50) { // zipped ani file if (n) { strncpy (aniDirName, _cur_resfile_name, n - 1); aniDirName[n - 1] = 0; aniFileName = _cur_resfile_name + n; } else { strcpy(aniDirName, "."); aniFileName = _cur_resfile_name; } aniDir = uio_openDir (repository, aniDirName, 0); aniMount = uio_mountDir (repository, aniDirName, uio_FSTYPE_ZIP, aniDir, aniFileName, "/", autoMount, uio_MOUNT_RDONLY | uio_MOUNT_TOP, NULL); aniFile = uio_fopen (aniDir, aniFileName, "r"); opos = 0; n = 0; } else { // unpacked ani file strncpy (filename, _cur_resfile_name, n); aniFile = fp; aniDir = contentDir; } } cel_total = 0; uio_fseek (aniFile, opos, SEEK_SET); while (uio_fgets (CurrentLine, sizeof (CurrentLine), aniFile)) { ++cel_total; } img = HMalloc (sizeof (TFB_Canvas) * cel_total); ani = HMalloc (sizeof (AniData) * cel_total); if (!img || !ani) { log_add (log_Warning, "Couldn't allocate space for '%s'", _cur_resfile_name); if (aniMount) { uio_fclose(aniFile); uio_closeDir(aniDir); uio_unmountDir(aniMount); } HFree (img); HFree (ani); return NULL; } cel_index = 0; uio_fseek (aniFile, opos, SEEK_SET); while (uio_fgets (CurrentLine, sizeof (CurrentLine), aniFile) && cel_index < cel_total) { sscanf (CurrentLine, "%s %d %d %d %d", &filename[n], &ani[cel_index].transparent_color, &ani[cel_index].colormap_index, &ani[cel_index].hotspot_x, &ani[cel_index].hotspot_y); img[cel_index] = TFB_DrawCanvas_LoadFromFile (aniDir, filename); if (img[cel_index] == NULL) { const char *err; err = TFB_DrawCanvas_GetError (); log_add (log_Warning, "_GetCelData: Unable to load image!"); if (err != NULL) log_add (log_Warning, "Gfx Driver reports: %s", err); } else { ++cel_index; } if ((int)uio_ftell (aniFile) - (int)opos >= (int)length) break; } Drawable = NULL; if (cel_index && (Drawable = AllocDrawable (cel_index))) { if (!Drawable) { while (cel_index--) TFB_DrawCanvas_Delete (img[cel_index]); HFree (Drawable); Drawable = NULL; } else { FRAME FramePtr; Drawable->Flags = WANT_PIXMAP; Drawable->MaxIndex = cel_index - 1; FramePtr = &Drawable->Frame[cel_index]; while (--FramePtr, cel_index--) process_image (FramePtr, img, ani, cel_index); } } if (Drawable == NULL) log_add (log_Warning, "Couldn't get cel data for '%s'", _cur_resfile_name); if (aniMount) { uio_fclose(aniFile); uio_closeDir(aniDir); uio_unmountDir(aniMount); } HFree (img); HFree (ani); return Drawable; }
static BOOL moda_uioReader_Read (MREADER* reader, void* ptr, size_t size) { return uio_fread (ptr, size, 1, ((MUIOREADER*)reader)->file); }