Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imporve custom compress speed via merging the multi Constraints and other optimizations as follows: #178

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

yuruiyin
Copy link

@yuruiyin yuruiyin commented Mar 6, 2021

Issue description:

  • Firstly, If we use multi Constraints such as ResolutionConstraint, QualityConstraint, FormatConstraint, DestinationConstraint, SizeConstraint, there will exists multi bitmap.compress() which is just like one(constraint) by one(constraint). For example, the code is as follows:
compressedImage = Compressor.compress(this@MainActivity, imageFile) {
                    destination(destFile)  
                    resolution(2000, 2000)
                    format(Bitmap.CompressFormat.WEBP)
                    quality(100)
                    size(2_000_000) // 5M
                }

if each constraint spend 2s, then the compression of the above will spend 10s(the sum of each time cost). The result is not what we want.

  • Secondly, since the png which is lossless will ignore the compress quality setting, but in the SizeConstraint Class, the png format bitmap always will be applied the quality reducing multi times which is useless.

Solution:

  1. Merge multi ResolutionConstraints and QualityConstraints and FormatConstraints (without DestinationConstraint and SizeConstraint) into only one DefaultConstraint.
  2. Move the SizeConstraint to the last post since it can reduce the number of compress times in this type of SizeConstraint.
  3. In SizeConstraint, we can avoid performing the compression if the bitmap compress format is png.
  4. If there is a DestinationConstraint, we can reduce the number of copy file times via using the dest file from DestinationConstraint in the method of copyToCache.

…ther optimations as follows:

1. merge multi ResolutionConstraints and QualityConstraints and FormatConstraints (without DestinationConstraint and SizeConstraint) into only one DefaultConstraint
2. Move the SizeConstraint to the last post since it can reduce the number of compress times in this type of SizeConstraint.
3. In SizeConstraint, we can avoid performing the compression if the bitmap compress format is png.
4. If there is a DestinationConstraint, we can reduce the number of copy file times via using the dest file from DestinationConstraint in the method of copyToCache.
@yuruiyin
Copy link
Author

yuruiyin commented Mar 7, 2021

@zetbaitsu hi, plz help review, thanks~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant