Пример #1
0
Surface *Surface::Load(const OSChar *inFilename)
{
   FILE *file = OpenRead(inFilename);
   if (!file)
   {
      #ifdef ANDROID
      ByteArray bytes = AndroidGetAssetBytes(inFilename);
      if (bytes.Ok())
      {
         Surface *result = LoadFromBytes(bytes.Bytes(), bytes.Size());
         return result;
      }

      #endif
      return 0;
   }

   Surface *result = TryJPEG(file,0,0);
   if (!result)
   {
      rewind(file);
      result = TryPNG(file,0,0);
   }

   fclose(file);
   return result;
}
Пример #2
0
 Sound *Sound::Create(const std::string &inFilename,bool inForceMusic)
 {
    //Always check if openal is intitialized
    if (!OpenALInit())
       return 0;
    
    //Return a reference
    OpenALSound *sound;
    
    #ifdef ANDROID
    if (!inForceMusic)
    {
       ByteArray bytes = AndroidGetAssetBytes(inFilename.c_str());
       sound = new OpenALSound((float*)bytes.Bytes(), bytes.Size());
    }
    else
    {
       sound = new OpenALSound(inFilename, inForceMusic);
    }
    #else
    sound = new OpenALSound(inFilename, inForceMusic);
    #endif
    
    if (sound->ok ())
       return sound;
    else
       return 0;
 }
Пример #3
0
static int sGetFile(const char *inFilename, unsigned char **outBuf)
{
   #ifdef ANDROID
   ByteArray bytes = AndroidGetAssetBytes(inFilename);
   #else
   ByteArray bytes = ByteArray::FromFile(inFilename);
   #endif
   
   ELOG("Loaded cert %s %d bytes.", inFilename, bytes.Size());
   if (bytes.Size()>0)
   {
      *outBuf = (unsigned char *)malloc(bytes.Size());
      memcpy(*outBuf,bytes.Bytes(),bytes.Size());
      return bytes.Size();
   }

   return -1;
}
Пример #4
0
Surface *Surface::Load(const OSChar *inFilename)
{
   FILE *file = OpenRead(inFilename);
   if (!file)
   {
      #ifdef ANDROID
      ByteArray bytes = AndroidGetAssetBytes(inFilename);
      if (bytes.Ok())
      {
         Surface *result = LoadFromBytes(bytes.Bytes(), bytes.Size());
         return result;
      }

      #endif
      return 0;
   }

   int len = 0;
   while(inFilename[len])
      len++;

   bool jpegFirst = false;
   bool pngFirst = false;
   if (len>4)
   {
      // Jpeg/jpg
      if (inFilename[len-4]=='j' || inFilename[len-4]=='J' || 
             inFilename[len-3]=='j' || inFilename[len-4]=='J' )
         jpegFirst = true;
      else if (inFilename[len-3]=='p' || inFilename[len-3]=='P' )
         pngFirst = true;
   }
   Surface *result = 0;

   if (jpegFirst)
   {
      result = TryJPEG(file,0,0);
      if (!result)
      {
         rewind(file);
         result = TryPNG(file,0,0);
      }
   }
   else if (pngFirst)
   {
      result = TryPNG(file,0,0);
      if (!result)
      {
         rewind(file);
         result = TryJPEG(file,0,0);
      }
   }
   else
   {
      uint8 first = 0;
      fread(&first,1,1,file);
      if (first==0xff)
      {
         rewind(file);
         result = TryJPEG(file,0,0);
      }
      else if (first==0x89)
      {
         rewind(file);
         result = TryPNG(file,0,0);
      }
   }

   fclose(file);
   return result;
}