Skip to content

Commit

Permalink
fix util_stb decode png24, decodeall function
Browse files Browse the repository at this point in the history
  • Loading branch information
YuriSizuku committed Dec 5, 2024
1 parent a223d2a commit 59e6dfc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion asset/plugin/util_stb.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ PLUGIN_STATUS decode_pre(void *context,

// decode png
int w, h, c;
g_img = stbi_load_from_memory(rawdata + cfg->start, datasize, &w, &h, &c, 0);
g_img = stbi_load_from_memory(rawdata + cfg->start, datasize, &w, &h, &c, 4);
if(!g_img)
{
sprintf(s_msg + strlen(s_msg), "[cmodule_util_png::pre] not a png format\n");
Expand Down
11 changes: 7 additions & 4 deletions src/core_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,16 +307,19 @@ int TileSolver::Decode(struct tilecfg_t *tilecfg, wxFileName pluginfile)
struct pixel_t *pixels;
status = decoder->decodeall(context,
rawdata + start, datasize, &m_tilecfg.fmt, &pixels, &npixel, true);
wxLogMessage(wxString::Format("[TileSolver::Decode] decoder->decodeall recv %zu pixels", npixel));

size_t ntilepixel = m_tilecfg.fmt.w * m_tilecfg.fmt.h;
for(int i=0; i< ntile; i++)
{
size_t tilestart = i * nbytes;
if(tilestart + nbytes > npixel) break;
size_t tilestart = i * ntilepixel;
if(tilestart + ntilepixel > npixel) break;
auto& tile = m_tiles[i];
uint8_t *rgbdata = tile.GetData();
uint8_t *adata = tile.GetAlpha();
for(int pixeli=0; pixeli < m_tilecfg.fmt.w * m_tilecfg.fmt.h; pixeli++)
for(int pixeli=0; pixeli < ntilepixel; pixeli++)
{
memcpy(rgbdata + pixeli*3, (void*)(pixels + tilestart + pixeli), 3);
memcpy(rgbdata + pixeli*3, (void*)&pixels[tilestart + pixeli], 3);
adata[pixeli] = pixels[tilestart + pixeli].a; // alpah is in seperate channel
}
}
Expand Down

0 comments on commit 59e6dfc

Please sign in to comment.