MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / SlurpFile

Function SlurpFile

engine/Poseidon/Graphics/Textures/JpgImport.cpp:55–79  ·  view source on GitHub ↗

Read a whole file. Prefer the engine's FileServer when available (so PBO / search-path resolution works); fall back to std::ifstream in unit-test contexts where the server isn't initialised.

Source from the content-addressed store, hash-verified

53// search-path resolution works); fall back to std::ifstream in unit-test
54// contexts where the server isn't initialised.
55bool SlurpFile(const char* name, std::vector<uint8_t>& out)
56{
57 if (GFileServer)
58 {
59 QIFStream in;
60 GFileServer->Open(in, name);
61 if (!in.fail() && in.rest() > 0)
62 {
63 int rest = in.rest();
64 const auto* bytes = reinterpret_cast<const uint8_t*>(in.act());
65 out.assign(bytes, bytes + rest);
66 return true;
67 }
68 }
69 std::ifstream file(name, std::ios::binary | std::ios::ate);
70 if (!file)
71 return false;
72 auto size = file.tellg();
73 if (size <= 0)
74 return false;
75 out.resize(static_cast<size_t>(size));
76 file.seekg(0);
77 file.read(reinterpret_cast<char*>(out.data()), size);
78 return file.good();
79}
80
81// Box-average color of an RGBA8 buffer. Used as ITextureSource::GetAverageColor().
82PackedColor ComputeAverage(const uint8_t* rgba, int w, int h)

Callers 1

InitMethod · 0.85

Calls 8

restMethod · 0.80
actMethod · 0.80
tellgMethod · 0.80
seekgMethod · 0.80
OpenMethod · 0.45
failMethod · 0.45
resizeMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected