Closed Bug 1048683 Opened 10 years ago Closed 4 years ago

Optimise nine-patches to remove redundant rows/columns


(Firefox for Android Graveyard :: Theme and Visual Design, defect)

Not set


(Not tracked)



(Reporter: ckitching, Assigned: ckitching)




(1 file)

In a nine-patch image with only a single scalable region along a particular axis, if that region consists entirely of duplicated rows/columns it can safely be collapsed to a single row/column of those pixels without altering appearance (and slightly reducing size).

We have several nine-patches that are susceptible to this optimisation. Let's safe a few kilobytes.

So, at the weekend I wrote an evil hackful program to perform this optimisation, found at:

The concept is pretty simple:

Check if the image has more than one scalable region along the x-axis. If it does, abort.
Check if all the columns in the scalable region along the x-axis are identical. If not, abort.
Replace all these columns with a single column.

Repeat for the y-axis.
Attachment #8467521 - Flags: review?(rnewman)
Attachment #8467521 - Flags: review?(rnewman) → review?(
Could you send an example of how an image will be changed? It would be easier to understand what you're trying to achieve here with something more visual.
Flags: needinfo?(chriskitching)
Of course.

One of the images that makes this easiest to understand is probably the one used for the URL bar when it's selected (highlighted orange).
(Dropbox's viewer seems to not respect its transparent pixels, so you will probably want to download both images and open them in gimp or something)

This image has a scalable region in both the X and Y directions. There's a colour gradient along the Y axis, but along the X axis every column in the scalable region is the same, so this image can be reduced to:

Conceptually, the transformation is like taking the scalable region of a ninepatch and flattening it down to one pixel (in cases where this doesn't destroy any data. Doing so along the Y-axis in this example image would destroy the gradient, so it is not done).

Another similar example:

A more extreme example: this image has large scalable regions in both axes that can be collapsed, reducing the image almost to nothing:

If I've understood the nine-patch scaling system properly, these transformations are safe?
Flags: needinfo?(chriskitching)
Comment on attachment 8467521 [details] [diff] [review]
Deduplicate nine-patch scalable regions

Got it, makes sense. Are you confident this will not cause regressions? Please double check the update images in the app.
Attachment #8467521 - Flags: review?( → review+
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 34
Depends on: 1055598
Reopening after the backout.

See Bug 1055598.

It seems the script is behaving as described, but that the process of deleting these "redundant" rows isn't generally safe (things start becoming translucent, strangely enough).

Another puzzle for another time, methinks...
Resolution: FIXED → ---
Merge of backout:
Target Milestone: Firefox 34 → ---
Depends on: 1056312
We have completed our launch of our new Firefox on Android. The development of the new versions use GitHub for issue tracking. If the bug report still reproduces in a current version of [Firefox on Android nightly]( an issue can be reported at the [Fenix GitHub project]( If you want to discuss your report please use [Mozilla's chat]( server and join the [#fenix]( channel.
Closed: 10 years ago4 years ago
Resolution: --- → INCOMPLETE
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in before you can comment on or make changes to this bug.