If I create a Halide::Buffer by constructing it with a pointer from an STB_Image function call like so:
inline Halide::Buffer<uint8_t> LoadFromFile(const char* filename)
{
int w, h, d;
unsigned char* image_data = stbi_load(filename, &w, &h, &d, 0);
Halide::Buffer buff = Halide::Buffer(image_data, std::vector<int>{w, h, d});
return buff;
}
Who is responsible for freeing the underlying buffer? I assumed it would be me since I allocated the memory so I should free it. If I am responsible, where should it be done?
Thanks
Whenever you pass a raw pointer to the
Halide::Bufferconstructor, it does not take ownership. It's unfortunate that STBI doesn't include a way to load an image to a pre-allocated buffer.If the Halide image io library meets your needs, you might find it more convenient.
Now
inputowns the image data and will be freed when the destructor is called. The Halide image io library supports the following formats:.matfiles