Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pixels per inch is wrong on 7/8 Plus phones and minis #12

Open
fancyham opened this issue Jul 4, 2020 · 5 comments
Open

Pixels per inch is wrong on 7/8 Plus phones and minis #12

fancyham opened this issue Jul 4, 2020 · 5 comments

Comments

@fancyham
Copy link

fancyham commented Jul 4, 2020

PPI number seems to be wrong for iPhone 6, 7, 8 Plus devices, leading to incorrect dimensionInInches, dimensionInCentimeters values, and pixelsPerInch, that don't match up with physical device.

Library returns screen dimensions of:
5.5 x 3.09 inches for the screen
But the actual physical dimensions are:
4.79 × 2.7

There is a 1.15x error.

This seems to be related to the 1/1.15 downsampling unique to these models from the rendered screen buffer to the device's physical screen.

This helps explain the downsampling: https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions
(Edit: this link shows the incorrect 401 PPI for drawing to the screen)

So, I think the PPI in this module is calculated using the rendered screen buffer's dimensions (main.nativeBounds.height = 2208, width = 1242), but it should be calculated using device's physical pixels (1920, 1080).

This would be necessary, to do, say a ruler app.

@marchv
Copy link
Owner

marchv commented Jul 4, 2020

Hi @fancyham and thanks for reaching out...

Hmm, that is a surprise me. When this was made I used an iPhone 7 Plus myself and as you can see in the example in README.md I got 5.5" in out in diagonal screen dimension 👀. Unfortunately, I have updated my phone to iOS 14 beta so I couldn't test it today.

PS. I am familiar with www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions already, but thanks anyway :)

What iOS version did you get this on?

Cheers! :)

@fancyham
Copy link
Author

fancyham commented Jul 4, 2020

Yes, it's pretty strange!

This is on iOS 13.3 on a simulator and the diagonal ends up 6.31". Perhaps it's a bug in the simulator as I don't have a physical device to test on?

I believe the issue is that physically, the screen is indeed 401 ppi, but due to that weird downsampling, when drawing to the screen, it's (401*1.15 ppi).

Here's what I'm displaying in SwiftUI

struct ContentView: View {
    var body: some View {
        VStack(alignment: .leading){
            Text("Length of screen in inches =\n \(Float(UIScreen.lengthOfScreenInInches!)) inches  (\(Float(UIScreen.lengthOfScreenInInches!) * 2.54)cm)\n")
            Text("Width of screen in inches =\n \(Float(UIScreen.widthOfScreenInInches!)) inches  (\(Float(UIScreen.widthOfScreenInInches!) * 2.54)cm)\n")
            Text("")
            Text("Size = \(UIScreen.dimensionInInches!.debugDescription) inches")
            Text("Diagonal = \(sqrt(pow((Float(UIScreen.dimensionInInches!.width)), 2) + pow(Float(UIScreen.dimensionInInches!.height), 2)))")
            Text("Pixels per inch = \(Float(UIScreen.pixelsPerInch!))\n")
            Text("")
            Text("UIScreen.main.nativeBounds.width = \(UIScreen.main.nativeBounds.width)")
        }
    }
}

And getting this for an iPhone 7 Plus (simulator)
Screen Shot 2020-07-04 at 10 45 02 AM

I found that I get correct numbers for those devices if I change the 'return 401' to 'return 401*1.15

        case "iPhone7,1":                                fallthrough // iPhone 6 Plus
        case "iPhone8,2":                                fallthrough // iPhone 6S Plus
        case "iPhone9,2", "iPhone9,4":                   fallthrough // iPhone 7 Plus
        case "iPhone10,2", "iPhone10,5":                             // iPhone 8 Plus
            return 401*1.15

@fancyham
Copy link
Author

fancyham commented Jul 4, 2020

I think this explains what's going on:
https://medium.com/we-are-appcepted/the-curious-case-of-iphone-6-1080p-display-b33dac5bbcb6

The screen is physically ~401 PPI, but internally, it's ~462 PPI.

So if you're able to replicate the same issue on your physical device, one solution could be to change the 'return 401' to 'return 462'

I can post my code if that's helpful.

I suspect Apple was expecting to use a higher-resolution screen but then their display provider couldn't deliver, so they resorted to the downsampling.

@fancyham
Copy link
Author

fancyham commented Jul 8, 2020

BTW, I wrote to www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions and they replied that they realize the 401 PPI number on their page is misleading but that they don't want to imply that the Plus phones have a higher resolution than the X so currently they'll continue listing the screen's physical PPI rather than what might be called "462 virtual PPI".

@fancyham fancyham changed the title Pixels per inch is wrong on Plus phones Pixels per inch is wrong on 7/8 Plus phones and minis Dec 15, 2022
@fancyham
Copy link
Author

fancyham commented Dec 15, 2022

Similar issue is happening with the iPhone 12 and 13 mini. Their screens are actually rendered as if on a larger device, then scaled down by a percentage. In this case, 96%.

Drawing a ruler without doing this scaling will yield incorrect measurements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants