try to decode the image header as soon as some data is available
This commit is contained in:
@@ -179,9 +179,8 @@ bool Asset::open_url(const std::string& url, std::function<bool(float)> progress
|
|||||||
close();
|
close();
|
||||||
LOG("download %s", url.c_str());
|
LOG("download %s", url.c_str());
|
||||||
m_current_url = url;
|
m_current_url = url;
|
||||||
std::vector<uint8_t> data;
|
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &data);
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &tmp_data);
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_data_handler_asset);
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_data_handler_asset);
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
||||||
@@ -200,9 +199,10 @@ bool Asset::open_url(const std::string& url, std::function<bool(float)> progress
|
|||||||
{
|
{
|
||||||
if (m_data)
|
if (m_data)
|
||||||
delete m_data;
|
delete m_data;
|
||||||
m_data = new uint8_t[data.size()];
|
m_data = new uint8_t[tmp_data.size()];
|
||||||
std::copy(data.begin(), data.end(), m_data);
|
std::copy(tmp_data.begin(), tmp_data.end(), m_data);
|
||||||
m_len = data.size();
|
m_len = tmp_data.size();
|
||||||
|
tmp_data.clear();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ public:
|
|||||||
bool m_stop_async = false;
|
bool m_stop_async = false;
|
||||||
std::function<bool(float)> on_progress;
|
std::function<bool(float)> on_progress;
|
||||||
std::future<bool> remote_future;
|
std::future<bool> remote_future;
|
||||||
|
std::vector<uint8_t> tmp_data;
|
||||||
|
|
||||||
std::string m_current_path;
|
std::string m_current_path;
|
||||||
std::string m_current_url;
|
std::string m_current_url;
|
||||||
|
|||||||
@@ -135,9 +135,18 @@ bool NodeImage::set_image(const std::string& path)
|
|||||||
|
|
||||||
void NodeImage::load_url(const std::string& url)
|
void NodeImage::load_url(const std::string& url)
|
||||||
{
|
{
|
||||||
|
m_remote_header_decoded = false;
|
||||||
m_remote_asset = std::make_shared<Asset>();
|
m_remote_asset = std::make_shared<Asset>();
|
||||||
m_remote_asset->open_url_async(url,
|
m_remote_asset->open_url_async(url,
|
||||||
[this] (float progress) -> bool {
|
[this] (float progress) -> bool {
|
||||||
|
int w, h, c;
|
||||||
|
if (!m_remote_header_decoded &&
|
||||||
|
stbi_info_from_memory(m_remote_asset->tmp_data.data(), m_remote_asset->tmp_data.size(), &w, &h, &c))
|
||||||
|
{
|
||||||
|
if (m_autosize)
|
||||||
|
SetAspectRatio((float)w / (float)h);
|
||||||
|
m_remote_header_decoded = true;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
[this] (bool success) {
|
[this] (bool success) {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ public:
|
|||||||
uint16_t m_tex_id;
|
uint16_t m_tex_id;
|
||||||
std::shared_ptr<Asset> m_remote_asset;
|
std::shared_ptr<Asset> m_remote_asset;
|
||||||
std::shared_ptr<Texture2D> m_remote_texture;
|
std::shared_ptr<Texture2D> m_remote_texture;
|
||||||
|
bool m_remote_header_decoded = false;
|
||||||
static void static_init();
|
static void static_init();
|
||||||
virtual Node* clone_instantiate() const override;
|
virtual Node* clone_instantiate() const override;
|
||||||
virtual void clone_copy(Node* dest) const override;
|
virtual void clone_copy(Node* dest) const override;
|
||||||
|
|||||||
Reference in New Issue
Block a user