Skip to content

Wrong code in YYImageCoder.m #41

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

Closed
wysaid opened this issue Jul 9, 2016 · 2 comments
Closed

Wrong code in YYImageCoder.m #41

wysaid opened this issue Jul 9, 2016 · 2 comments

Comments

@wysaid
Copy link

wysaid commented Jul 9, 2016

The code below in YYImageCode.m at line 1405-1415
The buffer named "tmp" is never used, please fix.
And the code segment is never run...

`
if (iter.x_offset != 0 || iter.y_offset != 0) {

void *tmp = calloc(1, destLength);

if (tmp) {

    vImage_Buffer src = {destBytes, canvasHeight, canvasWidth, bytesPerRow};

    vImage_Buffer dest = {destBytes, canvasHeight, canvasWidth, bytesPerRow};

    vImage_CGAffineTransform transform = {1, 0, 0, 1, iter.x_offset, -iter.y_offset};

    uint8_t backColor[4] = {0};

    vImageAffineWarpCG_ARGB8888(&src, &dest, NULL, &transform, backColor, kvImageBackgroundColorFill);

    memcpy(destBytes, tmp, destLength);

    free(tmp);

}

}

`

@wysaid
Copy link
Author

wysaid commented Jul 9, 2016

And also there's a waste of memory in the alignment calculation.
code:

hasAlpha = config.input.has_alpha;
bitsPerComponent = 8;
bitsPerPixel = 32;
bytesPerRow = YYImageByteAlign(bitsPerPixel / 8 * canvasWidth, 32);

The image can have 3 or 4 channels. But you're not handling the two situations.
So if an image has no alpha channel, 25% of additional useless memory is allocated.

ibireme added a commit that referenced this issue Jul 9, 2016
…e webp frame with nonzero canvas offset.
@ibireme
Copy link
Owner

ibireme commented Jul 9, 2016

Thanks~

  1. The bug is fixed: b659f90
  2. Core Animation prefer to use bgrA8888 (kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedFirst) data to display image, see also: https://github.com/path/FastImageCache#byte-alignment

@wysaid wysaid closed this as completed Sep 9, 2019
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

No branches or pull requests

2 participants