Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Still no Implementation #9

Closed
swa00 opened this issue Dec 18, 2020 · 17 comments
Closed

Still no Implementation #9

swa00 opened this issue Dec 18, 2020 · 17 comments

Comments

@swa00
Copy link

swa00 commented Dec 18, 2020

Hi,

at first - Thx a lot for your work ...
I do not have experience with NDK and i need the Lib only for one operation in my app ( bevel)

But im Sorry , maybe i'm stupid - i followed all instructions with the finished zip from here
#4 (comment)

i still get no Unsatisfied Link error. Can you pls help me ??

What i have done

a) create a blank project ( androidx , AS 4.1.1)
b) copied the whole Source, created a (blank) Jni folder,
c) created a libs/arm64-v8a and copied all files from zip above into it
d) compile project ( with NO changes of init part in your Mainactivity )
f) added Write permission

When i start the project , the lib will loaded ( System.loadLibrary("jmagick-7");

But the next point fails

java.lang.UnsatisfiedLinkError: No implementation found for void com.wdtec.testapp.magick.Magick.setAppConfigDataDir(java.lang.String) (tried Java_com_wdtec_testapp_magick_Magick_setAppConfigDataDir and Java_com_wdtec_testapp_magick_Magick_setAppConfigDataDir__Ljava_lang_String_2)

Any cool tip as christmas gift for me ? :-)

Thank u very much

@MolotovCherry
Copy link
Owner

MolotovCherry commented Dec 18, 2020

Did you follow the Quick Setup Instructions on the main page, including the section on How to Run the Binary, and the FAQ of Frequently most encountered problems and how to solve them (which includes how to solve the Unsatisfied Link Error)? There's even a link to an example app with the full app folder structure and example code.

By the way, I really don't recommend to use that version. 1) It's old, 2) you probably don't need nor want jmagick, 3) invoking the binary with the commands you want should more than suffice for everything you need, 4) it's harder to to use jmagick rather than just invoking a binary with commands

Also, setting up the NDK to build it yourself is incredibly easy. It's as easy as downloading and installing it from the SDK manager, then you can look at my example app for a build config and app structure. I even included a bat file to start the build process.

d) compile project ( with NO changes of init part in your Mainactivity )

