@@ -15,41 +15,75 @@ namespace raylib {
1515 */
1616class Image : public ::Image {
1717 public:
18+ Image (void * data = nullptr ,
19+ int width = 0 ,
20+ int height = 0 ,
21+ int mipmaps = 0 ,
22+ int format = 0 ) : ::Image{data, width, height, mipmaps, format} {
23+ // Nothing.
24+ }
25+
1826 Image (const ::Image& image) {
1927 set (image);
2028 }
2129
30+ /* *
31+ * Load an image from the given file.
32+ *
33+ * @throws raylib::RaylibException Thrown if the image failed to load from the file.
34+ *
35+ * @see Load()
36+ */
2237 Image (const std::string& fileName) {
23- Load (fileName);
24- if (!IsReady ()) {
38+ if (!Load (fileName)) {
2539 throw RaylibException (TextFormat (" Failed to load Image from file: %s" , fileName.c_str ()));
2640 }
2741 }
2842
43+ /* *
44+ * Load a raw image from the given file, with the provided width, height, and formats.
45+ *
46+ * @throws raylib::RaylibException Thrown if the image failed to load from the file.
47+ *
48+ * @see LoadRaw()
49+ */
2950 Image (const std::string& fileName, int width, int height, int format, int headerSize) {
30- LoadRaw (fileName, width, height, format, headerSize);
31- if (!IsReady ()) {
51+ if (!Load (fileName, width, height, format, headerSize)) {
3252 throw RaylibException (TextFormat (" Failed to load Image from file: %s" , fileName.c_str ()));
3353 }
3454 }
3555
56+ /* *
57+ * Load an animation image from the given file.
58+ *
59+ * @throws raylib::RaylibException Thrown if the image failed to load from the file.
60+ *
61+ * @see LoadAnim()
62+ */
3663 Image (const std::string& fileName, int * frames) {
37- LoadAnim (fileName, frames);
38- if (!IsReady ()) {
64+ if (!Load (fileName, frames)) {
3965 throw RaylibException (TextFormat (" Failed to load Image from animation: %s" , fileName.c_str ()));
4066 }
4167 }
4268
69+ /* *
70+ * Load an image from the given file.
71+ *
72+ * @throws raylib::RaylibException Thrown if the image failed to load from the file.
73+ */
4374 Image (const std::string& fileType, const unsigned char * fileData, int dataSize) {
44- LoadFromMemory (fileType, fileData, dataSize);
45- if (!IsReady ()) {
75+ if (!Load (fileType, fileData, dataSize)) {
4676 throw RaylibException (" Failed to load Image from memory" );
4777 }
4878 }
4979
80+ /* *
81+ * Load an image from the given file.
82+ *
83+ * @throws raylib::RaylibException Thrown if the image failed to load from the file.
84+ */
5085 Image (const ::Texture2D& texture) {
51- set (::LoadImageFromTexture (texture));
52- if (!IsReady ()) {
86+ if (!Load (texture)) {
5387 throw RaylibException (" Failed to load Image from Texture" );
5488 }
5589 }
@@ -189,32 +223,46 @@ class Image : public ::Image {
189223 /* *
190224 * Load image from file into CPU memory (RAM)
191225 */
192- void Load (const std::string& fileName) {
226+ bool Load (const std::string& fileName) {
193227 set (::LoadImage (fileName.c_str ()));
228+ return IsReady ();
194229 }
195230
196231 /* *
197232 * Load image from RAW file data.
198233 */
199- void LoadRaw (const std::string& fileName, int width, int height, int format, int headerSize) {
234+ bool Load (const std::string& fileName, int width, int height, int format, int headerSize) {
200235 set (::LoadImageRaw (fileName.c_str (), width, height, format, headerSize));
236+ return IsReady ();
201237 }
202238
203239 /* *
204240 * Load image sequence from file (frames appended to image.data).
205241 */
206- void LoadAnim (const std::string& fileName, int * frames) {
242+ bool Load (const std::string& fileName, int * frames) {
207243 set (::LoadImageAnim (fileName.c_str (), frames));
244+ return IsReady ();
208245 }
209246
210247 /* *
211248 * Load image from memory buffer, fileType refers to extension: i.e. "png".
212249 */
213- void LoadFromMemory (
250+ bool Load (
214251 const std::string& fileType,
215252 const unsigned char *fileData,
216253 int dataSize) {
217254 set (::LoadImageFromMemory (fileType.c_str (), fileData, dataSize));
255+ return IsReady ();
256+ }
257+
258+ /* *
259+ * Load an image from the given file.
260+ *
261+ * @return True or false depending on whether or not the image was loaded from the texture.
262+ */
263+ bool Load (const ::Texture2D& texture) {
264+ set (::LoadImageFromTexture (texture));
265+ return IsReady ();
218266 }
219267
220268 /* *
0 commit comments