UGCKitVideoEffectColorPalette.m 1.2 KB

1234567891011121314151617181920212223242526272829
  1. // Copyright (c) 2019 Tencent. All rights reserved.
  2. #import "UGCKitVideoEffectColorPalette.h"
  3. #import <Foundation/Foundation.h>
  4. #define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
  5. green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
  6. blue:((float)(rgbValue & 0xFF))/255.0 \
  7. alpha:1.0]
  8. UIColor * UGCKitVideoEffectColorPaletteColorAtIndex(NSUInteger index) {
  9. NSCAssert([NSThread isMainThread], @"This class is designed to run on main thread.");
  10. NSUInteger preset[] = {0xEC5F9B, 0xEC8435, 0x1FBCB6, 0x449FF3, 0x6EA745};
  11. size_t size = sizeof(preset) / sizeof(preset[0]);
  12. if (index < size) {
  13. return UIColorFromRGB(preset[index]);
  14. }
  15. CGFloat hue = (index * 37) % 360 / 360.0;
  16. UIColor *color = [UIColor colorWithHue:hue saturation:0.4 + 0.04 * (index % 10) brightness:0.5 + 0.04 * (index%10) alpha:1];
  17. // CGFloat r,g,b;
  18. // [color getRed:&r green:&g blue:&b alpha:NULL];
  19. // NSLog(@"index: %d, color: #%X%X%X", (int)index,(int)(r*255),(int)(g*255),(int)(b*255));
  20. return color;
  21. }