Explorar o código

兼容 - 转档 SDK V1.6.0 DPI 计算方法不同,图像对照时,用 CI 实现图像等比例缩放对照

zhudongyong %!s(int64=2) %!d(string=hai) anos
pai
achega
073506bde1

+ 38 - 23
KdanAutoTest/KdanAuto/Class/AutoTestCase/AutoTest.swift

@@ -280,28 +280,31 @@ class AutoTest : NSObject, AutoTestProtocal {
                 var subDegree = Double(0);
                 var subCount = Int(0)
                 var itemIndex = 0;
+//                let maxProcessCount = min(3, max(items.count, 1))
                 
                 var processItemBlock = {(items:NSMutableArray) in
                     
                 }
                 processItemBlock = {(items:NSMutableArray) in
                     if (itemIndex >= items.count) {
-                        if subCount != 0 {
-                            subDegree = subDegree/Double(subCount)
-                        }else {
-                            subDegree = 0.0
-                        }
-                        
-                        TestDegreeManager.shared().set(subDegree,
-                                                       fileType: self.fileType(),
-                                                       type: self.type(),
-                                                       fileName: fileName)
-                        DispatchQueue.global().async {
-                            autoreleasepool {
-                                // 执行下一个文件转档
-                                complention(subDegree)
+//                        if (itemIndex >= (items.count + (maxProcessCount - 1))) {
+                            if subCount != 0 {
+                                subDegree = subDegree/Double(subCount)
+                            }else {
+                                subDegree = 0.0
                             }
-                        }
+                            
+                            TestDegreeManager.shared().set(subDegree,
+                                                           fileType: self.fileType(),
+                                                           type: self.type(),
+                                                           fileName: fileName)
+                            DispatchQueue.global().async {
+                                autoreleasepool {
+                                    // 执行下一个文件转档
+                                    complention(subDegree)
+                                }
+                            }
+//                        }
                         return
                     }
                     DispatchQueue.global().async {
@@ -360,8 +363,10 @@ class AutoTest : NSObject, AutoTestProtocal {
                                                         
                                                         compareCount += 1
                                                         if (compareCount >= subImages.count) {
-                                                            itemIndex += 1
-                                                            processItemBlock(items)
+                                                            DispatchQueue.global().async {
+                                                                itemIndex += 1
+                                                                processItemBlock(items)
+                                                            }
                                                         }
                                                     })
                                                 }
@@ -369,8 +374,10 @@ class AutoTest : NSObject, AutoTestProtocal {
                                             
                                             if (subImages.count == 0) {
                                                 // complention
-                                                itemIndex += 1
-                                                processItemBlock(items)
+                                                DispatchQueue.global().async {
+                                                    itemIndex += 1
+                                                    processItemBlock(items)
+                                                }
                                                 return
                                             }
                                         }else {
@@ -397,8 +404,10 @@ class AutoTest : NSObject, AutoTestProtocal {
                                                 }
                                                 
                                                 // complention
-                                                itemIndex += 1
-                                                processItemBlock(items)
+                                                DispatchQueue.global().async {
+                                                    itemIndex += 1
+                                                    processItemBlock(items)
+                                                }
                                             })
                                         }
                                     }else {
@@ -406,8 +415,10 @@ class AutoTest : NSObject, AutoTestProtocal {
                                                                                                  attributes:[.foregroundColor : NSColor.red]))
                                         
                                         // complention
-                                        itemIndex += 1
-                                        processItemBlock(items)
+                                        DispatchQueue.global().async {
+                                            itemIndex += 1
+                                            processItemBlock(items)
+                                        }
                                     }
                                 }
                             }
@@ -415,6 +426,10 @@ class AutoTest : NSObject, AutoTestProtocal {
                     }
                 }
                 processItemBlock(items)
+//                while (itemIndex < (maxProcessCount - 1)) {
+//                    itemIndex += 1;
+//                    processItemBlock(items)
+//                }
                 
                 return
             }

+ 2 - 2
KdanAutoTest/KdanAuto/Class/AutoTestCase/AutoTestProperty.plist

@@ -296,7 +296,7 @@
 			<key>Params</key>
 			<dict>
 				<key>imageDpi</key>
-				<integer>200</integer>
+				<integer>216</integer>
 			</dict>
 		</dict>
 	</array>
@@ -346,7 +346,7 @@
 			<key>Params</key>
 			<dict>
 				<key>imageDpi</key>
-				<integer>200</integer>
+				<integer>216</integer>
 			</dict>
 		</dict>
 	</array>

+ 1 - 1
KdanAutoTest/KdanAuto/Class/CompareViewController/ImageCompareCellView.swift

