@Override
    protected float getScore(Size size, Size desired) {
        if (size.width <= 0 || size.height <= 0) {
            return 0f;
        }
        Size scaled = size.scaleCrop(desired);
        // Scaling preserves aspect ratio
        float scaleRatio = scaled.width * 1.0f / size.width;

        // Treat downscaling as slightly better than upscaling
        float scaleScore;
        if (scaleRatio > 1.0f) {
            // Upscaling
            scaleScore = (float)Math.pow(1.0f / scaleRatio, 1.1);
        } else {
            // Downscaling
            scaleScore = scaleRatio;
        }

        // Ratio of scaledDimension / dimension.
        // Note that with scaleCrop, only one dimension is cropped.
        float cropRatio = scaled.width * 1.0f / desired.width +
                scaled.height * 1.0f / desired.height;

        // Cropping is bad, square it
        // 1.0 means no cropping. 50% cropping is 0.44f, 10% cropping is 0.82f
        float cropScore = 1.0f / cropRatio / cropRatio;

        return scaleScore * cropScore;
    }
Get a score for our size.

Based on heuristics for penalizing scaling and cropping.

1.0 is perfect (exact match).
0.0 means we can't use it at all.

@param size the camera preview size (that can be scaled)
@param desired the viewfinder size
@return the score
zxing-android-embedded/src/com/journeyapps/barcodescanner/camera/CenterCropStrategy.java