Skip to main content
andrea venturi
Associate III
April 18, 2020
Solved

how to remove unused graphic not referred in screens..

  • April 18, 2020
  • 3 replies
  • 1639 views

hi,

slowly slowly i've got my growing TouchGFX project to become too fat for the2MB flash on a STM32F429..

as i've put too much graphic assets on the "database" and i'm not using all of them in the screens, i'm wondering if there's a way to find out "programmatically" which assets are not really referenced.. ( i know which "few" icons i put up with a routine..)

i only found this thread, 4 year old, that's really shows a manual procedure (and tedious..) =)

https://touchgfx.zendesk.com/hc/en-us/community/posts/207462585-Removing-unused-bitmap

thanx for hints!

This topic has been closed for replies.
Best answer by Martin KJELDSEN

There's no "tool" to do this if you're having a hard time getting an overview of unused assets, but if i have time i could write a script for you. Should be easy to do if you want to do it yourself. Hints:

  1. BitmapDatabase.hpp (generated in generated/images/include) contains all the bitmap ids
  2. Transform filenames (assets/images/) into IDs (e.g. BITMAP_BLUE_BACKGROUNDS_MAIN_BG_800X480PX_ID might be blue_backgrounds_main_bg_800x480px.png)
  3. Search all gui code (generated or otherwise) for references to the ids - If not found, add the filename to a list
  4. Delete all unused files contained in the list
  5. Re-generate assets (will clean up the bitmap database)
  6. Commit the removal of the assets from assets/images to your git repo

/Martin

3 replies

Martin KJELDSEN
Martin KJELDSENBest answer
Principal III
April 20, 2020

There's no "tool" to do this if you're having a hard time getting an overview of unused assets, but if i have time i could write a script for you. Should be easy to do if you want to do it yourself. Hints:

  1. BitmapDatabase.hpp (generated in generated/images/include) contains all the bitmap ids
  2. Transform filenames (assets/images/) into IDs (e.g. BITMAP_BLUE_BACKGROUNDS_MAIN_BG_800X480PX_ID might be blue_backgrounds_main_bg_800x480px.png)
  3. Search all gui code (generated or otherwise) for references to the ids - If not found, add the filename to a list
  4. Delete all unused files contained in the list
  5. Re-generate assets (will clean up the bitmap database)
  6. Commit the removal of the assets from assets/images to your git repo

/Martin

Martin KJELDSEN
Principal III
April 20, 2020

Here's some dirty Ruby-pseudo-code to get you started:

found = false
unused = []
 
pngs = Dir["assets/images/*.png"].collect {|a| "BITMAP_" + File.basename(a, ".png").upcase + "_ID" }
Dir["**/*View*.cpp"].each { |f| 
	pngs.each { |p|
	 found = true if File.open(f).grep(/p/) 
	}
 
	unused << p if !found
 found = false
}

andrea venturi
Associate III
April 20, 2020

than again Martin for the fast and constructive reply.. i'll try to make up something next days and report!

Martin KJELDSEN
Principal III
April 20, 2020

Sweet! Let me know how you do :)