@@ -101,7 +101,7 @@ class ImageCompareCellView : NSTableCellView {
                 
                 let degree = _fileInfo.degree()
                 if degree == -1 {
-                    _degreeInfoLbl.stringValue = "文件不存在"
+                    _degreeInfoLbl.stringValue = "对照文件不存在"
                     _degreeInfoLbl.textColor = NSColor.red
                 } else {
                     if abs(degree - 100) > 0 {

+ 3 - 1
KdanAutoTest/KdanAuto/Class/Tools/FileConveter/FileConverter.swift

@@ -128,7 +128,9 @@ class FileConverter : NSObject, CPDFConverterDelegate, CPDFConverterFPDelegate {
                     }
                     if (params != nil) {
                         if let dipValue = params!["imageDpi"] as? NSNumber {
-                            try? (self.options as! CPDFConvertImgOptions).imageDpi = Int32(dipValue.intValue)
+                            if (CPDFConvertKit.sharedInstance().buildNumber >= 150) {
+                                try? (self.options as! CPDFConvertImgOptions).imageDpi = Int32(dipValue.intValue)
+                            }
                         }
                     }
                     self.pdfConverter?.convert(toFilePath: cachePath, pageIndexs: self.pages, options: self.options)

+ 46 - 11
KdanAutoTest/KdanAuto/Class/Tools/ImageProcess/ImageProcess.swift

@@ -7,6 +7,7 @@
 
 import Foundation
 import AppKit
+import CoreImage
 
 class ImageProcess : NSObject {
     
@@ -28,18 +29,34 @@ class ImageProcess : NSObject {
             let checkImage = cImage!
             
             let resultImageRep = NSBitmapImageRep.init(cgImage: resultImage.cgImage(forProposedRect: nil, context: nil, hints: nil)!)
-            let checkImageRep = NSBitmapImageRep.init(cgImage: checkImage.cgImage(forProposedRect: nil, context: nil, hints: nil)!)
+            var checkImageRep = NSBitmapImageRep.init(cgImage: checkImage.cgImage(forProposedRect: nil, context: nil, hints: nil)!)
             
             let rWidth = resultImageRep.pixelsWide
             let rHeight = resultImageRep.pixelsHigh
             //            let rBitPerPixel = resultImageRep.bitsPerPixel / 8
             //            let rBytePerRow = resultImageRep.bytesPerRow
             
-            let cWidth = checkImageRep.pixelsWide
-            let cHeight = checkImageRep.pixelsHigh
+            var cWidth = checkImageRep.pixelsWide
+            var cHeight = checkImageRep.pixelsHigh
             //            let cBitPerPixel = checkImageRep.bitsPerPixel / 8
             //            let cBytePerRow = checkImageRep.bytesPerRow
             
+            // 图像为等比例、且长宽比相同
+            if rHeight*cHeight > 0 &&
+                fabs(Double(rWidth-cWidth)) > 1 &&
+                fabs(Double(rWidth)/Double(rHeight) - Double(cWidth)/Double(cHeight)) < 0.001  {
+                var ciImage = CIImage(cgImage: checkImage.cgImage(forProposedRect: nil, context: nil, hints: nil)!)
+                ciImage = ciImage.transformed(by: CGAffineTransformMakeScale(Double(rWidth)/Double(cWidth), Double(rHeight)/Double(cHeight)))
+                let context = CIContext()
+                let cgImage = context.createCGImage(ciImage, from: ciImage.extent)
+                if cgImage != nil {
+                    checkImageRep = NSBitmapImageRep(cgImage: cgImage!);
+                    
+                    cWidth = checkImageRep.pixelsWide
+                    cHeight = checkImageRep.pixelsHigh
+                }
+            }
+            
             let maxWidth = min(rWidth, cWidth) - 1
             let maxHeight = min(rHeight, cHeight) - 1
             
@@ -203,25 +220,41 @@ class ImageProcess : NSObject {
             }
             
             let resultImage = rImage!
-            let checkImage = cImage!
+            var checkImage = cImage!
             
             let resultImageRep = NSBitmapImageRep.init(cgImage: resultImage.cgImage(forProposedRect: nil, context: nil, hints: nil)!)
-            let checkImageRep = NSBitmapImageRep.init(cgImage: checkImage.cgImage(forProposedRect: nil, context: nil, hints: nil)!)
+            var checkImageRep = NSBitmapImageRep.init(cgImage: checkImage.cgImage(forProposedRect: nil, context: nil, hints: nil)!)
             
             let rWidth = resultImageRep.pixelsWide
             let rHeight = resultImageRep.pixelsHigh
             //            let rBitPerPixel = resultImageRep.bitsPerPixel / 8
             //            let rBytePerRow = resultImageRep.bytesPerRow
             
-            let cWidth = checkImageRep.pixelsWide
-            let cHeight = checkImageRep.pixelsHigh
+            var cWidth = checkImageRep.pixelsWide
+            var cHeight = checkImageRep.pixelsHigh
             //            let cBitPerPixel = checkImageRep.bitsPerPixel / 8
             //            let cBytePerRow = checkImageRep.bytesPerRow
             
+            // 图像为等比例、且长宽比相同
+            if rHeight*cHeight > 0 &&
+                fabs(Double(rWidth-cWidth)) > 1 &&
+                fabs(Double(rWidth)/Double(rHeight) - Double(cWidth)/Double(cHeight)) < 0.001 {
+                var ciImage = CIImage(cgImage: checkImage.cgImage(forProposedRect: nil, context: nil, hints: nil)!)
+                ciImage = ciImage.transformed(by: CGAffineTransformMakeScale(Double(rWidth)/Double(cWidth), Double(rHeight)/Double(cHeight)))
+                let context = CIContext()
+                let cgImage = context.createCGImage(ciImage, from: ciImage.extent)
+                if cgImage != nil {
+                    checkImageRep = NSBitmapImageRep(cgImage: cgImage!);
+                    
+                    cWidth = checkImageRep.pixelsWide
+                    cHeight = checkImageRep.pixelsHigh
+                }
+            }
+            
             let maxWidth = min(rWidth, cWidth) - 1
             let maxHeight = min(rHeight, cHeight) - 1
             
-            if (maxWidth == 0) {
+            if (maxWidth == 0 || maxHeight == 0) {
                 complention(-1)
                 return
             }
@@ -346,9 +379,11 @@ class ImageProcess : NSObject {
                 }
             }
             
-            NSLog(String("过滤点数目\(bgCount)"))
-            
-            complention(outDegree)
+            DispatchQueue.global().async {
+                NSLog(String("过滤点数目\(bgCount)"))
+                
+                complention(outDegree)
+            }
         }
     }