I port the dwt2d from wavelib (c) to kotlin (java) line by line. It works at first attempt.
Then I tried to rewrite the program based on my understanding. It brokes in an unexpected way and I don't know why.
Conclusion of the day: do not rewrite codes if it's working .
Such is life.