diff --git a/aniphallow.lua b/aniphallow.lua index c421c0a..5224899 100644 --- a/aniphallow.lua +++ b/aniphallow.lua @@ -2660,26 +2660,30 @@ openMainDialog = function() text = "Analyze", visible = false, onclick = function() - app.alert("ANALYZE CLICKED - build 1919ad8+1") -- Always refresh to avoid stale image from a different sprite refreshSource() if not S.sourceImage then app.alert("No source image. Open a sprite first.") return 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 - app.alert("Source image has zero size. " .. diag) + app.alert("Source image has zero size") return end 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 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 usedTileH = S.gbTileH if S.gbAnalyzeMode == "tile" then @@ -2690,6 +2694,14 @@ openMainDialog = function() else S.gbTiles, S.gbTotalTiles = analyzeTiles(S.sourceImage, S.gbFlipOpt, S.gbOffsetOpt, usedTileW, usedTileH) 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.gbTileH = usedTileH S.gbOptImage, S.gbCols = buildOptimizedImage(