-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
Implemented CENTER_INSIDE support #727
Conversation
final int verticalPadding = (height - inBitmap.getHeight()) / 2; | ||
|
||
Bitmap.Config config = getSafeConfig(inBitmap); | ||
Bitmap toReuse = pool.get(width, height, config); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pool may return null (at least in 3.0 it did)
I have one bigger concern (other than my small line comments): |
final int horizontalPadding = (width - inBitmap.getWidth()) / 2; | ||
final int verticalPadding = (height - inBitmap.getHeight()) / 2; | ||
|
||
Bitmap.Config config = getSafeConfig(inBitmap); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs to upgrade to 8888 if there's a padding, otherwise we'll end up with a color that someone won't like (BLACK/WHITE are both wrong choices), it should be TRANSPARENT.
Thanks for the feedback @TWiStErRob. Right on it! |
I think you can disregard padding entirely, it's hard for me to imagine a scenario where you want extra transparency baked into the Bitmap. I'd just check if the width and height are greater than the target, and if so, fitCenter, and otherwise just return the original Bitmap. Transformations never promise that the Bitmap they return will exactly match the requested width and height. Thanks for putting this up! |
@sjudd what if the requested transformation doesn't match scaleType? ImageView.scaleType = fitCenter
.centerInside() on load I would still expect a small image to be centered in a middle of a bigger space. |
Oh I wouldn't, I'd expect the Bitmap to remain at the smallest possible size (to minimize memory usage), but for the Bitmap to be stretched by the view when it's drawn to match the requested scale type. None of our other transformations try to override a conflicting scale type set on a view, I don't think we need to do so here either. |
@sjudd ah, you're right; the ImageView wins; @josemontiel sorry about that. |
@sjudd so just to be sure, it should check if the Bitmap's dimensions are larger than the target and call fitCenter, otherwise return the input as is? |
@josemontiel I believe so? I think that matches what ImageView does? |
What do you both think about the Downsampler issue? NONE will prevent huge images from loading with centerInside. |
That definitely would be a problem, perhaps the NONE strategy could be overridden in the Downsampler when the source's dimensions are larger than the target's? |
Hmm, there's already a |
Hmm interesting @TWiStErRob . It could be something like this:
|
Yeah I think you're going to need a new downsample strategy that's equivalent to CENTER_INSIDE but that doesn't upscale. The names here are pretty poor, sorry for that. Is there some standard naming convention for these transformations? Alternative suggestions welcome. I'm not totally sure that FIT_INSIDE is much clearer than CENTER_INSIDE, though I agree CENTER_INSIDE is poor. If we rename CENTER_INSIDE to FIT_INSIDE, what do we call the equivalent strategy that doesn't downsample? @josemontiel That looks right, but I think you could simplify by just returning |
@sjudd I'm not aware of any standards here, I created #730 with my suggestions/questions. @josemontiel I think you should just go with your "Real" naming and we'll rename it by fixing #730 |
@TWiStErRob I'll go with DownscaleOnly, makes sense. |
|
Implemented CENTER_INSIDE support Implemented CENTER_INSIDE support CENTER_INSIDE implemented CENTER_INSIDE implemented: DownscaleOnly Downsample strategy CENTER_INSIDE: Formatting fixed
@sjudd this looks ready. |
LGTM, I'll merge internally as soon as I can and push out. I'll probably rename DOWNSCALE_ONLY per our brief discussion on your doc @TWiStErRob since this isn't the only strategy that doesn't upscale. |
Thanks! |
Implemented CENTER_INSIDE support
*** Reason for rollback *** Broke Street View *** Original change description *** MOE automated commit. Merge pull request bumptech#762 from vanniktech/master_clean_upload_script Clean upload script up ------------- Merge pull request bumptech#727 from josemontiel/master Implemented CENTER_INSIDE support ------------- Update Downsampler names. ------------- Merge pull request bumptech#758 from mullender/glide-issue-738 fix for issue bumptech#738 Some images simply do not download (Black image) -… ------------- Created by MOE: https://github.com/google/moe *** ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=108724201
*** Reason for rollback *** Rollforward with compatibility for apps targeting API 21 *** Original change description *** Automated g4 rollback of changelist 108709885. *** Reason for rollback *** Broke Street View *** Original change description *** MOE automated commit. Merge pull request bumptech#762 from vanniktech/master_clean_upload_script Clean upload script up ------------- Merge pull request bumptech#727 from josemontiel/master Implemented CENTER_INSIDE support ------------- Update Downsampler names. ------------- Merge pull request bumptech#758 from mullender/glide-issue-738 fix for issue bumptech#738 Some images simply do no... *** ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=108748541
Fixes #591