mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-14 02:10:15 +00:00
Merge pull request #1168 from garrettmoon/preventDownscaling
[ASImageNode] Allow prevention of downscaling
This commit is contained in:
commit
a9c60e37ea
@ -48,6 +48,14 @@ typedef UIImage * _Nullable (^asimagenode_modification_block_t)(UIImage *image);
|
|||||||
*/
|
*/
|
||||||
@property (nonatomic, assign, getter=isCropEnabled) BOOL cropEnabled;
|
@property (nonatomic, assign, getter=isCropEnabled) BOOL cropEnabled;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @abstract Indicates that efficient downsizing of backing store should *not* be enabled.
|
||||||
|
*
|
||||||
|
* @discussion Defaults to NO. @see ASCroppedImageBackingSizeAndDrawRectInBounds for more
|
||||||
|
* information.
|
||||||
|
*/
|
||||||
|
@property (nonatomic, assign) BOOL forceUpscaling;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @abstract Enables or disables efficient cropping.
|
* @abstract Enables or disables efficient cropping.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -66,6 +66,7 @@
|
|||||||
|
|
||||||
// Cropping.
|
// Cropping.
|
||||||
BOOL _cropEnabled; // Defaults to YES.
|
BOOL _cropEnabled; // Defaults to YES.
|
||||||
|
BOOL _forceUpscaling; //Defaults to NO.
|
||||||
CGRect _cropRect; // Defaults to CGRectMake(0.5, 0.5, 0, 0)
|
CGRect _cropRect; // Defaults to CGRectMake(0.5, 0.5, 0, 0)
|
||||||
CGRect _cropDisplayBounds;
|
CGRect _cropDisplayBounds;
|
||||||
}
|
}
|
||||||
@ -84,6 +85,7 @@
|
|||||||
self.opaque = NO;
|
self.opaque = NO;
|
||||||
|
|
||||||
_cropEnabled = YES;
|
_cropEnabled = YES;
|
||||||
|
_forceUpscaling = NO;
|
||||||
_cropRect = CGRectMake(0.5, 0.5, 0, 0);
|
_cropRect = CGRectMake(0.5, 0.5, 0, 0);
|
||||||
_cropDisplayBounds = CGRectNull;
|
_cropDisplayBounds = CGRectNull;
|
||||||
_placeholderColor = ASDisplayNodeDefaultPlaceholderColor();
|
_placeholderColor = ASDisplayNodeDefaultPlaceholderColor();
|
||||||
@ -156,6 +158,7 @@
|
|||||||
{
|
{
|
||||||
UIImage *image;
|
UIImage *image;
|
||||||
BOOL cropEnabled;
|
BOOL cropEnabled;
|
||||||
|
BOOL forceUpscaling;
|
||||||
CGFloat contentsScale;
|
CGFloat contentsScale;
|
||||||
CGRect cropDisplayBounds;
|
CGRect cropDisplayBounds;
|
||||||
CGRect cropRect;
|
CGRect cropRect;
|
||||||
@ -169,6 +172,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
cropEnabled = _cropEnabled;
|
cropEnabled = _cropEnabled;
|
||||||
|
forceUpscaling = _forceUpscaling;
|
||||||
contentsScale = _contentsScaleForDisplay;
|
contentsScale = _contentsScaleForDisplay;
|
||||||
cropDisplayBounds = _cropDisplayBounds;
|
cropDisplayBounds = _cropDisplayBounds;
|
||||||
cropRect = _cropRect;
|
cropRect = _cropRect;
|
||||||
@ -223,6 +227,7 @@
|
|||||||
boundsSizeInPixels,
|
boundsSizeInPixels,
|
||||||
contentMode,
|
contentMode,
|
||||||
cropRect,
|
cropRect,
|
||||||
|
forceUpscaling,
|
||||||
&backingSize,
|
&backingSize,
|
||||||
&imageDrawRect);
|
&imageDrawRect);
|
||||||
}
|
}
|
||||||
@ -385,6 +390,18 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL)forceUpscaling
|
||||||
|
{
|
||||||
|
ASDN::MutexLocker l(_imageLock);
|
||||||
|
return _forceUpscaling;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setForceUpscaling:(BOOL)forceUpscaling
|
||||||
|
{
|
||||||
|
ASDN::MutexLocker l(_imageLock);
|
||||||
|
_forceUpscaling = forceUpscaling;
|
||||||
|
}
|
||||||
|
|
||||||
- (asimagenode_modification_block_t)imageModificationBlock
|
- (asimagenode_modification_block_t)imageModificationBlock
|
||||||
{
|
{
|
||||||
ASDN::MutexLocker l(_imageLock);
|
ASDN::MutexLocker l(_imageLock);
|
||||||
|
|||||||
@ -19,12 +19,14 @@ ASDISPLAYNODE_EXTERN_C_BEGIN
|
|||||||
@param boundsSize The bounds in which the image will be displayed.
|
@param boundsSize The bounds in which the image will be displayed.
|
||||||
@param contentMode The mode that defines how image will be scaled and cropped to fit. Supported values are UIViewContentModeScaleToAspectFill and UIViewContentModeScaleToAspectFit.
|
@param contentMode The mode that defines how image will be scaled and cropped to fit. Supported values are UIViewContentModeScaleToAspectFill and UIViewContentModeScaleToAspectFit.
|
||||||
@param cropRect A rectangle that is to be featured by the cropped image. The rectangle is specified as a "unit rectangle," using percentages of the source image's width and height, e.g. CGRectMake(0.5, 0, 0.5, 1.0) will feature the full right half a photo. If the cropRect is empty, the contentMode will be used to determine the drawRect's size, and only the cropRect's origin will be used for positioning.
|
@param cropRect A rectangle that is to be featured by the cropped image. The rectangle is specified as a "unit rectangle," using percentages of the source image's width and height, e.g. CGRectMake(0.5, 0, 0.5, 1.0) will feature the full right half a photo. If the cropRect is empty, the contentMode will be used to determine the drawRect's size, and only the cropRect's origin will be used for positioning.
|
||||||
|
@param forceUpscaling A boolean that indicates you would *not* like the backing size to be downscaled if the image is smaller than the destination size. Setting this to YES will result in higher memory usage when images are smaller than their destination.
|
||||||
@discussion If the image is smaller than the size and UIViewContentModeScaleToAspectFill is specified, we suggest the input size so it will be efficiently upscaled on the GPU by the displaying layer at composite time.
|
@discussion If the image is smaller than the size and UIViewContentModeScaleToAspectFill is specified, we suggest the input size so it will be efficiently upscaled on the GPU by the displaying layer at composite time.
|
||||||
*/
|
*/
|
||||||
extern void ASCroppedImageBackingSizeAndDrawRectInBounds(CGSize sourceImageSize,
|
extern void ASCroppedImageBackingSizeAndDrawRectInBounds(CGSize sourceImageSize,
|
||||||
CGSize boundsSize,
|
CGSize boundsSize,
|
||||||
UIViewContentMode contentMode,
|
UIViewContentMode contentMode,
|
||||||
CGRect cropRect,
|
CGRect cropRect,
|
||||||
|
BOOL forceUpscaling,
|
||||||
CGSize *outBackingSize,
|
CGSize *outBackingSize,
|
||||||
CGRect *outDrawRect
|
CGRect *outDrawRect
|
||||||
);
|
);
|
||||||
|
|||||||
@ -36,6 +36,7 @@ void ASCroppedImageBackingSizeAndDrawRectInBounds(CGSize sourceImageSize,
|
|||||||
CGSize boundsSize,
|
CGSize boundsSize,
|
||||||
UIViewContentMode contentMode,
|
UIViewContentMode contentMode,
|
||||||
CGRect cropRect,
|
CGRect cropRect,
|
||||||
|
BOOL forceUpscaling,
|
||||||
CGSize *outBackingSize,
|
CGSize *outBackingSize,
|
||||||
CGRect *outDrawRect
|
CGRect *outDrawRect
|
||||||
)
|
)
|
||||||
@ -62,7 +63,7 @@ void ASCroppedImageBackingSizeAndDrawRectInBounds(CGSize sourceImageSize,
|
|||||||
|
|
||||||
// If fitting the desired aspect ratio to the image size actually results in a larger buffer, use the input values.
|
// If fitting the desired aspect ratio to the image size actually results in a larger buffer, use the input values.
|
||||||
// However, if there is a pixel savings (e.g. we would have to upscale the image), overwrite the function arguments.
|
// However, if there is a pixel savings (e.g. we would have to upscale the image), overwrite the function arguments.
|
||||||
if ((scaledSizeForImage.width * scaledSizeForImage.height) < (destinationWidth * destinationHeight)) {
|
if (forceUpscaling == NO && (scaledSizeForImage.width * scaledSizeForImage.height) < (destinationWidth * destinationHeight)) {
|
||||||
destinationWidth = (size_t)roundf(scaledSizeForImage.width);
|
destinationWidth = (size_t)roundf(scaledSizeForImage.width);
|
||||||
destinationHeight = (size_t)roundf(scaledSizeForImage.height);
|
destinationHeight = (size_t)roundf(scaledSizeForImage.height);
|
||||||
if (destinationWidth == 0 || destinationHeight == 0) {
|
if (destinationWidth == 0 || destinationHeight == 0) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user