Skip to content

Commit 03463fd

Browse files
committed
Fix error handling, add extension shortcut
1 parent 4839124 commit 03463fd

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

engine/core/core_image.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ image_c* image_c::LoaderForFile(IConsole* conHnd, std::filesystem::path const& f
108108
}
109109
if (fileName.extension() == ".dds")
110110
return new dds_c(conHnd);
111+
if (fileName.extension() == ".webp")
112+
return new webp_c(conHnd);
111113

112114
// Attempt to detect image file type from first 4 bytes of file
113115
byte dat[4];
@@ -505,12 +507,15 @@ bool webp_c::Load(std::filesystem::path const& fileName, std::optional<size_call
505507
int width;
506508
int height;
507509

508-
WebPGetInfo(fileData.data(), fileData.size(), &width, &height);
510+
bool valid = WebPGetInfo(fileData.data(), fileData.size(), &width, &height);
511+
if (!valid)
512+
return true;
509513

510514
auto data = WebPDecodeRGBA(fileData.data(), fileData.size(), &width, &height);
511515
bool success = CopyRaw(IMGTYPE_RGBA, width, height, data);
516+
WebPFree(data);
512517

513-
return success;
518+
return !success;
514519
}
515520

516521
bool webp_c::Save(std::filesystem::path const& fileName)

0 commit comments

Comments
 (0)