private int getRoundedSampleSize(int degreesToRotate, int inWidth, int inHeight, int outWidth, int outHeight) {
        int targetHeight = outHeight == Target.SIZE_ORIGINAL ? inHeight : outHeight;
        int targetWidth = outWidth == Target.SIZE_ORIGINAL ? inWidth : outWidth;

        final int exactSampleSize;
        if (degreesToRotate == 90 || degreesToRotate == 270) {
            // If we're rotating the image +-90 degrees, we need to downsample accordingly so the image width is
            // decreased to near our target's height and the image height is decreased to near our target width.
            //noinspection SuspiciousNameCombination
            exactSampleSize = getSampleSize(inHeight, inWidth, targetWidth, targetHeight);
        } else {
            exactSampleSize = getSampleSize(inWidth, inHeight, targetWidth, targetHeight);
        }

        // BitmapFactory only accepts powers of 2, so it will round down to the nearest power of two that is less than
        // or equal to the sample size we provide. Because we need to estimate the final image width and height to
        // re-use Bitmaps, we mirror BitmapFactory's calculation here. For bug, see issue #224. For algorithm see
        // http://stackoverflow.com/a/17379704/800716.
        final int powerOfTwoSampleSize = exactSampleSize == 0 ? 0 : Integer.highestOneBit(exactSampleSize);

        // Although functionally equivalent to 0 for BitmapFactory, 1 is a safer default for our code than 0.
        return Math.max(1, powerOfTwoSampleSize);
    }
Load the image for the given InputStream. If a recycled Bitmap whose dimensions exactly match those of the image
for the given InputStream is available, the operation is much less expensive in terms of memory.

<p>
    Note - this method will throw an exception of a Bitmap with dimensions not matching
    those of the image for the given InputStream is provided.
</p>

@param is An {@link InputStream} to the data for the image.
@param pool A pool of recycled bitmaps.
@param outWidth The width the final image should be close to.
@param outHeight The height the final image should be close to.
@return A new bitmap containing the image from the given InputStream, or recycle if recycle is not null.
core/src/main/java/com/bumptech/glide/load/resource/bitmap/Downsampler.java