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

Feature customizable default cache serializer #1373

Merged
merged 3 commits into from
Dec 23, 2019

Conversation

onevcat
Copy link
Owner

@onevcat onevcat commented Dec 17, 2019

For #1362



/// The compression quality when converting image to a lossy format data. Default is 1.0.
public var compressionQuality: CGFloat = 1.0
Copy link

@Adobels Adobels Dec 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it have to be CGFloat? Can't it be a Double as it was?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compressionQuality might be defined as an enumeration with a default value set to high.
public var compressionQuality: JPEGCompressionLevel = .high

enum JPEGCompressionLevel {
  case custom(Double)
  case max, high, med, low

  var rawValue: Double {
    switch self {
    case .max:
      return 1.0
    case .high:
      return 0.9
    case .med:
      return 0.5
    case .low:
      return 0.2
    case .custom(let customValue):
      return customValue
    }
  }
}

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UIImage receives a CGFloat when converting to JPEG data: https://developer.apple.com/documentation/uikit/uiimage/1624115-jpegdata

So I guess keeping them aligned would reduce the mental pressure of users.

What do you mean by "a Double as it was"? I don't think this value once being a Double anywhere... 😕

Copy link

@Adobels Adobels Dec 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made the mistaken assumption about the original type of the compressionQuality property because CoreGraphics library was imported.
Below, updated code proposition.

enum JPEGCompressionLevel {
  case custom(CGFloat)
  case max, high, med, low

  var rawValue: CGFloat {
    switch self {
    case .max:
      return 1.0
    case .high:
      return 0.9
    case .med:
      return 0.5
    case .low:
      return 0.2
    case .custom(let customValue):
      return customValue
    }
  }
}

Example of use:

var cacheSerializer = DefaultCacheSerializer()
cacheSerializer.compressionQuality = .max
cacheSerializer.compressionQuality = .custom(0.8)

@onevcat onevcat merged commit 17b2d8c into master Dec 23, 2019
@onevcat onevcat deleted the feature/customizable-default-cache-serializer branch January 17, 2020 13:25
skoduricg pushed a commit to rentpath/Kingfisher that referenced this pull request Sep 24, 2021
…ault-cache-serializer

Feature customizable default cache serializer
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

Successfully merging this pull request may close these issues.

2 participants