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>
|
|
|
|
|
|
|
|
#import "RCTDefines.h"
|
|
|
|
|
|
|
|
/**
|
2015-08-12 14:07:24 +00:00
|
|
|
* This function takes an input content size (typically from an image), a target
|
|
|
|
* size and scale that it will be drawn at (typically in a CGContext) and then
|
|
|
|
* calculates the rectangle to draw the image into so that it will be sized and
|
|
|
|
* positioned correctly if drawn using the specified content mode.
|
2015-07-14 11:06:17 +00:00
|
|
|
*/
|
2015-08-12 14:07:24 +00:00
|
|
|
RCT_EXTERN CGRect RCTTargetRect(CGSize sourceSize, CGSize destSize,
|
|
|
|
CGFloat destScale, UIViewContentMode resizeMode);
|
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
|
|
|
|
* image so that it will be displayed correctly with the specified content mode.
|
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,
|
|
|
|
UIViewContentMode 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,
|
|
|
|
UIViewContentMode resizeMode);
|
2015-11-10 13:03:07 +00:00
|
|
|
/**
|
|
|
|
* This function takes a source size and scale and returns the size in pixels.
|
|
|
|
* Note that the pixel width/height is rounded up to the nearest integral size.
|
|
|
|
*/
|
|
|
|
RCT_EXTERN CGSize RCTSizeInPixels(CGSize pointSize, CGFloat scale);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
RCT_EXTERN UIImage *RCTDecodeImageWithData(NSData *data,
|
|
|
|
CGSize destSize,
|
|
|
|
CGFloat destScale,
|
|
|
|
UIViewContentMode 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.
|
|
|
|
*/
|
|
|
|
RCT_EXTERN NSDictionary<NSString *, id> *RCTGetImageMetadata(NSData *data);
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
RCT_EXTERN NSData *RCTGetImageData(CGImageRef image, float quality);
|