Build native card inspector and secure state; hide manual analysis and unify automatic follow (validation in progress)

这个提交包含在:
dayu 于 2026-10-21 22:45:37 +08:00 提交
1 父节点 5793e3de49
当前提交 f4c0d608a4
20 个文件已更改
+1492 -236

没有与搜索条件相匹配的文件

+26 -18
查看文件
@@ -63,11 +63,13 @@
"/Localized: Plugin/InfoPlist.strings",
"/Localized: Plugin/Localizable.strings",
Plugin/beatygrilPlugIn.m,
Plugin/Info.plist,
Plugin/main.m,
Plugin/PGBeautyRenderer.m,
Plugin/PGFaceProcessor.m,
Plugin/PGFaceSelectOSC.m,
Plugin/Info.plist,
Plugin/main.m,
Plugin/PGInspectorState.m,
Plugin/PGInspectorView.m,
"Wrapper Application/Info.plist",
);
target = 6945FC8A3088B7220013E108 /* Wrapper Application */;
@@ -306,11 +308,11 @@
6945FCCD3088B7220013E108 /* Debug configuration for PBXNativeTarget "XPC Service" */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Manual;
CODE_SIGN_INJECT_BASE_ENTITLEMENTS = NO;
CODE_SIGN_IDENTITY = "Developer ID Application";
ENABLE_HARDENED_RUNTIME = YES;
CODE_SIGN_INJECT_BASE_ENTITLEMENTS = NO;
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = B3W25FX5H5;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
INFOPLIST_FILE = beatygril/Plugin/Info.plist;
@@ -329,11 +331,11 @@
6945FCCE3088B7220013E108 /* Release configuration for PBXNativeTarget "XPC Service" */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Manual;
CODE_SIGN_INJECT_BASE_ENTITLEMENTS = NO;
CODE_SIGN_IDENTITY = "Developer ID Application";
ENABLE_HARDENED_RUNTIME = YES;
CODE_SIGN_INJECT_BASE_ENTITLEMENTS = NO;
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = B3W25FX5H5;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
INFOPLIST_FILE = beatygril/Plugin/Info.plist;
@@ -353,11 +355,11 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_ENTITLEMENTS = "beatygril/Wrapper Application/SandboxEntitlements.entitlements";
CODE_SIGN_STYLE = Manual;
CODE_SIGN_INJECT_BASE_ENTITLEMENTS = NO;
CODE_SIGN_IDENTITY = "Developer ID Application";
ENABLE_HARDENED_RUNTIME = YES;
CODE_SIGN_INJECT_BASE_ENTITLEMENTS = NO;
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = B3W25FX5H5;
ENABLE_HARDENED_RUNTIME = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
INFOPLIST_FILE = "beatygril/Wrapper Application/Info.plist";
PRODUCT_BUNDLE_IDENTIFIER = com.dayu.beatygril;
@@ -370,11 +372,11 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_ENTITLEMENTS = "beatygril/Wrapper Application/SandboxEntitlements.entitlements";
CODE_SIGN_STYLE = Manual;
CODE_SIGN_INJECT_BASE_ENTITLEMENTS = NO;
CODE_SIGN_IDENTITY = "Developer ID Application";
ENABLE_HARDENED_RUNTIME = YES;
CODE_SIGN_INJECT_BASE_ENTITLEMENTS = NO;
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = B3W25FX5H5;
ENABLE_HARDENED_RUNTIME = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
INFOPLIST_FILE = "beatygril/Wrapper Application/Info.plist";
PRODUCT_BUNDLE_IDENTIFIER = com.dayu.beatygril;
@@ -387,9 +389,11 @@
isa = XCBuildConfiguration;
buildSettings = {
ADDITIONAL_SDKS = /Library/Developer/SDKs/FxPlug.sdk;
ARCHS = "arm64 x86_64";
ONLY_ACTIVE_ARCH = NO;
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = (
arm64,
x86_64,
);
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
@@ -448,6 +452,7 @@
MACOSX_DEPLOYMENT_TARGET = 13.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = NO;
SDKROOT = macosx;
SWIFT_VERSION = 5;
};
@@ -457,9 +462,11 @@
isa = XCBuildConfiguration;
buildSettings = {
ADDITIONAL_SDKS = /Library/Developer/SDKs/FxPlug.sdk;
ARCHS = "arm64 x86_64";
ONLY_ACTIVE_ARCH = NO;
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = (
arm64,
x86_64,
);
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
@@ -512,6 +519,7 @@
MACOSX_DEPLOYMENT_TARGET = 13.0;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = NO;
SDKROOT = macosx;
SWIFT_VERSION = 5;
};
+4 -4
查看文件
@@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>1.0.6</string>
<string>1.1.0</string>
<key>CFBundleVersion</key>
<string>8</string>
<string>9</string>
<key>NSHumanReadableCopyright</key>
<string></string>
<key>PlugInKit</key>
@@ -72,7 +72,7 @@
<key>uuid</key>
<string>FB14B0E6-59B2-4836-916F-CD0C559E9241</string>
<key>version</key>
<string>1.0.6</string>
<string>1.1.0</string>
</dict>
<dict>
<key>className</key>
@@ -84,7 +84,7 @@
<key>uuid</key>
<string>E0E432C8-3D71-4ABA-B006-E7F519E06C87</string>
<key>version</key>
<string>1.0.6</string>
<string>1.1.0</string>
<key>protocolNames</key>
<array>
<string>FxOnScreenControl</string>
@@ -0,0 +1,42 @@
#import <Foundation/Foundation.h>
#import <FxPlug/FxPlugSDK.h>
#import "PGBeautyTypes.h"
#import "PGParameterIDs.h"
NS_ASSUME_NONNULL_BEGIN
/// The descriptor list is shared by UI, persistence and render settings.
/// Keys: id, name, section (smooth/color/shape/more), kind
/// (slider/toggle/preset/master), min, max, default, format, bypass.
FOUNDATION_EXPORT NSArray<NSDictionary *> *PGInspectorControls(void);
FOUNDATION_EXPORT NSDictionary * _Nullable PGInspectorDescriptor(UInt32 identifier);
@interface PGInspectorState : NSObject <NSSecureCoding, NSCopying, FxCustomParameterInterpolation_v2>
@property (nonatomic, copy, readonly) NSDictionary<NSNumber *, NSNumber *> *values;
@property (nonatomic, copy, readonly) NSSet<NSNumber *> *disabledParameters;
/// An untouched panel must not replace parameters from an existing document.
@property (nonatomic, readonly) BOOL hasEdits;
+ (instancetype)stateWithValues:(NSDictionary *)values disabledParameters:(NSSet *)disabled hasEdits:(BOOL)edited;
- (double)valueForParameter:(UInt32)identifier;
- (BOOL)isParameterEnabled:(UInt32)identifier;
@end
FOUNDATION_EXPORT PGBeautySettings PGSettingsWithInspectorState(PGBeautySettings settings, PGInspectorState * _Nullable state);
/// All arbitrary-time FxPlug parameter access is bracketed by host actions.
/// The published custom object owns the full UI state, so FCP save/undo does
/// not depend on unpublished parameters being mirrored by the template.
@interface PGInspectorController : NSObject
@property (nonatomic, strong, readonly) PGInspectorState *state;
@property (nonatomic, readonly) BOOL available;
@property (nonatomic, copy, readonly) NSString *statusMessage;
- (instancetype)initWithAPIManager:(id<PROAPIAccessing>)manager;
- (void)refresh;
- (void)beginInteraction;
- (void)endInteraction;
- (BOOL)setValue:(double)value forParameter:(UInt32)identifier;
- (BOOL)toggleEnabledForParameter:(UInt32)identifier;
- (BOOL)resetParameter:(UInt32)identifier;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,224 @@
#import "PGInspectorState.h"
#import <math.h>
#import <stddef.h>
NSArray<NSDictionary *> *PGInspectorControls(void) {
static NSArray *controls; static dispatch_once_t once;
dispatch_once(&once, ^{
PGBeautySettings defaults=PGBeautyDefaults();
NSMutableArray *items=[NSMutableArray new];
#define ITEM(ID,NAME,FIELD,SECTION,KIND,FORMAT,MIN,MAX,BYPASS,STORAGE) \
[items addObject:@{@"id":@(ID),@"name":@NAME,@"section":@SECTION,@"kind":@KIND,@"format":@FORMAT,@"min":@(MIN),@"max":@(MAX),@"default":@(defaults.FIELD),@"bypass":@(BYPASS),@"offset":@(offsetof(PGBeautySettings,FIELD)),@"storage":@STORAGE}]
ITEM(PGSmoothingEnabled,"磨皮",featureProtection,"smooth","master","integer",0,1,NO,"master");
ITEM(PGMidtone,"局部磨皮",midtoneDetail,"smooth","slider","percent",0,1,YES,"float");
ITEM(PGHighPass,"全局磨皮",highPassDetail,"smooth","slider","percent",0,1,YES,"float");
ITEM(PGFeatureProtect,"五官保护",featureProtection,"smooth","toggle","integer",0,1,NO,"uint");
ITEM(PGColorEnabled,"美白",featureProtection,"color","master","integer",0,1,NO,"master");
ITEM(PGTonePreset,"肤色",skinTonePreset,"color","preset","integer",0,6,NO,"uint");
NSMutableDictionary *preset=[items.lastObject mutableCopy];
preset[@"options"]=@[@"原色",@"自然白",@"冷白",@"暖白",@"红润白",@"小麦",@"古铜"];items[items.count-1]=preset;
ITEM(PGBrightness,"肤色亮度",skinBrightness,"color","slider","percent",0,1,YES,"float");
ITEM(PGTeeth,"白牙",teethWhitening,"color","slider","percent",0,1,YES,"float");
ITEM(PGHue,"皮肤色相",skinHue,"color","slider","degrees",-30,30,YES,"float");
ITEM(PGShapeEnabled,"瘦脸",featureProtection,"shape","master","integer",0,1,NO,"master");
ITEM(PGTrackBoxes,"人脸框预览",showTrackBox,"shape","toggle","integer",0,1,NO,"uint");
ITEM(PGFastMulti,"多人模式",fastMultiFace,"shape","toggle","integer",0,1,NO,"uint");
ITEM(PGJumpGuard,"防跳脸范围",faceJumpGuardRange,"shape","slider","percent",1,4,NO,"float");
ITEM(PGThin,"瘦脸",faceThin,"shape","slider","signed",0,1,YES,"float");
ITEM(PGBigEye,"大眼",faceBigEye,"shape","slider","signed",0,1,YES,"float");
ITEM(PGShort,"短脸",faceShort,"shape","slider","signed",-1,1,YES,"float");
ITEM(PGNarrow,"窄脸",faceNarrow,"shape","slider","signed",-1,1,YES,"float");
ITEM(PGChin,"下巴",faceChin,"shape","slider","signed",-1,1,YES,"float");
ITEM(PGVFace,"V脸",faceV,"shape","slider","signed",0,1,YES,"float");
ITEM(PGJaw,"下颌骨",faceJaw,"shape","slider","signed",0,1,YES,"float");
ITEM(PGCheekbone,"颧骨",faceCheekbone,"shape","slider","signed",0,1,YES,"float");
ITEM(PGSmallHead,"小头",faceSmallHead,"shape","slider","signed",0,1,YES,"float");
ITEM(PGSmallHeadRange,"小头范围",faceSmallHeadRange,"shape","slider","percent",0,1,NO,"float");
ITEM(PGAmount,"磨皮强度",amount,"more","slider","percent",0,1,YES,"float");
ITEM(PGRadius,"磨皮半径",radius,"more","slider","radius",1,30,NO,"float");
ITEM(PGSaturation,"肤色饱和度",skinSaturation,"more","slider","percent",-100,100,YES,"float");
ITEM(PGEvenTone,"均匀肤色",skinEvenTone,"more","slider","percent",0,1,YES,"float");
ITEM(PGEyeBright,"眼睛提亮",eyeBrightening,"more","slider","percent",0,1,YES,"float");
ITEM(PGSharpness,"锐化",sharpness,"more","slider","percent",0,1,YES,"float");
ITEM(PGMix,"整体混合",mix,"more","slider","percent",0,1,NO,"float");
#undef ITEM
controls=[items copy];
}); return controls;
}
NSDictionary *PGInspectorDescriptor(UInt32 identifier) {
for(NSDictionary *d in PGInspectorControls()) if([d[@"id"] unsignedIntValue]==identifier) return d;
return nil;
}
static double PGControlValue(id raw,NSDictionary *d) {
double value=[raw isKindOfClass:NSNumber.class]?[raw doubleValue]:[d[@"default"] doubleValue];
if(!isfinite(value)) value=[d[@"default"] doubleValue];
value=fmin([d[@"max"] doubleValue],fmax([d[@"min"] doubleValue],value));
if(![d[@"storage"] isEqual:@"float"]) value=round(value);
return value;
}
@implementation PGInspectorState
+ (BOOL)supportsSecureCoding {return YES;}
+ (instancetype)stateWithValues:(NSDictionary *)values disabledParameters:(NSSet *)disabled hasEdits:(BOOL)edited {
PGInspectorState *state=[self new]; NSMutableDictionary *safe=[NSMutableDictionary new];NSMutableSet *bypassed=[NSMutableSet new];
for(NSDictionary *d in PGInspectorControls()) {
NSNumber *key=d[@"id"];safe[key]=@(PGControlValue(values[key],d));
if([d[@"bypass"] boolValue] && [disabled containsObject:key]) [bypassed addObject:key];
}
state->_values=[safe copy];state->_disabledParameters=[bypassed copy];state->_hasEdits=edited;return state;
}
- (instancetype)init {if((self=[super init])) {_values=@{};_disabledParameters=[NSSet set];}return self;}
- (instancetype)initWithCoder:(NSCoder *)coder {
NSInteger version=[coder decodeIntegerForKey:@"schema"];
if(version!=1) return nil;
NSSet *classes=[NSSet setWithObjects:NSDictionary.class,NSNumber.class,nil];
NSDictionary *values=[coder decodeObjectOfClasses:classes forKey:@"values"];
NSSet *disabled=[coder decodeObjectOfClasses:[NSSet setWithObjects:NSSet.class,NSNumber.class,nil] forKey:@"disabled"];
return [PGInspectorState stateWithValues:values?:@{} disabledParameters:disabled?:[NSSet set] hasEdits:[coder decodeBoolForKey:@"edited"]];
}
- (void)encodeWithCoder:(NSCoder *)coder {
[coder encodeInteger:1 forKey:@"schema"];[coder encodeObject:_values forKey:@"values"];
[coder encodeObject:_disabledParameters forKey:@"disabled"];[coder encodeBool:_hasEdits forKey:@"edited"];
}
- (id)copyWithZone:(NSZone *)zone {return [PGInspectorState stateWithValues:_values disabledParameters:_disabledParameters hasEdits:_hasEdits];}
- (double)valueForParameter:(UInt32)identifier {NSDictionary *d=PGInspectorDescriptor(identifier);return d?PGControlValue(_values[@(identifier)],d):0;}
- (BOOL)isParameterEnabled:(UInt32)identifier {return ![_disabledParameters containsObject:@(identifier)];}
- (BOOL)isEqual:(id)object {
if(object==self)return YES;
if(![object isKindOfClass:PGInspectorState.class])return NO;
PGInspectorState *other=object;return _hasEdits==other.hasEdits && [_values isEqual:other.values] && [_disabledParameters isEqual:other.disabledParameters];
}
- (NSUInteger)hash {return _values.hash ^ _disabledParameters.hash ^ _hasEdits;}
- (NSObject<NSSecureCoding,NSCopying> *)interpolateBetween:(NSObject<NSSecureCoding,NSCopying> *)rightValue withWeight:(float)weight {
if(![rightValue isKindOfClass:PGInspectorState.class])return [self copy];
PGInspectorState *right=(PGInspectorState *)rightValue;double t=isfinite(weight)?fmin(1,fmax(0,weight)):0;
if(t==0)return [self copy];if(t==1)return [right copy];
if(!_hasEdits || !right.hasEdits)return [self copy];
NSMutableDictionary *values=[NSMutableDictionary new];
for(NSDictionary *d in PGInspectorControls()) {
UInt32 key=[d[@"id"] unsignedIntValue];double a=[self valueForParameter:key],b=[right valueForParameter:key];
// Menus, switches and enable masks hold the preceding key until the
// next key. Numeric slider values interpolate within their valid range.
values[@(key)]=[d[@"storage"] isEqual:@"float"]?@(a+(b-a)*t):@(a);
}
return [PGInspectorState stateWithValues:values disabledParameters:_disabledParameters hasEdits:_hasEdits||right.hasEdits];
}
@end
PGBeautySettings PGSettingsWithInspectorState(PGBeautySettings s,PGInspectorState *state) {
if(!state.hasEdits)return s;
for(NSDictionary *d in PGInspectorControls()) {
NSString *storage=d[@"storage"];if([storage isEqual:@"master"])continue;
UInt32 key=[d[@"id"] unsignedIntValue];double value=[state valueForParameter:key];
if(![state isParameterEnabled:key]) value=0;
size_t offset=[d[@"offset"] unsignedIntegerValue];
if([storage isEqual:@"float"]) *(float *)((uint8_t *)&s+offset)=value;
else *(uint32_t *)((uint8_t *)&s+offset)=(uint32_t)value;
}
if(![state valueForParameter:PGSmoothingEnabled])s.amount=s.midtoneDetail=s.highPassDetail=0;
if(![state valueForParameter:PGColorEnabled]) {s.skinBrightness=s.skinHue=s.skinSaturation=s.skinEvenTone=s.teethWhitening=s.eyeBrightening=0;s.skinTonePreset=0;}
if(![state valueForParameter:PGShapeEnabled])s.faceThin=s.faceBigEye=s.faceShort=s.faceNarrow=s.faceChin=s.faceV=s.faceJaw=s.faceCheekbone=s.faceSmallHead=0;
return s;
}
@interface PGInspectorController ()
@property (nonatomic,strong,readwrite) PGInspectorState *state;
@property (nonatomic,readwrite) BOOL available;
@property (nonatomic,copy,readwrite) NSString *statusMessage;
@property (nonatomic,strong) id<PROAPIAccessing> manager;
@property (nonatomic,strong) id<FxCustomParameterActionAPI_v4> action;
@property (nonatomic) BOOL interacting;
@property (nonatomic) NSTimeInterval pendingUntil;
@end
@implementation PGInspectorController
- (instancetype)initWithAPIManager:(id<PROAPIAccessing>)manager {
if((self=[super init])){_manager=manager;_state=[PGInspectorState stateWithValues:@{} disabledParameters:[NSSet set] hasEdits:NO];_statusMessage=@"";}
return self;
}
- (BOOL)start {
if(_interacting)return YES;
_action=[_manager apiForProtocol:@protocol(FxCustomParameterActionAPI_v4)];
id retrieval=[_manager apiForProtocol:@protocol(FxParameterRetrievalAPI_v6)];
id setting=[_manager apiForProtocol:@protocol(FxParameterSettingAPI_v5)];
_available=_action && retrieval && setting;
if(!_available){_statusMessage=@"等待宿主连接";return NO;}
[_action startAction:self];_interacting=YES;return YES;
}
- (void)finish {if(_interacting){_interacting=NO;[_action endAction:self];_action=nil;}}
- (void)readAtTime:(CMTime)time {
id<FxParameterRetrievalAPI_v6> api=[_manager apiForProtocol:@protocol(FxParameterRetrievalAPI_v6)];
NSObject *object=nil;[api getCustomParameterValue:&object fromParameter:PGInspectorPanel atTime:time];
if([object isKindOfClass:PGInspectorState.class] && [(PGInspectorState *)object hasEdits]) {
PGInspectorState *host=(PGInspectorState *)object;
if([host isEqual:_state])_pendingUntil=0;
if(!_pendingUntil || NSDate.timeIntervalSinceReferenceDate>=_pendingUntil)_state=[host copy];
return;
}
if(_pendingUntil && NSDate.timeIntervalSinceReferenceDate<_pendingUntil)return;
NSMutableDictionary *values=[NSMutableDictionary new];
for(NSDictionary *d in PGInspectorControls()) {
UInt32 key=[d[@"id"] unsignedIntValue];double value=[d[@"default"] doubleValue];
if([d[@"kind"] isEqual:@"preset"]) {int menu=(int)value;if([api getIntValue:&menu fromParameter:key atTime:time])value=menu;}
else if([d[@"kind"] isEqual:@"toggle"] || [d[@"kind"] isEqual:@"master"]) {BOOL on=value!=0;if([api getBoolValue:&on fromParameter:key atTime:time])value=on;}
else [api getFloatValue:&value fromParameter:key atTime:time];
values[@(key)]=@(value);
}
_state=[PGInspectorState stateWithValues:values disabledParameters:[NSSet set] hasEdits:NO];
}
- (void)refresh {
if(_interacting)return;
if(![self start])return;
@try {[self readAtTime:[_action currentTime]];_statusMessage=@"";} @finally {[self finish];}
}
- (void)beginInteraction {
if(_interacting)return;
if([self start])[self readAtTime:[_action currentTime]];
}
- (void)endInteraction {[self finish];}
- (BOOL)commit:(PGInspectorState *)next {
if([next isEqual:_state] && _state.hasEdits)return YES;
id<FxParameterSettingAPI_v5> api=[_manager apiForProtocol:@protocol(FxParameterSettingAPI_v5)];
CMTime time=[_action currentTime];
// The published object is authoritative. Only mirror after its write was
// accepted; a rejected write must never leave half-applied hidden values.
if(![api setCustomParameterValue:next toParameter:PGInspectorPanel atTime:time]){_statusMessage=@"参数未能保存,请重试";return NO;}
for(NSDictionary *d in PGInspectorControls()) {
UInt32 key=[d[@"id"] unsignedIntValue];double value=[next valueForParameter:key];
if(![next isParameterEnabled:key])value=0;
double previous=[_state isParameterEnabled:key]?[_state valueForParameter:key]:0;
if(previous==value)continue;
if([d[@"kind"] isEqual:@"preset"]) [api setIntValue:(int)value toParameter:key atTime:time];
else if([d[@"kind"] isEqual:@"toggle"] || [d[@"kind"] isEqual:@"master"]) [api setBoolValue:value!=0 toParameter:key atTime:time];
else [api setFloatValue:value toParameter:key atTime:time];
}
_state=next;_pendingUntil=NSDate.timeIntervalSinceReferenceDate+.35;_statusMessage=@"";return YES;
}
- (BOOL)setValue:(double)value forParameter:(UInt32)identifier {
NSDictionary *d=PGInspectorDescriptor(identifier);if(!d || !isfinite(value))return NO;
BOOL owned=!_interacting;if(owned)[self beginInteraction];if(!_interacting)return NO;
BOOL ok=NO;@try {
NSMutableDictionary *values=[_state.values mutableCopy];values[@(identifier)]=@(PGControlValue(@(value),d));
ok=[self commit:[PGInspectorState stateWithValues:values disabledParameters:_state.disabledParameters hasEdits:YES]];
} @finally {if(owned)[self finish];}return ok;
}
- (BOOL)toggleEnabledForParameter:(UInt32)identifier {
NSDictionary *d=PGInspectorDescriptor(identifier);if(!d)return NO;
if([d[@"kind"] isEqual:@"master"] || [d[@"kind"] isEqual:@"toggle"])return [self setValue:![self.state valueForParameter:identifier] forParameter:identifier];
if(![d[@"bypass"] boolValue])return NO;
BOOL owned=!_interacting;if(owned)[self beginInteraction];if(!_interacting)return NO;
BOOL ok=NO;@try {
NSMutableSet *disabled=[_state.disabledParameters mutableCopy];NSNumber *key=@(identifier);
if([disabled containsObject:key])[disabled removeObject:key];else [disabled addObject:key];
ok=[self commit:[PGInspectorState stateWithValues:_state.values disabledParameters:disabled hasEdits:YES]];
} @finally {if(owned)[self finish];}return ok;
}
- (BOOL)resetParameter:(UInt32)identifier {
NSDictionary *d=PGInspectorDescriptor(identifier);if(!d)return NO;
BOOL owned=!_interacting;if(owned)[self beginInteraction];if(!_interacting)return NO;
BOOL ok=NO;@try {
NSMutableDictionary *values=[_state.values mutableCopy];values[@(identifier)]=d[@"default"];
NSMutableSet *disabled=[_state.disabledParameters mutableCopy];[disabled removeObject:@(identifier)];
ok=[self commit:[PGInspectorState stateWithValues:values disabledParameters:disabled hasEdits:YES]];
} @finally {if(owned)[self finish];}return ok;
}
- (void)dealloc {if(_interacting)[_action endAction:self];}
@end
@@ -0,0 +1,15 @@
#import <AppKit/AppKit.h>
#import "PGInspectorState.h"
NS_ASSUME_NONNULL_BEGIN
/// Native inspector controls. Host access belongs exclusively to the controller.
@interface PGInspectorView : NSView
@property (nonatomic, strong, readonly) PGInspectorController *controller;
- (instancetype)initWithAPIManager:(id<PROAPIAccessing>)manager;
/// Also permits a deterministic controller in an offscreen preview or test.
- (instancetype)initWithController:(PGInspectorController *)controller;
- (void)refreshFromHost;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,344 @@
#import "PGInspectorView.h"
#include <math.h>
static NSColor *PGUIColor(CGFloat r, CGFloat g, CGFloat b, CGFloat a) {
return [NSColor colorWithSRGBRed:r green:g blue:b alpha:a];
}
static NSColor *PGUIText(void) { return PGUIColor(.88,.91,.95,1); }
static NSColor *PGUIMuted(void) { return PGUIColor(.60,.65,.73,1); }
static NSTextField *PGUILabel(NSString *text, CGFloat size, NSFontWeight weight) {
NSTextField *label=[NSTextField labelWithString:text ?: @""];
label.font=[NSFont systemFontOfSize:size weight:weight]; label.textColor=PGUIText();
label.lineBreakMode=NSLineBreakByTruncatingTail; return label;
}
static CGFloat PGValueScale(NSDictionary *descriptor) {
return [descriptor[@"format"] isEqual:@"percent"] && [descriptor[@"max"] doubleValue]<=10 ? 100 : 1;
}
static NSString *PGFormattedValue(NSDictionary *descriptor, double value) {
NSString *format=descriptor[@"format"];
if ([format isEqual:@"percent"]) return [NSString stringWithFormat:@"%.0f%%",value*PGValueScale(descriptor)];
if ([format isEqual:@"degrees"]) return [NSString stringWithFormat:@"%+.0f°",value];
if ([format isEqual:@"signed"]) return [NSString stringWithFormat:@"%.2f",value];
if ([format isEqual:@"integer"]) return [NSString stringWithFormat:@"%.0f",value];
return [NSString stringWithFormat:@"%.1f",value];
}
@interface PGInspectorGlyphButton : NSButton
@property (nonatomic, copy) NSString *glyph;
@property (nonatomic, strong) NSColor *accent;
@property (nonatomic, strong) NSColor *swatch;
@end
@implementation PGInspectorGlyphButton
- (BOOL)isFlipped { return YES; }
- (void)drawRect:(NSRect)dirtyRect {
(void)dirtyRect; NSRect b=NSInsetRect(self.bounds,1,1);
CGFloat opacity=self.enabled?1:.35;
NSColor *accent=[self.accent colorWithAlphaComponent:opacity];
BOOL on=self.state==NSControlStateValueOn;
if ([self.glyph isEqual:@"swatch"]) {
NSRect circle=NSInsetRect(b,3,3);
[[(self.swatch ?: PGUIColor(.12,.19,.23,1)) colorWithAlphaComponent:opacity] setFill]; [[NSBezierPath bezierPathWithOvalInRect:circle] fill];
[[PGUIText() colorWithAlphaComponent:.25*opacity] setStroke];
NSBezierPath *ring=[NSBezierPath bezierPathWithOvalInRect:circle];ring.lineWidth=1;[ring stroke];
if (!self.swatch) {
[PGUIMuted() setStroke];NSBezierPath *slash=[NSBezierPath bezierPath];
[slash moveToPoint:NSMakePoint(NSMinX(circle)+4,NSMinY(circle)+4)];[slash lineToPoint:NSMakePoint(NSMaxX(circle)-4,NSMaxY(circle)-4)];slash.lineWidth=1.5;[slash stroke];
}
if(on) { [accent setStroke];NSBezierPath *selection=[NSBezierPath bezierPathWithOvalInRect:NSInsetRect(b,.5,.5)];selection.lineWidth=1.5;[selection stroke]; }
} else if ([self.glyph isEqual:@"switch"]) {
NSRect pill=NSInsetRect(b,1,3);
[(on?accent:PGUIColor(.20,.25,.34,opacity)) setFill];[[NSBezierPath bezierPathWithRoundedRect:pill xRadius:NSHeight(pill)/2 yRadius:NSHeight(pill)/2]fill];
CGFloat diameter=NSHeight(pill)-4;CGFloat x=on?NSMaxX(pill)-diameter-2:NSMinX(pill)+2;
[[NSColor colorWithWhite:.98 alpha:opacity]setFill];[[NSBezierPath bezierPathWithOvalInRect:NSMakeRect(x,NSMinY(pill)+2,diameter,diameter)]fill];
} else {
NSBezierPath *back=[NSBezierPath bezierPathWithRoundedRect:b xRadius:7 yRadius:7];
[[self.accent colorWithAlphaComponent:([self.glyph isEqual:@"eye"]?.055:.13)*opacity]setFill];[back fill];
if ([self.glyph isEqual:@"eye"]) {
[[self.accent colorWithAlphaComponent:.35*opacity]setStroke];back.lineWidth=.7;[back stroke];
NSPoint c=NSMakePoint(NSMidX(b),NSMidY(b));
NSBezierPath *eye=[NSBezierPath bezierPath];[eye moveToPoint:NSMakePoint(c.x-6,c.y)];
[eye curveToPoint:NSMakePoint(c.x+6,c.y) controlPoint1:NSMakePoint(c.x-3,c.y-5.5) controlPoint2:NSMakePoint(c.x+3,c.y-5.5)];
[eye curveToPoint:NSMakePoint(c.x-6,c.y) controlPoint1:NSMakePoint(c.x+3,c.y+5.5) controlPoint2:NSMakePoint(c.x-3,c.y+5.5)];eye.lineWidth=1.3;[accent setStroke];[eye stroke];
if(on){[accent setFill];[[NSBezierPath bezierPathWithOvalInRect:NSMakeRect(c.x-1.8,c.y-1.8,3.6,3.6)]fill];}
else{NSBezierPath *slash=[NSBezierPath bezierPath];[slash moveToPoint:NSMakePoint(c.x-6,c.y+6)];[slash lineToPoint:NSMakePoint(c.x+6,c.y-6)];slash.lineWidth=1.2;[slash stroke];}
} else {
NSString *symbol=[self.glyph isEqual:@"disclosure"]?(on?@"⌄":@"›"):@"↻";
NSFont *font=[NSFont systemFontOfSize:[self.glyph isEqual:@"disclosure"]?19:18 weight:NSFontWeightSemibold];
NSDictionary *attributes=@{NSFontAttributeName:font,NSForegroundColorAttributeName:[self.accent colorWithAlphaComponent:(on?1:.58)*opacity]};
NSSize size=[symbol sizeWithAttributes:attributes];[symbol drawAtPoint:NSMakePoint(NSMidX(b)-size.width/2,NSMidY(b)-size.height/2)withAttributes:attributes];
}
}
if(self.window.firstResponder==self){[[self.accent colorWithAlphaComponent:.8]setStroke];NSBezierPath *focus=[NSBezierPath bezierPathWithRoundedRect:NSInsetRect(self.bounds,.5,.5) xRadius:7 yRadius:7];focus.lineWidth=1;[focus stroke];}
}
- (void)setState:(NSControlStateValue)state { [super setState:state];self.needsDisplay=YES; }
- (void)setEnabled:(BOOL)enabled { [super setEnabled:enabled];self.needsDisplay=YES; }
@end
static PGInspectorGlyphButton *PGUIButton(NSString *glyph, NSColor *accent, id target, SEL action) {
PGInspectorGlyphButton *button=[[PGInspectorGlyphButton alloc]initWithFrame:NSZeroRect];
button.glyph=glyph;button.accent=accent;button.bordered=NO;button.title=@"";
[button setButtonType:([glyph isEqual:@"eye"]||[glyph isEqual:@"switch"]||[glyph isEqual:@"disclosure"]||[glyph isEqual:@"swatch"])?NSButtonTypePushOnPushOff:NSButtonTypeMomentaryPushIn];
button.target=target;button.action=action;button.focusRingType=NSFocusRingTypeExterior;
return button;
}
@interface PGInspectorSliderCell : NSSliderCell
@property (nonatomic, strong) NSColor *accent;
@end
@implementation PGInspectorSliderCell
- (void)drawBarInside:(NSRect)rect flipped:(BOOL)flipped {
(void)flipped;NSRect bar=NSMakeRect(NSMinX(rect),NSMidY(rect)-2,NSWidth(rect),4);
[PGUIColor(.08,.13,.20,self.enabled?1:.5)setFill];NSBezierPath *track=[NSBezierPath bezierPathWithRoundedRect:bar xRadius:2 yRadius:2];[track fill];
[[self.accent colorWithAlphaComponent:.18]setStroke];track.lineWidth=.7;[track stroke];
double range=self.maxValue-self.minValue;if(range<=0)return;
CGFloat from=self.minValue<0?(CGFloat)((0-self.minValue)/range):0;
CGFloat to=(CGFloat)((self.doubleValue-self.minValue)/range);
NSRect fill=NSMakeRect(NSMinX(bar)+MIN(from,to)*NSWidth(bar),NSMinY(bar),fabs(to-from)*NSWidth(bar),NSHeight(bar));
[[self.accent colorWithAlphaComponent:self.enabled?.85:.23]setFill];[[NSBezierPath bezierPathWithRoundedRect:fill xRadius:2 yRadius:2]fill];
}
- (void)drawKnob:(NSRect)knobRect {
CGFloat d=12;NSRect r=NSMakeRect(NSMidX(knobRect)-d/2,NSMidY(knobRect)-d/2,d,d);
[[self.accent colorWithAlphaComponent:self.enabled?.22:.08]setFill];[[NSBezierPath bezierPathWithOvalInRect:NSInsetRect(r,-2,-2)]fill];
[[NSColor colorWithWhite:.97 alpha:self.enabled?1:.5]setFill];NSBezierPath *knob=[NSBezierPath bezierPathWithOvalInRect:r];[knob fill];
[[self.accent colorWithAlphaComponent:self.enabled?.85:.25]setStroke];knob.lineWidth=1;[knob stroke];
}
- (CGFloat)knobThickness { return 14; }
@end
@interface PGInspectorSlider : NSSlider
@property (nonatomic, copy) void (^interactionBegan)(void);
@property (nonatomic, copy) void (^interactionEnded)(void);
@end
@implementation PGInspectorSlider
- (void)mouseDown:(NSEvent *)event {
if(!self.enabled)return;if(self.interactionBegan)self.interactionBegan();
@try{[super mouseDown:event];}@finally{if(self.interactionEnded)self.interactionEnded();}
}
- (void)keyDown:(NSEvent *)event {
if(self.interactionBegan)self.interactionBegan();
@try{[super keyDown:event];}@finally{if(self.interactionEnded)self.interactionEnded();}
}
@end
@interface PGInspectorNumberCell : NSTextFieldCell
@end
@implementation PGInspectorNumberCell
- (NSRect)drawingRectForBounds:(NSRect)bounds {
NSRect rect=[super drawingRectForBounds:bounds];CGFloat height=[self cellSizeForBounds:bounds].height;
if(NSHeight(rect)>height){rect.origin.y+=(NSHeight(rect)-height)*.5;rect.size.height=height;}return rect;
}
@end
@interface PGInspectorNumberField : NSTextField
@end
@implementation PGInspectorNumberField
+ (Class)cellClass { return PGInspectorNumberCell.class; }
@end
@class PGInspectorRow;
@interface PGInspectorCard : NSView
@property (nonatomic, strong) NSColor *accent;
@property (nonatomic, copy) NSString *heading;
@property (nonatomic, strong) NSTextField *titleLabel;
@property (nonatomic, strong) PGInspectorGlyphButton *master;
@property (nonatomic, copy) NSArray<PGInspectorRow *> *rows;
@property (nonatomic) BOOL expanded;
- (CGFloat)heightForWidth:(CGFloat)width;
@end
@interface PGInspectorView ()
@property (nonatomic, strong, readwrite) PGInspectorController *controller;
- (void)reloadControls;
- (void)beginControlInteraction;
- (void)endControlInteraction;
- (void)writeValue:(double)value parameter:(UInt32)identifier;
@end
@interface PGInspectorRow : NSView <NSTextFieldDelegate>
@property (nonatomic, weak) PGInspectorView *inspector;
@property (nonatomic, copy) NSDictionary *descriptor;
@property (nonatomic, strong) NSColor *accent;
@property (nonatomic, strong) NSTextField *label;
@property (nonatomic, strong) NSTextField *valueField;
@property (nonatomic, strong) NSTextField *hint;
@property (nonatomic, strong) PGInspectorSlider *slider;
@property (nonatomic, strong) PGInspectorGlyphButton *eye;
@property (nonatomic, strong) PGInspectorGlyphButton *reset;
@property (nonatomic, strong) PGInspectorGlyphButton *toggle;
@property (nonatomic, copy) NSArray<PGInspectorGlyphButton *> *swatches;
- (instancetype)initWithDescriptor:(NSDictionary *)descriptor accent:(NSColor *)accent inspector:(PGInspectorView *)inspector;
- (CGFloat)heightForWidth:(CGFloat)width;
- (void)reloadState:(PGInspectorState *)state master:(BOOL)master available:(BOOL)available;
@end
@implementation PGInspectorRow
- (BOOL)isFlipped { return YES; }
- (instancetype)initWithDescriptor:(NSDictionary *)descriptor accent:(NSColor *)accent inspector:(PGInspectorView *)inspector {
if((self=[super initWithFrame:NSZeroRect])) {
_descriptor=[descriptor copy];_accent=accent;_inspector=inspector;
self.identifier=[NSString stringWithFormat:@"pg.parameter.%@",descriptor[@"id"]];
NSString *name=descriptor[@"name"];_label=PGUILabel(name,12,NSFontWeightSemibold);[self addSubview:_label];
NSString *kind=descriptor[@"kind"];
if([descriptor[@"bypass"]boolValue]){
_eye=PGUIButton(@"eye",accent,self,@selector(toggleEnabled:));_eye.toolTip=[@"启用 / 停用 · " stringByAppendingString:name];_eye.accessibilityLabel=_eye.toolTip;[self addSubview:_eye];
}
if([kind isEqual:@"preset"]){
NSArray *colors=@[NSNull.null,PGUIColor(.95,.87,.80,1),PGUIColor(.88,.88,.95,1),PGUIColor(1,.86,.72,1),PGUIColor(.99,.78,.75,1),PGUIColor(.76,.57,.39,1),PGUIColor(.48,.32,.22,1)];
NSArray *options=descriptor[@"options"] ?: @[];NSMutableArray *buttons=[NSMutableArray new];
for(NSUInteger i=0;i<7;i++){
PGInspectorGlyphButton *button=PGUIButton(@"swatch",accent,self,@selector(selectPreset:));button.tag=i;button.swatch=i?colors[i]:nil;
button.toolTip=i<options.count?options[i]:[NSString stringWithFormat:@"%@ %lu",name,(unsigned long)i];button.accessibilityLabel=button.toolTip;
[self addSubview:button];[buttons addObject:button];
}_swatches=[buttons copy];
}else{
_reset=PGUIButton(@"reset",accent,self,@selector(resetValue:));_reset.toolTip=[@"重置 · "stringByAppendingString:name];_reset.accessibilityLabel=_reset.toolTip;[self addSubview:_reset];
if([kind isEqual:@"toggle"]){
_toggle=PGUIButton(@"switch",accent,self,@selector(toggleValue:));_toggle.accessibilityLabel=name;[self addSubview:_toggle];
_hint=PGUILabel(@"",10,NSFontWeightMedium);_hint.textColor=PGUIMuted();_hint.alignment=NSTextAlignmentRight;[self addSubview:_hint];
_label.lineBreakMode=NSLineBreakByWordWrapping;_label.maximumNumberOfLines=2;
}else{
_slider=[[PGInspectorSlider alloc]initWithFrame:NSZeroRect];PGInspectorSliderCell *cell=[PGInspectorSliderCell new];cell.accent=accent;_slider.cell=cell;
_slider.minValue=[descriptor[@"min"]doubleValue];_slider.maxValue=[descriptor[@"max"]doubleValue];_slider.continuous=YES;_slider.target=self;_slider.action=@selector(sliderChanged:);_slider.accessibilityLabel=name;
__weak PGInspectorView *weakInspector=inspector;
_slider.interactionBegan=^{[weakInspector beginControlInteraction];};_slider.interactionEnded=^{[weakInspector endControlInteraction];};[self addSubview:_slider];
_valueField=[[PGInspectorNumberField alloc]initWithFrame:NSZeroRect];_valueField.font=[NSFont monospacedDigitSystemFontOfSize:11 weight:NSFontWeightSemibold];_valueField.textColor=PGUIText();_valueField.alignment=NSTextAlignmentCenter;
_valueField.bordered=NO;_valueField.bezeled=NO;_valueField.drawsBackground=NO;_valueField.backgroundColor=PGUIColor(.14,.19,.26,1);_valueField.wantsLayer=YES;_valueField.layer.backgroundColor=_valueField.backgroundColor.CGColor;_valueField.layer.cornerRadius=7;_valueField.layer.borderWidth=.7;_valueField.layer.borderColor=[accent colorWithAlphaComponent:.24].CGColor;
_valueField.target=self;_valueField.action=@selector(numberCommitted:);_valueField.delegate=self;_valueField.accessibilityLabel=[name stringByAppendingString:@"数值"];[self addSubview:_valueField];
}
}
NSString *key=[descriptor[@"id"]stringValue];
_slider.identifier=[@"pg.value."stringByAppendingString:key];_valueField.identifier=[@"pg.number."stringByAppendingString:key];
_toggle.identifier=[@"pg.toggle."stringByAppendingString:key];_eye.identifier=[@"pg.enable."stringByAppendingString:key];_reset.identifier=[@"pg.reset."stringByAppendingString:key];
}return self;
}
- (CGFloat)heightForWidth:(CGFloat)width {
if(_swatches)return 46;
if(_toggle)return width<310 && [_descriptor[@"name"]length]>12 ? 48 : 36;
return width<310?52:36;
}
- (void)layout {
[super layout];CGFloat w=NSWidth(self.bounds),h=NSHeight(self.bounds);BOOL narrow=w<310;
CGFloat labelX=_eye?25:0;
_eye.frame=NSMakeRect(0,6,20,22);
if(_swatches){
_label.frame=NSMakeRect(labelX,14,33,20);CGFloat x=labelX+37;CGFloat d=MIN(28,MAX(12,(w-x-24)/7));CGFloat gap=MIN(8,MAX(0,(w-x-7*d)/6));
for(NSUInteger i=0;i<_swatches.count;i++)_swatches[i].frame=NSMakeRect(x+i*(d+gap),7,d,d);return;
}
_reset.frame=NSMakeRect(w-23,6,23,23);
if(_toggle){
CGFloat switchX=w-76;_toggle.frame=NSMakeRect(switchX,4+(h-36)/2,46,28);_hint.frame=NSMakeRect(switchX-39,10+(h-36)/2,34,18);
_label.frame=NSMakeRect(labelX,h>36?3:9,MAX(20,switchX-labelX-42),h>36?42:22);return;
}
CGFloat fieldW=49,fieldX=w-23-7-fieldW;_valueField.frame=NSMakeRect(fieldX,5,fieldW,25);
if(narrow){_label.frame=NSMakeRect(labelX,8,MAX(20,fieldX-labelX-6),22);_slider.frame=NSMakeRect(labelX,29,MAX(20,w-labelX-30),18);}
else{CGFloat labelW=MIN(116,MAX(71,w*.29));_label.frame=NSMakeRect(labelX,9,labelW,21);CGFloat start=labelX+labelW+5;_slider.frame=NSMakeRect(start,7,MAX(20,fieldX-start-8),22);}
}
- (void)reloadState:(PGInspectorState *)state master:(BOOL)master available:(BOOL)available {
UInt32 identifier=[_descriptor[@"id"]unsignedIntValue];double value=[state valueForParameter:identifier];BOOL enabled=[state isParameterEnabled:identifier];
_label.alphaValue=master&&enabled?1:.5;_eye.state=enabled?NSControlStateValueOn:NSControlStateValueOff;_eye.enabled=available&&master;
_reset.enabled=available;_reset.state=fabs(value-[_descriptor[@"default"]doubleValue])>.000001?NSControlStateValueOn:NSControlStateValueOff;
_slider.enabled=available&&master&&enabled;_slider.doubleValue=value;
_valueField.enabled=available&&master&&enabled;if(!_valueField.currentEditor)_valueField.stringValue=PGFormattedValue(_descriptor,value);
_toggle.enabled=available&&master&&enabled;_toggle.state=value>.5?NSControlStateValueOn:NSControlStateValueOff;
UInt32 identifierForHint=[_descriptor[@"id"]unsignedIntValue];
_hint.stringValue=identifierForHint==PGFastMulti?(value>.5?@"多人":@"单人"):identifierForHint==PGTrackBoxes?(value>.5?@"预览中":@"隐藏"):(value>.5?@"开启":@"关闭");
for(NSUInteger i=0;i<_swatches.count;i++){_swatches[i].enabled=available&&master&&enabled;_swatches[i].state=i==(NSUInteger)llround(value)?NSControlStateValueOn:NSControlStateValueOff;}
}
- (void)sliderChanged:(NSSlider *)sender { [_inspector writeValue:sender.doubleValue parameter:[_descriptor[@"id"]unsignedIntValue]]; }
- (void)toggleValue:(NSButton *)sender { [_inspector writeValue:sender.state==NSControlStateValueOn?1:0 parameter:[_descriptor[@"id"]unsignedIntValue]]; }
- (void)selectPreset:(NSButton *)sender { [_inspector writeValue:sender.tag parameter:[_descriptor[@"id"]unsignedIntValue]]; }
- (void)toggleEnabled:(id)sender { (void)sender;[_inspector.controller toggleEnabledForParameter:[_descriptor[@"id"]unsignedIntValue]];[_inspector reloadControls]; }
- (void)resetValue:(id)sender { (void)sender;[_inspector.controller resetParameter:[_descriptor[@"id"]unsignedIntValue]];[_inspector reloadControls]; }
- (void)numberCommitted:(id)sender {
(void)sender;NSString *text=[_valueField.stringValue stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];
if([text hasSuffix:@"%"]||[text hasSuffix:@"°"])text=[text substringToIndex:text.length-1];
NSNumber *number=nil;
for(NSLocale *locale in @[NSLocale.currentLocale,[NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"]]){
NSScanner *scanner=[NSScanner scannerWithString:text];scanner.locale=locale;double parsed;
if([scanner scanDouble:&parsed]&&scanner.isAtEnd){number=@(parsed);break;}
}
if(number&&isfinite(number.doubleValue)){
double value=number.doubleValue/PGValueScale(_descriptor);value=fmin([_descriptor[@"max"]doubleValue],fmax([_descriptor[@"min"]doubleValue],value));
if(fabs(value-[_inspector.controller.state valueForParameter:[_descriptor[@"id"]unsignedIntValue]])>.0000001)[_inspector writeValue:value parameter:[_descriptor[@"id"]unsignedIntValue]];
}else NSBeep();
_valueField.stringValue=PGFormattedValue(_descriptor,[_inspector.controller.state valueForParameter:[_descriptor[@"id"]unsignedIntValue]]);
}
- (void)controlTextDidEndEditing:(NSNotification *)notification { (void)notification;[self numberCommitted:_valueField]; }
@end
@implementation PGInspectorCard
- (BOOL)isFlipped { return YES; }
- (CGFloat)heightForWidth:(CGFloat)width {
if(!_expanded)return 44;CGFloat height=49;for(PGInspectorRow *row in _rows){height+=[row heightForWidth:MAX(0,width-24)];if([row.descriptor[@"id"]unsignedIntValue]==PGJumpGuard)height+=8;}return height+7;
}
- (void)layout {
[super layout];CGFloat w=NSWidth(self.bounds);_titleLabel.frame=NSMakeRect(25,13,MAX(70,w-80),22);_master.frame=NSMakeRect(w-39,10,25,25);
CGFloat y=49;for(PGInspectorRow *row in _rows){row.hidden=!_expanded;if(!_expanded)continue;CGFloat h=[row heightForWidth:w-24];row.frame=NSMakeRect(12,y,w-24,h);y+=h;if([row.descriptor[@"id"]unsignedIntValue]==PGJumpGuard)y+=8;}
}
- (void)drawRect:(NSRect)dirtyRect {
(void)dirtyRect;NSBezierPath *shape=[NSBezierPath bezierPathWithRoundedRect:NSInsetRect(self.bounds,.5,.5) xRadius:13 yRadius:13];
[NSGraphicsContext saveGraphicsState];[shape addClip];NSGradient *gradient=[[NSGradient alloc]initWithStartingColor:[_accent blendedColorWithFraction:.87 ofColor:PGUIColor(.09,.14,.21,1)] endingColor:PGUIColor(.055,.085,.14,1)];[gradient drawInRect:self.bounds angle:90];[NSGraphicsContext restoreGraphicsState];
[[_accent colorWithAlphaComponent:.22]setStroke];shape.lineWidth=.8;[shape stroke];
NSRect pill=NSMakeRect(12,10,MAX(53,[_heading length]*13+20),25);[[_accent colorWithAlphaComponent:.10]setFill];NSBezierPath *p=[NSBezierPath bezierPathWithRoundedRect:pill xRadius:8 yRadius:8];[p fill];[[_accent colorWithAlphaComponent:.32]setStroke];p.lineWidth=.7;[p stroke];
if(_expanded){[[PGUIMuted() colorWithAlphaComponent:.20]setStroke];NSBezierPath *line=[NSBezierPath bezierPath];[line moveToPoint:NSMakePoint(12,43)];[line lineToPoint:NSMakePoint(NSWidth(self.bounds)-12,43)];line.lineWidth=.5;[line stroke];
for(PGInspectorRow *row in _rows)if([row.descriptor[@"id"]unsignedIntValue]==PGJumpGuard){CGFloat y=NSMaxY(row.frame)+4;[line removeAllPoints];[line moveToPoint:NSMakePoint(12,y)];[line lineToPoint:NSMakePoint(NSWidth(self.bounds)-12,y)];[line stroke];}
}
}
@end
@implementation PGInspectorView {
NSArray<PGInspectorCard *> *_cards;
PGInspectorCard *_more;
NSTextField *_brand,*_website,*_status;
NSTimer *_refreshTimer;
NSUInteger _interactionDepth;
}
- (instancetype)initWithAPIManager:(id<PROAPIAccessing>)manager { return [self initWithController:[[PGInspectorController alloc]initWithAPIManager:manager]]; }
- (instancetype)initWithController:(PGInspectorController *)controller {
if((self=[super initWithFrame:NSMakeRect(0,0,320,100)])){
_controller=controller;self.appearance=[NSAppearance appearanceNamed:NSAppearanceNameDarkAqua];
NSArray *sections=@[@"smooth",@"color",@"shape",@"more"],*headings=@[@"磨皮",@"美白",@"瘦脸",@"更多设置"];
NSArray *colors=@[PGUIColor(.28,.83,.96,1),PGUIColor(.34,.89,.84,1),PGUIColor(.59,.69,.98,1),PGUIColor(.54,.64,.76,1)];
NSMutableArray *cards=[NSMutableArray new];
for(NSUInteger index=0;index<sections.count;index++){
NSString *section=sections[index];PGInspectorCard *card=[[PGInspectorCard alloc]initWithFrame:NSZeroRect];card.accent=colors[index];card.heading=headings[index];card.expanded=index<3;
card.titleLabel=PGUILabel(headings[index],12,NSFontWeightSemibold);card.titleLabel.textColor=colors[index];[card addSubview:card.titleLabel];NSMutableArray *rows=[NSMutableArray new];
for(NSDictionary *descriptor in PGInspectorControls()){
if(![descriptor[@"section"]isEqual:section])continue;
if([descriptor[@"kind"]isEqual:@"master"]){card.master=PGUIButton(@"eye",colors[index],self,@selector(masterChanged:));card.master.tag=[descriptor[@"id"]integerValue];card.master.identifier=[NSString stringWithFormat:@"pg.master.%@",descriptor[@"id"]];card.master.accessibilityLabel=descriptor[@"name"];card.master.toolTip=descriptor[@"name"];[card addSubview:card.master];continue;}
PGInspectorRow *row=[[PGInspectorRow alloc]initWithDescriptor:descriptor accent:colors[index] inspector:self];[rows addObject:row];[card addSubview:row];
}
card.rows=rows;if(index==3){_more=card;card.master=PGUIButton(@"disclosure",colors[index],self,@selector(moreChanged:));card.master.identifier=@"pg.more";card.master.accessibilityLabel=@"展开更多设置";[card addSubview:card.master];}
[self addSubview:card];[cards addObject:card];
}_cards=[cards copy];
_brand=PGUILabel(@"大鱼 · 人像美化",15,NSFontWeightSemibold);_brand.alignment=NSTextAlignmentCenter;[self addSubview:_brand];
_website=PGUILabel(@"dayu.media",10,NSFontWeightMedium);_website.alignment=NSTextAlignmentCenter;_website.textColor=PGUIMuted();[self addSubview:_website];
_status=PGUILabel(@"",10,NSFontWeightRegular);_status.textColor=PGUIMuted();_status.alignment=NSTextAlignmentCenter;[self addSubview:_status];
[self reloadControls];[self setFrameSize:NSMakeSize(320,[self heightForWidth:320])];
}return self;
}
- (BOOL)isFlipped { return YES; }
- (CGFloat)heightForWidth:(CGFloat)width { CGFloat h=12;for(PGInspectorCard *card in _cards)h+=[card heightForWidth:MAX(0,width-20)]+10;return h+83; }
- (NSSize)intrinsicContentSize { return NSMakeSize(NSViewNoIntrinsicMetric,[self heightForWidth:NSWidth(self.bounds)>0?NSWidth(self.bounds):320]); }
- (NSSize)fittingSize { CGFloat w=NSWidth(self.bounds)>0?NSWidth(self.bounds):320;return NSMakeSize(w,[self heightForWidth:w]); }
- (void)setFrameSize:(NSSize)newSize { if(_cards)newSize.height=[self heightForWidth:newSize.width];[super setFrameSize:newSize];[self invalidateIntrinsicContentSize];self.needsLayout=YES; }
- (void)layout {
[super layout];CGFloat w=NSWidth(self.bounds),y=12;for(PGInspectorCard *card in _cards){CGFloat h=[card heightForWidth:w-20];card.frame=NSMakeRect(10,y,MAX(0,w-20),h);y+=h+10;}
_brand.frame=NSMakeRect(12,y+12,MAX(0,w-24),23);_website.frame=NSMakeRect(12,y+38,MAX(0,w-24),17);_status.frame=NSMakeRect(12,y+61,MAX(0,w-24),16);
}
- (void)drawRect:(NSRect)dirtyRect { [PGUIColor(.035,.060,.105,1)setFill];NSRectFill(dirtyRect); }
- (void)reloadControls {
PGInspectorState *state=_controller.state;BOOL available=_controller.available;
for(PGInspectorCard *card in _cards){BOOL master=card==_more || [state valueForParameter:(UInt32)card.master.tag]>.5;
if(card!=_more){card.master.state=master?NSControlStateValueOn:NSControlStateValueOff;card.master.enabled=available;}
for(PGInspectorRow *row in card.rows)[row reloadState:state master:master available:available];
}
_status.stringValue=_controller.statusMessage.length?_controller.statusMessage:@"自动跟随 · 无需手动分析";_status.toolTip=_status.stringValue;
}
- (BOOL)hasActiveTextEditor { for(PGInspectorCard *card in _cards)for(PGInspectorRow *row in card.rows)if(row.valueField.currentEditor)return YES;return NO; }
- (void)refreshFromHost { if(_interactionDepth || [self hasActiveTextEditor])return;[_controller refresh];[self reloadControls]; }
- (void)writeValue:(double)value parameter:(UInt32)identifier { [_controller setValue:value forParameter:identifier];[self reloadControls]; }
- (void)beginControlInteraction { if(_interactionDepth++==0)[_controller beginInteraction]; }
- (void)endControlInteraction { if(!_interactionDepth)return;if(--_interactionDepth==0){[_controller endInteraction];[self refreshFromHost];} }
- (void)masterChanged:(NSButton *)sender { [_controller setValue:sender.state==NSControlStateValueOn?1:0 forParameter:(UInt32)sender.tag];[self reloadControls]; }
- (void)moreChanged:(NSButton *)sender { _more.expanded=sender.state==NSControlStateValueOn;sender.accessibilityLabel=_more.expanded?@"收起更多设置":@"展开更多设置";[_more setNeedsDisplay:YES];[self setFrameSize:self.frame.size]; }
- (void)viewDidMoveToWindow {
[super viewDidMoveToWindow];[_refreshTimer invalidate];_refreshTimer=nil;
if(self.window){[self refreshFromHost];__weak PGInspectorView *weakSelf=self;_refreshTimer=[NSTimer timerWithTimeInterval:.65 repeats:YES block:^(NSTimer *timer){PGInspectorView *view=weakSelf;if(!view||!view.window){[timer invalidate];return;}[view refreshFromHost];}];[[NSRunLoop mainRunLoop]addTimer:_refreshTimer forMode:NSRunLoopCommonModes];}
}
- (void)dealloc { [_refreshTimer invalidate]; }
@end
+2 -1
查看文件
@@ -13,5 +13,6 @@ enum {
PGAnalyzeForward=50, PGAnalyzeBackward=51, PGClearTrack=52, PGStatus=53,
PGTrackData1=60, PGTrackData2=61, PGTrackData3=62,
PGSmoothingEnabled=70, PGColorEnabled=71, PGShapeEnabled=72,
PGDetailEnabled=73, PGHelp=74
PGDetailEnabled=73, PGHelp=74,
PGInspectorPanel=210
};
+1 -1
查看文件
@@ -2,7 +2,7 @@
#import <FxPlug/FxPlugSDK.h>
#import "PGBeautyTypes.h"
@interface beatygrilPlugIn : NSObject <FxTileableEffect, FxAnalyzer>
@interface beatygrilPlugIn : NSObject <FxTileableEffect, FxAnalyzer, FxCustomParameterViewHost_v2>
@property (nonatomic, assign) id<PROAPIAccessing> apiManager;
- (PGBeautySettings)settingsAtTime:(CMTime)time;
- (void)analyzeForward;
+33 -29
查看文件
@@ -2,6 +2,8 @@
#import "PGParameterIDs.h"
#import "PGBeautyRenderer.h"
#import "PGFaceProcessor.h"
#import "PGInspectorState.h"
#import "PGInspectorView.h"
#import <Metal/Metal.h>
#import <IOSurface/IOSurface.h>
#import <stddef.h>
@@ -90,7 +92,6 @@ static CIImage *PGImageFromTile(FxImageTile *tile) {
@property BOOL analyzing;
@property BOOL analysisForward;
@property (strong) NSArray<NSString *> *loadedTracks;
@property uint32_t compatibleTrackMask;
@property BOOL reportedRender;
@end
@@ -120,8 +121,8 @@ static CIImage *PGImageFromTile(FxImageTile *tile) {
PGSlider spec=PGSliders[i]; if (spec.identifier!=identifier) continue;
NSString *name=[NSString stringWithUTF8String:spec.name];
float value=*(float *)((uint8_t *)&defaults+spec.offset);
if (spec.percent) return [api addPercentSliderWithName:name parameterID:identifier defaultValue:value parameterMin:spec.min parameterMax:spec.max sliderMin:spec.min sliderMax:spec.max delta:spec.step parameterFlags:kFxParameterFlag_DEFAULT];
return [api addFloatSliderWithName:name parameterID:identifier defaultValue:value parameterMin:spec.min parameterMax:spec.max sliderMin:spec.min sliderMax:spec.max delta:spec.step parameterFlags:kFxParameterFlag_DEFAULT];
if (spec.percent) return [api addPercentSliderWithName:name parameterID:identifier defaultValue:value parameterMin:spec.min parameterMax:spec.max sliderMin:spec.min sliderMax:spec.max delta:spec.step parameterFlags:kFxParameterFlag_HIDDEN];
return [api addFloatSliderWithName:name parameterID:identifier defaultValue:value parameterMin:spec.min parameterMax:spec.max sliderMin:spec.min sliderMax:spec.max delta:spec.step parameterFlags:kFxParameterFlag_HIDDEN];
}
return NO;
}
@@ -129,37 +130,47 @@ static CIImage *PGImageFromTile(FxImageTile *tile) {
id<FxParameterCreationAPI_v5> api=[_apiManager apiForProtocol:@protocol(FxParameterCreationAPI_v5)];
if (!api) return PGFail(error,@"无法取得 FxPlug 参数创建接口。");
__block BOOL ok=YES;
ok=[api addCustomParameterWithName:@"" parameterID:PGInspectorPanel
defaultValue:[PGInspectorState stateWithValues:@{} disabledParameters:[NSSet set] hasEdits:NO]
parameterFlags:kFxParameterFlag_CUSTOM_UI|kFxParameterFlag_USE_FULL_VIEW_WIDTH]&&ok;
void (^slider)(UInt32)=^(UInt32 identifier){ok=[self addSlider:identifier api:api]&&ok;};
void (^toggle)(NSString *,UInt32,BOOL)=^(NSString *name,UInt32 identifier,BOOL value){ok=[api addToggleButtonWithName:name parameterID:identifier defaultValue:value parameterFlags:kFxParameterFlag_DEFAULT]&&ok;};
void (^group)(NSString *,UInt32)=^(NSString *name,UInt32 identifier){ok=[api startParameterSubGroup:name parameterID:identifier parameterFlags:kFxParameterFlag_DEFAULT]&&ok;};
void (^toggle)(NSString *,UInt32,BOOL)=^(NSString *name,UInt32 identifier,BOOL value){ok=[api addToggleButtonWithName:name parameterID:identifier defaultValue:value parameterFlags:kFxParameterFlag_HIDDEN]&&ok;};
void (^group)(NSString *,UInt32)=^(NSString *name,UInt32 identifier){ok=[api startParameterSubGroup:name parameterID:identifier parameterFlags:kFxParameterFlag_HIDDEN]&&ok;};
void (^end)(void)=^{ok=[api endParameterSubGroup]&&ok;};
group(@"磨皮",100); toggle(@"启用磨皮",PGSmoothingEnabled,YES);
slider(PGAmount); slider(PGMidtone); slider(PGRadius); toggle(@"保护五官",PGFeatureProtect,YES); end();
group(@"肤色",101); toggle(@"启用肤色",PGColorEnabled,YES);
ok=[api addPopupMenuWithName:@"肤色风格" parameterID:PGTonePreset defaultValue:0 menuEntries:@[@"原色",@"自然白",@"冷白",@"暖白",@"红润白",@"小麦",@"古铜"] parameterFlags:0]&&ok;
ok=[api addPopupMenuWithName:@"肤色风格" parameterID:PGTonePreset defaultValue:0 menuEntries:@[@"原色",@"自然白",@"冷白",@"暖白",@"红润白",@"小麦",@"古铜"] parameterFlags:kFxParameterFlag_HIDDEN]&&ok;
slider(PGBrightness); slider(PGHue); slider(PGSaturation); slider(PGEvenTone); slider(PGTeeth); slider(PGEyeBright); end();
group(@"细节",102); toggle(@"启用细节",PGDetailEnabled,YES); slider(PGHighPass); slider(PGSharpness); end();
group(@"脸型",103); toggle(@"启用脸型",PGShapeEnabled,YES);
UInt32 shape[]={PGThin,PGBigEye,PGShort,PGNarrow,PGChin,PGVFace,PGJaw,PGCheekbone,PGSmallHead,PGSmallHeadRange};
for(NSUInteger i=0;i<sizeof(shape)/sizeof(UInt32);i++) slider(shape[i]); end();
group(@"人脸选择与跟踪",104); toggle(@"只处理选中人脸",PGSingleFace,NO);
ok=[api addPointParameterWithName:@"选脸位置" parameterID:PGSelection defaultX:.5 defaultY:.5 parameterFlags:0]&&ok;
ok=[api addPointParameterWithName:@"选脸位置" parameterID:PGSelection defaultX:.5 defaultY:.5 parameterFlags:kFxParameterFlag_HIDDEN]&&ok;
toggle(@"多人高速模式",PGFastMulti,NO); slider(PGJumpGuard);
toggle(@"使用跟踪数据",PGTrackEnabled,NO);
ok=[api addPopupMenuWithName:@"跟踪目标" parameterID:PGTarget defaultValue:0 menuEntries:@[@"目标 1",@"目标 2",@"目标 3"] parameterFlags:kFxParameterFlag_NOT_ANIMATABLE]&&ok;
ok=[api addPushButtonWithName:@"向前分析" parameterID:PGAnalyzeForward selector:@selector(analyzeForward) parameterFlags:0]&&ok;
ok=[api addPushButtonWithName:@"向后分析" parameterID:PGAnalyzeBackward selector:@selector(analyzeBackward) parameterFlags:0]&&ok;
ok=[api addPushButtonWithName:@"清除当前目标" parameterID:PGClearTrack selector:@selector(clearTracking) parameterFlags:0]&&ok;
ok=[api addStringParameterWithName:@"跟踪状态" parameterID:PGStatus defaultValue:@"选择画面中的人脸后开始分析" parameterFlags:kFxParameterFlag_NOT_ANIMATABLE|kFxParameterFlag_DISABLED]&&ok;
ok=[api addPopupMenuWithName:@"跟踪目标" parameterID:PGTarget defaultValue:0 menuEntries:@[@"目标 1",@"目标 2",@"目标 3"] parameterFlags:kFxParameterFlag_NOT_ANIMATABLE|kFxParameterFlag_HIDDEN]&&ok;
ok=[api addPushButtonWithName:@"向前分析" parameterID:PGAnalyzeForward selector:@selector(analyzeForward) parameterFlags:kFxParameterFlag_HIDDEN|kFxParameterFlag_DISABLED]&&ok;
ok=[api addPushButtonWithName:@"向后分析" parameterID:PGAnalyzeBackward selector:@selector(analyzeBackward) parameterFlags:kFxParameterFlag_HIDDEN|kFxParameterFlag_DISABLED]&&ok;
ok=[api addPushButtonWithName:@"清除当前目标" parameterID:PGClearTrack selector:@selector(clearTracking) parameterFlags:kFxParameterFlag_HIDDEN|kFxParameterFlag_DISABLED]&&ok;
ok=[api addStringParameterWithName:@"跟踪状态" parameterID:PGStatus defaultValue:@"自动人脸跟随" parameterFlags:kFxParameterFlag_NOT_ANIMATABLE|kFxParameterFlag_DISABLED|kFxParameterFlag_HIDDEN]&&ok;
toggle(@"显示人脸框",PGFaceBoxes,NO); toggle(@"显示跟踪框",PGTrackBoxes,NO); end();
group(@"蒙版与输出",105); slider(PGThreshold); slider(PGSoftness); slider(PGEdgeProtect);
toggle(@"预览蒙版",PGShowMask,NO); toggle(@"反转蒙版",PGInvertMask,NO);
ok=[api addPopupMenuWithName:@"蒙版通道" parameterID:PGDebugChannel defaultValue:0 menuEntries:@[@"皮肤",@"牙齿",@"眼睛"] parameterFlags:0]&&ok;
ok=[api addPopupMenuWithName:@"蒙版通道" parameterID:PGDebugChannel defaultValue:0 menuEntries:@[@"皮肤",@"牙齿",@"眼睛"] parameterFlags:kFxParameterFlag_HIDDEN]&&ok;
slider(PGMix); end();
for(UInt32 identifier=PGTrackData1;identifier<=PGTrackData3;identifier++)
ok=[api addStringParameterWithName:@"分析数据" parameterID:identifier defaultValue:@"" parameterFlags:kFxParameterFlag_HIDDEN|kFxParameterFlag_NOT_ANIMATABLE]&&ok;
return ok ? YES : PGFail(error,@"宿主未能创建完整的人像美化参数。");
}
- (NSView *)createViewForParameterID:(UInt32)identifier {
return identifier==PGInspectorPanel ? [[PGInspectorView alloc] initWithAPIManager:_apiManager] : nil;
}
- (Class)classForCustomParameterID:(UInt32)identifier {return identifier==PGInspectorPanel?PGInspectorState.class:Nil;}
- (NSSet<Class> *)classesForCustomParameterID:(UInt32)identifier {
return identifier==PGInspectorPanel?[NSSet setWithObjects:PGInspectorState.class,NSDictionary.class,NSNumber.class,NSSet.class,nil]:[NSSet set];
}
- (PGBeautySettings)settingsAtTime:(CMTime)time {
PGBeautySettings s=PGBeautyDefaults();
id<FxParameterRetrievalAPI_v6> api=[_apiManager apiForProtocol:@protocol(FxParameterRetrievalAPI_v6)];
@@ -192,6 +203,13 @@ static CIImage *PGImageFromTile(FxImageTile *tile) {
enabled=YES; [api getBoolValue:&enabled fromParameter:PGShapeEnabled atTime:time];
if(!enabled) s.faceThin=s.faceBigEye=s.faceShort=s.faceNarrow=s.faceChin=s.faceV=s.faceJaw=s.faceCheekbone=s.faceSmallHead=0;
if(s.fastMultiFace) s.singleFace=0;
NSObject *panel=nil;
[api getCustomParameterValue:&panel fromParameter:PGInspectorPanel atTime:time];
if([panel isKindOfClass:PGInspectorState.class])s=PGSettingsWithInspectorState(s,(PGInspectorState *)panel);
// The current product follows faces automatically. Old manual-analysis and
// debug values remain saved for document compatibility, but cannot silently
// override live geometry or leave an invisible mask/selection mode active.
s.trackingEnabled=0;s.singleFace=0;s.showMask=0;s.invertMask=0;s.debugChannel=0;s.showFaceBoxes=0;
return s;
}
- (NSArray<NSString *> *)trackStrings {
@@ -207,7 +225,7 @@ static CIImage *PGImageFromTile(FxImageTile *tile) {
if(!state) return PGFail(error,@"缺少渲染状态输出位置。");
if(![_apiManager apiForProtocol:@protocol(FxParameterRetrievalAPI_v6)]) return PGFail(error,@"无法读取宿主参数。");
PGBeautySettings s=[self settingsAtTime:time];
*state=[NSPropertyListSerialization dataWithPropertyList:@{@"settings":[NSData dataWithBytes:&s length:sizeof(s)],@"tracks":[self trackStrings]} format:NSPropertyListBinaryFormat_v1_0 options:0 error:error];
*state=[NSPropertyListSerialization dataWithPropertyList:@{@"settings":[NSData dataWithBytes:&s length:sizeof(s)],@"tracks":@[@"",@"",@""]} format:NSPropertyListBinaryFormat_v1_0 options:0 error:error];
return *state!=nil;
}
- (BOOL)destinationImageRect:(FxRect *)rect sourceImages:(NSArray<FxImageTile *> *)sources destinationImage:(FxImageTile *)destination pluginState:(NSData *)state atTime:(CMTime)time error:(NSError **)error {
@@ -237,6 +255,7 @@ static CIImage *PGImageFromTile(FxImageTile *tile) {
if(![plist isKindOfClass:NSDictionary.class]||![plist[@"settings"] isKindOfClass:NSData.class]||[plist[@"settings"] length]!=sizeof(PGBeautySettings)) return PGFail(error,@"渲染状态版本无效。");
PGBeautySettings s;[plist[@"settings"] getBytes:&s length:sizeof(s)];
if(s.version!=1) return PGFail(error,@"此版本不支持保存的渲染状态。");
s.trackingEnabled=0;s.singleFace=0;
CIImage *input=PGImageFromTile(sources.firstObject); if(!input) return PGFail(error,@"无法读取 IOSurface。");
@synchronized(self) {
if(!_reportedRender) {
@@ -255,21 +274,6 @@ static CIImage *PGImageFromTile(FxImageTile *tile) {
NSArray *tracks=plist[@"tracks"];
if(![tracks isKindOfClass:NSArray.class]||tracks.count!=3) return PGFail(error,@"跟踪状态无效。");
for(id track in tracks) if(![track isKindOfClass:NSString.class]) return PGFail(error,@"跟踪记录无效。");
if(![_loadedTracks isEqualToArray:tracks]) {
_compatibleTrackMask=0;
for(NSUInteger i=0;i<3;i++) {
NSData *data=[[NSData alloc] initWithBase64EncodedString:tracks[i] options:0];
BOOL compatible=PGCompatibleHostTrack(data);
if(compatible) _compatibleTrackMask |= 1u<<i;
[_faceProcessor setTrackingData:compatible?data:nil forTarget:i];
}
_loadedTracks=[tracks copy];
}
// Previous releases did not record which image-axis contract their
// analysis used. Never replay potentially inverted coordinates.
// Preserve the user's saved data and use realtime follow until they
// reanalyze that target under this coordinate contract.
if(s.trackingEnabled && !(_compatibleTrackMask & (1u<<MIN(s.targetIndex,2)))) s.trackingEnabled=0;
NSError *stageError=nil;
PGFaceFrame *frame=[_faceProcessor processImage:input settings:s time:time error:&stageError];
if(!frame) { os_log_error(PGRenderLog(), "face processing failed: %{public}@",stageError); if(error)*error=stageError; return NO; }
@@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.6</string>
<string>1.1.0</string>
<key>CFBundleVersion</key>
<string>8</string>
<string>9</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSHumanReadableCopyright</key>