Delete unused MDFImageCalculations and textColorOnBackgroundImage.
PiperOrigin-RevId: 458123929
diff --git a/src/MDFTextAccessibility.h b/src/MDFTextAccessibility.h
index 34a13d1..e119a30 100644
--- a/src/MDFTextAccessibility.h
+++ b/src/MDFTextAccessibility.h
@@ -60,33 +60,6 @@
targetTextAlpha:(CGFloat)targetTextAlpha
font:(nullable UIFont *)font;
-/**
- An optionally transparent text color suitable for displaying on a background image with a
- particular font.
-
- The color returned will be white or black with an alpha value of targetTextAlpha, unless the
- contrast ratio is insufficient, in which case the alpha is increased (made more opaque).
-
- If the passed font is nil, then a conservative guess is used.
-
- The content of the background image is simply averaged to make an average color, which is then used
- as if it were the background color of the text. Depending on the contents of the image, this
- approximation may or may not result in legible text.
-
- The supplied image region will be intersected with the image's bounds. If the resulting region is
- null or empty then this method returns nil.
-
- @param backgroundImage The opaque background image the text will be displayed on.
- @param region The region in which the text will be displayed. Can be conservatively large.
- @param targetTextAlpha The target alpha of the text.
- @param font The font to be used to display the text. Can be nil.
- @return A color with acceptable contrast ratio, or nil if the region is out of bounds of the image.
- */
-+ (nullable UIColor *)textColorOnBackgroundImage:(nonnull UIImage *)backgroundImage
- inRegion:(CGRect)region
- targetTextAlpha:(CGFloat)targetTextAlpha
- font:(nullable UIFont *)font;
-
#pragma mark Advanced methods
/**
diff --git a/src/MDFTextAccessibility.m b/src/MDFTextAccessibility.m
index 38cf89b..fb8dcaf 100644
--- a/src/MDFTextAccessibility.m
+++ b/src/MDFTextAccessibility.m
@@ -17,7 +17,6 @@
#import "MDFTextAccessibility.h"
#import "MDFColorCalculations.h"
-#import "MDFImageCalculations.h"
#import "NSArray+MDFUtils.h"
static const CGFloat kMinContrastRatioNormalText = 4.5f;
@@ -39,20 +38,6 @@
options:options];
}
-+ (nullable UIColor *)textColorOnBackgroundImage:(nonnull UIImage *)backgroundImage
- inRegion:(CGRect)region
- targetTextAlpha:(CGFloat)targetTextAlpha
- font:(nullable UIFont *)font {
- UIColor *backgroundColor = MDFAverageColorOfOpaqueImage(backgroundImage, region);
- if (!backgroundColor) {
- return nil;
- }
-
- return [self textColorOnBackgroundColor:backgroundColor
- targetTextAlpha:targetTextAlpha
- font:font];
-}
-
+ (nullable UIColor *)textColorOnBackgroundColor:(nonnull UIColor *)backgroundColor
targetTextAlpha:(CGFloat)targetTextAlpha
options:(MDFTextAccessibilityOptions)options {
diff --git a/src/private/MDFImageCalculations.h b/src/private/MDFImageCalculations.h
deleted file mode 100644
index 7cdb664..0000000
--- a/src/private/MDFImageCalculations.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- Copyright 2016-present Google Inc. All Rights Reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
-#import <UIKit/UIKit.h>
-
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-/**
- Return the average color of an image in a particular region.
-
- The region will be intersected with the image's bounds. If the resulting region is empty (or the
- input region was null) then this function returns nil.
-
- @param image The image to examine.
- @param region The region of the image to average, or CGRectInfinite for the entire image.
- @return The average color, or nil if the region was invalid.
- */
-UIColor *MDFAverageColorOfOpaqueImage(UIImage *image, CGRect region);
-
-#if defined __cplusplus
-} // extern "C"
-#endif
diff --git a/src/private/MDFImageCalculations.m b/src/private/MDFImageCalculations.m
deleted file mode 100644
index d554614..0000000
--- a/src/private/MDFImageCalculations.m
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- Copyright 2016-present Google Inc. All Rights Reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
-#import "MDFImageCalculations.h"
-
-UIColor *MDFAverageColorOfOpaqueImage(UIImage *image, CGRect region) {
- CGImageRef imageRef = image.CGImage;
- CGImageRef cropped = CGImageCreateWithImageInRect(imageRef, region);
-
- // Empty/null regions will cause cropped to be nil.
- if (!cropped) {
- return nil;
- }
-
- UIGraphicsBeginImageContext(CGSizeMake(1, 1));
-
- uint8_t argb[4];
- CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
- CGContextRef context =
- CGBitmapContextCreate(argb, // data
- 1, // width
- 1, // height
- 8, // Bits per component
- 4, // Bytes per row
- colorspace, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big);
- CGColorSpaceRelease(colorspace);
- CGContextSetInterpolationQuality(context, kCGInterpolationMedium);
- CGContextSetBlendMode(context, kCGBlendModeCopy);
- CGContextDrawImage(context, CGRectMake(0, 0, 1, 1), cropped);
- CGContextRelease(context);
- CGImageRelease(cropped);
-
- CGFloat alpha = argb[0] / (CGFloat)255;
- CGFloat scale = alpha > 0 ? 1 / (alpha * 255) : 0;
- UIColor *color = [UIColor colorWithRed:scale * argb[1]
- green:scale * argb[2]
- blue:scale * argb[3]
- alpha:alpha];
- UIGraphicsEndImageContext();
- return color;
-}