Add detailed diagnostic when Analyze returns 0/0
This commit is contained in:
parent
aee2ef2287
commit
1726222ec3
|
|
@ -2660,26 +2660,30 @@ openMainDialog = function()
|
||||||
text = "Analyze",
|
text = "Analyze",
|
||||||
visible = false,
|
visible = false,
|
||||||
onclick = function()
|
onclick = function()
|
||||||
app.alert("ANALYZE CLICKED - build 1919ad8+1")
|
|
||||||
-- Always refresh to avoid stale image from a different sprite
|
-- Always refresh to avoid stale image from a different sprite
|
||||||
refreshSource()
|
refreshSource()
|
||||||
if not S.sourceImage then
|
if not S.sourceImage then
|
||||||
app.alert("No source image. Open a sprite first.")
|
app.alert("No source image. Open a sprite first.")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- Diagnostics
|
|
||||||
local diag = "mode=" .. S.gbAnalyzeMode ..
|
|
||||||
" tileW=" .. S.gbTileW .. " tileH=" .. S.gbTileH ..
|
|
||||||
" imgW=" .. tostring(S.sourceImage.width) ..
|
|
||||||
" imgH=" .. tostring(S.sourceImage.height)
|
|
||||||
if S.sourceImage.width == 0 or S.sourceImage.height == 0 then
|
if S.sourceImage.width == 0 or S.sourceImage.height == 0 then
|
||||||
app.alert("Source image has zero size. " .. diag)
|
app.alert("Source image has zero size")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if S.gbTileW < 1 or S.gbTileH < 1 then
|
if S.gbTileW < 1 or S.gbTileH < 1 then
|
||||||
app.alert("Bad tile size. " .. diag)
|
app.alert("Bad tile size: " .. S.gbTileW .. "x" .. S.gbTileH)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
-- Count non-transparent pixels in source
|
||||||
|
local nonEmptyPixels = 0
|
||||||
|
local sampleW = math.min(S.sourceImage.width, 200)
|
||||||
|
local sampleH = math.min(S.sourceImage.height, 200)
|
||||||
|
for y = 0, sampleH - 1 do
|
||||||
|
for x = 0, sampleW - 1 do
|
||||||
|
local px = S.sourceImage:getPixel(x, y)
|
||||||
|
if pc.rgbaA(px) > 0 then nonEmptyPixels = nonEmptyPixels + 1 end
|
||||||
|
end
|
||||||
|
end
|
||||||
local usedTileW = S.gbTileW
|
local usedTileW = S.gbTileW
|
||||||
local usedTileH = S.gbTileH
|
local usedTileH = S.gbTileH
|
||||||
if S.gbAnalyzeMode == "tile" then
|
if S.gbAnalyzeMode == "tile" then
|
||||||
|
|
@ -2690,6 +2694,14 @@ openMainDialog = function()
|
||||||
else
|
else
|
||||||
S.gbTiles, S.gbTotalTiles = analyzeTiles(S.sourceImage, S.gbFlipOpt, S.gbOffsetOpt, usedTileW, usedTileH)
|
S.gbTiles, S.gbTotalTiles = analyzeTiles(S.sourceImage, S.gbFlipOpt, S.gbOffsetOpt, usedTileW, usedTileH)
|
||||||
end
|
end
|
||||||
|
if S.gbTotalTiles == 0 then
|
||||||
|
app.alert("0/0 result. mode=" .. S.gbAnalyzeMode ..
|
||||||
|
" tile=" .. usedTileW .. "x" .. usedTileH ..
|
||||||
|
" img=" .. S.sourceImage.width .. "x" .. S.sourceImage.height ..
|
||||||
|
" nonEmptyPx(200x200)=" .. nonEmptyPixels ..
|
||||||
|
" cm=" .. tostring(S.sourceImage.colorMode) ..
|
||||||
|
" spriteCM=" .. tostring(app.sprite and app.sprite.colorMode or "nil"))
|
||||||
|
end
|
||||||
S.gbTileW = usedTileW
|
S.gbTileW = usedTileW
|
||||||
S.gbTileH = usedTileH
|
S.gbTileH = usedTileH
|
||||||
S.gbOptImage, S.gbCols = buildOptimizedImage(
|
S.gbOptImage, S.gbCols = buildOptimizedImage(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue