2015-07-14 11:06:17 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import <UIKit/UIKit.h>
|
|
|
|
|
2016-11-23 15:47:52 +00:00
|
|
|
#import <React/RCTDefines.h>
|
|
|
|
#import <React/RCTResizeMode.h>
|
2015-07-14 11:06:17 +00:00
|
|
|
|
2016-01-06 11:54:25 +00:00
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
2015-07-14 11:06:17 +00:00
|
|
|
/**
|
2016-01-20 19:03:22 +00:00
|
|
|
* This function takes an source size (typically from an image), a target size
|
|
|
|
* and scale that it will be drawn at (typically in a CGContext) and then
|
2015-08-12 14:07:24 +00:00
|
|
|
* calculates the rectangle to draw the image into so that it will be sized and
|
2016-01-20 19:03:22 +00:00
|
|
|
* positioned correctly according to the specified resizeMode.
|
2015-07-14 11:06:17 +00:00
|
|
|
*/
|
2015-08-12 14:07:24 +00:00
|
|
|
RCT_EXTERN CGRect RCTTargetRect(CGSize sourceSize, CGSize destSize,
|
2016-01-20 19:03:22 +00:00
|
|
|
CGFloat destScale, RCTResizeMode resizeMode);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function takes a source size (typically from an image), a target rect
|
|
|
|
* that it will be drawn into (typically relative to a CGContext), and works out
|
|
|
|
* the transform needed to draw the image at the correct scale and position.
|
|
|
|
*/
|
|
|
|
RCT_EXTERN CGAffineTransform RCTTransformFromTargetRect(CGSize sourceSize,
|
|
|
|
CGRect targetRect);
|
2015-07-14 11:06:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This function takes an input content size & scale (typically from an image),
|
2015-08-12 14:07:24 +00:00
|
|
|
* a target size & scale at which it will be displayed (typically in a
|
|
|
|
* UIImageView) and then calculates the optimal size at which to redraw the
|
2016-01-20 19:03:22 +00:00
|
|
|
* image so that it will be displayed correctly with the specified resizeMode.
|
2015-07-14 11:06:17 +00:00
|
|
|
*/
|
2015-08-12 14:07:24 +00:00
|
|
|
RCT_EXTERN CGSize RCTTargetSize(CGSize sourceSize, CGFloat sourceScale,
|
|
|
|
CGSize destSize, CGFloat destScale,
|
2016-01-20 19:03:22 +00:00
|
|
|
RCTResizeMode resizeMode, BOOL allowUpscaling);
|
2015-07-14 11:06:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This function takes an input content size & scale (typically from an image),
|
|
|
|
* a target size & scale that it will be displayed at, and determines if the
|
|
|
|
* source will need to be upscaled to fit (which may result in pixelization).
|
|
|
|
*/
|
|
|
|
RCT_EXTERN BOOL RCTUpscalingRequired(CGSize sourceSize, CGFloat sourceScale,
|
|
|
|
CGSize destSize, CGFloat destScale,
|
2016-01-20 19:03:22 +00:00
|
|
|
RCTResizeMode resizeMode);
|
2015-11-10 13:03:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This function takes the source data for an image and decodes it at the
|
|
|
|
* specified size. If the original image is smaller than the destination size,
|
|
|
|
* the resultant image's scale will be decreased to compensate, so the
|
|
|
|
* width/height of the returned image is guaranteed to be >= destSize.
|
|
|
|
* Pass a destSize of CGSizeZero to decode the image at its original size.
|
|
|
|
*/
|
2016-01-06 11:54:25 +00:00
|
|
|
RCT_EXTERN UIImage *__nullable RCTDecodeImageWithData(NSData *data,
|
|
|
|
CGSize destSize,
|
|
|
|
CGFloat destScale,
|
2016-01-20 19:03:22 +00:00
|
|
|
RCTResizeMode resizeMode);
|
2015-11-17 17:53:47 +00:00
|
|
|
|
Added getImageSize method
Summary:
public
This diff adds a `getSize()` method to `Image` to retrieve the width and height of an image prior to displaying it. This is useful when working with images from uncontrolled sources, and has been a much-requested feature.
In order to retrieve the image dimensions, the image may first need to be loaded or downloaded, after which it will be cached. This means that in principle you could use this method to preload images, however it is not optimized for that purpose, and may in future be implemented in a way that does not fully load/download the image data.
A fully supported way to preload images will be provided in a future diff.
The API (separate success and failure callbacks) is far from ideal, but until we agree on a unified standard, this was the most conventional way I could think of to implement it. If it returned a promise or something similar, it would be unique among all such APIS in the framework.
Please note that this has been a long time coming, in part due to much bikeshedding about what the API should look like, so while it's not unlikely that the API may change in future, I think having *some* way to do this is better than waiting until we can define the "perfect" way.
Reviewed By: vjeux
Differential Revision: D2797365
fb-gh-sync-id: 11eb1b8547773b1f8be0bc55ddf6dfedebf7fc0a
2016-01-01 02:50:26 +00:00
|
|
|
/**
|
|
|
|
* This function takes the source data for an image and decodes just the
|
|
|
|
* metadata, without decompressing the image itself.
|
|
|
|
*/
|
2016-01-06 11:54:25 +00:00
|
|
|
RCT_EXTERN NSDictionary<NSString *, id> *__nullable RCTGetImageMetadata(NSData *data);
|
Added getImageSize method
Summary:
public
This diff adds a `getSize()` method to `Image` to retrieve the width and height of an image prior to displaying it. This is useful when working with images from uncontrolled sources, and has been a much-requested feature.
In order to retrieve the image dimensions, the image may first need to be loaded or downloaded, after which it will be cached. This means that in principle you could use this method to preload images, however it is not optimized for that purpose, and may in future be implemented in a way that does not fully load/download the image data.
A fully supported way to preload images will be provided in a future diff.
The API (separate success and failure callbacks) is far from ideal, but until we agree on a unified standard, this was the most conventional way I could think of to implement it. If it returned a promise or something similar, it would be unique among all such APIS in the framework.
Please note that this has been a long time coming, in part due to much bikeshedding about what the API should look like, so while it's not unlikely that the API may change in future, I think having *some* way to do this is better than waiting until we can define the "perfect" way.
Reviewed By: vjeux
Differential Revision: D2797365
fb-gh-sync-id: 11eb1b8547773b1f8be0bc55ddf6dfedebf7fc0a
2016-01-01 02:50:26 +00:00
|
|
|
|
2015-11-17 17:53:47 +00:00
|
|
|
/**
|
|
|
|
* Convert an image back into data. Images with an alpha channel will be
|
|
|
|
* converted to lossless PNG data. Images without alpha will be converted to
|
|
|
|
* JPEG. The `quality` argument controls the compression ratio of the JPEG
|
|
|
|
* conversion, with 1.0 being maximum quality. It has no effect for images
|
|
|
|
* using PNG compression.
|
|
|
|
*/
|
2017-07-25 04:39:02 +00:00
|
|
|
RCT_EXTERN NSData *__nullable RCTGetImageData(UIImage *image, float quality);
|
2016-01-06 11:54:25 +00:00
|
|
|
|
2016-01-20 19:03:22 +00:00
|
|
|
/**
|
|
|
|
* This function transforms an image. `destSize` is the size of the final image,
|
|
|
|
* and `destScale` is its scale. The `transform` argument controls how the
|
|
|
|
* source image will be mapped to the destination image.
|
|
|
|
*/
|
|
|
|
RCT_EXTERN UIImage *__nullable RCTTransformImage(UIImage *image,
|
|
|
|
CGSize destSize,
|
|
|
|
CGFloat destScale,
|
|
|
|
CGAffineTransform transform);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return YES if image has an alpha component
|
|
|
|
*/
|
|
|
|
RCT_EXTERN BOOL RCTImageHasAlpha(CGImageRef image);
|
|
|
|
|
2016-01-06 11:54:25 +00:00
|
|
|
NS_ASSUME_NONNULL_END
|