Changeset 2381
- Timestamp:
- Feb 8, 2013, 3:05:28 AM (10 years ago)
- Location:
- trunk/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/image/codec/gdiplus-image.cpp
r2241 r2381 41 41 42 42 private: 43 Gdiplus::Bitmap * bitmap;44 Gdiplus::BitmapData bdata;43 Gdiplus::Bitmap *m_bitmap; 44 Gdiplus::BitmapData m_bdata; 45 45 }; 46 46 … … 63 63 } 64 64 65 String fullpath = String(System::GetDataDir()) + String(path); 66 size_t len; 67 len = mbstowcs(NULL, &fullpath[0], 0); 68 wchar_t *wpath = new wchar_t[len + 1]; 69 if (mbstowcs(wpath, &fullpath[0], len + 1) == (size_t)-1) 65 Array<String> pathlist = System::GetPathList(path); 66 m_bitmap = NULL; 67 for (int i = 0; i < pathlist.Count(); ++i) 70 68 { 69 size_t len; 70 len = mbstowcs(NULL, pathlist[i].C(), 0); 71 wchar_t *wpath = new wchar_t[len + 1]; 72 if (mbstowcs(wpath, pathlist[i].C(), len + 1) == (size_t)-1) 73 { 71 74 #if !LOL_RELEASE 72 Log::Error("invalid image name %s\n", &fullpath[0]);75 Log::Error("invalid image name %s\n", pathlist[i].C()); 73 76 #endif 77 delete[] wpath; 78 continue; 79 } 80 81 status = Gdiplus::Ok; 82 m_bitmap = Gdiplus::Bitmap::FromFile(wpath, 0); 83 84 if (m_bitmap) 85 { 86 status = m_bitmap->GetLastStatus(); 87 if (status != Gdiplus::Ok) 88 { 89 #if !LOL_RELEASE 90 if (status != Gdiplus::InvalidParameter) 91 Log::Error("error %d loading %s\n", 92 status, pathlist[i].C()); 93 #endif 94 delete m_bitmap; 95 m_bitmap = NULL; 96 } 97 } 98 74 99 delete[] wpath; 75 return false; 100 if (m_bitmap) 101 break; 76 102 } 77 103 78 bitmap = NULL; 79 status = Gdiplus::Ok; 80 bitmap = Gdiplus::Bitmap::FromFile(wpath, 0); 81 if (bitmap) 82 { 83 status = bitmap->GetLastStatus(); 84 if (status != Gdiplus::Ok) 85 { 86 #if !LOL_RELEASE 87 if (status != Gdiplus::InvalidParameter) 88 Log::Error("error %d loading %s\n", 89 status, &fullpath[0]); 90 #endif 91 delete bitmap; 92 bitmap = NULL; 93 } 94 } 95 96 delete[] wpath; 97 if (!bitmap) 104 if (!m_bitmap) 98 105 { 99 106 #if !LOL_RELEASE … … 103 110 } 104 111 105 size = ivec2( bitmap->GetWidth(),bitmap->GetHeight());112 size = ivec2(m_bitmap->GetWidth(), m_bitmap->GetHeight()); 106 113 format = Image::FORMAT_RGBA; 107 114 108 115 Gdiplus::Rect rect(0, 0, size.x, size.y); 109 if( bitmap->LockBits(&rect, Gdiplus::ImageLockModeRead,110 PixelFormat32bppARGB, &bdata) != Gdiplus::Ok)116 if(m_bitmap->LockBits(&rect, Gdiplus::ImageLockModeRead, 117 PixelFormat32bppARGB, &m_bdata) != Gdiplus::Ok) 111 118 { 112 119 #if !LOL_RELEASE 113 120 Log::Error("could not lock bits in %s\n", path); 114 121 #endif 115 delete bitmap;122 delete m_bitmap; 116 123 return false; 117 124 } … … 120 127 * know about ARGB, only RGBA. So we swap bytes. We could also fix 121 128 * this in the shader. */ 122 uint8_t *p = static_cast<uint8_t *>( bdata.Scan0);129 uint8_t *p = static_cast<uint8_t *>(m_bdata.Scan0); 123 130 for (int y = 0; y < size.y; y++) 124 131 for (int x = 0; x < size.x; x++) … … 135 142 bool GdiPlusImageData::Close() 136 143 { 137 bitmap->UnlockBits(&bdata);138 delete bitmap;144 m_bitmap->UnlockBits(&m_bdata); 145 delete m_bitmap; 139 146 140 147 return true; … … 143 150 void * GdiPlusImageData::GetData() const 144 151 { 145 return bdata.Scan0;152 return m_bdata.Scan0; 146 153 } 147 154 -
trunk/src/image/codec/sdl-image.cpp
r2237 r2381 58 58 bool SdlImageData::Open(char const *path) 59 59 { 60 String fullpath = String(System::GetDataDir()) + String(path); 61 m_img = IMG_Load(&fullpath[0]); 60 Array<String> pathlist = System::GetPathList(path); 61 for (int i = 0; i < pathlist.Count(); i++) 62 { 63 m_img = IMG_Load(pathlist[i].C()); 64 if (m_img) 65 break; 66 } 67 62 68 if (!m_img) 63 69 { 64 70 #if !LOL_RELEASE 65 Log::Error("could not load %s\n", &fullpath[0]);71 Log::Error("could not load image %s\n", path); 66 72 #endif 67 73 return false; -
trunk/src/lol/sys/init.h
r2358 r2381 47 47 String const &solutiondir = LOL_CONFIG_SOLUTIONDIR); 48 48 49 extern void SetDataDir(String const &dir);50 extern String const &GetDataDir();49 extern void AddDataDir(String const &dir); 50 extern Array<String> GetPathList(String const &file); 51 51 52 52 } /* namespace System */ -
trunk/src/sample.cpp
r2237 r2381 64 64 65 65 #if defined USE_SDL_MIXER 66 String fullpath = String(System::GetDataDir()) + String(path); 67 data->chunk = Mix_LoadWAV(&fullpath[0]); 66 Array<String> pathlist = System::GetPathList(path); 67 for (int i = 0; i < pathlist.Count(); ++i) 68 { 69 data->chunk = Mix_LoadWAV(pathlist[0].C()); 70 if (data->chunk) 71 break; 72 } 68 73 if (!data->chunk) 69 74 { 70 75 #if !LOL_RELEASE 71 Log::Error("could not load %s\n", &fullpath[0]);76 Log::Error("could not load sample %s\n", path); 72 77 #endif 73 78 SDL_Quit(); -
trunk/src/sys/init.cpp
r2358 r2381 35 35 # define SEPARATOR '/' 36 36 #endif 37 38 static Array<String> data_dir; 37 39 38 40 void Init(int argc, char *argv[], … … 78 80 if (rootdir.Last() != SEPARATOR) 79 81 rootdir += SEPARATOR; 80 SetDataDir(&rootdir[0]);82 AddDataDir(rootdir); 81 83 got_rootdir = true; 82 84 } … … 88 90 if (!got_rootdir) 89 91 { 90 SetDataDir(&binarydir[0]);92 AddDataDir(binarydir); 91 93 got_rootdir = true; 92 94 } 93 95 94 Log::Debug("binary dir: %s\n", &binarydir[0]); 95 Log::Debug("root dir: %s\n", &GetDataDir()[0]); 96 Log::Debug("binary dir: %s\n", binarydir.C()); 97 for (int i = 0; i < data_dir.Count(); ++i) 98 Log::Debug("data dir %d/%d: %s\n", i + 1, data_dir.Count(), 99 data_dir[i].C()); 96 100 } 97 101 … … 100 104 */ 101 105 102 String data_dir = ""; 103 104 void SetDataDir(String const &dir) 106 void AddDataDir(String const &dir) 105 107 { 106 data_dir =dir;108 data_dir << dir; 107 109 } 108 110 109 String const &GetDataDir()111 Array<String> GetPathList(String const &file) 110 112 { 111 return data_dir; 113 Array<String> ret; 114 115 for (int i = 0; i < data_dir.Count(); ++i) 116 ret << data_dir[0] + file; 117 118 if (ret.Count() == 0) 119 ret << file; 120 121 return ret; 112 122 } 113 123
Note: See TracChangeset
for help on using the changeset viewer.