You need to look at and change the code. It's example code meant to be changed and configured according to your needs. It's not build ready. You need to look at the main instructions on the main page and add your ENV variables (btw, all that is done in the code already, so you just need to uncomment/change it and make sure you're using a binary only build -> I realize I'm referencing the binary version, that's because this is the version you should be using).

(Again, you really don't want to use the jmagick version there. It'll make things harder for you when programming. Use the binary code section in the MainActivity.java, I marked the sections. And delete the jmagick section).

And if you want to use the latest code, you'll have to build it yourself, but like I said before, there's some Quick Start Instructions on the main page for that, and it's as easy as copying my app folder, looking at and changing the code, installing NDK from the SDK manager, and putting the project in the JNI folder and starting the build.

I'd also need to see your entire project to tell you what's wrong, because there's too many points of failure.

Lastly -> There are some old binary builds in the release section, you can use it for initial testing to see if you got it right (use the static build if you want it to be the easiest for you). But ultimately, I suggest you use the most up-to-date sources. And again, literally anything you want to do can be done in a binary build, plus you get official documentation from the Imagemagick website for it (good luck finding documentation for jmagick)

@swa00
Copy link
Author

swa00 commented Dec 18, 2020

Dear Cherry ,

I'd also need to see your entire project to tell you what's wrong, because there's too many points of failure.

at first - THANK you very much for your (long) answer and your time you spent for it.
While i try to understand completly your answer and get into it, as attach my cleaned project
https://my.hidrive.com/lnk/x6gmmusi

i think also, that i do not understand correctly , whats the different between the versions and
what IM source-code has to use. to build

Again thank you very much for your time.

@swa00 swa00 closed this as completed Dec 18, 2020
@swa00 swa00 reopened this Dec 18, 2020
@swa00
Copy link
Author

swa00 commented Dec 18, 2020

.

@MolotovCherry
Copy link
Owner

i think also, that i do not understand correctly , whats the different between the versions and
what IM source-code has to use. to build

As usual, new versions offer bug fixes and newer features.

@MolotovCherry
Copy link
Owner

MolotovCherry commented Dec 18, 2020

So some things I noticed with your project.

  • In your build.gradle, you don't have sourceSets or splits inside defaultConfig. Reference
  • libs folder is fine, but like I said before, you should be using the binary version. Using only shared libs without a binary isn't going to be that useful for you.
  • You can place the jni folder with all the source of the project at the same level of your build.gradle, libs and src folders. Reference
  • You need the assets folder for things to work properly. Reference
  • You're missing the fakewt and magick support Java libraries. They're placed at the wrong folder level. See in the reference the level they're at. app/src/main/java/awt and app/src/main/java/magick. Not that you'll need those though, that's only for the jmagick version, which you should be using the binary version anyways (no need for those libraries after that).
  • MainActivity.java, as I said before, after getting the binary only version (and you should build it yourself too), you also need to check the code and uncomment /delete the proper sections, and configure it to what you need:

Uncomment section:

        /* CODE FOR SETTING UP BINARY USAGE
           Obviously you will need to check whether you already set this up or not
           You don't want to run this every time you start your app
           You can use Android SharedPrefs to keep track of it

Delete section:

        // FOLLOWING CODE EXAMPLE BELOW IS FOR JMAGICK ONLY. IF YOU DON'T USE JMAGICK, 
        // USE THE BINARY CODE ABOVE ONLY
....
    /// END JMAGICK SECTION

Uncomment section

    /* AsyncTask example code used for executing the binary
       If you don't run the binary on a separate thread, your UI will freeze
       Adapt it to your needs

... And so on

  • And build it from source so you can use the latest.
    • Install ndk from the sdk manager.
    • Copy all project files into project/app/jni and run build-release.bat. Building only works on Windows.

P.P.S. If you look closely at the example app, there's a binary and lib already in the folders. You could just copy that example app verbatim, uncomment the binary java code (and delete the jmagick section), and it'd probably work out of the box

@swa00
Copy link
Author

swa00 commented Dec 18, 2020

Thank you - very much :-)

I started to get into it - this will take the night and i will give you the feedback
(Hopefully happy ..... or i will change my proffession next year)

@MolotovCherry
Copy link
Owner

MolotovCherry commented Dec 18, 2020

Java_com_wdtec_testapp_magick_Magick_setAppConfigDataDir

This error means that Java is looking for the native function in JNI, but it can't find it. Notice the path com_wdtec_testapp_. In short, your packages are in the wrong places.

My C functions are named Java_magick_Magick_setAppConfigDataDir, which you can see the Java package path here magick_Magick. Reference

So, if you fix your package locations (and the package statements and import statements), it'll fix that error

@swa00
Copy link
Author

swa00 commented Dec 18, 2020

This error means that Java is looking for the native function in JNI, but it can't find it. Notice the path >>com_wdtec_testapp_. In short, your packages are in the wrong places.
So, if you fix your package locations (and the package statements and import statements), it'll fix that error

Oh, my, god !!!!
This was the goal and its working !!!
Note for me in the future : Leave it like it is and don't think too much :-)

@cherryleafroad

Thank you very very much for your help.
i wish you and your family a nice christmas time and please keep healthy

@MolotovCherry
Copy link
Owner

MolotovCherry commented Dec 18, 2020

You should know that the jmagick version is probably unreliable too, I wouldn't trust it much to do what it should. jmagick was already pretty much defunct before I even included it here. The only way to get a good jmagick version would be to do a complete rewrite from the ground up, but unfortunately after writing thousands of lines of C code, it was too much work for 1 person *facepalm

@swa00
Copy link
Author

swa00 commented Dec 18, 2020

yes you wrote this sometimes above .... and i'm a pure "c" developer - the work ist too much ......
But as i see it , its the only "usable" Imagelib to do simple processes.

in my case, i only need a bevel function like "EmbossMaskFilter" from the original Google API.
But this filter was removed ( deprecated ) since API 28 without any replacement or comment from Google.
(How often at google :-()

Therefore i tried OpenCV and ImageMagick .
But if you have any other alternative , or idea - let me know.

@MolotovCherry
Copy link
Owner

MolotovCherry commented Dec 18, 2020

I mean the binary version. It's much easier to do something like what you what from the commandline ;) You don't have to give up this imagemagick to go for the binary version. If the jmagick API was stable though I'd have no issue saying it may be better (although maybe a bit of work figuring out the programming commands, but nonetheless better). Little tiny bugs or problems may creep up on you without you knowing.

For example, I made something using it, and it wouldn't get transparency right even though it works in the commandline. C coding wasn't right.

Therefore i tried OpenCV and ImageMagick .
But` if you have any other alternative , or idea - let me know.

At the time of project creation, there was a surprisingly lack of any good image editing tools for Android (or they were horribly outdated). That's why I made this one. As you say, it's the only "usable" one.

@swa00
Copy link
Author

swa00 commented Dec 18, 2020

i also found something in this direction

https://github.com/thenewcircle/renderscriptimaging

Its working (and fast) , but you have to step deeply in impageprocessing from scratch , to implement
all basic functions - same work to re-develop any c-library

@swa00
Copy link
Author

swa00 commented Dec 19, 2020

Beside Note : Playing with your implementation , i found out that an Android - bitmap operation is missing.
e.g getting the BGRA pixels and transfer them to (int) ARGB. (or just get an Bitmap Object during runtime)

Ref :
https://github.com/paulasiimwe/Android-ImageMagick/blob/master/jni/magick_MagickBitmap.c

@MolotovCherry
Copy link
Owner

MolotovCherry commented Dec 19, 2020

Beside Note : Playing with your implementation , i found out that an Android - bitmap operation is missing.
e.g getting the BGRA pixels and transfer them to (int) ARGB. (or just get an Bitmap Object during runtime)

Ref :
https://github.com/paulasiimwe/Android-ImageMagick/blob/master/jni/magick_MagickBitmap.c

Yet another thing missing from the official project. Another example why I don't trust jmagick all that much, as its API is incomplete and lacking (also bug prone). If you feel like getting the src compiling though, adding that file to the build wouldn't be that hard for you.

Just update the build file to include the src, then throw in the magick java src. (and remove the loadlibrary, we already do that).

@swa00
Copy link
Author

swa00 commented Dec 19, 2020

Thx a lot :-)

in the moment i'm trying to figure out , how to setup the system correctly to use NDK .
As i wrote above , i never played with NDK .

Do you have time to recomplie the binaries and place them here as ZIP ?
(If not - no problem - it just saves time - it is only a question)

@MolotovCherry
Copy link
Owner

MolotovCherry commented Dec 19, 2020

I don't - I haven't done this project in a long time and don't have things set up anymore. But if you encounter errors and need additional help, feel free to let me know and I'll help you out. I'm closing this issue as the original problem is solved.

@swa00
Copy link
Author

swa00 commented Dec 19, 2020

Using the new NDK 22.070, you have to change several things

a) /MagicCore/memory.c -> function AcquireAlignedMemory_STDC (Line 252)

  • Because "align_alloc" is obsolte ... change
    return(aligned_alloc(CACHE_LINE_SIZE,extent));
    into
    void *ptr = NULL; posix_memalign(&ptr,CACHE_LINE_SIZE,extent); return ptr;

b)
Batchfile needs some changes

  • during batch compiling error "fcntl(): Bad file descriptor"
    NDK needs to disable parallel processing with the flag "--output-sync=none"

  • Win10 - the setting of envoirments does not work, so the ndk_build needs full pathes

Full Example
ndk-build --output-sync=none NDK_PROJECT_PATH=[YOUR_PATH_TO_Android-ImageMagick7-master] NDK_APPLICATION_MK=Application.mk APP_BUILD_SCRIPT=Android.mk NDK_OUT=../build/ NDK_LIBS_OUT=../jniLibs -j 4

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants