QGVAPConfigModel.m 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // Tencent is pleased to support the open source community by making vap available.
  2. //
  3. // Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
  4. //
  5. // Licensed under the MIT License (the "License"); you may not use this file except in
  6. // compliance with the License. You may obtain a copy of the License at
  7. //
  8. // http://opensource.org/licenses/MIT
  9. //
  10. // Unless required by applicable law or agreed to in writing, software distributed under the License is
  11. // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  12. // either express or implied. See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import "QGVAPConfigModel.h"
  15. #import "NSDictionary+HWDUtil.h"
  16. //资源适配类型
  17. VapAttachmentFitType const kVapAttachmentFitTypeFitXY = @"fitXY"; //按指定尺寸缩放
  18. VapAttachmentFitType const kVapAttachmentFitTypeCenterFull = @"centerFull"; //默认按资源尺寸展示,如果资源尺寸小于遮罩,则等比缩放至可填满
  19. //资源类型
  20. VapAttachmentSourceType const kVapAttachmentSourceTypeTextStr = @"txt"; //文字
  21. VapAttachmentSourceType const kVapAttachmentSourceTypeImgUrl = @"img"; //图片
  22. //资源加载类型
  23. VapAttachmentLoadType const kVapAttachmentLoadTypeLocal = @"local";
  24. VapAttachmentLoadType const kVapAttachmentLoadTypeNet = @"net";
  25. //字体
  26. VapAttachmentSourceStyle const kVapAttachmentSourceStyleBoldText = @"b"; //粗体
  27. //遮罩融合类型
  28. VapAttachmentMaskType const kVapAttachmentMaskTypeSrcOut = @"srcOut"; //表示去除遮挡区域
  29. VapAttachmentMaskType const kVapAttachmentMaskTypeSrcIn = @"srcIn"; //表示根据遮罩形状裁剪
  30. VapAttachmentMaskType const kVapAttachmentMaskTypeSrcMix = @"srcMix";
  31. NSInteger const kVapLayoutMaxWidth = 1504;
  32. @implementation QGVAPConfigModel
  33. - (NSString *)description {
  34. return [NSString stringWithFormat:@"<%@: %p> {info:%@, configs:%@}", self.class, self, _info, _mergedConfig];
  35. }
  36. - (NSString *)jsonString {
  37. NSString *infoJson = [self.info jsonString];
  38. __block NSString *srcString = nil;
  39. __block NSString *framesString = nil;
  40. if (self.resources.count > 0) {
  41. srcString = @"[";
  42. [self.resources enumerateObjectsUsingBlock:^(QGVAPSourceInfo * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  43. srcString = [srcString stringByAppendingString:[obj jsonString]];
  44. if (idx != self.resources.count-1) {
  45. srcString = [srcString stringByAppendingString:@","];
  46. }
  47. }];
  48. srcString = [srcString stringByAppendingString:@"]"];
  49. }
  50. if (self.mergedConfig.count > 0) {
  51. framesString = @"[";
  52. [self.mergedConfig enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull key, NSArray<QGVAPMergedInfo *> * _Nonnull obj, BOOL * _Nonnull stop) {
  53. __block NSString *objString = @"[";
  54. [obj enumerateObjectsUsingBlock:^(QGVAPMergedInfo * _Nonnull mergInfo, NSUInteger idx, BOOL * _Nonnull stop) {
  55. objString = [objString stringByAppendingString:[mergInfo jsonString]];
  56. objString = [objString stringByAppendingString:@","];
  57. }];
  58. if([objString hasSuffix:@","]) {
  59. objString = [objString substringToIndex:objString.length-1];
  60. }
  61. objString = [objString stringByAppendingString:@"]"];
  62. framesString = [framesString stringByAppendingString:[NSString stringWithFormat:@"{\"i\":%@,\"obj\":%@},", key, objString]];
  63. }];
  64. if([framesString hasSuffix:@","]) {
  65. framesString = [framesString substringToIndex:framesString.length-1];
  66. }
  67. framesString = [framesString stringByAppendingString:@"]"];
  68. }
  69. NSString *totalString = @"{";
  70. if (infoJson) {
  71. totalString = [totalString stringByAppendingString:[NSString stringWithFormat:@"\"info\":%@", infoJson]];
  72. }
  73. if (srcString) {
  74. totalString = [totalString stringByAppendingString:[NSString stringWithFormat:@",\"src\":%@", srcString]];
  75. }
  76. if (framesString) {
  77. totalString = [totalString stringByAppendingString:[NSString stringWithFormat:@",\"frame\":%@", framesString]];
  78. }
  79. totalString = [totalString stringByAppendingString:@"}"];
  80. return totalString;
  81. }
  82. @end
  83. @implementation QGVAPCommonInfo
  84. - (NSString *)description {
  85. return [NSString stringWithFormat:@"<%@: %p> {version:%@, frames:%@, size:(%@,%@), videoSize:(%@,%@) orien:%@, fps:%@, merged:%@, alpha:(%@,%@,%@,%@), rgb:(%@,%@,%@,%@)}", self.class, self, @(_version), @(_framesCount), @(_size.width), @(_size.height), @(_videoSize.width), @(_videoSize.height), @(_targetOrientaion), @(_fps), @(_isMerged), @(_alphaAreaRect.origin.x), @(_alphaAreaRect.origin.y), @(_alphaAreaRect.size.width), @(_alphaAreaRect.size.height), @(_rgbAreaRect.origin.x), @(_rgbAreaRect.origin.y), @(_rgbAreaRect.size.width), @(_rgbAreaRect.size.height)];
  86. }
  87. - (NSString *)jsonString {
  88. return [NSString stringWithFormat:@"{\"v\":%@,\"f\":%@,\"w\":%@,\"h\":%@,\"videoW\":%@,\"videoH\":%@,\"orien\":%@,\"fps\":%@,\"isVapx\":%@,\"aFrame\":[%@,%@,%@,%@],\"rgbFrame\":[%@,%@,%@,%@]}", @(_version),@(_framesCount),@(_size.width),@(_size.height),@(_videoSize.width),@(_videoSize.height),@(_targetOrientaion),@(_fps),@(_isMerged),@(_alphaAreaRect.origin.x),@(_alphaAreaRect.origin.y),@(_alphaAreaRect.size.width),@(_alphaAreaRect.size.height),@(_rgbAreaRect.origin.x),@(_rgbAreaRect.origin.y),@(_rgbAreaRect.size.width),@(_rgbAreaRect.size.height)];
  89. }
  90. @end
  91. @implementation QGVAPSourceInfo
  92. - (NSString *)description {
  93. return [NSString stringWithFormat:@"<%@: %p> {type:%@, tag:%@ color:%@, style:%@, size:(%@,%@), fitType:%@}", self.class, self, _type, _contentTag, _color, _style, @(_size.width), @(_size.height), _fitType];
  94. }
  95. - (NSString *)jsonString {
  96. return [NSString stringWithFormat:@"{\"srcId\":\"%@\",\"srcType\":\"%@\",\"loadType\":\"%@\", \"srcTag\":\"%@\",%@%@\"w\":%@,\"h\":%@,\"fitType\":\"%@\"}", _srcID, _type, _loadType, _contentTag, (_color.length > 0)?[NSString stringWithFormat:@"\"color\":\"%@\",",_color] : @"", _style.length>0 ? [NSString stringWithFormat:@"\"style\":\"%@\",",_style]:@"", @(_size.width), @(_size.height), _fitType];
  97. }
  98. @end
  99. @implementation QGVAPMergedInfo
  100. - (NSString *)description {
  101. return [NSString stringWithFormat:@"<%@: %p> {index:%@, rect:(%@,%@,%@,%@), mask:%@, maskRect:(%@,%@,%@,%@), maskRotation:%@, source:%@}", self.class, self, @(_renderIndex), @(_renderRect.origin.x), @(_renderRect.origin.y), @(_renderRect.size.width), @(_renderRect.size.height), @(_needMask), @(_maskRect.origin.x), @(_maskRect.origin.y), @(_maskRect.size.width), @(_maskRect.size.height), @(_maskRotation), _source];
  102. }
  103. - (NSString *)jsonString {
  104. return [NSString stringWithFormat:@"{\"srcId\":\"%@\",\"z\":%@,\"frame\":[%@,%@,%@,%@],\"mFrame\":[%@,%@,%@,%@],\"mt\":%@}", _source.srcID, @(_renderIndex), @(_renderRect.origin.x), @(_renderRect.origin.y), @(_renderRect.size.width), @(_renderRect.size.height),@(_maskRect.origin.x), @(_maskRect.origin.y), @(_maskRect.size.width), @(_maskRect.size.height), @(_maskRotation)];
  105. }
  106. @end