-1

I've got my RGB data of the CGImage. but the processing to get avrage color is so slow. any idea? apreciated.

let screenShot:CGImage = CGDisplayCreateImage(activeDisplays[Int(index)],rect: myrect)!
let dp: UnsafePointer<UInt8> = CFDataGetBytePtr(screenShot.dataProvider?.data)
var bsum:Int = 0
var rsum:Int = 0
var gsum:Int = 0
for j in 0..<(oneH*oneW){
    rsum += Int(dp[j*4])
    gsum += Int(dp[j*4+1])
    bsum += Int(dp[j*4+2])
}
rsum/=onepack
gsum/=onepack
bsum/=onepack
JoJo.Z
  • 1

1 Answers1

0

https://gist.github.com/jeffrafter/ad8516d4ed7221a5cfd4b66d2f7f4ca1

this is the right answer.

but I found it coast too much time. so I dicided to sample the pixel by jumping a few rows.it's faster.

JoJo.Z
  • 1