public ImageTranscodeResult transcode()

in native-imagetranscoder/src/main/java/com/facebook/imagepipeline/nativecode/NativeJpegTranscoder.java [87:148]


  public ImageTranscodeResult transcode(
      final EncodedImage encodedImage,
      final OutputStream outputStream,
      @Nullable RotationOptions rotationOptions,
      @Nullable final ResizeOptions resizeOptions,
      @Nullable ImageFormat outputFormat,
      @Nullable Integer quality)
      throws IOException {
    if (quality == null) {
      quality = DEFAULT_JPEG_QUALITY;
    }
    if (rotationOptions == null) {
      rotationOptions = RotationOptions.autoRotate();
    }
    final int downsampleRatio =
        DownsampleUtil.determineSampleSize(
            rotationOptions, resizeOptions, encodedImage, mMaxBitmapSize);
    InputStream is = null;
    try {
      final int softwareNumerator =
          JpegTranscoderUtils.getSoftwareNumerator(
              rotationOptions, resizeOptions, encodedImage, mResizingEnabled);
      final int downsampleNumerator =
          JpegTranscoderUtils.calculateDownsampleNumerator(downsampleRatio);
      final int numerator;
      if (mUseDownsamplingRatio) {
        numerator = downsampleNumerator;
      } else {
        numerator = softwareNumerator;
      }
      is = encodedImage.getInputStream();
      if (INVERTED_EXIF_ORIENTATIONS.contains(encodedImage.getExifOrientation())) {
        // Use exif orientation to rotate since we can't use the rotation angle for
        // inverted exif orientations
        final int exifOrientation =
            JpegTranscoderUtils.getForceRotatedInvertedExifOrientation(
                rotationOptions, encodedImage);
        transcodeJpegWithExifOrientation(
            Preconditions.checkNotNull(is, "Cannot transcode from null input stream!"),
            outputStream,
            exifOrientation,
            numerator,
            quality);
      } else {
        // Use actual rotation angle in degrees to rotate
        final int rotationAngle =
            JpegTranscoderUtils.getRotationAngle(rotationOptions, encodedImage);
        transcodeJpeg(
            Preconditions.checkNotNull(is, "Cannot transcode from null input stream!"),
            outputStream,
            rotationAngle,
            numerator,
            quality);
      }
    } finally {
      Closeables.closeQuietly(is);
    }
    return new ImageTranscodeResult(
        downsampleRatio == DownsampleUtil.DEFAULT_SAMPLE_SIZE
            ? TranscodeStatus.TRANSCODING_NO_RESIZING
            : TranscodeStatus.TRANSCODING_SUCCESS);
  }