Skip to content

Commit

Permalink
fix(ios): fix image blurry error
Browse files Browse the repository at this point in the history
  • Loading branch information
ozonelmy authored and zoomchan-cxj committed Mar 29, 2022
1 parent b685310 commit 83281ca
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions ios/sdk/component/image/HippyImageView.m
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,14 @@ static BOOL HippyImageNeedsShrinkForSize(UIImage *inputImage, CGSize size) {
buffer1.rowBytes = buffer2.rowBytes = CGImageGetBytesPerRow(imageRef);
size_t bytes = buffer1.rowBytes * buffer1.height;
buffer1.data = malloc(bytes);
if (NULL == buffer1.data) {
return inputImage;
}
buffer2.data = malloc(bytes);

if (NULL == buffer2.data) {
free(buffer1.data);
return inputImage;
}
// A description of how to compute the box kernel width from the Gaussian
// radius (aka standard deviation) appears in the SVG spec:
// http://www.w3.org/TR/SVG/filters.html#feGaussianBlurElement
Expand All @@ -126,9 +132,19 @@ static BOOL HippyImageNeedsShrinkForSize(UIImage *inputImage, CGSize size) {
dataSource = NULL;

// perform blur
vImageBoxConvolve_ARGB8888(&buffer1, &buffer2, tempBuffer, 0, 0, boxSize, boxSize, NULL, kvImageEdgeExtend);
vImageBoxConvolve_ARGB8888(&buffer2, &buffer1, tempBuffer, 0, 0, boxSize, boxSize, NULL, kvImageEdgeExtend);
vImageBoxConvolve_ARGB8888(&buffer1, &buffer2, tempBuffer, 0, 0, boxSize, boxSize, NULL, kvImageEdgeExtend);
vImage_Error error;
error = vImageBoxConvolve_ARGB8888(&buffer1, &buffer2, tempBuffer, 0, 0, boxSize, boxSize, NULL, kvImageEdgeExtend);
if (error) {
return inputImage;
}
error = vImageBoxConvolve_ARGB8888(&buffer2, &buffer1, tempBuffer, 0, 0, boxSize, boxSize, NULL, kvImageEdgeExtend);
if (error) {
return inputImage;
}
error = vImageBoxConvolve_ARGB8888(&buffer1, &buffer2, tempBuffer, 0, 0, boxSize, boxSize, NULL, kvImageEdgeExtend);
if (error) {
return inputImage;
}

// free buffers
free(buffer2.data);
Expand All @@ -137,7 +153,8 @@ static BOOL HippyImageNeedsShrinkForSize(UIImage *inputImage, CGSize size) {
tempBuffer = NULL;

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
CGBitmapInfo bitmapInfoMasked = CGImageGetBitmapInfo(imageRef);
CGBitmapInfo bitmapInfo = bitmapInfoMasked & kCGBitmapByteOrderMask;
CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo(imageRef);
if (alphaInfo == kCGImageAlphaNone || alphaInfo == kCGImageAlphaOnly) {
alphaInfo = kCGImageAlphaNoneSkipFirst;
Expand Down

0 comments on commit 83281ca

Please sign in to comment.