Skip to content

Commit 8e2bcca

Browse files
committed
Merge branch 'png-mainline' of https://github.com/opacam/python-for-android into matplotlib_recipe
2 parents 959c2ea + 164c227 commit 8e2bcca

File tree

6 files changed

+479
-34
lines changed

6 files changed

+479
-34
lines changed

pythonforandroid/recipes/Pillow/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ def get_recipe_env(self, arch=None, with_flags_in_cc=True):
2121
ndk_include_dir = join(self.ctx.ndk_dir, 'sysroot', 'usr', 'include')
2222

2323
png = self.get_recipe('png', self.ctx)
24-
png_lib_dir = png.get_lib_dir(arch)
25-
png_jni_dir = png.get_jni_dir(arch)
24+
png_lib_dir = join(png.get_build_dir(arch.arch), '.libs')
25+
png_inc_dir = png.get_build_dir(arch)
2626

2727
jpeg = self.get_recipe('jpeg', self.ctx)
2828
jpeg_inc_dir = jpeg_lib_dir = jpeg.get_build_dir(arch.arch)
@@ -41,7 +41,7 @@ def get_recipe_env(self, arch=None, with_flags_in_cc=True):
4141
env['FREETYPE_ROOT'] = '{}|{}'.format(free_lib_dir, free_inc_dir)
4242
env['ZLIB_ROOT'] = '{}|{}'.format(ndk_lib_dir, ndk_include_dir)
4343

44-
cflags = ' -I{}'.format(png_jni_dir)
44+
cflags = ' -I{}'.format(png_inc_dir)
4545
cflags += ' -I{} -I{}'.format(harf_inc_dir, join(harf_inc_dir, 'src'))
4646
cflags += ' -I{}'.format(free_inc_dir)
4747
cflags += ' -I{}'.format(jpeg_inc_dir)

pythonforandroid/recipes/android/src/android/permissions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def autoclass(item):
1111
class Permission:
1212
ACCEPT_HANDOVER = "android.permission.ACCEPT_HANDOVER"
1313
ACCESS_COARSE_LOCATION = "android.permission.ACCESS_COARSE_LOCATION"
14+
ACCESS_FINE_LOCATION = "android.permisssion.ACCESS_FINE_LOCATION"
1415
ACCESS_LOCATION_EXTRA_COMMANDS = (
1516
"android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"
1617
)
Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,52 @@
1-
from pythonforandroid.recipe import NDKRecipe
2-
from pythonforandroid.util import current_directory
1+
from pythonforandroid.recipe import Recipe
32
from pythonforandroid.logger import shprint
4-
3+
from pythonforandroid.util import current_directory
4+
from multiprocessing import cpu_count
5+
from os.path import join, exists
56
import sh
67

7-
from os.path import join
88

9-
10-
class PngRecipe(NDKRecipe):
9+
class PngRecipe(Recipe):
1110
name = 'png'
12-
# This version is the last `sha commit` published in the repo (it's more
13-
# than one year old...) and it's for libpng version `1.6.29`. We set a
14-
# commit for a version because the author of the github's repo never
15-
# released/tagged it, despite He performed the necessary changes in
16-
# master branch.
17-
version = 'b43b4c6'
18-
19-
# TODO: Try to move the repo to mainline
20-
url = 'https://github.com/julienr/libpng-android/archive/{version}.zip'
21-
22-
patches = ['build_shared_library.patch']
23-
24-
generated_libraries = ['libpng.so']
11+
version = 'v1.6.37'
12+
url = 'https://github.com/glennrp/libpng/archive/{version}.zip'
13+
14+
def should_build(self, arch):
15+
return not exists(
16+
join(self.get_build_dir(arch.arch), '.libs', 'libpng16.so')
17+
)
18+
19+
def get_recipe_env(self, arch=None):
20+
env = super(PngRecipe, self).get_recipe_env(arch)
21+
ndk_lib_dir = join(self.ctx.ndk_platform, 'usr', 'lib')
22+
ndk_include_dir = join(self.ctx.ndk_dir, 'sysroot', 'usr', 'include')
23+
env['CFLAGS'] += ' -I{}'.format(ndk_include_dir)
24+
env['LDFLAGS'] += ' -L{}'.format(ndk_lib_dir)
25+
env['LDFLAGS'] += ' --sysroot={}'.format(self.ctx.ndk_platform)
26+
return env
2527

2628
def build_arch(self, arch):
2729
super(PngRecipe, self).build_arch(arch)
28-
29-
with current_directory(self.get_build_dir(arch.arch)):
30+
build_dir = self.get_build_dir(arch.arch)
31+
with current_directory(build_dir):
32+
env = self.get_recipe_env(arch)
33+
build_arch = (
34+
shprint(sh.gcc, '-dumpmachine')
35+
.stdout.decode('utf-8')
36+
.split('\n')[0]
37+
)
3038
shprint(
31-
sh.cp,
32-
join(
33-
self.get_build_dir(arch.arch),
34-
'libs',
35-
arch.arch,
36-
'libpng.so'),
37-
join(self.ctx.get_libs_dir(arch.arch), 'libpng16.so'))
38-
39-
40-
pass
39+
sh.Command('./configure'),
40+
'--build=' + build_arch,
41+
'--host=' + arch.command_prefix,
42+
'--target=' + arch.command_prefix,
43+
'--disable-static',
44+
'--enable-shared',
45+
'--prefix={}/install'.format(self.get_build_dir(arch.arch)),
46+
_env=env,
47+
)
48+
shprint(sh.make, '-j', str(cpu_count()), _env=env)
49+
self.install_libs(arch, join(build_dir, '.libs', 'libpng16.so'))
50+
4151

4252
recipe = PngRecipe()
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
from distutils.core import setup
3+
from setuptools import find_packages
4+
5+
options = {'apk': {'requirements': 'harfbuzz,sdl2,pillow,kivy,python3',
6+
'blacklist-requirements': 'sqlite3',
7+
'android-api': 27,
8+
'ndk-api': 21,
9+
'dist-name': 'pillow_testapp',
10+
'arch': 'armeabi-v7a',
11+
'permissions': ['VIBRATE'],
12+
}}
13+
14+
package_data = {'': ['*.py',
15+
'*.png']
16+
}
17+
18+
setup(
19+
name='testapp_pillow',
20+
version='1.0',
21+
description='p4a setup.py test',
22+
author='Pol Canelles',
23+
author_email='[email protected]',
24+
packages=find_packages(),
25+
options=options,
26+
package_data={'testapp_pillow': ['*.py', '*.png', '*.ttf']}
27+
)

testapps/testapp_pillow/colours.png

187 KB
Loading

0 commit comments

Comments
 (0)