-
Notifications
You must be signed in to change notification settings - Fork 611
Add support for more modern image format like JPEG XL #899
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
Closed
Closed
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
641ad58
Make image diffing strategies custom scale aware (#336)
moritzsternemann 4579af4
Add PreviewSnapshots to "Plug-ins" (#695)
jflan-dd 870a891
feat: add basic support for JPEG XL
mackoj d3abda0
feat: make test compile
mackoj 006c91f
feat: use global imageFormat
mackoj 5831676
Merge branch 'main' into feat/addBasicSupportForJXL
mackoj be21490
fix: compilation issue$
mackoj 8f772fc
fix: cleaning
mackoj e53ff1e
fix: improve implementation add heic
mackoj 42bddc4
fix: cleanup a bit
mackoj ef1e6e0
fix: cleanup a bit
mackoj f6647b5
feat: add support for webp
mackoj 4b83371
feat: cleaning
mackoj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
Sources/SnapshotTesting/Snapshotting/ImageSerializer.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import Foundation | ||
import JxlCoder | ||
|
||
#if !os(macOS) | ||
import UIKit.UIImage | ||
public typealias SnapImage = UIImage | ||
|
||
private func EncodePNGImage(_ image: SnapImage) -> Data? { | ||
return image.pngData() | ||
} | ||
|
||
private func DecodePNGImage(_ data: Data) -> SnapImage? { | ||
UIImage(data: data) | ||
} | ||
|
||
#else | ||
import AppKit.NSImage | ||
public typealias SnapImage = NSImage | ||
|
||
private func EncodePNGImage(_ image: SnapImage) -> Data? { | ||
guard let cgImage = image.cgImage(forProposedRect: nil, context: nil, hints: nil) else { return nil } | ||
let rep = NSBitmapImageRep(cgImage: cgImage) | ||
rep.size = image.size | ||
return rep.representation(using: .png, properties: [:]) | ||
} | ||
|
||
private func DecodePNGImage(_ data: Data) -> SnapImage? { | ||
NSImage(data: data) | ||
} | ||
|
||
#endif | ||
|
||
package protocol DefaultValueProvider<Value> { | ||
associatedtype Value | ||
|
||
static var defaultValue: Value { get } | ||
} | ||
|
||
public enum ImageFormat: String, DefaultValueProvider { | ||
case jxl | ||
case png | ||
|
||
public static var defaultValue = ImageFormat.png | ||
} | ||
|
||
package func EncodeImage(image: SnapImage, _ format: ImageFormat) -> Data? { | ||
switch format { | ||
case .jxl: return try? JXLCoder.encode(image: image) | ||
case .png: return EncodePNGImage(image) | ||
} | ||
} | ||
|
||
package func DecodeImage(data: Data, _ format: ImageFormat) -> SnapImage? { | ||
switch format { | ||
case .jxl: return try? JXLCoder.decode(data: data) | ||
case .png: return DecodePNGImage(data) | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.