Skip to content

Commit ebddc1a

Browse files
authored
Merge pull request #30 from marcprux/master
Android Support
2 parents b8deca7 + ec98009 commit ebddc1a

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed

.github/workflows/android.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Android
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
android:
11+
runs-on: ubuntu-24.04
12+
name: Android
13+
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v4
17+
- name: Build for Android
18+
uses: skiptools/swift-android-action@v2
19+
with:
20+
run-tests: false

Sources/JPEG/decode.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,6 +1768,20 @@ extension JPEG.Data.Spectral:RandomAccessCollection
17681768
///
17691769
/// - Returns:
17701770
/// The plane.
1771+
#if os(Android) // workaround for an Android toolchain crash in `yield`
1772+
public
1773+
subscript(p:Int) -> Plane
1774+
{
1775+
get
1776+
{
1777+
self.planes[p]
1778+
}
1779+
set
1780+
{
1781+
self.planes[p] = newValue
1782+
}
1783+
}
1784+
#else
17711785
public
17721786
subscript(p:Int) -> Plane
17731787
{
@@ -1780,6 +1794,7 @@ extension JPEG.Data.Spectral:RandomAccessCollection
17801794
yield &self.planes[p]
17811795
}
17821796
}
1797+
#endif
17831798
/// Returns the index of the plane storing the color channel represented
17841799
/// by the given component key, or `nil` if the component key is a
17851800
/// non-recognized component.

Sources/JPEGSystem/os.swift

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import JPEG
88
import Darwin
99
#elseif os(Linux)
1010
import Glibc
11+
#elseif os(Android)
12+
import Android
1113
#else
1214
#warning("unsupported or untested platform (please open an issue at https://github.com/tayloraswift/swift-jpeg/issues)")
1315
#endif
1416

15-
#if os(macOS) || os(Linux)
17+
#if os(macOS) || os(Linux) || os(Android)
1618

1719
/// A namespace for platform-dependent functionality.
1820
///
@@ -25,7 +27,11 @@ enum System
2527
public
2628
enum File
2729
{
30+
#if os(Android)
31+
typealias Descriptor = OpaquePointer
32+
#else
2833
typealias Descriptor = UnsafeMutablePointer<FILE>
34+
#endif
2935

3036
/// A type for reading data from files on disk.
3137
public
@@ -102,7 +108,12 @@ extension System.File.Source
102108
{
103109
(buffer:inout UnsafeMutableBufferPointer<UInt8>, count:inout Int) in
104110

105-
count = fread(buffer.baseAddress, MemoryLayout<UInt8>.stride,
111+
#if os(Android)
112+
let baseAddress = buffer.baseAddress!
113+
#else
114+
let baseAddress = buffer.baseAddress
115+
#endif
116+
count = fread(baseAddress, MemoryLayout<UInt8>.stride,
106117
capacity, self.descriptor)
107118
}
108119

@@ -210,7 +221,12 @@ extension System.File.Destination
210221
{
211222
let count:Int = buffer.withUnsafeBufferPointer
212223
{
213-
fwrite($0.baseAddress, MemoryLayout<UInt8>.stride,
224+
#if os(Android)
225+
let baseAddress = $0.baseAddress!
226+
#else
227+
let baseAddress = $0.baseAddress
228+
#endif
229+
return fwrite(baseAddress, MemoryLayout<UInt8>.stride,
214230
$0.count, self.descriptor)
215231
}
216232

0 commit comments

Comments
 (0)