Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 26 additions & 29 deletions src/OpenStreetMap-esp32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,45 +454,42 @@ bool OpenStreetMap::fetchTile(CachedTile &tile, uint32_t x, uint32_t y, uint8_t
return false;
}

PNG *png = getPNGForCore();
if (!png)
{
result = "PNG decoder unavailable";
return false;
}

char url[64];
snprintf(url, sizeof(url), "https://tile.openstreetmap.org/%u/%u/%u.png",
static_cast<unsigned int>(zoom),
static_cast<unsigned int>(x),
static_cast<unsigned int>(y));

int decodeResult;
{
auto buffer = urlToBuffer(url, result);
if (!buffer)
return false;

PNG *png = getPNGForCore();
if (!png)
{
result = "PNG decoder unavailable";
return false;
}

const int16_t rc = png->openRAM(buffer.value()->get(), buffer.value()->size(), PNGDraw);
if (rc != PNG_SUCCESS)
{
result = "PNG Decoder Error: " + String(rc);
return false;
}
const auto buffer = urlToBuffer(url, result);
if (!buffer)
return false;

if (png->getWidth() != OSM_TILESIZE || png->getHeight() != OSM_TILESIZE)
{
result = "Unexpected tile size: w=" + String(png->getWidth()) + " h=" + String(png->getHeight());
return false;
}
const int16_t rc = png->openRAM(buffer.value()->get(), buffer.value()->size(), PNGDraw);
if (rc != PNG_SUCCESS)
{
result = "PNG Decoder Error: " + String(rc);
return false;
}

currentInstance = this;
currentTileBuffer = tile.buffer;
decodeResult = png->decode(0, PNG_FAST_PALETTE);
currentTileBuffer = nullptr;
currentInstance = nullptr;
if (png->getWidth() != OSM_TILESIZE || png->getHeight() != OSM_TILESIZE)
{
result = "Unexpected tile size: w=" + String(png->getWidth()) + " h=" + String(png->getHeight());
return false;
}

currentInstance = this;
currentTileBuffer = tile.buffer;
const int decodeResult = png->decode(0, PNG_FAST_PALETTE);
currentTileBuffer = nullptr;
currentInstance = nullptr;

if (decodeResult != PNG_SUCCESS)
{
result = "Decoding " + String(url) + " failed with code: " + String(decodeResult);
Expand Down
2 changes: 1 addition & 1 deletion src/OpenStreetMap-esp32.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ constexpr uint16_t OSM_TILE_TIMEOUT_MS = 2500;
constexpr uint16_t OSM_DEFAULT_CACHE_ITEMS = 10;
constexpr uint16_t OSM_MAX_ZOOM = 18;
constexpr UBaseType_t OSM_TASK_PRIORITY = 10;
constexpr uint32_t OSM_TASK_STACKSIZE = 4096;
constexpr uint32_t OSM_TASK_STACKSIZE = 5120;
constexpr uint32_t OSM_JOB_QUEUE_SIZE = 50;

using tileList = std::vector<std::pair<uint32_t, int32_t>>;
Expand Down