PHP 7.4.33
Preview: RCTImageBlurUtils.mm Size: 3.58 KB
/var/www/uibuilder.cmshelp.dk/httpdocs/node_modules/react-native/Libraries/Image/RCTImageBlurUtils.mm
/*
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

#import <React/RCTImageBlurUtils.h>

UIImage *RCTBlurredImageWithRadius(UIImage *inputImage, CGFloat radius)
{
  CGImageRef imageRef = inputImage.CGImage;
  CGFloat imageScale = inputImage.scale;
  UIImageOrientation imageOrientation = inputImage.imageOrientation;

  // Image must be nonzero size
  if (CGImageGetWidth(imageRef) * CGImageGetHeight(imageRef) == 0) {
    return inputImage;
  }

  // convert to ARGB if it isn't
  if (CGImageGetBitsPerPixel(imageRef) != 32 || !((CGImageGetBitmapInfo(imageRef) & kCGBitmapAlphaInfoMask))) {
    UIGraphicsImageRendererFormat *const rendererFormat = [UIGraphicsImageRendererFormat defaultFormat];
    rendererFormat.scale = inputImage.scale;
    UIGraphicsImageRenderer *const renderer = [[UIGraphicsImageRenderer alloc] initWithSize:inputImage.size
                                                                                     format:rendererFormat];

    imageRef = [renderer imageWithActions:^(UIGraphicsImageRendererContext *_Nonnull context) {
                 [inputImage drawAtPoint:CGPointZero];
               }].CGImage;
  }

  vImage_Buffer buffer1, buffer2;
  buffer1.width = buffer2.width = CGImageGetWidth(imageRef);
  buffer1.height = buffer2.height = CGImageGetHeight(imageRef);
  buffer1.rowBytes = buffer2.rowBytes = CGImageGetBytesPerRow(imageRef);
  size_t bytes = buffer1.rowBytes * buffer1.height;
  buffer1.data = malloc(bytes);
  if (!buffer1.data) {
    return inputImage;
  }
  buffer2.data = malloc(bytes);
  if (!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
  uint32_t boxSize = floor((radius * imageScale * 3 * sqrt(2 * M_PI) / 4 + 0.5) / 2);
  boxSize |= 1; // Ensure boxSize is odd

  // create temp buffer
  vImage_Error tempBufferSize = vImageBoxConvolve_ARGB8888(
      &buffer1, &buffer2, NULL, 0, 0, boxSize, boxSize, NULL, kvImageGetTempBufferSize | kvImageEdgeExtend);
  if (tempBufferSize <= 0) {
    free(buffer1.data);
    free(buffer2.data);
    return inputImage;
  }
  void *tempBuffer = malloc(tempBufferSize);
  if (!tempBuffer) {
    free(buffer1.data);
    free(buffer2.data);
    return inputImage;
  }

  // copy image data
  CFDataRef dataSource = CGDataProviderCopyData(CGImageGetDataProvider(imageRef));
  memcpy(buffer1.data, CFDataGetBytePtr(dataSource), bytes);
  CFRelease(dataSource);

  // 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);

  // free buffers
  free(buffer2.data);
  free(tempBuffer);

  // create image context from buffer
  CGContextRef ctx = CGBitmapContextCreate(
      buffer1.data,
      buffer1.width,
      buffer1.height,
      8,
      buffer1.rowBytes,
      CGImageGetColorSpace(imageRef),
      CGImageGetBitmapInfo(imageRef));

  // create image from context
  imageRef = CGBitmapContextCreateImage(ctx);
  UIImage *outputImage = [UIImage imageWithCGImage:imageRef scale:imageScale orientation:imageOrientation];
  CGImageRelease(imageRef);
  CGContextRelease(ctx);
  free(buffer1.data);
  return outputImage;
}

Directory Contents

Dirs: 0 × Files: 70
Name Size Perms Modified Actions
305 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
6.37 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
1.24 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
10.57 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
10.79 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
7.92 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
306 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
465 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
3.14 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
2.52 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
7.11 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
1.47 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
1.12 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
2.81 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
3.94 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
2.36 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
2.20 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
595 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
4.93 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
406 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
440 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
424 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
1.69 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
430 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
414 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
609 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
4.76 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
302 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
2.16 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
569 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
841 B lrw-r--r-- 2025-03-28 11:04:43
Edit Download
299 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
1.51 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
364 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
3.58 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
1.20 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
5.74 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
1.85 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
295 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
4.38 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
1.42 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
51.56 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
816 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
6.15 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
2.01 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
1.10 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
1.04 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
276 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
380 B lrw-r--r-- 2025-03-28 11:04:43
Edit Download
1.69 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
8.35 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
3.13 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
2.84 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
707 B lrw-r--r-- 2025-03-28 11:04:43
Edit Download
3.50 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
12.22 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
844 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
15.24 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
279 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
4.53 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
362 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
2.16 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
1.53 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
623 B lrw-r--r-- 2025-03-28 11:04:43
Edit Download
310 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
10.67 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
2.43 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
710 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
4.22 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
1.30 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).