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

Fix bug #3564 #3565

Merged
merged 2 commits into from
Jul 15, 2023
Merged

Fix bug #3564 #3565

merged 2 commits into from
Jul 15, 2023

Conversation

fattiger00
Copy link

@fattiger00 fattiger00 commented Jul 14, 2023

New Pull Request Checklist

  • I have read and understood the CONTRIBUTING guide

  • I have read the Documentation

  • I have searched for a similar pull request in the project and found #3321

  • I have updated this branch with the latest master to avoid conflicts (via merge from master or rebase)

  • I have added the required tests to prove the fix/feature I am adding

  • I have updated the documentation (if necessary)

  • I have run the tests and they pass

  • I have run the lint and it passes (pod lib lint)

This merge request fixes: [#3564]

Pull Request Description

How I fix it:

It's a patch of this PR #3321

In File SDImageCoderHelper.m + 717

 destTile.size.height += kDestSeemOverlap;

use kDestSeemOverlap to avoid the loss of precision. but when the original height can not be evenly divided by the target height, use the code below to avoid the content missing.

if( y == iterations - 1 && remainder ) {
    float dify = destTile.size.height;
    destTile.size.height = CGImageGetHeight( sourceTileImageRef ) * imageScale;
    dify -= destTile.size.height;
    destTile.origin.y = MIN(0, destTile.origin.y + dify);
}

But in the above code snippet,destTile.size. height is not added with kDestSeemOverlap. so It may lead to one-pixel content loss.

so I reference the code line 717, and add an overlay height to destTile.
destTile.size.height = CGImageGetHeight( sourceTileImageRef ) * imageScale + kDestSeemOverlap;

Add test case

Since the test size CGSizeMake(1029, 1029) contains the edge case of CGSizeMake(3024, 4032).

as the PR #3321 described: This code is handling the rendering of the last tile if the height of the tile is not equally distributed to the height of the image.

I change the data and add a new assert for this PR.

yang added 2 commits July 15, 2023 00:30
@dreampiggy
Copy link
Contributor

Also....SDWebImage itself's image loading pipeline, no long use this API at all. Seems you use by your own ?

@dreampiggy
Copy link
Contributor

The test case on Mac I can fix it, ignore

@dreampiggy dreampiggy merged commit 512eb99 into SDWebImage:master Jul 15, 2023
3 of 4 checks passed
@fattiger00
Copy link
Author

Also....SDWebImage itself's image loading pipeline, no long use this API at all. Seems you use by your own ?

Yep, For the app Image system based on SDWebImage, customizing a downsampling function is kind of lame. Since it's including some internal precondition judge functions which include multi-devices adaptations. On the other hand, I personally think SDWebImage should cover the similar Utils tool function.

If you have any better advice, I'd like to discuss it.

@dreampiggy
Copy link
Contributor

dreampiggy commented Jul 16, 2023

The downsample is recommended happended on coder level, not given a decoded CGImage and re-scale, which waste CPU/RAM. See that ScaleDownLimitBytes. You can customize the coder by your own as well. See more in 5.16.0 changelog

For force-decode, it not always needed because you can generate CGImage carefully to avoid CA copy it, see more in 5.17.0 changelog.

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

2 participants